Skip to content

Commit

Permalink
fixup! Add scripts for setting up hoeve
Browse files Browse the repository at this point in the history
  • Loading branch information
lmbollen committed Aug 28, 2024
1 parent 6608fac commit ead12c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 2 additions & 3 deletions hitl-setup/dhcpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
subnet 100.100.100.0 netmask 255.255.255.0 {
range 100.100.100.2 100.100.100.254;
option routers 100.100.100.1;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.2 10.0.0.254;
}
27 changes: 21 additions & 6 deletions hitl-setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ BRIDGE_NAME="eth-fpga"
# File containing the list of network interfaces
INTERFACES_FILE="interfaces"

INTERFACE_IP="100.100.100.1/24"
DHCP_IP="100.100.100.0"
INTERFACE_IP="10.0.0.1/24"
DHCP_IP="10.0.0.0"

# Function to read interfaces from the file
read_interfaces() {
Expand All @@ -37,6 +37,7 @@ create_bridge() {
fi
}

# Function to remove the bridge
remove_bridge() {
echo "Deleting bridge $BRIDGE_NAME..."
if ip link show $BRIDGE_NAME &> /dev/null; then
Expand All @@ -47,6 +48,8 @@ remove_bridge() {
fi
}


# Add all ethernet inferfaces specified in $INTERFACES_FILE to the bridge
add_interfaces() {
for iface in "${INTERFACES[@]}"; do
echo "Adding interface $iface to bridge $BRIDGE_NAME and setting it up."
Expand All @@ -55,13 +58,17 @@ add_interfaces() {
done
}

# Remove all ethernet inferfaces specified in $INTERFACES_FILE from the bridge
remove_interfaces() {
for iface in "${INTERFACES[@]}"; do
echo "Removing interface $iface from bridge $BRIDGE_NAME."
ip link set $iface nomaster
done
}

# Check if the bridge and interfaces are set up correctly
# The bridge should exist, be up and have the correct IP address
# All interfaces should exist, be up and have the bridge as master
check_eth() {
# Check if the bridge exists
if ! ip link show $BRIDGE_NAME &> /dev/null; then
Expand Down Expand Up @@ -101,7 +108,10 @@ check_eth() {
done
}

#For dhcp we use `isc-dhcp-server` package
# For dhcp we use `isc-dhcp-server` package
# We need to make sure that the package is installed
# We need to make sure that /etc/default/isc-dhcp-server mentions the bridge as an interface
# We then restart the service and check if it's listening on the correct interface
setup_dhcp() {
# Make sure the package is installed
apt-get install isc-dhcp-server
Expand All @@ -124,7 +134,7 @@ setup_dhcp() {
fi

# When we start the service we should be able to see:
# Listening on LPF/$BRIDGE_NAME/<MAC ADDRESS>/$INTERFACE_IP
# Listening on LPF/$BRIDGE_NAME/<MAC ADDRESS>/$DHCP_IP
systemctl restart isc-dhcp-server

# Wait for the service to be started
Expand All @@ -136,6 +146,7 @@ setup_dhcp() {
fi
}

# Check if the DHCP server is installed and running
check_dhcp() {
# Check if the service is installed
if ! dpkg -l | grep -q "isc-dhcp-server"; then
Expand All @@ -152,8 +163,9 @@ check_dhcp() {
echo "isc-dhcp-server is running."

#Ideally I'd verify if it's listening on the correct interface
#But I'm not sure how to do that
#But I'm not sure how to do that without restarting the service
}

# Main script logic
case "$1" in
check)
Expand Down Expand Up @@ -181,9 +193,12 @@ case "$1" in
setup_dhcp
;;
*)
echo "Usage: $0 {create|add|show|remove|delete}"
echo "Usage: $0 {check|dhcp|eth|rm-eth|setup}"
echo " check - Check if the ethernet bridge $BRIDGE_NAME and DHCP are set up correctly"
echo " dhcp - Install and set up DHCP on the bridge $BRIDGE_NAME, please manually configure /etc/dhcp/dhcpd.conf"
echo " eth - Create an ethernet bridge $BRIDGE_NAME with all interfaces"
echo " rm-eth - Delete the ethernet bridge $BRIDGE_NAME"
echo " setup - Perform both eth and dhcp setup"
exit 1
;;
esac

0 comments on commit ead12c1

Please sign in to comment.