Bypassing a corporate Web filter when using the command line

or ‘How to bypass a corporate Web filter and download YouTube videos via the command line’

One of the offices where I work uses a Web filter to block access to certain sites, such as YouTube. However, sometimes it is necessary to view blocked Web sites for work purposes. For example, these days a lot of companies or individuals post product reviews on YouTube that are useful for work purposes. In such cases I have used Tor to access the blocked sites in a Web browser such as Firefox, Chrome, Konqueror etc. See my post How to install and use Tor for anonymous browsing or to access country-restricted content from another country for details of how to set up and use Tor with a Web browser.

But sometimes I need to access blocked Web sites from the command line. For example, today I needed to download a YouTube video for work purposes, and I wanted to use youtube-dl to do it. The solution was simple…

First I launched vidalia and polipo as explained in the above-mentioned post on Tor, then I launched another Konsole/Terminal window and entered the commands shown below:

$ # First find out what resolutions are available for the video I want to download:
$ youtube-dl -F https://www.youtube.com/watch?v=T3Rr4CUoTSQ
Setting language
T3Rr4CUoTSQ: Downloading webpage
T3Rr4CUoTSQ: Downloading video info webpage
T3Rr4CUoTSQ: Extracting video information
[info] Available formats for T3Rr4CUoTSQ:
format code extension resolution note
140 m4a audio only DASH audio , audio@128k (worst)
160 mp4 192p DASH video
133 mp4 240p DASH video
134 mp4 360p DASH video
135 mp4 480p DASH video
136 mp4 720p DASH video
17 3gp 176x144
36 3gp 320x240
5 flv 400x240
43 webm 640x360
18 mp4 640x360
22 mp4 1280x720 (best)
$ # Now try to download the video at the resolution I want:
$ youtube-dl -f 22 -o Clevo_W230ST_overview.flv https://www.youtube.com/watch?v=T3Rr4CUoTSQ
Setting language
T3Rr4CUoTSQ: Downloading webpage
T3Rr4CUoTSQ: Downloading video info webpage
T3Rr4CUoTSQ: Extracting video information
ERROR: unable to download video data: HTTP Error 403: Forbidden

As you can see above, the corporate Web filter blocked youtube-dl from downloading the video.

So I informed the shell session about the local HTTP proxy (polipo) running on my laptop, by assigning and exporting the environment variable http_proxy using the following syntax:

export http_proxy=http://server-ip:port/

which in my case meant the following (refer to my article on Tor):

$ export http_proxy=http://127.0.0.1:8123/

and then I was able to download the video from YouTube despite the corporate Web filter:

$ youtube-dl -f 22 -o Clevo_W230ST_overview.flv https://www.youtube.com/watch?v=T3Rr4CUoTSQ
Setting language
T3Rr4CUoTSQ: Downloading webpage
T3Rr4CUoTSQ: Downloading video info webpage
T3Rr4CUoTSQ: Extracting video information
[download] Destination: Clevo_W230ST_overview.flv
[download] 100% of 100.23MiB in 05:50
$

Useful Reference: How To Use Proxy Server To Access Internet at Shell Prompt With http_proxy Variable

KDE Connect – Link your Android device to your KDE desktop

KDE Connect app icon on my Samsung Galaxy Note II

KDE Connect app icon on my Samsung Galaxy Note II

KDE Connect is a nice tool that links your Android phone or tablet seamlessly via WiFi to KDE on your PC (the latter can be connected via WiFi or cable to the network). It allows your KDE desktop to receive notifications, files and media player commands from your Android device. The available KDE Connect plug-ins are:

Battery report
Periodically report battery status

Clipboard sync
Share the clipboard content

Multimedia remote controls
Control audio/video from your phone
(pause; first track; previous track; next track; last track; change volume)

Notification sync
Access your notification from other devices

Ping
Send and receive pings

Telephony notifier
Send notifications from SMS and calls

You will need to install the Android KDE Connect application on your Android device, and the Linux KDE Connect application on your PC.

Install the KDE Connect app on your Android device from the Google Play Store. You will then see the KDE Connect icon on the apps screen of your Android device.

For Gentoo users an ebuild for KDE Connect is available in the Gentoo KDE team’s testing overlay, so here are the instructions on how to install KDE Connect on your PC from there.

Firstly, mask the KDE overlay so that none of the packages in it interferes with the KDE software you installed from the main Portage tree:

# echo "*/*::kde" >> /etc/portage/package.mask

Then unmask the KDE Connect package in the KDE overlay:

# echo "kde-misc/kdeconnect" >> /etc/portage/package.unmask

N.B. If /etc/portage/package.mask is a directory rather than a file (either is possible) in your installation, and if /etc/portage/package.unmask is a directory rather than a file (either is possible) in your installation, use the following commands instead of the above two commands:

# echo "*/*::kde" > /etc/portage/package.mask/kde_overlay
# echo "kde-misc/kdeconnect" > /etc/portage/package.unmask/kdeconnect

Now add the KDE overlay and merge the package:

# layman -a kde
# emerge kdeconnect

If a firewall is running on your PC, you will need to configure it to allow tcp and udp traffic via a specific range of ports (1714 to 1764). I have UFW running on my main laptop, so in my case I used the following commands:

# ufw allow proto tcp to any port 1714:1764
# ufw allow proto udp to any port 1714:1764

The rules should look like this:

# ufw status verbose | grep 1714
1714:1764/tcp ALLOW IN Anywhere
1714:1764/udp ALLOW IN Anywhere
1714:1764/tcp ALLOW IN Anywhere (v6)
1714:1764/udp ALLOW IN Anywhere (v6)

If you have the KConfig Module kcm_ufw installed on your PC then you can instead use System Settings > Firewall to add the UFW rules via the KDE GUI.

By the way, to check which KConfig modules are installed on your PC you can use the following command under your user account:

$ kcmshell4 --list

Using KDE Connect is not difficult, so I will leave you to play with it. Obviously make sure WiFi is enabled on your Android device, and that it and your PC are connected to the same network. Tap on the KDE Connect icon on your Android device to launch the app, and you should see your PC’s name listed under CONNECTED DEVICES. Tap on the PC name and you should see the following screen:

KDE Connect screen

KDE Connect screen

If you tap on ‘Send ping’, the KDE Notification widget on the KDE System Tray should pop up a notification.

You can see what KDE Connect plug-ins are available, and select/deselect them:

KDE Connect plugins

KDE Connect plugins

KDE Connect also enables you to use your Android device as a remote control for media players running on your PC. When you launch a media player in KDE its name will appear in a list of selectable players in KDE Connect, and the name of the track currently playing will also be displayed:

KDE Connect - Remote control

KDE Connect - Remote control

When you select a file on your Android device and tap the Share icon, KDE Connect will be one of the options displayed on the ‘Share via’ menu. This is a handy way to send files from your Android device to your PC. The KDE Notification widget on your PC will notify you when the file has been transferred to ~/Desktop/ on your PC:

KDE on your PC notifies you when a file has been sent via KDE Connect

KDE on your PC notifies you a file has been sent via KDE Connect

You should also get notifications on your KDE desktop when someone phones or sends you an SMS.

Kudos and many thanks to the people responsible for KDE Connect. KDE is already a superb desktop environment, and with the addition of KDE Connect it is better still.

Fixing a problem with received video in Skype when using the AMD Catalyst (FGLRX) driver in Linux

Some users of Skype for Linux have reported that the bottom half of the received video image is corrupted in installations that use the closed-source video driver for ATI GPUs (the AMD Catalyst proprietary Linux driver, also known as the ‘FGLRX’ driver). One user described the lower half of the video image as “covered in small coloured squares like a chequer board”.

From what I have read in a few forums, it seems the problem does not occur when the open-source Radeon driver is used. My own experience corroborates that: I use the Radeon driver on one of my laptops, and received video in Skype is fine.

My main laptop has an AMD ATI Mobility Radeon HD 5650 GPU and I am using the Catalyst driver under Gentoo Linux. In this case there was a problem with received video in most Skype sessions. Either of the following effects usually occurred:

Snapshot 1 - Extract of received video image in Skype, showing an example of the corrupted image

Snapshot 1 - Extract of received video image in Skype, showing an example of the corrupted image

Snapshot 2 - Extract of received video image in Skype, showing another example of the corrupted image

Snapshot 2 - Extract of received video image in Skype, showing another example of the corrupted image

As shown in Snapshot 1, the lower half of the received video image was covered in a grid of thin green lines with areas tinged with purple, blue or green, whereas there was no grid of lines in the upper half of the image but some areas were tinged with red or blue.

As shown in Snapshot 2, the lower half of the received video image was covered in a grid of thin red lines, with a purple tinge in some areas, whereas there was no grid of lines in the upper half of the image, which looked reasonable but had some red-, green- or blue-tinged areas.

In all cases Skype’s thumbnail of my Webcam’s video image looked fine, and the person on the other end of the call said the video image received from me looked fine too.

Because of a bug in a previous version of the Catalyst driver a few years ago — see my blog posts Playing QuickTime videos in Firefox and Chromium + XVideo bug in AMD Catalyst 11.11 and 11.12 driver and AMD Catalyst for Linux driver 12.2 fixes the XVideo bug that crashed X.Org Server 1.11.x — I happen to know that Sykpe uses X11 overlays with the XVideo extension (xv), rather than using the OpenGL renderer (gl) or X11 with the SHM extension (x11). This made me wonder whether the use of XVideo with the Catalyst driver was causing the current problem. Unlike media players such as MPlayer and VLC, it is not possible to configure Skype to use gl or x11 instead of xv, so I thought it would not be possible to test whether the use of gl or x11 instead of xv would make a difference. Until, that is, I came upon a ‘trick’ posted by openSUSE user queequeg in 2009 during the period when an earlier version of the Catalyst driver had the aforementioned bug:

Skype Video Workaround for ATI

Anybody trying to make a video call with Skype and ATI fglrx drivers has had problems due to Skype using the “xv” video mode with the driver can’t handle. For anyone interested that is affected by this, there is a workaround:

