-
Notifications
You must be signed in to change notification settings - Fork 2
/
configureHops.sh
executable file
·52 lines (45 loc) · 1.03 KB
/
configureHops.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
#!/bin/bash
cd "$( dirname "${BASH_SOURCE[0]}" )/."
stop=false
config_file=""
peer=""
_setArgs(){
while [ "$1" != "" ]; do
case $1 in
"-h" | "--help")
echo "options:"
echo "-h, --help show brief help"
echo "-c, --config (optional) define config file to load"
stop=true
;;
"-c" | "--config")
shift
config_file="$1"
;;
esac
shift
done
}
_setArgs $*
if "$stop"; then
return
fi
if [ ! -n "$config_file" ]; then
config_file=$(./getConfig.sh)
fi
if [[ "$config_file" == *"Error"* ]] || [ ! -n "$config_file" ] || [ ! -f "$config_file" ]; then
echo "$config_file does not exists."
return
fi
hops=()
hop=true
while [ -n "$hop" ]; do
read -p 'Public key of hop (leave empty when done): ' hop
if [ -n "$hop" ]; then
hops+=( "\"$hop\"" )
fi
done
config=$(jq '.' "$config_file")
config=$(echo "${hops[@]}" | jq -s --argjson config "$config" '$config + {"hops": .}')
echo "$config" | tee "$config_file" >/dev/null
echo "Hops configured"