about summary refs log tree commit diff stats
path: root/pkgs/update_pkgs.sh
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-24 18:21:04 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-24 18:21:04 +0200
commitd1f6e8fa73623feda4ef0f232fe65c59d3437378 (patch)
treece06c31cbfe351e1ca77a989c9ec34a703ed298f /pkgs/update_pkgs.sh
parentfeat(pkgs/update.sh): Notify the user about the run update scripts (diff)
downloadnixos-config-d1f6e8fa73623feda4ef0f232fe65c59d3437378.tar.gz
nixos-config-d1f6e8fa73623feda4ef0f232fe65c59d3437378.zip
fix(update.sh): Use more descriptive names for the toplevel update.sh scripts
Diffstat (limited to 'pkgs/update_pkgs.sh')
-rwxr-xr-xpkgs/update_pkgs.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkgs/update_pkgs.sh b/pkgs/update_pkgs.sh
new file mode 100755
index 00000000..0a8c4cfc
--- /dev/null
+++ b/pkgs/update_pkgs.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env sh
+
+die() {
+    printf "\033[31;1mError: \033[0m%s\n" "$1"
+    exit 1
+}
+
+cd "$(dirname "$0")" || die "Bug: run with the wrong first arg: '$0'!"
+cd ./by-name || die "(BUG): The directory './by-name' does not exist?"
+
+# First check if all the update scripts conform to the standard
+files_with_update="$(mktemp)";
+trap 'rm "$files_with_update"' EXIT
+
+fd '^update.sh$' . --type file --extension sh --max-depth 3 | while read -r file; do
+    grep -q "nix flake update" "$file" && echo "$file" >> "$files_with_update"
+done
+
+if [ "$(wc -l < "$files_with_update")" != 0 ]; then
+    die "Some packages seem to try to update their flake with 'nix flake update'. This is redundant. These Packages are: $(echo && cat "$files_with_update")"
+fi
+
+# Than actually perform the update
+fd . --type directory --max-depth 1 | while read -r shard; do
+    cd "$shard" || die "(BUG): Shard '$shard' does not exist?"
+
+    fd . --type directory --max-depth 1 | while read -r package; do
+        cd "$package" || die "(BUG): Package '$package' does not exist?"
+
+        if [ -x update.sh ]; then
+            printf "  \033[34;1m> \033[0m\033[34;1m%s\033[0m\n" "Running '${shard}${package}update.sh' .."
+
+            [ -f flake.nix ] && nix flake update
+
+            direnv allow
+            eval "$(direnv export bash 2>/dev/null)"
+            ./update.sh "$@"
+        fi
+        cd - >/dev/null || die "Bug: Last dir does not exist"
+    done
+    cd - >/dev/null || die "Bug: Last dir does not exist"
+done
+
+# vim: ft=sh