-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdate-all
executable file
·91 lines (71 loc) · 1.65 KB
/
update-all
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
set -eo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source "$DIR/helpers/functions"
match() {
key="$1"
shift
if [[ $# -eq 0 ]]; then
return 0
fi
for match; do
if [[ "$key" == $match ]]; then
return 0
fi
done
return 1
}
update_clients() {
echo "Clients:"
for client_config in "clients/"*.conf; do
client_name="$(basename "$client_config" .conf)"
if ! match "$client_name" "$@"; then
continue
fi
for server_config in "servers/"*.conf; do
server_name="$(basename "$server_config" .conf)"
client_updatecmd=$(get_value "$client_config" "UpdateCmd_$server_name" "UpdateCmd")
if ! peer_allowed "$client_config" "$server_config"; then
continue
fi
if [[ -n "$client_updatecmd" ]]; then
echo "$client_name:$server_name... "
"$DIR/emit-client" $client_updatecmd "$server_name" "$client_name" || true
fi
done
done
echo
}
update_servers() {
shift
echo "Servers:"
for server_config in "servers/"*.conf; do
server_name="$(basename "$server_config" .conf)"
if ! match "$server_name" "$@"; then
continue
fi
server_updatecmd=$(get_value "$server_config" "UpdateCmd")
if [[ -n "$server_updatecmd" ]]; then
echo "$server_name... "
"$DIR/emit-server" $server_updatecmd "$server_name" || true
fi
done
echo
}
case "$1" in
servers)
update_servers "$@"
;;
clients)
update_clients "$@"
;;
all)
update_clients "$@"
update_servers "$@"
;;
*)
echo "$0 <all/servers/clients> [client name...]"
exit 1
;;
esac
echo Done.