1. Run the xvinfo command and look at the number of xv sessions available. Some cards have only 1, some have as many as 4. This is the number of xv occurances that the card can do at one time.
2. “Use up” all these xv sessions by opening videos in your favorite video player making sure to use xv for the video output. The videos can then be paused.
3. Once this (or they) are open, skype can be started and will default to X11 video and work properly with video calls.

I know this is a goofy way to get around this issue, but until fglrx can handle xv or skype allows an option to choose X11 for video render, I don’t know of any other way to do it.

(From what I hear, the 11.1 fglrx drivers can handle xv, but I haven’t confirmed this.)

So I tried his work-around. I had to launch four media players in order to use all available XVideo sessions. Lo and behold, when I launched Skype and made a video call the received video image was perfect. So it appeared that the Catalyst driver is not able to handle well the XVideo output from Skype. However, playing and pausing four videos every time I want to make a video call in Skype would hardly be practical, would it? And that is not the only downside: when I maximised a Firefox window during the Skype video call, my laptop spontaneously rebooted (I assume the X.Org server crashed).

I did also wonder whether just disabling compositing would solve the problem, so I disabled KWin Desktop Effects, but that didn’t make any difference.

I had also read in several forums that enabling or disabling the TexturedVideo and/or VideoOverlay options in the xorg.conf file have an effect on the video image produced by the Catalyst driver, but I could not find a post mentioning the use of either of those options to fix the specific problem I was seeing. So I decided not to pursue the xorg.conf route.

In my searches of the Web I came across a post somewhere that mentioned using GTK+ UVC Viewer (guvcview) to adjust video properties and improve video in Skype. I thought guvcview was only for adjusting the video image from a Webcam connected to my machine, i.e. adjusting the outgoing video image, and would not have any effect on received video. Nevertheless, I decided to install and launch guvcview to see if I could adjust both incoming and outgoing video properties. To my surprise, guvcview appeared to have fixed the problem with the received video. These are the steps I followed:

  1. I launched Skype and started a video call. The received video image had a grid of thin red lines and purple/green/blue tinting (similar to Snapshot 2).
  2. I Installed guvcview using the package manager.
  3. I launched guvcview in a Konsole (terminal) window. After guvcview created the file /home/fitzcarraldo/.config/guvcview/video0 and checked various video and audio settings it exited because my Webcam was being used by Skype (‘libv4l2: error setting pixformat: Device or resource busy‘).
  4. I clicked on the Webcam icon in the Skype call window, to turn my Webcam off.
  5. I launched guvcview again. The lower half of the received video image in Skype changed from a grid of thin red lines to a continuous green-coloured band, and the upper half of the image now looked reasonable but still had some red- or blue-tinged areas (see Snapshot 3 below).
  6. Snapshot 3 - Extract of received video image in Skype after I launched guvcview again

    Snapshot 3 - Extract of received video image in Skype after I launched guvcview again

  7. On the ‘Image Controls’ tab in the ‘GUVCViewer Controls’ window I changed the video frequency from 60 Hz to 50 Hz then back to 60 Hz again. I was just tinkering, and I believe this had no bearing on the outcome.
  8. I clicked on the ‘Quit’ button in the guvcview window to terminate the application.
  9. I clicked on the Webcam icon in the Skype call window to turn on again the Webcam, and the received Skype video image changed to a perfect image (see Snapshot 4 below).
  10. Snapshot 4 - Extract of received video image in Skype after I turned on again my Webcam in Skype

    Snapshot 4 - Extract of received video image in Skype after I turned on again my Webcam in Skype

It appears that guvcview had an effect on the received video image in Skype, although, if it did, I do not understand how. To check if the fix was permanent I ended the Skype video call, signed out of Skype and quit the application, rebooted and made a new Skype video call. The received video image in Skype was again perfect. I even deleted the guvcview configuration file and repeated this check, just in case the configuration file was somehow being used even though I had not launched guvcview, but the received video in yet another Skype video call was still perfect. I also clicked on the Webcam icon in the Skype call window several times during each call in order to turn my Webcam off and on several times; the received video image of the other person remained perfect.

So there you have it: when using an AMD ATI GPU and the Catalyst driver, it seems that guvcview can be used — at least in my case — to eliminate the type of image corruption in received Skype video shown in Snapshots 1 and 2. So, if you are also using the AMD Catalyst for Linux driver and are experiencing a similar problem, try guvcview. It might just do the trick.

‘Server not found’ by browser at launch

I haven’t had any significant Linux problems or new requirements in the last few months, hence no new posts here. My last real problem was back in June 2013 when I rolled my Gentoo installation to latest using Portage and found that, whenever I launched Firefox, it displayed the ‘Server not found’ page and I had to click ‘Try Again’, and then Firefox displayed the expected Web site. From then onwards, Firefox would work as expected until I exited the application. Thunderbird was also unable to access e-mail servers on the first attempt after it was launched. The same thing happened in Sabayon Linux when I rolled to latest using Entropy a couple of days later. Anyway, here is how I fixed the problem in both distributions.

First I used Wireshark to see what was going on, and it transpired that Gentoo (and Sabayon) was sending an IPv4 request followed quickly by an IPv6 request, but the reply to the IPv6 request was being received first and was a ‘server not found’ message since my ISP does not support IPv6 and my router apparently does not handle IPv6 requests correctly. Gentoo (and Sabayon) then used an IPv4 address when I clicked ‘Try Again’ in the browser window, and thereafter Firefox always dispayed the expected Web sites.

I should point out that IPv6 is enabled in the kernels I use and I’ve never before had to disable IPv6 in Firefox (or system-wide) on the affected laptops. So why the change in functionality, I wonder?

With Wireshark capturing packets, when I launched Firefox I was seeing a server failure message indicating “AAAA” (IPv6) instead of “A” (IPv4). To stop this happening I could have chosen any one of the three following solutions:

1. I could have used about:config in Firefox (and Config Editor in Thunderbird) to change the value of network.dns.disableIPv6 to true instead of false.

2. I could have disabled IPv6 system-wide by editing /etc/modprobe.d/aliases.conf and uncommenting the line “alias net-pf-10 off“.

3. I could have forced the getaddrinfo() function in glibc to make the IPv4 and IPv6 requests sequentially rather than in parallel.

Just for the fun of it I chose the third option on a couple of my laptops, and, as they use NetworkManager, this is how I did it:

fitzcarraldo@aspire5536 ~ $ su
Password:
aspire5536 fitzcarraldo # cat /etc/resolv.conf
# Generated by resolvconf
domain home
nameserver 192.168.1.254
aspire5536 fitzcarraldo # cd /etc/NetworkManager/dispatcher.d/
aspire5536 dispatcher.d # touch 06-dhclientoptions
aspire5536 dispatcher.d # nano 06-dhclientoptions
aspire5536 dispatcher.d # cat 06-dhclientoptions
#!/bin/bash
echo "options single-request" >> /etc/resolv.conf
aspire5536 dispatcher.d # chmod +x /etc/NetworkManager/dispatcher.d/06-dhclientoptions
aspire5536 dispatcher.d # # Now I disconnect then reconnect to the network
aspire5536 dispatcher.d # cat /etc/resolv.conf
# Generated by resolvconf
domain home
nameserver 192.168.1.254
options single-request
aspire5536 dispatcher.d #

As you can see above, I added a two-line Bash script 06-dhclientoptions in the directory /etc/NetworkManager/dispatcher.d/ that appends the line “options single-request” (without the quotes) to the contents of the file /etc/resolv.conf. The addition of the line “options single-request” in resolve.conf causes the getaddrinfo() function in glibc to make the IPv4 and IPv6 requests sequentially rather than in parallel. With this change, Firefox and Thunderbird no longer have a problem accessing the Internet the first time they are launched.

From “man 5 resolv.conf” under “options”:

single-request (since glibc 2.10)
sets RES_SNGLKUP in _res.options. By default, glibc performs IPv4 and IPv6 lookups in parallel since version 2.9. Some appliance DNS servers cannot handle these queries properly and make the requests time out. This option disables the behavior and makes glibc perform the IPv6 and IPv4 requests sequentially (at the cost of some slowdown of the resolving process).

single-request-reopen (since glibc 2.9)
The resolver uses the same socket for the A and AAAA requests. Some hardware mistakenly sends back only one reply. When that happens the client system will sit and wait for the second reply. Turning this option on changes this behavior so that if two requests from the same port are not handled correctly it will close the socket and open a new one before sending the second request.

I had to use NetworkManagerDispatcher to add the line “options single-request” to /etc/resolv.conf because NetworkManager overwrites /etc/resolv.conf if you edit it manually.

UPDATE (February 4, 2014): As I have recently seen the line “options single-request” occurring more than once in the file /etc/resolv.conf I now recommend /etc/NetworkManager/dispatcher.d/06-dhclientoptions consists of the following:

#!/bin/bash
if grep -q "options single-request" /etc/resolv.conf; then
    exit
else
    echo "options single-request" >> /etc/resolv.conf
fi

Dropbox revisited

In a previous post I explained how I installed Kfilebox, an unofficial KDE front-end for Dropbox. However, development of Kfilebox appears to have stopped, as the original author posted the following recently on a blog:

“I have stopped working on kfilebox after some updates in dropbox. Shortly: there is no way to get recent changed files, no more access to config options, cant configure it.”

