From 295b8cfdec251852e2c002f2b5fd4299e63d1559 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sat, 10 Jun 2023 10:01:06 +0200 Subject: add new version --- mikrotik-setup-script.rsc | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 mikrotik-setup-script.rsc (limited to 'mikrotik-setup-script.rsc') diff --git a/mikrotik-setup-script.rsc b/mikrotik-setup-script.rsc new file mode 100644 index 0000000..058f609 --- /dev/null +++ b/mikrotik-setup-script.rsc @@ -0,0 +1,65 @@ +{ + # name of bridge to add veth interface to + :local BRIDGENAME "bridgeLocal" + # name the veth interface will get + :local VETHNAME "mDNSTrunk" + # set hostname of container + :local HOSTNAME "mDNS" + # set vlan-ids to reflect traffic between + :local VLANS {100;200} + # define image filename + :local IMAGENAME "mdns_x86.tar" + # path to data root for the container + :local CONTAINERROOT "docker/container/mdns_repeater" + + # ------------------------------- + # variable holds all vlans seperated by spaces + :local ALLVLANS "" + + # check bridge existance + :if ([:len [/interface bridge find name="$BRIDGENAME"]] = 0) do={ + :put "Could not find a bridge with name '$BRIDGENAME' !" + :quit + } + # add veth interface + :if ([:len [/interface veth find name="$VETHNAME"]] = 0) do={ + # add veth interface + /interface veth add address=172.19.19.2/24 gateway=172.19.19.1 name=$VETHNAME + } + # add veth interface to bridge + :if ([:len [/interface bridge port find interface=$VETHNAME]] = 0) do={ + /interface bridge port add interface=$VETHNAME bridge=$BRIDGENAME + } + + # for each vlan id + :foreach id in=$VLANS do={ + # find existing vlan entry + :local vlanentry [/interface bridge vlan find vlan-ids ~ "(^|;)$id(;|\$)" and bridge=$BRIDGENAME] + + :if ([:len $vlanentry] = 0) do={ + # if entry does not exist add it to vlan list + /interface bridge vlan add bridge=$BRIDGENAME tagged="$BRIDGENAME,$VETHNAME" vlan-ids=$id + } else={ + # if entry exists and veth interface is not a tagged member append veth interface to vlan as tagged interface + :if ([:len [/interface bridge vlan find vlan-ids=$id and current-tagged ~ "$VETHNAME"]] = 0) do={ + /interface bridge vlan set $vlanentry tagged=([get $vlanentry tagged],"$VETHNAME") + } + } + # build ALLVLAN variable + :if ($ALLVLANS != "") do={ + :set ALLVLANS ($ALLVLANS . " " . $id) + } else={ + :set ALLVLANS $id + } + } + # add container environment variable wich defines the vlans used + :if ([:len [/container envs find name=mdns key=VLANS]] = 0) do={ + /container envs add name=mdns key=VLANS value=$ALLVLANS + } + # finally add container + :if ([:len [/container find root-dir="$CONTAINERROOT"]] = 0) do={ + /container add file=$IMAGENAME envlist=mdns logging=yes start-on-boot=yes root-dir="$CONTAINERROOT" interface=$VETHNAME hostname=$HOSTNAME + } else={ + :put "Container already exists, please delete it beforehand and run again!" + } +} -- cgit v1.2.3