The most irritating part with many linux installations is the following:
They provide wifi tools on the install image, but they are not part of the core system to be installed.
The core system expects a desktop computer, or just any device having a wired only connection to the internet (or LAN for that reason) .
So, first of a remainder of the packages required:
- dhcpcd, and ifconfig (or ip) (should already be installed)
- wpa_supplicant
- iw
As for all my scripts, it uses TUI, so you might want to install GIT or just download it from the http://github.com/sri-arjuna/tui page.
Now, the concept is, to have one script per spot, and have logfiles for each of the spots.
The logfiles are created according to the script its name, and create the key (creds) file automaticly if its missing.
Add the missing pieces, AP, password and your wifi device.
Then, save the code as something like: wifi-home.
#!/bin/bashNow lets prepare that thing to be executed upon boot, prepare:
#
# Variables
#
WIFI=wlp3s0 # Your WIFI device
SSID="AP-name" # The AP its name
PASS="AP-pass" # Password for that AP
URL="google.com" # Which URL to ping
ME=${0##*/}
KEY="$HOME/.config/$ME.key" # Where to save the keyfile
#
# Internals
#
start=${start:-false}
[ 0 -eq ${UID:-0} ] && \
LOG=/var/log/$ME.log || \
LOG=$HOME/.local/logs/$ME.log
#
# Functions
#
wifi_createkey () { # SSID PASS FILE
# Creates a wpa key file if none exists yet
#
[ -d "$(dirname $3)" ] || mkdir -p "$(dirname $3)"
wpa_passphrase "$1" "$2" > "$3"
}
wifi_start() {
# Start wpa supplicant in background
#
wpa_supplicant -B -i$WIFI -c"$KEY" 1>>"$LOG" 2>>"$LOG" &
dhcpcd -B 1>>"$LOG" 2>>"$LOG"
}
p() { ping -c 1 "$URL" 1>/dev/zero 2>/dev/zero;}
#
# Display and action
#
# Is there a key file?
[ ! -f "$KEY" ] && wifi_createkey "$SSID" "$PASS" "$KEY"
# If it cant ping, then there is no internet
if ! p 1>/dev/zero 2>/dev/zero
then start=true
# If they are already running, they are blocking the new connection
for used in dhcpcd ${0##*/}
do # Make sure those processes are killed if they are still running
if ps|grep $used | grep -v $$ >/dev/zero && tui-yesno "$used is already running, stop it?"
then pkill $used
kill $(ps|awk -v user=$used '/used/ {print $1}')
fi
done
fi
# Now only start if we need to
if $start
then tui-status -r 2 "Starting WIFI..."
wifi_start &
tui-status $? "Started wifi"
fi
[Unit]And place it in /etc/systemd/system as wifi-home.service.
Description=Wifi-Home
[Service]
Type=oneshot
ExecStart=/path/to/script/wifi-home.sh
[Install]
WantedBy=multi-user.target
And now finaly as root:
systemctl enable wifi-home
systemctl start wifi-home
After a restart, you can check how long the loading took:
$ systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.
graphical.target @12.509s
└─multi-user.target @12.508s
└─wifi-home.service @11.729s +778ms
└─basic.target @11.382s
...
Hope this helps