From dcf95a859126ee63e97a81803c2dfe774ed30d28 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Nov 2023 03:31:19 +0100 Subject: [PATCH 1/9] feat: Display info message --- run/print.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 run/print.sh diff --git a/run/print.sh b/run/print.sh new file mode 100644 index 0000000..832afa0 --- /dev/null +++ b/run/print.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +info () { echo -e "\E[1;34m❯\E[1;36m $1\E[0m" ; } + +sleep 1 + +IP=$(ip address show dev eth0 | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) + +if [[ "$IP" == "20.20"* ]]; then + MSG="port 5000" +else + MSG="http://${IP}:5000" +fi + +echo "" +info "--------------------------------------------------------" +info " You can now login to DSM at ${MSG}" +info "--------------------------------------------------------" +echo "" From 538d7f01953ffb3bdff1f1c84cb0f76401022118 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Nov 2023 03:36:13 +0100 Subject: [PATCH 2/9] fix: Display stderr output --- run/serial.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run/serial.sh b/run/serial.sh index 4d71516..f3d9fa1 100644 --- a/run/serial.sh +++ b/run/serial.sh @@ -45,7 +45,7 @@ if [[ "${HOST_DEBUG}" == [Yy1]* ]]; then { set +x; } 2>/dev/null echo else - ./run/host.bin "${HOST_ARGS[@]}" 2> /dev/null & + ./run/host.bin "${HOST_ARGS[@]}" >/dev/null & fi # Configure serial ports From 2d97bc1cef020241f6af88f84bab2e5af991afd4 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Nov 2023 03:44:12 +0100 Subject: [PATCH 3/9] feat: Retrieve IP address --- run/print.sh | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/run/print.sh b/run/print.sh index 832afa0..0176018 100644 --- a/run/print.sh +++ b/run/print.sh @@ -2,15 +2,46 @@ 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" ; } sleep 1 -IP=$(ip address show dev eth0 | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) +# Retrieve IP from guest VM +RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1) + +if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then + error "Failed to connect to guest: $RESPONSE" && exit 1 +fi + +# Retrieve the HTTP port number +if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then + error "Failed to parse response from guest: $RESPONSE" && exit 1 +fi + +rest=${RESPONSE#*http_port} +rest=${rest#*:} +rest=${rest%%,*} +PORT=${rest%%\"*} + +[ -z "${PORT}" ] && error "Guest has not set a portnumber yet.." && exit 1 + +# Retrieve the IP address +if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then + error "Failed to parse response from guest: $RESPONSE" && exit 1 +fi + +rest=${RESPONSE#*eth0} +rest=${rest#*ip} +rest=${rest#*:} +rest=${rest#*\"} +IP=${rest%%\"*} + +[ -z "${IP}" ] && error "Guest has not received an IP yet.." && exit 1 if [[ "$IP" == "20.20"* ]]; then - MSG="port 5000" + MSG="port ${PORT}" else - MSG="http://${IP}:5000" + MSG="http://${IP}:${PORT}" fi echo "" @@ -18,3 +49,5 @@ info "--------------------------------------------------------" info " You can now login to DSM at ${MSG}" info "--------------------------------------------------------" echo "" + +exit 0 From 899687d3f246ff1e11e41247070141a6355f6516 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Nov 2023 04:12:09 +0100 Subject: [PATCH 4/9] fix: Retry if needed --- run/print.sh | 56 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/run/print.sh b/run/print.sh index 0176018..fafbf53 100644 --- a/run/print.sh +++ b/run/print.sh @@ -5,38 +5,46 @@ info () { echo -e "\E[1;34m❯\E[1;36m $1\E[0m" ; } error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; } sleep 1 +retry=true -# Retrieve IP from guest VM -RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1) +while [ "$retry" = true ] +do -if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then - error "Failed to connect to guest: $RESPONSE" && exit 1 -fi + # Retrieve IP from guest VM + RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1) -# Retrieve the HTTP port number -if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then - error "Failed to parse response from guest: $RESPONSE" && exit 1 -fi + if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then + error "Failed to connect to guest: $RESPONSE" && exit 1 + fi -rest=${RESPONSE#*http_port} -rest=${rest#*:} -rest=${rest%%,*} -PORT=${rest%%\"*} + # Retrieve the HTTP port number + if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then + error "Failed to parse response from guest: $RESPONSE" && exit 1 + fi -[ -z "${PORT}" ] && error "Guest has not set a portnumber yet.." && exit 1 + rest=${RESPONSE#*http_port} + rest=${rest#*:} + rest=${rest%%,*} + PORT=${rest%%\"*} -# Retrieve the IP address -if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then - error "Failed to parse response from guest: $RESPONSE" && exit 1 -fi + [ -z "${PORT}" ] && error "Guest has not set a portnumber yet.." && sleep 3 && continue -rest=${RESPONSE#*eth0} -rest=${rest#*ip} -rest=${rest#*:} -rest=${rest#*\"} -IP=${rest%%\"*} + # Retrieve the IP address + if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then + error "Failed to parse response from guest: $RESPONSE" && exit 1 + fi -[ -z "${IP}" ] && error "Guest has not received an IP yet.." && exit 1 + rest=${RESPONSE#*eth0} + rest=${rest#*ip} + rest=${rest#*:} + rest=${rest#*\"} + IP=${rest%%\"*} + + [ -z "${IP}" ] && error "Guest has not received an IP yet.." && sleep 3 && continue + + retry=false + +done if [[ "$IP" == "20.20"* ]]; then MSG="port ${PORT}" From 8e41b4e567fa253b3aaa759e6f0c4ae9655747fe Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Nov 2023 04:21:07 +0100 Subject: [PATCH 5/9] fix: Increase sleep --- run/print.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/run/print.sh b/run/print.sh index fafbf53..cb1eb8e 100644 --- a/run/print.sh +++ b/run/print.sh @@ -4,22 +4,23 @@ 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" ; } -sleep 1 retry=true while [ "$retry" = true ] do + sleep 2 + # Retrieve IP from guest VM RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1) if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then - error "Failed to connect to guest: $RESPONSE" && exit 1 + error "Failed to connect to guest: $RESPONSE" && continue fi # Retrieve the HTTP port number if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then - error "Failed to parse response from guest: $RESPONSE" && exit 1 + error "Failed to parse response from guest: $RESPONSE" && continue fi rest=${RESPONSE#*http_port} @@ -27,11 +28,11 @@ do rest=${rest%%,*} PORT=${rest%%\"*} - [ -z "${PORT}" ] && error "Guest has not set a portnumber yet.." && sleep 3 && continue + [ -z "${PORT}" ] && continue # Retrieve the IP address if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then - error "Failed to parse response from guest: $RESPONSE" && exit 1 + error "Failed to parse response from guest: $RESPONSE" && continue fi rest=${RESPONSE#*eth0} @@ -40,7 +41,7 @@ do rest=${rest#*\"} IP=${rest%%\"*} - [ -z "${IP}" ] && error "Guest has not received an IP yet.." && sleep 3 && continue + [ -z "${IP}" ] && continue retry=false @@ -57,5 +58,3 @@ info "--------------------------------------------------------" info " You can now login to DSM at ${MSG}" info "--------------------------------------------------------" echo "" - -exit 0 From ede42b3647bc152767ba51029be87ec0510126df Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Nov 2023 04:22:08 +0100 Subject: [PATCH 6/9] fix: Do not install agent --- run/install.sh | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/run/install.sh b/run/install.sh index dc057b8..5bc9b47 100644 --- a/run/install.sh +++ b/run/install.sh @@ -230,18 +230,6 @@ rm -f "$MOUNT/.SynoUpgradePackages/ActiveInsight-"* [ -f "$HDP.txz" ] && tar xpfJ "$HDP.txz" --absolute-names -C "$MOUNT/" [ -f "$IDB.txz" ] && tar xpfJ "$IDB.txz" --absolute-names -C "$MOUNT/usr/syno/synoman/indexdb/" -# Install Agent - -LOC="$MOUNT/usr/local/bin" -mkdir -p "$LOC" -cp /agent/agent.sh "$LOC/agent.sh" -chmod 755 "$LOC/agent.sh" - -LOC="$MOUNT/usr/local/etc/rc.d" -mkdir -p "$LOC" -cp /agent/service.sh "$LOC/agent.sh" -chmod 755 "$LOC/agent.sh" - info "Install: Installing system partition..." LABEL="1.44.1-42218" From 7a55c650d0a1163e97fe6741b92ffeb0730ea962 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Nov 2023 04:26:00 +0100 Subject: [PATCH 7/9] fix: Do not install agent --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index fb93a14..fb786c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,8 +34,6 @@ RUN apt-get update && apt-get -y upgrade && \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* COPY run/*.sh /run/ -COPY agent/*.sh /agent/ - COPY --from=builder /qemu-host.bin /run/host.bin RUN chmod +x /run/*.sh && chmod +x /run/*.bin From 5365a9ed4ed0d4e03af1bc4973c4a86b6fe86001 Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Nov 2023 04:32:50 +0100 Subject: [PATCH 8/9] fix: Do not send NMI --- run/power.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/run/power.sh b/run/power.sh index 97db8b1..fcff1c7 100644 --- a/run/power.sh +++ b/run/power.sh @@ -39,13 +39,8 @@ _graceful_shutdown() { echo && error "Could not send shutdown command to the guest ($RESPONSE)" - # Send a NMI interrupt which will be detected by the agent script - if ! echo 'nmi' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null ; then - - kill -15 "$(cat "${_QEMU_PID}")" - pkill -f qemu-system-x86_64 || true - - fi + kill -15 "$(cat "${_QEMU_PID}")" + pkill -f qemu-system-x86_64 || true fi @@ -58,8 +53,9 @@ _graceful_shutdown() { if echo 'info version'| nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 ; then sleep 1 - CNT="$(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT}" - [[ "${DEBUG}" == [Yy1]* ]] && info "Shutting down, waiting... (${CNT})" + + #CNT="$(cat ${_QEMU_SHUTDOWN_COUNTER})/${QEMU_POWERDOWN_TIMEOUT}" + #[[ "${DEBUG}" == [Yy1]* ]] && info "Shutting down, waiting... (${CNT})" fi From d793921bcfd6cd24df0b288cf47451748c7495df Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 8 Nov 2023 12:07:38 +0100 Subject: [PATCH 9/9] fix: Print to stderr --- run/print.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/run/print.sh b/run/print.sh index cb1eb8e..988193c 100644 --- a/run/print.sh +++ b/run/print.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -Eeuo pipefail -info () { echo -e "\E[1;34m❯\E[1;36m $1\E[0m" ; } +info () { echo -e >&2 "\E[1;34m❯\E[1;36m $1\E[0m" ; } error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; } retry=true @@ -10,9 +10,12 @@ while [ "$retry" = true ] do sleep 2 - + # Retrieve IP from guest VM + + set +e RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1) + set -e if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then error "Failed to connect to guest: $RESPONSE" && continue @@ -53,8 +56,8 @@ else MSG="http://${IP}:${PORT}" fi -echo "" +echo "" >&2 info "--------------------------------------------------------" info " You can now login to DSM at ${MSG}" info "--------------------------------------------------------" -echo "" +echo "" >&2