c.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env dash
  2. set -e
  3. cd "$(dirname "$0")"
  4. readonly wd="/var/spool/build/src/seppo"
  5. uname -sm | figlet
  6. opam switch
  7. [ "$1" = "inside" ] && {
  8. shift
  9. cd
  10. rsync -qaP --delete --exclude _build --exclude doc "$wd" .
  11. # just be explicit:
  12. echo "GIT_SHA=$GIT_SHA make -C seppo $*"
  13. GIT_SHA=$GIT_SHA make -C seppo "$@"
  14. exit
  15. }
  16. emul_path="$(sysctl compat.linux.emul_path | cut -c25-)"
  17. readonly emul_path
  18. ls -d "$emul_path$(dirname "$wd")" > /dev/null
  19. pwd
  20. echo "rsync -qaP --delete --exclude _build --exclude .git . $emul_path$wd"
  21. rsync -qaP --delete --exclude _build --exclude .git . "$emul_path$wd"
  22. GIT_SHA="$(git log -1 --format="%h")"
  23. echo "GIT_SHA=$GIT_SHA gmake -C $emul_path$wd $*"
  24. GIT_SHA=$GIT_SHA gmake -C "$emul_path$wd" "$@"
  25. echo ""
  26. echo "doas chroot $emul_path su - $USER -c \"GIT_SHA=$GIT_SHA sh $wd/$(basename "$0") inside $*\""
  27. doas chroot "$emul_path" su - "$USER" -c "GIT_SHA=$GIT_SHA sh $wd/$(basename "$0") inside $*"
  28. echo ""
  29. echo collect binaries
  30. cd "$emul_path$wd/_build"
  31. pwd
  32. rsync -aP "$emul_path$HOME/seppo/_build/"*.cgi .
  33. tar czf source.tar.gz --exclude _build ..
  34. echo sign binaries
  35. pk_pem="$(ls /media/*/seppo.priv.pem 2>/dev/null)"
  36. readonly pk_pem
  37. for f in *.cgi source.tar.gz
  38. do
  39. # https://stackoverflow.com/a/18359743
  40. # echo "openssl dgst -sha256 -sign $pk_pem -out $f.signature $f"
  41. openssl dgst -sha256 -sign "$pk_pem" -out "$f.signature" "$f"
  42. done
  43. ls -l ./*.signature
  44. echo deploy
  45. for dst in dev.seppo.social dev1.seppo.social
  46. do
  47. echo "$dst" | figlet
  48. arch="$(ssh "$dst" uname -sm | tr ' ' '-')"
  49. rsync -avPz -- *"-$arch"-*.cgi* "$dst":~/seppo.social/dev/ || {
  50. beep ; beep ; beep
  51. continue
  52. }
  53. f="$(ls -t "seppo-$arch"-*.cgi | head -n 1)"
  54. ssh "$dst" "cd seppo.social/dev && rm seppo.cgi ; ln -s $f seppo.cgi"
  55. done
  56. beep