fix: Verify files are not empty (#37)

This commit is contained in:
Kroese 2024-04-16 15:00:38 +02:00 committed by GitHub
parent 3448634874
commit d1f9191e3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 11 deletions

View file

@ -38,14 +38,16 @@ fi
AAVMF="/usr/share/AAVMF/" AAVMF="/usr/share/AAVMF/"
DEST="$STORAGE/${BOOT_MODE,,}" DEST="$STORAGE/${BOOT_MODE,,}"
if [ ! -f "$DEST.rom" ]; then if [ ! -s "$DEST.rom" ]; then
[ ! -f "$AAVMF/$ROM" ] && error "UEFI boot file ($AAVMF/$ROM) not found!" && exit 44 [ ! -s "$AAVMF/$ROM" ] && error "UEFI boot file ($AAVMF/$ROM) not found!" && exit 44
rm -f "$DEST.rom"
dd if=/dev/zero "of=$DEST.rom" bs=1M count=64 status=none dd if=/dev/zero "of=$DEST.rom" bs=1M count=64 status=none
dd "if=$AAVMF/$ROM" "of=$DEST.rom" conv=notrunc status=none dd "if=$AAVMF/$ROM" "of=$DEST.rom" conv=notrunc status=none
fi fi
if [ ! -f "$DEST.vars" ]; then if [ ! -s "$DEST.vars" ]; then
[ ! -f "$AAVMF/$VARS" ] && error "UEFI vars file ($AAVMF/$VARS) not found!" && exit 45 [ ! -s "$AAVMF/$VARS" ] && error "UEFI vars file ($AAVMF/$VARS) not found!" && exit 45
rm -f "$DEST.vars"
dd if=/dev/zero "of=$DEST.vars" bs=1M count=64 status=none dd if=/dev/zero "of=$DEST.vars" bs=1M count=64 status=none
dd "if=$AAVMF/$VARS" "of=$DEST.vars" conv=notrunc status=none dd "if=$AAVMF/$VARS" "of=$DEST.vars" conv=notrunc status=none
fi fi

View file

@ -385,7 +385,7 @@ addDisk () {
FS=$(stat -f -c %T "$DIR") FS=$(stat -f -c %T "$DIR")
checkFS "$FS" "$DISK_FILE" "$DISK_DESC" || exit $? checkFS "$FS" "$DISK_FILE" "$DISK_DESC" || exit $?
if ! [ -f "$DISK_FILE" ] ; then if ! [ -s "$DISK_FILE" ] ; then
if [[ "${DISK_FMT,,}" != "raw" ]]; then if [[ "${DISK_FMT,,}" != "raw" ]]; then
PREV_FMT="raw" PREV_FMT="raw"
@ -394,12 +394,12 @@ addDisk () {
fi fi
PREV_EXT=$(fmt2ext "$PREV_FMT") PREV_EXT=$(fmt2ext "$PREV_FMT")
if [ -f "$DISK_BASE.$PREV_EXT" ] ; then if [ -s "$DISK_BASE.$PREV_EXT" ] ; then
convertDisk "$DISK_BASE.$PREV_EXT" "$PREV_FMT" "$DISK_FILE" "$DISK_FMT" "$DISK_BASE" "$DISK_DESC" "$FS" || exit $? convertDisk "$DISK_BASE.$PREV_EXT" "$PREV_FMT" "$DISK_FILE" "$DISK_FMT" "$DISK_BASE" "$DISK_DESC" "$FS" || exit $?
fi fi
fi fi
if [ -f "$DISK_FILE" ]; then if [ -s "$DISK_FILE" ]; then
CUR_SIZE=$(getSize "$DISK_FILE") CUR_SIZE=$(getSize "$DISK_FILE")

View file

@ -37,7 +37,7 @@ info "$MSG" && html "$MSG"
fKill "progress.sh" fKill "progress.sh"
(( rc != 0 )) && error "Failed to download $BOOT , reason: $rc" && exit 60 (( rc != 0 )) && error "Failed to download $BOOT , reason: $rc" && exit 60
[ ! -f "$TMP" ] && error "Failed to download $BOOT" && exit 61 [ ! -s "$TMP" ] && error "Failed to download $BOOT" && exit 61
html "Download finished successfully..." html "Download finished successfully..."

View file

@ -223,7 +223,7 @@ closeNetwork() {
else else
local pid="/var/run/dnsmasq.pid" local pid="/var/run/dnsmasq.pid"
[ -f "$pid" ] && pKill "$(<"$pid")" [ -s "$pid" ] && pKill "$(<"$pid")"
ip link set "$VM_NET_TAP" down promisc off || true ip link set "$VM_NET_TAP" down promisc off || true
ip link delete "$VM_NET_TAP" || true ip link delete "$VM_NET_TAP" || true
@ -251,7 +251,7 @@ getInfo() {
if [ -z "$MAC" ]; then if [ -z "$MAC" ]; then
local file="$STORAGE/$PROCESS.mac" local file="$STORAGE/$PROCESS.mac"
[ -f "$file" ] && MAC=$(<"$file") [ -s "$file" ] && MAC=$(<"$file")
if [ -z "$MAC" ]; then if [ -z "$MAC" ]; then
# Generate MAC address based on Docker container ID in hostname # Generate MAC address based on Docker container ID in hostname
MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/') MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')

View file

@ -21,7 +21,7 @@ fi
while true while true
do do
if [ -f "$file" ]; then if [ -s "$file" ]; then
bytes=$(du -sb "$file" | cut -f1) bytes=$(du -sb "$file" | cut -f1)
if (( bytes > 1000 )); then if (( bytes > 1000 )); then
size=$(echo "$bytes" | numfmt --to=iec --suffix=B | sed -r 's/([A-Z])/ \1/') size=$(echo "$bytes" | numfmt --to=iec --suffix=B | sed -r 's/([A-Z])/ \1/')