diff --git a/run/install.sh b/run/install.sh index 5a05ffd..4ef735b 100644 --- a/run/install.sh +++ b/run/install.sh @@ -2,7 +2,7 @@ set -eu # Display wait message on port 5000 -/run/server.sh 5000 > /dev/null & +/run/server.sh 5000 "Please wait while Virtual DSM is installing..." > /dev/null & DL="https://global.synologydownload.com/download/DSM" diff --git a/run/network.sh b/run/network.sh index b4a6301..0e8425f 100644 --- a/run/network.sh +++ b/run/network.sh @@ -179,6 +179,9 @@ else # Configuration for DHCP IP configureDHCP + # Display the received IP on port 5000 + /run/server.sh 5000 "The location of DSM is http://${DHCP_IP}:5000" > /dev/null & + fi NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0" diff --git a/run/server.sh b/run/server.sh index e65758d..a4b28b5 100644 --- a/run/server.sh +++ b/run/server.sh @@ -1,10 +1,23 @@ #!/usr/bin/env bash set -eu +trap exit SIGINT SIGTERM -HTML="

Please wait while Virtual DSM is installing...

" -RESPONSE="HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n$HTML\r\n" +# Close any previous instances +script_name=${BASH_SOURCE[0]} -while { echo -en "$RESPONSE"; } | nc -lN "${1:-8080}"; do - echo "================================================" +for pid in $(pidof -x $script_name); do + if [ $pid != $$ ]; then + kill -15 $pid 2> /dev/null + wait $pid 2> /dev/null + fi done +# Serve the page +HTML="

$2

" +LENGTH="${#HTML}" + +RESPONSE="HTTP/1.1 200 OK\nContent-Length: ${LENGTH}\nConnection: close\n\n$HTML\n\n" + +while true; do + echo -en "$RESPONSE" | nc -N -lp "${1:-8080}"; +done