make it work with and without cgi

master
BodgeMaster 2022-04-06 07:09:27 +02:00
parent dcaf1e7127
commit 8844d48611
4 changed files with 22 additions and 10 deletions

View File

@ -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`.
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.

16
pyhi-cgi.sh Executable file
View File

@ -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"

12
pyhi.sh Normal file → Executable file
View File

@ -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 - "$@"

0
pyhp.py Normal file → Executable file
View File