#!/bin/sh

# Extract source files from tarballs
tar xvf squid-2.5.STABLE11.tar.gz
tar xvzf AE.tgz

# Replace main.c client_side.c store.c of the SQUID source code with new ones and add two header files
cp AE/main.c AE/client_side.c AE/store.c AE/AEI.h AE/IPC.h squid-2.5.STABLE11/src

# Make SQUID
cd squid-2.5.STABLE11
./configure '--enable-removal-policies=lru heap'
make all
make install
cd ..

# Make AE
make -C AE depend
make -C AE
make -C AE/Sketch depend
make -C AE/Sketch

# Copy the configuration file
cp AE/AE.conf /usr/local/squid/etc

# Create the data directory for AE
data_dir=/usr/local/squid/var/AE_data
if test ! -d $data_dir; then
  mkdir $data_dir
  chown squid $data_dir
fi

# Create the cache directory for SQUID
cache_dir=/usr/local/squid/var/cache
if test ! -d $cache_dir; then
  mkdir $cache_dir
  chown squid $cache_dir
fi

# Change the owner of the log directory for SQUID
chown squid /usr/local/squid/var/logs

echo Installation completed.

