From c70e12f0a2540ba6385e6a91f935f5740a123bfd Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 14 Oct 2025 03:33:25 +0200 Subject: [PATCH 1/5] fix: Lower spare disk space (#1061) Reduced spare disk space threshold from 2GB to 512MB. --- src/disk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/disk.sh b/src/disk.sh index 14df45b..340b444 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -434,7 +434,7 @@ addDisk () { if [[ "${DISK_SPACE,,}" == "max" ]]; then - local SPARE=2147483648 + local SPARE=536870912 SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1) (( SPACE < SPARE )) && SPACE="$SPARE" || SPACE=$((SPACE-SPARE)) GB=$(( SPACE/1073741824 )) From b8e778a79db42efd59ff6cbb20c8fe47df474929 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 14 Oct 2025 14:16:20 +0200 Subject: [PATCH 2/5] fix: Configure ports for Slirp networking (#1062) --- src/network.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network.sh b/src/network.sh index d72a5d8..ea1a0c9 100644 --- a/src/network.sh +++ b/src/network.sh @@ -213,7 +213,7 @@ getSlirp() { local args="" local list="" - list=$(getUserPorts) + list=$(getUserPorts "${USER_PORTS:-}") list="${list//,/ }" list="${list## }" list="${list%% }" @@ -255,7 +255,7 @@ configureSlirp() { NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST" local forward="" - forward=$(getUserPorts "${USER_PORTS:-}") + forward=$(getSlirp) [ -n "$forward" ] && NET_OPTS+=",$forward" if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then From ea49cb144b172d0181833fd82f33b17bcd76e02a Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 14 Oct 2025 16:44:11 +0200 Subject: [PATCH 3/5] feat: Validate user port configuration (#1063) --- src/network.sh | 64 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/src/network.sh b/src/network.sh index ea1a0c9..bebb8a8 100644 --- a/src/network.sh +++ b/src/network.sh @@ -185,26 +185,68 @@ configureDNS() { getHostPorts() { - local list="$1" + local list="${HOST_PORTS:-}" list=$(echo "${list// /}" | sed 's/,*$//g') + list="${list//,,/,}" [ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT" + # Remove duplicates + list=$(echo "$list," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g') + echo "$list" return 0 } getUserPorts() { - local args="" - local list=$1 + local list="${USER_PORTS:-}" list=$(echo "${list// /}" | sed 's/,*$//g') local ssh="22" - local dsm="5000" + local dsm="5000,5001" [ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm" - echo "$list" + list="${list//,,/,}" + list="${list//,/ }" + list="${list## }" + list="${list%% }" + + local exclude + exclude=$(getHostPorts) + exclude="${exclude//,/ }" + exclude="${exclude## }" + exclude="${exclude%% }" + + local ports="" + + for userport in $list; do + + local num="${userport///tcp}" + num="${num///udp}" + [ -z "$num" ] && continue + + for hostport in $exclude; do + + local val="${hostport///tcp}" + + if [[ "$num" == "${val///udp}" ]]; then + num="" + warn "Could not assign port ${val///udp} to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!" + fi + + done + + if [ -n "$num" ]; then + [ -z "$ports" ] && ports="$userport" || ports+=",$userport" + fi + + done + + # Remove duplicates + ports=$(echo "$ports," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g') + + echo "$ports" return 0 } @@ -213,15 +255,15 @@ getSlirp() { local args="" local list="" - list=$(getUserPorts "${USER_PORTS:-}") + list=$(getUserPorts) list="${list//,/ }" list="${list## }" list="${list%% }" for port in $list; do - proto="tcp" - num="${port%/tcp}" + local proto="tcp" + local num="${port%/tcp}" if [[ "$port" == *"/udp" ]]; then proto="udp" @@ -235,6 +277,8 @@ getSlirp() { args+="hostfwd=$proto::$num-$VM_NET_IP:$num," done + args=$(echo "$args" | sed 's/,*$//g') + echo "${args%?}" return 0 } @@ -299,7 +343,7 @@ configurePasst() { [ -n "$PASST_MTU" ] && PASST_OPTS+=" -m $PASST_MTU" local forward="" - forward=$(getUserPorts "${USER_PORTS:-}") + forward=$(getUserPorts) forward="${forward///tcp}" forward="${forward///udp}" @@ -447,7 +491,7 @@ configureNAT() { update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null fi - exclude=$(getHostPorts "$HOST_PORTS") + exclude=$(getHostPorts) if [ -n "$exclude" ]; then if [[ "$exclude" != *","* ]]; then From c2fa58ef2712a830453cdb56377284c7ae64b0d2 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 15 Oct 2025 10:31:42 +0200 Subject: [PATCH 4/5] feat: Fall back to slirp when passt fails (#1064) --- src/network.sh | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/src/network.sh b/src/network.sh index bebb8a8..c3fff31 100644 --- a/src/network.sh +++ b/src/network.sh @@ -185,14 +185,12 @@ configureDNS() { getHostPorts() { - local list="${HOST_PORTS:-}" - list=$(echo "${list// /}" | sed 's/,*$//g') - list="${list//,,/,}" - - [ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT" + local list="" + list+="$MON_PORT," + list+="${HOST_PORTS// /}," # Remove duplicates - list=$(echo "$list," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g') + list=$(echo "${list//,,/,}," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g') echo "$list" return 0 @@ -200,33 +198,25 @@ getHostPorts() { getUserPorts() { - local list="${USER_PORTS:-}" - list=$(echo "${list// /}" | sed 's/,*$//g') - local ssh="22" local dsm="5000,5001" - [ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm" - list="${list//,,/,}" - list="${list//,/ }" - list="${list## }" - list="${list%% }" + local list="$ssh,$dsm," + list+="${USER_PORTS// /}," local exclude exclude=$(getHostPorts) - exclude="${exclude//,/ }" - exclude="${exclude## }" - exclude="${exclude%% }" local ports="" + local userport="" + local hostport="" - for userport in $list; do + for userport in ${list//,/ }; do local num="${userport///tcp}" num="${num///udp}" - [ -z "$num" ] && continue - for hostport in $exclude; do + for hostport in ${exclude//,/ }; do local val="${hostport///tcp}" @@ -237,14 +227,12 @@ getUserPorts() { done - if [ -n "$num" ]; then - [ -z "$ports" ] && ports="$userport" || ports+=",$userport" - fi + [ -n "$num" ] && ports+="$userport," done # Remove duplicates - ports=$(echo "$ports," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g') + ports=$(echo "${ports//,,/,}," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g') echo "$ports" return 0 @@ -256,14 +244,12 @@ getSlirp() { local list="" list=$(getUserPorts) - list="${list//,/ }" - list="${list## }" - list="${list%% }" - for port in $list; do + for port in ${list//,/ }; do local proto="tcp" local num="${port%/tcp}" + [ -z "$num" ] && continue if [[ "$port" == *"/udp" ]]; then proto="udp" @@ -305,7 +291,7 @@ configureSlirp() { if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then echo "$gateway" > /run/shm/qemu.gw else - cp /etc/resolv.conf /etc/resolv.dnsmasq + [ ! -f /etc/resolv.dnsmasq ] && cp /etc/resolv.conf /etc/resolv.dnsmasq configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1 echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf fi @@ -360,7 +346,7 @@ configurePasst() { PASST_OPTS+=" -q" if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then - cp /etc/resolv.conf /etc/resolv.dnsmasq + [ ! -f /etc/resolv.dnsmasq ] && cp /etc/resolv.conf /etc/resolv.dnsmasq echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf fi @@ -375,8 +361,8 @@ configurePasst() { if (( rc != 0 )); then [ -f "$log" ] && cat "$log" - error "Failed to start passt, reason: $rc" - return 1 + warn "failed to start passt ($rc), falling back to slirp networking!" + configureSlirp && return 0 || return 1 fi fi From 48e7a9fff0fd0dc47390bcbdc08230826c3ca5bf Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 15 Oct 2025 11:37:05 +0200 Subject: [PATCH 5/5] fix: Round down minimum disk size (#1065) --- src/disk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/disk.sh b/src/disk.sh index 340b444..8fff2d4 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -437,7 +437,7 @@ addDisk () { local SPARE=536870912 SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1) (( SPACE < SPARE )) && SPACE="$SPARE" || SPACE=$((SPACE-SPARE)) - GB=$(( SPACE/1073741824 )) + GB=$(( SPACE/1073741825 )) DISK_SPACE="${GB}G" fi