-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-for-teams.sh
executable file
·74 lines (58 loc) · 1.42 KB
/
run-for-teams.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
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash jq parallel
set -e
mapAllHosts() {
local deployment="$1"
local type
local host
teamHosts=()
juryHost=""
while read line; do
args=($line)
type="${args[0]}"
host="${args[1]}"
case "$type" in
team)
teamHosts+=("$host")
;;
jury)
juryHost="$host"
;;
esac
done < <(nixops export -d "$deployment" | jq -r '.[keys | first].resources | keys | .[]' | parallel determineHost "$deployment")
}
usage() {
echo "Usage: $0 <deployment> <script> args..." >&2
exit 1
}
deployment="$1"
shift || usage
script="$1"
shift || usage
determineHost() {
local deployment="$1"
local host="$2"
if [ "$(nixops show-option -d "$deployment" "$host" adLib.teamHost.enable)" = "true" ]; then
echo "team $host"
elif [ "$(nixops show-option -d "$deployment" "$host" adLib.juryHost.enable)" = "true" ]; then
echo "jury $host"
fi
}
export -f determineHost
teamHosts=()
juryHost=""
while read line; do
args=($line)
type="${args[0]}"
host="${args[1]}"
case "$type" in
team)
teamHosts+=("$host")
;;
jury)
juryHost="$host"
;;
esac
done < <(nixops export -d "$deployment" | jq -r '.[keys | first].resources | keys | .[]' | parallel determineHost "$deployment")
unset -f determineHost
parallel -j4 "$script" "$deployment" "$juryHost" {} "$@" -s {.} -all -qcache ::: "${teamHosts[@]}"