summaryrefslogtreecommitdiff
path: root/install-header.sh
blob: 766ba0a0ed822b6f1f522e9b2d923027a1ba1f3b (plain)
    1 #!/usr/bin/env bash
    2 
    3 # This is a pre-allocated string of 30 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="${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_runscript() {
   37   extract_chunk_index "${SELF}" '-' 1 | xz -d -c > "${TMP}/run.sh"
   38 }
   39 
   40 extract_payload() {
   41   extract_chunk_index "${SELF}" '-' 2 | xz -d -c | tar -C "${TMP}" -x
   42   export PAYLOAD="${TMP}/pkg"
   43 }
   44 
   45 
   46 main() {
   47   SELF="$(cd $(dirname ${0}) && pwd)/$(basename ${0})"
   48   TMP="$(mktemp -d /tmp/installer-XXXXXXX)"
   49 
   50   extract_header
   51   extract_runscript
   52   #extract_chunks "${self}" "${tmp}"
   53 
   54   cd "${TMP}"
   55   source run.sh
   56 
   57   # Function 'deploy' is provided by run.sh
   58   if [ "$(type -t deploy)" == 'function' ]; then
   59     deploy ${@}
   60   else
   61     printf "ERROR: Deploy function not found.\n"
   62   fi
   63 
   64   # Cleanup
   65   [ -z "${NOCLEANUP:-}" ] && rm -rf "${TMP}"
   66 }
   67 
   68 main ${@}
   69 exit 0

Generated by cgit