Compare commits
18 Commits
12e9698024
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| cac0699f82 | |||
| 1c54ed9ebd | |||
| 43de006a49 | |||
| 7f1c2eaec5 | |||
| ac4fe4cc1c | |||
| a9f5300ade | |||
| 59b1b711ac | |||
| 32c44d84d8 | |||
| 8209fcbf1b | |||
| 3d81515a7e | |||
| 3424fbc3ac | |||
| 6b34c42f41 | |||
| 94b836f96e | |||
| ee1f0a22ee | |||
| 54b4b44b7a | |||
| 8cdba1906f | |||
| 2984ef9193 | |||
| bb5855fec9 |
193
arch_update
193
arch_update
@@ -1,71 +1,182 @@
|
|||||||
#! /bin/sh -
|
#! /bin/sh -
|
||||||
#Full Arch Linux Update Script
|
# Full Arch Linux Update Script
|
||||||
|
|
||||||
SNAPSHOT_DIR=/.snapshots
|
# ---------------- Global variables ----------------
|
||||||
DAYS_TO_KEEP=30
|
BACKUP_LIMIT=3
|
||||||
|
MIRRORS_COUNTRY=DE
|
||||||
|
|
||||||
# Backup system
|
# ---------------- Print usage ----------------
|
||||||
if which btrfs >/dev/null; then
|
print_usage() {
|
||||||
echo -e '\nCreating backup...' >&2
|
echo 'Usage: arch_update [-b N] [-c XX] [-d /path/to/docker/compose/]...
|
||||||
|
arch_update -h
|
||||||
|
|
||||||
cur_time=$(date -Is)
|
-b N Keep N system backups
|
||||||
cur_time_s=$(date -d $cur_time +%s)
|
-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
|
# ---------------- Handle cli arguments ----------------
|
||||||
old_time_s=$(date -d $(echo "$file" | sed 's/[[:alpha:]]\+-//') +%s)
|
backup_limit=$BACKUP_LIMIT
|
||||||
if [ $(((cur_time_s - old_time_s) / 86400)) -gt $DAYS_TO_KEEP ]; then
|
docker_composes=
|
||||||
sudo btrfs subvolume delete "$SNAPSHOT_DIR"/"$file"
|
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
|
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
|
# ---------------- Check dependencies ----------------
|
||||||
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
|
|
||||||
if ! which yay >/dev/null 2>&1; then
|
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
|
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
|
||||||
! 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
|
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
|
yay -Syu --noconfirm
|
||||||
|
|
||||||
# Remove orphans
|
# ---------------- Remove orphans ----------------
|
||||||
echo -e '\nRemoving orphans ...' >&2
|
|
||||||
orphans=$(yay -Qtdq)
|
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
|
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.'
|
||||||
|
|||||||
Reference in New Issue
Block a user