Skip to content

Commit

Permalink
Add bridge setup script
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Dye <[email protected]>
  • Loading branch information
ecdye committed Jul 11, 2024
1 parent a563602 commit b3f9dde
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ jobs:
sudo add-apt-repository ppa:canonical-server/server-backports
sudo apt-get update
sudo apt-get install --yes gnupg xz-utils expect systemd-container qemu-user-static qemu-utils qemu-system-arm libfdt-dev isc-dhcp-client iproute2
sudo ip link add name br0 type bridge
sudo ip link set eth0 master br0
sudo ip tuntap add tap0 mode tap
sudo ip link set tap0 master br0
sudo ip link set up dev eth0
sudo ip link set up dev tap0
sudo ip link set up dev br0
sudo dhclient -v br0
sudo ip addr flush dev eth0
sudo ./tests/bridge.bash
echo "imagexz=$(basename "$(curl "https://downloads.raspberrypi.org/raspios_lite_armhf_latest" -s -L -I -o /dev/null -w '%{url_effective}')")" >> $GITHUB_OUTPUT
echo "image=$(echo "$(basename "$(curl "https://downloads.raspberrypi.org/raspios_lite_armhf_latest" -s -L -I -o /dev/null -w '%{url_effective}')")" | sed -e 's/.xz//')" >> $GITHUB_OUTPUT
- name: Cache Raspberry Pi OS 32bit image
Expand Down
43 changes: 43 additions & 0 deletions tests/bridge.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

if [[ $EUID != 0 ]]
then echo "Run this script as root"
exit
fi

BRIDGE="br0"
TAP="tap0"
INTERFACE="eth0"

echo "Adding bridge $BRIDGE"
ip link add name $BRIDGE type bridge

echo "Flushing interface $INTERFACE"
ip addr flush dev $INTERFACE

echo "Setting $BRIDGE as master of $INTERFACE"
ip link set $INTERFACE master $BRIDGE

echo "Adding tap $TAP"
ip tuntap add $TAP mode tap

echo "Setting $BRIDGE as master of $TAP"
ip link set $TAP master $BRIDGE

echo "Setting $INTERFACE, $BRIDGE and $TAP up"
ip link set up dev $INTERFACE
ip link set up dev $TAP
ip link set up dev $BRIDGE

echo "Stopping NetworkManager"
systemctl stop NetworkManager

echo "Requesting ip for $BRIDGE"

if dhclient $BRIDGE; then
echo "Requesting ip for $INTERFACE"
dhclient $INTERFACE
echo "Killing dhclient and starting NetworkManager"
pkill -9 dhclient
systemctl start NetworkManager
fi

0 comments on commit b3f9dde

Please sign in to comment.