Compare commits

...

15 Commits

Author SHA1 Message Date
cac0699f82 Docker compose needs sudo 2026-02-27 23:30:46 +01:00
1c54ed9ebd add --needed flag for second attempt at installing dependencies 2026-02-22 08:32:11 +01:00
43de006a49 Small bug fixes 2026-02-22 08:29:36 +01:00
7f1c2eaec5 Small readability fix 2026-02-22 08:18:25 +01:00
ac4fe4cc1c Add cli argument handling and docker compose support 2026-02-22 08:12:40 +01:00
a9f5300ade Move searching for new configs before flatpaks 2026-02-22 08:11:52 +01:00
59b1b711ac Use dependencies variable to clean up output, also make installing dependencies more reliable by updating the package list if the installation fails the first time 2026-02-22 08:10:34 +01:00
32c44d84d8 Change comments to include some dashes for better readability 2026-02-22 08:06:51 +01:00
8209fcbf1b Change shebang to include a dash at the end to indicate there are no more cli arguments 2026-02-22 08:03:53 +01:00
3d81515a7e Small cleanup 2026-01-31 08:49:30 +01:00
3424fbc3ac Ask the user whether they want to proceed 2026-01-24 20:23:18 +01:00
6b34c42f41 Display updates before the process starts 2026-01-24 20:22:59 +01:00
94b836f96e Remove probably unnecessary "set -e" 2026-01-24 09:45:39 +01:00
ee1f0a22ee Only display flatpak message if it is installed 2026-01-24 09:26:19 +01:00
54b4b44b7a Actually do the update at the point is is supposed to be done 2026-01-16 05:53:04 +01:00

View File

