summaryrefslogtreecommitdiff
path: root/install-header.sh
blob: 200e9c5c5c46de704bb6c1c92d19a988330f9ac6 (plain)
    1 #!/usr/bin/env bash
    2 
    3 # This is a pre-allocated string of 39 chars of whitespace
    4 # DO NOT CHANGE THIS without great care - it will break header length
    5 # calculations
    6 LENS=(                                       )
    7 export SELF             # Absolute path to the installer script (me!)
    8 export TMP              # Path to tmp install staging directory
    9 export PAYLOAD          # Path to the extracted payload directory
   10 export NOCLEANUP        # Do not clean up deploy resources. Useful for debugging
   11 export DECOMPRESS='{{ DECOMPRESS }}' # Command to decompress data
   12 
   13 # Header:    0
   14 # runscript: 1
   15 # payload:   2
   16 extract_chunk_index() {
   17   local src="${1}"
   18   local dest="${2}"
   19   local index="${3}"
   20   local skip=0  # Byte count to skip into source
   21   local of      # Output path with 'of=' prefix. Only used if dest is not '-'
   22 
   23   for (( i = 0; i < index; i++ )); do
   24     skip=$(( skip + LENS[$i] ))
   25   done
   26 
   27   [ "${dest}" != '-' ] && of="of=${dest}"
   28   # Extract the requested chunk index
   29   dd bs=${LENS[$index]} count=1 iflag=skip_bytes skip=${skip} \
   30     if=${src} ${of} 2>/dev/null
   31 }
   32 
   33 extract_header() {
   34   extract_chunk_index "${SELF}" "${TMP}/header.sh" 0
   35 }
   36 
   37 extract_libinstall() {
   38   extract_chunk_index "${SELF}" '-' 1 | ${DECOMPRESS} | tar -C "${TMP}" -x
   39 }
   40 
   41 extract_runscript() {
   42   extract_chunk_index "${SELF}" '-' 2 | ${DECOMPRESS} > "${TMP}/run.sh"
   43 }
   44 
   45 extract_payload() {
   46   extract_chunk_index "${SELF}" '-' 3 | ${DECOMPRESS} | tar -C "${TMP}" -x
   47   export PAYLOAD="${TMP}/pkg"
   48 }
   49 
   50 
   51 main() {
   52   SELFDIR="$(cd $(dirname ${0}) && pwd)"
   53   SELF="${SELFDIR}/$(basename ${0})"
   54   TMP="$(mktemp -d /tmp/installer-XXXXXXX)"
   55 
   56   extract_header
   57   extract_libinstall
   58   extract_runscript
   59 
   60   cd "${TMP}"
   61 
   62   source libinstall/template.sh
   63   source libinstall/ensure.sh
   64   source libinstall/colorize.sh
   65 
   66   source run.sh
   67 
   68   # Function 'deploy' is provided by run.sh
   69   if [ "$(type -t deploy)" == 'function' ]; then
   70     deploy ${@}
   71   else
   72     printf "ERROR: Deploy function not found.\n"
   73   fi
   74 
   75   # Cleanup
   76   [ -z "${NOCLEANUP:-}" ] && rm -rf "${TMP}"
   77 }
   78 
   79 main ${@}
   80 exit 0

Generated by cgit