Skip to content

Instantly share code, notes, and snippets.

@Alistair1231
Last active February 7, 2025 22:21
Show Gist options
  • Save Alistair1231/dfe1d2a77fae473d86f956084844071d to your computer and use it in GitHub Desktop.
Save Alistair1231/dfe1d2a77fae473d86f956084844071d to your computer and use it in GitHub Desktop.
arch linux revive pacman on old installs
# This one-liner revives an old Arch Linux install where `pacman -Syu` is not working by:
# 1. Updating mirror list for DE, AT, CH sorted by rate - ensures access to active and fast mirrors.
# 2. Downloading and running static pacman, initializing and populating pacman keyring - re-establishes basic package management capabilities.
# 3. Updating archlinux-keyring and pacman-contrib - ensures keyring and essential tools are up-to-date.
# 4. Reranking mirror list with the top 5 fastest servers - this is why we needed pacman-contrib.
# 5. Running `sudo pacman -Syu --noconfirm` - brings the system to the latest package versions.
curl -s "https://archlinux.org/mirrorlist/?country=DE&country=AT&country=CH&protocol=https&use_mirror_status=on&sort=rate" | sed -e 's/^#Server/Server/' -e '/^#/d' | sudo tee /etc/pacman.d/mirrorlist && \
curl -L https://pkgbuild.com/~morganamilo/pacman-static/x86_64/bin/pacman-static -o /tmp/pacman-static && \
chmod +x /tmp/pacman-static && \
sudo pacman-key --init && \
sudo pacman-key --populate archlinux && \
sudo /tmp/pacman-static -Sy archlinux-keyring pacman-contrib --noconfirm && \
curl -s "https://archlinux.org/mirrorlist/?country=DE&country=AT&country=CH&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 5 - | sudo tee /etc/pacman.d/mirrorlist && \
sudo pacman -Syu --noconfirm
#! add chaotic-aur so you don't usually need to build stuff from the AUR yourself
curl -L 'https://github.com/chaotic-aur/.github/raw/refs/heads/main/profile/README.md' -o /tmp/chaotic_README.md && \
# keys and mirrorlist
cat /tmp/chaotic_README.md | grep -Po '(?<= - `# )pacm.*(?=`)' | tee /tmp/chaotic.sh && \
sed -i -E \
-e 's/^(pacman-key --recv-key )/sudo \1/' \
-e 's/^(pacman-key --lsign-key )/sudo \1/' \
-e 's/^(pacman -U )/sudo \1/' \
-e 's/^(sudo pacman -U )/& --noconfirm /' \
/tmp/chaotic.sh && \
sudo bash /tmp/chaotic.sh && \
# Append to repo to pacman.conf
cat /tmp/chaotic_README.md | grep -Pzo '(?<= - `)[\[I].*(?=`)' | tr '\0' '\n' | sudo tee -a /etc/pacman.conf && \
sudo pacman -Syu --noconfirm paru yay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment