#!/bin/bash
set -e  # Exit on error

echo "=== ES40 Network Setup ==="

# Create feth pair
echo "Creating feth5000/feth5001..."
sudo /sbin/ifconfig feth5000 create
sudo /sbin/ifconfig feth5001 create 
sudo /sbin/ifconfig feth5000 peer feth5001

# Create bridge
echo "Creating bridge200..."
sudo /sbin/ifconfig bridge200 create

# Add feth5000 to bridge
echo "Adding feth5000 to bridge200..."
sudo /sbin/ifconfig bridge200 addm feth5000

# Bring interfaces up
echo "Bringing interfaces up..."
sudo /sbin/ifconfig feth5000 up
sudo /sbin/ifconfig feth5001 up
sudo /sbin/ifconfig bridge200 up

# Configure bridge with IP
echo "Configuring bridge200 with 10.0.40.1..."
sudo /sbin/ifconfig bridge200 10.0.40.1 netmask 255.255.255.0

# Enable IP forwarding
echo "Enabling IP forwarding..."
sudo sysctl -w net.inet.ip.forwarding=1 > /dev/null

echo ""
echo "Network interfaces:"
/sbin/ifconfig bridge200 | grep -E 'inet|flags'
echo ""
/sbin/ifconfig feth5001 | head -n 5
echo ""
echo "ES40 Configuration (in your config):"
echo '    adapter = "feth5001";   # or however es40/axpbox specifies the pcap device'
echo ""
echo "Tru64 5.1B  OS Configuration:"
echo "    IP:          10.0.40.2"
echo "    Netmask:     255.255.255.0"
echo "    Gateway:     10.0.40.1"
echo "    ifconfig tu0 10.0.40.2 netmask 255.255.255.0 up"
echo "    route add default 10.0.40.1" 

echo ""
echo "Done"
