#!/bin/bash

# Exit on any error
set -e

# Bridge name
BRIDGE_NAME="br0"

# Network interfaces to add to the bridge
INTERFACES=("eth0" "eth1" "eth2" "eth3" "eth4")

# Create the bridge
ip link add name $BRIDGE_NAME type bridge
ip link set $BRIDGE_NAME up

# Enable VLAN filtering
bridge vlan add dev $BRIDGE_NAME vid 1 pvid untagged self

# Add interfaces to the bridge and configure VLANs
for iface in "\${INTERFACES[@]}"; do
    # Add interface to the bridge
    ip link set $iface master $BRIDGE_NAME
    
    # Configure VLAN for each interface (example configuration)
    bridge vlan add dev $iface vid 1 pvid untagged
    bridge vlan add dev $iface vid 100
    bridge vlan add dev $iface vid 200
done

# Additional VLAN configuration (example)
bridge vlan add dev $BRIDGE_NAME vid 100 self
bridge vlan add dev $BRIDGE_NAME vid 200 self

# Display bridge and VLAN information
echo "Bridge configuration:"
ip link show $BRIDGE_NAME
echo "
VLAN configuration:"
bridge vlan show

echo "Bridge setup complete!"