WizardKit/archlive/airootfs/usr/local/bin/connect-to-network
Alan Mason 077401ef85 2017-06: Retroactive Updates
* Include extras/* in ISO
  * build-wk modifies build.sh before it is called
* NetworkManager is back
* Switched to Numix-Square icons
* Added remount-rw script
  * Accessible in Thunar as custom action
* Readded mesa-demos to fix inxi message
* Removed xorg-video-ati (conflicts with AMDGPU)
* Swapping nvidia in for nouveau (attempt to fix X for newer macs)
* Added mbpfan-git
* Added Mac fans script (set all fans to auto/max)
* Fixed issue where udevil would use /media/$USER/Name for the first call
2017-12-06 17:58:25 -08:00

64 lines
1.6 KiB
Bash

#!/bin/bash
#
## Get connected to a network
# 1. Checks if already online; skips if so
# 2. If no wired devices are present then reload kernel modules
# 3. If wireless devices are present, and we're still offline, then connect to WiFi
die () {
echo "$0:" "$@" >&2
exit 1
}
function test_connection() {
if ip a | grep -Eq '(10.[0-9]+|172.(1[6-9]|2[0-9]|3[0-1]).[0-9]+|192.168).[0-9]+.[0-9]+'; then
return 0
else
return 1
fi
}
# Load settings
if [[ -f "/run/archiso/bootmnt/arch/arch.conf" ]]; then
source "/run/archiso/bootmnt/arch/arch.conf" || \
die "ERROR: failed to load arch.conf (from /run/archiso/bootmnt/arch/)"
else
source "/usr/local/bin/arch.conf" || \
die "ERROR: failed to load arch.conf (from /usr/local/bin/)"
fi
# Init
WIFI_SSID="${WIFI_SSID}"
WIFI_PASS="${WIFI_PASS}"
# Connect to network
if ! test_connection; then
# LAN
if ! ip l | grep -Eq '[0-9]+: +en'; then
## Reload the tg3/broadcom driver (known fix for some Dell systems)
echo "No wired network adapters found; reloading drivers..."
sudo modprobe -r tg3
sudo modprobe broadcom
sudo modprobe tg3
sleep 5s
fi
# WiFi
if ip l | grep -Eq '[0-9]+: +wl'; then
## Skip if we're already connected (i.e. the code above worked)
if ! test_connection; then
echo "Attempting to connect to ${WIFI_SSID}..."
nmcli dev wifi connect "${WIFI_SSID}" password "${WIFI_PASS}"
sleep 5s
fi
fi
fi
# Done
if test_connection; then
exit 0
else
exit 1
fi