-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
restore.sh
executable file
·61 lines (51 loc) · 1.49 KB
/
restore.sh
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
#!/usr/bin/env nix-shell
#!nix-shell -i bash ./shell.nix
set -eu
set -o pipefail
cfgOpt() {
touch build.cfg
ret=$(awk '$1 == "'"$1"'" { print $2; }' build.cfg)
if [ -z "$ret" ]; then
echo "Config option '$1' isn't specified in build.cfg" >&2
echo "Example format:"
echo "$1 value"
echo ""
exit 1
fi
echo "$ret"
}
if [ "${PACKET_AUTH_TOKEN:-x}" == "x" ]; then
PACKET_AUTH_TOKEN=$(cfgOpt "packetKey")
fi
if [ "${PACKET_PROJECT_ID:-x}" == "x" ]; then
PACKET_PROJECT_ID=$(cfgOpt "packetProjectId")
fi
restore() {
data=$((
curl \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header "X-Auth-Token: $PACKET_AUTH_TOKEN" \
--fail \
"https://api.packet.net/devices/${1}" \
| jq -r '.tags | .[]' | grep -v '^skip-hydra$'
# using jq -R . to convert the lines in to JSON strings,
# use jq -s . to convert the of JSON strings in to a JSON list
) | jq -R . | jq -s '{
id: $id,
tags: .
}' --arg id "$1")
curl -X PATCH \
--data "${data}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header "X-Auth-Token: $PACKET_AUTH_TOKEN" \
--fail \
"https://api.packet.net/devices/${1}" > /dev/null 2> /dev/null
}
id=$1
host=$2
sos=$3
echo "--- adding back to hydra"
restore "${id}"
echo "--- ok!"