Add cli argument handling and docker compose support
This commit is contained in:
72
arch_update
72
arch_update
@@ -1,7 +1,61 @@
|
|||||||
#! /bin/sh -
|
#! /bin/sh -
|
||||||
# Full Arch Linux Update Script
|
# Full Arch Linux Update Script
|
||||||
|
|
||||||
|
# ---------------- Global variables ----------------
|
||||||
BACKUP_LIMIT=3
|
BACKUP_LIMIT=3
|
||||||
|
MIRRORS_COUNTRY=DE
|
||||||
|
|
||||||
|
# ---------------- 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
|
||||||
|
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
|
||||||
|
composes="$composes $2"
|
||||||
|
else
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-h)
|
||||||
|
print_usage
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
# ---------------- Check dependencies ----------------
|
# ---------------- Check dependencies ----------------
|
||||||
echo -e '\nInstalling dependencies ...' >&2
|
echo -e '\nInstalling dependencies ...' >&2
|
||||||
@@ -27,6 +81,7 @@ fi
|
|||||||
|
|
||||||
dependencies=
|
dependencies=
|
||||||
! which curl >/dev/null 2>&1 && dependencies="$dependencies curl"
|
! which curl >/dev/null 2>&1 && dependencies="$dependencies curl"
|
||||||
|
[ ! "X$composes" = 'X' ] && ! docker compose >/dev/null 2>&1 && dependencies="$dependencies docker docker-compose"
|
||||||
! which git >/dev/null 2>&1 && dependencies="$dependencies git"
|
! which git >/dev/null 2>&1 && dependencies="$dependencies git"
|
||||||
! which neovim >/dev/null 2>&1 && dependencies="$dependencies neovim"
|
! which neovim >/dev/null 2>&1 && dependencies="$dependencies neovim"
|
||||||
! which pacman-contrib >/dev/null 2>&1 && dependencies="$dependencies pacman-contrib"
|
! which pacman-contrib >/dev/null 2>&1 && dependencies="$dependencies pacman-contrib"
|
||||||
@@ -71,7 +126,8 @@ done
|
|||||||
# ---------------- Backup system ----------------
|
# ---------------- Backup system ----------------
|
||||||
if which btrfs >/dev/null 2>&1; then
|
if which btrfs >/dev/null 2>&1; then
|
||||||
[ ! -f /etc/snapper/configs/root ] && sudo snapper -c root create-config /
|
[ ! -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
|
echo -e '\nCreating backup...' >&2
|
||||||
sudo snapper -c root create -c number
|
sudo snapper -c root create -c number
|
||||||
@@ -79,7 +135,10 @@ fi
|
|||||||
|
|
||||||
# ---------------- Update mirrors ----------------
|
# ---------------- 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
|
||||||
@@ -106,5 +165,14 @@ if which flatpak >/dev/null 2>&1; then
|
|||||||
flatpak update
|
flatpak update
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ---------------- Update docker composes ----------------
|
||||||
|
if docker compose >/dev/null 2>&1; then
|
||||||
|
for dir in $composes; do
|
||||||
|
cd $dir
|
||||||
|
docker compose pull
|
||||||
|
docker compose up -d
|
||||||
|
done
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
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