fix: Verify files are not empty (#689)

This commit is contained in:
Kroese 2024-04-16 15:35:35 +02:00 committed by GitHub
parent 5015597183
commit e81dc0f31d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 27 additions and 25 deletions

View File

@ -4,13 +4,13 @@ set -Eeuo pipefail
: "${NETWORK:="Y"}" : "${NETWORK:="Y"}"
[ -f "/run/shm/qemu.end" ] && echo "QEMU is shutting down.." && exit 1 [ -f "/run/shm/qemu.end" ] && echo "QEMU is shutting down.." && exit 1
[ ! -f "/run/shm/qemu.pid" ] && echo "QEMU is not running yet.." && exit 0 [ ! -s "/run/shm/qemu.pid" ] && echo "QEMU is not running yet.." && exit 0
[[ "$NETWORK" != [Yy1]* ]] && echo "Networking is disabled.." && exit 0 [[ "$NETWORK" != [Yy1]* ]] && echo "Networking is disabled.." && exit 0
file="/run/shm/dsm.url" file="/run/shm/dsm.url"
address="/run/shm/qemu.ip" address="/run/shm/qemu.ip"
[ ! -f "$file" ] && echo "DSM has not enabled networking yet.." && exit 1 [ ! -s "$file" ] && echo "DSM has not enabled networking yet.." && exit 1
location=$(<"$file") location=$(<"$file")

View File

@ -13,8 +13,8 @@ set -Eeuo pipefail
BOOT="$STORAGE/$BASE.boot.img" BOOT="$STORAGE/$BASE.boot.img"
SYSTEM="$STORAGE/$BASE.system.img" SYSTEM="$STORAGE/$BASE.system.img"
[ ! -f "$BOOT" ] && error "Virtual DSM boot-image does not exist ($BOOT)" && exit 81 [ ! -s "$BOOT" ] && error "Virtual DSM boot-image does not exist ($BOOT)" && exit 81
[ ! -f "$SYSTEM" ] && error "Virtual DSM system-image does not exist ($SYSTEM)" && exit 82 [ ! -s "$SYSTEM" ] && error "Virtual DSM system-image does not exist ($SYSTEM)" && exit 82
DISK_OPTS="\ DISK_OPTS="\
-object iothread,id=io2 \ -object iothread,id=io2 \
@ -386,7 +386,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"
@ -395,12 +395,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

@ -5,6 +5,7 @@ set -Eeuo pipefail
if [ -f "$STORAGE/dsm.ver" ]; then if [ -f "$STORAGE/dsm.ver" ]; then
BASE=$(<"$STORAGE/dsm.ver") BASE=$(<"$STORAGE/dsm.ver")
[ -z "$BASE" ] && BASE="DSM_VirtualDSM_69057"
else else
# Fallback for old installs # Fallback for old installs
BASE="DSM_VirtualDSM_42962" BASE="DSM_VirtualDSM_42962"
@ -12,14 +13,14 @@ fi
if [ -n "$URL" ]; then if [ -n "$URL" ]; then
BASE=$(basename "$URL" .pat) BASE=$(basename "$URL" .pat)
if [ ! -f "$STORAGE/$BASE.system.img" ]; then if [ ! -s "$STORAGE/$BASE.system.img" ]; then
BASE=$(basename "${URL%%\?*}" .pat) BASE=$(basename "${URL%%\?*}" .pat)
: "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}" : "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g') BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
fi fi
fi fi
if [[ -f "$STORAGE/$BASE.boot.img" ]] && [[ -f "$STORAGE/$BASE.system.img" ]]; then if [[ -s "$STORAGE/$BASE.boot.img" ]] && [[ -s "$STORAGE/$BASE.system.img" ]]; then
return 0 # Previous installation found return 0 # Previous installation found
fi fi
@ -106,7 +107,7 @@ fi
ROOT="Y" ROOT="Y"
RDC="$STORAGE/dsm.rd" RDC="$STORAGE/dsm.rd"
if [ ! -f "$RDC" ]; then if [ ! -s "$RDC" ]; then
MSG="Downloading installer..." MSG="Downloading installer..."
PRG="Downloading installer ([P])..." PRG="Downloading installer ([P])..."
@ -118,6 +119,7 @@ if [ ! -f "$RDC" ]; then
LOC="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat" LOC="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
rm -f "$RD" rm -f "$RD"
rm -f "$RDC"
/run/progress.sh "$RD" "$PRG" & /run/progress.sh "$RD" "$PRG" &
{ curl -r "$POS" -sfk -S -o "$RD" "$LOC"; rc=$?; } || : { curl -r "$POS" -sfk -S -o "$RD" "$LOC"; rc=$?; } || :
@ -215,7 +217,7 @@ else
fi fi
[ ! -f "$PAT" ] && error "Failed to download $URL" && exit 69 [ ! -s "$PAT" ] && error "Failed to download $URL" && exit 69
SIZE=$(stat -c%s "$PAT") SIZE=$(stat -c%s "$PAT")
@ -252,7 +254,7 @@ MSG="Preparing system partition..."
info "Install: $MSG" && html "$MSG" info "Install: $MSG" && html "$MSG"
BOOT=$(find "$TMP" -name "*.bin.zip") BOOT=$(find "$TMP" -name "*.bin.zip")
[ ! -f "$BOOT" ] && error "The PAT file contains no boot image." && exit 67 [ ! -s "$BOOT" ] && error "The PAT file contains no boot image." && exit 67
BOOT=$(echo "$BOOT" | head -c -5) BOOT=$(echo "$BOOT" | head -c -5)
unzip -q -o "$BOOT".zip -d "$TMP" unzip -q -o "$BOOT".zip -d "$TMP"
@ -313,15 +315,15 @@ IDB="$TMP/indexdb"
PKG="$TMP/packages" PKG="$TMP/packages"
HDP="$TMP/synohdpack_img" HDP="$TMP/synohdpack_img"
[ ! -f "$HDA.tgz" ] && error "The PAT file contains no OS image." && exit 64 [ ! -s "$HDA.tgz" ] && error "The PAT file contains no OS image." && exit 64
mv "$HDA.tgz" "$HDA.txz" mv "$HDA.tgz" "$HDA.txz"
[ -d "$PKG" ] && mv "$PKG/" "$MOUNT/.SynoUpgradePackages/" [ -d "$PKG" ] && mv "$PKG/" "$MOUNT/.SynoUpgradePackages/"
rm -f "$MOUNT/.SynoUpgradePackages/ActiveInsight-"* rm -f "$MOUNT/.SynoUpgradePackages/ActiveInsight-"*
[ -f "$HDP.txz" ] && tar xpfJ "$HDP.txz" --absolute-names -C "$MOUNT/" [ -s "$HDP.txz" ] && tar xpfJ "$HDP.txz" --absolute-names -C "$MOUNT/"
if [ -f "$IDB.txz" ]; then if [ -s "$IDB.txz" ]; then
INDEX_DB="$MOUNT/usr/syno/synoman/indexdb/" INDEX_DB="$MOUNT/usr/syno/synoman/indexdb/"
mkdir -p "$INDEX_DB" mkdir -p "$INDEX_DB"
tar xpfJ "$IDB.txz" --absolute-names -C "$INDEX_DB" tar xpfJ "$IDB.txz" --absolute-names -C "$INDEX_DB"

View File

@ -200,7 +200,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
@ -228,7 +228,7 @@ getInfo() {
if [ -z "$VM_NET_MAC" ]; then if [ -z "$VM_NET_MAC" ]; then
local file="$STORAGE/dsm.mac" local file="$STORAGE/dsm.mac"
[ -f "$file" ] && VM_NET_MAC=$(<"$file") [ -s "$file" ] && VM_NET_MAC=$(<"$file")
if [ -z "$VM_NET_MAC" ]; then if [ -z "$VM_NET_MAC" ]; then
# Generate MAC address based on Docker container ID in hostname # Generate MAC address based on Docker container ID in hostname
VM_NET_MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:11:32:\3:\4:\5/') VM_NET_MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:11:32:\3:\4:\5/')

View File

@ -36,7 +36,7 @@ finish() {
touch "$QEMU_END" touch "$QEMU_END"
if [ -f "$QEMU_PID" ]; then if [ -s "$QEMU_PID" ]; then
pid=$(<"$QEMU_PID") pid=$(<"$QEMU_PID")
echo && error "Forcefully terminating QEMU process, reason: $reason..." echo && error "Forcefully terminating QEMU process, reason: $reason..."
@ -45,7 +45,7 @@ finish() {
while isAlive "$pid"; do while isAlive "$pid"; do
sleep 1 sleep 1
# Workaround for zombie pid # Workaround for zombie pid
[ ! -f "$QEMU_PID" ] && break [ ! -s "$QEMU_PID" ] && break
done done
fi fi
@ -64,7 +64,7 @@ terminal() {
local dev="" local dev=""
if [ -f "$QEMU_OUT" ]; then if [ -s "$QEMU_OUT" ]; then
local msg local msg
msg=$(<"$QEMU_OUT") msg=$(<"$QEMU_OUT")
@ -113,7 +113,7 @@ _graceful_shutdown() {
touch "$QEMU_END" touch "$QEMU_END"
echo && info "Received $1 signal, sending shutdown command..." echo && info "Received $1 signal, sending shutdown command..."
if [ ! -f "$QEMU_PID" ]; then if [ ! -s "$QEMU_PID" ]; then
echo && error "QEMU PID file does not exist?" echo && error "QEMU PID file does not exist?"
finish "$code" && return "$code" finish "$code" && return "$code"
fi fi
@ -157,7 +157,7 @@ _graceful_shutdown() {
[[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt/$QEMU_TIMEOUT)" [[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt/$QEMU_TIMEOUT)"
# Workaround for zombie pid # Workaround for zombie pid
[ ! -f "$QEMU_PID" ] && break [ ! -s "$QEMU_PID" ] && break
done done

View File

@ -21,7 +21,7 @@ resp_err="Guest returned an invalid response:"
curl_err="Failed to connect to guest: curl error" curl_err="Failed to connect to guest: curl error"
jq_err="Failed to parse response from guest: jq error" jq_err="Failed to parse response from guest: jq error"
while [ ! -f "$file" ] while [ ! -s "$file" ]
do do
# Check if not shutting down # Check if not shutting down
@ -30,7 +30,7 @@ do
sleep 3 sleep 3
[ -f "$shutdown" ] && exit 1 [ -f "$shutdown" ] && exit 1
[ -f "$file" ] && break [ -s "$file" ] && break
# Retrieve network info from guest VM # Retrieve network info from guest VM
{ json=$(curl -m 20 -sk "$url"); rc=$?; } || : { json=$(curl -m 20 -sk "$url"); rc=$?; } || :

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/')