-
Notifications
You must be signed in to change notification settings - Fork 55
/
sdm-apt-cacher
executable file
·47 lines (41 loc) · 1.45 KB
/
sdm-apt-cacher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
econf=0 # 0 to edit /etc/apt/apt.conf.d/02proxy (Cleaner, but not visible on terminal)
#!0 to edit /etc/apt/sources.list and /etc/apt/sources.list.d/raspi.list (more intrusive, but visible on terminal)
function enablecacher () {
if [ $econf -eq 0 ]
then
[ ! -f /etc/apt/apt.conf.d/02proxy ] && echo "Acquire::http::proxy \"http://$1\";" >> /etc/apt/apt.conf.d/02proxy
else
if ! (grep $1 /etc/apt/sources.list > /dev/null 2>&1)
then
sudo sed -i "s/http:\/\//http:\/\/$1\//" /etc/apt/sources.list
sudo sed -i "s/http:\/\//http:\/\/$1\//" /etc/apt/sources.list.d/raspi.list
fi
fi
}
[ "$2" != "" ] && serverip=$2
port=3142
mode="$1"
[ "$mode" == "" ] && mode=client && echo "% 'client' or 'server' not specified; assuming 'client'"
if [ "$mode" == "client" ]
then
enablecacher $serverip:$port # Point the client to the apt caching server
else
echo "% Setting up apt caching server"
echo "% Answer NO to enabling HTTPS tunnels"
sudo apt install -y apt-cacher-ng
enablecacher 127.0.0.1:$port
sudo rm -rf /var/lib/apt/lists
sudo rm -rf /var/cache/apt/*
fi
#
# Resetting the apt-cacher-ng server cache
#
# No need to do it regularly unless disk space or other issues
#
# sudo systemctl stop apt-cacher-ng
# sudo rm -rf /var/cache/apt-cacher-ng
# sudo mkdir -p /var/cache/apt-cacher-ng
# sudo chown -R apt-cacher-ng:apt-cacher-ng /var/cache/apt-cacher-ng
# sudo systemctl start apt-cacher-ng
#