diff --git a/src/check.sh b/src/check.sh index de23293..d7842ff 100644 --- a/src/check.sh +++ b/src/check.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -Eeuo pipefail +: "${DHCP:="N"}" : "${NETWORK:="Y"}" [ -f "/run/shm/qemu.end" ] && echo "QEMU is shutting down.." && exit 1 @@ -9,6 +10,7 @@ set -Eeuo pipefail file="/run/shm/dsm.url" address="/run/shm/qemu.ip" +gateway="/run/shm/qemu.gw" [ ! -s "$file" ] && echo "DSM has not enabled networking yet.." && exit 1 @@ -16,13 +18,13 @@ location=$(<"$file") if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then - if [[ "$location" == "20.20"* ]]; then - ip="20.20.20.1" + if [[ "$DHCP" == [Yy1]* ]]; then + ip=$(<"$address") + echo "Failed to reach DSM at http://$location" + else + ip=$(<"$gateway") port="${location##*:}" echo "Failed to reach DSM at port $port" - else - echo "Failed to reach DSM at http://$location" - ip=$(<"$address") fi echo "You might need to whitelist IP $ip in the DSM firewall." && exit 1 diff --git a/src/network.sh b/src/network.sh index 6650f86..fcf0c25 100644 --- a/src/network.sh +++ b/src/network.sh @@ -121,6 +121,8 @@ configureDNS() { local mask="$5" local gateway="$6" + echo "$gateway" > /run/shm/qemu.gw + [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]] && return 0 [[ "$DEBUG" == [Yy1]* ]] && echo "Starting dnsmasq daemon..." @@ -258,9 +260,10 @@ configureSlirp() { if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then cp /etc/resolv.conf /etc/resolv.dnsmasq echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf - configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1 fi + configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1 + VM_NET_IP="$ip" return 0 } @@ -368,7 +371,14 @@ configureNAT() { fi fi - local ip="172.30.0.2" + local ip base + base=$(echo "$IP" | sed -r 's/([^.]*.){2}//') + if [[ "$IP" != "172.30."* ]]; then + ip="172.30.$base" + else + ip="172.31.$base" + fi + [ -n "$VM_NET_IP" ] && ip="$VM_NET_IP" local gateway="" @@ -683,6 +693,8 @@ getInfo() { fi echo "$IP" > /run/shm/qemu.ip + echo "$nic" > /run/shm/qemu.nic + return 0 } diff --git a/src/print.sh b/src/print.sh index 4da6386..2330413 100644 --- a/src/print.sh +++ b/src/print.sh @@ -11,11 +11,12 @@ error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; } file="/run/shm/dsm.url" info="/run/shm/msg.html" +driver="/run/shm/qemu.nic" page="/run/shm/index.html" address="/run/shm/qemu.ip" shutdown="/run/shm/qemu.end" template="/var/www/index.html" -url="http://127.0.0.1:$COM_PORT/read?command=10" +url="http://127.0.0.1:2210/read?command=10" resp_err="Guest returned an invalid response:" curl_err="Failed to connect to guest: curl error" @@ -56,11 +57,7 @@ do (( rc != 0 )) && error "$jq_err $rc ( $json )" && continue [[ "$ip" == "null" ]] && error "$resp_err $json" && continue - if [ -z "$ip" ]; then - [[ "$DHCP" == [Yy1]* ]] && continue - ip="20.20.20.21" - fi - + [ -z "$ip" ] && continue echo "$ip:$port" > $file done @@ -69,7 +66,7 @@ done location=$(<"$file") -if [[ "$location" != "20.20"* ]]; then +if [[ "$DHCP" == [Yy1]* ]]; then msg="http://$location" title="