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