Compare commits

..

3 Commits

View File

@@ -1,45 +1,31 @@
#! /bin/sh -
#Full Arch Linux Update Script
#!/bin/sh
# Full Arch Linux Update Script
SNAPSHOT_DIR=/.snapshots
DAYS_TO_KEEP=30
set -e
# 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
BACKUP_LIMIT=3
# 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
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
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
@@ -47,12 +33,12 @@ curl -s 'https://archlinux.org/mirrorlist/?country=DE&protocol=https&use_mirror_
# Update system
echo -e '\nUpdating system ...' >&2
yay -Syu
yay -Syu --noconfirm
# Remove orphans
echo -e '\nRemoving orphans ...' >&2
orphans=$(yay -Qtdq)
[ ! "X$orphans" = 'X' ] && yay -Rns $orphans
[ ! "X$orphans" = 'X' ] && yay -Rns --noconfirm $orphans
# Clean cache
echo -e '\nCleaning cache ...' >&2