mirror of
https://github.com/AuxXxilium/arv-v-dsm.git
synced 2024-11-23 23:10:58 +07:00
feat: Detect default interface
* feat: Detect default interface
This commit is contained in:
parent
1208c53ebb
commit
527bded1b2
@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
: ${VM_NET_DEV:='eth0'}
|
||||
|
||||
[ -f "/run/qemu.end" ] && echo "QEMU is shutting down.." && exit 1
|
||||
[ ! -f "/run/qemu.pid" ] && echo "QEMU is not running yet.." && exit 0
|
||||
|
||||
file="/run/dsm.url"
|
||||
address="/run/qemu.ip"
|
||||
|
||||
[ ! -f "$file" ] && echo "DSM has not enabled networking yet.." && exit 1
|
||||
|
||||
location=$(cat "$file")
|
||||
@ -19,7 +19,7 @@ if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
|
||||
echo "Failed to reach DSM at port $port"
|
||||
else
|
||||
echo "Failed to reach DSM at http://$location"
|
||||
ip=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||
ip="$(cat "$address")"
|
||||
fi
|
||||
|
||||
echo "You might need to whitelist IP $ip in the DSM firewall." && exit 1
|
||||
|
@ -6,8 +6,8 @@ set -Eeuo pipefail
|
||||
: ${DHCP:='N'}
|
||||
: ${MAC:='02:11:32:AA:BB:CC'}
|
||||
|
||||
: ${VM_NET_DEV:=''}
|
||||
: ${VM_NET_TAP:='dsm'}
|
||||
: ${VM_NET_DEV:='eth0'}
|
||||
: ${VM_NET_MAC:="$MAC"}
|
||||
: ${VM_NET_HOST:='VirtualDSM'}
|
||||
|
||||
@ -204,14 +204,21 @@ fi
|
||||
update-alternatives --set iptables /usr/sbin/iptables-legacy > /dev/null
|
||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||
|
||||
if [ -z "$VM_NET_DEV" ]; then
|
||||
# Automaticly detect the default network interface
|
||||
VM_NET_DEV=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
|
||||
[ -z "$VM_NET_DEV" ] && VM_NET_DEV="eth0"
|
||||
fi
|
||||
|
||||
if [ ! -d "/sys/class/net/$VM_NET_DEV" ]; then
|
||||
error "Network interface $VM_NET_DEV does not exist inside the container!"
|
||||
error "Network interface '$VM_NET_DEV' does not exist inside the container!"
|
||||
error "$ADD_ERR -e \"VM_NET_DEV=NAME\" to specify another interface name." && exit 27
|
||||
fi
|
||||
|
||||
VM_NET_MAC="${VM_NET_MAC//-/:}"
|
||||
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
||||
IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||
echo "$IP" > /run/qemu.ip
|
||||
|
||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||
info "Container IP is $IP with gateway $GATEWAY" && echo
|
||||
|
@ -2,12 +2,12 @@
|
||||
set -Eeuo pipefail
|
||||
|
||||
: ${DHCP:='N'}
|
||||
: ${VM_NET_DEV:='eth0'}
|
||||
|
||||
info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "$1" "\E[0m\n" >&2; }
|
||||
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: $1" "\E[0m\n" >&2; }
|
||||
|
||||
file="/run/dsm.url"
|
||||
address="/run/qemu.ip"
|
||||
shutdown="/run/qemu.end"
|
||||
url="http://127.0.0.1:2210/read?command=10"
|
||||
|
||||
@ -69,7 +69,7 @@ if [[ "$location" != "20.20"* ]]; then
|
||||
|
||||
else
|
||||
|
||||
ip=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||
ip="$(cat "$address")"
|
||||
port="${location##*:}"
|
||||
|
||||
if [[ "$ip" == "172."* ]]; then
|
||||
|
@ -38,6 +38,7 @@ STORAGE="/storage"
|
||||
# Cleanup files
|
||||
|
||||
rm -f /run/dsm.url
|
||||
rm -f /run/qemu.ip
|
||||
rm -f /run/qemu.log
|
||||
rm -f /run/qemu.pid
|
||||
rm -f /run/qemu.end
|
||||
@ -120,7 +121,7 @@ setCountry() {
|
||||
return 0
|
||||
}
|
||||
|
||||
addPackage () {
|
||||
addPackage() {
|
||||
local pkg=$1
|
||||
local desc=$2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user