diff --git a/README.md b/README.md index 95a2398..6b5791e 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,6 @@ An example file outlining the format is provided. # How to use: -Put `pyhi.sh` and `pyhp.py` somewhere where your web server can execute them, then configure said web server to execute `.pyh` files using `pyhi.sh`. \ No newline at end of file +Put `pyhi-cgi.sh` somewhere where the server will execute it as CGI script with the environment variable `PYHP` set to point to `pyhp.py`. If the environment variable is unset, `pyhi-cgi.sh` will try to find `pyhp.py` in the same directory as it itself is. Then configure the web server to run `.pyh` files using `pyhi-cgi.sh` as a cgi script. + +Alternatively, put `pyhi.sh` and `pyhp.py` somewhere and run `pyhi.sh` with the `.pyh` file as the first argument. Any other command line arguments will be passed to the `.pyh` file. The same `PYHP` environment variable can be used as described above. diff --git a/pyhi-cgi.sh b/pyhi-cgi.sh new file mode 100755 index 0000000..1e68cc6 --- /dev/null +++ b/pyhi-cgi.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +if [ -z "$PYHP" ]; then + PYHP=""$(dirname "$0")"/pyhp.py" +fi + +HYPERTEXT=$("$PYHP" "$PATH_TRANSLATED" | python3 -) + +# check for headers, if present assume the pyh file is going to handle them +if head -n1 <<< "$HYPERTEXT" | grep "[A-Za-z][A-Za-z0-9\-]*: " > /dev/null 2>&1; then + true +else + echo -ne "Content-type: text/html\\n\\n" +fi + +echo "$HYPERTEXT" diff --git a/pyhi.sh b/pyhi.sh old mode 100644 new mode 100755 index d442e10..553a76a --- a/pyhi.sh +++ b/pyhi.sh @@ -4,13 +4,7 @@ if [ -z "$PYHP" ]; then PYHP=""$(dirname "$0")"/pyhp.py" fi -HYPERTEXT=$("$PYHP" "$PYH" | python3 - "$PATH_TRANSLATED") +PYH="$1" +shift -# check for headers, if present assume the pyh file is going to handle them -if head -n1 <<< "$HYPERTEXT" | grep "[A-Za-z][A-Za-z0-9\-]*: "; then - true -else - echo -ne "Content-type: text/html\\n\\n" -fi - -echo "$HYPERTEXT" +"$PYHP" "$PYH" | python3 - "$@" diff --git a/pyhp.py b/pyhp.py old mode 100644 new mode 100755