forked from leifj/multiverse
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathaddhost
More file actions
executable file
·82 lines (70 loc) · 1.8 KB
/
addhost
File metadata and controls
executable file
·82 lines (70 loc) · 1.8 KB
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
#!/bin/bash
cmd_hostname=""
cmd_do_bootstrap="no"
cmd_fqdn=""
function usage() {
echo "Usage: $0 [-h] [-b] [-n fqdn] [--] [<host>]"
echo " -h show help"
echo " -b bootstrap <host> (using ssh)"
echo " -n specify FQDN (if not the same as <host>)"
echo ""
echo " <host> can be an IP number, or something that resolves to one"
}
while getopts "bhn:p:" this; do
case "${this}" in
h)
usage
exit 0
;;
b) cmd_do_bootstrap="yes" ;;
n) cmd_fqdn="${OPTARG}" ;;
p) cmd_proxy="${OPTARG}" ;;
*)
echo "Unknown option ${this}"
echo ""
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [[ ! $cmd_hostname ]]; then
cmd_hostname="$1"
fi
if [[ ! $cmd_fqdn ]]; then
cmd_fqdn="$cmd_hostname"
fi
if test -z "$cmd_hostname"; then
usage
exit 1
fi
proxyjump=()
if [[ -n $cmd_proxy ]]; then
proxyjump+=("-o")
proxyjump+=("ProxyJump=${cmd_proxy}i")
fi
# shellcheck source=/dev/null
test -f cosmos.conf && . ./cosmos.conf
_remote=${remote:='ro'}
defrepo=$(git remote get-url "${_remote}" 2>/dev/null)
rrepo=${repo:="$defrepo"}
rtag=${tag:="changeme"}
if [[ ! $rrepo ]]; then
echo "$0: repo not set in cosmos.conf and no git remote named '${_remote}' found"
exit 1
fi
if [ ! -d "$cmd_fqdn" ]; then
cp -pr default "$cmd_fqdn"
git add "$cmd_fqdn"
git commit -m "$cmd_fqdn added" "$cmd_fqdn"
./bump-tag
fi
if [ "$cmd_do_bootstrap" = "yes" ]; then
cosmos_deb=$(find apt/ -maxdepth 1 -name 'cosmos_*.deb' | sort -V | tail -1)
scp "${proxyjump[@]}" "$cosmos_deb" apt/bootstrap-cosmos.sh root@"$cmd_hostname":
# We want to expand the variables on clientside - shellcheck ignore
# shellcheck disable=SC2029
ssh root@"$cmd_hostname" "${proxyjump[@]}" ./bootstrap-cosmos.sh "$cmd_fqdn" "$rrepo" "$rtag"
ssh root@"$cmd_hostname" "${proxyjump[@]}" cosmos update
ssh root@"$cmd_hostname" "${proxyjump[@]}" cosmos apply
fi