-
Notifications
You must be signed in to change notification settings - Fork 0
/
permReverse.sh
executable file
·84 lines (81 loc) · 2.16 KB
/
permReverse.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
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
##
## filename : permReverse.sh
## desc : konversi permission karakter, dari string ke oktal dan sebaliknya.
## author : noone <noone.nu1@gmail.com> <chars19.blogspot.com>
## licensed : (proudly) GPL
## info :
##
karakter="xwr"
nilKarakter () {
case $1 in
0) nk="---" ;;
1) nk="--x" ;;
2) nk="-w-" ;;
3) nk="-wx" ;;
4) nk="r--" ;;
5) nk="r-x" ;;
6) nk="rw-" ;;
7) nk="rwx" ;;
esac
}
show_oct () {
for ((x=0;x<8;x++));do
nilKarakter $x
karX=$nk
for((y=0;y<8;y++));do
nilKarakter $y
karY=$nk
for((z=0;z<8;z++));do
nilKarakter $z
karZ=$nk
angka="$x$y$z"
karakter="$karX$karY$karZ"
if test "$1" == "all";then
echo "$angka = $karakter"
elif test "$1" == "$karakter"; then
echo "$karakter -> $angka"
exit 1
elif test "$1" == "$angka"; then
echo "$angka -> $karakter"
exit 1
fi
done
done
done
}
show_help () {
echo "\
+-----------------------------------------------------------------------+
| Reverse permission number, |
| from character to octal or octal to character |
| Using : ./permReverse <octal/character permission / OPTIONS> |
| Option : ./permReverse -list to show all. |
| ./permReverse <anything> to show this page. |
| 'octal_permission' |
| -> must 3 numbers and that is octal. |
| 'character_permission' |
| -> just accept character 'rwx' or '-' in 9 characters. |
| |
+---------------------------------------------------------------> nu1 <-+"
exit 1
}
if test $# -eq 1;then
num=`echo $1 | awk '/^[0-7]*$/'`
chr=`echo $1 | awk '/^[r,w,x,-]*$/'`
if [ ${#num} -eq 3 ] ; then
show_oct "$num"
# echo "num"
elif [ ${#chr} -eq 9 ] ;then
show_oct "$chr"
# echo "chr"
else
case $1 in
"-l" | "-li" | "-lis" | "-list" )
show_oct "all" ;;
*) show_help ;;
esac
fi
else
show_help
fi