summaryrefslogtreecommitdiff
path: root/install-header.sh
blob: 0c2fc6de210c84c7cbe0a29ba3a0e26e15565c11 (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   SELF="$(cd $(dirname ${0}) && pwd)/$(basename ${0})"
   53   TMP="$(mktemp -d /tmp/installer-XXXXXXX)"
   54 
   55   extract_header
   56   extract_libinstall
   57   extract_runscript
   58 
   59   cd "${TMP}"
   60 
   61   source libinstall/template.sh
   62   source libinstall/ensure.sh
   63 
   64   source run.sh
   65 
   66   # Function 'deploy' is provided by run.sh
   67   if [ "$(type -t deploy)" == 'function' ]; then
   68     deploy ${@}
   69   else
   70     printf "ERROR: Deploy function not found.\n"
   71   fi
   72 
   73   # Cleanup
   74   [ -z "${NOCLEANUP:-}" ] && rm -rf "${TMP}"
   75 }
   76 
   77 main ${@}
   78 exit 0

Generated by cgit