forked from sailfishos/sdk-build-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdk-setup-qa.sh
executable file
·211 lines (180 loc) · 4.77 KB
/
sdk-setup-qa.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
#
# Copyright 2013-2014 Jolla Ltd.
# Contact: Juha Kallioinen <[email protected]>
#
# Change the ssu domain and release for SDK QA purposes
#
# The ssu domain and release will be changed for the build engine, sdk
# emulator and all scratchbox2 targets found in the build engine.
#
# Run this script on the build engine.
#
################################################################
SSU_RELEASE=latest
SSU_DOMAIN=sailfishqa
SSU_REGDOMAIN=10.0.0.20
################################################################
#
sdk_user=mersdk
ssh_keys=/etc/$sdk_user/share/ssh/private_keys/SailfishOS_Emulator/
emu_ip=10.220.220.1
if [[ $(hostname) != "SailfishSDK" ]]; then
echo "You must run this script in the SailfishSDK build engine."
exit 1
fi
if [[ $EUID -ne 0 ]]; then
exec sudo $0 "$@"
echo "$0 must be run as root and sudo failed; exiting"
exit 1
fi
usage()
{
cat <<EOF
Change the ssu domain and release for the build engine, emulator and
sb2 targets.
Without any arguments the following values will be used:
domain: $SSU_DOMAIN
release: $SSU_RELEASE
reg domain: $SSU_REGDOMAIN
Usage:
$0 [OPTION]
Options:
-i ignore connection problems to the Emulator
-d <ADDR> use hostname or ip address <ADDR> as the reg domain
-r <REL> use <REL> as the release
-y answer 'yes' to all questions from this script
EOF
[[ -n $1 ]] && exit 1
}
OPT_ASK_USER=1
OPT_IGNORE_EMULATOR=0
while [[ ${1:-} ]]; do
case "$1" in
-y) shift
OPT_ASK_USER=0
;;
-i) shift
OPT_IGNORE_EMULATOR=1
;;
-d) shift
SSU_REGDOMAIN=$1; shift
[[ -z $SSU_REGDOMAIN ]] && usage quit
;;
-r) shift
SSU_RELEASE=$1; shift
[[ -z $SSU_RELEASE ]] && usage quit
;;
-h|--help|-*)
usage quit
;;
*)
usage quit
;;
esac
done
if [[ $OPT_IGNORE_EMULATOR -eq 0 ]]; then
echo "Testing connection to the Emulator ..."
ssh -F /etc/ssh/ssh_config.sdk -i $ssh_keys/root root@$emu_ip true
if [[ $? -ne 0 ]]; then
echo "Could not connect to the Emulator. Please start it or use -i option to ignore this."
exit 1
fi
fi
cat <<EOF
#### Going to execute with these options:
reg domain: [$SSU_REGDOMAIN]
domain: [$SSU_DOMAIN]
release: [$SSU_RELEASE]
EOF
[[ $OPT_IGNORE_EMULATOR -eq 1 ]] && echo "(Ignoring the Emulator)"
echo
if [[ $OPT_ASK_USER -gt 0 ]]; then
while true; do
read -p "Do you want to continue? (y/n) " answer
case $answer in
[Yy]*)
break ;;
[Nn]*)
echo "Ok, exiting"
exit 0
;;
*)
echo "Please answer yes or no."
;;
esac
done
fi
# this temp file must be located in a path the sb2 targets can access
repoini=$(mktemp /home/$sdk_user/repoini.XXXX)
[[ ! -f $repoini ]] && { echo "Could not create tempfile $repoini. Exiting."; exit 1; }
# make sure it's readable
chmod a+r $repoini
# set cleanup handler for the tempfile
trap "{ rm -f $repoini; exit 0; }" EXIT
#releaseDomain=betarepo-nd27k0.sailfishos.org
cat >$repoini <<EOF
[$SSU_DOMAIN-domain]
_ca-certificate=/etc/ssl/certs/sailfish-ca.pem
releaseProtocol=http
releaseDomain=$SSU_REGDOMAIN
releasePath=sdk
secureDomain=%(releaseDomain)
ssuRegDomain=ssu.sailfishos.org
EOF
check_target_visible() {
local tgt=$1
local sbox2dir=/home/$sdk_user/.scratchbox2
. $sbox2dir/$tgt/sb2.config
if [ ! -d "$SBOX_TARGET_ROOT" ]; then
echo "no"
return
fi
echo "yes"
}
get_targets() {
tgts=$(sudo -i -u $sdk_user sb2-config -l 2>&1)
[[ $? -ne 0 ]] && return 0
for t in $tgts; do
if [[ $(check_target_visible $t) == "yes" ]]; then
echo $t
fi
done
}
target_change_domain()
{
local tgt
[[ -z ${1:-} ]] && return 0
tgt=$1
echo "#### Changing $tgt domain"
# use sed to append contents of $repoini file to ssu repos.ini
sudo -i -u $sdk_user bash -c "sb2 -t $tgt -m sdk-install -R sed -i '$ r $repoini' /usr/share/ssu/repos.ini" 2>/dev/null
sudo -i -u $sdk_user bash -c "sb2 -t $tgt -m sdk-install -R ssu domain $SSU_DOMAIN" 2>/dev/null
sudo -i -u $sdk_user bash -c "sb2 -t $tgt -m sdk-install -R ssu release $SSU_RELEASE" 2>/dev/null
}
######
#
# Build engine
echo "#### Changing BE ssu domain"
cat $repoini >> /usr/share/ssu/repos.ini
ssu domain $SSU_DOMAIN
ssu release $SSU_RELEASE
######
#
# Emulator
if [[ $OPT_IGNORE_EMULATOR -eq 0 ]]; then
echo "#### Changing Emulator ssu domain"
cat $repoini | ssh -F /etc/ssh/ssh_config.sdk -i $ssh_keys/root root@$emu_ip "cat >> /usr/share/ssu/repos.ini"
ssh -F /etc/ssh/ssh_config.sdk -i $ssh_keys/root root@$emu_ip ssu domain $SSU_DOMAIN
ssh -F /etc/ssh/ssh_config.sdk -i $ssh_keys/root root@$emu_ip ssu release $SSU_RELEASE
else
echo "#### Ignoring the Emulator"
fi
######
#
# Targets
targets=$(get_targets)
for target in $targets; do
target_change_domain $target
done
echo "#### Done"