summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--install-template.sh28
-rwxr-xr-xtest.sh31
2 files changed, 55 insertions, 4 deletions
diff --git a/install-template.sh b/install-template.sh
index 2dcdb29..132380f 100644
--- a/install-template.sh
+++ b/install-template.sh
@@ -224,7 +224,7 @@ need_cmd chmod
CFG_ARGS="$@"
HELP=0
-if [ "$1" = "--help" ]
+if [ "${1-}" = "--help" ]
then
HELP=1
shift
@@ -288,6 +288,18 @@ TEMPLATE_RUST_INSTALLER_VERSION=%%TEMPLATE_RUST_INSTALLER_VERSION%%
# This is where we are installing from
src_dir="$(cd $(dirname "$0") && pwd)"
+# The name of the script
+src_basename="$(basename "$0")"
+
+# If we've been run as 'uninstall.sh' (from the existing installation)
+# then we're doing a full uninstall, as opposed to the --uninstall flag
+# which just means 'uninstall my components'.
+if [ "$src_basename" = "uninstall.sh" ]; then
+ CFG_UNINSTALL=1
+ CFG_DESTDIR_PREFIX="$(cd "$src_dir/../../" && pwd)"
+ CFG_LIBDIR="$(cd "$src_dir/../" && pwd)"
+fi
+
# This is where we are installing to
dest_prefix="$CFG_DESTDIR_PREFIX"
@@ -375,12 +387,14 @@ need_ok "failed to remove install probe"
# That would surely cause chaos.
msg "verifying destination is not the same as source"
prefix_dir="$(cd "$dest_prefix" && pwd)"
-if [ "$src_dir" = "$prefix_dir" ]
-then
+if [ "$src_dir" = "$prefix_dir" -a "${CFG_UNINSTALL-}" != 1 ]; then
err "cannot install to same directory as installer"
fi
-# Open the components file to get the list of components to install
+# Open the components file to get the list of components to install.
+# NB: During install this components file is read from the installer's
+# source dir, during a full uninstall it's read from the manifest dir,
+# and thus contains all installed components.
components=`cat "$src_dir/components"`
# Sanity check: do we have components?
@@ -695,6 +709,12 @@ if [ "$ostype" = "unknown-linux-gnu" -a ! -n "${CFG_DISABLE_LDCONFIG-}" ]; then
fi
fi
+# Install the uninstaller
+uninstaller="$abs_libdir/$TEMPLATE_REL_MANIFEST_DIR/uninstall.sh"
+msg "creating uninstall script at $uninstaller"
+cp "$src_dir/$src_basename" "$uninstaller"
+need_ok "unable to install uninstaller"
+
echo
echo " $TEMPLATE_SUCCESS_MESSAGE"
echo
diff --git a/test.sh b/test.sh
index 2ca955c..67b075e 100755
--- a/test.sh
+++ b/test.sh
@@ -358,6 +358,37 @@ multiple_components() {
}
runtest multiple_components
+uninstall_from_installed_script() {
+ try sh "$S/gen-installer.sh" \
+ --image-dir="$TEST_DIR/image1" \
+ --work-dir="$WORK_DIR/c1" \
+ --output-dir="$OUT_DIR/c1" \
+ --component-name=rustc
+ try sh "$S/gen-installer.sh" \
+ --image-dir="$TEST_DIR/image3" \
+ --work-dir="$WORK_DIR/c2" \
+ --output-dir="$OUT_DIR/c2" \
+ --component-name=cargo
+ try "$WORK_DIR/c1/package/install.sh" --prefix="$PREFIX_DIR"
+ try "$WORK_DIR/c2/package/install.sh" --prefix="$PREFIX_DIR"
+ try test -e "$PREFIX_DIR/something-to-install"
+ try test -e "$PREFIX_DIR/dir-to-install/foo"
+ try test -e "$PREFIX_DIR/bin/program"
+ try test -e "$PREFIX_DIR/bin/program2"
+ try test -e "$PREFIX_DIR/bin/bad-bin"
+ try test -e "$PREFIX_DIR/bin/cargo"
+ # All components should be uninstalled by this script
+ try sh "$PREFIX_DIR/lib/packagelib/uninstall.sh"
+ try test ! -e "$PREFIX_DIR/something-to-install"
+ try test ! -e "$PREFIX_DIR/dir-to-install/foo"
+ try test ! -e "$PREFIX_DIR/bin/program"
+ try test ! -e "$PREFIX_DIR/bin/program2"
+ try test ! -e "$PREFIX_DIR/bin/bad-bin"
+ try test ! -e "$PREFIX_DIR/bin/cargo"
+ try test ! -e "$PREFIX_DIR/lib/packagelib"
+}
+runtest uninstall_from_installed_script
+
# Combined installer tests
combine_installers() {