-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlsmcd_cpanel.sh
executable file
·139 lines (115 loc) · 3.74 KB
/
lsmcd_cpanel.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# bash script for quick set up LiteSpeed Memcached with SASL support on cPanel system
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
UBUNTU="0"
if cat /etc/*release | grep -q "CentOS Linux 7" ; then
echo -e "\nDetecting CentOS 7.x...\n"
elif cat /etc/*release | grep -q "Ubuntu" ; then
echo -e "\nDetecting Ubuntu...\n"
UBUNTU="1"
elif cat /etc/*release | grep -q "CloudLinux 7" ; then
echo -e "\nDetecting CloudLinux 7.x...\n"
elif cat /etc/*release | grep -q "CloudLinux" ; then
echo -e "\nDetecting CloudLinux ...\n"
dnf config-manager --set-enabled cloudlinux-PowerTools > /dev/null 2>&1
dnf config-manager --set-enabled PowerTools > /dev/null 2>&1
elif cat /etc/*release | grep -qi "CentOS" ; then
echo -e "\nDetecting CentOS ...\n"
dnf config-manager --set-enabled PowerTools > /dev/null 2>&1
dnf config-manager --set-enabled powertools > /dev/null 2>&1
else
echo "This script only supports CentOS, CloudLinux and Ubuntu system!"
exit 1
fi
if [[ ! -d /usr/local/cpanel ]] ; then
echo "cPanel not detected..."
exit
fi
create_sasl_user() {
if [[ -f /etc/sasllsmcd ]] ; then
user_list=$(sasldblistusers2 /etc/sasllsmcd | cut -d@ -f1)
#get current user list
fi
for name in $(ls /home/);
do
if [[ -d /home/$name/public_html ]] ; then
#check public_html existance to make sure it's vhost user instead of cPanel created dir
if ! echo "$user_list" | grep -i -q "$name" ; then
#check if user already in the list to avoid override existing users
passwd=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10 ; echo '')
echo "$passwd" | saslpasswd2 -p -f /etc/sasllsmcd "$name"
# use -p to set a random password without prompt
echo "$name added into LSMCD"
else
echo "$name already in the list..."
fi
fi
done
sudo chown nobody:nobody /etc/sasllsmcd
sudo chmod 600 /etc/sasllsmcd
echo -e "\n\n\nthe password generated is random and not usable , user will need to go to cPanel LSMCD manager to reset a new password"
}
install_lsmcd() {
if [ $UBUNTU = "1" ]; then
apt-get install git build-essential zlib1g-dev libexpat1-dev openssl libssl-dev libsasl2-dev libpcre3-dev sasl2-bin -y
else
if ! yum groupinstall -y "Development Tools" ; then
echo "yum install failed, do you have root privilege ?"
exit 1
fi
if ! yum install -y autoconf automake zlib-devel openssl-devel expat-devel pcre-devel libmemcached-devel cyrus-sasl* ; then
echo "yum install failed, do you have root privilege ?"
exit 1
fi
fi
if ! mkdir -p /home/lsmcd_tmp ; then
echo "failed to create temp dir, exit"
exit 1
fi
if ! cd /home/lsmcd_tmp ; then
echo "failed to enter temp dir, exit"
exit 1
fi
git clone https://github.com/litespeedtech/lsmcd.git
if ! cd lsmcd ; then
echo "failed to enter temp dir, exit"
exit 1
fi
./fixtimestamp.sh
./configure CFLAGS=" -O3" CXXFLAGS=" -O3"
if ! make ; then
echo "something wrong...exit"
exit 1
fi
if ! make install ; then
echo "something wrong...exit"
exit 1
fi
sed -i 's|Cached.UseSasl=.*|Cached.UseSasl=true|g' /usr/local/lsmcd/conf/node.conf
sed -i 's|#Cached.SaslDB=.*|Cached.SaslDB=/etc/sasllsmcd|g' /usr/local/lsmcd/conf/node.conf
rm -rf /dev/shm/lsmcd/*
systemctl daemon-reload
systemctl start lsmcd
systemctl enable lsmcd
git clone https://github.com/litespeedtech/lsmcd_cpanel_plugin.git
if ! cd lsmcd_cpanel_plugin/res/lsmcd_usermgr ; then
echo "failed to enter temp dir, exit"
exit 1
fi
if [ $UBUNTU = "1" ]; then
apt-get install python3 python3-pip -y
else
yum -y install python3 python3-pip
fi
./install.sh
rm -rf /home/lsmcd_tmp
}
if [[ -f /usr/local/lsmcd/conf/node.conf ]] ; then
create_sasl_user
else
install_lsmcd
create_sasl_user
fi