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

Generated by cgit