From d1f6e8fa73623feda4ef0f232fe65c59d3437378 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 24 May 2024 18:21:04 +0200 Subject: fix(update.sh): Use more descriptive names for the toplevel update.sh scripts --- modules/system/secrets/update.sh | 37 --------------------------- modules/system/secrets/update_secrets.sh | 37 +++++++++++++++++++++++++++ pkgs/update.sh | 44 -------------------------------- pkgs/update_pkgs.sh | 44 ++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 81 deletions(-) delete mode 100755 modules/system/secrets/update.sh create mode 100755 modules/system/secrets/update_secrets.sh delete mode 100755 pkgs/update.sh create mode 100755 pkgs/update_pkgs.sh diff --git a/modules/system/secrets/update.sh b/modules/system/secrets/update.sh deleted file mode 100755 index edc4ae8a..00000000 --- a/modules/system/secrets/update.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env nix -#! nix shell nixpkgs#age nixpkgs#jq nixpkgs#dash --command dash -# shellcheck shell=dash - -cleanup() { - [ "$key_file" ] && rm "$key_file" -} -trap cleanup EXIT - -update_lf_cd_paths() { - echo "Starting to update the lf/cd_paths file.." - - cd "$(git rev-parse --show-toplevel)/sys/secrets" || { - echo "A secrets dir does not exist! (This is most likely a bug)" - exit 1 - } - - key_file="$(mktemp)" - - nix eval -f ./secrets.nix --json | jq --raw-output '.["lf/cd_paths"].publicKeys | join("\n")' >"$key_file" - - # `lf-make-map` is provided by the dev shell - { - lf-make-map --quiet --depth 4 visualize ~/media ~/repos ~/school | sed 's|\(.*\)|# \1|' - lf-make-map --quiet --depth 4 generate ~/media ~/repos ~/school - } | age --recipients-file "$key_file" --encrypt --armor --output ./lf/cd_paths - - echo "Finished updating the lf/cd_paths file.." -} - -main() { - update_lf_cd_paths -} - -main - -# vim: ft=sh diff --git a/modules/system/secrets/update_secrets.sh b/modules/system/secrets/update_secrets.sh new file mode 100755 index 00000000..877d2892 --- /dev/null +++ b/modules/system/secrets/update_secrets.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env nix +#! nix shell nixpkgs#age nixpkgs#jq nixpkgs#dash --command dash +# shellcheck shell=dash + +cleanup() { + [ "$key_file" ] && rm "$key_file" +} +trap cleanup EXIT + +update_lf_cd_paths() { + echo "Starting to update the lf/cd_paths file.." + + cd "$(git rev-parse --show-toplevel)/modules/system/secrets" || { + echo "A secrets dir does not exist! (This is most likely a bug)" + exit 1 + } + + key_file="$(mktemp)" + + nix eval -f ./secrets.nix --json | jq --raw-output '.["lf/cd_paths"].publicKeys | join("\n")' >"$key_file" + + # `lf-make-map` is provided by the dev shell + { + lf-make-map --quiet --depth 4 visualize ~/media ~/repos ~/school | sed 's|\(.*\)|# \1|' + lf-make-map --quiet --depth 4 generate ~/media ~/repos ~/school + } | age --recipients-file "$key_file" --encrypt --armor --output ./lf/cd_paths + + echo "Finished updating the lf/cd_paths file.." +} + +main() { + update_lf_cd_paths +} + +main + +# vim: ft=sh diff --git a/pkgs/update.sh b/pkgs/update.sh deleted file mode 100755 index 0a8c4cfc..00000000 --- a/pkgs/update.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/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 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 -- cgit 1.4.1