-
Notifications
You must be signed in to change notification settings - Fork 2
/
addPeer.sh
executable file
·52 lines (44 loc) · 1.02 KB
/
addPeer.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"
echo "-p, --peer (optional) the peer to add"
stop=true
;;
"-c" | "--config")
shift
config_file="$1"
;;
"-p" | "--peer")
shift
peer="$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
while [ ! -n "$peer" ]; do
read -p 'Node id of new peer: ' peer
done
config=$(jq --arg peer "$peer" '.peers += [$peer]' "$config_file")
echo "$config" | tee "$config_file" >/dev/null
echo "$peer has been added"