From 77c3d3f1a4b0c59b3aece4cbac0499fd10f80d4a Mon Sep 17 00:00:00 2001 From: Cyberes Date: Tue, 13 Jun 2023 10:33:04 -0600 Subject: [PATCH] add files --- bridge-install.sh | 220 ++++++++++++++++++++++++++++++++++++++++++++++ config.sh.example | 15 ++++ 2 files changed, 235 insertions(+) create mode 100644 bridge-install.sh create mode 100644 config.sh.example diff --git a/bridge-install.sh b/bridge-install.sh new file mode 100644 index 0000000..13d256f --- /dev/null +++ b/bridge-install.sh @@ -0,0 +1,220 @@ +#!/bin/bash +# https://raspberrypi.stackexchange.com/questions/88954/workaround-for-a-wifi-bridge-on-a-raspberry-pi-with-proxy-arp +# https://www.willhaley.com/blog/raspberry-pi-wifi-ethernet-bridge/ + +# TODO: non-interactive install + +# ============================================================================== +# Config + +SOURCE=${BASH_SOURCE[0]} +while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd ) + SOURCE=$(readlink "$SOURCE") + [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd ) + +if [[ -f "$DIR/config.sh" ]]; then + source "$DIR/config.sh" +else + echo "config.sh missing!" + exit 1 +fi + +# ============================================================================== +# Setup + +# Must be run as root +if [ "$(id -u)" -ne 0 ]; then + echo 'This script must be run as root.' >&2 + exit 1 +fi + +# We only need to get the $WLAN_IFACE IP address and will copy it over to $ETH_IFACE later +WLAN_IFACE_IP=$(ip -4 -br addr show $WLAN_IFACE | grep -Po "\\d+\\.\\d+\\.\\d+\\.\\d+") + +# ============================================================================== +# Install stuff + +echo "# INSTALL THINGS #" + +THINGS_TO_INSTALL="parprouted dhcp-helper net-tools" + +if ! $NON_INTERACTIVE; then + echo "Going to install: $THINGS_TO_INSTALL" + read -p "Press ENTER to continue or CTRL+C to cancel..." +fi + +echo -e "\n" + +apt-get install $THINGS_TO_INSTALL + +echo -e "\n\nSetting up services...\n" + +systemctl stop dhcp-helper +systemctl enable dhcp-helper + +if ! $NON_INTERACTIVE; then + echo -e "\n\nGoing to replace networking with systemd-networkd." + read -p "Press ENTER to continue or CTRL+C to cancel..." +fi + +echo -e "\n" +apt-get --autoremove -y purge ifupdown dhcpcd5 isc-dhcp-client isc-dhcp-common + +echo -e "\n\nConnecting to WiFi..." + +WPA_SUPP_FILE="/etc/wpa_supplicant/wpa_supplicant-$WLAN_IFACE.conf" +cat > "$WPA_SUPP_FILE" < "$NET_CONF_FILE" < "$DHCP_HELPER_CONF" <> /etc/dhcpcd.conf + +# Disable dhcpcd control of $ETH_IFACE. +# grep "^denyinterfaces ${ETH_IFACE}\$" /etc/dhcpcd.conf || printf "denyinterfaces $ETH_IFACE\n" >> /etc/dhcpcd.conf + +# Enable avahi reflector if it's not already enabled. +sed -i'' 's/#enable-reflector=no/enable-reflector=yes/' /etc/avahi/avahi-daemon.conf +grep '^enable-reflector=yes$' /etc/avahi/avahi-daemon.conf || { + printf "something went wrong...\n\n" + printf "Manually set 'enable-reflector=yes in /etc/avahi/avahi-daemon.conf'\n" +} +echo "Enabled avahi reflector." + +PARPROUTED_SERVICE="/etc/systemd/system/parprouted.service" +cat > "$PARPROUTED_SERVICE" <