feat: Retrieve IP address

This commit is contained in:
Kroese 2023-11-08 03:44:12 +01:00 committed by GitHub
parent 538d7f0195
commit 2d97bc1cef

View File

@ -2,15 +2,46 @@
set -Eeuo pipefail set -Eeuo pipefail
info () { echo -e "\E[1;34m\E[1;36m $1\E[0m" ; } 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 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 if [[ "$IP" == "20.20"* ]]; then
MSG="port 5000" MSG="port ${PORT}"
else else
MSG="http://${IP}:5000" MSG="http://${IP}:${PORT}"
fi fi
echo "" echo ""
@ -18,3 +49,5 @@ info "--------------------------------------------------------"
info " You can now login to DSM at ${MSG}" info " You can now login to DSM at ${MSG}"
info "--------------------------------------------------------" info "--------------------------------------------------------"
echo "" echo ""
exit 0