arv-v-dsm/run/server.sh

24 lines
592 B
Bash
Raw Normal View History

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
script_name=${BASH_SOURCE[0]}
for pid in $(pidof -x $script_name); do
if [ $pid != $$ ]; then
2023-04-20 20:26:22 +07:00
kill -15 $pid 2> /dev/null
2023-04-20 20:06:44 +07:00
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-20 21:12:10 +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