-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_ssh_keys.sh
More file actions
executable file
·62 lines (47 loc) · 1.48 KB
/
fetch_ssh_keys.sh
File metadata and controls
executable file
·62 lines (47 loc) · 1.48 KB
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
#!/bin/bash
source "$HOME/bin/shell-proteins/bash/base.inc.sh"
# Import core functions
protein_require "core/print_usage"
protein_require "grzegorzblaszczyk/shell-proteins-ext/bash/os/get_os_version"
os_version="`get_os_version`"
case "${os_version}" in
MacOSX)
os="mac"
;;
Ubuntu)
os="ubuntu"
;;
*)
os="unknown"
;;
esac
protein_require "grzegorzblaszczyk/shell-proteins-ext/bash/${os}/verify_if_installed_with_dot"
verify_if_installed_with_dot "curl" "/usr/bin/curl"
verify_if_installed_with_dot "jq" "/usr/local/bin/jq"
verify_if_installed_with_dot "tr" "/usr/bin/tr"
echo ""
DEBUG="${DEBUG:-false}"
CAT=`which cat`
CURL=`which curl`
CUT=`which cut`
GREP=`which grep`
JQ=`which jq`
RM=`which rm`
SORT=`which sort`
TR=`which tr`
UNIQ=`which uniq`
DIGITALOCEAN_API_HOST="https://api.digitalocean.com"
DIGITALOCEAN_TOKEN=`${CAT} .digitalocean_credentials_ssh_keys | ${GREP} "DIGITALOCEAN_TOKEN" | ${CUT} -f 2 -d "=" | ${TR} -d '"'`
echo "Using DIGITALOCEAN_TOKEN: ${DIGITALOCEAN_TOKEN}..."
PER_PAGE=200
KEYS_JSON_FILE="keys.json"
CONTENT_TYPE_HEADER="Content-Type: application/json"
AUTHORIZATION_HEADER="Authorization: Bearer ${DIGITALOCEAN_TOKEN}"
echo "Getting list of SSH keys..."
${CURL} -X GET -H "${CONTENT_TYPE_HEADER}" -H "${AUTHORIZATION_HEADER}" \
"${DIGITALOCEAN_API_HOST}/v2/account/keys?per_page=100" > ${KEYS_JSON_FILE}
${CAT} ${KEYS_JSON_FILE}
${CAT} ${KEYS_JSON_FILE} | ${JQ} '.ssh_keys[]'
if [ "x${DEBUG}" == "xfalse" ]; then
${RM} -f ${KEYS_JSON_FILE} ${JSON_FILE}
fi