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

This commit is contained in:
Jason 2022-02-16 14:38:33 -05:00
parent 85958cd3f7
commit 3d192d5ad6
No known key found for this signature in database
GPG Key ID: 4F765975C1F0EE5F

View File

@ -1,16 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
if [ "$1" = "healthcheck" ]; then SQUID_USER="${SQUID_USER:-root}"
squidclient -h localhost cache_object://localhost/counters
exit $?
fi
SQUID_USER="${SQUID_USER:-squid}"
SQUID_LOG_DIR="${SQUID_LOG_DIR:-/data/log/squid}" SQUID_LOG_DIR="${SQUID_LOG_DIR:-/data/log/squid}"
SQUID_CACHE_DIR="${SQUID_CACHE_DIR:-/data/cache/squid}" SQUID_CACHE_DIR="${SQUID_CACHE_DIR:-/data/cache/squid}"
HOSTNAME="${HOSTNAME:-$(hostname -f)}" export HOSTNAME="${HOSTNAME:-$(hostname -f)}"
__init() {
mkdir -p "/config" "/data" mkdir -p "/config" "/data"
for dir in apache2 e2guardian squid squidguard; do for dir in apache2 e2guardian squid squidguard; do
@ -24,17 +19,17 @@ for dir in apache2 e2guardian squid squidguard; do
fi fi
done done
mkdir -p "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}" 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"
chown -Rf ${SQUID_USER}:${SQUID_USER} "/config" "/data" chown -Rf ${SQUID_USER}:${SQUID_USER} "/config" "/data"
chmod -Rf 755 "${SQUID_LOG_DIR}" chmod -Rf 777 "${SQUID_LOG_DIR}" "${SQUID_CACHE_DIR}"
cp -Rf "/config/." "/etc/" cp -Rf "/config/." "/etc/"
if [ "${UPDATE_BLACKLIST_URL}" != "" ]; then if [ "${UPDATE_BLACKLIST_URL}" != "" ]; then
sudo wget -O backlist.tar.gz ${UPDATE_BLACKLIST_URL} && sudo wget -O /tmp/backlist.tar.gz ${UPDATE_BLACKLIST_URL} &&
tar -xzf backlist.tar.gz -C "/data/squidguard/db" && tar -xzf /tmp/backlist.tar.gz -C "/data/squidguard/db" &&
rm -Rf backlist.tar.gz && rm -Rf /tmp/backlist.tar.gz &&
chown -Rf ${SQUID_USER}:${SQUID_USER} "/data/squidguard/db" chown -Rf ${SQUID_USER}:${SQUID_USER} "/data/squidguard/db"
fi fi
@ -52,18 +47,37 @@ elif [[ ${1} == squid || ${1} == $(which squid) ]]; then
EXTRA_ARGS="${@:2}" EXTRA_ARGS="${@:2}"
set -- set --
fi fi
}
# start apache to serve wpad.dat file and or block.html case "$1" in
sudo /etc/init.d/apache2 restart
# default behaviour is to launch squid healthcheck)
if [[ -z ${1} ]]; then squidclient -h localhost cache_object://localhost/counters
exit $?
;;
update)
shift 1
/usr/local/bin/create-blocklists.sh
exit $?
;;
bash | shell | sh)
exec /bin/bash -l
;;
*)
__init "$@"
if [[ ! -d ${SQUID_CACHE_DIR}/00 ]]; then if [[ ! -d ${SQUID_CACHE_DIR}/00 ]]; then
echo "Initializing cache..." echo "Initializing cache..."
$(which squid) -N -f /etc/squid/squid.conf -z $(which squid) -N -f "/config/squid/squid.conf" -z
fi 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..." echo "Starting squid..."
exec $(which squid) -f /etc/squid/squid.conf -NYCd 1 ${EXTRA_ARGS} exec $(which squid) -f "/config/squid/squid.conf" -NYCd 1 ${EXTRA_ARGS}
else ;;
exec "$@" esac
fi