Wireless LAN activation hotkeys how-to

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Post Reply
Level 1
Level 1
Posts: 1
Joined: Fri Aug 19, 2011 11:19 am
Location: France

Wireless LAN activation hotkeys how-to

Post by Wynndrake » Fri Aug 19, 2011 12:26 pm

Greetings all ! As a newcomer here, and also a newcomer to Linux Mint (but also an Ubuntu user) I thought it could be a nice idea not to arrive empty-handed for my first post here :) I'll also post an introduction very soon !

So, I thought it could be nice posting a little how-to about how to enable key combinations support on laptops such as Fujitsu-Siemens ones, and especially the Amilo series. Being the owner of an Amilo 1650G and an Amilo Li 2727, I spent an awful number of hours (days ?) trying to have the damn wifi activation button or key combination work. For the hotkey, it's hopeless, sadly, but I found what seems to be a pretty decent solution, in my humble opinion, regarding the famous FN+F1 keys combination (which is not always natively operational in most distros, sadly).

This was tested with a fresh Linux Mint 11 installation on an Amilo Li 2727 laptop computer. The wireless LAN card is natively recognized and all the kernel modules (ath5k, acer-wmi, etc.) are properly loaded without any user intervention. So, here comes the fun :

To be able to toggle the WLAN on and off without always having to use sudo to summon the rfkill command, the easiest way is to proceed as follows :

1 - Create a "wifiusers" group by entering the following command in a terminal :

Code: Select all

sudo groupadd wifiusers
2 - Add the computer users to this group, from the graphical interface, because it's easier (we'll see why this group is created later in the how-to)

Code: Select all

Click the main Menu -> Administration category -> Users and groups
or simply perform a search on "Users and Groups" in the main menu.

3- In the "Users Settings" window, click the "Manage groups" button (enter your admin password if prompted for it, of course).

4 - Scroll down the list until you find the "wifiusers" group, select it and click the "Properties" button.

5 - You will see a list with checkboxes before the users' names. Check the boxes corresponding to the users you want to allow to be able to toggle the wifi on or off, then click "Ok".

6 - Back to the groups list, click "Close", then "Close" again in the "Users Settings" window.

The easiest part is now complete. What have we done so far ? We have created a special group and added users to it in order to be later able to use the rfkill command without having to temporarily elevate the user's privilege every time they want to toggle the wireless LAN on or off. But now we have this group set up, we have to configure the system so that it explicitely doesn't require administrator privileges for any user belonging to the "wifiusers" group who would use /usr/sbin/rfkill or /sbin/rfkill (enter : man rfkill, if you don't know what it is for).
We will have to be careful for the next step because it involves editing /etc/sudoers (so, as root).

7 - Open visudo :

Code: Select all

sudo visudo
8 - Under the line saying "root ALL=(ALL:ALL) ALL" add this :

Code: Select all

%wifiusers ALL = NOPASSWD: /usr/sbin/rfkill, /sbin/rfkill
DOUBLE-CHECK HERE. In case of doubt, never save, exit without saving and repeat the procedure from Step 7.

9 - Press CTRL+O to save, and confirm (visudo will prompt for confirmation or cancellation)

10 - Press CTRL+X to exit visudo

The dangerous part is now done. We now have a group with users who can summon rfkill without having to prefix the command with sudo. To test it, simply enter :

Code: Select all

rfkill list all
If it lists you the enabled/disabled interfaces without requiring administrator privileges, it means the addition in /etc/sudoers was successfully taken into account.
Now, we only need to create a little script that will make it easier for us and will spare us from always having to enter rfkill unblock wifi to enable the WLAN interface or rfkill block wifi to switch it off.

11 - A very simple Bash script will do it. Create a new file in gEdit or in VIM, depending on your preferences, and enter this :

Code: Select all


# Reading the interface state (blocked or unblocked)
INTFACE=`rfkill list wifi | grep -om 1 "Soft blocked: yes"`

# If rfkill returns that the interfaces are blocked, the script will unblock the wifi interfaces, and the other way round if they're unblocked. So that we can easily toggle the WLAN interface on and off
# Side note : really make sure "Soft blocked: yes" is written as returned by rfkill
if [ "$INTFACE" == "Soft blocked: yes" ]; then
         rfkill unblock wifi
         rfkill block wifi
exit 0
12 - Save the file as "wifitoggle"

13 - Make it executable and move it to /usr/bin so that it can be used by any normal user as any normal command or installed program :

Code: Select all

chmod +x wifitoggle && sudo mv wifitoggle /usr/bin
Now you can enter "wifitoggle" in a terminal to toggle the WLAN on, and enter the same command to toggle the WLAN off ! No extra parameter required :)

14 - Final step ! (Phew !) Now, let's go to the main menu -> Preferences -> Keyboard shortcuts. Click on "Add" in the keyboard shortcuts window.
Name : Wifi switch
Command : wifitoggle
Then, click on "Apply". All you need to do now is defining which key shortcut you want for toggling wifi on/off. Personally, I chose CTRL+F1 as it was unused on my machine. But there, do it at your own convenience :)

I hope this helps !
~Knowledge is power ~

Post Reply

Return to “Tutorials”