]>
Commit | Line | Data |
---|---|---|
3157f602 XL |
1 | #!/bin/sh |
2 | # Copyright 2014 The Rust Project Developers. See the COPYRIGHT | |
3 | # file at the top-level directory of this distribution and at | |
4 | # http://rust-lang.org/COPYRIGHT. | |
5 | # | |
6 | # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
7 | # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
8 | # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
9 | # option. This file may not be copied, modified, or distributed | |
10 | # except according to those terms. | |
11 | ||
12 | msg() { | |
13 | echo "combine-installers: $1" | |
14 | } | |
15 | ||
16 | step_msg() { | |
17 | msg | |
18 | msg "$1" | |
19 | msg | |
20 | } | |
21 | ||
22 | warn() { | |
23 | echo "combine-installers: WARNING: $1" | |
24 | } | |
25 | ||
26 | err() { | |
27 | echo "combine-installers: error: $1" | |
28 | exit 1 | |
29 | } | |
30 | ||
31 | need_ok() { | |
32 | if [ $? -ne 0 ] | |
33 | then | |
34 | err "$1" | |
35 | fi | |
36 | } | |
37 | ||
38 | need_cmd() { | |
39 | if command -v $1 >/dev/null 2>&1 | |
40 | then msg "found $1" | |
41 | else err "need $1" | |
42 | fi | |
43 | } | |
44 | ||
45 | putvar() { | |
46 | local T | |
47 | eval T=\$$1 | |
48 | eval TLEN=\${#$1} | |
49 | if [ $TLEN -gt 35 ] | |
50 | then | |
51 | printf "combine-installers: %-20s := %.35s ...\n" $1 "$T" | |
52 | else | |
53 | printf "combine-installers: %-20s := %s %s\n" $1 "$T" "$2" | |
54 | fi | |
55 | } | |
56 | ||
57 | valopt() { | |
58 | VAL_OPTIONS="$VAL_OPTIONS $1" | |
59 | ||
60 | local OP=$1 | |
61 | local DEFAULT=$2 | |
62 | shift | |
63 | shift | |
64 | local DOC="$*" | |
65 | if [ $HELP -eq 0 ] | |
66 | then | |
67 | local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_') | |
68 | local V="CFG_${UOP}" | |
69 | eval $V="$DEFAULT" | |
70 | for arg in $CFG_ARGS | |
71 | do | |
72 | if echo "$arg" | grep -q -- "--$OP=" | |
73 | then | |
74 | val=$(echo "$arg" | cut -f2 -d=) | |
75 | eval $V=$val | |
76 | fi | |
77 | done | |
78 | putvar $V | |
79 | else | |
80 | if [ -z "$DEFAULT" ] | |
81 | then | |
82 | DEFAULT="<none>" | |
83 | fi | |
84 | OP="${OP}=[${DEFAULT}]" | |
85 | printf " --%-30s %s\n" "$OP" "$DOC" | |
86 | fi | |
87 | } | |
88 | ||
89 | opt() { | |
90 | BOOL_OPTIONS="$BOOL_OPTIONS $1" | |
91 | ||
92 | local OP=$1 | |
93 | local DEFAULT=$2 | |
94 | shift | |
95 | shift | |
96 | local DOC="$*" | |
97 | local FLAG="" | |
98 | ||
99 | if [ $DEFAULT -eq 0 ] | |
100 | then | |
101 | FLAG="enable" | |
102 | else | |
103 | FLAG="disable" | |
104 | DOC="don't $DOC" | |
105 | fi | |
106 | ||
107 | if [ $HELP -eq 0 ] | |
108 | then | |
109 | for arg in $CFG_ARGS | |
110 | do | |
111 | if [ "$arg" = "--${FLAG}-${OP}" ] | |
112 | then | |
113 | OP=$(echo $OP | tr 'a-z-' 'A-Z_') | |
114 | FLAG=$(echo $FLAG | tr 'a-z' 'A-Z') | |
115 | local V="CFG_${FLAG}_${OP}" | |
116 | eval $V=1 | |
117 | putvar $V | |
118 | fi | |
119 | done | |
120 | else | |
121 | if [ ! -z "$META" ] | |
122 | then | |
123 | OP="$OP=<$META>" | |
124 | fi | |
125 | printf " --%-30s %s\n" "$FLAG-$OP" "$DOC" | |
126 | fi | |
127 | } | |
128 | ||
129 | flag() { | |
130 | BOOL_OPTIONS="$BOOL_OPTIONS $1" | |
131 | ||
132 | local OP=$1 | |
133 | shift | |
134 | local DOC="$*" | |
135 | ||
136 | if [ $HELP -eq 0 ] | |
137 | then | |
138 | for arg in $CFG_ARGS | |
139 | do | |
140 | if [ "$arg" = "--${OP}" ] | |
141 | then | |
142 | OP=$(echo $OP | tr 'a-z-' 'A-Z_') | |
143 | local V="CFG_${OP}" | |
144 | eval $V=1 | |
145 | putvar $V | |
146 | fi | |
147 | done | |
148 | else | |
149 | if [ ! -z "$META" ] | |
150 | then | |
151 | OP="$OP=<$META>" | |
152 | fi | |
153 | printf " --%-30s %s\n" "$OP" "$DOC" | |
154 | fi | |
155 | } | |
156 | ||
157 | validate_opt () { | |
158 | for arg in $CFG_ARGS | |
159 | do | |
160 | isArgValid=0 | |
161 | for option in $BOOL_OPTIONS | |
162 | do | |
163 | if test --disable-$option = $arg | |
164 | then | |
165 | isArgValid=1 | |
166 | fi | |
167 | if test --enable-$option = $arg | |
168 | then | |
169 | isArgValid=1 | |
170 | fi | |
171 | if test --$option = $arg | |
172 | then | |
173 | isArgValid=1 | |
174 | fi | |
175 | done | |
176 | for option in $VAL_OPTIONS | |
177 | do | |
178 | if echo "$arg" | grep -q -- "--$option=" | |
179 | then | |
180 | isArgValid=1 | |
181 | fi | |
182 | done | |
183 | if [ "$arg" = "--help" ] | |
184 | then | |
185 | echo | |
186 | echo "No more help available for Configure options," | |
187 | echo "check the Wiki or join our IRC channel" | |
188 | break | |
189 | else | |
190 | if test $isArgValid -eq 0 | |
191 | then | |
192 | err "Option '$arg' is not recognized" | |
193 | fi | |
194 | fi | |
195 | done | |
196 | } | |
197 | ||
198 | msg "looking for programs" | |
199 | msg | |
200 | ||
201 | need_cmd tar | |
202 | need_cmd cp | |
203 | need_cmd rm | |
204 | need_cmd mkdir | |
205 | need_cmd echo | |
206 | need_cmd tr | |
207 | ||
208 | CFG_SRC_DIR="$(cd $(dirname $0) && pwd)" | |
209 | CFG_SELF="$0" | |
210 | CFG_ARGS="$@" | |
211 | ||
212 | HELP=0 | |
213 | if [ "$1" = "--help" ] | |
214 | then | |
215 | HELP=1 | |
216 | shift | |
217 | echo | |
218 | echo "Usage: $CFG_SELF [options]" | |
219 | echo | |
220 | echo "Options:" | |
221 | echo | |
222 | else | |
223 | step_msg "processing $CFG_SELF args" | |
224 | fi | |
225 | ||
226 | valopt product-name "Product" "The name of the product, for display" | |
227 | valopt package-name "package" "The name of the package, tarball" | |
228 | valopt verify-bin "" "The command to run with --version to verify the install works" | |
229 | valopt rel-manifest-dir "${CFG_PACKAGE_NAME}lib" "The directory under lib/ where the manifest lives" | |
230 | valopt success-message "Installed." "The string to print after successful installation" | |
231 | valopt legacy-manifest-dirs "" "Places to look for legacy manifests to uninstall" | |
232 | valopt input-tarballs "" "Installers to combine" | |
233 | valopt non-installed-overlay "" "Directory containing files that should not be installed" | |
234 | valopt work-dir "./workdir" "The directory to do temporary work and put the final image" | |
235 | valopt output-dir "./dist" "The location to put the final tarball" | |
236 | ||
237 | if [ $HELP -eq 1 ] | |
238 | then | |
239 | echo | |
240 | exit 0 | |
241 | fi | |
242 | ||
243 | step_msg "validating $CFG_SELF args" | |
244 | validate_opt | |
245 | ||
246 | RUST_INSTALLER_VERSION=`cat "$CFG_SRC_DIR/rust-installer-version"` | |
247 | ||
248 | # Create the work directory for the new installer | |
249 | mkdir -p "$CFG_WORK_DIR" | |
250 | need_ok "couldn't create work dir" | |
251 | ||
252 | rm -Rf "$CFG_WORK_DIR/$CFG_PACKAGE_NAME" | |
253 | need_ok "couldn't delete work package dir" | |
254 | ||
255 | mkdir -p "$CFG_WORK_DIR/$CFG_PACKAGE_NAME" | |
256 | need_ok "couldn't create work package dir" | |
257 | ||
258 | INPUT_TARBALLS=`echo "$CFG_INPUT_TARBALLS" | sed 's/,/ /g'` | |
259 | ||
260 | # Merge each installer into the work directory of the new installer | |
261 | for input_tarball in $INPUT_TARBALLS; do | |
262 | ||
263 | # Extract the input tarballs | |
264 | tar xzf $input_tarball -C "$CFG_WORK_DIR" | |
265 | need_ok "failed to extract tarball" | |
266 | ||
267 | # Verify the version number | |
268 | PKG_NAME=`echo "$input_tarball" | sed s/\.tar\.gz//g` | |
269 | PKG_NAME=`basename $PKG_NAME` | |
270 | VERSION=`cat "$CFG_WORK_DIR/$PKG_NAME/rust-installer-version"` | |
271 | if [ "$RUST_INSTALLER_VERSION" != "$VERSION" ]; then | |
272 | err "incorrect installer version in $input_tarball" | |
273 | fi | |
274 | ||
275 | # Interpret the manifest to copy the contents to the new installer | |
276 | COMPONENTS=`cat "$CFG_WORK_DIR/$PKG_NAME/components"` | |
277 | for component in $COMPONENTS; do | |
278 | while read directive; do | |
279 | COMMAND=`echo $directive | cut -f1 -d:` | |
280 | FILE=`echo $directive | cut -f2 -d:` | |
281 | ||
282 | NEW_FILE_PATH="$CFG_WORK_DIR/$CFG_PACKAGE_NAME/$FILE" | |
283 | mkdir -p "$(dirname $NEW_FILE_PATH)" | |
284 | ||
285 | case "$COMMAND" in | |
286 | file | dir) | |
287 | if [ -e "$NEW_FILE_PATH" ]; then | |
288 | err "file $NEW_FILE_PATH already exists" | |
289 | fi | |
290 | cp -R "$CFG_WORK_DIR/$PKG_NAME/$FILE" "$NEW_FILE_PATH" | |
291 | need_ok "failed to copy file $FILE" | |
292 | ;; | |
293 | ||
294 | * ) | |
295 | err "unknown command" | |
296 | ;; | |
297 | ||
298 | esac | |
299 | done < "$CFG_WORK_DIR/$PKG_NAME/manifest-$component.in" | |
300 | ||
301 | # Copy the manifest | |
302 | if [ -e "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/manifest-$component.in" ]; then | |
303 | err "manifest for $component already exists" | |
304 | fi | |
305 | cp "$CFG_WORK_DIR/$PKG_NAME/manifest-$component.in" "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/manifest-$component.in" | |
306 | need_ok "failed to copy manifest for $component" | |
307 | ||
308 | # Merge the component name | |
309 | echo "$component" >> "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/components" | |
310 | need_ok "failed to merge component $component" | |
311 | done | |
312 | done | |
313 | ||
314 | # Write the version number | |
315 | echo "$RUST_INSTALLER_VERSION" > "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/rust-installer-version" | |
316 | ||
317 | # Copy the overlay | |
318 | if [ -n "$CFG_NON_INSTALLED_OVERLAY" ]; then | |
319 | OVERLAY_FILES=`(cd "$CFG_NON_INSTALLED_OVERLAY" && find . -type f)` | |
320 | for f in $OVERLAY_FILES; do | |
321 | if [ -e "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/$f" ]; then err "overlay $f exists"; fi | |
322 | ||
323 | cp "$CFG_NON_INSTALLED_OVERLAY/$f" "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/$f" | |
324 | need_ok "failed to copy overlay $f" | |
325 | done | |
326 | fi | |
327 | ||
328 | # Generate the install script | |
329 | "$CFG_SRC_DIR/gen-install-script.sh" \ | |
330 | --product-name="$CFG_PRODUCT_NAME" \ | |
331 | --verify-bin="$CFG_VERIFY_BIN" \ | |
332 | --rel-manifest-dir="$CFG_REL_MANIFEST_DIR" \ | |
333 | --success-message="$CFG_SUCCESS_MESSAGE" \ | |
334 | --legacy-manifest-dirs="$CFG_LEGACY_MANIFEST_DIRS" \ | |
335 | --output-script="$CFG_WORK_DIR/$CFG_PACKAGE_NAME/install.sh" | |
336 | ||
337 | need_ok "failed to generate install script" | |
338 | ||
339 | mkdir -p "$CFG_OUTPUT_DIR" | |
340 | need_ok "couldn't create output dir" | |
341 | ||
342 | rm -Rf "$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME.tar.gz" | |
343 | need_ok "couldn't delete old tarball" | |
344 | ||
345 | # Make a tarball | |
346 | tar -czf "$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME.tar.gz" -C "$CFG_WORK_DIR" "$CFG_PACKAGE_NAME" | |
347 | need_ok "failed to tar" |