#! /bin/sh
#----------------------------------------------------------------------------
# squid-init-cache  - squid-init-cache squid cache
#
# Copyright (c) 2001-2022 Ansgar Püster <ansgar(at)eisfair.org>
#
# Creation:     14.12.2003  ap
# Last Update:  $Id$
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#----------------------------------------------------------------------------

# configuration file
squidfile=/etc/config.d/squid

# include eislib
. /var/install/include/eislib

# read configuration
. $squidfile

clrhome
mecho
mecho

# stop doing anything if SQUID_MANUAL_CONFIGURATION is set to 'yes'
if [ "$SQUID_MANUAL_CONFIGURATION" = 'yes' ]
then
   mecho --warn "Attention: SQUID_MANUAL_CONFIGURATION='yes' squid configuration will not be changed"
   exit 0
fi

mecho -info "Initialize/reinitialize squid's cache ..."

# check if directory exists
if [ ! -d $SQUID_CACHE_DIR ]; then
   mkdir -p $SQUID_CACHE_DIR
   chown squid.squid $SQUID_CACHE_DIR
fi

# stop squid
sh /etc/init.d/squid stop
mecho

# initialize cache directory
/usr/sbin/squid -f /etc/squid/squid.conf -z 2>&1
# wait until squids child prozess has terminated
sleep 1
while [ -f /run/squid.pid ]
do
   sleep 1
done
mecho

# start squid
sh /etc/init.d/squid start
mecho
mecho

anykey