feat: Add returnvalues to functions (#1210)

This commit is contained in:
Kroese
2026-07-06 03:48:39 +02:00
committed by GitHub
parent 415aaa3038
commit 954a6076ad
7 changed files with 56 additions and 0 deletions
+2
View File
@@ -119,6 +119,8 @@ allocateRaw() {
fallocate -l "$DATA_SIZE" "$DISK_FILE" &>/dev/null && return 0
fallocate -l -x "$DATA_SIZE" "$DISK_FILE" && return 0
truncate -s "$DATA_SIZE" "$DISK_FILE"
return 0
}
getDiskOptions() {
+8
View File
@@ -34,6 +34,8 @@ checkConfiguredMemory() {
fi
fi
fi
return 0
}
configureHalfMemory() {
@@ -50,6 +52,8 @@ configureHalfMemory() {
else
RAM_SIZE="max"
fi
return 0
}
configureMaxMemory() {
@@ -77,6 +81,8 @@ configureMaxMemory() {
RAM_SIZE="${wanted}M"
info "Allocated $wanted MB of RAM for the virtual machine."
return 0
}
checkMinimumMemory() {
@@ -89,6 +95,8 @@ checkMinimumMemory() {
error "Not enough memory available, there is only $wanted MB left!"
exit 16
fi
return 0
}
checkConfiguredMemory
+2
View File
@@ -22,6 +22,8 @@ _trap() {
for sig; do
trap "$func $sig" "$sig"
done
return 0
}
app() {
+8
View File
@@ -95,6 +95,8 @@ readGuestIp() {
writeDsmLocation() {
echo "$ip:$port" > "$file"
return 0
}
pollGuestLocation() {
@@ -137,6 +139,8 @@ writeDhcpPage() {
echo "$html" > "$page"
echo "$body" > "$msgs"
return 0
}
buildStaticMessage() {
@@ -152,6 +156,8 @@ buildStaticMessage() {
else
msg="http://$ip:$port"
fi
return 0
}
printLoginMessage() {
@@ -160,6 +166,8 @@ printLoginMessage() {
info " You can now login to DSM at $msg"
info "-----------------------------------------------------------"
echo "" >&2
return 0
}
pollGuestLocation
+22
View File
@@ -15,6 +15,8 @@ selectClocksource() {
CLOCKSOURCE="tsc"
[[ "${ARCH,,}" == "arm64" ]] && CLOCKSOURCE="arch_sys_counter"
CLOCK="/sys/devices/system/clocksource/clocksource0/current_clocksource"
return 0
}
checkClocksource() {
@@ -35,6 +37,8 @@ checkClocksource() {
"hpet" ) warn "unsupported clock source detected: '$result'. Please set host clock source to '$CLOCKSOURCE'." ;;
*) warn "unexpected clock source detected: '$result'. Please set host clock source to '$CLOCKSOURCE'." ;;
esac
return 0
}
checkSse42() {
@@ -42,6 +46,8 @@ checkSse42() {
error "Your CPU does not have the SSE4 instruction set that Virtual DSM requires!"
! enabled "$DEBUG" && exit 88
fi
return 0
}
configureKvmCpuModel() {
@@ -53,6 +59,8 @@ configureKvmCpuModel() {
CPU_MODEL="host"
CPU_FEATURES+=",migratable=no"
fi
return 0
}
appendKvmInvtscFeature() {
@@ -74,12 +82,16 @@ appendKvmInvtscFeature() {
fi
fi
return 0
}
configureKvm() {
configureKvmCpuModel
checkSse42
appendKvmInvtscFeature
return 0
}
configureTcgCpuModel() {
@@ -94,6 +106,8 @@ configureTcgCpuModel() {
else
CPU_MODEL="qemu64"
fi
return 0
}
configureTcg() {
@@ -107,6 +121,8 @@ configureTcg() {
configureTcgCpuModel
CPU_FEATURES+=",+ssse3,+sse4.1,+sse4.2"
return 0
}
extractHostCpuArgument() {
@@ -136,6 +152,8 @@ extractHostCpuArgument() {
fi
fi
return 0
}
composeCpuFlags() {
@@ -153,6 +171,8 @@ composeCpuFlags() {
CPU_FLAGS="$CPU_MODEL,$CPU_FEATURES,$CPU_FLAGS"
fi
fi
return 0
}
configureHostCpuName() {
@@ -171,6 +191,8 @@ configureHostCpuName() {
HOST_CPU+=" $ARCH"
fi
fi
return 0
}
selectClocksource
+6
View File
@@ -32,6 +32,8 @@ validateHostMac() {
if [[ ${#HOST_MAC} != 17 ]]; then
error "Invalid HOST_MAC address: '$HOST_MAC', should be 12 or 17 digits long!" && exit 28
fi
return 0
}
buildHostArguments() {
@@ -44,6 +46,8 @@ buildHostArguments() {
[ -n "$HOST_MODEL" ] && HOST_ARGS+=("-model=$HOST_MODEL")
[ -n "$HOST_SERIAL" ] && HOST_ARGS+=("-hostsn=$HOST_SERIAL")
[ -n "$GUEST_SERIAL" ] && HOST_ARGS+=("-guestsn=$GUEST_SERIAL")
return 0
}
startHostBinary() {
@@ -80,6 +84,8 @@ configureSerialPorts() {
-device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \
-chardev socket,id=charchannel0,host=127.0.0.1,port=$CHR_PORT,reconnect=10 \
-device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=vchannel"
return 0
}
validateHostMac
+8
View File
@@ -18,11 +18,15 @@ WSD_PID="$QEMU_DIR/websocketd.pid"
prepareWebFiles() {
cp -r /var/www/* "$QEMU_DIR"
rm -f "$WSD_PID" "$WEB_PID"
return 0
}
configureWebPorts() {
sed -i "s/listen 5000 default_server;/listen $WEB_PORT default_server;/g" /etc/nginx/sites-enabled/web.conf
sed -i "s/proxy_pass http:\/\/127.0.0.1:8004\/;/proxy_pass http:\/\/127.0.0.1:$WSD_PORT\/;/g" /etc/nginx/sites-enabled/web.conf
return 0
}
configureIpv6Listen() {
@@ -31,6 +35,8 @@ configureIpv6Listen() {
if [ -f /proc/net/if_inet6 ] && [[ "$(cat /proc/sys/net/ipv6/conf/all/disable_ipv6 2>/dev/null)" != "1" ]] && [ -n "$(ifconfig -a | grep inet6)" ]; then
sed -i "s/listen $WEB_PORT default_server;/listen [::]:$WEB_PORT default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf
fi
return 0
}
configureWebServer() {
@@ -40,6 +46,8 @@ configureWebServer() {
configureWebPorts
configureIpv6Listen
return 0
}
startWebServer() {