@@ -1,57 +1,182 @@
#!/bin/sh #! /bin/sh -
# Full Arch Linux Update Script # Full Arch Linux Update Script
set -e # ---------------- Global variables ----------------
BACKUP_LIMIT=3 BACKUP_LIMIT=3
MIRRORS_COUNTRY=DE
# Check dependencies # ---------------- Print usage ----------------
echo -e '\nInstalling dependencies ...' >&2 print_usage() {
echo 'Usage: arch_update [-b N] [-c XX] [-d /path/to/docker/compose/]...
arch_update -h
-b N Keep N system backups
-c XX Set the country code for the pacman mirrorlist
-d /path/to/docker/compose/ Path to a docker compose.yml file, NOT the file itself
-h Display this usage page and exit' >&2
}
# ---------------- Handle cli arguments ----------------
backup_limit=$BACKUP_LIMIT
docker_composes=
mirrors_country=$MIRRORS_COUNTRY
while [ $# -gt 0 ]; do
case $1 in
-b)
if [ $2 -gt -1 ]; then
backup_limit=$2
else
print_usage
exit 1
fi
shift 2
;;
-c)
mirrors_country=$2
shift 2
;;
-d)
if ls $2 2>/dev/null | grep -F compose.yml >/dev/null; then
docker_composes="$docker_composes $2"
else
print_usage
exit 1
fi
shift 2
;;
-h)
print_usage
exit
;;
*)
print_usage
exit 1
;;
esac
done
# ---------------- Check dependencies ----------------
if ! which yay >/dev/null 2>&1; then if ! which yay >/dev/null 2>&1; then
! which git >/dev/null 2>&1 &&
if ! sudo pacman -S --noconfirm git; then
if sudo pacman -Syu; then
sudo pacman -S --noconfirm git
else
echo -e '\nUnable to fetch package list. Aborting ...' >&2
exit 1
fi
fi
cd /tmp
git clone https://aur.archlinux.org/yay.git git clone https://aur.archlinux.org/yay.git
cd yay cd yay
makepkg -cirs makepkg -cirs
cd .. cd ..
rm -fr yay rm -fr yay
cd
fi fi
yay -Syu --needed --noconfirm curl git neovim pacman-contrib yaycache
dependencies=
! which curl >/dev/null 2>&1 && dependencies="$dependencies curl"
[ ! "X$docker_composes" = 'X' ] && ! docker compose >/dev/null 2>&1 && dependencies="$dependencies docker docker-compose"
! which git >/dev/null 2>&1 && dependencies="$dependencies git"
! which nvim >/dev/null 2>&1 && dependencies="$dependencies neovim"
! which paccache >/dev/null 2>&1 && dependencies="$dependencies pacman-contrib"
which btrfs >/dev/null 2>&1 && ! which snapper >/dev/null 2>&1 && dependencies="$dependencies snapper"
! which yaycache >/dev/null 2>&1 && dependencies="$dependencies yaycache"
if [ ! "X$dependencies" = 'X' ]; then
echo -e '\nInstalling dependencies ...' >&2
if ! yay -S --needed --noconfirm $dependencies; then
if yay -Syu; then
yay -S --needed --noconfirm $dependencies
else
echo -e '\nUnable to fetch package list. Aborting ...' >&2
exit 1
fi
fi
fi
[ ! -e /usr/local/bin/vim ] && sudo ln -s /usr/bin/nvim /usr/local/bin/vim [ ! -e /usr/local/bin/vim ] && sudo ln -s /usr/bin/nvim /usr/local/bin/vim
# Backup system # ---------------- Display updates beforehand ----------------
if which btrfs >/dev/null; then echo -e '\nChecking for updates ...' >&2
yay -Syu --needed --noconfirm snapper 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
[ ! -f /etc/snapper/configs/root ] && sudo snapper -c root create-config / [ ! -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 [ ! $(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 echo -e '\nCreating backup...' >&2
sudo snapper -c root create -c number sudo snapper -c root create -c number
fi fi
# Update mirrors # ---------------- Update mirrors ----------------
echo -e '\nUpdating mirrors ...' >&2 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 curl -s "https://archlinux.org/mirrorlist/?country=$mirrors_country&protocol=https&use_mirror_status=on" |
sed -e 's/^#\(Server\)/\1/' -e '/^#/d' |
rankmirrors - |
sudo tee /etc/pacman.d/mirrorlist
# Update system # ---------------- Update system ----------------
echo -e '\nUpdating system ...' >&2 echo -e '\nUpdating system ...' >&2
yay -Syu --noconfirm yay -Syu --noconfirm
# Remove orphans # ---------------- Remove orphans ----------------
echo -e '\nRemoving orphans ...' >&2
orphans=$(yay -Qtdq) orphans=$(yay -Qtdq)
[ ! "X$orphans" = 'X' ] && yay -Rns --noconfirm $orphans if [ ! "X$orphans" = 'X' ]; then
echo -e '\nRemoving orphans ...' >&2
yay -Rns --noconfirm $orphans
fi
# Clean cache # ---------------- Clean cache ----------------
echo -e '\nCleaning cache ...' >&2 echo -e '\nCleaning cache ...' >&2
sudo paccache -r sudo paccache -r
yaycache -r yaycache -r
# Update flatpaks # ---------------- Find new configs ----------------
echo -e '\nUpdating flatpaks ...' >&2
which flatpak >/dev/null 2>&1 && flatpak update
# Find new configs
echo -e '\nSearching for new configs ...' >&2 echo -e '\nSearching for new configs ...' >&2
[ -f /etc/pacman.d/mirrorlist.pacnew ] && sudo rm /etc/pacman.d/mirrorlist.pacnew [ -f /etc/pacman.d/mirrorlist.pacnew ] && sudo rm /etc/pacman.d/mirrorlist.pacnew
sudo pacdiff sudo pacdiff
# ---------------- Update flatpaks ----------------
if which flatpak >/dev/null 2>&1; then
echo -e '\nUpdating flatpaks ...' >&2
flatpak update
fi
# ---------------- Update docker composes ----------------
if sudo docker compose >/dev/null 2>&1; then
echo -e '\nUpdating docker composes ...' >&2
for dir in $docker_composes; do
cd $dir
sudo docker compose pull
sudo docker compose up -d
done
fi
# ---------------- The end ----------------
echo -e '\nIt is recommended to restart the system.' echo -e '\nIt is recommended to restart the system.'