install.sh
#!/bin/sh
# Set timezone
timedatectl set-timezone America/Regina
# Update OS and install necessary packages
apt update
apt upgrade -y
apt install -y ca-certificates curl wget mc net-tools
# Install Docker GPG key
#curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
wget -O /etc/apt/keyrings/docker.asc https://download.docker.com/linux/ubuntu/gpg
chmod a+r /etc/apt/keyrings/docker.asc
# Install Docker repo
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
#install docker and co.
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Create shell script for start/stop container
cat << EOF > /opt/squid/control_squid.sh
#!/bin/bash
case "\$1" in
start)
docker compose -f /opt/squid/docker-compose.yml up -d
;;
stop)
docker compose -f /opt/squid/docker-compose.yml down
;;
restart)
docker compose -f /opt/squid/docker-compose.yml down
docker compose -f /opt/squid/docker-compose.yml up -d
;;
*)
echo "Usage: ./control_squid.sh {start|stop|restart}"
exit 1
;;
esac
EOF
chmod +x /opt/squid/control_squid.sh
# Set up Docker for squid
cat << EOF > /opt/squid/docker-compose.yml
services:
squid:
image: ubuntu/squid:latest
restart: unless-stopped
ports:
- "3128:3128"
volumes:
- ./logs:/var/log/squid
- ./data:/var/spool/squid
- ./conf:/etc/squid
networks:
inside:
ipv4_address: 10.100.10.2
# user: "1100:1100"
networks:
inside:
external: false
ipam:
config:
- subnet: 10.100.10.0/24
EOF
# Create dirs
mkdir /opt/squid/logs
mkdir /opt/squid/conf
mkdir /opt/squid/data
chown -R 13:13 ./logs
chown -R 13:13 ./data
/opt/squid/conf/quid.conf content example
acl localnet src 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8 # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10 # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16 # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12 # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16 # RFC 1918 local private network (LAN)
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
acl localnet src 142.3.31.0/24
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localhost
http_access allow localnet
http_access deny all
http_port 3128
coredump_dir /var/spool/squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern \/(Packages|Sources)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
refresh_pattern \/Release(|\.gpg)$ 0 0% 0 refresh-ims
refresh_pattern \/InRelease$ 0 0% 0 refresh-ims
refresh_pattern \/(Translation-.*)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
refresh_pattern . 0 20% 4320
logfile_rotate 0
cache_dir ufs /var/spool/squid 30000 16 256
cache_mem 512 MB
maximum_object_size 4 MB
cache_log /var/log/squid/cache.log
start container
/opt/squid/control_squid.sh start
done