-
Notifications
You must be signed in to change notification settings - Fork 7
/
update-permissions.sh
85 lines (77 loc) · 2.2 KB
/
update-permissions.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
#!/bin/bash
# bash <(curl -s https://raw.githubusercontent.com/KnoAll/cacti-template/dev/update-permissions.sh) dev debug
green=$(tput setaf 2)
red=$(tput setaf 1)
tan=$(tput setaf 3)
reset=$(tput sgr0)
branch=master
printinfo() {
if [ -z "$1" ]; then
printf "${tan}::: ${green}%s${reset}\n" "$@"
else
printf "${tan}::: ${green}%s${reset}\n" "$(date +%a_%R): $@"
fi
}
printwarn() {
printf "${tan}*** WARNING: %s${reset}\n" "$(date +%a_%R): $@"
}
printerror() {
printf "${red}!!! ERROR: %s${reset}\n" "$(date +%a_%R): $@"
}
#ingest options
if [[ "$#" > 0 ]]; then
for var in "$@"; do
case $var in
debug|-debug|--debug)
printwarn "Now DEBUGGING!"
trap 'printwarn "DEBUG: $BASH_COMMAND on line $LINENO exited with code: $?"' DEBUG
;;
dev|-dev|--dev)
branch="dev"
printwarn "Now on DEV branch..."
;;
esac
done
fi
if [ -x "$(command -v dnf)" ]; then
pkg_mgr=dnf
elif [ -x "$(command -v yum)" ]; then
pkg_mgr=yum
elif [ -x "$(command -v apt)" ]; then
pkg_mgr=apt
else
printerror "You seem to be on something other than CentOS/Alma/Rocky or Raspian, cannot proceed..."
exit 1
fi
printinfo "Fixing Cacti permissions..."
case $pkg_mgr in
dnf|yum)
perm_grp=apache
;;
apt)
perm_grp=www-data
;;
esac
groups | grep -q '\$perm_grp\b'
if [ $? -ne 0 ];then
sudo usermod -a -G $perm_grp cacti
fi
sudo chgrp -R $perm_grp /var/www/html/cacti/log
sudo chgrp -R $perm_grp /var/www/html/cacti/resource
sudo chgrp -R $perm_grp /var/www/html/cacti/cache
sudo chgrp -R $perm_grp /var/www/html/cacti/scripts
sudo chgrp -R $perm_grp /var/www/html/cacti/rra
sudo chgrp -R $perm_grp /var/www/html/cacti/include/vendor/csrf
sudo chown -R cacti /var/www/html
sudo find /var/www/html -type d -exec chmod g+rwx {} +
sudo find /var/www/html -type f -exec chmod g+rw {} +
sudo find /var/www/html -type d -exec chmod u+rwx {} +
sudo find /var/www/html -type f -exec chmod u+rw {} +
sudo find /var/www/html -type d -exec chmod g+s {} +
touch /var/www/html/cacti/log/cacti.log
chmod g+w /var/www/html/cacti/log/cacti.log
printinfo
sudo systemctl restart httpd
if [ -f /opt/smokeping/bin/smokeping ]; then
bash <(curl -s https://raw.githubusercontent.com/KnoAll/cacti-template/$branch/update-permissions-smokeping.sh) $1 $2 $3
fi