forked from lloeki/apply
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply
executable file
·67 lines (55 loc) · 1.04 KB
/
apply
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
#!/bin/bash
set -e
set -u
function usage() {
echo "usage: $(basename "$0") [-v] [-p] <host> [<host>...]"
exit 1
}
function host_targets() {
local host="$*"
cat < "${APPLY_ROOT}"/"$host" | tr '\n' ' '
}
function push_each() {
local vflag="$1"
local parallelize="$2"
shift
shift
if [[ -n $parallelize ]]; then
# shellcheck disable=SC2086
parallel -j10 --progress --colsep ' ' ./push $vflag
else
# shellcheck disable=SC2086
parallel -j1 -u --colsep ' ' ./push $vflag
fi
}
if [[ -z "${APPLY_ROOT:-}" ]]; then
APPLY_ROOT="."
fi
if [[ $# -lt 1 ]]; then
usage
fi
if [[ "$1" == "-v" ]]; then
vflag='-v'
shift
else
vflag=''
fi
if [[ "$1" == "-p" ]]; then
pflag='-p'
shift
else
pflag=''
fi
if [[ $# -lt 1 ]]; then
usage
fi
hosts=()
while [[ $# -gt 0 ]]; do
hosts+=("$1")
shift
done
for host in ${hosts[*]}; do
target=${host#*/}
# shellcheck disable=SC2046
echo $(host_targets "$host") root@"$target"
done | push_each "$vflag" "$pflag"