aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2019-03-25 20:34:27 -0300
committerSilvio Rhatto <rhatto@riseup.net>2019-03-25 20:34:27 -0300
commit74e28743f7021e3db39eaa3d81afa9eaff710ad6 (patch)
treed149c96e82f1dd0f9f857ab304c3586d231b51cd
parenta81717fd7fb29f7e84600ff5bf8587b00ed65b3d (diff)
downloadutils-ssh-74e28743f7021e3db39eaa3d81afa9eaff710ad6.tar.gz
utils-ssh-74e28743f7021e3db39eaa3d81afa9eaff710ad6.tar.bz2
Initial working version of ssh-agent-loadkey-menu
-rwxr-xr-xssh-agent-loadkey-menu63
1 files changed, 55 insertions, 8 deletions
diff --git a/ssh-agent-loadkey-menu b/ssh-agent-loadkey-menu
index c804d1d..6029729 100755
--- a/ssh-agent-loadkey-menu
+++ b/ssh-agent-loadkey-menu
@@ -13,13 +13,60 @@ if [ ! -d "$KEYS" ]; then
exit 1
fi
-# Display menu with available keys
-# Check the selected option
-# Check if the selected option has a custom procedure (monkeysphere, keyringer, etc)
-# Grab passphrase and load the key
-#( cd $KEYS && find -name '*.pub' | grep -v decomissioned )
+# Get available keys
+function __query {
+ ( cd $KEYS && find -name '*.pub' | sed -e 's/.pub$//' | grep -v decomissioned )
+}
+
+# List available keys
+function __list {
+ n="0"
+ __query | sort | uniq | while read key; do
+ echo -en "$n. $key"
+ echo ""
+ let ++n
+ done | column -t -c 6
+}
# Display the keys available in the agent
-#echo "Current loaded keys:"
-#echo ""
-#ssh-add -L | cut -d ' ' -f 3 | sed -e 's/^/\t/'
+function __loaded {
+ echo "Current loaded keys:"
+ echo ""
+
+ ssh-add -L | cut -d ' ' -f 3 | sed -e 's/^/\t/'
+}
+
+# Key chooser mennu
+function __chooser {
+ echo "Available keys"
+ echo ""
+ __list | sed -e 's/^/\t/'
+ echo ""
+ __loaded
+ echo ""
+
+ read -rep "Choose key: " n
+
+ # Check the selected option
+ if [ ! -z "$n" ]; then
+ key="$(__list | grep -E "(^$n.| $n:)" | sed -e "s/^[0-9]*. //" | cut -d : -f 1)"
+
+ if [ ! -z "$key" ]; then
+ __load $key
+ fi
+ fi
+}
+
+# Load a key
+function __load {
+ # Check if the selected option has a custom procedure (monkeysphere, keyringer, etc)
+ if [ -x "$KEYS/$1.askpass" ]; then
+ # SSH-ADD(1) says: "Note that on some machines it may be necessary to redirect the input from /dev/null to make this work".
+ SSH_ASKPASS="$KEYS/$1.askpass" ssh-add $HOME/.ssh/keys/$1 < /dev/null
+ else
+ ssh-add $HOME/.ssh/keys/$1
+ fi
+}
+
+# Dispatch
+__chooser