-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd
executable file
·66 lines (53 loc) · 1.29 KB
/
add
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
#!/usr/bin/env bash
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/script/globals"
. "$DIR/script/functions"
FILE=$1
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_private_key {
# Decrypt keys
decrypt_private_keys
flush_passphrase_cache
untar
${MV_BIN} $FILE ${SSH_KEY_DIR}/
# Encrypt keys
encrypt_private_keys
clear_gpg_agent_files
kill_agent
}
function load_full_key {
echo "full!";
# Decrypt keys
decrypt_private_keys
decrypt_all_keys
flush_passphrase_cache
clear_gpg_agent_files
kill_agent
untar
# Get private keys and copy sources.
PRIVATE_KEYS=`${GREP_BIN} -rl 'BEGIN .* PRIVATE KEY' ${FILE}`
for key in $PRIVATE_KEYS
do
${CP_BIN} $key ${SSH_KEY_DIR}/
done
${MV_BIN} $FILE ${SSH_FULL_KEY_DIR}/
# Encrypt keys
encrypt_private_keys
encrypt_all_keys
}
if is_encrypted; then
check_dependencies
set_gpg_home
if [ ! -d "$FILE" ]; then
load_private_key
else
load_full_key
fi
clear_gpg_agent_files
else
echo "ERROR! 'sh add' only works when the drive is encrypted!";
fi