From ac4fe4cc1c3ca2c6e1cb7a8dd771fb5d3fb13edf Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sun, 22 Feb 2026 08:12:40 +0100 Subject: [PATCH] Add cli argument handling and docker compose support --- arch_update | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/arch_update b/arch_update index f8e1fad..7570eb1 100755 --- a/arch_update +++ b/arch_update @@ -1,7 +1,61 @@ #! /bin/sh - # Full Arch Linux Update Script +# ---------------- Global variables ---------------- 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 ---------------- echo -e '\nInstalling dependencies ...' >&2 @@ -27,6 +81,7 @@ fi dependencies= ! 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 neovim >/dev/null 2>&1 && dependencies="$dependencies neovim" ! which pacman-contrib >/dev/null 2>&1 && dependencies="$dependencies pacman-contrib" @@ -71,7 +126,8 @@ 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 + [ ! $(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 @@ -79,7 +135,10 @@ fi # ---------------- 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 ---------------- echo -e '\nUpdating system ...' >&2 @@ -106,5 +165,14 @@ if which flatpak >/dev/null 2>&1; then flatpak update 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.'