Add MAC variable

Add MAC variable
This commit is contained in:
Kroese 2023-05-07 15:58:36 +02:00 committed by GitHub
commit c7f6a2498c

View File

@ -3,12 +3,14 @@ set -Eeuo pipefail
# Docker environment variables # Docker environment variables
: ${DHCP:='N'}
: ${MAC:='02:11:32:AA:BB:CC'}
: ${VM_NET_TAP:='dsm'} : ${VM_NET_TAP:='dsm'}
: ${VM_NET_DEV:='eth0'} : ${VM_NET_DEV:='eth0'}
: ${VM_NET_MAC:='$MAC'}
: ${VM_NET_HOST:='VirtualDSM'} : ${VM_NET_HOST:='VirtualDSM'}
: ${VM_NET_MAC:='02:11:32:AA:BB:CC'}
: ${DHCP:='N'}
: ${DNS_SERVERS:=''} : ${DNS_SERVERS:=''}
: ${DNSMASQ_OPTS:=''} : ${DNSMASQ_OPTS:=''}
: ${DNSMASQ:='/usr/sbin/dnsmasq'} : ${DNSMASQ:='/usr/sbin/dnsmasq'}
@ -28,11 +30,7 @@ configureDHCP() {
[[ "${DEBUG}" == [Yy1]* ]] && set -x [[ "${DEBUG}" == [Yy1]* ]] && set -x
{ ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || : { ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || :
if (( rc != 0 )); then if (( rc == 0 )); then
echo -n "INFO: Could not create macvlan, skipping..."
else
ip address add "${IP}" dev "${VM_NET_VLAN}" ip address add "${IP}" dev "${VM_NET_VLAN}"
ip link set dev "${VM_NET_VLAN}" up ip link set dev "${VM_NET_VLAN}" up
@ -43,6 +41,10 @@ configureDHCP() {
ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0 ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0
ip route add default via "${GATEWAY}" ip route add default via "${GATEWAY}"
else
echo "INFO: Could not create ${VM_NET_VLAN} on ${VM_NET_DEV}, skipping..."
fi fi
{ ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || : { ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || :
@ -214,8 +216,6 @@ if [[ "${DEBUG}" == [Yy1]* ]]; then
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/) IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
echo "INFO: Container IP is ${IP} with gateway ${GATEWAY}" && echo echo "INFO: Container IP is ${IP} with gateway ${GATEWAY}" && echo
ifconfig
ip route && echo
fi fi