- I am a Fedora user, but this should be fairly generic across all distros. I'm able to read most things posted here and translate where necessary (and wouldn't be as far as I am without some of the posts here).
- These instructions assume you have wifi working and fairly stable. Now you're just ready to use the hardware switch on the laptop so you can save some power drain when not using wifi (my powertop shows ~0.5 difference).
Much of this was gleaned from two scripts, rm_driver.sh and add_driver.sh, that came with the Acer Linpus install as well as the .XHkeys file in the Linpus default 'user' home directory. It's been tweaked to my liking, adjust to suit your situation as needed.
Requirements:
1) A program to trap specific keycodes and execute a specific program when a specific keycode is seen. The Acer Linpus is using xhkeys. I've chosen, for now, to use xhotkeys.
2) Might need rights and knowledge to edit the sudoers file. Depends on how your distro is setup.
3) Knowledge of how to create/save a file to '/usr/local/bin/'. This isn't intended to be a full how-to and you could create the files in a place where your regular user account has rights to do so (ala '~/bin/').
4) Adjust paths to any commands shown to match where they are on your system.
Basic steps:
1) Create the "turn off" and "turn on" scripts in the '/usr/local/bin/' directory. Let's pretend we call them the same as on the Acer Linpus install:
- "turn off": /usr/local/bin/rm_driver.sh
- "turn on": /usr/local/bin/add_driver.sh
2) Make them executable:
- Code: Select all
sudo chmod 0755 /usr/local/bin/rm_driver.sh
sudo chmod 0755 /usr/local/bin/add_driver.sh
3) Test them by hand in a terminal with your normal account:
- Code: Select all
/usr/local/bin/rm_driver.sh
/usr/local/bin/add_driver.sh
4) Debug as necessary. If you have to type in a password when running the 'sudo' command at any time from when you first login, see below for some example ways to setup the sudoers file. You could do a quick and dirty '[user] ALL=(ALL) NOPASSWD: ALL' for debugging purposes only. I don't recommend leaving it that way, though.
5) Once you can run the scripts by hand without any errors and the wifi is correctly stopped and started, you can now setup your chosen "hotkey" program. The keycodes that should be trapped are 234 for the "off" script and 233 for the "on" script. When I setup xhotkeys I:
- Ran, in a terminal, 'xhotkeys -c' to get the configuration screen.
- In the configuration screen I clicked on the "Add" button.
- In the "Add" window I typed the name (for example "Wifi-Off"). Then I clicked on the "Change Hotk" button and moved the wifi switch (in this case I knew wifi was on, so the code generated was for the off command). Lastly in the "Command" box I typed in the full path to the script I wanted executed (again, for the off example of /usr/local/bin/rm_driver.sh).
- The "Test command" button won't do anything unless the xhotkey daemon is running. You could start this in another terminal window by typing only 'xhotkey'. Leave the window running the daemon open to see if there are any errors when testing.
- Repeat for the "on" script and trapping the "on" code.
6) Once everything is debugged, locked down, and confirmed working with your "hotkey" program then set it to run when you login to X-Windows and enjoy.
The "turn off" script:
- Code: Select all
#!/bin/sh
# Disable the wireless drivers
#
# Requires sudo rights to the following commands
RMOD=/sbin/rmmod
IFCFG=/sbin/ifconfig
WLANCFG=/usr/bin/wlanconfig
# Sudo rights not required for the following commands
SDO=/usr/bin/sudo
LMOD=/sbin/lsmod
GRP=/bin/grep
AWK=/usr/bin/awk
###################
$SDO $IFCFG ath0 down
sleep 1
$SDO $WLANCFG ath0 destroy
# New order
$SDO $RMOD ath_pci
sleep 1
for d in `$LMOD | $GRP ^wlan_ | $AWK '{print $1}'`; do
$SDO $RMOD $d
done
sleep 1
for d in `$LMOD | $GRP ^ath_ | $AWK '{print $1}'`; do
$SDO $RMOD $d
done
$SDO $RMOD wlan
exit 0
The "turn on" script:
- Code: Select all
#!/bin/sh
# Enable wireless drivers
#
# Requires sudo rights to the following commands
MODP=/sbin/modprobe
SYSCT=/sbin/sysctl
IFCFG=/sbin/ifconfig
# Sudo rights not required for the following commands
SDO=/usr/bin/sudo
###################
# Load the driver
$SDO $MODP ath_pci
# Turn the LED back on
$SDO $SYSCT -q -w dev.wifi0.softled=1
$SDO $SYSCT -q -w dev.wifi0.ledpin=3
# Bring the interface up
$SDO $IFCFG ath0 up
exit 0
Locked down sudoers settings example (replace [user] with the account you login as):
- Code: Select all
Cmnd_Alias ATHDIFCFG = /sbin/ifconfig ath0 down
Cmnd_Alias ATHDWLANCFG = /usr/bin/wlanconfig ath0 destroy
Cmnd_Alias ATHDRMODW1 = /sbin/rmmod wlan_*
Cmnd_Alias ATHDRMODA = /sbin/rmmod ath_*
Cmnd_Alias ATHDRMODW2 = /sbin/rmmod wlan
Cmnd_Alias ATHUMODP = /sbin/modprobe ath_pci
Cmnd_Alias ATHUSYSCTL1 = /sbin/sysctl -q -w dev.wifi0.softled\=1
Cmnd_Alias ATHUSYSCTL2 = /sbin/sysctl -q -w dev.wifi0.ledpin\=3
Cmnd_Alias ATHUIFCFG = /sbin/ifconfig ath0 up
[user] ALL = NOPASSWD: ATHDIFCFG, ATHDWLANCFG, ATHDRMODW1, ATHDRMODA, ATHDRMODW2, ATHUMODP, ATHUSYSCTL1, ATHUSYSCTL2, ATHUIFCFG
Semi-locked down sudoers example settings (replace [user] with the account you login as):
- Code: Select all
Cmnd_Alias MODP = /sbin/modprobe
Cmnd_Alias SYSCT = /sbin/sysctl
Cmnd_Alias IFCFG = /sbin/ifconfig
Cmnd_Alias RMOD = /sbin/rmmod
Cmnd_Alias WLANCFG = /usr/bin/wlanconfig
[user] ALL = NOPASSWD: MODP, SYSCT, IFCFG, RMOD, WLANCFG
