-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathsetup-reg.sh
More file actions
executable file
·146 lines (138 loc) · 4.09 KB
/
setup-reg.sh
File metadata and controls
executable file
·146 lines (138 loc) · 4.09 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash -e
#
# Apache v2 license
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
DIR="$( cd "$( dirname "$0" )" &> /dev/null && pwd )"
. "$DIR"/setup-common.sh
print_help () {
echo "Usage: [options] <user>@<host>[:port] [<user>@<ip> ...]"
echo ""
echo "--port=<port> Specify the SUT ssh port."
echo "--force Force replacing any existing certificate."
echo "--no-password Do not ask for password. Use DEV_SUDO_PASSWORD and/or SUT_SSH_PASSWORD/SUT_SUDO_PASSWORD instead."
echo "--nointelcert Do not install Intel certificates."
echo ""
echo "<host> can be in the form of a FQDN hostname or an IP address."
echo "The default registry port of a docker registry is 20666."
echo "<user@ip> additional hosts that may need to access the registry."
echo ""
exit 3
}
if [ -z "$1" ]; then
print_help
fi
reg_port=20666
ssh_port=22
reg_host=""
reg_user="$(id -un)"
sut_hosts=()
ansible_options=()
[ ! -e vars.yaml ] || ansible_options+=(-e "@vars.yaml")
setup_ansible_options=()
setup_native_options=()
replace="false"
last=""
for v in $@; do
k1="$(echo "${v#--}" | cut -f1 -d=)"
v1="$(echo "${v#--}" | cut -f2- -d= | sed 's/%20/ /g')"
case "$v" in
--help)
print_help
;;
--nointelcert)
setup_native_options+=("$v")
;;
--port=*)
ssh_port="${v#--port=}"
;;
--port)
;;
--force)
replace="true"
;;
--no-password)
setup_ansible_options+=("$v")
setup_native_options+=("$v")
export ANSIBLE_BECOME_EXE='echo "$DEV_SUDO_PASSWORD" | sudo -S'
;;
--*=*)
validate_ansible_option $k1 $v
setup_native_options+=("$v")
ansible_options+=("-e" "$k1=$v1")
;;
--no*)
validate_ansible_option ${k1#no} $v
setup_native_options+=("$v")
ansible_options+=("-e" "${k1#no}=false")
;;
--*)
validate_ansible_option $k1 $v
setup_native_options+=("$v")
ansible_options+=("-e" "$k1=true")
;;
*)
if [ "$last" = "--port" ]; then
ssh_port="$v"
elif [ -z "$reg_host" ]; then
reg_host="${v//:*/}"
reg_host="${reg_host//*@/}"
[[ "$v" != *"@"* ]] || reg_user="${v//@*/}"
[[ "$v" != *":"* ]] || reg_port="${v//*:/}"
elif [[ "$v" = *"@"* ]]; then
sut_hosts+=("$v")
else
echo "Unsupported argument: $v"
exit 3
fi
;;
esac
last="$v"
done
if [[ "$reg_host" = *"localhost"* ]] || [[ "$reg_host" = *"127.0.0.1"* ]]; then
echo "The registry host $reg_host must be fully qualified"
exit 3
fi
./setup-ansible.sh "${setup_ansible_options[@]}" 2>&1 | tee setup-reg.logs
connection=local
[[ "$reg_host" = "$(hostname -f)"* ]] || [[ " $(hostname -i) " = *" $reg_host "* ]] || connection=ssh
reg_host_ssh="$([ "$connection" = "local" ] || echo "$reg_user@$reg_host")"
[[ "$reg_host_ssh${sut_hosts[@]}" != *"@"* ]] || ./setup-sut-native.sh --port $ssh_port $reg_host_ssh ${sut_hosts[@]} "${setup_native_options[@]}" 2>&1 | tee -a setup-reg.logs
. <(sed '/^# BEGIN WSF Setup/,/^# END WSF Setup/{d}' /etc/environment)
export http_proxy https_proxy no_proxy
rm -f /tmp/wsf-setup-ssh-* 2> /dev/null || true
ANSIBLE_ROLES_PATH=../terraform/template/ansible/common/roles ANSIBLE_INVENTORY_ENABLED=yaml ansible-playbook --flush-cache -vv -e wl_logs_dir="$DIR" -e my_ip_list=1.1.1.1 -e dev_cert_host="$reg_host" -e dev_registry_port="$reg_port" -e dev_cert_replace=$replace "${ansible_options[@]}" -i <(cat <<EOF
all:
children:
dev_hosts:
hosts:
dev_host:
ansible_host: "127.0.0.1"
private_ip: "127.0.0.1"
ansible_connection: local
reg_hosts:
hosts:
reg_host:
ansible_host: "$reg_host"
ansible_user: "$reg_user"
private_ip: "$reg_host"
ansible_port: "$ssh_port"
ansible_connection: "$connection"
cluster_hosts:
hosts:
$(i=0
for h in ${sut_hosts[@]}; do
cat <<EOF2
worker-$i:
ansible_host: "${h/*@/}"
ansible_user: "${h/@*/}"
private_ip: "${h/*@/}"
ansible_port: "$ssh_port"
EOF2
i=$((i+1))
done
)
EOF
) ./setup-reg.yaml 2>&1 | tee -a setup-reg.logs
rm -f timing.yaml