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 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" 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 diff --git a/run/print.sh b/run/print.sh new file mode 100644 index 0000000..988193c --- /dev/null +++ b/run/print.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +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 + +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 + fi + + # Retrieve the HTTP port number + if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then + error "Failed to parse response from guest: $RESPONSE" && continue + fi + + rest=${RESPONSE#*http_port} + rest=${rest#*:} + rest=${rest%%,*} + PORT=${rest%%\"*} + + [ -z "${PORT}" ] && continue + + # Retrieve the IP address + if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then + error "Failed to parse response from guest: $RESPONSE" && continue + fi + + rest=${RESPONSE#*eth0} + rest=${rest#*ip} + rest=${rest#*:} + rest=${rest#*\"} + IP=${rest%%\"*} + + [ -z "${IP}" ] && continue + + retry=false + +done + +if [[ "$IP" == "20.20"* ]]; then + MSG="port ${PORT}" +else + MSG="http://${IP}:${PORT}" +fi + +echo "" >&2 +info "--------------------------------------------------------" +info " You can now login to DSM at ${MSG}" +info "--------------------------------------------------------" +echo "" >&2 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