First well working version

This commit is contained in:
Jason Streifling 2024-09-20 20:59:12 +02:00
parent 889dc2c3b6
commit 7ef7097fa0

62
arch_update Executable file
View File

@ -0,0 +1,62 @@
#! /bin/sh -
#Full Arch Linux Update Script
SNAPSHOT_DIR=/.snapshots
DAYS_TO_KEEP=90
# Backup system
if which btrfs >/dev/null; then
echo -e '\nCreating backup...' >&2
cur_time=$(date -Is)
cur_time_s=$(date -d $cur_time +%s)
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"
fi
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
! which rankmirrors >/dev/null 2>&1 && sudo pacman -Syu pacman-contrib
if ! which yay >/dev/null 2>&1; then
sudo pacman -Syu
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -cirs
cd ..
rm -fr yay
fi
! which yaycache >/dev/null 2>&1 && yay -Syu yaycache
# 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
# Remove orphans
echo -e '\nRemoving orphans ...' >&2
orphans=$(yay -Qtdq)
[ ! "X$orphans" = 'X' ] && yay -Rns $orphans
# Clean cache
echo -e '\nCleaning cache ...' >&2
sudo paccache -r
yaycache -r
# Find new configs
echo -e '\nSearching for new configs ...' >&2
sudo pacdiff
echo -e '\nIt is recommended to restart the system.'