Compare commits
12 Commits
94b836f96e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| cac0699f82 | |||
| 1c54ed9ebd | |||
| 43de006a49 | |||
| 7f1c2eaec5 | |||
| ac4fe4cc1c | |||
| a9f5300ade | |||
| 59b1b711ac | |||
| 32c44d84d8 | |||
| 8209fcbf1b | |||
| 3d81515a7e | |||
| 3424fbc3ac | |||
| 6b34c42f41 |
163
arch_update
163
arch_update
@@ -1,57 +1,182 @@
|
||||
#!/bin/sh
|
||||
#! /bin/sh -
|
||||
# Full Arch Linux Update Script
|
||||
|
||||
# ---------------- Global variables ----------------
|
||||
BACKUP_LIMIT=3
|
||||
MIRRORS_COUNTRY=DE
|
||||
|
||||
# Check dependencies
|
||||
echo -e '\nInstalling dependencies ...' >&2
|
||||
# ---------------- Print usage ----------------
|
||||
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
|
||||
! 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
|
||||
yay -S --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
|
||||
|
||||
# Backup system
|
||||
# ---------------- 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
|
||||
yay -S --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
|
||||
[ ! $(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
|
||||
# ---------------- 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 --noconfirm
|
||||
|
||||
# Remove orphans
|
||||
echo -e '\nRemoving orphans ...' >&2
|
||||
# ---------------- Remove orphans ----------------
|
||||
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
|
||||
sudo paccache -r
|
||||
yaycache -r
|
||||
|
||||
# Update flatpaks
|
||||
# ---------------- 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
|
||||
|
||||
# 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 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.'
|
||||
|
||||
Reference in New Issue
Block a user