#!/usr/bin/env bash # This is a pre-allocated string of 30 chars of whitespace # DO NOT CHANGE THIS without great care - it will break header length # calculations 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 # Header: 0 # runscript: 1 # payload: 2 extract_chunk_index() { local src="${1}" local dest="${2}" local index="${3}" local skip=0 # Byte count to skip into source local of # Output path with 'of=' prefix. Only used if dest is not '-' for (( i = 0; i < index; i++ )); do skip=$(( skip + LENS[$i] )) done [ "${dest}" != '-' ] && of="${dest}" # Extract the requested chunk index dd bs=1 count=${LENS[$index]} iflag=skip_bytes skip=${skip} \ if=${src} ${of} 2>/dev/null } extract_header() { extract_chunk_index "${SELF}" "${TMP}/header.sh" 0 } extract_runscript() { extract_chunk_index "${SELF}" '-' 1 | xz -d -c > "${TMP}/run.sh" } extract_payload() { extract_chunk_index "${SELF}" '-' 2 | xz -d -c | tar -C "${TMP}" -x export PAYLOAD="${TMP}/pkg" } main() { SELF="$(cd $(dirname ${0}) && pwd)/$(basename ${0})" TMP="$(mktemp -d /tmp/installer-XXXXXXX)" extract_header extract_runscript #extract_chunks "${self}" "${tmp}" cd "${TMP}" source run.sh # Function 'deploy' is provided by run.sh if [ "$(type -t deploy)" == 'function' ]; then deploy ${@} else printf "ERROR: Deploy function not found.\n" fi # Cleanup [ -z "${NOCLEANUP:-}" ] && rm -rf "${TMP}" } main ${@} exit 0