2023-03-28 00:23:50 +07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eu
|
2023-04-20 20:27:06 +07:00
|
|
|
trap exit SIGINT SIGTERM
|
2023-03-28 00:23:50 +07:00
|
|
|
|
2023-04-20 20:06:44 +07:00
|
|
|
# Close any previous instances
|
2023-04-22 22:24:07 +07:00
|
|
|
script_name="${BASH_SOURCE[0]}"
|
2023-04-20 20:06:44 +07:00
|
|
|
|
2023-04-21 11:42:19 +07:00
|
|
|
for pid in $(pidof -x "$script_name"); do
|
|
|
|
if [ "$pid" != $$ ]; then
|
|
|
|
kill -15 "$pid" 2> /dev/null
|
|
|
|
wait "$pid" 2> /dev/null
|
2023-04-20 21:02:21 +07:00
|
|
|
fi
|
2023-04-20 20:06:44 +07:00
|
|
|
done
|
|
|
|
|
|
|
|
# Serve the page
|
2023-04-22 22:24:07 +07:00
|
|
|
HTML="<HTML><HEAD><STYLE>body { color: white; background-color: #00BFFF; }</STYLE>\
|
|
|
|
</HEAD><BODY><BR><BR><H1><CENTER>$2</CENTER></H1></BODY></HTML>"
|
|
|
|
|
2023-04-20 21:22:42 +07:00
|
|
|
LENGTH="${#HTML}"
|
2023-03-28 00:23:50 +07:00
|
|
|
|
2023-04-20 21:00:56 +07:00
|
|
|
RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n"
|
2023-04-20 20:47:59 +07:00
|
|
|
|
2023-04-20 21:02:21 +07:00
|
|
|
while true; do
|
|
|
|
echo -en "$RESPONSE" | nc -N -lp "${1:-8080}";
|
2023-04-20 20:47:59 +07:00
|
|
|
done
|