Files
arch_update/arch_update
2026-01-31 08:49:30 +01:00

81 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
# Full Arch Linux Update Script
BACKUP_LIMIT=3
# Check dependencies
echo -e '\nInstalling dependencies ...' >&2
if ! which yay >/dev/null 2>&1; then
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -cirs
cd ..
rm -fr yay
fi
yay -S --needed --noconfirm curl git neovim pacman-contrib yaycache
[ ! -e /usr/local/bin/vim ] && sudo ln -s /usr/bin/nvim /usr/local/bin/vim
# Display updates beforehand
echo -e '\nChecking for updates ...' >&2
checkupdates
yay -Qua
# Ask to proceed
while true; do
echo -e '\nDo you want to start the update? Y/n' >&2
read -r answer || exit 1
case $answer in
'' | [yY])
break
;;
[nN])
exit 0
;;
*)
echo -e 'Answer with y or n.' >&2
;;
esac
done
# Backup system
if which btrfs >/dev/null 2>&1; then
yay -S --needed --noconfirm snapper
[ ! -f /etc/snapper/configs/root ] && sudo snapper -c root create-config /
[ ! $(sudo awk -F '"' '/NUMBER_LIMIT=/ {print $2}' /etc/snapper/configs/root) -eq $BACKUP_LIMIT ] && sudo sed -i.bak "s/\(NUMBER_LIMIT=\"\).*\"/\1$BACKUP_LIMIT\"/" /etc/snapper/configs/root
echo -e '\nCreating backup...' >&2
sudo snapper -c root create -c number
fi
# Update mirrors
echo -e '\nUpdating mirrors ...' >&2
curl -s 'https://archlinux.org/mirrorlist/?country=DE&protocol=https&use_mirror_status=on' | sed -e 's/^#\(Server\)/\1/' -e '/^#/d' | rankmirrors - | sudo tee /etc/pacman.d/mirrorlist
# Update system
echo -e '\nUpdating system ...' >&2
yay -Syu --noconfirm
# Remove orphans
echo -e '\nRemoving orphans ...' >&2
orphans=$(yay -Qtdq)
[ ! "X$orphans" = 'X' ] && yay -Rns --noconfirm $orphans
# Clean cache
echo -e '\nCleaning cache ...' >&2
sudo paccache -r
yaycache -r
# Update flatpaks
if which flatpak >/dev/null 2>&1; then
echo -e '\nUpdating flatpaks ...' >&2
flatpak update
fi
# Find new configs
echo -e '\nSearching for new configs ...' >&2
[ -f /etc/pacman.d/mirrorlist.pacnew ] && sudo rm /etc/pacman.d/mirrorlist.pacnew
sudo pacdiff
echo -e '\nIt is recommended to restart the system.'