Unverified Commit e81dc0f3 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

fix: Verify files are not empty (#689)

parent 50155971
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4,13 +4,13 @@ set -Eeuo pipefail
: "${NETWORK:="Y"}"

[ -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

file="/run/shm/dsm.url"
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")

+5 −5
Original line number Diff line number Diff line
@@ -13,8 +13,8 @@ set -Eeuo pipefail
BOOT="$STORAGE/$BASE.boot.img"
SYSTEM="$STORAGE/$BASE.system.img"

[ ! -f "$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 "$BOOT" ] && error "Virtual DSM boot-image does not exist ($BOOT)" && exit 81
[ ! -s "$SYSTEM" ] && error "Virtual DSM system-image does not exist ($SYSTEM)" && exit 82

DISK_OPTS="\
    -object iothread,id=io2 \
@@ -386,7 +386,7 @@ addDisk () {
  FS=$(stat -f -c %T "$DIR")
  checkFS "$FS" "$DISK_FILE" "$DISK_DESC" || exit $?

  if ! [ -f "$DISK_FILE" ] ; then
  if ! [ -s "$DISK_FILE" ] ; then

    if [[ "${DISK_FMT,,}" != "raw" ]]; then
      PREV_FMT="raw"
@@ -395,12 +395,12 @@ addDisk () {
    fi
    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 $?
    fi
  fi

  if [ -f "$DISK_FILE" ]; then
  if [ -s "$DISK_FILE" ]; then

    CUR_SIZE=$(getSize "$DISK_FILE")

+10 −8
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ set -Eeuo pipefail

if [ -f "$STORAGE/dsm.ver" ]; then
  BASE=$(<"$STORAGE/dsm.ver")
  [ -z "$BASE" ] && BASE="DSM_VirtualDSM_69057"
else
  # Fallback for old installs
  BASE="DSM_VirtualDSM_42962"
@@ -12,14 +13,14 @@ fi

if [ -n "$URL" ]; then
  BASE=$(basename "$URL" .pat)
  if [ ! -f "$STORAGE/$BASE.system.img" ]; then
  if [ ! -s "$STORAGE/$BASE.system.img" ]; then
    BASE=$(basename "${URL%%\?*}" .pat)
    : "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
    BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
  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
fi

@@ -106,7 +107,7 @@ fi
ROOT="Y"
RDC="$STORAGE/dsm.rd"

if [ ! -f "$RDC" ]; then
if [ ! -s "$RDC" ]; then

  MSG="Downloading installer..."
  PRG="Downloading installer ([P])..."
@@ -118,6 +119,7 @@ if [ ! -f "$RDC" ]; then
  LOC="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"

  rm -f "$RD"
  rm -f "$RDC"
  /run/progress.sh "$RD" "$PRG" &
  { curl -r "$POS" -sfk -S -o "$RD" "$LOC"; rc=$?; } || :

@@ -215,7 +217,7 @@ else

fi

[ ! -f "$PAT" ] && error "Failed to download $URL" && exit 69
[ ! -s "$PAT" ] && error "Failed to download $URL" && exit 69

SIZE=$(stat -c%s "$PAT")

@@ -252,7 +254,7 @@ MSG="Preparing system partition..."
info "Install: $MSG" && html "$MSG"

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)
unzip -q -o "$BOOT".zip -d "$TMP"
@@ -313,15 +315,15 @@ IDB="$TMP/indexdb"
PKG="$TMP/packages"
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"

[ -d "$PKG" ] && mv "$PKG/" "$MOUNT/.SynoUpgradePackages/"
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/"
  mkdir -p "$INDEX_DB"
  tar xpfJ "$IDB.txz" --absolute-names -C "$INDEX_DB"
+2 −2
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ closeNetwork() {
  else

    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 delete "$VM_NET_TAP" || true
@@ -228,7 +228,7 @@ getInfo() {

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

  touch "$QEMU_END"

  if [ -f "$QEMU_PID" ]; then
  if [ -s "$QEMU_PID" ]; then

    pid=$(<"$QEMU_PID")
    echo && error "Forcefully terminating QEMU process, reason: $reason..."
@@ -45,7 +45,7 @@ finish() {
    while isAlive "$pid"; do
      sleep 1
      # Workaround for zombie pid
      [ ! -f "$QEMU_PID" ] && break
      [ ! -s "$QEMU_PID" ] && break
    done
  fi

@@ -64,7 +64,7 @@ terminal() {

  local dev=""

  if [ -f "$QEMU_OUT" ]; then
  if [ -s "$QEMU_OUT" ]; then

    local msg
    msg=$(<"$QEMU_OUT")
@@ -113,7 +113,7 @@ _graceful_shutdown() {
  touch "$QEMU_END"
  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?"
    finish "$code" && return "$code"
  fi
@@ -157,7 +157,7 @@ _graceful_shutdown() {
    [[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt/$QEMU_TIMEOUT)"

    # Workaround for zombie pid
    [ ! -f "$QEMU_PID" ] && break
    [ ! -s "$QEMU_PID" ] && break

  done

Loading