aboutsummarylogtreecommitdiffstats
path: root/proxy.cgi
diff options
context:
space:
mode:
authorGaetan Bisson2016-08-28 06:48:44 -1000
committerGaetan Bisson2016-08-28 06:48:44 -1000
commitaac70d2686759458807fda1185ce4c0835ab69e8 (patch)
treeb826a043d5f164c6f4e8db2ee70cdae823dcd6cc /proxy.cgi
parent906396775aae17567547ac8a6beb37c7d2c019ae (diff)
downloadaur-aac70d2686759458807fda1185ce4c0835ab69e8.tar.gz
upstream update
Diffstat (limited to 'proxy.cgi')
-rwxr-xr-xproxy.cgi25
1 files changed, 17 insertions, 8 deletions
diff --git a/proxy.cgi b/proxy.cgi
index 6ee2e8079b5a..2338201cf429 100755
--- a/proxy.cgi
+++ b/proxy.cgi
@@ -3,23 +3,28 @@
set -e
# This CGI script is a caching Arch Linux mirror proxy: it forwards new package
-# requests to an actual mirror while caching content to /var/cache/pacman/pkg.
+# 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
-read MIR < /etc/pacman.d/mirrorlist
-MIR=${MIR%%\$*}
-MIR=${MIR##*= }
+MIR=$(awk -F '[$=]' '(!/^#/){print$2;exit}' /etc/pacman.d/mirrorlist)
+
+MIR=${MIR# }
-[[ $PATH_INFO = /vesath/* ]] && MIR='http://arch.vesath.org'
+[[ $PATH_INFO = /vesath/* ]] &&
+MIR='http://arch.vesath.org'
PKG=${PATH_INFO##*/}
-[[ $PKG = *.db* ]] && exec curl --silent --include "$MIR$PATH_INFO"
+
+[[ $PKG = *.db* ]] &&
+exec curl --silent --include "${MIR# }$PATH_INFO"
cat <<EOF
Content-Type: application/octet-stream
@@ -27,6 +32,10 @@ Connection: close
EOF
-[[ -e $PKG ]] && exec cat "$PKG"
-curl --silent "$MIR$PATH_INFO" | tee "$PKG.part"
+[[ -s $PKG ]] &&
+exec cat "$PKG"
+
+curl --silent "$MIR$PATH_INFO" |
+tee "$PKG.part"
+
mv "$PKG.part" "$PKG"