-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpermission.sh
73 lines (70 loc) · 1.86 KB
/
permission.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
cekDir(){
if [ -d "${val}" ]; then
for filename in $(find $val);
do
echo "`stat -c "%a" "$filename"` u=`stat -c "%U" "$filename"` g=`stat -c "%G" "$filename"` $filename"
done
elif [[ -f "${val}" ]]; then
#echo "$val is not a Directory"
echo "`stat -c "%a" "$val"` u=`stat -c "%U" "$val"` g=`stat -c "%G" "$val"` $val"
else
echo "
Unknown either FILE nor DIRECTORY,
Please specify precisely
"
fi
}
fixPerm(){
if [ -d "${val}" ]; then
for filename in $(find $val);
do
echo "File permission set to 0644" >&2
find "${val}" -type f -exec chmod 0644 {} \;
echo "Directory permission set to 0755" >&2
find "${val}" -type d -exec chmod 0755 {} \;
done
elif [[ -f "${val}" ]]; then
#statements
echo "change file permission to 0644" >&2
chmod 0644 "${val}"
fi
}
optspec=":hvfr-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
dir)
val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
cekDir
;;
dir=*)
val=${OPTARG#*=}
opt=${OPTARG%=$val}
cekDir
;;
*)
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then
echo "Unknown option --${OPTARG}" >&2
fi
;;
esac;;
h)
echo "usage: $0 [-v] [-f] [--dir[=]<value>]" >&2
exit 2
;;
f)
fixPerm
echo "Fixing permission file and folder"
;;
v)
echo "Parsing option: '-${optchar}'" >&2
;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Non-option argument: '-${OPTARG}'" >&2
fi
;;
esac
done