-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwww-check-perms.sh
executable file
·92 lines (78 loc) · 2.42 KB
/
www-check-perms.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
83
84
85
86
87
88
89
90
91
#!/bin/bash
set -e
normalText="\e[0m"
blackText="\e[30m"
cyanText="\e[36m"
lightRedText="\e[91m"
lightGreenText="\e[92m"
lightYellowText="\e[93m"
greenBackground="\e[42m"
yellowBackground="\e[43m"
redBackground="\e[41m"
function display_status {
pathname="$1"
expectedLinkTarget="$2"
if [ ! -e "$pathname" ]
then
echo -e "❌ $pathname: \n\t${lightYellowText}Does not exist or has insufficient permissions.${normalText}."
return
fi
pathStat=$(stat --format "%A" "$pathname")
fileType=$(echo "$pathStat" | cut -c1)
ownerPermissions=$(echo "$pathStat" | cut -c2-4)
groupPermissions=$(echo "$pathStat" | cut -c5-7)
otherPermissions=$(echo "$pathStat" | cut -c8-10)
otherRead=$(echo "$otherPermissions" | cut -c1)
otherWrite=$(echo "$otherPermissions" | cut -c2)
otherExecute=$(echo "$otherPermissions" | cut -c3)
if [ "$fileType" == "d" ]
then
if [ "$otherExecute" == "x" ]
then
echo -e "✅ $pathname: Directory is traversable by others."
else
echo -e "❌ $pathname: Directory must be traversable by others.\n\tExecute: ${lightYellowText}chmod a+x \"$pathname\"${normalText}"
fi
elif [ "$fileType" == "-" ]
then
if [ "$otherRead" == "r" ]
then
echo -e "✅ $pathname: File is readable by others."
else
echo -e "❌ $pathname: File must be readable by others.\n\tExecute: ${lightYellowText}chmod a+r \"$pathname\"${normalText}"
fi
elif [ "$fileType" == "l" ]
then
resolvedPathname=$(readlink -f "$pathname")
if [ "$resolvedPathname" == "$expectedLinkTarget" ]
then
echo -e "✅ $pathname: Link exists and targets $resolvedPathname as expected."
else
echo -e "❌ $pathname:\n\t${lightYellowText}Link exists but does not target expected target ($expectedLinkTarget).${normalText}"
fi
fi
}
# Check standard links
display_status "$HOME/www"
display_status "$HOME/Digital Portfolio"
display_status "$HOME/www/Digital Portfolio" "$HOME/Digital Portfolio"
# Check path trail to root
currentDirectory="$(pwd)"
while [[ "$currentDirectory" != "/" ]]
do
if [ "$currentDirectory" == "$HOME/www/Digital Portfolio" ]
then
display_status "$currentDirectory" "$HOME/Digital Portfolio"
else
display_status "$currentDirectory"
fi
currentDirectory=$(dirname "$currentDirectory")
done
# Check all relevant files in current directory
for file in *.{html,css,js}
do
if [[ -f "$file" ]]
then
display_status "$file"
fi
done