From 4c909b5b7bdc5881865225d1cf0e3055011d6120 Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Wed, 16 Oct 2024 13:12:55 +0100 Subject: [PATCH] refactor: simplify gpg-restore --- .../scripts/gpg-restore/gpg-restore.sh | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/home-manager/_mixins/scripts/gpg-restore/gpg-restore.sh b/home-manager/_mixins/scripts/gpg-restore/gpg-restore.sh index 7b5eda6fa..202924fc9 100755 --- a/home-manager/_mixins/scripts/gpg-restore/gpg-restore.sh +++ b/home-manager/_mixins/scripts/gpg-restore/gpg-restore.sh @@ -4,28 +4,15 @@ mkdir -p --mode=700 "${HOME}/.gnupg" gpgconf --kill gpg-agent -if [ "$(uname)" = "Darwin" ]; then - base_temp_dir=$(getconf DARWIN_USER_TEMP_DIR)/secrets.d/ -else - base_temp_dir="/run/user/$(id -u)/secrets.d" -fi - -if [ -d "${base_temp_dir}" ]; then - # Find the numerically highest sub-directory - temp_dir=$(find "${base_temp_dir}" -type d -maxdepth 1 -exec basename {} \; | sort -n | tail -n 1) - temp_dir="${base_temp_dir}/${temp_dir}" -else - echo "Directory ${base_temp_dir} does not exist." - exit 1 -fi +temp_dir="${HOME}/.config/sops-nix/secrets" -if [ -d "${temp_dir}" ]; then +if [ -e "${temp_dir}/gpg_private" ]; then gpg --import --batch "${temp_dir}/gpg_private" gpg --import "${temp_dir}/gpg_public" gpg --list-secret-keys gpg --list-keys gpg --import-ownertrust "${temp_dir}/gpg_ownertrust" else - echo "Secrets directory ${temp_dir} does not exist." + echo "GPG keys were not found in: ${temp_dir}" exit 1 fi