-
Notifications
You must be signed in to change notification settings - Fork 46
/
start.sh
59 lines (48 loc) · 1.28 KB
/
start.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
#!/bin/sh
set -e
CHOWN=$(/usr/bin/which chown)
SQUID=$(/usr/bin/which squid)
prepare_folders() {
echo "Preparing folders..."
mkdir -p /etc/squid-cert/
mkdir -p /var/cache/squid/
mkdir -p /var/log/squid/
"$CHOWN" -R squid:squid /etc/squid-cert/
"$CHOWN" -R squid:squid /var/cache/squid/
"$CHOWN" -R squid:squid /var/log/squid/
}
initialize_cache() {
echo "Creating cache folder..."
"$SQUID" -z
sleep 5
}
create_cert() {
if [ ! -f /etc/squid-cert/private.pem ]; then
echo "Creating certificate..."
openssl req -new -newkey rsa:2048 -sha256 -days 3650 -nodes -x509 \
-extensions v3_ca -keyout /etc/squid-cert/private.pem \
-out /etc/squid-cert/private.pem \
-subj "/CN=$CN/O=$O/OU=$OU/C=$C" -utf8 -nameopt multiline,utf8
openssl x509 -in /etc/squid-cert/private.pem \
-outform DER -out /etc/squid-cert/CA.der
openssl x509 -inform DER -in /etc/squid-cert/CA.der \
-out /etc/squid-cert/CA.pem
else
echo "Certificate found..."
fi
}
clear_certs_db() {
echo "Clearing generated certificate db..."
rm -rfv /var/lib/ssl_db/
/usr/lib/squid/ssl_crtd -c -s /var/lib/ssl_db
"$CHOWN" -R squid.squid /var/lib/ssl_db
}
run() {
echo "Starting squid..."
prepare_folders
create_cert
clear_certs_db
initialize_cache
exec "$SQUID" -NYCd 1 -f /etc/squid/squid.conf
}
run