blob: 6847224f51ba4aed1068aa24b6cfab32bff6df75 (
plain)
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
|
#!/usr/bin/bash
set -e
# This CGI script is a caching Arch Linux mirror proxy: it forwards new package
# requests to an actual mirror while caching contents to /var/cache/pacman/pkg.
# Use in pacman.conf with:
#
# Server = http://server/path/to/proxy.cgi/$repo/os/$arch/
[[ $REMOTE_ADDR = 127.0.0.1 ]]
cd /var/cache/pacman/pkg
touch used-by-proxy
MIR=$(awk -F '[$=]' '(!/^#/){print$2;exit}' /etc/pacman.d/mirrorlist)
MIR=${MIR# }
MIR=${MIR%/}
PKG=${PATH_INFO##*/}
if [[ $PATH_INFO = /vesath/* ]]; then
MIR='http://arch.vesath.org/'
PATH_INFO=${PATH_INFO#/vesath/os/}
fi
[[ $PKG = *.db* ]] &&
exec curl --silent --include "$MIR$PATH_INFO"
cat <<EOF
Content-Type: application/octet-stream
Connection: close
EOF
[[ -s $PKG ]] &&
exec cat "$PKG"
curl --silent "$MIR$PATH_INFO" |
tee "$PKG.part"
mv "$PKG.part" "$PKG"
|