-
Notifications
You must be signed in to change notification settings - Fork 0
/
load
executable file
·70 lines (58 loc) · 1.36 KB
/
load
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/script/globals"
. "$DIR/script/functions"
KEY_NAME=$1
HOURS=$2
CLEAR=$3
if [ -z $KEY_NAME ]; then
echo "ERROR! load requires a key name!"
fi
if [ -z $HOURS ]; then
HOURS=1
fi
function check_dependencies {
[ -z "${SSH_AGENT_BIN}" ] && echo "No ssh-agent bin found, exiting." && exit 1
[ -z "${SSH_ADD_BIN}" ] && echo "No ssh-add bin found, exiting." && exit 1
}
function load_key {
if [ "$CLEAR" = "--clear" ]; then
${SSH_ADD_BIN} -D
fi
${SSH_ADD_BIN} -t ${HOURS}H $DIR/$1
}
function load_keys {
SSH_KEYS=`${GREP_BIN} -rl 'BEGIN .* PRIVATE KEY' ${SSH_KEY_DIR}`
# No private keys found in directory
if [ -z ${SSH_KEYS} ]; then
encrypt_private_keys
print_separator
echo "ERROR! No ssh keys found, exiting." && exit 1
fi
for key in $SSH_KEYS
do
load_key $key
done
}
function load {
if [ "$KEY_NAME" = "--all" ]; then
load_keys
else
load_key $SSH_KEY_DIR/$KEY_NAME
fi
print_separator
}
if is_encrypted; then
check_dependencies
set_gpg_home
decrypt_private_keys
flush_passphrase_cache
untar
load
encrypt_private_keys
clear_gpg_agent_files
kill_agent
else
echo "ERROR! Cannot load unencrypted keys! Run: \"sh encrypt\" first";
fi