🗃️ modified: bin/entrypoint-squid.sh 🗃️

This commit is contained in:
Jason 2022-02-16 17:39:19 -05:00
parent 1963a3da56
commit cb62c8289c
No known key found for this signature in database
GPG Key ID: 4F765975C1F0EE5F

View File

@ -1,8 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SQUID_USER="${SQUID_USER:-root}" export SQUID_PORT="${SQUID_PORT:-3127}"
SQUID_LOG_DIR="${SQUID_LOG_DIR:-/data/log/squid}" export E2GUARD_PORT="${E2GUARD_PORT:-3128}"
SQUID_CACHE_DIR="${SQUID_CACHE_DIR:-/data/cache/squid}" export APACHE2_PORT="${APACHE2_PORT:-8080}"
export SQUID_USER="${SQUID_USER:-squid}"
export APACHE2_USER="${APACHE2_USER:-www-data}"
export E2GUARD_USER="${E2GUARD_USER:-e2guardian}"
export SQUID_LOG_DIR="${SQUID_LOG_DIR:-/data/log/squid}"
export SQUID_CACHE_DIR="${SQUID_CACHE_DIR:-/data/cache/squid}"
export HOSTNAME="${HOSTNAME:-$(hostname -f)}" export HOSTNAME="${HOSTNAME:-$(hostname -f)}"
__init() { __init() {
@ -19,10 +26,35 @@ __init() {
fi fi
done done
mkdir -p "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" "/data/log/apache2"
mkdir -p "/data/log/squidguard" "/data/log/e2guardian" "/data/squidguard/db" mkdir -p "/data/log/squidguard" "/data/log/e2guardian" "/data/squidguard/db"
mkdir -p "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" "/data/log/apache2" "/data/htdocs/cgi-bin"
chown -Rf ${SQUID_USER}:${SQUID_USER} "/config" "/data" chown -Rf ${SQUID_USER}:${SQUID_USER} "/config" "/data"
chmod -Rf 777 "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" chown -Rf ${E2GUARD_USER}:${E2GUARD_USER} "/data/log/e2guardian" "/config/e2guardian"
chown -Rf ${APACHE2_USER}:${APACHE2_USER} "/data/htdocs" "/config/apache2" "/data/log/apache2"
chmod -Rf 777 "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" "/data/log/e2guardian"
if [ "${WPAD_IP}" != "" ]; then
sed 's/{{WPAD_IP}}/'"${WPAD_IP}"'/' -i "/data/htdocs/www/wpad.dat"
sed 's/{{WPAD_NOPROXY_NET}}/'"${WPAD_NOPROXY_NET}"'/' -i "/data/htdocs/www/wpad.dat"
sed 's/{{WPAD_NOPROXY_MASK}}/'"${WPAD_NOPROXY_MASK}"'/' -i "/data/htdocs/www/wpad.dat"
fi
if [ -f "/config/apache2/apache2.conf" ]; then
sed -i "s|SERVERNAME|$HOSTNAME|g" "/config/apache2/apache2.conf"
sed -i "s|REPLACE_SQUID_USER|$SQUID_USER|g" "/config/apache2/apache2.conf"
sed -i "s|REPLACE_HTTP_PORT|$APACHE2_PORT|g" "/config/apache2/apache2.conf"
fi
if [ -f "/config/e2guardian/e2guardian.conf" ]; then
sed -i "s|SQUID_PORT|$SQUID_PORT|g" "/config/e2guardian/e2guardian.conf"
sed -i "s|E2GUARD_PORT|$E2GUARD_PORT|g" "/config/e2guardian/e2guardian.conf"
sed -i "s|REPLACE_SQUID_USER|$SQUID_USER|g" "/config/e2guardian/e2guardian.conf"
fi
if [ -f "/config/squid/squid.conf" ]; then
sed -i "s|SERVERNAME|$HOSTNAME|g" "/config/squid/squid.conf"
sed -i "s|SQUID_PORT|$SQUID_PORT|g" "/config/squid/squid.conf"
fi
cp -Rf "/config/." "/etc/" cp -Rf "/config/." "/etc/"
@ -33,10 +65,12 @@ __init() {
chown -Rf ${SQUID_USER}:${SQUID_USER} "/data/squidguard/db" chown -Rf ${SQUID_USER}:${SQUID_USER} "/data/squidguard/db"
fi fi
if [ "${WPAD_IP}" != "" ]; then if [ ! -f "/data/htdocs/cgi-bin/cachemgr.cgi" ]; then
sed 's/{{WPAD_IP}}/'"${WPAD_IP}"'/' -i "/data/htdocs/www/wpad.dat" cp -Rf "/usr/lib/cgi-bin/cachemgr.cgi" "/data/htdocs/cgi-bin/cachemgr.cgi"
sed 's/{{WPAD_NOPROXY_NET}}/'"${WPAD_NOPROXY_NET}"'/' -i "/data/htdocs/www/wpad.dat" fi
sed 's/{{WPAD_NOPROXY_MASK}}/'"${WPAD_NOPROXY_MASK}"'/' -i "/data/htdocs/www/wpad.dat"
if [ ! -f "/data/htdocs/cgi-bin/e2guardian.pl" ]; then
cp -Rf "/usr/lib/cgi-bin/e2guardian.pl" "/data/htdocs/cgi-bin/e2guardian.pl"
fi fi
# allow arguments to be passed to squid # allow arguments to be passed to squid
@ -50,9 +84,8 @@ __init() {
} }
case "$1" in case "$1" in
healthcheck) healthcheck)
squidclient -h localhost cache_object://localhost/counters squidclient -h localhost -p $SQUID_PORT cache_object://localhost/counters
exit $? exit $?
;; ;;
@ -77,6 +110,9 @@ bash | shell | sh)
[ -f "/var/run/apache2.pid" ] && rm -R /var/run/apache2.pid [ -f "/var/run/apache2.pid" ] && rm -R /var/run/apache2.pid
apache2 -D FOREGROUND -f "/config/apache2/apache2.conf" & apache2 -D FOREGROUND -f "/config/apache2/apache2.conf" &
echo "Starting e2guardian..."
e2guardian -N -c "/config/e2guardian/e2guardian.conf" &
echo "Starting squid..." echo "Starting squid..."
exec $(which squid) -f "/config/squid/squid.conf" -NYCd 1 ${EXTRA_ARGS} exec $(which squid) -f "/config/squid/squid.conf" -NYCd 1 ${EXTRA_ARGS}
;; ;;