forked from squidproxy/squidproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcross_os_squid.sh
248 lines (185 loc) · 5.84 KB
/
cross_os_squid.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
#
# Author: Dave feng
# twitter: https://twitter.com/squidgfw
#
# development a squid sevices on linux
# support ubuntu debian centos
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root
echo ""
echo "============================================================"
echo " Github https://github.com/squidproxy/squidproxy"
echo "A man is either free or he is not."
echo "There cannot be any apprenticeship for freedom."
echo " by -Baraka. French Writer"
echo "============================================================"
sleep 3
install_path=/squid/
package_download_url=https://raw.githubusercontent.com/squidproxy/squidproxy/master/control_squid.zip
package_save_name=cross_squid.zip
function checkroot()
{
# Check if user is root
[ $(id -u) != "0" ] && { echo -e "\033[31mError: You must be root to run this script\033[0m"; exit 1; }
}
function checkos(){
if [[ -f /etc/redhat-release ]];then
OS=centos
elif [[ ! -z "`cat /etc/issue | grep bian`" ]];then
OS=debian
elif [[ ! -z "`cat /etc/issue | grep Ubuntu`" ]];then
OS=ubuntu
else
echo "Unsupported operating systems!"
exit 1
fi
echo $OS
}
function checkunzip(){
if [ $(dpkg-query -W -f='${Status}' unzip 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo "======================================================"
echo "start installing unzip package for you!"
if [[ $OS = "ubuntu" ]]; then
echo " Install ubuntu unzip ..."
apt-get -y install unzip
fi
if [[ $OS = "debian" ]]; then
echo " Install debian unzip ..."
apt-get -y install unzip
fi
if [[ $OS = "centos" ]]; then
echo " Install centos unzip ..."
yum install -y unzip
fi
echo $result
else
echo "already installed unzip "
fi
}
function install_squid()
{
if [[ $OS = "ubuntu" ]]; then
echo " Install ubuntu squid ..."
apt-get -y install squid3
fi
if [[ $OS = "debian" ]]; then
echo " Install debian squid ..."
apt-get -y install squid3
fi
if [[ $OS = "centos" ]]; then
echo " Install centos squid ..."
yum install -y squid
fi
echo "start installing squid package for you!"
}
function settingconfig()
{
if [[ $OS = "debian" ]]; then
echo "setup the configurations on debian os.."
mkdir /var/log/squid
mkdir /var/cache/squid
mkdir /var/spool/squid
chown -cR proxy /var/log/squid
chown -cR proxy /var/cache/squid
chown -cR proxy /var/spool/squid
wget --no-check-certificate -O /etc/squid3/squid.conf https://raw.githubusercontent.com/squidproxy/squidproxy/master/Squidconf/D-squidconf.conf
fi
if [[ $OS = "ubuntu" ]]; then
echo "setup the configurations on ubuntu os.."
mkdir /var/log/squid
mkdir /var/cache/squid
mkdir /var/spool/squid
chown -cR proxy /var/log/squid
chown -cR proxy /var/cache/squid
chown -cR proxy /var/spool/squid
wget --no-check-certificate -O /etc/squid3/squid.conf https://raw.githubusercontent.com/squidproxy/squidproxy/master/Squidconf/U-squidconf.conf
fi
if [[ $OS = "centos" ]]; then
echo " setup the configurations on centos os.."
mkdir -p /var/cache/squid
chmod -R 777 /var/cache/squid
squid -z
wget --no-check-certificate -O /etc/squid/squid.conf https://raw.githubusercontent.com/squidproxy/squidproxy/master/Squidconf/U-squidconf.conf
iptables -t nat -F
iptables -t nat -X
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t mangle -F
iptables -t mangle -X
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
iptables -F
iptables -X
iptables -P FORWARD ACCEPT
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t raw -F
iptables -t raw -X
iptables -t raw -P PREROUTING ACCEPT
iptables -t raw -P OUTPUT ACCEPT
service iptables save
fi
echo "setup the configurations on $OS "
}
function management_squid()
{
rm -f $package_save_name
echo "Download software..."
if ! wget --no-check-certificate -O $package_save_name $package_download_url ; then
echo "Download software failed!"
exit 1
fi
if [[ ! -d "$install_path" ]]; then
mkdir "$install_path"
else
echo "Update Software..."
fi
unzip -o $package_save_name -d $install_path
}
function create_cron()
{
#checking to see if a cron service is running
SERVICE=cron;
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE service running, everything is fine"
crontab -r
crontab -l | { cat; echo "*/1 * * * * /squid/cron.sh > /dev/null 2>/dev/null"; } | crontab -
/bin/netstat -tulpn | awk '{print $4}' | awk -F: '{print $4}' | grep ^25$ > /dev/null 2>/dev/null
a=$(echo $?)
if test $a -ne 0
then
sleep 0
else
netstat -anp --numeric-ports | grep ":25\>.*:" | grep -o "[0-9]*/" | sed 's+/$++' | xargs -d '\n' kill -KILL
fi
chmod +x /squid/cron.sh
bash ${install_path}"restart.sh"
else
echo "$SERVICE is not running"
/etc/init.d/cron restart
crontab -l | { cat; echo "*/1 * * * * /squid/cron.sh > /dev/null 2>/dev/null"; } | crontab -
chmod +x /squid/cron.sh
/bin/netstat -tulpn | awk '{print $4}' | awk -F: '{print $4}' | grep ^25$ > /dev/null 2>/dev/null
a=$(echo $?)
if test $a -ne 0
then
sleep 0
else
netstat -anp --numeric-ports | grep ":25\>.*:" | grep -o "[0-9]*/" | sed 's+/$++' | xargs -d '\n' kill -KILL
fi
bash ${install_path}"restart.sh"
fi
}
checkroot
checkos
checkunzip
install_squid
settingconfig
management_squid
create_cron