Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Rewrite the rust-installer in Rust #62

Merged
merged 21 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*~
tmp
tmp
target/
**/*.rs.bk
Cargo.lock
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
addons:
apt:
packages:
- p7zip-full

language: rust
script:
- cargo build
- ./test.sh
25 changes: 25 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
authors = ["The Rust Project Developers"]
name = "installer"
version = "0.0.0"

[[bin]]
doc = false
name = "rust-installer"
path = "src/main.rs"

[dependencies]
error-chain = "0.10.0"
flate2 = "0.2.19"
tar = "0.4.11"
walkdir = "1.0.7"
xz2 = "0.1.3"

[dependencies.clap]
features = ["yaml"]
version = "2.22.1"

[target."cfg(windows)".dependencies]
lazy_static = "0.2.8"
kernel32-sys = "0.2.2"
winapi = "0.2.8"
314 changes: 2 additions & 312 deletions combine-installers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,194 +9,7 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

set -u

msg() {
echo "combine-installers: ${1-}"
}

step_msg() {
msg
msg "$1"
msg
}

warn() {
echo "combine-installers: WARNING: $1" >&2
}

err() {
echo "combine-installers: error: $1" >&2
exit 1
}

need_ok() {
if [ $? -ne 0 ]
then
err "$1"
fi
}

need_cmd() {
if command -v $1 >/dev/null 2>&1
then msg "found $1"
else err "need $1"
fi
}

putvar() {
local t
local tlen
eval t=\$$1
eval tlen=\${#$1}
if [ $tlen -gt 35 ]
then
printf "combine-installers: %-20s := %.35s ...\n" $1 "$t"
else
printf "combine-installers: %-20s := %s %s\n" $1 "$t"
fi
}

valopt() {
VAL_OPTIONS="$VAL_OPTIONS $1"

local op=$1
local default=$2
shift
shift
local doc="$*"
if [ $HELP -eq 0 ]
then
local uop=$(echo $op | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
local v="CFG_${uop}"
eval $v="$default"
for arg in $CFG_ARGS
do
if echo "$arg" | grep -q -- "--$op="
then
local val=$(echo "$arg" | cut -f2 -d=)
eval $v=$val
fi
done
putvar $v
else
if [ -z "$default" ]
then
default="<none>"
fi
op="${default}=[${default}]"
printf " --%-30s %s\n" "$op" "$doc"
fi
}

opt() {
BOOL_OPTIONS="$BOOL_OPTIONS $1"

local op=$1
local default=$2
shift
shift
local doc="$*"
local flag=""

if [ $default -eq 0 ]
then
flag="enable"
else
flag="disable"
doc="don't $doc"
fi

if [ $HELP -eq 0 ]
then
for arg in $CFG_ARGS
do
if [ "$arg" = "--${flag}-${op}" ]
then
op=$(echo $op | tr 'a-z-' 'A-Z_')
flag=$(echo $flag | tr 'a-z' 'A-Z')
local v="CFG_${flag}_${op}"
eval $v=1
putvar $v
fi
done
else
if [ ! -z "$META" ]
then
op="$op=<$META>"
fi
printf " --%-30s %s\n" "$flag-$op" "$doc"
fi
}

flag() {
BOOL_OPTIONS="$BOOL_OPTIONS $1"

local op=$1
shift
local doc="$*"

if [ $HELP -eq 0 ]
then
for arg in $CFG_ARGS
do
if [ "$arg" = "--${op}" ]
then
op=$(echo $op | tr 'a-z-' 'A-Z_')
local v="CFG_${op}"
eval $v=1
putvar $v
fi
done
else
if [ ! -z "$META" ]
then
op="$op=<$META>"
fi
printf " --%-30s %s\n" "$op" "$doc"
fi
}

validate_opt () {
for arg in $CFG_ARGS
do
local is_arg_valid=0
for option in $BOOL_OPTIONS
do
if test --disable-$option = $arg
then
is_arg_valid=1
fi
if test --enable-$option = $arg
then
is_arg_valid=1
fi
if test --$option = $arg
then
is_arg_valid=1
fi
done
for option in $VAL_OPTIONS
do
if echo "$arg" | grep -q -- "--$option="
then
is_arg_valid=1
fi
done
if [ "$arg" = "--help" ]
then
echo
echo "No more help available for Configure options,"
echo "check the Wiki or join our IRC channel"
break
else
if test $is_arg_valid -eq 0
then
err "Option '$arg' is not recognized"
fi
fi
done
}
set -ue

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

msg "looking for programs"
msg

need_cmd tar
need_cmd cp
need_cmd rm
need_cmd mkdir
need_cmd echo
need_cmd tr

CFG_ARGS="$@"

HELP=0
if [ "$1" = "--help" ]
then
HELP=1
shift
echo
echo "Usage: $0 [options]"
echo
echo "Options:"
echo
else
step_msg "processing arguments"
fi

OPTIONS=""
BOOL_OPTIONS=""
VAL_OPTIONS=""

valopt product-name "Product" "The name of the product, for display"
valopt package-name "package" "The name of the package, tarball"
valopt rel-manifest-dir "${CFG_PACKAGE_NAME}lib" "The directory under lib/ where the manifest lives"
valopt success-message "Installed." "The string to print after successful installation"
valopt legacy-manifest-dirs "" "Places to look for legacy manifests to uninstall"
valopt input-tarballs "" "Installers to combine"
valopt non-installed-overlay "" "Directory containing files that should not be installed"
valopt work-dir "./workdir" "The directory to do temporary work and put the final image"
valopt output-dir "./dist" "The location to put the final tarball"

if [ $HELP -eq 1 ]
then
echo
exit 0
fi

step_msg "validating arguments"
validate_opt

src_dir="$(abs_path $(dirname "$0"))"

rust_installer_version=`cat "$src_dir/rust-installer-version"`

# Create the work directory for the new installer
mkdir -p "$CFG_WORK_DIR"
need_ok "couldn't create work dir"

rm -Rf "$CFG_WORK_DIR/$CFG_PACKAGE_NAME"
need_ok "couldn't delete work package dir"

mkdir -p "$CFG_WORK_DIR/$CFG_PACKAGE_NAME"
need_ok "couldn't create work package dir"

input_tarballs=`echo "$CFG_INPUT_TARBALLS" | sed 's/,/ /g'`

# Merge each installer into the work directory of the new installer
for input_tarball in $input_tarballs; do

# Extract the input tarballs
tar xzf $input_tarball -C "$CFG_WORK_DIR"
need_ok "failed to extract tarball"

# Verify the version number
pkg_name=`echo "$input_tarball" | sed s/\.tar\.gz//g`
pkg_name=`basename $pkg_name`
version=`cat "$CFG_WORK_DIR/$pkg_name/rust-installer-version"`
if [ "$rust_installer_version" != "$version" ]; then
err "incorrect installer version in $input_tarball"
fi

# Copy components to new combined installer
components=`cat "$CFG_WORK_DIR/$pkg_name/components"`
for component in $components; do

# All we need to do is copy the component directory
cp -R "$CFG_WORK_DIR/$pkg_name/$component" "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/$component"
need_ok "failed to copy component $component"

# Merge the component name
echo "$component" >> "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/components"
need_ok "failed to merge component $component"
done
done

# Write the version number
echo "$rust_installer_version" > "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/rust-installer-version"

# Copy the overlay
if [ -n "$CFG_NON_INSTALLED_OVERLAY" ]; then
overlay_files=`(cd "$CFG_NON_INSTALLED_OVERLAY" && find . -type f)`
for f in $overlay_files; do
if [ -e "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/$f" ]; then err "overlay $f exists"; fi

cp "$CFG_NON_INSTALLED_OVERLAY/$f" "$CFG_WORK_DIR/$CFG_PACKAGE_NAME/$f"
need_ok "failed to copy overlay $f"
done
fi

# Generate the install script
"$src_dir/gen-install-script.sh" \
--product-name="$CFG_PRODUCT_NAME" \
--rel-manifest-dir="$CFG_REL_MANIFEST_DIR" \
--success-message="$CFG_SUCCESS_MESSAGE" \
--legacy-manifest-dirs="$CFG_LEGACY_MANIFEST_DIRS" \
--output-script="$CFG_WORK_DIR/$CFG_PACKAGE_NAME/install.sh"

need_ok "failed to generate install script"

mkdir -p "$CFG_OUTPUT_DIR"
need_ok "couldn't create output dir"

"$src_dir/make-tarballs.sh" \
--work-dir="$CFG_WORK_DIR" \
--input="$CFG_PACKAGE_NAME" \
--output="$CFG_OUTPUT_DIR/$CFG_PACKAGE_NAME"
cargo run --manifest-path="$src_dir/Cargo.toml" -- combine "$@"
Loading