tangetools/wifi-reload/wifi-reload
2019-10-12 22:20:20 +02:00

99 lines
2.3 KiB
Bash
Executable file

#!/bin/bash
: <<=cut
=encoding utf8
=head1 NAME
wifi-reload - reload wifi setup
=head1 SYNOPSIS
B<wifi-reload>
=head1 DESCRIPTION
Sometimes the wifi config gets stuck. B<wifi-reload> tries to get the
config unstuck by reloading modules, wpa_supplicant and
NetworkManager.
=head1 AUTHOR
Copyright (C) 2017 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc.
=head1 LICENSE
Copyright (C) 2012 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 SEE ALSO
B<bash>(1)
=cut
modules="rt2500usb iwl4965 iwl3945 iwldvm ath9k ath9k_common ath9k_hw ath ath3k brcmfmac rt73usb rt2x00lib cfg80211 mac80211"
stop() {
sudo killall wpa_supplicant
PID=$(sudo NetworkManager 2>&1 | grep -Eo '[0-9]+')
sudo kill $PID || sudo killall NetworkManager
sudo parallel -j1 --delay 0.03 --retries 50 modprobe -r ::: $modules
killall nm-applet || killall -9 nm-applet
sudo killall -9 wpa_supplicant
sudo kill -9 $PID || sudo killall -9 NetworkManager
}
starthw() {
parallel -j1 sudo modprobe ::: $modules
sudo rfkill unblock all
}
startnm() {
#sudo service network-manager start
sudo NetworkManager &
#sudo /etc/init.d/network-manager restart
#sudo /etc/init.d/network-manager start
nm-applet 2>/dev/null &
}
config() {
IF=$1
sudo bash -c 'cat >> /etc/resolv.conf' < /etc/resolvconf/resolv.conf.d/head
#sudo iwconfig wls1 essid Turris
#sudo iwconfig wls1 essid Leif
#sudo iwconfig wls1 essid SKYbroadbandCC95
sudo wpa_supplicant -c/etc/wpa_supplicant.conf -i$IF -d &
sudo dhclient $IF &
}
stop
starthw
IF=$(stdout iwconfig |perl -ane '/^\s|no wireless extension/ and next; print $F[0],"\n"')
iwconfig
config $IF
startnm
if tty -s ; then
# STDIN is terminal
true timeout 12 dmesg -Tw &
fi