-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure
executable file
·248 lines (207 loc) · 5.76 KB
/
configure
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
set -o nounset
set -o pipefail
INPUT=$(dirname "$0")/config.py.in
OUTPUT=config.py
brief_usage()
{
cat <<END
Usage: configure [--engine-type|-t <type>] [--keep|-k] [--non-interactive|-y]
[--quiet] [--] <installer> [<args>...]
Prepare the test suite for use with the specified SDK <installer>. Possible
<args> will be used as initial arguments for the installer.
END
}
usage()
{
cat <<END
$(brief_usage)
OPTIONS
--engine-type|-t <type>
Test with the specified build engine <type>, either 'vbox' or
'docker', defaults to 'vbox'. Corresponds to the BUILD_ENGINE_TYPE
configuration option.
--keep|-k
Use existing SDK installation. Corresponds to the
USE_EXISTING_SDK_INSTALLATION configuration option.
--non-interactive|-y
Answer yes to all questions.
--quiet
Do not print summary
END
}
fatal()
{
echo "Fatal: $*" >&2
}
bool_to_python()
{
[[ $1 ]] && echo True || echo False
}
strings_to_python()
{
python3 -c 'import sys; print(repr(sys.argv[1:]))' "$@"
}
show_meta()
{
local installer=$1
local args=("${@:2}")
local out=
out=$("$installer" ${args[@]:+"${args[@]}"} --verbose non-interactive=1 show-meta=1)
# Installer should exit with 3 as it is actually canceled with show-meta=1
if (( $? != 0 && $? != 3 )); then
fatal "Failed to run installer in order to retrieve its metadata"
return 1
fi
local meta=$(sed -n 's/.*show-meta:: //p' <<<"$out")
if [[ ! $meta ]]; then
fatal "The specified installer executable contains no metadata"
return 1
fi
printf '%s\n' "$meta"
}
get()
{
local meta=$1
local key=$2
local value=$(sed -n "s/^$key=//p" <<<"$meta")
if [[ ! $value ]]; then
fatal "Failed to retrieve '$key' from installer metadata: No such key"
return 1
fi
printf '%s\n' "$value"
}
configure()
{
local orig_cmdline=("$@")
local installer_args=$(strings_to_python ${OPT_INSTALLER_ARGS[@]:+"${OPT_INSTALLER_ARGS[@]}"})
local meta=
meta=$(show_meta "$OPT_INSTALLER" ${OPT_INSTALLER_ARGS[@]:+"${OPT_INSTALLER_ARGS[@]}"} \
|tr , '\n') || return
local sdk_version=
sdk_version=$(get "$meta" sdk_release) || return
local os_version_ea=
os_version_ea=$(get "$meta" os_release_ea) || return
local os_version_latest=
os_version_latest=$(get "$meta" os_release_latest) || return
local use_existing=$(bool_to_python "$OPT_KEEP")
{
printf 'Installer: %q\n' "$OPT_INSTALLER"
printf 'Installer arguments:'
printf ' %q' ${OPT_INSTALLER_ARGS[@]:+"${OPT_INSTALLER_ARGS[@]}"}
printf '\n'
printf 'Use existing SDK installation: %s\n' "$use_existing"
printf 'SDK version: %s\n' "$sdk_version"
printf 'OS version (EA): %s\n' "$os_version_ea"
printf 'OS version (latest): %s\n' "$os_version_latest"
printf 'Build engine type: %s\n' "$OPT_ENGINE_TYPE"
} >&2
cat <<END
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!! AUTOGENERATED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
# This file was automatically generated from:
#
# $INPUT
#
# with the command:
#
# ${orig_cmdline[*]}
#
# Feel free to further adjust the values but do not forget the file will be
# completely overwritten every time the above mentioned command is issued.
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
END
local config=
config=$(cat) || return
config=${config//'{{SDK_VERSION}}'/"$sdk_version"}
config=${config//'{{OS_VERSION_EA}}'/"$os_version_ea"}
config=${config//'{{OS_VERSION_LATEST}}'/"$os_version_latest"}
config=${config//'{{USE_EXISTING_SDK_INSTALLATION}}'/"$use_existing"}
config=${config//'{{INSTALLER}}'/"$OPT_INSTALLER"}
config=${config//'{{INSTALLER_ARGS}}'/"$installer_args"}
config=${config//'{{BUILD_ENGINE_TYPE}}'/"$OPT_ENGINE_TYPE"}
printf '%s' "$config"
}
parse_args()
{
OPT_INSTALLER=
OPT_INSTALLER_ARGS=()
OPT_ENGINE_TYPE=vbox
OPT_HELP=
OPT_KEEP=
OPT_NON_INTERACTIVE=
OPT_QUIET=
while (( $# > 0 )); do
case $1 in
--engine-type|-t)
if ! [[ $2 ]]; then
fatal "Argument expected: '$1'"
return 1
fi
OPT_ENGINE_TYPE=$2
shift
;;
--help|-h)
OPT_HELP=1
return
;;
--keep|-k)
OPT_KEEP=1
;;
--non-interactive|-y)
OPT_NON_INTERACTIVE=1
;;
--quiet)
OPT_QUIET=1
;;
--)
shift
positionals+=("$@")
shift $#
;;
-??*)
arg=$1
shift
set -- "${arg}" -"${arg:1:1}" -"${arg:2}" "${@}"
;;
-*)
fatal "Unknown option '$1'"
brief_usage >&2
return 1
;;
*)
positionals+=("$@")
shift $#
;;
esac
shift
done
set -- "${positionals[@]}"
if (( $# == 0 )); then
fatal "Argument expected"
brief_usage >&2
return 1
fi
OPT_INSTALLER=$1
shift
OPT_INSTALLER_ARGS=("$@")
}
main()
{
parse_args "$@" || return
if [[ $OPT_HELP ]]; then
usage
return
fi
local YN=
if [[ -e $OUTPUT && ! $OPT_NON_INTERACTIVE ]]; then
read -p "Existing configuration found - overwrite? [y/N] " YN
if [[ $YN != [yY] ]]; then
echo "User aborted!" >&2
return 1
fi
fi
configure "$0" "$@" <"$INPUT" >"$OUTPUT"
}
main "$@"