Unverified Commit 2fdb19ae authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Make monitor configurable (#379)

parent 4a0dbc6c
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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
  
+5 −2
Original line number Diff line number Diff line
#!/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}"
+30 −0
Original line number Diff line number Diff line
@@ -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
+48 −5
Original line number Diff line number Diff line
@@ -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;}
@@ -89,13 +133,12 @@ html()
    HTML="${HTML/\[5\]/$FOOTER2}"

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

    return 0
}

addPackage() {

  local pkg=$1
  local desc=$2