2023-11-08 03:31:19 +01:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -Eeuo pipefail
|
|
|
|
|
|
2023-11-08 12:07:38 +01:00
|
|
|
|
info () { echo -e >&2 "\E[1;34m❯\E[1;36m $1\E[0m" ; }
|
2023-11-08 03:44:12 +01:00
|
|
|
|
error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; }
|
2023-11-08 03:31:19 +01:00
|
|
|
|
|
2023-11-08 04:12:09 +01:00
|
|
|
|
retry=true
|
2023-11-08 03:31:19 +01:00
|
|
|
|
|
2023-11-08 04:12:09 +01:00
|
|
|
|
while [ "$retry" = true ]
|
|
|
|
|
do
|
2023-11-08 03:44:12 +01:00
|
|
|
|
|
2023-11-08 04:21:07 +01:00
|
|
|
|
sleep 2
|
2023-11-08 12:07:38 +01:00
|
|
|
|
|
2023-11-08 04:12:09 +01:00
|
|
|
|
# Retrieve IP from guest VM
|
2023-11-08 12:07:38 +01:00
|
|
|
|
|
|
|
|
|
set +e
|
2023-11-08 04:12:09 +01:00
|
|
|
|
RESPONSE=$(curl -s -m 16 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
2023-11-08 12:07:38 +01:00
|
|
|
|
set -e
|
2023-11-08 03:44:12 +01:00
|
|
|
|
|
2023-11-08 04:12:09 +01:00
|
|
|
|
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
2023-11-08 04:21:07 +01:00
|
|
|
|
error "Failed to connect to guest: $RESPONSE" && continue
|
2023-11-08 04:12:09 +01:00
|
|
|
|
fi
|
2023-11-08 03:44:12 +01:00
|
|
|
|
|
2023-11-08 04:12:09 +01:00
|
|
|
|
# Retrieve the HTTP port number
|
|
|
|
|
if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then
|
2023-11-08 04:21:07 +01:00
|
|
|
|
error "Failed to parse response from guest: $RESPONSE" && continue
|
2023-11-08 04:12:09 +01:00
|
|
|
|
fi
|
2023-11-08 03:44:12 +01:00
|
|
|
|
|
2023-11-08 04:12:09 +01:00
|
|
|
|
rest=${RESPONSE#*http_port}
|
|
|
|
|
rest=${rest#*:}
|
|
|
|
|
rest=${rest%%,*}
|
|
|
|
|
PORT=${rest%%\"*}
|
2023-11-08 03:44:12 +01:00
|
|
|
|
|
2023-11-08 04:21:07 +01:00
|
|
|
|
[ -z "${PORT}" ] && continue
|
2023-11-08 04:12:09 +01:00
|
|
|
|
|
|
|
|
|
# Retrieve the IP address
|
|
|
|
|
if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then
|
2023-11-08 04:21:07 +01:00
|
|
|
|
error "Failed to parse response from guest: $RESPONSE" && continue
|
2023-11-08 04:12:09 +01:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
rest=${RESPONSE#*eth0}
|
|
|
|
|
rest=${rest#*ip}
|
|
|
|
|
rest=${rest#*:}
|
|
|
|
|
rest=${rest#*\"}
|
|
|
|
|
IP=${rest%%\"*}
|
|
|
|
|
|
2023-11-08 04:21:07 +01:00
|
|
|
|
[ -z "${IP}" ] && continue
|
2023-11-08 03:44:12 +01:00
|
|
|
|
|
2023-11-08 04:12:09 +01:00
|
|
|
|
retry=false
|
2023-11-08 03:44:12 +01:00
|
|
|
|
|
2023-11-08 04:12:09 +01:00
|
|
|
|
done
|
2023-11-08 03:31:19 +01:00
|
|
|
|
|
|
|
|
|
if [[ "$IP" == "20.20"* ]]; then
|
2023-11-08 03:44:12 +01:00
|
|
|
|
MSG="port ${PORT}"
|
2023-11-08 03:31:19 +01:00
|
|
|
|
else
|
2023-11-08 03:44:12 +01:00
|
|
|
|
MSG="http://${IP}:${PORT}"
|
2023-11-08 03:31:19 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2023-11-08 12:07:38 +01:00
|
|
|
|
echo "" >&2
|
2023-11-08 03:31:19 +01:00
|
|
|
|
info "--------------------------------------------------------"
|
|
|
|
|
info " You can now login to DSM at ${MSG}"
|
|
|
|
|
info "--------------------------------------------------------"
|
2023-11-08 12:07:38 +01:00
|
|
|
|
echo "" >&2
|