From 2ece865417d89b956e53c0b7378bb9998cd136e6 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 5 Jun 2024 18:18:29 +0200 Subject: [PATCH] fix: Download error messages (#756) --- src/config.sh | 4 ++-- src/disk.sh | 43 +++++++++++++++++++++++++++---------------- src/display.sh | 2 +- src/install.sh | 26 ++++++++++++++++---------- src/network.sh | 13 +++++-------- src/power.sh | 2 +- src/proc.sh | 16 ++++++++-------- src/serial.sh | 2 +- 8 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/config.sh b/src/config.sh index 20d85f1..f38bec1 100644 --- a/src/config.sh +++ b/src/config.sh @@ -6,8 +6,8 @@ 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,smm=off,usb=off,vmport=off,dump-guest-core=off,hpet=off${KVM_OPTS}" DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4" -DEV_OPTS="$DEV_OPTS -object rng-random,id=objrng0,filename=/dev/urandom" -DEV_OPTS="$DEV_OPTS -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c" +DEV_OPTS+=" -object rng-random,id=objrng0,filename=/dev/urandom" +DEV_OPTS+=" -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c" ARGS="$DEF_OPTS $CPU_OPTS $RAM_OPTS $MAC_OPTS $DISPLAY_OPTS $MON_OPTS $SERIAL_OPTS $NET_OPTS $DISK_OPTS $DEV_OPTS $ARGUMENTS" ARGS=$(echo "$ARGS" | sed 's/\t/ /g' | tr -s ' ') diff --git a/src/disk.sh b/src/disk.sh index 2000710..b914a05 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -90,6 +90,7 @@ supportsDirect() { } createDisk() { + local DISK_FILE=$1 local DISK_SPACE=$2 local DISK_DESC=$3 @@ -152,8 +153,8 @@ createDisk() { qcow2) local DISK_PARAM="$DISK_ALLOC" - isCow "$FS" && DISK_PARAM="$DISK_PARAM,nocow=on" - [ -n "$DISK_FLAGS" ] && DISK_PARAM="$DISK_PARAM,$DISK_FLAGS" + isCow "$FS" && DISK_PARAM+=",nocow=on" + [ -n "$DISK_FLAGS" ] && DISK_PARAM+=",$DISK_FLAGS" if ! qemu-img create -f "$DISK_FMT" -o "$DISK_PARAM" -- "$DISK_FILE" "$DATA_SIZE" ; then rm -f "$DISK_FILE" @@ -173,6 +174,7 @@ createDisk() { } resizeDisk() { + local DISK_FILE=$1 local DISK_SPACE=$2 local DISK_DESC=$3 @@ -238,6 +240,7 @@ resizeDisk() { } convertDisk() { + local SOURCE_FILE=$1 local SOURCE_FMT=$2 local DST_FILE=$3 @@ -268,18 +271,19 @@ convertDisk() { fi fi - html "Converting $DISK_DESC to $DST_FMT..." - info "Converting $DISK_DESC to $DST_FMT, please wait until completed..." + local msg="Converting $DISK_DESC to $DST_FMT" + html "$msg..." + info "$msg, please wait until completed..." local CONV_FLAGS="-p" local DISK_PARAM="$DISK_ALLOC" - isCow "$FS" && DISK_PARAM="$DISK_PARAM,nocow=on" + isCow "$FS" && DISK_PARAM+=",nocow=on" if [[ "$DST_FMT" != "raw" ]]; then if [[ "$ALLOCATE" == [Nn]* ]]; then - CONV_FLAGS="$CONV_FLAGS -c" + CONV_FLAGS+=" -c" fi - [ -n "$DISK_FLAGS" ] && DISK_PARAM="$DISK_PARAM,$DISK_FLAGS" + [ -n "$DISK_FLAGS" ] && DISK_PARAM+=",$DISK_FLAGS" fi # shellcheck disable=SC2086 @@ -308,13 +312,15 @@ convertDisk() { fi fi - html "Conversion of $DISK_DESC completed..." - info "Conversion of $DISK_DESC to $DST_FMT completed succesfully!" + msg="Conversion of $DISK_DESC" + html "$msg completed..." + info "$msg to $DST_FMT completed succesfully!" return 0 } checkFS () { + local FS=$1 local DISK_FILE=$2 local DISK_DESC=$3 @@ -348,6 +354,7 @@ checkFS () { } createDevice () { + local DISK_FILE=$1 local DISK_TYPE=$2 local DISK_INDEX=$3 @@ -366,22 +373,22 @@ createDevice () { echo "$result" ;; "usb" ) - result="$result,if=none \ + result+=",if=none \ -device usb-storage,drive=${DISK_ID}${index}" echo "$result" ;; "ide" ) - result="$result,if=none \ + result+=",if=none \ -device ide-hd,drive=${DISK_ID},bus=ide.$DISK_INDEX,rotation_rate=$DISK_ROTATION${index}" echo "$result" ;; "blk" | "virtio-blk" ) - result="$result,if=none \ + result+=",if=none \ -device virtio-blk-pci,drive=${DISK_ID},scsi=off,bus=pcie.0,addr=$DISK_ADDRESS,iothread=io2${index}" echo "$result" ;; "scsi" | "virtio-scsi" ) - result="$result,if=none \ + result+=",if=none \ -device virtio-scsi-pci,id=${DISK_ID}b,bus=pcie.0,addr=$DISK_ADDRESS,iothread=io2 \ -device scsi-hd,drive=${DISK_ID},bus=${DISK_ID}b.0,channel=0,scsi-id=0,lun=0,rotation_rate=$DISK_ROTATION${index}" echo "$result" @@ -392,6 +399,7 @@ createDevice () { } addDisk () { + local DISK_BASE=$1 local DISK_TYPE=$2 local DISK_DESC=$3 @@ -436,6 +444,7 @@ addDisk () { else PREV_FMT="qcow2" fi + PREV_EXT=$(fmt2ext "$PREV_FMT") if [ -s "$DISK_BASE.$PREV_EXT" ] ; then @@ -458,12 +467,13 @@ addDisk () { fi OPTS=$(createDevice "$DISK_FILE" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE") - DISK_OPTS="$DISK_OPTS $OPTS" + DISK_OPTS+=" $OPTS" return 0 } addDevice () { + local DISK_DEV=$1 local DISK_TYPE=$2 local DISK_INDEX=$3 @@ -474,7 +484,7 @@ addDevice () { local OPTS OPTS=$(createDevice "$DISK_DEV" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "raw" "$DISK_IO" "$DISK_CACHE") - DISK_OPTS="$DISK_OPTS $OPTS" + DISK_OPTS+=" $OPTS" return 0 } @@ -585,7 +595,8 @@ else addDisk "$DISK4_FILE" "$DISK_TYPE" "disk4" "$DISK4_SIZE" "6" "0xf" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE" || exit $? fi -DISK_OPTS="$DISK_OPTS -object iothread,id=io2" +DISK_OPTS+=" -object iothread,id=io2" html "Initialized disks successfully..." + return 0 diff --git a/src/display.sh b/src/display.sh index 2eeaccf..60db609 100644 --- a/src/display.sh +++ b/src/display.sh @@ -16,7 +16,7 @@ if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then fi DISPLAY_OPTS="-display egl-headless,rendernode=/dev/dri/renderD128" -DISPLAY_OPTS="$DISPLAY_OPTS -vga $VGA" +DISPLAY_OPTS+=" -vga $VGA" [ ! -d /dev/dri ] && mkdir -m 755 /dev/dri diff --git a/src/install.sh b/src/install.sh index be2180e..357c2ff 100644 --- a/src/install.sh +++ b/src/install.sh @@ -146,12 +146,13 @@ if [ ! -s "$RDC" ]; then fKill "progress.sh" - (( rc == 4 )) && error "Failed to download $LOC , network failure!" && exit 60 - (( rc == 8 )) && error "Failed to download $LOC , server issued an error response!" && exit 60 + ERR="Failed to download $LOC" + (( rc == 4 )) && error "$ERR , network failure!" && exit 60 + (( rc == 8 )) && error "$ERR , server issued an error response!" && exit 60 if (( rc != 0 )); then if (( rc != 22 )) && (( rc != 56 )); then - error "Failed to download $LOC, reason: $rc" && exit 60 + error "$ERR , reason: $rc" && exit 60 fi SUM="skip" else @@ -171,9 +172,11 @@ if [ ! -s "$RDC" ]; then { wget "$LOC" -O "$PAT" -q --no-check-certificate --timeout=10 --show-progress "$PROGRESS"; rc=$?; } || : fKill "progress.sh" - (( rc == 4 )) && error "Failed to download $LOC , network failure!" && exit 60 - (( rc == 8 )) && error "Failed to download $LOC , server issued an error response!" && exit 60 - (( rc != 0 )) && error "Failed to download $LOC , reason: $rc" && exit 60 + + ERR="Failed to download $LOC" + (( rc == 4 )) && error "$ERR , network failure!" && exit 60 + (( rc == 8 )) && error "$ERR , server issued an error response!" && exit 60 + (( rc != 0 )) && error "$ERR , reason: $rc" && exit 60 tar --extract --file="$PAT" --directory="$(dirname "$RD")"/. "$(basename "$RD")" rm "$PAT" @@ -226,6 +229,8 @@ rm -rf "$TMP" && mkdir -p "$TMP" info "Install: Downloading $BASE.pat..." MSG="Downloading DSM" +ERR="Failed to download $URL" + html "$MSG..." PAT="/$BASE.pat" @@ -246,13 +251,14 @@ else { wget "$URL" -O "$PAT" -q --no-check-certificate --timeout=10 --show-progress "$PROGRESS"; rc=$?; } || : fKill "progress.sh" - (( rc == 4 )) && error "Failed to download $URL , network failure!" && exit 69 - (( rc == 8 )) && error "Failed to download $URL , server issued an error response!" && exit 69 - (( rc != 0 )) && error "Failed to download $URL , reason: $rc" && exit 69 + + (( rc == 4 )) && error "$ERR , network failure!" && exit 69 + (( rc == 8 )) && error "$ERR , server issued an error response!" && exit 69 + (( rc != 0 )) && error "$ERR , reason: $rc" && exit 69 fi -[ ! -s "$PAT" ] && error "Failed to download $URL" && exit 69 +[ ! -s "$PAT" ] && error "$ERR" && exit 69 SIZE=$(stat -c%s "$PAT") diff --git a/src/network.sh b/src/network.sh index 2d4c98f..0ba067b 100644 --- a/src/network.sh +++ b/src/network.sh @@ -81,26 +81,23 @@ configureDHCP() { configureDNS() { # dnsmasq configuration: - DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-range=$VM_NET_IP,$VM_NET_IP --dhcp-host=$VM_NET_MAC,,$VM_NET_IP,$VM_NET_HOST,infinite --dhcp-option=option:netmask,255.255.255.0" + DNSMASQ_OPTS+=" --dhcp-range=$VM_NET_IP,$VM_NET_IP --dhcp-host=$VM_NET_MAC,,$VM_NET_IP,$VM_NET_HOST,infinite --dhcp-option=option:netmask,255.255.255.0" # Create lease file for faster resolve echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:$VM_NET_MAC" > /var/lib/misc/dnsmasq.leases chmod 644 /var/lib/misc/dnsmasq.leases # Set DNS server and gateway - DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:dns-server,${VM_NET_IP%.*}.1 --dhcp-option=option:router,${VM_NET_IP%.*}.1" + DNSMASQ_OPTS+=" --dhcp-option=option:dns-server,${VM_NET_IP%.*}.1 --dhcp-option=option:router,${VM_NET_IP%.*}.1" # Add DNS entry for container - DNSMASQ_OPTS="$DNSMASQ_OPTS --address=/host.lan/${VM_NET_IP%.*}.1" + DNSMASQ_OPTS+=" --address=/host.lan/${VM_NET_IP%.*}.1" DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//') - [[ "$DEBUG" == [Yy1]* ]] && set -x if ! $DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}; then error "Failed to start dnsmasq, reason: $?" && exit 29 fi - { set +x; } 2>/dev/null - [[ "$DEBUG" == [Yy1]* ]] && echo return 0 } @@ -195,7 +192,7 @@ configureNAT() { if [ -c /dev/vhost-net ]; then { exec 40>>/dev/vhost-net; rc=$?; } 2>/dev/null || : - (( rc == 0 )) && NET_OPTS="$NET_OPTS,vhost=on,vhostfd=40" + (( rc == 0 )) && NET_OPTS+=",vhost=on,vhostfd=40" fi configureDNS @@ -354,6 +351,6 @@ else fi -NET_OPTS="$NET_OPTS -device virtio-net-pci,romfile=,netdev=hostnet0,mac=$VM_NET_MAC,id=net0" +NET_OPTS+=" -device virtio-net-pci,romfile=,netdev=hostnet0,mac=$VM_NET_MAC,id=net0" return 0 diff --git a/src/power.sh b/src/power.sh index d1eea47..ebbf27f 100644 --- a/src/power.sh +++ b/src/power.sh @@ -176,7 +176,7 @@ MON_OPTS="\ if [[ "$CONSOLE" != [Yy]* ]]; then - MON_OPTS="$MON_OPTS -daemonize -D $QEMU_LOG" + MON_OPTS+=" -daemonize -D $QEMU_LOG" _trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT diff --git a/src/proc.sh b/src/proc.sh index 404aa24..08c61c6 100644 --- a/src/proc.sh +++ b/src/proc.sh @@ -56,12 +56,12 @@ if [[ "$KVM" != [Nn]* ]]; then if ! grep -qw "sse4_2" <<< "$flags"; then info "Your CPU does not have the SSE4 instruction set that Virtual DSM requires, it will be emulated..." [ -z "$CPU_MODEL" ] && CPU_MODEL="$DEF_MODEL" - CPU_FEATURES="$CPU_FEATURES,+ssse3,+sse4.1,+sse4.2" + CPU_FEATURES+=",+ssse3,+sse4.1,+sse4.2" fi if [ -z "$CPU_MODEL" ]; then CPU_MODEL="host" - CPU_FEATURES="$CPU_FEATURES,migratable=no" + CPU_FEATURES+=",migratable=no" fi if grep -qw "svm" <<< "$flags"; then @@ -69,7 +69,7 @@ if [[ "$KVM" != [Nn]* ]]; then # AMD processor if grep -qw "tsc_scale" <<< "$flags"; then - CPU_FEATURES="$CPU_FEATURES,+invtsc" + CPU_FEATURES+=",+invtsc" fi else @@ -79,7 +79,7 @@ if [[ "$KVM" != [Nn]* ]]; then vmx=$(sed -ne '/^vmx flags/s/^.*: //p' /proc/cpuinfo) if grep -qw "tsc_scaling" <<< "$vmx"; then - CPU_FEATURES="$CPU_FEATURES,+invtsc" + CPU_FEATURES+=",+invtsc" fi fi @@ -96,13 +96,13 @@ else if [ -z "$CPU_MODEL" ]; then if [[ "$ARCH" == "amd64" ]]; then CPU_MODEL="max" - CPU_FEATURES="$CPU_FEATURES,migratable=no" + CPU_FEATURES+=",migratable=no" else CPU_MODEL="$DEF_MODEL" fi fi - CPU_FEATURES="$CPU_FEATURES,+ssse3,+sse4.1,+sse4.2" + CPU_FEATURES+=",+ssse3,+sse4.1,+sse4.2" fi @@ -129,9 +129,9 @@ if [ -n "$HOST_CPU" ]; then else HOST_CPU="QEMU, Virtual CPU," if [ "$ARCH" == "amd64" ]; then - HOST_CPU="$HOST_CPU X86_64" + HOST_CPU+=" X86_64" else - HOST_CPU="$HOST_CPU $ARCH" + HOST_CPU+=" $ARCH" fi fi diff --git a/src/serial.sh b/src/serial.sh index 1c5d1fd..2017828 100644 --- a/src/serial.sh +++ b/src/serial.sh @@ -67,7 +67,7 @@ else SERIAL_OPTS="-serial mon:stdio" fi -SERIAL_OPTS="$SERIAL_OPTS \ +SERIAL_OPTS+=" \ -device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \ -chardev socket,id=charchannel0,host=127.0.0.1,port=12345,reconnect=10 \ -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=vchannel"