diff --git a/src/check.sh b/src/check.sh index d61f998..771127b 100644 --- a/src/check.sh +++ b/src/check.sh @@ -1,11 +1,11 @@ #!/usr/bin/env bash set -Eeuo pipefail -[ -f "/run/qemu.end" ] && echo "QEMU is shutting down.." && exit 1 -[ ! -f "/run/qemu.pid" ] && echo "QEMU is not running yet.." && exit 0 +[ -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 -file="/run/dsm.url" -address="/run/qemu.ip" +file="/run/shm/dsm.url" +address="/run/shm/qemu.ip" [ ! -f "$file" ] && echo "DSM has not enabled networking yet.." && exit 1 diff --git a/src/install.sh b/src/install.sh index 24cd75e..b0812d8 100644 --- a/src/install.sh +++ b/src/install.sh @@ -139,7 +139,7 @@ if [ -f "$RDC" ]; then (( rc != 0 )) && error "Failed to extract $RDC, reason $rc" && exit 92 fi - mkdir -p /run/extract + rm -rf /run/extract && mkdir -p /run/extract for file in $TMP/usr/lib/libcurl.so.4 \ $TMP/usr/lib/libmbedcrypto.so.5 \ $TMP/usr/lib/libmbedtls.so.13 \ @@ -211,6 +211,7 @@ else fi +rm -rf /run/extract info "Install: Preparing system partition..." BOOT=$(find "$TMP" -name "*.bin.zip") @@ -275,15 +276,8 @@ PKG="$TMP/packages" HDP="$TMP/synohdpack_img" [ ! -f "$HDA.tgz" ] && error "The PAT file contains no OS image." && exit 64 - mv "$HDA.tgz" "$HDA.txz" -if [[ "$ROOT" != [Nn]* ]]; then - - tar xpfJ "$HDA.txz" --absolute-names -C "$MOUNT/" - -fi - [ -d "$PKG" ] && mv "$PKG/" "$MOUNT/.SynoUpgradePackages/" rm -f "$MOUNT/.SynoUpgradePackages/ActiveInsight-"* @@ -301,6 +295,8 @@ NUMBLOCKS="622560" # (4980480 * 512) / 4096 if [[ "$ROOT" != [Nn]* ]]; then + tar xpfJ "$HDA.txz" --absolute-names --skip-old-files -C "$MOUNT/" + info "Install: Installing system partition..." mke2fs -q -t ext4 -b 4096 -d "$MOUNT/" -L "$LABEL" -F -E "offset=$OFFSET" "$SYSTEM" "$NUMBLOCKS" diff --git a/src/network.sh b/src/network.sh index e41e5a7..dcbda17 100644 --- a/src/network.sh +++ b/src/network.sh @@ -218,7 +218,7 @@ getInfo() { GATEWAY=$(ip r | grep default | awk '{print $3}') IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) - echo "$IP" > /run/qemu.ip + echo "$IP" > /run/shm/qemu.ip return 0 } diff --git a/src/power.sh b/src/power.sh index 0b62775..416cd89 100644 --- a/src/power.sh +++ b/src/power.sh @@ -10,10 +10,10 @@ API_HOST="127.0.0.1:2210" QEMU_TERM="" QEMU_PORT=7100 QEMU_TIMEOUT=50 -QEMU_PID="/run/qemu.pid" -QEMU_LOG="/run/qemu.log" -QEMU_OUT="/run/qemu.out" -QEMU_END="/run/qemu.end" +QEMU_PID="/run/shm/qemu.pid" +QEMU_LOG="/run/shm/qemu.log" +QEMU_OUT="/run/shm/qemu.out" +QEMU_END="/run/shm/qemu.end" if [[ "$KVM" == [Nn]* ]]; then API_TIMEOUT=$(( API_TIMEOUT*2 )) diff --git a/src/print.sh b/src/print.sh index dbfa250..6d42cc4 100644 --- a/src/print.sh +++ b/src/print.sh @@ -6,9 +6,9 @@ set -Eeuo pipefail info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n" >&2; } error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; } -file="/run/dsm.url" -address="/run/qemu.ip" -shutdown="/run/qemu.end" +file="/run/shm/dsm.url" +address="/run/shm/qemu.ip" +shutdown="/run/shm/qemu.end" url="http://127.0.0.1:2210/read?command=10" resp_err="Guest returned an invalid response:" diff --git a/src/reset.sh b/src/reset.sh index 200b9b7..319a7a2 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -31,17 +31,24 @@ VERS=$(qemu-system-x86_64 --version | head -n 1 | cut -d '(' -f 1) # Check folder STORAGE="/storage" -[ ! -d "$STORAGE" ] && error "Storage folder ($STORAGE) not found!" && exit 13 +if [ ! -d "$STORAGE" ]; then + error "Storage folder ($STORAGE) not found!" && exit 13 +fi + +if [ ! -d "/run/shm" ]; then + if [ -d "/dev/shm" ]; then + ln -s /dev/shm /run/shm + else + error "Folder /dev/shm not found!" && exit 14 + fi +fi # Cleanup files - -rm -f /run/dsm.url -rm -f /run/qemu.* +rm -f /run/shm/qemu.* +rm -f /run/shm/dsm.url # Cleanup dirs - rm -rf /tmp/dsm -rm -f /tmp/server.* rm -rf "$STORAGE/tmp" # Helper functions diff --git a/src/server.sh b/src/server.sh index 267c8f2..995839a 100644 --- a/src/server.sh +++ b/src/server.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -eu -TMP_FILE=$(mktemp -q /tmp/server.XXXXXX) +TMP_FILE=$(mktemp -q /run/shm/server.XXXXXX) stop() { trap - SIGINT EXIT @@ -53,7 +53,7 @@ else HTML=$(html "xxx") { echo "#!/bin/bash" - echo "[ -f \"/run/dsm.url\" ] && LOCATION=\$(cat \"/run/dsm.url\")" + echo "[ -f \"/run/shm/dsm.url\" ] && LOCATION=\$(cat \"/run/shm/dsm.url\")" echo "HTML=\"$HTML\"; [ -z \"\$LOCATION\" ] && BODY=\"$WAIT\" || BODY=\"$BODY\"; HTML=\${HTML/xxx/\$BODY}" echo "printf '%b' \"HTTP/1.1 200 OK\\nContent-Length: \${#HTML}\\nConnection: close\\n\\n\$HTML\"" } > "$TMP_FILE"