Nevertheless I continued using Kfilebox. However, after a few days the Kfilebox icon stopped appearing in the KDE System Tray, and clicking on ‘Show hidden icons’ > ‘Kfilebox’ on the Panel displayed “The Dropbox daemon isn’t running” in the pop-up menu. Also, if I clicked on the hidden Kfilebox icon and selected ‘Preferences…’ the Dropbox folder field was empty and I had to keep re-entering the location of the Dropbox folder. So I decided to uninstall Kfilebox and try using Dropbox directly with KDE. I performed the steps listed below.

  1. Uninstall Kfilebox:

    # emerge -C kfilebox

  2. Remove any associated directories and files that might be left over:

    # rm -rf /home/fitzcarraldo/.dropbox
    # rm -rf /home/fitzcarraldo/.dropbox-dist
    # rm /home/fitzcarraldo/.kde4/share/config/kfileboxrc

  3. Install Dropbox:

    # emerge dropbox

  4. Do not edit /etc/conf.d/dropbox and do not configure Gentoo to launch the Dropbox daemon at start-up (i.e. do not add /etc/init.d/dropbox to the default runlevel). Instead configure KDE to launch the daemon when logging-in to KDE:
    1. Kickoff > System Settings > Startup and Shutdown
    2. Click on ‘Autostart’ in the left pane.
    3. Click on the ‘Add Script…’ button on the right side of the window.
    4. Enter the location of the Dropbox daemon in the box in the pop-up window. I entered “/opt/dropbox/dropboxd” (without the quotes) in the box and clicked ‘OK’.
  5. Run Dropbox for the first time and configure the local installation:
    1. Open a Dolphin window and browse to the directory containing the daemon (/opt/dropbox/) and double-click on dropboxd to launch the daemon.
    2. The Dropbox set-up window will pop-up and it should be obvious what to do from there onwards. As I already had a Dropbox account I selected ‘I already have a Dropbox account’ and clicked ‘Next’, I then entered my e-mail address, my Dropbox password and my computer’s name in the boxes and clicked ‘Next’. I left the default free 2 GB option selected and clicked ‘Next’. I left the default set-up ‘Typical’ selected and clicked ‘Install’. I read the introductory information displayed in the next couple of windows and clicked ‘Next’. I clicked ‘Finish’ in the final ‘That’s it!’ window.
  6. A Dropbox icon then appears in the System Tray on the Panel and synchronises with the Dropbox directory on the remote Dropbox server.

Now if I click on the Dropbox icon in the System Tray, the Dropbox directory window pops up. If I right-click on the icon in the System Tray, a menu pops-up with the expected Dropbox options.

So there was no need to use Kfilebox after all, as using the Dropbox daemon directly is just as user-friendly.

Installing Dropbox in Gentoo running KDE

kfilebox
I had never used Dropbox before and had no intention of doing so, but today a work colleague sent me some large files via Dropbox so I was forced to sign up. I tried to install Dropbox on my main laptop running Gentoo Linux and KDE but, for a well-known application, I had a surprising amount of trouble, hence this blog post.

To begin with, I found the following Dropbox-related packages:

# eix dropbox
* gnome-extra/nautilus-dropbox
Available versions: (~)0.6.9 (~)0.7.0 0.7.1 (~)1.4.0 {debug}
Homepage: http://www.dropbox.com/
Description: Store, Sync and Share Files Online
.
* net-misc/dropbox
Available versions: 1.2.48-r1^ms (~)1.2.51-r2^ms (~)1.4.3-r1^ms (~)1.4.7-r1^ms (~)1.4.7-r2^ms (~)1.4.17^ms (~)1.4.23^ms (~)1.6.16^ms {X +librsync-bundled}
Homepage: http://dropbox.com/
Description: Dropbox daemon (pretends to be GUI-less)
.
* net-misc/dropbox-cli
Available versions: 1 1-r1 {PYTHON_TARGETS="python2_6 python2_7"}
Homepage: http://www.dropbox.com/
Description: Cli interface for dropbox daemon (python)
.
* xfce-extra/thunar-dropbox [1]
Available versions: [m](~)0.2.0
Homepage: http://www.softwarebakery.com/maato/thunar-dropbox.html
Description: Plugin for Thunar that adds context-menu items for Dropbox
.
[1] "sabayon" /var/lib/layman/sabayon
.
Found 4 matches.

But I don’t have GNOME or Xfce installed on my main laptop, so the first and last packages were of no interest. A quick search on the Web turned up Kfilebox, which seemed to be exactly what I needed. I was pleased to find that the package is in the main Portage tree:

# eix kfilebox
* kde-misc/kfilebox
Available versions: (4) (~)0.4.8 (~)0.4.9
{LINGUAS="ar br cs de el es fr gl it lt nl pl pt ru si tr zh zh_CN"}
Homepage: http://kdropbox.deuteros.es/
Description: KDE dropbox client

So I installed kfilebox, dropbox and dropbox-cli, thinking I would need them all. Then, before doing anything else, I surfed to the Dropbox Web site and signed up for an account.

I launched Konsole and entered the command kfilebox. A window popped-up telling me that the Dropbox Daemon was being downloaded, then another window popped up offering me two options/buttons: ‘Run gtk based installer’ and ‘Or simply link account’. I clicked on the latter, thinking that was all I needed to do as I had already signed up for an account via the Dropbox Web site. But a Dropbox icon did not appear in the Panel, nor did Dolphin show a Dropbox folder icon in my home directory, and the KDE Notifications widget kept popping up notification after notification from Kfilebox to “Please visit url to link to this machine”. The trouble was that clicking on the apparent link in the notifications did nothing.

The directories .dropbox and .dropbox-dist existed in my home directory, and the contents of /home/fitzcarraldo/.kde4/share/config/kfileboxrc were as follows:

[General]
AutoStart=true
Browser=rekonq
DropboxDir=/home/fitzcarraldo/.dropbox-dist/
FileManager=dolphin
GtkUiDisabled=true
IconSet=default
ShowNotifications=true
StartDaemon=true

As the rekonq Web browser is not installed on this laptop, I edited the file and changed Browser=rekonq to Browser=firefox then rebooted, but it made no difference.

So I uninstalled everything:

# emerge -C kfilebox dropbox dropbox-cli
# rm -rf /home/fitzcarraldo/.dropbox
# rm -rf /home/fitzcarraldo/.dropbox-dist
# rm /home/fitzcarraldo/.kde4/share/config/kfileboxrc

then rebooted and reinstalled only Kfilebox:

# emerge kfilebox

I then launched Konsole and entered the command kfilebox. The pop-up window appeared notifying me that the Dropbox Daemon was being downloaded, followed by the pop-up window offering me the choice of running the gtk-based installer or simply linking the account. This time I chose the option to run the gtk-based installer and just followed the intuitive instructions in the various pop-up windows that followed, one of which offered to create a new Dropbox account or to link to an existing Dropbox account. As I wanted to do the latter I entered my e-mail address and Dropbox password, a Dropbox icon then appeared on the Panel and a Dropbox folder icon is now visible in Dolphin.

I checked the contents of ~/.kde4/share/config/kfileboxrc and they were the same as listed above, so I edited the file to replace rekonq with firefox, although I’m not sure yet what (if anything) that does, as Dropbox is new to me and I’m still learning. Anyway, the important thing is that I could now click on the ‘View folder’ button in an e-mail sent to me by a colleague and the files uploaded by my colleague were automatically downloaded into the ~/Dropbox directory.

EDIT May 30, 2013: Kfilebox is no longer in development and has started playing up. However, I found out how to install Dropbox directly and use it with KDE, and it’s just as user-friendly as Kfilebox. See my post Dropbox revisited for how to install Dropbox directly.

Setting the wireless regulatory domain in Linux on your laptop

I travel internationally and want to make sure that my laptop uses the legal wireless networking frequencies in the country I am visiting. In Linux, CRDA (Central Regulatory Domain Agent) is the udev helper used to communicate between userspace and the kernel, and it enables you to view and alter the wireless regulatory domain your kernel uses. For more information see the Regulatory page on the Linux Wireless Wiki site.

CFG80211 is the Linux wireless LAN (802.11) configuration API. The kernel on my main laptop has the following configuration settings relating to CFG80211:

# cat /usr/src/linux/.config | grep CFG80211
CONFIG_CFG80211=m
# CONFIG_CFG80211_DEVELOPER_WARNINGS is not set
# CONFIG_CFG80211_REG_DEBUG is not set
CONFIG_CFG80211_DEFAULT_PS=y
# CONFIG_CFG80211_DEBUGFS is not set
# CONFIG_CFG80211_INTERNAL_REGDB is not set
CONFIG_CFG80211_WEXT=y

and the cfg80211 module is loaded:

# lsmod | grep cfg80211
cfg80211 145747 3 iwlwifi,mac80211,iwldvm

I have the package crda installed, and I have the following udev rule file /etc/udev/rules.d/regulatory.rules to allow the kernel to communicate with userspace:

KERNEL=="regulatory*", ACTION=="change", SUBSYSTEM=="platform", RUN+="/sbin/crda"

So, how do you check which wireless regulatory domain your kernel is currently using, and switch to another domain if necessary? These tasks are performed using the iw command. You’ll need to install the package iw if it is not already installed.

To see the regulatory domain your laptop is using now, enter the following command as root user:

iw reg get

When I use the above command on my laptop after start-up, I normally see the following:

