about summary refs log tree commit diff stats
path: root/pkgs/by-name/fu/fupdate-sys/update-sys.sh
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-14 11:56:32 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-14 11:56:32 +0200
commitcf94ffb40e6afbeeea4b3737faf3eaef972d869f (patch)
treebe3f8f6cd0db965a738b4e7e0a3632521a3221f8 /pkgs/by-name/fu/fupdate-sys/update-sys.sh
parentpkgs/stamp: Migrate to `writeShellApplication` (diff)
downloadnixos-config-cf94ffb40e6afbeeea4b3737faf3eaef972d869f.zip
pkgs/update-sys: Migrate to `writeShellApplication` and rename to fupdate-sys
Diffstat (limited to '')
-rwxr-xr-xpkgs/by-name/fu/fupdate-sys/update-sys.sh (renamed from pkgs/by-name/up/update-sys/update-sys.sh)82
1 files changed, 79 insertions, 3 deletions
diff --git a/pkgs/by-name/up/update-sys/update-sys.sh b/pkgs/by-name/fu/fupdate-sys/update-sys.sh
index d28247f6..38debf44 100755
--- a/pkgs/by-name/up/update-sys/update-sys.sh
+++ b/pkgs/by-name/fu/fupdate-sys/update-sys.sh
@@ -1,8 +1,78 @@
 #!/usr/bin/env dash
 
-# shellcheck source=/dev/null
-SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH
+# FIXME(@bpeetz): Ideally I could replace this script with a deployment tool. Thus we
+# would have the same tool on the server as I use in my config. <2025-04-14>
 
+# Shell library {{{
+die() {
+    error "$1"
+    if [ -n "$2" ]; then
+        exit "$2"
+    else
+        exit 1
+    fi
+}
+print() {
+    printf "%s" "$*"
+}
+println() {
+    printf "%s\n" "$*"
+}
+eprint() {
+    >&2 print "$@"
+}
+eprintln() {
+    >&2 println "$@"
+}
+if [ -n "$NO_COLOR" ]; then
+    error() {
+        eprintln "==> ERROR:" "$*"
+    }
+    warning() {
+        eprintln "==> WARNING:" "$*"
+    }
+    debug() {
+        [ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln "==> [Debug:]" "$*"
+    }
+    debug2() {
+        [ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln " -> [Debug:]" "$*"
+    }
+    msg() {
+        eprintln "==>" "$*"
+    }
+    msg2() {
+        eprintln " ->" "$*"
+    }
+    prompt() {
+        eprint "..>" "$*"
+    }
+else
+    error() {
+        eprintln "\033[1;91m==> ERROR:\033[0m" "\033[1;93m$*\033[0m"
+    }
+    warning() {
+        eprintln "\033[1;91m==> WARNING:\033[0m" "\033[1;93m$*\033[0m"
+    }
+    debug() {
+        [ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln "\033[1;94m==> [Debug:]\033[0m" "\033[1;93m$*\033[0m"
+    }
+    debug2() {
+        [ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln "\033[1;94m -> [Debug:]\033[0m" "\033[1;93m$*\033[0m"
+    }
+    msg() {
+        eprintln "\033[1;96m==>\033[0m" "\033[1;93m$*\033[0m"
+    }
+    msg2() {
+        eprintln "\033[1;96m ->\033[0m" "\033[1;93m$*\033[0m"
+    }
+    prompt() {
+        eprint "\033[1;96m..>\033[0m" "\033[1;93m$*\033[0m"
+    }
+fi
+# }}}
+
+
+NAME="update-sys"
 help() {
     cat <<EOF
 This is a NixOS System flake update manager.
@@ -28,7 +98,6 @@ ARGUMENTS:
 EOF
     exit "$1"
 }
-default_branch=$(mktmp)
 BRANCH=""
 
 while [ "$#" -gt 0 ]; do
@@ -70,6 +139,13 @@ fi
 msg2 "Updating git repository..."
 git pull --rebase
 
+# We use a tempfile, to make this truly async.
+default_branch=$(mktemp)
+cleanup() {
+    rm "$default_branch"
+}
+trap cleanup EXIT
+
 git remote show origin | grep 'HEAD' | cut -d':' -f2 | sed -e 's/^ *//g' -e 's/ *$//g' >"$default_branch" &
 
 msg2 "Updating system..."