cgi.sh 923 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # -*- coding: utf-8 -*-
  3. basedir="$(realpath "$0" | xargs dirname)"
  4. info()
  5. {
  6. echo "--- $*"
  7. }
  8. error()
  9. {
  10. echo "=== ERROR: $*" >&2
  11. }
  12. warning()
  13. {
  14. echo "=== WARNING: $*" >&2
  15. }
  16. die()
  17. {
  18. error "$*"
  19. exit 1
  20. }
  21. release="debug"
  22. get_path="/"
  23. while [ $# -ge 1 ]; do
  24. case "$1" in
  25. --debug|-d)
  26. release="debug"
  27. ;;
  28. --release|-r)
  29. release="release"
  30. ;;
  31. *)
  32. get_path="$1"
  33. ;;
  34. esac
  35. shift
  36. done
  37. target="$basedir/../target/$release"
  38. binary="$target/cms-cgi"
  39. [ -x "$binary" ] || die "cms-cgi binary $binary not found."
  40. rundir="$basedir/run"
  41. export QUERY_STRING=
  42. export REQUEST_METHOD=GET
  43. export PATH_INFO="$get_path"
  44. export CONTENT_LENGTH=
  45. export CONTENT_TYPE=
  46. export HTTPS=on
  47. export HTTP_HOST=example.com
  48. export HTTP_COOKIE=
  49. "$binary" --rundir "$rundir" || die "cms-cgi failed."
  50. # vim: ts=4 sw=4 expandtab