# iw reg get
country 00:
(2402 - 2472 @ 40), (3, 20)
(2457 - 2482 @ 20), (3, 20), PASSIVE-SCAN, NO-IBSS
(2474 - 2494 @ 20), (3, 20), NO-OFDM, PASSIVE-SCAN, NO-IBSS
(5170 - 5250 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS
(5735 - 5835 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

The country code 00 is not the code of the country I am in at present. To tell the kernel which wireless regulatory domain you wish to use, enter the following command as root user:

iw reg set ISO_3166-1_alpha-2

where ISO_3166-1_alpha-2 is the 2-character code for the country you are in. You can find the list of ISO 3166-1 alpha-2 codes on the Wikipedia page ISO 3166-1 alpha-2.

For example, if I were in the UK then I would enter the following command:

# iw reg set GB

and the regulatory domain would then be reported like this:

# iw reg get
country GB:
(2402 - 2482 @ 40), (N/A, 20)
(5170 - 5250 @ 40), (N/A, 20)
(5250 - 5330 @ 40), (N/A, 20), DFS
(5490 - 5710 @ 40), (N/A, 27), DFS

It is not a big deal to use the command line, but I wanted to make it even easier. I’m using KDE on my main laptop, so I created a Desktop Configuration File /home/fitzcarraldo/Desktop/Set_wireless_regulatory_domain containing the following:

[Desktop Entry]
Comment[en_GB]=
Comment=
Exec=/home/fitzcarraldo/iw_reg.sh
GenericName[en_GB]=Set wireless regulatory domain
GenericName=Set wireless regulatory domain
Icon=/home/fitzcarraldo/national-flags-icon.png
MimeType=
Name[en_GB]=Set_wireless_regulatory_domain
Name=Set_wireless_regulatory_domain
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=

and gave it the following file permissions:

# chmod 744 /home/fitzcarraldo/Desktop/Set_wireless_regulatory_domain
# ls -la /home/fitzcarraldo/Desktop/Set_wireless_regulatory_domain
-rwxr--r-- 1 fitzcarraldo users 496 Jan 15 21:53 /home/fitzcarraldo/Desktop/Set_wireless_regulatory_domain

I used a search engine to find a nice PNG icon consisting of several overlapping national flags, and saved it with the file name name national-flags-icon.png in my home directory.

I created a Bash shell script /home/fitzcarraldo/iw_reg.sh containing the following:

#!/bin/bash
echo "First you need to enter the password of your user account..."
sudo echo ""
echo "The ISO 3166-1 alpha-2 codes are listed on Web page https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2"
echo ""
echo "The current wireless regulatory domain is set as: "
echo ""
sudo iw reg get
echo ""
echo -n "Enter the ISO 3166-1 alpha-2 code (upper case) for the country you are in now, and press ENTER: "
read REGULATORYDOMAIN
sudo iw reg set $REGULATORYDOMAIN
echo ""
echo "The current wireless regulatory domain is now set as: "
echo ""
sudo iw reg get
echo ""
echo "All done. You can close this window."

and gave it the following file permissions:

# chmod 744 /home/fitzcarraldo/iw_reg.sh
# ls -la /home/fitzcarraldo/iw_reg.sh
-rwxr--r-- 1 fitzcarraldo users 632 Jan 15 21:33 /home/fitzcarraldo/iw_reg.sh

Now, if I double-click on the icon for Set_wireless_regulatory_domain on my desktop, a Konsole window pops up with a prompt for me to enter my user account password. When I enter my password the window displays the current wireless regulatory domain the kernel is using and prompts me to enter the 2-character code for the regulatory domain I wish to use instead. When I enter the country code the window displays the new regulatory domain, as shown in the sample below.


First you need to enter the password of your user account...
Password:

The ISO 3166-1 alpha-2 codes are listed on Web page https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

The current wireless regulatory domain is set as:

country SA:
(2402 - 2482 @ 40), (N/A, 20)
(5170 - 5250 @ 20), (3, 23)
(5250 - 5330 @ 20), (3, 23), DFS
(5735 - 5835 @ 20), (3, 30)

Enter the ISO 3166-1 alpha-2 code (upper case) for the country you are in now, and press ENTER: GB

The current wireless regulatory domain is now set as:

country GB:
(2402 - 2482 @ 40), (N/A, 20)
(5170 - 5250 @ 40), (N/A, 20)
(5250 - 5330 @ 40), (N/A, 20), DFS
(5490 - 5710 @ 40), (N/A, 27), DFS

All done. You can close this window.

The task of viewing and changing the regulatory domain after start-up is now very easy for me. The only thing that would be easier than this would be if Linux could detect automatically which country I’m in and set the regulatory domain automatically.

AirDroid, a handy Android app for managing your phone from Linux

AirDroid

In a previous article I explained how I installed and used the Windows application MyPhoneExplorer in WINE to manage the phone book (contacts list) in my HTC Desire mobile phone. Well, today I found out about AirDroid, a clever and useful Android application that can do the same thing, as well as the other tasks that MyPhoneExplorer can do, such as transfer files between my laptop and my phone, typing SMS on the laptop to send from the phone, and so on.

Last week I bought a Samsung Galaxy Note II and I needed to transfer a lot of large PDF files from my laptop to the new phone. Now, with my HTC Desire I could simply connect the phone to my laptop with a USB cable, mount the phone in KDE as a storage device, and drag the files across from one Dolphin file manager window to another. But the Samsung phone uses MTP for file transfers and, when the phone is connected to my laptop with a USB cable I can browse the phone’s file directories in Dolphin, but I cannot copy files from the laptop to the phone. Applications that use MTP for file transfer do exist for Windows and OS X (in fact Samsung provides Kies for this purpose), but my laptop runs Linux. I had not got around to installing the latest version (1.8.4) of MyPhoneExplorer to check if it works with the HTC Desire, let alone with a Samsung phone. So I searched the Web to see if there was a Linux application that uses MTP for general file transfer (i.e. not one of the dedicated music players in Linux that do support MTP for transferring music files only).

And that is how I learned about AirDroid, which allows you to “wirelessly manage your Android from your favourite browser.” The AirDroid Web site and the Android Play Store page for AirDroid explain the features of the application and both have a video showing it in operation.

From the AirDroid Web site:

What is AirDroid?

AirDroid is a fast, free app that lets you wirelessly manage & control your Android devices (phone & tablet) from a web browser. It’s designed with the vision to bridge the gap between your Android device and web browser, on desktop computers or tablet devices, on Windows, Mac/iOS, or Linux.

What can I do with AirDroid?

You can use AirDroid to send/receive SMS (text messages, if supported by the device), install/uninstall apps, transfer files between Android device and computer/tablet, and manage contacts, photos, music, videos, and ringtones, etc., all in a web browser. Install AirDroid on your Android device and open your favorite web browser to experience it yourself.

I immediately used Play Store on my phone to install AirDroid. I launched AirDroid, launched Firefox on my laptop and opened http://web.airdroid.com/, and was able to connect the laptop and phone quickly and easily. I block-selected the eighty files in the Dolphin window that I wanted to copy to the phone and dragged them to the phone’s Download directory window in the Firefox window. One by one the files were copied to the phone, with a little progress bar against each one. However, for some reason a few of the files were not copied so I dragged those across individually after the copying of the others had completed.

AirDroid in Firefox on my laptop

AirDroid in Firefox on my laptop

The above snapshot of my laptop’s screen shows the AirDroid desktop inside the maximised Firefox window. The window with the yellow folder icons inside it is actually an AirDroid window which I opened by clicking on the blue folder named ‘Files’ on the left side of the AirDroid desktop. These windows can be dragged around the AirDroid desktop in the browser window, and can even be resized.

A connection problem, and a solution

When I tried to connect the phone and laptop again later, an error message was displayed in the browser window on the laptop:

Failed to connect. Make sure your device is connected to a same WiFi network.

I was sure that the two devices were on the same WiFi network but, no matter what I tried, I could not get the laptop and phone to connect again. I looked through the AirDroid forums and found a thread indicating that this is a common problem.

Some users who posted in that thread were able to connect after they disabled the firewall on the PC, and others were able to connect by deleting the cookies in the browser. However, I think the fundamental cause of the problem is IPTables in Android Jelly Bean (see this comment). Anyway, taking all these factors into consideration, here is the way I got around the problem when it occurred:

On the laptop

1. Make sure the firewall is disabled.

As I use UFW on my laptop, all I need to do is:

# ufw disable

2. Launch Firefox and delete all cookies.

3. Open http://web.airdroid.com/

On the phone

1. Power down the phone, then power it up again.

2. Disable ‘Mobile data’ so that the phone cannot connect to the Internet via the mobile network, only via WiFi.

3. Enable WiFi.

4. Launch AirDroid.

From then on use AirDroid as usual, i.e. click on ‘Start’ and then either click on the camera icon and point the camera at the QR Code on the AirDroid page in the brower window or type the 6-character passcode displayed on the phone in the passcode box in the browser window and click ‘Login’.

That’s it!

AirDroid is a novel and useful application that now enables me to manage my Android phone from within Linux without needing to use WINE. Nice! :-)

(My thanks to Gentoo Forums user Q-collective in the thread [Workaround] Syncing Galaxy S3: What mediaplayer is capable? for mentioning AirDroid, otherwise I would never have known about it.)

EDIT November 5, 2012: I have used AirDroid on my home network and a public network, both using DHCP, not static IP addresses. I think AirDroid does not work if you use static IP addressing, so if you still run into trouble after following all the steps listed above, also check if you have a static IP address specified in the phone and router, and set them to use dynamic IP addressing instead.

EDIT November 26, 2012: Apparently some people — even those using static IP addresses — can get AirDroid working in their home network simply by rebooting their home router, so that’s something else you could try.

How to install the linux-firmware package in Gentoo

The microcode image (a.k.a. firmware) file for a driver can be installed from the distribution’s package manager. For example, in Gentoo the microcode package for the Intel Wireless WiFi 5100AGN, 5300AGN and 5350AGN controllers is named sys-firmware/iwl5000-ucode. However, microcode files are also available in a single package named sys-kernel/linux-firmware and can be installed using that package instead. However, to me at least, it was not obvious how to do this and the elog output when you merge the linux-firmware package is not particularly helpful:

* If you are only interested in particular firmware files, edit the saved
* configfile and remove those that you do not want.
>>> sys-kernel/linux-firmware-20120816 merged.

In other words, I used to enter the following command to install the microcode for the Intel 5300AGN WiFi controller:

emerge sys-firmware/iwl5000-ucode

and that command installed only the microcode files needed for that WiFi controller, but the following command also installed many other microcode files for hardware that my laptop does not have:

emerge sys-kernel/linux-firmware

You can see below what the above command installs in /lib/firmware/ (/lib64/firmware/ if you have a 64-bit installation) in the case of the package linux-firmware-20120816.

# ls /lib/firmware/
3com bnx2 emi26 iwlwifi-4965-2.ucode LICENCE.broadcom_bcm43xx matrox qlogic s2250_loader.fw usbdux
acenic bnx2x emi62 iwlwifi-5000-1.ucode LICENCE.chelsio_firmware mrvl r128 sb16 usbduxfast_firmware.bin
ACX100_USB.bin bnx2x-e1-4.8.53.0.fw ene-ub6250 iwlwifi-5000-2.ucode LICENCE.ene_firmware mts_cdma.fw radeon slicoss usbdux_firmware.bin
adaptec bnx2x-e1-5.2.13.0.fw ess iwlwifi-5000-5.ucode LICENCE.i2400m mts_edge.fw RADIO0d.BIN STLC2500_R4_00_03.ptc usbduxsigma_firmware.bin
advansys bnx2x-e1-5.2.7.0.fw f2255usb.bin iwlwifi-5150-2.ucode LICENCE.iwlwifi_firmware mts_gsm.fw RADIO11.BIN STLC2500_R4_00_06.ssf v4l-cx231xx-avcore-01.fw
af9005.fw bnx2x-e1h-4.8.53.0.fw GPL-3 iwlwifi-6000-4.ucode LICENCE.Marvell mts_mt9234mu.fw RADIO15.BIN STLC2500_R4_02_02_WLAN.ssf v4l-cx23418-apu.fw
agere_ap_fw.bin bnx2x-e1h-5.2.13.0.fw htc_7010.fw iwlwifi-6000g2a-5.ucode LICENCE.mwl8335 mts_mt9234zba.fw README STLC2500_R4_02_04.ptc v4l-cx23418-cpu.fw
agere_sta_fw.bin bnx2x-e1h-5.2.7.0.fw htc_9271.fw iwlwifi-6000g2a-6.ucode LICENCE.myri10ge_firmware mwl8k rt2561.bin sun v4l-cx23418-dig.fw
ar3k brcm i2400m-fw-usb-1.4.sbcf iwlwifi-6000g2b-5.ucode LICENCE.OLPC myri10ge_ethp_z8e.dat rt2561s.bin sxg v4l-cx23885-avcore-01.fw
ar7010_1_1.fw cis i2400m-fw-usb-1.5.sbcf iwlwifi-6000g2b-6.ucode LICENCE.phanfw myri10ge_eth_z8e.dat rt2661.bin TDA7706_OM_v2.5.1_boot.txt v4l-cx23885-enc.fw
ar7010.fw configure i6050-fw-usb-1.5.sbcf iwlwifi-6050-4.ucode LICENCE.qla2xxx myri10ge_rss_ethp_z8e.dat rt2860.bin TDA7706_OM_v3.0.2_boot.txt v4l-cx25840.fw
ar9170-1.fw cpia2 intelliport2.bin iwlwifi-6050-5.ucode LICENCE.ralink-firmware.txt myri10ge_rss_eth_z8e.dat rt2870.bin tehuti vicam
ar9170-2.fw cxgb3 isci kaweth LICENCE.rtlwifi_firmware.txt myricom rt3070.bin ti_3410.fw vntwusb.fw
ar9271.fw cxgb4 iwlwifi-1000-3.ucode keyspan LICENCE.tda7706-firmware.txt ositech rt3071.bin ti_5052.fw vxge
ath3k-1.fw dabusb iwlwifi-1000-5.ucode keyspan_pda LICENCE.ti-connectivity phanfw.bin rt3090.bin TIACX111.BIN WHENCE
ath6k dsp56k iwlwifi-100-5.ucode korg LICENCE.ueagle-atm4-firmware ql2100_fw.bin rt3290.bin ti-connectivity whiteheat.fw
atmsar11.fw dvb-fe-xc5000-1.6.114.fw iwlwifi-105-6.ucode lbtf_usb.bin LICENCE.via_vt6656 ql2200_fw.bin rt73.bin tigon whiteheat_loader.fw
av7110 dvb-usb-dib0700-1.20.fw iwlwifi-135-6.ucode lgs8g75.fw LICENCE.xc5000 ql2300_fw.bin RTL8192E tlg2300_firmware.bin WLANGEN.BIN
BCM2033-FW.bin dvb-usb-terratec-h5-drxk.fw iwlwifi-2000-6.ucode libertas LICENSE.dib0700 ql2322_fw.bin rtl_nic tr_smctr.bin yam
BCM2033-MD.hex e100 iwlwifi-2030-6.ucode LICENCE.agere LICENSE.radeon ql2400_fw.bin rtlwifi ttusb-budget yamaha
BCM-LEGAL.txt edgeport iwlwifi-3945-2.ucode LICENCE.atheros_firmware Makefile ql2500_fw.bin s2250.fw ueagle-atm zd1211

But I only need the files iwlwifi-5000-*.ucode, not all those other microcode files, so here is what I do:

# emerge linux-firmware
# cp /etc/portage/savedconfig/sys-kernel/linux-firmware-20120816 /home/fitzcarraldo/linux-firmware-20120816.bak
# awk '{ printf "#"; print }' /home/fitzcarraldo/linux-firmware-20120816.bak > /etc/portage/savedconfig/sys-kernel/linux-firmware-20120816
# nano /etc/portage/savedconfig/sys-kernel/linux-firmware-20120816 # Remove the comment symbol from the files I want to install.
# cp /etc/portage/savedconfig/sys-kernel/linux-firmware-20120816 /home/fitzcarraldo/linux-firmware-20120816 # I like to keep a backup of the edited file too.
# USE="savedconfig" emerge linux-firmware

Of course you can add the savedconfig USE flag in /etc/portage/package.use instead, so that you do not have to type USE=”savedconfig” every time:

# echo "sys-kernel/linux-firmware savedconfig" >> /etc/portage/package.use

For example, I edited /etc/portage/savedconfig/sys-kernel/linux-firmware-20120816 so that the lines are commented out for firmware my laptop does not need. I could have deleted the unwanted lines instead, but I preferred to comment out unwanted lines in case I made a mistake. The file now looks like this:

# Remove files that shall not be installed from this list.
#3com/typhoon.bin
#3com/3C359.bin
#acenic/tg1.bin
#acenic/tg2.bin
#adaptec/starfire_rx.bin
#adaptec/starfire_tx.bin
#advansys/3550.bin
#advansys/38C1600.bin
#advansys/38C0800.bin
#advansys/mcode.bin
#agere_ap_fw.bin
#agere_sta_fw.bin
#ar3k/ramps_0x01020201_26.dfu
#ar3k/ramps_0x01020200_40.dfu
#ar3k/AthrBT_0x11020000.dfu
#ar3k/1020201/RamPatch.txt
#ar3k/1020201/PS_ASIC.pst
#ar3k/1020200/RamPatch.txt
#ar3k/1020200/ar3kbdaddr.pst
#ar3k/1020200/PS_ASIC.pst
#ar3k/ramps_0x11020000_40.dfu
#ar3k/AthrBT_0x01020201.dfu
#ar3k/30101/RamPatch.txt
#ar3k/30101/ar3kbdaddr.pst
#ar3k/30101/PS_ASIC.pst
#ar3k/30000/RamPatch.txt
#ar3k/30000/ar3kbdaddr.pst
#ar3k/30000/PS_ASIC.pst
#ar3k/30101coex/PS_ASIC_aclHighPri.pst
#ar3k/30101coex/PS_ASIC_aclLowPri.pst
#ar3k/30101coex/RamPatch.txt
#ar3k/30101coex/ar3kbdaddr.pst
#ar3k/30101coex/PS_ASIC.pst
#ar3k/ramps_0x01020001_26.dfu
#ar3k/AthrBT_0x31010000.dfu
#ar3k/AthrBT_0x01020001.dfu
#ar3k/ramps_0x01020201_40.dfu
#ar3k/ramps_0x01020200_26.dfu
#ar3k/AthrBT_0x01020200.dfu
#ar3k/ramps_0x31010000_40.dfu
#ar7010_1_1.fw
#ar7010.fw
#ar9170-1.fw
#ar9170-2.fw
#ar9271.fw
#ath3k-1.fw
#ath6k/AR6002/athwlan.bin.z77
#ath6k/AR6002/eeprom.bin
#ath6k/AR6002/data.patch.hw2_0.bin
#ath6k/AR6002/eeprom.data
#ath6k/AR6004/hw1.2/bdata.bin
#ath6k/AR6004/hw1.2/fw-2.bin
#ath6k/AR6003.1/hw2.1.1/athwlan.bin
#ath6k/AR6003.1/hw2.1.1/bdata.SD31.bin
#ath6k/AR6003.1/hw2.1.1/data.patch.bin
#ath6k/AR6003.1/hw2.1.1/bdata.WB31.bin
#ath6k/AR6003.1/hw2.1.1/endpointping.bin
#ath6k/AR6003.1/hw2.1.1/otp.bin
#ath6k/AR6003.1/hw2.1.1/bdata.SD32.bin
#ath6k/AR6003/hw1.0/athwlan.bin.z77
#ath6k/AR6003/hw1.0/otp.bin.z77
#ath6k/AR6003/hw1.0/bdata.SD31.bin
#ath6k/AR6003/hw1.0/data.patch.bin
#ath6k/AR6003/hw1.0/bdata.WB31.bin
#ath6k/AR6003/hw1.0/bdata.SD32.bin
#ath6k/AR6003/hw2.0/athwlan.bin.z77
#ath6k/AR6003/hw2.0/otp.bin.z77
#ath6k/AR6003/hw2.0/bdata.SD31.bin
#ath6k/AR6003/hw2.0/data.patch.bin
#ath6k/AR6003/hw2.0/bdata.WB31.bin
#ath6k/AR6003/hw2.0/bdata.SD32.bin
#ath6k/AR6003/hw2.1.1/athwlan.bin
#ath6k/AR6003/hw2.1.1/bdata.SD31.bin
#ath6k/AR6003/hw2.1.1/fw-3.bin
#ath6k/AR6003/hw2.1.1/data.patch.bin
#ath6k/AR6003/hw2.1.1/bdata.WB31.bin
#ath6k/AR6003/hw2.1.1/endpointping.bin
#ath6k/AR6003/hw2.1.1/otp.bin
#ath6k/AR6003/hw2.1.1/fw-2.bin
#ath6k/AR6003/hw2.1.1/bdata.SD32.bin
#atmsar11.fw
#av7110/Boot.S
#av7110/bootcode.bin
#av7110/Makefile
#bnx2/bnx2-rv2p-06-6.0.15.fw
#bnx2/bnx2-rv2p-09-6.0.17.fw
#bnx2/bnx2-rv2p-06-4.6.16.fw
#bnx2/bnx2-rv2p-09-5.0.0.j3.fw
#bnx2/bnx2-rv2p-06-5.0.0.j3.fw
#bnx2/bnx2-mips-09-5.0.0.j15.fw
#bnx2/bnx2-rv2p-09-4.6.15.fw
#bnx2/bnx2-rv2p-09ax-6.0.17.fw
#bnx2/bnx2-mips-06-5.0.0.j3.fw
#bnx2/bnx2-mips-06-6.2.3.fw
#bnx2/bnx2-mips-09-5.0.0.j9.fw
#bnx2/bnx2-rv2p-09-5.0.0.j10.fw
#bnx2/bnx2-mips-09-6.2.1b.fw
#bnx2/bnx2-rv2p-09ax-5.0.0.j3.fw
#bnx2/bnx2-mips-06-6.0.15.fw
#bnx2/bnx2-mips-09-6.2.1.fw
#bnx2/bnx2-mips-09-5.0.0.j3.fw
#bnx2/bnx2-rv2p-09ax-5.0.0.j10.fw
#bnx2/bnx2-mips-06-5.0.0.j6.fw
#bnx2/bnx2-mips-06-4.6.16.fw
#bnx2/bnx2-mips-06-6.2.1.fw
#bnx2/bnx2-mips-09-6.2.1a.fw
#bnx2/bnx2-mips-09-4.6.17.fw
#bnx2/bnx2-mips-09-6.0.17.fw
#bnx2x/bnx2x-e1h-6.2.5.0.fw
#bnx2x/bnx2x-e1-7.2.16.0.fw
#bnx2x/bnx2x-e1h-6.2.9.0.fw
#bnx2x/bnx2x-e2-6.2.5.0.fw
#bnx2x/bnx2x-e2-6.0.34.0.fw
#bnx2x/bnx2x-e2-6.2.9.0.fw
#bnx2x/bnx2x-e1-7.0.23.0.fw
#bnx2x/bnx2x-e1-6.2.9.0.fw
#bnx2x/bnx2x-e1-7.2.51.0.fw
#bnx2x/bnx2x-e1h-7.0.23.0.fw
#bnx2x/bnx2x-e1h-6.0.34.0.fw
#bnx2x/bnx2x-e2-7.0.29.0.fw
#bnx2x/bnx2x-e1h-7.2.51.0.fw
#bnx2x/bnx2x-e1h-7.0.29.0.fw
#bnx2x/bnx2x-e1h-7.2.16.0.fw
#bnx2x/bnx2x-e1-6.2.5.0.fw
#bnx2x/bnx2x-e2-7.0.20.0.fw
#bnx2x/bnx2x-e1-6.0.34.0.fw
#bnx2x/bnx2x-e1-7.0.29.0.fw
#bnx2x/bnx2x-e2-7.2.51.0.fw
#bnx2x/bnx2x-e2-7.0.23.0.fw
#bnx2x/bnx2x-e2-7.2.16.0.fw
#bnx2x/bnx2x-e1h-7.0.20.0.fw
#bnx2x/bnx2x-e1-7.0.20.0.fw
#bnx2x-e1-4.8.53.0.fw
#bnx2x-e1-5.2.13.0.fw
#bnx2x-e1-5.2.7.0.fw
#bnx2x-e1h-4.8.53.0.fw
#bnx2x-e1h-5.2.13.0.fw
#bnx2x-e1h-5.2.7.0.fw
#brcm/bcm43xx-0.fw
#brcm/brcmfmac4329.bin
#brcm/brcmfmac43236b.bin
#brcm/brcmfmac4330.bin
#brcm/brcmfmac4334.bin
#brcm/bcm4329-fullmac-4.bin
#brcm/bcm43xx_hdr-0.fw
#cis/MT5634ZLX.cis
#cis/SW_555_SER.cis
#cis/COMpad2.cis
#cis/SW_7xx_SER.cis
#cis/NE2K.cis
#cis/src/MT5634ZLX.cis
#cis/src/COMpad2.cis
#cis/src/NE2K.cis
#cis/src/DP83903.cis
#cis/src/RS-COM-2P.cis
#cis/src/LA-PCM.cis
#cis/src/COMpad4.cis
#cis/src/PE-200.cis
#cis/src/tamarack.cis
#cis/src/3CCFEM556.cis
#cis/src/PCMLM28.cis
#cis/src/3CXEM556.cis
#cis/src/PE520.cis
#cis/DP83903.cis
#cis/RS-COM-2P.cis
#cis/LA-PCM.cis
#cis/SW_8xx_SER.cis
#cis/COMpad4.cis
#cis/PE-200.cis
#cis/tamarack.cis
#cis/3CCFEM556.cis
#cis/Makefile
#cis/PCMLM28.cis
#cis/3CXEM556.cis
#cis/PE520.cis
configure
#cpia2/stv0672_vp4.bin
#cxgb3/t3b_psram-1.1.0.bin
#cxgb3/ael2005_twx_edc.bin
#cxgb3/t3fw-7.4.0.bin
#cxgb3/t3fw-7.1.0.bin
#cxgb3/t3c_psram-1.1.0.bin
#cxgb3/t3fw-7.12.0.bin
#cxgb3/t3fw-7.10.0.bin
#cxgb3/ael2020_twx_edc.bin
#cxgb3/t3fw-7.0.0.bin
#cxgb3/ael2005_opt_edc.bin
#cxgb4/t4fw.bin
#cxgb4/t4fw-1.4.23.0.bin
#dabusb/bitstream.bin
#dabusb/firmware.fw
#dsp56k/bootstrap.bin
#dsp56k/concat-bootstrap.pl
#dsp56k/bootstrap.asm
#dsp56k/Makefile
#dvb-fe-xc5000-1.6.114.fw
#dvb-usb-dib0700-1.20.fw
#dvb-usb-terratec-h5-drxk.fw
#e100/d101m_ucode.bin
#e100/d102e_ucode.bin
#e100/d101s_ucode.bin
#edgeport/boot.fw
#edgeport/down.fw
#edgeport/down2.fw
#edgeport/down3.bin
#edgeport/boot2.fw
#emi26/bitstream.fw
#emi26/loader.fw
#emi26/firmware.fw
#emi62/bitstream.fw
#emi62/loader.fw
#emi62/spdif.fw
#emi62/midi.fw
#ene-ub6250/msp_rdwr.bin
#ene-ub6250/sd_init1.bin
#ene-ub6250/sd_init2.bin
#ene-ub6250/ms_init.bin
#ene-ub6250/ms_rdwr.bin
#ene-ub6250/sd_rdwr.bin
#ess/maestro3_assp_minisrc.fw
#ess/maestro3_assp_kernel.fw
#f2255usb.bin
GPL-3
#htc_7010.fw
#htc_9271.fw
#i2400m-fw-usb-1.4.sbcf
#i2400m-fw-usb-1.5.sbcf
#i6050-fw-usb-1.5.sbcf
#intelliport2.bin
#isci/create_fw.c
#isci/README
#isci/probe_roms.h
#isci/isci_firmware.bin
#isci/create_fw.h
#isci/Makefile
#iwlwifi-1000-3.ucode
#iwlwifi-1000-5.ucode
#iwlwifi-100-5.ucode
#iwlwifi-105-6.ucode
#iwlwifi-135-6.ucode
#iwlwifi-2000-6.ucode
#iwlwifi-2030-6.ucode
#iwlwifi-3945-2.ucode
#iwlwifi-4965-2.ucode
iwlwifi-5000-1.ucode
iwlwifi-5000-2.ucode
iwlwifi-5000-5.ucode
#iwlwifi-5150-2.ucode
#iwlwifi-6000-4.ucode
#iwlwifi-6000g2a-5.ucode
#iwlwifi-6000g2a-6.ucode
#iwlwifi-6000g2b-5.ucode
#iwlwifi-6000g2b-6.ucode
#iwlwifi-6050-4.ucode
#iwlwifi-6050-5.ucode
#kaweth/trigger_code_fix.bin
#kaweth/new_code.bin
#kaweth/new_code_fix.bin
#kaweth/trigger_code.bin
#keyspan/usa19qi.fw
#keyspan/usa28xb.fw
#keyspan/usa28x.fw
#keyspan/usa49wlc.fw
#keyspan/usa49w.fw
#keyspan/usa19w.fw
#keyspan/usa28xa.fw
#keyspan/usa28.fw
#keyspan/usa19qw.fw
#keyspan/mpr.fw
#keyspan/usa18x.fw
#keyspan/usa19.fw
#keyspan_pda/keyspan_pda.S
#keyspan_pda/xircom_pgs.S
#keyspan_pda/keyspan_pda.fw
#keyspan_pda/xircom_pgs.fw
#keyspan_pda/Makefile
#korg/k1212.dsp
#lbtf_usb.bin
#lgs8g75.fw
#libertas/gspi8682.bin
#libertas/sd8682_helper.bin
#libertas/gspi8688_helper.bin
#libertas/gspi8686_v9.bin
#libertas/cf8385_helper.bin
#libertas/usb8682.bin
#libertas/cf8381_helper.bin
#libertas/usb8388_v9.bin
#libertas/sd8686_v8.bin
#libertas/sd8385_helper.bin
#libertas/sd8686_v9.bin
#libertas/sd8686_v9_helper.bin
#libertas/cf8381.bin
#libertas/gspi8686_v9_helper.bin
#libertas/usb8388_v5.bin
#libertas/gspi8682_helper.bin
#libertas/lbtf_sdio.bin
#libertas/gspi8688.bin
#libertas/sd8385.bin
#libertas/sd8682.bin
#libertas/usb8388_olpc.bin
#libertas/sd8688.bin
#libertas/sd8688_helper.bin
#libertas/sd8686_v8_helper.bin
#libertas/cf8385.bin
#LICENCE.agere
#LICENCE.atheros_firmware
#LICENCE.broadcom_bcm43xx
#LICENCE.chelsio_firmware
#LICENCE.ene_firmware
#LICENCE.i2400m
LICENCE.iwlwifi_firmware
#LICENCE.Marvell
#LICENCE.mwl8335
#LICENCE.myri10ge_firmware
#LICENCE.OLPC
#LICENCE.phanfw
#LICENCE.qla2xxx
#LICENCE.ralink-firmware.txt
#LICENCE.rtlwifi_firmware.txt
#LICENCE.tda7706-firmware.txt
#LICENCE.ti-connectivity
#LICENCE.ueagle-atm4-firmware
#LICENCE.via_vt6656
#LICENCE.xc5000
#LICENSE.dib0700
LICENSE.radeon
Makefile
#matrox/g400_warp.fw
#matrox/g200_warp.fw
#mrvl/sd8787_uapsta.bin
#mts_cdma.fw
#mts_edge.fw
#mts_gsm.fw
#mts_mt9234mu.fw
#mts_mt9234zba.fw
#mwl8k/fmimage_8366.fw
#mwl8k/helper_8366.fw
#mwl8k/fmimage_8366_ap-2.fw
#mwl8k/fmimage_8366_ap-1.fw
#mwl8k/fmimage_8687.fw
#mwl8k/helper_8687.fw
#myri10ge_ethp_z8e.dat
#myri10ge_eth_z8e.dat
#myri10ge_rss_ethp_z8e.dat
#myri10ge_rss_eth_z8e.dat
#myricom/lanai.bin
#ositech/Xilinx7OD.bin
#phanfw.bin
#ql2100_fw.bin
#ql2200_fw.bin
#ql2300_fw.bin
#ql2322_fw.bin
#ql2400_fw.bin
#ql2500_fw.bin
#qlogic/12160.bin
#qlogic/isp1000.bin
#qlogic/sd7220.fw
#qlogic/1280.bin
#qlogic/1040.bin
#r128/r128_cce.bin
#radeon/R600_pfp.bin
#radeon/RV770_pfp.bin
#radeon/RS780_me.bin
#radeon/CEDAR_me.bin
#radeon/TURKS_me.bin
#radeon/R600_me.bin
#radeon/RS600_cp.bin
#radeon/SUMO_me.bin
#radeon/CAYMAN_pfp.bin
#radeon/CYPRESS_me.bin
#radeon/CAICOS_pfp.bin
#radeon/R520_cp.bin
#radeon/VERDE_ce.bin
#radeon/RV630_me.bin
#radeon/R700_rlc.bin
#radeon/RV610_pfp.bin
#radeon/JUNIPER_me.bin
#radeon/RV710_pfp.bin
#radeon/RS690_cp.bin
#radeon/CYPRESS_pfp.bin
#radeon/SUMO2_me.bin
#radeon/VERDE_mc.bin
#radeon/BARTS_mc.bin
#radeon/CAICOS_mc.bin
#radeon/ARUBA_pfp.bin
#radeon/RV635_pfp.bin
#radeon/R420_cp.bin
#radeon/R600_rlc.bin
#radeon/RV630_pfp.bin
#radeon/RV635_me.bin
#radeon/PITCAIRN_ce.bin
#radeon/RV730_pfp.bin
radeon/REDWOOD_me.bin
#radeon/PALM_me.bin
#radeon/BTC_rlc.bin
#radeon/BARTS_pfp.bin
#radeon/SUMO_rlc.bin
radeon/REDWOOD_rlc.bin
#radeon/JUNIPER_rlc.bin
#radeon/R100_cp.bin
#radeon/VERDE_pfp.bin
#radeon/RV610_me.bin
#radeon/TAHITI_mc.bin
#radeon/CAYMAN_mc.bin
#radeon/RS780_pfp.bin
#radeon/VERDE_rlc.bin
radeon/REDWOOD_pfp.bin
#radeon/TAHITI_pfp.bin
#radeon/RV670_me.bin
#radeon/RV770_me.bin
#radeon/RV730_me.bin
#radeon/PITCAIRN_mc.bin
#radeon/CEDAR_pfp.bin
#radeon/CAICOS_me.bin
#radeon/BARTS_me.bin
#radeon/CYPRESS_rlc.bin
#radeon/TAHITI_ce.bin
#radeon/CAYMAN_rlc.bin
#radeon/CAYMAN_me.bin
#radeon/ARUBA_rlc.bin
#radeon/PALM_pfp.bin
#radeon/ARUBA_me.bin
#radeon/RV710_me.bin
#radeon/RV620_pfp.bin
#radeon/VERDE_me.bin
#radeon/TAHITI_rlc.bin
#radeon/RV670_pfp.bin
#radeon/TURKS_mc.bin
#radeon/TURKS_pfp.bin
#radeon/TAHITI_me.bin
#radeon/PITCAIRN_me.bin
#radeon/RV620_me.bin
#radeon/PITCAIRN_pfp.bin
#radeon/JUNIPER_pfp.bin
#radeon/SUMO_pfp.bin
#radeon/R300_cp.bin
#radeon/PITCAIRN_rlc.bin
#radeon/R200_cp.bin
#radeon/CEDAR_rlc.bin
#radeon/SUMO2_pfp.bin
README
#rt2561.bin
#rt2561s.bin
#rt2661.bin
#rt2860.bin
#rt2870.bin
#rt3070.bin
#rt3071.bin
#rt3090.bin
#rt3290.bin
#rt73.bin
#RTL8192E/data.img
#RTL8192E/main.img
#RTL8192E/boot.img
#rtl_nic/rtl8105e-1.fw
#rtl_nic/rtl8168e-2.fw
#rtl_nic/rtl8168f-2.fw
#rtl_nic/rtl8168e-1.fw
#rtl_nic/rtl8411-1.fw
#rtl_nic/rtl8168d-2.fw
#rtl_nic/rtl8168g-1.fw
#rtl_nic/rtl8168f-1.fw
#rtl_nic/rtl8168e-3.fw
#rtl_nic/rtl8168d-1.fw
#rtl_nic/rtl8106e-1.fw
#rtl_nic/rtl8402-1.fw
#rtlwifi/rtl8192cufw.bin
#rtlwifi/rtl8192sefw.bin
#rtlwifi/rtl8192cfw.bin
#rtlwifi/rtl8192defw.bin
#rtlwifi/rtl8712u.bin
#rtlwifi/rtl8192cfwU_B.bin
#rtlwifi/rtl8192cfwU.bin
#s2250.fw
#s2250_loader.fw
#sb16/ima_adpcm_capture.csp
#sb16/alaw_main.csp
#sb16/ima_adpcm_init.csp
#sb16/ima_adpcm_playback.csp
#sb16/mulaw_main.csp
#slicoss/oasisdbgdownload.sys
#slicoss/gbrcvucode.sys
#slicoss/oasisdownload.sys
#slicoss/oasisrcvucode.sys
#slicoss/gbdownload.sys
#sun/cassini.bin
#sxg/saharadbgdownloadB.sys
#sxg/saharadownloadB.sys
#TDA7706_OM_v2.5.1_boot.txt
#TDA7706_OM_v3.0.2_boot.txt
#tehuti/bdx.bin
#ti_3410.fw
#ti_5052.fw
#ti-connectivity/wl128x-fw-ap.bin
#ti-connectivity/wl1271-fw-ap.bin
#ti-connectivity/wl128x-fw-4-mr.bin
#ti-connectivity/wl128x-fw-4-sr.bin
#ti-connectivity/wl127x-fw-5-sr.bin
#ti-connectivity/wl128x-nvs.bin
#ti-connectivity/wl127x-fw-3.bin
#ti-connectivity/wl1271-nvs.bin
#ti-connectivity/wl127x-fw-5-plt.bin
#ti-connectivity/wl1271-fw-2.bin
#ti-connectivity/wl1271-fw.bin
#ti-connectivity/wl128x-fw-5-sr.bin
#ti-connectivity/wl128x-fw.bin
#ti-connectivity/wl127x-fw-plt-3.bin
#ti-connectivity/wl127x-nvs.bin
#ti-connectivity/wl12xx-nvs.bin
#ti-connectivity/wl128x-fw-4-plt.bin
#ti-connectivity/wl128x-fw-5-plt.bin
#ti-connectivity/wl127x-fw-4-plt.bin
#ti-connectivity/wl127x-fw-5-mr.bin
#ti-connectivity/wl128x-fw-3.bin
#ti-connectivity/TIInit_7.2.31.bts
#ti-connectivity/wl128x-fw-5-mr.bin
#ti-connectivity/wl127x-fw-4-mr.bin
#ti-connectivity/wl128x-fw-plt-3.bin
#ti-connectivity/wl18xx-fw.bin
#ti-connectivity/wl127x-fw-4-sr.bin
#tigon/tg3_tso5.bin
#tigon/tg3.bin
#tigon/tg3_tso.bin
#tlg2300_firmware.bin
#tr_smctr.bin
#ttusb-budget/dspbootcode.bin
#ueagle-atm/eagleIII.fw
#ueagle-atm/CMVep.bin
#ueagle-atm/DSPei.bin
#ueagle-atm/CMVepFR04.bin
#ueagle-atm/eagleI.fw
#ueagle-atm/930-fpga.bin
#ueagle-atm/CMV4p.bin.v2
#ueagle-atm/CMV9p.bin
#ueagle-atm/CMVepES03.bin
#ueagle-atm/CMVepIT.bin
#ueagle-atm/eagleII.fw
#ueagle-atm/CMVepFR.bin
#ueagle-atm/eagleIV.fw
#ueagle-atm/CMVepWO.bin
#ueagle-atm/CMVepFR10.bin
#ueagle-atm/CMVepES.bin
#ueagle-atm/CMVeiWO.bin
#ueagle-atm/CMVei.bin
#ueagle-atm/adi930.fw
#ueagle-atm/CMV9i.bin
#ueagle-atm/DSPep.bin
#ueagle-atm/DSP4p.bin
#ueagle-atm/DSP9i.bin
#ueagle-atm/DSP9p.bin
#usbdux/fx2-include.asm
#usbdux/Makefile_dux
#usbdux/usbduxsigma_firmware.asm
#usbdux/README.dux
#usbdux/usbduxfast_firmware.asm
#usbdux/usbdux_firmware.asm
#usbduxfast_firmware.bin
#usbdux_firmware.bin
#usbduxsigma_firmware.bin
#v4l-cx231xx-avcore-01.fw
#v4l-cx23418-apu.fw
#v4l-cx23418-cpu.fw
#v4l-cx23418-dig.fw
#v4l-cx23885-avcore-01.fw
#v4l-cx23885-enc.fw
#v4l-cx25840.fw
#vicam/firmware.fw
#vntwusb.fw
#vxge/X3fw.ncf
#vxge/X3fw-pxe.ncf
WHENCE
#whiteheat.fw
#whiteheat_loader.fw
#yam/9600.bin
#yam/1200.bin
#yamaha/yss225_registers.bin
#yamaha/ds1_ctrl.fw
#yamaha/ds1_dsp.fw
#yamaha/ds1e_ctrl.fw

and the resulting files in /lib64/firmware/ after re-merging linux-firmware are now:

# ls /lib/firmware/
ACX100_USB.bin BCM2033-FW.bin BCM-LEGAL.txt GPL-3 iwlwifi-5000-2.ucode LICENCE.iwlwifi_firmware Makefile RADIO0d.BIN RADIO15.BIN STLC2500_R4_00_03.ptc STLC2500_R4_02_02_WLAN.ssf TIACX111.BIN WLANGEN.BIN
af9005.fw BCM2033-MD.hex configure iwlwifi-5000-1.ucode iwlwifi-5000-5.ucode LICENSE.radeon radeon RADIO11.BIN README STLC2500_R4_00_06.ssf STLC2500_R4_02_04.ptc WHENCE zd1211
# ls /lib/firmware/radeon
REDWOOD_me.bin REDWOOD_pfp.bin REDWOOD_rlc.bin

Compare that with the contents of /lib/firmware/ I listed earlier. Much tidier, isn’t it? I’ve saved quite a bit of wasted disk space.

I hope this post is helpful to others, as I searched unsucessfully for instructions on how to install the linux-firmware package so that only the necessary firmware files are installed. Don’t worry though: you could simply go ahead and install linux-firmware without editing the file in /etc/portage/savedconfig/sys-kernel/ if you don’t mind having unecessary files in /lib/firmware/ in addition to the firmware files you need.

Synchronise your Gentoo Linux clock with an Internet time server

There are a number of ways to synchronise Gentoo Linux with a time server on the Internet. Here I look at a few alternatives.

ntp-client

ntp-client and the NTP daemon ntpd are installed when you install the package net-misc/ntp. Although I have read on some Web sites that /etc/init.d/ntp-client should be added to the default runlevel in order to read the time from an NTP server (once-only, during start-up), this in fact does not work because usually the network connection is not up by the time the ntp-client initscript runs. Bear in mind that ntp-client does not run continuously; it syncs once with an external time server if there is a network connection, and that’s it.

NetworkManager Dispatcher

If you are using NetworkManager, an elegant solution is to use NetworkManagerDispatcher to restart ntp-client in order to resync your system clock every time a network connection comes up. This is my favoured solution for laptops; see further on for how to configure your machine to do this.

cronjob

Another way would be to create a cronjob to run periodically the ‘/etc/init.d/ntp-client restart‘ command or the ‘ntpd -q‘ command (the -q option means “set the time and quit”).

Wait a while after start up

A ‘quick-and-dirty’ method, which I have used sometimes to synchronise a laptop’s system clock every time it boots, would be to delay running ntp-client until the network is up by putting e.g. the command below in a file 10_ntp-client.start in the directory /etc/local.d/ (10 seconds is usually enough time for a wired or wireless connection to my home network to be established):

#!/bin/bash
sleep 10s && /etc/init.d/ntp-client restart

Don’t forget to make it executable:

# chmod 744 /etc/local.d/10_ntp-client.start

NTP daemon

Regarding the NTP daemon, it is possible to configure this from the command line, rather than via a Desktop Environment GUI, to run at start-up and continue running to adjust your system clock. The command:

# rc-update add ntpd default

will add the daemon’s initscript to the default runlevel so that it is launched automatically at the next startup, and the command:

# /etc/init.d/ntpd start

will start the daemon running right now.

Note that, by default, the NTP daemon won’t correct, all in one go, a time difference between your system clock and the remote NTP server if that difference is above a certain size. However, if you want to override the default behaviour, i.e. allow the NTP daemon to make a large first adjustment to the system clock, you can set the environment variable NTPD_OPTS in the file /etc/conf.d/ntpd as follows:

NTPD_OPTS="-g"
# The -g option enables ntpd to make large adjustments.

This would mean that you would not need to run ntp-client before ntpd. However, if you run ntp-client automatically — either once after start-up or periodically — then that would be good enough for the typical Desktop user, and could be an alternative to having a continuously-running NTP daemon. Nothing stops you doing both if you want, of course.

Updating the hardware clock

If you make clock_systohc="YES" in the file /etc/conf.d/hwclock then the time in the system clock will be written to the BIOS (CMOS) clock (a.k.a. hardware clock) when you shut down your PC.

How to configure NetworkManager Dispatcher to synchronise the system clock only when a network connection is made

If you’re using a machine that is permanently connected to a network, running the NTP daemon makes sense. But what if you have a machine that is not always connected to a network when it is powered up? I have a laptop and I don’t want the NTP daemon running all the time. But I would like my laptop to synchronise with an external time server once after start up when I connect to the Internet. NetworkManager has a handy tool called NetworkManager Dispatcher for doing just this.

If you have installed NetworkManager, you’ll find there is an initscript /usr/portage/net-misc/networkmanager/files/NetworkManagerDispatcher. Copy it to the directory /etc/init.d/ and give it the necessary restrictive permissions:

# cp /usr/portage/net-misc/networkmanager/files/NetworkManagerDispatcher /etc/init.d/
# chmod 744 NetworkManagerDispatcher

Then create a shell script called e.g. 99_ntp-client in the directory /etc/NetworkManager/dispatcher.d/ to be run by NetworkManagerDispatcher when a network connection is established, containing the following code:

#!/bin/bash

INTERFACE=$1 # The interface which is brought up or down
STATUS=$2 # The new state of the interface

case "$STATUS" in
    'up') # $INTERFACE is up
        echo "System time before starting ntp-client:" > /home/fitzcarraldo/ntp-client.txt
        date >> /home/fitzcarraldo/ntp-client.txt
        echo "Starting ntp-client:" >> /home/fitzcarraldo/ntp-client.txt
        rc-config restart ntp-client &>> /home/fitzcarraldo/ntp-client.txt
        echo "System time after starting ntp-client:" >> /home/fitzcarraldo/ntp-client.txt
        date >> /home/fitzcarraldo/ntp-client.txt
        ;;
    'down') # $INTERFACE is down
        # Check for active interface and down if no one active
        if [ ! `nm-tool|grep State|cut -f2 -d' '` = "connected" ]; then
                echo "Stopping ntp-client at:" > /home/fitzcarraldo/ntp-client.txt
                date >> /home/fitzcarraldo/ntp-client.txt
                rc-config stop ntp-client &>> /home/fitzcarraldo/ntp-client.txt
        fi
        ;;
