diff options
| author | Michael Grote | 2023-06-10 10:01:06 +0200 |
|---|---|---|
| committer | Michael Grote | 2023-06-10 10:01:06 +0200 |
| commit | 295b8cfdec251852e2c002f2b5fd4299e63d1559 (patch) | |
| tree | 5496120cc5b070b0dc7a2c685a678412299749db /run.sh | |
| parent | 60df3d193f421e9ad9c646085ccb70f4e9829cde (diff) | |
add new version
Diffstat (limited to 'run.sh')
| -rw-r--r-- | run.sh | 55 |
1 files changed, 35 insertions, 20 deletions
@@ -1,31 +1,46 @@ #!/bin/bash - -# Exit on error +# on error exit set -e +# set vlan parent interface +INTERFACE=eth0 +# assign vlan ids via commandline parameter 1 +VLANS=$1 +if [[ -z "$VLANS" ]];then + echo -e "No VLAN-IDs assigned through environment variable with name 'VLANS'!\nExit container." + exit 1 +fi +# build interface list with parent interface and vlan ids +ALLVLANIF=$(echo -n $VLANS | sed -re "s/\b([0-9]+)/${INTERFACE}.\1/g") -HOSTNAME="mDns" -INTERFACE="eth0" -VLANS="20 100" +# get MTU of parent interface +MTU=$(ip link show $INTERFACE | grep -Ei 'mtu \d+' | cut -d " " -f2) -MTU=$(ip link show "$INTERFACE" | awk '{print $5}') +# cleanup non used vlan interfaces +for VLAN in $(ls -1 /sys/class/net | grep -E "^${INTERFACE}\\." | grep -Ev "$(echo $ALLVLANIF | tr ' ' '|')") ;do + echo "Deleting orphaned interface: $VLAN" + ip link delete $VLAN +done +# for each vlan id for VLAN in $VLANS; do - # INTERFACE PROVISION - IFNAME="${INTERFACE}.${VLAN}" - [ ! -d "/sys/class/net/${IFNAME}" ] && { - echo "create interface ${IFNAME}" - ip link add link "$INTERFACE" name "$IFNAME" mtu "$MTU" type vlan id "$VLAN" + VLANIF="${INTERFACE}.$VLAN" + # create vlan interface + [[ ! -d "/sys/class/net/${VLANIF}" ]] && { + echo "Creating interface ${VLANIF}" + ip link add link $INTERFACE name "$VLANIF" mtu $MTU type vlan id $VLAN } - echo "bring up ${IFNAME} interface" - ip link set "${IFNAME}" up + echo "Bring up $VLANIF interface" + ip link set "$VLANIF" up - # DHCP - [ -f "/var/run/udhcpc.${IFNAME}.pid" ] && { - kill "$(cat "/var/run/udhcpc.$IFNAME.pid")" || true - rm "/var/run/udhcpc.$IFNAME.pid" + # starting DHCP client on interface + [[ -f "/var/run/udhcpc.${VLANIF}.pid" ]] && { + kill "$(cat "/var/run/udhcpc.${VLANIF}.pid")" >/dev/null + rm "/var/run/udhcpc.${VLANIF}.pid" } - echo "starting dhcp client on ${IFNAME}" - udhcpc -b -i "$IFNAME" -x hostname:"$HOSTNAME" -p "/var/run/udhcpc.${IFNAME}.pid" + echo "Starting dhcp client on ${VLANIF}" + udhcpc -b -i $VLANIF -x hostname:"$HOSTNAME" -p "/var/run/udhcpc.${VLANIF}.pid" done -exec "$@" +echo "Starting mDNS repeater process ... " +# run repeater on vlan interfaces +exec /bin/mdns-repeater -f $ALLVLANIF |