nrsc 766 B

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