esac

Make the root user the owner of the script, and only allow the root user to write to it and execute it:

# cd /etc/NetworkManager/dispatcher.d/
# chown root:root 99_ntp-client
# chmod 744 99_ntp-client

Then add NetworkManagerDispatcher to the default runlevel so that it will be launched every time you boot your machine:

# rc-update add NetworkManagerDispatcher default

As the package net-misc/ntp installs both /etc/init.d/ntpd and /etc/init.d/net-client, users could optionally add the NTP daemon ntpd to the default runlevel too if desired, which would provide continuous, incremental adjustments to the system clock once net-client has done its one-shot adjustment each time a network comes up:

# rc-update add ntpd default

But users who don’t leave their PCs on for days on end — or who use laptops — can ignore the above step and just stick with the NetworkManagerDispatcher and net-client solution, whereas users who leave their machines on for days or weeks on end can also use the NTP daemon to keep the system clock in sync in between the times when ntp-client has synchronised.

Don’t forget to delete ntp-client from the start-up level if you are using NetworkManagerDispatcher to run it:

# rc-update del ntp-client

Notice that the script /etc/NetworkManager/dispatcher.d/99_ntp-client logs some information in a text file ntp-client.txt in my home directory which I can check. Here is an example of what ntp-client.txt contains after I select a network (or it is selected automatically) following start up of my laptop:

