From b6ef2c83429bfeba68c131445e6dd29cc04a2f83 Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Mon, 9 Apr 2018 15:45:45 -0600 Subject: install-header: Added --extract-only switch This switch skips the deploy function as well as the cleanup process, executing the extraction process before exiting. This will enable easier debugging. Note that this switch does not support a short version to avoid risk of conflicting with downstream run.sh-provided switches (eg: -e). --- install-header.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/install-header.sh b/install-header.sh index 200e9c5..1470c8f 100755 --- a/install-header.sh +++ b/install-header.sh @@ -7,7 +7,8 @@ LENS=( ) export SELF # Absolute path to the installer script (me!) export TMP # Path to tmp install staging directory export PAYLOAD # Path to the extracted payload directory -export NOCLEANUP # Do not clean up deploy resources. Useful for debugging +export NOCLEANUP=0 # Do not clean up deploy resources. Useful for debugging +export EXTRACTONLY=0 # Execute extract, skipping deployment and cleanup export DECOMPRESS='{{ DECOMPRESS }}' # Command to decompress data # Header: 0 @@ -49,6 +50,8 @@ extract_payload() { main() { + local args=(${@}) + SELFDIR="$(cd $(dirname ${0}) && pwd)" SELF="${SELFDIR}/$(basename ${0})" TMP="$(mktemp -d /tmp/installer-XXXXXXX)" @@ -65,15 +68,32 @@ main() { source run.sh - # Function 'deploy' is provided by run.sh - if [ "$(type -t deploy)" == 'function' ]; then + for (( i = 0; i < ${#args[@]}; i++ )); do + # NOTE: Do not support short switches here to reduce the probability of + # conflicting with a switch provided by the downstream run.sh + if [ "${args[$i]}" = '--extract-only' ]; then + export EXTRACTONLY=1 + export NOCLEANUP=1 + fi + done + + if [ "${EXTRACTONLY}" = '1' ]; then + printf 'Extracting...\n' + extract_payload + printf 'Installation payload available at "%s"\n' "${TMP}/pkg" + printf 'Skipping cleanup\n' + return 0 + elif [ "$(type -t deploy)" == 'function' ]; then + # Function 'deploy' is provided by run.sh deploy ${@} else printf "ERROR: Deploy function not found.\n" fi # Cleanup - [ -z "${NOCLEANUP:-}" ] && rm -rf "${TMP}" + if [ "${NOCLEANUP}" -ne 0 ]; then + rm -rf "${TMP}" + fi } main ${@} -- cgit v1.2.3