Compare commits

..

18 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
8cdba1906f Stop yay from asking so many questions 2026-01-09 23:22:02 +01:00
2984ef9193 Simplify getting dependencies 2026-01-09 23:21:12 +01:00
bb5855fec9 Move system backups to snapper 2026-01-09 23:20:35 +01:00

View File

@@ -1,71 +1,182 @@
#! /bin/sh -
#Full Arch Linux Update Script
# Full Arch Linux Update Script
SNAPSHOT_DIR=/.snapshots
DAYS_TO_KEEP=30
# ---------------- Global variables ----------------
BACKUP_LIMIT=3
MIRRORS_COUNTRY=DE
# Backup system
if which btrfs >/dev/null; then
echo -e '\nCreating backup...' >&2
# ---------------- Print usage ----------------
print_usage() {
echo 'Usage: arch_update [-b N] [-c XX] [-d /path/to/docker/compose/]...
arch_update -h
cur_time=$(date -Is)
cur_time_s=$(date -d $cur_time +%s)
-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
}
for file in $(ls "$SNAPSHOT_DIR"); do
old_time_s=$(date -d $(echo "$file" | sed 's/[[:alpha:]]\+-//') +%s)
if [ $(((cur_time_s - old_time_s) / 86400)) -gt $DAYS_TO_KEEP ]; then
sudo btrfs subvolume delete "$SNAPSHOT_DIR"/"$file"
# ---------------- 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
done
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
sudo btrfs subvolume snapshot / "$SNAPSHOT_DIR"/root-$cur_time
sudo btrfs subvolume snapshot /home "$SNAPSHOT_DIR"/home-$cur_time
fi
# Check dependencies
echo -e '\nInstalling dependencies ...' >&2
! which curl >/dev/null 2>&1 && sudo pacman -Syu curl
! which git >/dev/null 2>&1 && sudo pacman -Syu git
if ! which vim >/dev/null 2>&1; then
sudo pacman -Syu neovim
sudo ln -s /usr/bin/nvim /usr/local/bin/vim
fi
! which rankmirrors >/dev/null 2>&1 && sudo pacman -Syu pacman-contrib
# ---------------- Check dependencies ----------------
if ! which yay >/dev/null 2>&1; then
sudo pacman -Syu
! 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
cd yay
makepkg -cirs
cd ..
rm -fr yay
cd
fi
! which yaycache >/dev/null 2>&1 && yay -Syu yaycache
# Update mirrors
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
# ---------------- 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
[ ! -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
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
yay -Syu
yay -Syu --noconfirm
# Remove orphans
echo -e '\nRemoving orphans ...' >&2
# ---------------- Remove orphans ----------------
orphans=$(yay -Qtdq)
[ ! "X$orphans" = 'X' ] && yay -Rns $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
sudo paccache -r
yaycache -r
# Update flatpaks
echo -e '\nUpdating flatpaks ...' >&2
which flatpak >/dev/null 2>&1 && flatpak update
# Find new configs
# ---------------- 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
# ---------------- 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.'