System time before starting ntp-client:
Sun Jun 3 19:24:08 BST 2012
Starting ntp-client:
Restarting init script
* Setting clock via the NTP client 'ntpd' ...ntpd: time slew +0.067178s
[ ok ]
System time after starting ntp-client:
Sun Jun 3 19:24:17 BST 2012

As you can see above, the ntpd command was executed once by NetworkManagerDispatcher and made a small adjustment to the system time on my laptop.

Replacing ntpdate with ntpd in ntp-client

Just for the fun of it, I changed /etc/conf.d/ntp-client to use the command ntpd instead of ntpdate, even though the ntpdate command works fine. Anyway, here’s my /etc/conf.d/ntp-client file these days:

NTPCLIENT_CMD="ntpd"
NTPCLIENT_OPTS="-g -q"

I have added the -g option so that the ntpd command can make large adjustments to the system time if it is way off the actual time. This is useful at the beginning and end of Daylight Saving Time, or if you dual boot with Windows. Here is an example of the former when I powered up my laptop the morning after the clocks changed from BST to GMT at the end of Summer 2010:

$ cat /home/fitzcarraldo/ntp-client.txt
System time before starting ntp-client:
Sun Oct 31 09:37:23 GMT 2010
Starting ntp-client:
Starting init script
* Setting clock via the NTP client 'ntpd'...ntpd: time set -3600.122381s
[ ok ]
System time after starting ntp-client:
Sun Oct 31 08:37:30 GMT 2010

You can specify the NTP server or NTP server pool in the file /etc/ntp.conf, but the default server pool already specified in that file should work. Note again that, when ntpd is run with the -q option, it synchronises the system clock once and terminates, i.e. it is not running as a daemon.

Follow

Get every new post delivered to your Inbox.

Join 43 other followers