unlocks.sh

SSH Keychain komfortabel mit Schlüsseln vollschaufeln, ohne in Fehler zu rennen Shell Script!!1!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh

SSH_ADD=$(which "ssh-add")
SSH_KEY=$(which "ssh-keygen")

msg () { echo "$(basename "$0") | $*"; }

KEY_FILE="${KEY-"$1"}"
if [ -z "$KEY_FILE" ]; then
    msg "specify key file, please."
    exit 1
fi
msg "$KEY_FILE"

KEY_INFO=$($SSH_KEY -lf "$KEY_FILE" 2>&1)
KEY_CODE=$?

msg "$KEY_INFO"
if [ $KEY_CODE -ne  0 ]; then
    msg "error" "[$KEY_CODE]"
    exit $KEY_CODE
fi

KEY_HASH=$(echo "$KEY_INFO" | cut -d' ' -f2)
if $SSH_ADD -l | grep -q "$KEY_HASH"; then
    msg "already unlocked."
    exit 0
fi

$SSH_ADD "$KEY_FILE"
exit $?
  • platformunabhängig
  • posix
  • verteiltes echtzeitjava
  • zertifiziert
  • banane