summaryrefslogtreecommitdiff
path: root/bin/guiscripts/keyadd
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2023-08-30 08:23:45 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2023-08-30 08:23:45 +0200
commit3f8594ee04d2a3d9b40a259daf3b564a53b510fa (patch)
tree66ed50643cdc81af813b5771a99732d0f78bb618 /bin/guiscripts/keyadd
parent45d39ae0c67bb086f4df0c366b251e06c888408d (diff)
parent333aaf38c66a1e4ba41d3acea38b21613c0075b2 (diff)
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'bin/guiscripts/keyadd')
-rwxr-xr-xbin/guiscripts/keyadd45
1 files changed, 31 insertions, 14 deletions
diff --git a/bin/guiscripts/keyadd b/bin/guiscripts/keyadd
index 96d6d03..cb81efe 100755
--- a/bin/guiscripts/keyadd
+++ b/bin/guiscripts/keyadd
@@ -22,9 +22,24 @@ die ()
echo "$1" >&2
}
+notify ()
+{
+ notify-send -t 1000 "keyadd" "$1"
+ die "$1"
+}
+
+
SSHFOLDER="$HOME/.ssh"
-if test -z "${key:=$1}"
+# Test if can connect to ssh-agent
+ssh-add -l > /dev/null 2>&1
+if [ $? -gt 1 ] # ignore if there are no identities
+then
+ notify "Could not connect to agent."
+ exit 1
+fi
+
+if [ -z "${key:=$1}" ]
then
key="$(find "$SSHFOLDER" -iname "*.pub" |
sed "s,$SSHFOLDER/,," | # Clean
@@ -35,24 +50,26 @@ else
fi
die "key: $key"
-test ! -f "$SSHFOLDER/$key" && exit 1
+[ ! -f "$SSHFOLDER/$key" ] && exit 1
-HOST=$(hostnamectl hostname | sed 's/forlure/fl/;s/montecristo/mc/')
-die "HOST: $HOST"
+HOST=$(hostnamectl hostname)
+die "host: $HOST"
if [ "$1" = "-d" ]
then
- ssh-add -d - < "$SSHFOLDER"/$key.pub &&
- notify-send "$0" "deleted <b>$key</b>" ||
- notify-send "$0" "could not delete."
-elif ! ssh-add -l | grep -q "$(ssh-keygen -lf "$SSHFOLDER"/$key)"
+ if ssh-add -q -d - < "$SSHFOLDER"/"$key".pub 2> /dev/null
+ then
+ notify "Deleted <b>$key</b>"
+ else
+ notify "Could not delete."
+ fi
+# check if key is already added
+elif ssh-add -l | grep -q "$(ssh-keygen -lf "$SSHFOLDER"/"$key")"
then
- die "adding: $key"
+ notify "Key already added."
+else
export PASSWORD="keys/$HOST/ssh/$key"
export SSH_ASKPASS="$0"
- ssh-add - < "$SSHFOLDER"/$key &&
- notify-send "$0" "added <b>$key</b>"
-else
- die "key already added."
- notify-send "$0" "key already added."
+ ssh-add -q - < "$SSHFOLDER"/"$key" &&
+ notify "Added <b>$key</b>."
fi