diff --git a/Dockerfile b/Dockerfile index 90af56e..eeaf447 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,22 +6,21 @@ ARG DEBCONF_NONINTERACTIVE_SEEN "true" RUN apt-get update \ && apt-get --no-install-recommends -y install \ - tini \ - wget \ + tini \ + wget \ ovmf \ - socat \ - nginx \ + nginx \ swtpm \ - procps \ - iptables \ - iproute2 \ + procps \ + iptables \ + iproute2 \ apt-utils \ - dnsmasq \ - net-tools \ + dnsmasq \ + net-tools \ qemu-utils \ - ca-certificates \ - netcat-openbsd \ - qemu-system-x86 \ + ca-certificates \ + netcat-openbsd \ + qemu-system-x86 \ && apt-get clean \ && novnc="1.4.0" \ && mkdir -p /usr/share/novnc \ @@ -29,12 +28,14 @@ RUN apt-get update \ && tar -xf /tmp/novnc.tar.gz -C /tmp/ \ && cd /tmp/noVNC-"$novnc" \ && mv app core vendor package.json *.html /usr/share/novnc \ + && sed -i 's/^worker_processes.*/worker_processes 1;/' /etc/nginx/nginx.conf \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* COPY ./src /run/ -COPY nginx.conf /etc/nginx/sites-enabled/novnc.conf +COPY ./web /var/www/ RUN chmod +x /run/*.sh +RUN mv /var/www/nginx.conf /etc/nginx/sites-enabled/web.conf VOLUME /storage EXPOSE 22 5900 8006 diff --git a/src/config.sh b/src/config.sh index 6d72cc6..e105b8b 100644 --- a/src/config.sh +++ b/src/config.sh @@ -15,4 +15,14 @@ DEV_OPTS="$DEV_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0 ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $BOOT_OPTS $DEV_OPTS $USB_OPTS $ARGUMENTS" ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ') +if [[ "${DISPLAY,,}" == "web" ]]; then + rm -f /dev/shm/index.html +else + if [[ "${DISPLAY,,}" == "vnc" ]]; then + html "You can now connect to VNC on port 5900." "0" + else + html "The virtual machine was booted successfully." "0" + fi +fi + return 0 diff --git a/src/disk.sh b/src/disk.sh index 8feba0d..c5d6d81 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -116,7 +116,9 @@ createDisk() { fi fi - info "Creating a $DISK_TYPE $DISK_DESC image in $DISK_FMT format with a size of $DISK_SPACE..." + MSG="Creating a $DISK_TYPE $DISK_DESC image in $DISK_FMT format with a size of $DISK_SPACE..." + info "$MSG" && html "$MSG" + local FAIL="Could not create a $DISK_TYPE $DISK_FMT $DISK_DESC image of $DISK_SPACE ($DISK_FILE)" case "${DISK_FMT,,}" in @@ -199,7 +201,9 @@ resizeDisk() { fi local GB=$(( (CUR_SIZE + 1073741823)/1073741824 )) - info "Resizing $DISK_DESC from ${GB}G to $DISK_SPACE..." + MSG="Resizing $DISK_DESC from ${GB}G to $DISK_SPACE..." + info "$MSG" && html "$MSG" + local FAIL="Could not resize the $DISK_TYPE $DISK_FMT $DISK_DESC image from ${GB}G to $DISK_SPACE ($DISK_FILE)" case "${DISK_FMT,,}" in @@ -266,7 +270,8 @@ convertDisk() { fi fi - info "Converting $DISK_DESC to $DST_FMT, please wait until completed..." + MSG="Converting $DISK_DESC to $DST_FMT, please wait until completed..." + info "$MSG" && html "$MSG" local CONV_FLAGS="-p" local DISK_PARAM="$DISK_ALLOC" @@ -305,7 +310,8 @@ convertDisk() { fi fi - info "Conversion of $DISK_DESC to $DST_FMT completed succesfully!" + MSG="Conversion of $DISK_DESC to $DST_FMT completed succesfully!" + info "$MSG" && html "$MSG" return 0 } @@ -420,6 +426,8 @@ addDevice () { return 0 } +html "Initializing disks..." + DISK1_FILE="$STORAGE/data" DISK2_FILE="/storage2/data2" DISK3_FILE="/storage3/data3" @@ -484,4 +492,5 @@ else addDisk "userdata4" "$DISK4_FILE" "$DISK_EXT" "disk4" "$DISK4_SIZE" "4" "0xd" "$DISK_FMT" || exit $? fi +html "Initialized disks successfully..." return 0 diff --git a/src/entry.sh b/src/entry.sh index c550e5d..eb3be8b 100755 --- a/src/entry.sh +++ b/src/entry.sh @@ -1,9 +1,8 @@ #!/usr/bin/env bash set -Eeuo pipefail -echo "❯ Starting QEMU for Docker v$($SUPPORT" + KERNEL=$(uname -r | cut -b 1) MINOR=$(uname -r | cut -d '.' -f2) ARCH=$(dpkg --print-architecture) VERS=$(qemu-system-x86_64 --version | head -n 1 | cut -d '(' -f 1) # Check folder - -STORAGE="/storage" [ ! -d "$STORAGE" ] && error "Storage folder ($STORAGE) not found!" && exit 13 # Helper functions -fKill () { - local name=$1 +html() +{ + local title="
${body/.../}
" + fi - { pkill -f "$name" || true; } 2>/dev/null + local timeout="4999" + [ -n "${2:-}" ] && timeout="$2" + local script="" + [[ "$timeout" == "0" ]] && script="" - while pgrep -f -l "$name" >/dev/null; do - sleep 0.1 - done + local HTML + HTML=$(<"$TEMPLATE") + HTML="${HTML/\[1\]/$title}" + HTML="${HTML/\[2\]/$script}" + HTML="${HTML/\[3\]/$body}" + HTML="${HTML/\[4\]/$FOOTER1}" + HTML="${HTML/\[5\]/$FOOTER2}" - return 0 + echo "$HTML" > "$PAGE" + + return 0 } addPackage () { @@ -55,7 +78,8 @@ addPackage () { return 0 fi - info "Installing $desc..." + MSG="Installing $desc..." + info "$MSG" && html "$MSG" DEBIAN_FRONTEND=noninteractive apt-get -qq update DEBIAN_FRONTEND=noninteractive apt-get -qq --no-install-recommends -y install "$pkg" > /dev/null @@ -63,4 +87,9 @@ addPackage () { return 0 } +# Start webserver +cp -r /var/www/* /dev/shm +html "Starting $APP..." +nginx -e stderr + return 0 diff --git a/src/server.sh b/src/server.sh deleted file mode 100644 index 2c77fa6..0000000 --- a/src/server.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/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="