Skip to content

Commit b787d33

Browse files
authored
Merge pull request #62 from cuviper/oxidize
[WIP] Rewrite the rust-installer in Rust
2 parents 2e6417f + 2cb08f7 commit b787d33

16 files changed

+1782
-1158
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*~
2-
tmp
2+
tmp
3+
target/
4+
**/*.rs.bk
5+
Cargo.lock

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
addons:
2-
apt:
3-
packages:
4-
- p7zip-full
5-
1+
language: rust
62
script:
3+
- cargo build
74
- ./test.sh

Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "installer"
4+
version = "0.0.0"
5+
6+
[[bin]]
7+
doc = false
8+
name = "rust-installer"
9+
path = "src/main.rs"
10+
11+
[dependencies]
12+
error-chain = "0.10.0"
13+
flate2 = "0.2.19"
14+
tar = "0.4.11"
15+
walkdir = "1.0.7"
16+
xz2 = "0.1.3"
17+
18+
[dependencies.clap]
19+
features = ["yaml"]
20+
version = "2.22.1"
21+
22+
[target."cfg(windows)".dependencies]
23+
lazy_static = "0.2.8"
24+
kernel32-sys = "0.2.2"
25+
winapi = "0.2.8"

combine-installers.sh

Lines changed: 2 additions & 312 deletions
Original file line numberDiff line numberDiff line change
@@ -9,194 +9,7 @@
99
# option. This file may not be copied, modified, or distributed
1010
# except according to those terms.
1111

12-
set -u
13-
14-
msg() {
15-
echo "combine-installers: ${1-}"
16-
}
17-
18-
step_msg() {
19-
msg
20-
msg "$1"
21-
msg
22-
}
23-
24-
warn() {
25-
echo "combine-installers: WARNING: $1" >&2
26-
}
27-
28-
err() {
29-
echo "combine-installers: error: $1" >&2
30-
exit 1
31-
}
32-
33-
need_ok() {
34-
if [ $? -ne 0 ]
35-
then
36-
err "$1"
37-
fi
38-
}
39-
40-
need_cmd() {
41-
if command -v $1 >/dev/null 2>&1
42-
then msg "found $1"
43-
else err "need $1"
44-
fi
45-
}
46-
47-
putvar() {
48-
local t
49-
local tlen
50-
eval t=\$$1
51-
eval tlen=\${#$1}
52-
if [ $tlen -gt 35 ]
53-
then
54-
printf "combine-installers: %-20s := %.35s ...\n" $1 "$t"
55-
else
56-
printf "combine-installers: %-20s := %s %s\n" $1 "$t"
57-
fi
58-
}
59-
60-
valopt() {
61-
VAL_OPTIONS="$VAL_OPTIONS $1"
62-
63-
local op=$1
64-
local default=$2
65-
shift
66-
shift
67-
local doc="$*"
68-
if [ $HELP -eq 0 ]
69-
then
70-
local uop=$(echo $op | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
71-
local v="CFG_${uop}"
72-
eval $v="$default"
73-
for arg in $CFG_ARGS
74-
do
75-
if echo "$arg" | grep -q -- "--$op="
76-
then
77-
local val=$(echo "$arg" | cut -f2 -d=)
78-
eval $v=$val
79-
fi
80-
done
81-
putvar $v
82-
else
83-
if [ -z "$default" ]
84-
then
85-
default="<none>"
86-
fi
87-
op="${default}=[${default}]"
88-
printf " --%-30s %s\n" "$op" "$doc"
89-
fi
90-
}
91-
92-
opt() {
93-
BOOL_OPTIONS="$BOOL_OPTIONS $1"
94-
95-
local op=$1
96-
local default=$2
97-
shift
98-
shift
99-
local doc="$*"
100-
local flag=""
101-
102-
if [ $default -eq 0 ]
103-
then
104-
flag="enable"
105-
else
106-
flag="disable"
107-
doc="don't $doc"
108-
fi
109-
110-
if [ $HELP -eq 0 ]
111-
then
112-
for arg in $CFG_ARGS
113-
do
114-
if [ "$arg" = "--${flag}-${op}" ]
115-
then
116-
op=$(echo $op | tr 'a-z-' 'A-Z_')
117-
flag=$(echo $flag | tr 'a-z' 'A-Z')
118-
local v="CFG_${flag}_${op}"
119-
eval $v=1
120-
putvar $v
121-
fi
122-
done
123-
else
124-
if [ ! -z "$META" ]
125-
then
126-
op="$op=<$META>"
127-
fi
128-
printf " --%-30s %s\n" "$flag-$op" "$doc"
129-
fi
130-
}
131-
132-
flag() {
133-
BOOL_OPTIONS="$BOOL_OPTIONS $1"
134-
135-
local op=$1
136-
shift
137-
local doc="$*"
138-
139-
if [ $HELP -eq 0 ]
140-
then
141-
for arg in $CFG_ARGS
142-
do
143-
if [ "$arg" = "--${op}" ]
144-
then
145-
op=$(echo $op | tr 'a-z-' 'A-Z_')
146-
local v="CFG_${op}"
147-
eval $v=1
148-
putvar $v
149-
fi
150-
done
151-
else
152-
if [ ! -z "$META" ]
153-
then
154-
op="$op=<$META>"
155-
fi
156-
printf " --%-30s %s\n" "$op" "$doc"
157-
fi
158-
}
159-
160-
validate_opt () {
161-
for arg in $CFG_ARGS
162-
do
163-
local is_arg_valid=0
164-
for option in $BOOL_OPTIONS
165-
do
166-
if test --disable-$option = $arg
167-
then
168-
is_arg_valid=1
169-
fi
170-
if test --enable-$option = $arg
171-
then
172-
is_arg_valid=1
173-
fi
174-
if test --$option = $arg
175-
then
176-
is_arg_valid=1
177-
fi
178-
done
179-
for option in $VAL_OPTIONS
180-
do
181-
if echo "$arg" | grep -q -- "--$option="
182-
then
183-
is_arg_valid=1
184-
fi
185-
done
186-
if [ "$arg" = "--help" ]
187-
then
188-
echo
189-
echo "No more help available for Configure options,"
190-
echo "check the Wiki or join our IRC channel"
191-
break
192-
else
193-
if test $is_arg_valid -eq 0
194-
then
195-
err "Option '$arg' is not recognized"
196-
fi
197-
fi
198-
done
199-
}
12+
set -ue
20013

20114
# Prints the absolute path of a directory to stdout
20215
abs_path() {
@@ -207,128 +20,5 @@ abs_path() {
20720
(unset CDPATH && cd "$path" > /dev/null && pwd)
20821
}
20922

210-
msg "looking for programs"
211-
msg
212-
213-
need_cmd tar
214-
need_cmd cp
215-
need_cmd rm
216-
need_cmd mkdir
217-
need_cmd echo
218-
need_cmd tr
219-
220-
CFG_ARGS="$@"
221-
222-
HELP=0
223-
if [ "$1" = "--help" ]
224-
then
225-
HELP=1
226-
shift
227-
echo
228-
echo "Usage: $0 [options]"
229-
echo
230-
echo "Options:"
231-
echo
232-
else
233-
step_msg "processing arguments"
234-
fi
235-
236-
OPTIONS=""
237-
BOOL_OPTIONS=""
238-
VAL_OPTIONS=""
239-
240-
valopt product-name "Product" "The name of the product, for display"
241-
valopt package-name "package" "The name of the package, tarball"
242-
valopt rel-manifest-dir "${CFG_PACKAGE_NAME}lib" "The directory under lib/ where the manifest lives"
243-
valopt success-message "Installed." "The string to print after successful installation"
244-
valopt legacy-manifest-dirs "" "Places to look for legacy manifests to uninstall"
245-
valopt input-tarballs "" "Installers to combine"
246-
valopt non-installed-overlay "" "Directory containing files that should not be installed"
247-
valopt work-dir "./workdir" "The directory to do temporary work and put the final image"
248-
valopt output-dir "./dist" "The location to put the final tarball"
249-
250-
if [ $HELP -eq 1 ]
251-
then
252-
echo
253-
exit 0
254-
fi
255-
256-
step_msg "validating arguments"
257-
validate_opt
258-
25923
src_dir="$(abs_path $(dirname "$0"))"
260-
261-
rust_installer_version=`cat "$src_dir/rust-installer-version"`
262-
263-
# Create the work directory for the new installer
264-
mkdir -p "$CFG_WORK_DIR"
265-
need_ok "couldn't create work dir"
266-
267-
rm -Rf "$CFG_WORK_DIR/$CFG_PACKAGE_NAME"
268-
need_ok "couldn't delete work package dir"
269-
270-
mkdir -p "$CFG_WORK_DIR/$CFG_PACKAGE_NAME"
271-
need_ok "couldn't create work package dir"
272-
273-
input_tarballs=`echo "$CFG_INPUT_TARBALLS" | sed 's/,/ /g'`
274-
275-
# Merge each installer into the work directory of the new installer
276-
for input_tarball in $input_tarballs; do
277-
278-
# Extract the input tarballs
279-
tar xzf $input_tarball -C "$CFG_WORK_DIR"
280-
need_ok "failed to extract tarball"
281-
282-
# Verify the version number
283-
pkg_name=`echo "$input_tarball" | sed s/\.tar\.gz//g`
284-
pkg_name=`basename $pkg_name`
285-
version=`cat "$CFG_WORK_DIR/$pkg_name/rust-installer-version"`
286-
if [ "$rust_installer_version" != "$version" ]; then
287-
err "incorrect installer version in $input_tarball"
288-
fi
289-
290-
# Copy components to new combined installer
291-
components=`cat "$CFG_WORK_DIR/$pkg_name/components"`
292-
for component in $components; do
293-
294-
# All we need to do is copy the component directory
295-
cp -R "$CFG_WORK_DIR/$pkg_name/$component" "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/$component"
296-
need_ok "failed to copy component $component"
297-
298-
# Merge the component name
299-
echo "$component" >> "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/components"
300-
need_ok "failed to merge component $component"
301-
done
302-
done
303-
304-
# Write the version number
305-
echo "$rust_installer_version" > "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/rust-installer-version"
306-
307-
# Copy the overlay
308-
if [ -n "$CFG_NON_INSTALLED_OVERLAY" ]; then
309-
overlay_files=`(cd "$CFG_NON_INSTALLED_OVERLAY" && find . -type f)`
310-
for f in $overlay_files; do
311-
if [ -e "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/$f" ]; then err "overlay $f exists"; fi
312-
313-
cp "$CFG_NON_INSTALLED_OVERLAY/$f" "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/$f"
314-
need_ok "failed to copy overlay $f"
315-
done
316-
fi
317-
318-
# Generate the install script
319-
"$src_dir/gen-install-script.sh" \
320-
--product-name="$CFG_PRODUCT_NAME" \
321-
--rel-manifest-dir="$CFG_REL_MANIFEST_DIR" \
322-
--success-message="$CFG_SUCCESS_MESSAGE" \
323-
--legacy-manifest-dirs="$CFG_LEGACY_MANIFEST_DIRS" \
324-
--output-script="$CFG_WORK_DIR/$CFG_PACKAGE_NAME/install.sh"
325-
326-
need_ok "failed to generate install script"
327-
328-
mkdir -p "$CFG_OUTPUT_DIR"
329-
need_ok "couldn't create output dir"
330-
331-
"$src_dir/make-tarballs.sh" \
332-
--work-dir="$CFG_WORK_DIR" \
333-
--input="$CFG_PACKAGE_NAME" \
334-
--output="$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME"
24+
cargo run --manifest-path="$src_dir/Cargo.toml" -- combine "$@"

0 commit comments

Comments
 (0)