Files
arch_update/arch_update

58 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# Full Arch Linux Update Script
set -e
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 -Syu --needed --noconfirm curl git neovim pacman-contrib yaycache
[ ! -e /usr/local/bin/vim ] && sudo ln -s /usr/bin/nvim /usr/local/bin/vim
# Backup system
if which btrfs >/dev/null; then
yay -Syu --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
echo -e '\nUpdating flatpaks ...' >&2
which flatpak >/dev/null 2>&1 && flatpak update
# 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.'