summaryrefslogtreecommitdiff
path: root/install-header.sh
blob: a7b9269f37e2dd63489e8a700ff28301fcebb6ae (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 
   12 # Header:    0
   13 # runscript: 1
   14 # payload:   2
   15 extract_chunk_index() {
   16   local src="${1}"
   17   local dest="${2}"
   18   local index="${3}"
   19   local skip=0  # Byte count to skip into source
   20   local of      # Output path with 'of=' prefix. Only used if dest is not '-'
   21 
   22   for (( i = 0; i < index; i++ )); do
   23     skip=$(( skip + LENS[$i] ))
   24   done
   25 
   26   [ "${dest}" != '-' ] && of="of=${dest}"
   27   # Extract the requested chunk index
   28   dd bs=1 count=${LENS[$index]} iflag=skip_bytes skip=${skip} \
   29     if=${src} ${of} 2>/dev/null
   30 }
   31 
   32 extract_header() {
   33   extract_chunk_index "${SELF}" "${TMP}/header.sh" 0
   34 }
   35 
   36 extract_libinstall() {
   37   extract_chunk_index "${SELF}" '-' 1 | xz -d -c | tar -C "${TMP}" -x
   38 }
   39 
   40 extract_runscript() {
   41   extract_chunk_index "${SELF}" '-' 2 | xz -d -c > "${TMP}/run.sh"
   42 }
   43 
   44 extract_payload() {
   45   extract_chunk_index "${SELF}" '-' 3 | xz -d -c | tar -C "${TMP}" -x
   46   export PAYLOAD="${TMP}/pkg"
   47 }
   48 
   49 
   50 main() {
   51   SELF="$(cd $(dirname ${0}) && pwd)/$(basename ${0})"
   52   TMP="$(mktemp -d /tmp/installer-XXXXXXX)"
   53 
   54   extract_header
   55   extract_libinstall
   56   extract_runscript
   57 
   58   cd "${TMP}"
   59 
   60   source libinstall/template.sh
   61 
   62   source run.sh
   63 
   64   # Function 'deploy' is provided by run.sh
   65   if [ "$(type -t deploy)" == 'function' ]; then
   66     deploy ${@}
   67   else
   68     printf "ERROR: Deploy function not found.\n"
   69   fi
   70 
   71   # Cleanup
   72   [ -z "${NOCLEANUP:-}" ] && rm -rf "${TMP}"
   73 }
   74 
   75 main ${@}
   76 exit 0

Generated by cgit