github.com/carbocation/gotogether@v0.0.0-20130502180533-aa88e503440f/gotogether (about)

     1  #!/bin/bash
     2  # Pack assets as zip payload in go executable
     3  
     4  # Idea from Carlos Castillo (http://bit.ly/SmYXXm)
     5  
     6  case "$1" in
     7      -h | --help )
     8          echo "usage: $(basename $0) EXECTABLE RESOURCE_DIR [ZIP OPTIONS]";
     9          exit;;
    10      --version )
    11          echo "gotogether version 0.3.2"; exit;;
    12  esac
    13  
    14  if [ $# -lt 2 ]; then
    15      $0 -h
    16      exit 1
    17  fi
    18  
    19  exe=$1
    20  shift
    21  directories=$1
    22  shift
    23  
    24  if [ ! -f "${exe}" ]; then
    25      echo "error: can't find $exe"
    26      exit 1
    27  fi
    28  
    29  for root in $directories
    30  do
    31      if [ ! -d "${root}" ]; then
    32          echo "error: ${root} is not a directory"
    33          exit 1
    34      fi
    35  done
    36  
    37  # Exit on 1'st error
    38  set -e
    39  
    40  tmp="/tmp/gotogether-$(date +%s).zip"
    41  trap "rm -f ${tmp}" EXIT
    42  
    43  # Create zip file
    44  (zip -r "${tmp}" ${directories} $@)
    45  
    46  # Append zip to executable
    47  cat "${tmp}" >> "${exe}"
    48  # Fix zip offset in file
    49  zip -q -A "${exe}"