From 567b017eded9a14e20cb8aa0005326f70a167d8c Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 03:41:54 +0200 Subject: [PATCH 01/16] Colors in log --- run/run.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/run/run.sh b/run/run.sh index 9557ae0c..8a8cb25d 100755 --- a/run/run.sh +++ b/run/run.sh @@ -10,16 +10,19 @@ set -Eeuo pipefail : ${DISK_SIZE:='16G'} # Initial data disk size : ${RAM_SIZE:='512M'} # Maximum RAM amount -echo "Starting Virtual DSM for Docker v${VERSION}..." -trap 'echo >&2 "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR +error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" } +info () { echo -e "\E[1;34m❯\E[1;36m INFO: $1\E[0m" } -[ ! -f "/run/run.sh" ] && echo "ERROR: Script must run inside Docker container!" && exit 11 -[ "$(id -u)" -ne "0" ] && echo "ERROR: Script must be executed with root privileges." && exit 12 +info "Starting Virtual DSM for Docker v${VERSION}..." +trap 'error "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR + +[ ! -f "/run/run.sh" ] && error "Script must run inside Docker container!" && exit 11 +[ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12 STORAGE="/storage" KERNEL=$(uname -r | cut -b 1) -[ ! -d "$STORAGE" ] && echo "ERROR: Storage folder (${STORAGE}) not found!" && exit 13 +[ ! -d "$STORAGE" ] && error "Storage folder (${STORAGE}) not found!" && exit 13 if [ -f "$STORAGE"/dsm.ver ]; then BASE=$(cat "${STORAGE}/dsm.ver") @@ -58,7 +61,7 @@ else fi if [ -n "${KVM_ERR}" ]; then - echo "ERROR: KVM acceleration not detected ${KVM_ERR}, please enable it." + error "KVM acceleration not detected ${KVM_ERR}, please enable it." [[ "${DEBUG}" == [Yy1]* ]] && exit 88 else KVM_OPTS=",accel=kvm -enable-kvm -cpu host" From a5f871d23fea1a3c6209e81a7aca15d9dfa4f27c Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 03:45:10 +0200 Subject: [PATCH 02/16] Colors in log --- run/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run/run.sh b/run/run.sh index 8a8cb25d..debdba56 100755 --- a/run/run.sh +++ b/run/run.sh @@ -10,8 +10,8 @@ set -Eeuo pipefail : ${DISK_SIZE:='16G'} # Initial data disk size : ${RAM_SIZE:='512M'} # Maximum RAM amount -error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" } -info () { echo -e "\E[1;34m❯\E[1;36m INFO: $1\E[0m" } +error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; } +info () { echo -e "\E[1;34m❯\E[1;36m INFO: $1\E[0m" ; } info "Starting Virtual DSM for Docker v${VERSION}..." trap 'error "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR From d6bc1c1969b88220fa0dc17ae5a7e35bc7c9fddf Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 03:49:40 +0200 Subject: [PATCH 03/16] Colors in log --- run/disk.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/run/disk.sh b/run/disk.sh index 2c1be799..777d4e63 100644 --- a/run/disk.sh +++ b/run/disk.sh @@ -11,8 +11,8 @@ set -Eeuo pipefail BOOT="$STORAGE/$BASE.boot.img" SYSTEM="$STORAGE/$BASE.system.img" -[ ! -f "$BOOT" ] && echo "ERROR: Virtual DSM boot-image does not exist ($BOOT)" && exit 81 -[ ! -f "$SYSTEM" ] && echo "ERROR: Virtual DSM system-image does not exist ($SYSTEM)" && exit 82 +[ ! -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 DATA="${STORAGE}/data.img" @@ -25,7 +25,7 @@ DISK_SIZE=$(echo "${DISK_SIZE}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g') DATA_SIZE=$(numfmt --from=iec "${DISK_SIZE}") if (( DATA_SIZE < 6442450944 )); then - echo "ERROR: Please increase DISK_SIZE to at least 6 GB." && exit 83 + error "Please increase DISK_SIZE to at least 6 GB." && exit 83 fi if [ -f "${DATA}" ]; then @@ -34,7 +34,7 @@ if [ -f "${DATA}" ]; then if [ "$DATA_SIZE" -gt "$OLD_SIZE" ]; then - echo "INFO: Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.." + info "Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.." if [[ "${ALLOCATE}" == [Nn]* ]]; then @@ -49,20 +49,20 @@ if [ -f "${DATA}" ]; then SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1) if (( REQ > SPACE )); then - echo "ERROR: Not enough free space to resize virtual disk to ${DISK_SIZE}." - echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 84 + error "Not enough free space to resize virtual disk to ${DISK_SIZE}." + error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 84 fi # Resize file by allocating more space if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then - echo "ERROR: Could not allocate a file for the virtual disk." && exit 85 + error "Could not allocate a file for the virtual disk." && exit 85 fi if [[ "${ALLOCATE}" == [Zz]* ]]; then GB=$(( (REQ + 1073741823)/1073741824 )) - echo "INFO: Preallocating ${GB} GB of diskspace, please wait..." + info "Preallocating ${GB} GB of diskspace, please wait..." dd if=/dev/urandom of="${DATA}" seek="${OLD_SIZE}" count="${REQ}" bs=1M iflag=count_bytes oflag=seek_bytes status=none fi @@ -71,8 +71,8 @@ if [ -f "${DATA}" ]; then if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then - echo "INFO: Shrinking existing disks is not supported yet!" - echo "INFO: Creating backup of old drive in storage folder..." + info "Shrinking existing disks is not supported yet!" + info "Creating backup of old drive in storage folder..." mv -f "${DATA}" "${DATA}.bak" @@ -92,19 +92,19 @@ if [ ! -f "${DATA}" ]; then SPACE=$(df --output=avail -B 1 "${STORAGE}" | tail -n 1) if (( DATA_SIZE > SPACE )); then - echo "ERROR: Not enough free space to create a virtual disk of ${DISK_SIZE}." - echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 86 + error "Not enough free space to create a virtual disk of ${DISK_SIZE}." + error "Specify a smaller size or disable preallocation with ALLOCATE=N." && exit 86 fi # Create an empty file if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then rm -f "${DATA}" - echo "ERROR: Could not allocate a file for the virtual disk." && exit 87 + error "Could not allocate a file for the virtual disk." && exit 87 fi if [[ "${ALLOCATE}" == [Zz]* ]]; then - echo "INFO: Preallocating ${DISK_SIZE} of diskspace, please wait..." + info "Preallocating ${DISK_SIZE} of diskspace, please wait..." dd if=/dev/urandom of="${DATA}" count="${DATA_SIZE}" bs=1M iflag=count_bytes status=none fi @@ -112,7 +112,7 @@ if [ ! -f "${DATA}" ]; then # Check if file exists if [ ! -f "${DATA}" ]; then - echo "ERROR: Virtual disk does not exist ($DATA)" && exit 88 + error "Virtual disk does not exist ($DATA)" && exit 88 fi # Format as BTRFS filesystem @@ -124,14 +124,14 @@ fi SIZE=$(stat -c%s "${DATA}") if [[ SIZE -ne DATA_SIZE ]]; then - echo "ERROR: Virtual disk has the wrong size: ${SIZE}" && exit 89 + error "Virtual disk has the wrong size: ${SIZE}" && exit 89 fi AGENT="${STORAGE}/${BASE}.agent" [ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") || AGENT_VERSION=1 if ((AGENT_VERSION < 5)); then - echo "INFO: The installed VirtualDSM Agent v${AGENT_VERSION} is an outdated version, please upgrade it." + info "The installed VirtualDSM Agent v${AGENT_VERSION} is an outdated version, please upgrade it." fi DISK_OPTS="\ From 9c87df2edd7b06824e38a9e031a3f8f097b527e2 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 03:53:48 +0200 Subject: [PATCH 04/16] Colors in log --- run/install.sh | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/run/install.sh b/run/install.sh index e08ffbe4..bff57ec6 100644 --- a/run/install.sh +++ b/run/install.sh @@ -33,16 +33,16 @@ rm -rf "$TMP" && mkdir -p "$TMP" if [ ! -f "${RDC}" ]; then RD="$TMP/rd.gz" - echo "Install: Downloading installer..." + info "Install: Downloading installer..." LOC="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat" { curl -r 65627648-71021836 -sfk -o "$RD" "$LOC"; rc=$?; } || : - (( rc != 0 )) && echo "ERROR: Failed to download $LOC, reason: $rc" && exit 60 + (( rc != 0 )) && error "Failed to download $LOC, reason: $rc" && exit 60 SUM=$(md5sum "$RD" | cut -f 1 -d " ") if [ "$SUM" != "ab399db750f88ac7aa88f608f2b8651c" ]; then - echo "ERROR: Invalid download location (checksum $SUM)" && exit 61 + error "Invalid download location (checksum $SUM)" && exit 61 fi cp "$RD" "$RDC" @@ -64,7 +64,7 @@ chmod +x /run/extract/syno_extract_system_patch rm -rf "$TMP" && mkdir -p "$TMP" -echo "Install: Downloading $(basename "$URL")..." +info "Install: Downloading $(basename "$URL")..." PAT="/$BASE.pat" rm -f "$PAT" @@ -77,24 +77,24 @@ else fi { wget "$URL" -O "$PAT" -q --no-check-certificate --show-progress "$PROGRESS"; rc=$?; } || : -(( rc != 0 )) && echo "ERROR: Failed to download $URL, reason: $rc" && exit 69 +(( rc != 0 )) && error "Failed to download $URL, reason: $rc" && exit 69 -[ ! -f "$PAT" ] && echo "ERROR: Failed to download $URL" && exit 69 +[ ! -f "$PAT" ] && error "Failed to download $URL" && exit 69 SIZE=$(stat -c%s "$PAT") if ((SIZE<250000000)); then - echo "ERROR: Invalid PAT file: File is an update pack which contains no OS image." && exit 62 + error "Invalid PAT file: File is an update pack which contains no OS image." && exit 62 fi -echo "Install: Extracting downloaded image..." +info "Install: Extracting downloaded image..." if { tar tf "$PAT"; } >/dev/null 2>&1; then tar xpf "$PAT" -C "$TMP/." else export LD_LIBRARY_PATH="/run/extract" if ! /run/extract/syno_extract_system_patch "$PAT" "$TMP/." ; then - echo "ERROR: Invalid PAT file: File is an update pack which contains no OS image." && exit 63 + error "Invalid PAT file: File is an update pack which contains no OS image." && exit 63 fi export LD_LIBRARY_PATH="" fi @@ -104,19 +104,19 @@ IDB="$TMP/indexdb" PKG="$TMP/packages" HDP="$TMP/synohdpack_img" -[ ! -f "$HDA.tgz" ] && echo "ERROR: Invalid PAT file: contains no OS image." && exit 64 -[ ! -f "$HDP.txz" ] && echo "ERROR: Invalid PAT file: contains no HD pack." && exit 65 -[ ! -f "$IDB.txz" ] && echo "ERROR: Invalid PAT file: contains no IndexDB." && exit 66 -[ ! -d "$PKG" ] && echo "ERROR: Invalid PAT file: contains no packages." && exit 68 +[ ! -f "$HDA.tgz" ] && error "Invalid PAT file: contains no OS image." && exit 64 +[ ! -f "$HDP.txz" ] && error "Invalid PAT file: contains no HD pack." && exit 65 +[ ! -f "$IDB.txz" ] && error "Invalid PAT file: contains no IndexDB." && exit 66 +[ ! -d "$PKG" ] && error "Invalid PAT file: contains no packages." && exit 68 BOOT=$(find "$TMP" -name "*.bin.zip") -[ ! -f "$BOOT" ] && echo "ERROR: Invalid PAT file: contains no boot file." && exit 67 +[ ! -f "$BOOT" ] && error "Invalid PAT file: contains no boot file." && exit 67 BOOT=$(echo "$BOOT" | head -c -5) unzip -q -o "$BOOT".zip -d "$TMP" -[[ "${ALLOCATE}" == [Zz]* ]] && echo "Install: Allocating diskspace..." +[[ "${ALLOCATE}" == [Zz]* ]] && info "Install: Allocating diskspace..." SYSTEM="$TMP/sys.img" SYSTEM_SIZE=4954537983 @@ -125,22 +125,22 @@ SYSTEM_SIZE=4954537983 SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1) if (( SYSTEM_SIZE > SPACE )); then - echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87 + error "Not enough free space to create a 4 GB system disk." && exit 87 fi if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then rm -f "${SYSTEM}" - echo "ERROR: Could not allocate a file for the system disk." && exit 88 + error "Could not allocate a file for the system disk." && exit 88 fi if [[ "${ALLOCATE}" == [Zz]* ]]; then - echo "Install: Preallocating 4 GB of diskspace..." + info "Install: Preallocating 4 GB of diskspace..." dd if=/dev/urandom of="${SYSTEM}" count="${SYSTEM_SIZE}" bs=1M iflag=count_bytes status=none fi # Check if file exists if [ ! -f "${SYSTEM}" ]; then - echo "ERROR: System disk does not exist ($SYSTEM)" && exit 89 + error "System disk does not exist ($SYSTEM)" && exit 89 fi # Check the filesize @@ -148,7 +148,7 @@ SIZE=$(stat -c%s "${SYSTEM}") if [[ SIZE -ne SYSTEM_SIZE ]]; then rm -f "${SYSTEM}" - echo "ERROR: System disk has the wrong size: ${SIZE}" && exit 90 + error "System disk has the wrong size: ${SIZE}" && exit 90 fi PART="$TMP/partition.fdisk" @@ -165,7 +165,7 @@ PART="$TMP/partition.fdisk" sfdisk -q "$SYSTEM" < "$PART" -echo "Install: Extracting system partition..." +info "Install: Extracting system partition..." MOUNT="$TMP/system" @@ -196,7 +196,7 @@ chmod 755 "$LOC/agent.sh" # Store agent version echo "7" > "$STORAGE"/"$BASE".agent -echo "Install: Installing system partition..." +info "Install: Installing system partition..." LABEL="1.44.1-42218" OFFSET="1048576" # 2048 * 512 From c8395005aa65d4581dd853b9133b4bffdfc64a93 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 03:58:27 +0200 Subject: [PATCH 05/16] Colors in log --- run/network.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/run/network.sh b/run/network.sh index d4200432..0702275a 100644 --- a/run/network.sh +++ b/run/network.sh @@ -33,8 +33,8 @@ configureDHCP() { { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || : if (( rc != 0 )); then - echo "ERROR: Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," - echo "ERROR: and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15 + error "Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan'," + error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15 fi ip address add "${IP}" dev "${VM_NET_VLAN}" @@ -48,8 +48,8 @@ configureDHCP() { { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || : if (( rc != 0 )); then - echo "ERROR: Capability NET_ADMIN has not been set most likely. Please add the " - echo "ERROR: following docker setting to your container: --cap-add NET_ADMIN" && exit 16 + error "Capability NET_ADMIN has not been set most likely. Please add the " + error "following docker setting to your container: --cap-add NET_ADMIN" && exit 16 fi ip link set "${VM_NET_TAP}" up @@ -63,28 +63,28 @@ configureDHCP() { IFS=: read -r MAJOR MINOR < <(cat /sys/devices/virtual/net/"${VM_NET_TAP}"/tap*/dev) if (( MAJOR < 1)); then - echo "ERROR: Cannot find: sys/devices/virtual/net/${VM_NET_TAP}" && exit 18 + error "Cannot find: sys/devices/virtual/net/${VM_NET_TAP}" && exit 18 fi [[ ! -e "${TAP_PATH}" ]] && [[ -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "${TAP_PATH}" if [[ ! -e "${TAP_PATH}" ]]; then { mknod "${TAP_PATH}" c "$MAJOR" "$MINOR" ; rc=$?; } || : - (( rc != 0 )) && echo "ERROR: Cannot mknod: ${TAP_PATH} ($rc)" && exit 20 + (( rc != 0 )) && error "Cannot mknod: ${TAP_PATH} ($rc)" && exit 20 fi { exec 30>>"$TAP_PATH"; rc=$?; } || : if (( rc != 0 )); then - echo "ERROR: Cannot create TAP interface ($rc). Please add the following docker settings to your " - echo "ERROR: container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21 + error "Cannot create TAP interface ($rc). Please add the following docker settings to your " + error "container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21 fi { exec 40>>/dev/vhost-net; rc=$?; } || : if (( rc != 0 )); then - echo "ERROR: VHOST can not be found ($rc). Please add the following " - echo "ERROR: docker setting to your container: --device=/dev/vhost-net" && exit 22 + error "VHOST can not be found ($rc). Please add the following " + error "docker setting to your container: --device=/dev/vhost-net" && exit 22 fi NET_OPTS="-netdev tap,id=hostnet0,vhost=on,vhostfd=40,fd=30" @@ -99,8 +99,8 @@ configureNAT () { { ip link add dev dockerbridge type bridge ; rc=$?; } || : if (( rc != 0 )); then - echo "ERROR: Capability NET_ADMIN has not been set most likely. Please add the " - echo "ERROR: following docker setting to your container: --cap-add NET_ADMIN" && exit 23 + error "Capability NET_ADMIN has not been set most likely. Please add the " + error "following docker setting to your container: --cap-add NET_ADMIN" && exit 23 fi ip address add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge @@ -128,7 +128,7 @@ configureNAT () { if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then { sysctl -w net.ipv4.ip_forward=1 ; rc=$?; } || : if (( rc != 0 )); then - echo "ERROR: Please add the following docker setting to your container: --sysctl net.ipv4.ip_forward=1" && exit 24 + error "Please add the following docker setting to your container: --sysctl net.ipv4.ip_forward=1" && exit 24 fi fi @@ -208,15 +208,15 @@ GATEWAY=$(ip r | grep default | awk '{print $3}') if [[ "${DEBUG}" == [Yy1]* ]]; then IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) - echo "INFO: Container IP is ${IP} with gateway ${GATEWAY}" && echo + info "Container IP is ${IP} with gateway ${GATEWAY}" && echo fi if [[ "${DHCP}" == [Yy1]* ]]; then if [[ "$GATEWAY" == "172."* ]]; then - echo -n "ERROR: You cannot enable DHCP while the container is " - echo "in a bridge network, only on a macvlan network!" && exit 86 + error "You cannot enable DHCP while the container is " + error "in a bridge network, only on a macvlan network!" && exit 86 fi # Configuration for DHCP IP From 82d72de0a4c24a4bc4d51a652b1de737e2d6c711 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 04:00:14 +0200 Subject: [PATCH 06/16] Colors in log --- run/network.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run/network.sh b/run/network.sh index 0702275a..42188580 100644 --- a/run/network.sh +++ b/run/network.sh @@ -191,7 +191,7 @@ if [ ! -c /dev/net/tun ]; then chmod 666 /dev/net/tun fi -[ ! -c /dev/net/tun ] && echo "ERROR: TUN network interface not available..." && exit 85 +[ ! -c /dev/net/tun ] && error "TUN network interface not available..." && exit 85 # Create the necessary file structure for /dev/vhost-net if [ ! -c /dev/vhost-net ]; then @@ -236,6 +236,6 @@ fi NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0" -[[ "${DEBUG}" == [Yy1]* ]] && echo && echo "Finished network setup.." && echo +[[ "${DEBUG}" == [Yy1]* ]] && echo && info "Finished network setup.." && echo return 0 From 0838921a8a6fedc806b390876bd11a574b5262be Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 04:02:01 +0200 Subject: [PATCH 07/16] Colors in log --- run/power.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/run/power.sh b/run/power.sh index 817f1675..23040a3e 100644 --- a/run/power.sh +++ b/run/power.sh @@ -26,7 +26,7 @@ _graceful_shutdown() { [ ! -f "${_QEMU_PID}" ] && return [ -f "${_QEMU_SHUTDOWN_COUNTER}" ] && return - echo && echo "Received $1 signal, shutting down..." + echo && info "Received $1 signal, shutting down..." echo 0 > "${_QEMU_SHUTDOWN_COUNTER}" # Don't send the powerdown signal because vDSM ignores ACPI signals @@ -37,7 +37,7 @@ _graceful_shutdown() { if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then - echo && echo "ERROR: Could not send shutdown command to the guest ($RESPONSE)" + echo && error "Could not send shutdown command to the guest ($RESPONSE)" # If we cannot shutdown the usual way, fallback to the NMI method @@ -55,7 +55,7 @@ _graceful_shutdown() { if ((AGENT_VERSION < 2)); then - echo && echo "Please update the VirtualDSM Agent to allow for gracefull shutdowns..." + echo && info "Please update the VirtualDSM Agent to allow for gracefull shutdowns..." kill -15 "$(cat "${_QEMU_PID}")" pkill -f qemu-system-x86_64 || true @@ -72,13 +72,13 @@ _graceful_shutdown() { if echo 'info version'| nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 ; then sleep 1 - #echo "Shutting down, waiting... ($(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT})" + #info "Shutting down, waiting... ($(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT})" fi done - echo && echo "Quitting..." + echo && info "Quitting..." echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true return From 6adb747ca899726c5aef90056683f8400e203ba0 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 04:06:41 +0200 Subject: [PATCH 08/16] Colors in log --- run/network.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run/network.sh b/run/network.sh index 42188580..f405a139 100644 --- a/run/network.sh +++ b/run/network.sh @@ -39,11 +39,11 @@ configureDHCP() { ip address add "${IP}" dev "${VM_NET_VLAN}" ip link set dev "${VM_NET_VLAN}" up - + ip route flush dev "${VM_NET_VLAN}" ip route del "${NETWORK}" dev "${VM_NET_DEV}" ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0 - + # Create a macvtap network for the VM guest { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || : From d65d16d866f26e5880b66df4c4b5b15bfa120ef8 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 04:10:19 +0200 Subject: [PATCH 09/16] Colors in log --- run/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/run.sh b/run/run.sh index debdba56..c7c09a9d 100755 --- a/run/run.sh +++ b/run/run.sh @@ -10,8 +10,8 @@ set -Eeuo pipefail : ${DISK_SIZE:='16G'} # Initial data disk size : ${RAM_SIZE:='512M'} # Maximum RAM amount +info () { echo -e "\E[1;34m❯ \E[1;36m$1\E[0m" ; } error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; } -info () { echo -e "\E[1;34m❯\E[1;36m INFO: $1\E[0m" ; } info "Starting Virtual DSM for Docker v${VERSION}..." trap 'error "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR From b2bb0de22d3ab97a5bd407df32ab7d7aa5fb82a1 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 04:19:32 +0200 Subject: [PATCH 10/16] Colors in log --- agent/agent.sh | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/agent/agent.sh b/agent/agent.sh index 5a1fd107..e6c2d358 100644 --- a/agent/agent.sh +++ b/agent/agent.sh @@ -6,9 +6,12 @@ HEADER="VirtualDSM Agent" # Functions +error () { echo -e "\E[1;31m❯ ERROR: $1\E[0m" ; } +info () { echo -e "\E[1;34m❯\E[1;36m $HEADER: $1\E[0m" ; } + finish() { - echo "$HEADER: Shutting down.." + info "Shutting down.." exit } @@ -20,7 +23,7 @@ function checkNMI { if [ "$nmi" != "" ]; then - echo "$HEADER: Received shutdown request through NMI.." + info "Received shutdown request through NMI.." /usr/syno/sbin/synoshutdown -s > /dev/null finish @@ -48,27 +51,27 @@ function downloadUpdate { [[ remote_size -eq local_size ]] && return if ! curl -sfk -m 10 -o "${TMP}" "${URL}"; then - echo "$HEADER: curl error ($?)" && return + info "curl error ($?)" && return fi if [ ! -f "${TMP}" ]; then - echo "$HEADER: update error, file not found.." && return + info "update error, file not found.." && return fi line=$(head -1 "${TMP}") if [[ "$line" != "#!/usr/bin/env bash" ]]; then - echo "$HEADER: update error, invalid header: $line" && return + info "update error, invalid header: $line" && return fi if cmp --silent -- "${TMP}" "${SCRIPT}"; then - echo "$HEADER: update file is already equal? (${local_size} / ${remote_size})" && return + info "update file is already equal? (${local_size} / ${remote_size})" && return fi mv -f "${TMP}" "${SCRIPT}" chmod 755 "${SCRIPT}" - echo "$HEADER: succesfully installed update, please reboot." + info "succesfully installed update, please reboot." } @@ -82,7 +85,7 @@ function installPackages { [[ $BASE == "ActiveInsight" ]] && continue - echo "$HEADER: Installing package ${BASE}.." + info "Installing package ${BASE}.." /usr/syno/bin/synopkg install "$filename" > /dev/null /usr/syno/bin/synopkg start "$BASE" > /dev/null & @@ -97,7 +100,7 @@ function installPackages { trap finish SIGINT SIGTERM ts=$(date +%s%N) -echo "$HEADER v$VERSION" +info "running v$VERSION" checkNMI @@ -140,9 +143,9 @@ else MSG="http://${IP}:5000" fi -echo "--------------------------------------------------------" -echo " You can now login to DSM at ${MSG}" -echo "--------------------------------------------------------" +info "--------------------------------------------------------" +info " You can now login to DSM at ${MSG}" +info "--------------------------------------------------------" # Wait for NMI interrupt as a shutdown signal From 40b26b4209ef4850b538b206b63d0ef50488a51e Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 04:23:31 +0200 Subject: [PATCH 11/16] Colors in log --- agent/service.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/agent/service.sh b/agent/service.sh index 030bd44b..709c77e2 100644 --- a/agent/service.sh +++ b/agent/service.sh @@ -3,6 +3,9 @@ PIDFILE="/var/run/agent.pid" SCRIPT="/usr/local/bin/agent.sh" +error () { echo -e "\E[1;31m❯ ERROR: $1\E[0m" ; } +info () { echo -e "\E[1;34m❯\E[1;36m $1\E[0m" ; } + status() { if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then @@ -25,7 +28,7 @@ start() { if [ ! -f "$SCRIPT" ]; then - echo 'ERROR: Agent script not found!' > /dev/ttyS0 + error 'Agent script not found!' > /dev/ttyS0 URL="https://raw.githubusercontent.com/kroese/virtual-dsm/master/agent/agent.sh" @@ -54,7 +57,7 @@ stop() { echo 'Stopping agent service...' chmod 666 /dev/ttyS0 - echo 'Stopping agent service...' > /dev/ttyS0 + info 'Stopping agent service...' > /dev/ttyS0 kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE" rm -f /var/lock/subsys/agent.sh From 405c9d9622a28ffbdeeac642c43e4ed6d4a5f26b Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 04:41:31 +0200 Subject: [PATCH 12/16] Colors in log --- agent/agent.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/agent/agent.sh b/agent/agent.sh index e6c2d358..81178c03 100644 --- a/agent/agent.sh +++ b/agent/agent.sh @@ -7,11 +7,11 @@ HEADER="VirtualDSM Agent" # Functions error () { echo -e "\E[1;31m❯ ERROR: $1\E[0m" ; } -info () { echo -e "\E[1;34m❯\E[1;36m $HEADER: $1\E[0m" ; } +info () { echo -e "\E[1;34m❯\E[1;36m $1\E[0m" ; } finish() { - info "Shutting down.." + echo "$HEADER: Shutting down.." exit } @@ -51,27 +51,27 @@ function downloadUpdate { [[ remote_size -eq local_size ]] && return if ! curl -sfk -m 10 -o "${TMP}" "${URL}"; then - info "curl error ($?)" && return + error "$HEADER: curl error ($?)" && return fi if [ ! -f "${TMP}" ]; then - info "update error, file not found.." && return + error "$HEADER: update error, file not found.." && return fi line=$(head -1 "${TMP}") if [[ "$line" != "#!/usr/bin/env bash" ]]; then - info "update error, invalid header: $line" && return + error "$HEADER: update error, invalid header: $line" && return fi if cmp --silent -- "${TMP}" "${SCRIPT}"; then - info "update file is already equal? (${local_size} / ${remote_size})" && return + error "$HEADER: update file is already equal? (${local_size} / ${remote_size})" && return fi mv -f "${TMP}" "${SCRIPT}" chmod 755 "${SCRIPT}" - info "succesfully installed update, please reboot." + info "$HEADER: succesfully installed update, please reboot." } @@ -100,7 +100,7 @@ function installPackages { trap finish SIGINT SIGTERM ts=$(date +%s%N) -info "running v$VERSION" +echo "Started $HEADER v$VERSION..." checkNMI From 3a6a1ab47e64da945058d27050941475224df3d7 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 04:48:03 +0200 Subject: [PATCH 13/16] Colors in log --- agent/service.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/service.sh b/agent/service.sh index 709c77e2..87ae7c4a 100644 --- a/agent/service.sh +++ b/agent/service.sh @@ -28,13 +28,14 @@ start() { if [ ! -f "$SCRIPT" ]; then - error 'Agent script not found!' > /dev/ttyS0 - URL="https://raw.githubusercontent.com/kroese/virtual-dsm/master/agent/agent.sh" if ! curl -sfk -m 10 -o "${SCRIPT}" "${URL}"; then + error 'Failed to download agent script.' > /dev/ttyS0 rm -f "${SCRIPT}" return 1 + else + info 'Agent script was missing?' > /dev/ttyS0 fi chmod 755 "${SCRIPT}" @@ -84,4 +85,3 @@ case "$1" in echo "Usage: $0 {start|stop|restart}" exit 1 esac - From 83ab7890424b7ce50dbb0d457b86a04be758bd42 Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 05:01:51 +0200 Subject: [PATCH 14/16] Colors in log --- agent/agent.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/agent.sh b/agent/agent.sh index 81178c03..2b761f50 100644 --- a/agent/agent.sh +++ b/agent/agent.sh @@ -71,7 +71,7 @@ function downloadUpdate { mv -f "${TMP}" "${SCRIPT}" chmod 755 "${SCRIPT}" - info "$HEADER: succesfully installed update, please reboot." + info "$HEADER: succesfully installed update..." } @@ -100,7 +100,7 @@ function installPackages { trap finish SIGINT SIGTERM ts=$(date +%s%N) -echo "Started $HEADER v$VERSION..." +echo "❯ Started $HEADER v$VERSION..." checkNMI From 9108541b595cb1124be939f754eafa0b39329eaa Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 05:05:02 +0200 Subject: [PATCH 15/16] Colors in log --- agent/agent.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/agent.sh b/agent/agent.sh index 2b761f50..df7441c3 100644 --- a/agent/agent.sh +++ b/agent/agent.sh @@ -11,7 +11,7 @@ info () { echo -e "\E[1;34m❯\E[1;36m $1\E[0m" ; } finish() { - echo "$HEADER: Shutting down.." + echo "❯ $HEADER: Shutting down.." exit } From d262d428e285ee34a82207854c6a33971f385b7f Mon Sep 17 00:00:00 2001 From: Kroese Date: Thu, 11 May 2023 05:11:58 +0200 Subject: [PATCH 16/16] Colors in log --- run/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/run.sh b/run/run.sh index c7c09a9d..a4ba5e49 100755 --- a/run/run.sh +++ b/run/run.sh @@ -13,7 +13,7 @@ set -Eeuo pipefail info () { echo -e "\E[1;34m❯ \E[1;36m$1\E[0m" ; } error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; } -info "Starting Virtual DSM for Docker v${VERSION}..." +echo "❯ Starting Virtual DSM for Docker v${VERSION}..." trap 'error "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR [ ! -f "/run/run.sh" ] && error "Script must run inside Docker container!" && exit 11