Skip to content

Commit

Permalink
refactor: simplify gpg-restore
Browse files Browse the repository at this point in the history
  • Loading branch information
flexiondotorg committed Oct 16, 2024
1 parent 29ece57 commit 4c909b5
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions home-manager/_mixins/scripts/gpg-restore/gpg-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4c909b5

Please sign in to comment.