#!/bin/bash # This script enables wifi for my laptop outside the home network # Run this script as root only # Function to configure ath0 and obtain a DHCP IP address dhcp_get() { echo "Configuring interface ..."; iwconfig ath0 essid any key off ; echo "Acquiring IP Address ... "; dhcpcd -d -t 10 ath0; # The following will check if there was an IP addr issued if [[ -f /etc/dhcpc/dhcpcd-ath0.pid ]]; then echo "Connection ready!"; echo ; iwconfig ath0; else echo "Connection attempt unsuccessful."; echo ; iwconfig ath0; # dhcpcd will automatically bring ath0 down fi } # If chosen not to connect, turn off the interface if_down() { ifconfig ath0 down ; echo "WiFi interface not configured." ; exit ; } # Bring the interface up and scan for networks ifconfig ath0 up iwlist ath0 scan |more # List available networks # Ask to connect echo "Attempt connection (y/n)?" read x # yes or else case $x in 'y') dhcp_get ;; *) if_down ;; esac