Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Display wait message #338

Merged
merged 7 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN apt-get update \
tini \
wget \
ovmf \
socat \
procps \
iptables \
iproute2 \
Expand Down
4 changes: 4 additions & 0 deletions src/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bash
set -Eeuo pipefail

# Display wait message
MSG="Please wait while the ISO is being downloaded..."
/run/server.sh "QEMU" "$MSG" &

# Check if running with interactive TTY or redirected to docker log
if [ -t 1 ]; then
PROGRESS="--progress=bar:noscroll"
Expand Down
4 changes: 4 additions & 0 deletions src/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ closeNetwork() {

if [[ "$DHCP" == [Yy1]* ]]; then

fKill "server.sh"

ip link set "$VM_NET_TAP" down || true
ip link delete "$VM_NET_TAP" || true

Expand Down Expand Up @@ -253,6 +255,8 @@ getInfo() {
# Configure Network
# ######################################

fKill "server.sh"

if [ ! -c /dev/vhost-net ]; then
if mknod /dev/vhost-net c 10 238; then
chmod 660 /dev/vhost-net
Expand Down
32 changes: 32 additions & 0 deletions src/server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -eu

TMP_FILE=$(mktemp -q /dev/shm/server.XXXXXX)

stop() {
trap - SIGINT EXIT
{ pkill -f socat || true; } 2>/dev/null
[ -f "$TMP_FILE" ] && rm -f "$TMP_FILE"
}

trap 'stop' EXIT SIGINT SIGTERM SIGHUP

html()
{
local h="<!DOCTYPE html><HTML><HEAD><TITLE>$2</TITLE>"
h="$h<STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,"
h="$h Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD>"
h="$h<BODY><BR><BR><H1><CENTER>$1</CENTER></H1></BODY></HTML>"

echo "$h"
}

BODY="$2<script>setTimeout(() => { document.location.reload(); }, 4999);</script>"

HTML=$(html "$BODY" "$1")
printf '%b' "HTTP/1.1 200 OK\nContent-Length: ${#HTML}\nConnection: close\n\n$HTML" > "$TMP_FILE"

socat TCP4-LISTEN:80,reuseaddr,fork,crlf SYSTEM:"cat $TMP_FILE" 2> /dev/null &
socat TCP4-LISTEN:8006,reuseaddr,fork,crlf SYSTEM:"cat $TMP_FILE" 2> /dev/null & wait $!

exit