From 3d192d5ad6d7b7967fb810e67eb59a86e0c7fc7c Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 16 Feb 2022 14:38:33 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20modified:=20bin/entrypo?= =?UTF-8?q?int-squid.sh=20=F0=9F=97=83=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/entrypoint-squid.sh | 116 ++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 51 deletions(-) diff --git a/bin/entrypoint-squid.sh b/bin/entrypoint-squid.sh index 64da2ec..ecb2c7e 100755 --- a/bin/entrypoint-squid.sh +++ b/bin/entrypoint-squid.sh @@ -1,69 +1,83 @@ #!/usr/bin/env bash -set -e -if [ "$1" = "healthcheck" ]; then - squidclient -h localhost cache_object://localhost/counters - exit $? -fi - -SQUID_USER="${SQUID_USER:-squid}" +SQUID_USER="${SQUID_USER:-root}" SQUID_LOG_DIR="${SQUID_LOG_DIR:-/data/log/squid}" SQUID_CACHE_DIR="${SQUID_CACHE_DIR:-/data/cache/squid}" -HOSTNAME="${HOSTNAME:-$(hostname -f)}" +export HOSTNAME="${HOSTNAME:-$(hostname -f)}" -mkdir -p "/config" "/data" +__init() { + mkdir -p "/config" "/data" -for dir in apache2 e2guardian squid squidguard; do - if [ -f "/usr/local/share/squidFiles/$dir" ]; then - cp -Rf "/usr/local/share/squidFiles/$dir" "/config/$dir" - elif [ -d "/usr/local/share/squidFiles/$dir" ]; then - cp -Rf "/usr/local/share/squidFiles/$dir/." "/config/$dir/" - else - cp -Rf "/usr/local/share/squidFiles/data/." "/data/" - cp -Rf "usr/local/share/squidFiles/config/." "/config/" + for dir in apache2 e2guardian squid squidguard; do + if [ -f "/usr/local/share/squidFiles/$dir" ]; then + cp -Rf "/usr/local/share/squidFiles/$dir" "/config/$dir" + elif [ -d "/usr/local/share/squidFiles/$dir" ]; then + cp -Rf "/usr/local/share/squidFiles/$dir/." "/config/$dir/" + else + cp -Rf "/usr/local/share/squidFiles/data/." "/data/" + cp -Rf "usr/local/share/squidFiles/config/." "/config/" + fi + done + + mkdir -p "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" "/data/log/apache2" + mkdir -p "/data/log/squidguard" "/data/log/e2guardian" "/data/squidguard/db" + chown -Rf ${SQUID_USER}:${SQUID_USER} "/config" "/data" + chmod -Rf 777 "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" + + cp -Rf "/config/." "/etc/" + + if [ "${UPDATE_BLACKLIST_URL}" != "" ]; then + sudo wget -O /tmp/backlist.tar.gz ${UPDATE_BLACKLIST_URL} && + tar -xzf /tmp/backlist.tar.gz -C "/data/squidguard/db" && + rm -Rf /tmp/backlist.tar.gz && + chown -Rf ${SQUID_USER}:${SQUID_USER} "/data/squidguard/db" fi -done -mkdir -p "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" -mkdir -p "/data/log/squidguard" "/data/log/e2guardian" "/data/squidguard/db" -chown -Rf ${SQUID_USER}:${SQUID_USER} "/config" "/data" -chmod -Rf 755 "${SQUID_LOG_DIR}" + 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 -cp -Rf "/config/." "/etc/" + # allow arguments to be passed to squid + if [[ ${1:0:1} = '-' ]]; then + EXTRA_ARGS="$@" + set -- + elif [[ ${1} == squid || ${1} == $(which squid) ]]; then + EXTRA_ARGS="${@:2}" + set -- + fi +} -if [ "${UPDATE_BLACKLIST_URL}" != "" ]; then - sudo wget -O backlist.tar.gz ${UPDATE_BLACKLIST_URL} && - tar -xzf backlist.tar.gz -C "/data/squidguard/db" && - rm -Rf backlist.tar.gz && - chown -Rf ${SQUID_USER}:${SQUID_USER} "/data/squidguard/db" -fi +case "$1" in -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 +healthcheck) + squidclient -h localhost cache_object://localhost/counters + exit $? + ;; -# allow arguments to be passed to squid -if [[ ${1:0:1} = '-' ]]; then - EXTRA_ARGS="$@" - set -- -elif [[ ${1} == squid || ${1} == $(which squid) ]]; then - EXTRA_ARGS="${@:2}" - set -- -fi +update) + shift 1 + /usr/local/bin/create-blocklists.sh + exit $? + ;; -# start apache to serve wpad.dat file and or block.html -sudo /etc/init.d/apache2 restart +bash | shell | sh) + exec /bin/bash -l + ;; -# default behaviour is to launch squid -if [[ -z ${1} ]]; then +*) + __init "$@" if [[ ! -d ${SQUID_CACHE_DIR}/00 ]]; then echo "Initializing cache..." - $(which squid) -N -f /etc/squid/squid.conf -z + $(which squid) -N -f "/config/squid/squid.conf" -z fi + + echo "Starting apache web server..." + [ -f "/var/run/apache2.pid" ] && rm -R /var/run/apache2.pid + apache2 -D FOREGROUND -f "/config/apache2/apache2.conf" & + echo "Starting squid..." - exec $(which squid) -f /etc/squid/squid.conf -NYCd 1 ${EXTRA_ARGS} -else - exec "$@" -fi + exec $(which squid) -f "/config/squid/squid.conf" -NYCd 1 ${EXTRA_ARGS} + ;; +esac