96 lines
2.3 KiB
Bash
Executable File
96 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ==============================================================================
|
|
# Config
|
|
|
|
SOURCE=${BASH_SOURCE[0]}
|
|
while [ -L "$SOURCE" ]; do
|
|
DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)
|
|
SOURCE=$(readlink "$SOURCE")
|
|
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
|
|
done
|
|
DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)
|
|
|
|
if [[ -f "$DIR/../config/config.sh" ]]; then
|
|
source "$DIR/../config/config.sh"
|
|
else
|
|
echo "$DIR/../config/config.sh missing!"
|
|
exit 1
|
|
fi
|
|
|
|
# Must be run as root
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
echo 'This script must be run as root.' >&2
|
|
exit 1
|
|
fi
|
|
|
|
# ==============================================================================
|
|
|
|
iptables -X
|
|
iptables -F
|
|
iptables -t nat -X
|
|
iptables -t nat -F
|
|
echo "Cleared iptables"
|
|
|
|
# Restore MAC address to WLAN interface
|
|
ifconfig $WLAN_IFACE down
|
|
ifconfig $WLAN_IFACE hw ether "$(ethtool -P $WLAN_IFACE | awk '{print $3}')"
|
|
ifconfig $WLAN_IFACE up
|
|
echo "Reset $WLAN_IFACE"
|
|
|
|
while true; do
|
|
WLAN_IFACE_IP=$(ip -4 -br addr show $WLAN_IFACE | grep -Po "\\d+\\.\\d+\\.\\d+\\.\\d+")
|
|
if [ -n "${WLAN_IFACE_IP}" ]; then
|
|
echo "Got it!"
|
|
break
|
|
fi
|
|
echo "Waiting for $WLAN_IFACE to get an IP..."
|
|
sleep 5
|
|
done
|
|
|
|
systemctl start systemd-resolved
|
|
systemctl stop dnsmasq
|
|
echo "Reset DNS services"
|
|
|
|
echo -e "\nConnecting to WiFi..."
|
|
|
|
WPA_SUPP_FILE="/etc/wpa_supplicant/wpa_supplicant-$WLAN_IFACE.conf"
|
|
cat >"$WPA_SUPP_FILE" <<EOF
|
|
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
|
update_config=1
|
|
country=USifconfig $WLAN_IFACE
|
|
network={
|
|
ssid="$WIFI_SSID"
|
|
scan_ssid=1
|
|
key_mgmt=WPA-EAP
|
|
eap=PEAP
|
|
identity="$WIFI_USERNAME"
|
|
password="$WIFI_PWD"
|
|
phase1="peaplabel=0"
|
|
phase2="auth=MSCHAPV2"
|
|
}
|
|
EOF
|
|
chmod 600 "$WPA_SUPP_FILE"
|
|
echo "Created wpa_supplicant: $WPA_SUPP_FILE"
|
|
systemctl disable wpa_supplicant.service
|
|
systemctl stop wpa_supplicant.service
|
|
systemctl enable --now wpa_supplicant@$WLAN_IFACE.service
|
|
systemctl status --no-pager wpa_supplicant@$WLAN_IFACE.service
|
|
echo ""
|
|
ifconfig $WLAN_IFACE
|
|
|
|
echo -e "\n\n"
|
|
ifconfig $WLAN_IFACE
|
|
NET_CONF_FILE="/etc/systemd/network/08-$WLAN_IFACE.network"
|
|
cat >"$NET_CONF_FILE" <<EOF
|
|
[Match]
|
|
Name=$WLAN_IFACE
|
|
[Network]
|
|
IPForward=yes
|
|
DHCP=yes
|
|
EOF
|
|
echo "Created network config: $WLAN_IFACE"
|
|
|
|
echo "Restarting systemd-networkd..."
|
|
systemctl restart systemd-networkd.service
|