Skip to content

Instantly share code, notes, and snippets.

@jrconlin
Created March 6, 2021 22:03
Show Gist options
  • Save jrconlin/0b79fbfcba3d5ec91751cb1a667b410e to your computer and use it in GitHub Desktop.
Save jrconlin/0b79fbfcba3d5ec91751cb1a667b410e to your computer and use it in GitHub Desktop.
Re-enable wifi on Raspberry Pi Buster after rfkill nukes it
#! /bin/bash
# RaspberryOS Buster introduced rfkill which will shut off your wifi. It reports
# that you need to set the country for it, which is fair, but apparently it has
# issues noticing that your country is, indeed, set, so the wifi stays off.
#
# The following script checks to see if the `wlan` is blocked (well, if it's
# not unblocked), and unblocks it. Since the rfkill check happens after reboot,
# we need to delay a bit before we start checking.
# (e.g. in crontab:
# ```
# PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin
# @reboot $HOME/bin/enable_wifi.sh reboot >> /tmp/enable_wifi.log
# ```
#
# if you want my kind of paranoia, I'd recommend running this every 5 minutes.
# ```
# */5 * * * * $HOME/bin/enable_wifi.sh >> /tmp/enable_wifi.log
# ```
#)
if [ "$1" == "reboot" ]
then
# Sleep for around 30 seconds to let things boot and rfkill to kill your wifi.
# (Sigh heavily at this).
sleep 30
fi
# Get the wifi state as rfkill knows it. This is GREATLY trimmed down.
state=`/usr/sbin/rfkill -n --output=type,soft | grep wlan`
echo $state
# Can't search for "blocked" because it's not unique enough.
if [ "`echo $state | grep -v 'unblocked' `" != "" ]
then
echo "restarting wifi"
/usr/sbin/rfkill unblock wlan
echo "wifi restarted"
fi
@stamepicmorg
Copy link

thank you very much! 👍 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment