Skip to content

Instantly share code, notes, and snippets.

@cbiffle
Last active February 26, 2022 17:35
Show Gist options
  • Save cbiffle/eb4eda8958e4bfe240c0 to your computer and use it in GitHub Desktop.
Save cbiffle/eb4eda8958e4bfe240c0 to your computer and use it in GitHub Desktop.
Download old package on old Arch Linux install

Arch Linux is a rolling-release system that expects users to update regularly.

This can be a problem if you find yourself in possession of an older Arch Linux machine that hasn't been kept up to date. In particular, if you'd like to back up the contents of the system and reinstall, you may want certain tools available to do it (in my case it was pigz).

However, if they tools aren't already installed, you're out of luck: Arch's package repositories store only very recent versions of every package.

For emergencies like this, I've written the attached script, which automates package fetching from the Arch Linux Archive.

It's a good idea to keep your system up to date. Sometimes, a package is revved for a good reason, such as a serious security flaw, or a package builder compromise. So in general you don't want to do this.

However, this script does avoid the main risk in installing old versions of packages: since it queries the version in the locally sync'd Pacman database, you will at least install a package version that is consistent with the rest of your (ancient, out of date, insecure) operating system.

And, of course, Pacman will verify that the signature on the package is legit, in terms of your (ancient, out of date) Pacman keyring.

[cbiffle@metis ~]$ wget
-bash: wget: command not found
[cbiffle@metis ~]$ sudo pacman -S wget
[sudo] password for cbiffle:
resolving dependencies...
looking for conflicting packages...
Packages (1) wget-1.16.1-1
Total Download Size: 0.43 MiB
Total Installed Size: 1.99 MiB
:: Proceed with installation? [Y/n] y
:: Retrieving packages ...
error: failed retrieving file 'wget-1.16.1-1-x86_64.pkg.tar.xz' from mirrors.cat.pdx.edu : The requested URL returned error: 404
error: failed retrieving file 'wget-1.16.1-1-x86_64.pkg.tar.xz' from mirrors.kernel.org : The requested URL returned error: 404
error: failed retrieving file 'wget-1.16.1-1-x86_64.pkg.tar.xz' from ftp.osuosl.org : The requested URL returned error: 404
error: failed retrieving file 'wget-1.16.1-1-x86_64.pkg.tar.xz' from mirrors.xmission.com : The requested URL returned error: 404
warning: failed to retrieve some files
error: failed to commit transaction (unexpected error)
Errors occurred, no packages were upgraded.
[cbiffle@metis ~]$ ./retro.sh wget
resurrecting wget 1.16.1-1 x86_64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 435k 100 435k 0 0 390k 0 0:00:01 0:00:01 --:--:-- 391k
[cbiffle@metis ~]$ sudo pacman -S wget
resolving dependencies...
looking for conflicting packages...
Packages (1) wget-1.16.1-1
Total Installed Size: 1.99 MiB
:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring [######################] 100%
(1/1) checking package integrity [######################] 100%
(1/1) loading package files [######################] 100%
(1/1) checking for file conflicts [######################] 100%
(1/1) checking available disk space [######################] 100%
(1/1) installing wget [######################] 100%
Optional dependencies for wget
ca-certificates: HTTPS downloads [installed]
#!/bin/sh
set -e -u
TMP="$(mktemp --directory --tmpdir=/var/tmp)"
for PKGNAME in "$@"; do
VERSION="$(pacman -Si "${PKGNAME}" | grep ^Version | awk '{print $3}')"
ARCH="$(pacman -Si "${PKGNAME}" | grep ^Architecture | awk '{print $3}')"
PKG="${PKGNAME}-${VERSION}-${ARCH}.pkg.tar.xz"
CACHE="/var/cache/pacman/pkg/${PKG}"
if [ -e "${CACHE}" ]; then
echo "package already in cache: ${PKGNAME} ${VERSION} ${ARCH}"
continue
fi
echo "resurrecting ${PKGNAME} ${VERSION} ${ARCH}"
FIRST="$(echo "${PKGNAME}" | sed 's/\(.\).*/\1/g')"
URL="http://ala.seblu.net/packages/${FIRST}/${PKGNAME}/${PKG}"
curl -o "${TMP}/${PKG}" "${URL}"
sudo mv -n "${TMP}/${PKG}" "/var/cache/pacman/pkg/${PKG}"
done
rm -rf "${TMP}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment