]> git.proxmox.com Git - rustc.git/blame - src/rust-installer/test/rust-installer-v2/combine-installers.sh
New upstream version 1.16.0+dfsg1
[rustc.git] / src / rust-installer / test / rust-installer-v2 / combine-installers.sh
CommitLineData
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
12msg() {
13 echo "combine-installers: $1"
14}
15
16step_msg() {
17 msg
18 msg "$1"
19 msg
20}
21
22warn() {
23 echo "combine-installers: WARNING: $1"
24}
25
26err() {
27 echo "combine-installers: error: $1"
28 exit 1
29}
30
31need_ok() {
32 if [ $? -ne 0 ]
33 then
34 err "$1"
35 fi
36}
37
38need_cmd() {
39 if command -v $1 >/dev/null 2>&1
40 then msg "found $1"
41 else err "need $1"
42 fi
43}
44
45putvar() {
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
57valopt() {
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
89opt() {
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
129flag() {
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
157validate_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
198msg "looking for programs"
199msg
200
201need_cmd tar
202need_cmd cp
203need_cmd rm
204need_cmd mkdir
205need_cmd echo
206need_cmd tr
207
208CFG_SRC_DIR="$(cd $(dirname $0) && pwd)"
209CFG_SELF="$0"
210CFG_ARGS="$@"
211
212HELP=0
213if [ "$1" = "--help" ]
214then
215 HELP=1
216 shift
217 echo
218 echo "Usage: $CFG_SELF [options]"
219 echo
220 echo "Options:"
221 echo
222else
223 step_msg "processing $CFG_SELF args"
224fi
225
226valopt product-name "Product" "The name of the product, for display"
227valopt package-name "package" "The name of the package, tarball"
228valopt verify-bin "" "The command to run with --version to verify the install works"
229valopt rel-manifest-dir "${CFG_PACKAGE_NAME}lib" "The directory under lib/ where the manifest lives"
230valopt success-message "Installed." "The string to print after successful installation"
231valopt legacy-manifest-dirs "" "Places to look for legacy manifests to uninstall"
232valopt input-tarballs "" "Installers to combine"
233valopt non-installed-overlay "" "Directory containing files that should not be installed"
234valopt work-dir "./workdir" "The directory to do temporary work and put the final image"
235valopt output-dir "./dist" "The location to put the final tarball"
236
237if [ $HELP -eq 1 ]
238then
239 echo
240 exit 0
241fi
242
243step_msg "validating $CFG_SELF args"
244validate_opt
245
246RUST_INSTALLER_VERSION=`cat "$CFG_SRC_DIR/rust-installer-version"`
247
248# Create the work directory for the new installer
249mkdir -p "$CFG_WORK_DIR"
250need_ok "couldn't create work dir"
251
252rm -Rf "$CFG_WORK_DIR/$CFG_PACKAGE_NAME"
253need_ok "couldn't delete work package dir"
254
255mkdir -p "$CFG_WORK_DIR/$CFG_PACKAGE_NAME"
256need_ok "couldn't create work package dir"
257
258INPUT_TARBALLS=`echo "$CFG_INPUT_TARBALLS" | sed 's/,/ /g'`
259
260# Merge each installer into the work directory of the new installer
261for 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
312done
313
314# Write the version number
315echo "$RUST_INSTALLER_VERSION" > "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/rust-installer-version"
316
317# Copy the overlay
318if [ -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
326fi
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
337need_ok "failed to generate install script"
338
339mkdir -p "$CFG_OUTPUT_DIR"
340need_ok "couldn't create output dir"
341
342rm -Rf "$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME.tar.gz"
343need_ok "couldn't delete old tarball"
344
345# Make a tarball
346tar -czf "$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME.tar.gz" -C "$CFG_WORK_DIR" "$CFG_PACKAGE_NAME"
347need_ok "failed to tar"