summaryrefslogtreecommitdiff
path: root/install-template.sh
diff options
context:
space:
mode:
Diffstat (limited to 'install-template.sh')
-rw-r--r--install-template.sh242
1 files changed, 158 insertions, 84 deletions
diff --git a/install-template.sh b/install-template.sh
index 6ca971f..16c41e3 100644
--- a/install-template.sh
+++ b/install-template.sh
@@ -346,10 +346,9 @@ fi
step_msg "validating $CFG_SELF args"
validate_opt
-
-
# Template configuration.
# These names surrounded by '%%` are replaced by sed when generating install.sh
+# FIXME: Might want to consider loading this from a file and not generating install.sh
# Rust or Cargo
TEMPLATE_PRODUCT_NAME=%%TEMPLATE_PRODUCT_NAME%%
@@ -359,6 +358,11 @@ TEMPLATE_VERIFY_BIN=%%TEMPLATE_VERIFY_BIN%%
TEMPLATE_REL_MANIFEST_DIR=%%TEMPLATE_REL_MANIFEST_DIR%%
# 'Rust is ready to roll.' or 'Cargo is cool to cruise.'
TEMPLATE_SUCCESS_MESSAGE=%%TEMPLATE_SUCCESS_MESSAGE%%
+# Locations to look for directories containing legacy, pre-versioned manifests
+TEMPLATE_LEGACY_MANIFEST_DIRS=%%TEMPLATE_LEGACY_MANIFEST_DIRS%%
+
+# The revision of the installer, bumped for incompatible changes
+INSTALLER_VERSION=2
# OK, let's get installing ...
@@ -401,57 +405,102 @@ then
err "can't install to same directory as installer"
fi
+# Open the components file to get the list of components to install
+COMPONENTS=`cat "$CFG_SRC_DIR/components"`
+
+# Sanity check: do we have components?
+if [ ! -n "$COMPONENTS" ]; then
+ err "unable to find installation components"
+fi
+
# Using an absolute path to libdir in a few places so that the status
# messages are consistently using absolute paths.
absolutify "${CFG_LIBDIR}"
ABS_LIBDIR="${ABSOLUTIFIED}"
-# The file name of the manifest we're going to create during install
-INSTALLED_MANIFEST="${ABS_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}/manifest"
+# Replace commas in legacy manifest list with spaces
+LEGACY_MANIFEST_DIRS=`echo "$TEMPLATE_LEGACY_MANIFEST_DIRS" | sed "s/,/ /g"`
-# First, uninstall from the installation prefix.
-# Errors are warnings - try to rm everything in the manifest even if some fail.
-if [ -f "${INSTALLED_MANIFEST}" ]
-then
- msg
+# Uninstall from legacy manifests
+for md in $LEGACY_MANIFEST_DIRS; do
+ # First, uninstall from the installation prefix.
+ # Errors are warnings - try to rm everything in the manifest even if some fail.
+ if [ -f "$ABS_LIBDIR/$md/manifest" ]
+ then
+ msg
- # Iterate through installed manifest and remove files
- while read p; do
- # The installed manifest contains absolute paths
- msg "removing $p"
- if [ -f "$p" ]
- then
- rm -f "$p"
- if [ $? -ne 0 ]
+ # Iterate through installed manifest and remove files
+ while read p; do
+ # The installed manifest contains absolute paths
+ msg "removing $p"
+ if [ -f "$p" ]
then
- warn "failed to remove $p"
+ rm -f "$p"
+ if [ $? -ne 0 ]
+ then
+ warn "failed to remove $p"
+ fi
+ else
+ warn "supposedly installed file $p does not exist!"
fi
- else
- warn "supposedly installed file $p does not exist!"
- fi
- done < "${INSTALLED_MANIFEST}"
-
- # If we fail to remove $TEMPLATE_REL_MANIFEST_DIR below, then the
- # installed manifest will still be full; the installed manifest
- # needs to be empty before install.
- msg "removing ${INSTALLED_MANIFEST}"
- rm -f "${INSTALLED_MANIFEST}"
- # For the above reason, this is a hard error
- need_ok "failed to remove installed manifest"
-
- # Remove $TEMPLATE_REL_MANIFEST_DIR directory
- msg "removing ${ABS_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}"
- rm -Rf "${ABS_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}"
- if [ $? -ne 0 ]
- then
- warn "failed to remove ${TEMPLATE_REL_MANIFEST_DIR}"
- fi
-else
- # There's no manifest. If we were asked to uninstall, then that's a problem.
- if [ -n "${CFG_UNINSTALL}" ]
- then
- err "unable to find installation manifest at ${CFG_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}"
+ done < "$ABS_LIBDIR/$md/manifest"
+
+ # If we fail to remove $md below, then the
+ # installed manifest will still be full; the installed manifest
+ # needs to be empty before install.
+ msg "removing $ABS_LIBDIR/$md/manifest"
+ rm -f "$ABS_LIBDIR/$md/manifest"
+ # For the above reason, this is a hard error
+ need_ok "failed to remove installed manifest"
+
+ # Remove $TEMPLATE_REL_MANIFEST_DIR directory
+ msg "removing ${ABS_LIBDIR}/$md"
+ rm -Rf "${ABS_LIBDIR}/$md"
+ if [ $? -ne 0 ]
+ then
+ warn "failed to remove $md"
+ fi
+
+ UNINSTALLED_SOMETHING=1
fi
+done
+
+# Check installed version
+if [ -f "$ABS_LIBDIR/$TEMPLATE_REL_MANIFEST_DIR/rust-installer-version" ]; then
+ INSTALLED_VERSION=`cat $ABS_LIBDIR/$TEMPLATE_REL_MANIFEST_DIR/rust-installer-version"`
+fi
+
+case "$INSTALLED_VERSION" in
+
+ # TODO: If this is a previous version, then upgrade in place to the
+ # current version before uninstalling. No need to do this yet because
+ # there is no prior version (only the legacy 'unversioned' installer
+ # which we've already dealt with).
+
+ # This is the current version. Nothing need to be done except uninstall.
+ "2")
+ ;;
+
+ # TODO: If this is an unknown (future) version then bail.
+ *)
+ echo "The copy of $TEMPLATE_PRODUCT_NAME at $PREFIX was installed using an"
+ echo "unknown version ($INSTALLED_VERSION) of rust-installer. Uninstall"
+ echo "it first with the installer used for the original installation"
+ echo "before continuing."
+ exit 1
+ ;;
+esac
+
+# TODO: Uninstall (our components only) before reinstalling
+if [ -n "$INSTALLED_VERSION" ]; then
+ for component in $COMPONENTS; do
+ done
+fi
+
+# There's no installed version. If we were asked to uninstall, then that's a problem.
+if [ -n "${CFG_UNINSTALL}" -a ! -n "$UNINSTALLED_SOMETHING" ]
+then
+ err "unable to find installation manifest at ${CFG_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}"
fi
# If we're only uninstalling then exit
@@ -463,57 +512,82 @@ then
exit 0
fi
-# Create the installed manifest, which we will fill in with absolute file paths
-mkdir -p "${CFG_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}"
-need_ok "failed to create ${TEMPLATE_REL_MANIFEST_DIR}"
-touch "${INSTALLED_MANIFEST}"
-need_ok "failed to create installed manifest"
-
msg
-# Now install, iterate through the new manifest and copy files
-while read p; do
-
- # Decide the destination of the file
- FILE_INSTALL_PATH="${CFG_DESTDIR}${CFG_PREFIX}/$p"
+# Create the directory to contain the manifests
+mkdir -p "${CFG_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}"
+need_ok "failed to create ${TEMPLATE_REL_MANIFEST_DIR}"
- if echo "$p" | grep "^lib/" > /dev/null
- then
- pp=`echo $p | sed 's/^lib\///'`
- FILE_INSTALL_PATH="${CFG_LIBDIR}/$pp"
- fi
+# Install each component
+for component in $COMPONENTS; do
- if echo "$p" | grep "^share/man/" > /dev/null
- then
- pp=`echo $p | sed 's/^share\/man\///'`
- FILE_INSTALL_PATH="${CFG_MANDIR}/$pp"
- fi
+ # The file name of the manifest we're installing from
+ INPUT_MANIFEST="${CFG_SRC_DIR}/$component-manifest.in"
- # Make sure there's a directory for it
- umask 022 && mkdir -p "$(dirname ${FILE_INSTALL_PATH})"
- need_ok "directory creation failed"
+ # The file name of the manifest we're going to create during install
+ INSTALLED_MANIFEST="${ABS_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}/$component-manifest"
- # Make the path absolute so we can uninstall it later without
- # starting from the installation cwd
- absolutify "${FILE_INSTALL_PATH}"
- FILE_INSTALL_PATH="${ABSOLUTIFIED}"
+ # Create the installed manifest, which we will fill in with absolute file paths
+ touch "${INSTALLED_MANIFEST}"
+ need_ok "failed to create installed manifest"
- # Install the file
- msg "installing ${FILE_INSTALL_PATH}"
- if echo "$p" | grep "^bin/" > /dev/null
- then
- install -m755 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
- else
- install -m644 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
+ # Sanity check: do we have our input manifests?
+ if [ ! -f "$INPUT_MANIFEST" ]; then
+ err "manifest for $component does not exist at $INPUT_MANIFEST"
fi
- need_ok "file creation failed"
- # Update the manifest
- echo "${FILE_INSTALL_PATH}" >> "${INSTALLED_MANIFEST}"
- need_ok "failed to update manifest"
+ # Now install, iterate through the new manifest and copy files
+ while read p; do
-# The manifest lists all files to install
-done < "${CFG_SRC_DIR}/${CFG_LIBDIR_RELATIVE}/${TEMPLATE_REL_MANIFEST_DIR}/manifest.in"
+ # Decide the destination of the file
+ FILE_INSTALL_PATH="${CFG_DESTDIR}${CFG_PREFIX}/$p"
+
+ if echo "$p" | grep "^lib/" > /dev/null
+ then
+ pp=`echo $p | sed 's/^lib\///'`
+ FILE_INSTALL_PATH="${CFG_LIBDIR}/$pp"
+ fi
+
+ if echo "$p" | grep "^share/man/" > /dev/null
+ then
+ pp=`echo $p | sed 's/^share\/man\///'`
+ FILE_INSTALL_PATH="${CFG_MANDIR}/$pp"
+ fi
+
+ # Make sure there's a directory for it
+ umask 022 && mkdir -p "$(dirname ${FILE_INSTALL_PATH})"
+ need_ok "directory creation failed"
+
+ # Make the path absolute so we can uninstall it later without
+ # starting from the installation cwd
+ absolutify "${FILE_INSTALL_PATH}"
+ FILE_INSTALL_PATH="${ABSOLUTIFIED}"
+
+ # Install the file
+ msg "installing ${FILE_INSTALL_PATH}"
+ if echo "$p" | grep "^bin/" > /dev/null
+ then
+ install -m755 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
+ else
+ install -m644 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
+ fi
+ need_ok "file creation failed"
+
+ # Update the manifest
+ echo "${FILE_INSTALL_PATH}" >> "${INSTALLED_MANIFEST}"
+ need_ok "failed to update manifest"
+
+ # The manifest lists all files to install
+ done < "$INPUT_MANIFEST"
+
+ # Update the components
+ echo "$component " >> "${ABS_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}/components"
+ need_ok "failed to update components list for $component"
+
+done
+
+# Drop the version number into the manifest dir
+echo "$INSTALLER_VERSION" > "${ABS_LIBDIR}/${TEMPLATE_REL_MANIFEST_DIR}/rust-installer-version"
msg