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: Make monitor configurable #379

Merged
merged 6 commits into from
Jan 23, 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
7 changes: 5 additions & 2 deletions src/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ if [[ "${BOOT_MODE,,}" != "legacy" ]]; then

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

rm -rf /run/shm/tpm
rm -f /var/run/tpm.pid
mkdir -p /run/shm/tpm
chmod 755 /run/shm/tpm
swtpm socket -t -d --tpmstate dir=/run/shm/tpm --ctrl type=unixio,path=/run/swtpm-sock --tpm2

for (( i = 1; i < 50; i++ )); do
swtpm socket -t -d --tpmstate dir=/run/shm/tpm --ctrl type=unixio,path=/run/swtpm-sock --pid file=/var/run/tpm.pid --tpm2

for (( i = 1; i < 20; i++ )); do

[ -S "/run/swtpm-sock" ] && break

Expand Down
7 changes: 5 additions & 2 deletions src/config.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env bash
set -Eeuo pipefail

: "${SERIAL:="mon:stdio"}"
: "${MONITOR:="telnet:localhost:7100,server,nowait,nodelay"}"

DEF_OPTS="-nodefaults"
SERIAL_OPTS="-serial mon:stdio"
SERIAL_OPTS="-serial $SERIAL"
MON_OPTS="-monitor $MONITOR"
USB_OPTS="-device qemu-xhci -device usb-tablet"
MON_OPTS="-monitor telnet:localhost:7100,server,nowait,nodelay"
RAM_OPTS=$(echo "-m $RAM_SIZE" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
CPU_OPTS="-cpu $CPU_FLAGS -smp $CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1"
MAC_OPTS="-machine type=q35${SECURE},graphics=off,vmport=off,dump-guest-core=off,hpet=off${KVM_OPTS}"
Expand Down
30 changes: 30 additions & 0 deletions src/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,36 @@ configureNAT() {
return 0
}

closeNetwork() {

# Shutdown nginx
nginx -s stop 2> /dev/null
fWait "nginx"

exec 30<&- || true
exec 40<&- || true

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

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

else

local pid="/var/run/dnsmasq.pid"
[ -f "$pid" ] && pKill "$(<"$pid")"

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

ip link set dockerbridge down || true
ip link delete dockerbridge || true

fi

return 0
}

getInfo() {

if [ -z "$VM_NET_DEV" ]; then
Expand Down
53 changes: 48 additions & 5 deletions src/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ echo
: "${RAM_SIZE:="1G"}" # Maximum RAM amount
: "${DISK_SIZE:="16G"}" # Initial data disk size
: "${BOOT_INDEX:="10"}" # Boot index of CD drive

# Helper variables

STORAGE="/storage"
Expand All @@ -48,10 +48,54 @@ else
fi

# Check folder
[ ! -d "$STORAGE" ] && error "Storage folder ($STORAGE) not found!" && exit 13

if [ ! -d "$STORAGE" ]; then
error "Storage folder ($STORAGE) not found!" && exit 13
fi

# Helper functions

isAlive() {
local pid=$1

if kill -0 "$pid" 2>/dev/null; then
return 0
fi

return 1
}

pKill() {
local pid=$1

{ kill -15 "$pid" || true; } 2>/dev/null

while isAlive "$pid"; do
sleep 0.2
done

return 0
}

fWait() {
local name=$1

while pgrep -f -l "$name" >/dev/null; do
sleep 0.2
done

return 0
}

fKill() {
local name=$1

{ pkill -f "$name" || true; } 2>/dev/null
fWait "$name"

return 0
}

escape () {
local s
s=${1//&/\&amp;}
Expand Down Expand Up @@ -89,13 +133,12 @@ html()
HTML="${HTML/\[5\]/$FOOTER2}"

echo "$HTML" > "$PAGE"
echo "$body$script" > "$INFO"
echo "$body" > "$INFO"

return 0
}

addPackage () {

addPackage() {
local pkg=$1
local desc=$2

Expand Down