release.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env dash
  2. # https://nochlin.com/blog/6-techniques-i-use-to-create-a-great-user-experience-for-shell-scripts
  3. # via https://news.ycombinator.com/item?id=41512899
  4. set -u
  5. set -e
  6. cd "$(dirname "$0")"
  7. [ "$1" = "" ] && {
  8. cat << EOF
  9. Give me a git sha or source tar to mint a release from.
  10. EOF
  11. exit 0
  12. }
  13. pk_pem="$(ls /media/*/seppo.priv.pem 2>/dev/null)" ; readonly pk_pem
  14. wd="/var/spool/build/src/seppo" ; readonly wd
  15. emu="$(sysctl compat.linux.emul_path | cut -d : -f 2 | tr -d ' ')" ; readonly emu
  16. ls -d "$emu$wd" > /dev/null
  17. src="$(dirname "$emu$wd")/source.tar.gz" ; readonly src
  18. GIT_SHA="-"
  19. set +e
  20. if tar tzf "$1" > /dev/null 2>&1
  21. then
  22. cp -p "$1" "$src"
  23. else
  24. GIT_SHA="$1"
  25. echo "curl -LO https://codeberg.org/seppo/seppo/archive/$GIT_SHA.tar.gz"
  26. curl \
  27. --output "$src" \
  28. --location "https://codeberg.org/seppo/seppo/archive/$GIT_SHA.tar.gz"
  29. fi
  30. set -e
  31. tar tzf "$src" > /dev/null
  32. echo "one source to build them all"
  33. ls -l "$src"
  34. # echo "$emu$wd"
  35. rm -rf "${emu:?}$wd/"
  36. tar xzf "$src" -C "$(dirname "$emu$wd")"
  37. uname -sm | figlet
  38. opam switch
  39. echo "GIT_SHA=$GIT_SHA gmake -C $emu$wd clean test final"
  40. GIT_SHA="$GIT_SHA" gmake -C "$emu$wd" clean test final
  41. echo ""
  42. cat <<EOF > "$emu$wd/chroot.make.sh"
  43. uname -sm | figlet
  44. opam switch
  45. cd
  46. rsync -qaP --delete --exclude _build "$wd" .
  47. echo "GIT_SHA=$GIT_SHA make -C seppo "\$@""
  48. GIT_SHA="$GIT_SHA" make -C seppo "\$@"
  49. EOF
  50. echo "doas chroot $emu su - $USER -c \"GIT_SHA=$GIT_SHA sh $wd/chroot.make.sh clean test final\""
  51. doas chroot "$emu" su - "$USER" -c "GIT_SHA=$GIT_SHA sh $wd/chroot.make.sh clean test final"
  52. echo ""
  53. set +v
  54. echo "collect results"
  55. cd "$emu$wd/_build"
  56. pwd
  57. rsync -aP "$src" "$emu$HOME/seppo/_build/"*.cgi .
  58. # should this go into Makefile?
  59. ver="$(grep -hoE "^\(version [^\)]+" ../dune-project | cut -d ' ' -f2)"
  60. date="$(date)"
  61. readonly ver date
  62. export ver date GIT_SHA
  63. envsubst < ../README.txt.tpl > README.txt
  64. curl \
  65. --output "www.tar.gz" \
  66. --location "https://codeberg.org/seppo/www/archive/ma.tar.gz"
  67. echo "sign binaries"
  68. for f in README.txt *.cgi source.tar.gz www.tar.gz
  69. do
  70. # https://stackoverflow.com/a/18359743
  71. openssl dgst -sha256 -sign "$pk_pem" -out "$f.signature" "$f"
  72. done
  73. ls -Al *.signature
  74. dst="seppo-${ver}_$(date +%Y%m%d).tar.gz"
  75. readonly dst
  76. tar czf "$dst" -- README.txt* *.cgi* source.tar.gz* www.tar.gz*
  77. tar tzf "$dst"
  78. ls -l "$(pwd)/$dst"