|
@@ -1,6 +1,7 @@
|
|
|
#!/usr/bin/env bash
|
|
#!/usr/bin/env bash
|
|
|
set -euo pipefail
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
+HOST="${HOST:-$(hostname -s 2>/dev/null || hostname)}"
|
|
|
PASS_BASE="personal/ssh"
|
|
PASS_BASE="personal/ssh"
|
|
|
STORE_ROOT="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
|
|
STORE_ROOT="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
|
|
|
ABS_BASE_PATH="${STORE_ROOT}/${PASS_BASE}"
|
|
ABS_BASE_PATH="${STORE_ROOT}/${PASS_BASE}"
|
|
@@ -16,12 +17,13 @@ if [[ ! -d "$ABS_BASE_PATH" ]]; then
|
|
|
exit 1
|
|
exit 1
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+
|
|
|
# Loop through each identity subdirectory
|
|
# Loop through each identity subdirectory
|
|
|
-echo -n "Injecting ssh keys "
|
|
|
|
|
|
|
+echo -n "Loading ssh keys for host: "
|
|
|
while IFS= read -r dir; do
|
|
while IFS= read -r dir; do
|
|
|
IDENTITY=$(basename "$dir")
|
|
IDENTITY=$(basename "$dir")
|
|
|
-
|
|
|
|
|
- # Find the latest .gpg file by name (ISO sort)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ # Find the latest .gpg file by name (ISO sort) and hostname
|
|
|
LATEST_FILE=$(find "$dir" -maxdepth 1 -name "*.gpg" -exec basename {} \; \
|
|
LATEST_FILE=$(find "$dir" -maxdepth 1 -name "*.gpg" -exec basename {} \; \
|
|
|
| sed 's/\.gpg$//' \
|
|
| sed 's/\.gpg$//' \
|
|
|
| sort -r \
|
|
| sort -r \
|
|
@@ -31,10 +33,10 @@ while IFS= read -r dir; do
|
|
|
continue
|
|
continue
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
- echo -n "."
|
|
|
|
|
|
|
+ echo -n "$HOST"
|
|
|
|
|
|
|
|
# Decrypt and pipe directly to ssh-add
|
|
# Decrypt and pipe directly to ssh-add
|
|
|
# The '-' tells ssh-add to read the key from standard input (stdin)
|
|
# The '-' tells ssh-add to read the key from standard input (stdin)
|
|
|
pass show "${PASS_BASE}/${IDENTITY}/${LATEST_FILE}" | ssh-add - >/dev/null 2>&1
|
|
pass show "${PASS_BASE}/${IDENTITY}/${LATEST_FILE}" | ssh-add - >/dev/null 2>&1
|
|
|
|
|
|
|
|
-done < <(find "$ABS_BASE_PATH" -mindepth 1 -maxdepth 1 -type d)
|
|
|
|
|
|
|
+done < <(find "$ABS_BASE_PATH" -mindepth 1 -maxdepth 1 -type d -name "*${HOST}*")
|