Elogviewer: A handy GUI for viewing Portage elog messages in Gentoo Linux

When merging (installing) packages in Gentoo, ebuilds often output console messages with information or warnings from the writer of the ebuild, usually at the end of the installation process. However, these ‘elog’ messages will not be displayed if you have configured the environment variable EMERGE_DEFAULT_OPTS so as to merge packages quietly or in parallel. Even if you did not configure EMERGE_DEFAULT_OPTS that way, it is easy to miss these messages as they scroll up and off screen if several packages are merging, one after the other.

The Gentoo package manager Portage has a logging facility that, if enabled, will log these elog messages to files so that you can review them afterwards. You can enable this facility by editing the file /etc/portage/make.conf and adding the environment variable PORTAGE_ELOG_SYSTEM="save" and the environment variable PORTAGE_ELOG_CLASSES with one or more logging classes. Here are the relevant lines from the file /etc/portage/make.conf on my laptop:

PORTAGE_ELOG_CLASSES="info warn error log qa"

For example, after merging the package www-misc/bluegriffon-bin-1.8 at 06:01:00 on 14 April 2016, I am able to examine the contents of the log file for that specific job:

$ cat /var/log/portage/elog/www-misc:bluegriffon-bin-1.8:20160414-060100.log
INFO: setup
Package: www-misc/bluegriffon-bin-1.8
Repository: local_overlay
USE: abi_x86_64 amd64 elibc_glibc kernel_linux userland_GNU
FEATURES: preserve-libs sandbox userpriv usersandbox
LOG: install
If you use BlueGriffon in KDE, use System Settings > Common Appearance and Behaviour > Application Appearance > GTK
and select any GTK theme other than Oyxgen, otherwise BlueGriffon will crash when you click on any pull-down menu.
QA: other
QA Notice: Pre-stripped files found:

Of particular interest is the elog message:

If you use BlueGriffon in KDE, use System Settings > Common Appearance and Behaviour > Application Appearance > GTK
and select any GTK theme other than Oyxgen, otherwise BlueGriffon will crash when you click on any pull-down menu.

Clearly, some of the elog messages are important and must not be missed. After reading such messages, users can take appropriate action.

To facilitate reading Portage elog files, there is a GUI utility called Elogviewer which is easy to install and use:

# emerge elogviewer

$ elogviewer --help
usage: elogviewer [-h] [-p ELOGPATH] [--log {DEBUG,INFO,WARNING,ERROR}]

Elogviewer should help you not to miss important information. You need to
enable the elog feature by setting at least one of PORTAGE_ELOG_CLASSES="info
warn error log qa" and PORTAGE_ELOG_SYSTEM="save" in /etc/make.conf. You need
to add yourself to the portage group to use elogviewer without privileges.
Read /etc/make.conf.example for more information.

optional arguments:
  -h, --help            show this help message and exit
  -p ELOGPATH, --elogpath ELOGPATH
                        path to the elog directory
                        set logging level

I happen to have configured EMERGE_DEFAULT_OPTS="--jobs=8 --load-average=8" (i.e. perform installation jobs in parallel using all eight cores of the CPU) in my /etc/portage/make.conf file, so I don’t see elog messages on screen, and therefore Elogviewer comes in handy. The output in the Konsole window looks like the following when I merge a package:

# emerge -v bluegriffon-bin

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ~] www-misc/bluegriffon-bin-1.8::local_overlay  0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

>>> Verifying ebuild manifests
>>> Emerging (1 of 1) www-misc/bluegriffon-bin-1.8::local_overlay
>>> Installing (1 of 1) www-misc/bluegriffon-bin-1.8::local_overlay
>>> Jobs: 1 of 1 complete                           Load avg: 0.11, 0.07, 0.13
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * GNU info directory index is up-to-date.

Notice that the important elog message regarding switching the GTK theme in KDE that is included in the log file was not displayed on the console during installation of the package, because of my setting for EMERGE_DEFAULT_OPTS.

If I then launch Elogviewer, either from the command line or using the KDE launcher, a window pops up as shown below. I can then view a list of recently merged packages and click on each to read the elog output easily. Whether installing only one package or many packages in one session, this makes life easier.


Elogviewer window

Automatically detecting files placed in my Downloads directory in Gentoo Linux and scanning them for viruses

I have been using Linux for almost a decade and have never been unduly concerned about viruses on my machines running Linux. However, I do receive files from people who use Windows and Mac OS, and some of those files might contain Windows or Mac OS viruses, so, as a matter of courtesy and assistance to others, it would make some sense to scan those files before passing them on. Furthermore, as I use some Windows applications under WINE, it would also make sense to scan received files for Windows viruses if I am going to use those files with a Windows application running under WINE.

External files could get into my Gentoo Linux installations via pen drives, memory cards, optical discs, e-mails, my Dropbox directory and downloads from Web sites. In this post I am going to concentrate on the last of these. All the various e-mail account providers I use already scan e-mails for viruses on their e-mail servers before I even download e-mail into the e-mail client on my laptop (standard practice these days), so e-mail is not a particular worry.

I have had ClamAV and its GUI, ClamTk, installed for a long time. Whilst ClamTk can be used to schedule a daily update of virus signatures and a daily scan of one’s home directory by ClamAV, I normally run ClamTk and ClamAV ad hoc. However, I can see some benefit in launching ClamAV automatically when I download a file from the Internet, so I decided to do the following …

Automatically scan a file downloaded via a Web browser

I use Firefox to browse the Web, and had configured it to download files to the directory /home/fitzcarraldo/Downloads/. I decided to monitor automatically the Downloads directory for the addition of any file. As I use the ext4 file system, the method I opted to use is inotify, specifically the inotifywait command which is available once you install the package sys-fs/inotify-tools.

It is surprisingly easy to create a shell script to detect files downloaded into a directory. The following script, running continuously in a terminal, would detect any files created in my /home/fitzcarraldo/Downloads directory, scan the new files with ClamAV and display a report in the terminal window:



inotifywait -q -m -e create --format '%w%f' $DIR | while read FILE
     echo "File $FILE has been detected. Scanning it for viruses now ..."
     clamscan $FILE

A usable script would need to be a bit more sophisticated than the one shown above, because an existing file in the directory could be overwritten by one with the same name, or opened and amended. Furthermore, the script above would need a permanently open terminal window. Therefore I created a script to run in the background and use a GUI dialogue tool to pop up a window with the virus scanner’s report when the script detects a new or changed file in the Downloads directory. As this laptop has KDE 4 installed I opted to use KDialog to display the pop-up window, but I could instead have used Zenity. The final script is shown below.



# Get rid of old log file
rm $HOME/virus-scan.log 2> /dev/null

inotifywait -q -m -e close_write,moved_to --format '%w%f' $DIR | while read FILE
     # Have to check file length is nonzero otherwise commands may be repeated
     if [ -s $FILE ]; then
          date > $HOME/virus-scan.log
          clamscan $FILE >> $HOME/virus-scan.log
          kdialog --title "Virus scan of $FILE" --msgbox "$(cat $HOME/virus-scan.log)"

Now when I download a file in Firefox, a window pops up, displaying a message similar to the following:

Virus scan of /home/fitzcarraldo/Downloads/eicar_com.zip – KDialog

Fri 19 Feb 23:42:02 GMT 2016
/home/fitzcarraldo/Downloads/eicar_com.zip: Eicar-Test-Signature FOUND

———– SCAN SUMMARY ———–
Known viruses: 4259980
Engine version: 0.98.7
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 4.595 sec (0 m 4 s)

Notice in the above message that ClamAV detected a virus in a file eicar_com.zip that I downloaded from the European Expert Group for IT Security Web site (originally ‘European Institute for Computer Antivirus Research’). In fact the executable eicar.com does not contain a real virus; it was designed to contain a known signature that virus scanner creators and users can use in checking anti-virus software. You can find out more about the virus test files on the EICAR Web site.

Of course, if I use applications other than Firefox to download files, I need to make sure they download the files into the applicable directory so that the script can detect and scan the files:

fitzcarraldo@clevow230ss ~ $ cd Downloads/
fitzcarraldo@clevow230ss ~/Downloads $ youtube-dl -o Carnavalito.mp4 -f 18 https://www.youtube.com/watch?v=ZDUL3w7zFD4
ZDUL3w7zFD4: Downloading webpage
ZDUL3w7zFD4: Downloading video info webpage
ZDUL3w7zFD4: Extracting video information
ZDUL3w7zFD4: Downloading MPD manifest
[download] Destination: Carnavalito.mp4
[download] 100% of 16.61MiB in 00:05

So, now I have a shell script that pops up a window informing me whether or not any file I put in $HOME/Downloads/ contains a virus. But I would like the script to be launched automatically when I login to the Desktop Environment. Therefore, as I use KDE 4, I selected ‘System Settings’ > ‘Startup and Shutdown’ and, in the ‘Autostart’ pane, clicked on ‘Add Script…’ and entered the path to my shell script (I left ‘create as symlink’ ticked). Now, every time I use KDE, any file placed (automatically or manually) into $HOME/Downloads/ is scanned for viruses automatically and a window pops up giving the result.

As my laptop is not always connected to the Internet, I prefer to update the ClamAV virus signatures database manually, which I do either using the ClamTk GUI or via the command line using the freshclam command:

fitzcarraldo@clevow230ss ~ $ su
clevow230ss fitzcarraldo # freshclam
ClamAV update process started at Sat Feb 20 10:51:01 2016
WARNING: Your ClamAV installation is OUTDATED!
WARNING: Local version: 0.98.7 Recommended version: 0.99
DON'T PANIC! Read http://www.clamav.net/support/faq
main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
Downloading daily-21375.cdiff [100%]
Downloading daily-21376.cdiff [100%]
Downloading daily-21377.cdiff [100%]
Downloading daily-21378.cdiff [100%]
Downloading daily-21379.cdiff [100%]
Downloading daily-21380.cdiff [100%]
Downloading daily-21381.cdiff [100%]
Downloading daily-21382.cdiff [100%]
Downloading daily-21383.cdiff [100%]
Downloading daily-21384.cdiff [100%]
Downloading daily-21385.cdiff [100%]
Downloading daily-21386.cdiff [100%]
Downloading daily-21387.cdiff [100%]
Downloading daily-21388.cdiff [100%]
Downloading daily-21389.cdiff [100%]
Downloading daily-21390.cdiff [100%]
Downloading daily-21391.cdiff [100%]
daily.cld updated (version: 21391, sigs: 1850214, f-level: 63, builder: neo)
bytecode.cld is up to date (version: 271, sigs: 47, f-level: 63, builder: anvilleg)
Database updated (4274486 signatures) from db.UK.clamav.net (IP:
WARNING: Clamd was NOT notified: Can't connect to clamd through /var/run/clamav/clamd.sock: No such file or directory

Netflix – Not fit for purpose?

One of my family has a Netflix account. The account is accessible from any of the desktop and laptop computers in the house, whichever OS they are running.

Recently we bought a so-called ‘smart TV’ (an LG 40UF770V 4K Ultra HD TV, as it happens), and are pleased with it. It runs WebOS 2.0 (yay, Linux!) and the LG Content Store contains a Netflix app, which we promptly installed. The app worked perfectly for several weeks but then stopped being able to access Netflix. When the app was launched, the usual screen with the Netflix logo and the ‘Loading’ rotating indicator would appear but, after a minute or so, an error message would be displayed informing us that Netflix error ‘ui-113’ had occurred. One of the on-screen options then offered by the app was to check the network connection, which we tried, but everything was reported to be working correctly. Not to mention that all the other apps that require an Internet connection work fine. In order to watch a film using Netflix over the Christmas period we had to resort to connecting a laptop to the TV via an HDMI cable and accessing Netflix in a Web browser on the laptop. It is ridiculous to have to resort to such measures to view content on smart TVs which have Netflix apps.

I searched the Web and discovered that many, many people experience the same problem with Netflix and smart TVs. As in our case, they had no trouble accessing their Netflix account on their home network with other devices such as computers, tablets and smart phones. I came across reports by owners of smart TVs made by LG, Philips, Samsung, Sony, Toshiba, and other manufacturers. People who had contacted the relevant TV manufacturer were often told the problem is caused by Netflix, and people who had contacted Netflix were often told the problem is caused by the TV manufacturer.

Netflix has a Help page for this error message, but none of the steps Netflix listed worked, and neither did any of the remedies suggested by others on the Web (including in various YouTube videos). Resetting the TV did not solve the problem. Neither did cycling the mains power to the TV, broadband modem and router (however long the power was off). Nor did changing the TV’s setting for the IP address of the DNS server to one of the well-known public DNS servers such as Google’s. Nor did suggestions such as un-installing and re-installing the Netflix app. Nor did configuring the router to perform port forwarding for Netflix on the TV (not that this should be necessary, but I tried it anyway). Several people wrote that the parental lock in their routers caused the problem, but the parental lock is definitely not enabled in my router. I also tried to access Netflix via the TV’s Web browser; it can log-in to the Netflix account but cannot play content as it does not support the Microsoft Silverlight plug-in or HTML5 required by Netflix.

Nothing we tried solved the problem, and two weeks of this messing around was exasperating. Some people reported that changing the DNS server address in the TV to Google’s DNS servers worked, whereas others reported it didn’t. Even if some lucky person managed to get Netflix working on their smart TV using a certain procedure, other people in the same country with the same model of TV could not, even if they used the same procedure.

In addition to people in a given country trying to get the Netflix app in their smart TV to access their Netflix account in that country, I came across posts by people wanting to access Netflix in a different country (mostly people not in the USA wanting to access US Netflix because it offers a wider range of films and programmes, but also expatriates wanting to access Netflix for their home country with their home-country Netflix account). So I tried recommendations to configure the TV to use a DNS server in the US that some people in the UK had recently indicated would give the Netflix app access to US Netflix rather than UK Netflix (even though we wanted to access UK Netflix from the UK). But that didn’t work either.

However, I didn’t give up. I trawled the Web for lists of DNS servers that some people claimed would give access to Netflix in the UK. I found various Web sites listing IP addresses for DNS servers and tried several of them. Eventually I found one that actually enables the Netflix app in the TV to work, but it accesses US Netflix instead of UK Netflix. Given that the Netflix app has not worked for several weeks, I’m not complaining, but it is not what we were trying to achieve (US Netflix does not provide all the UK TV series available on UK Netflix). Furthermore, according to some of the posts I’ve read, periodically you have to change the DNS server address in the TV because Netflix stops working with the existing address.

Now, I’m a technically-oriented person and it took me several hours over a two-week period to find a solution (well, a work-around). Someone with little or no IT knowledge in the same situation would be at a complete loss as to how to get their Netfix account working. In order for streaming media services to become as ubiquitous as e.g. terrestrial TV, they have to be reliable and be accessible easily to paying customers. Use of Geolocation, GeoDNS and other complex techniques should not cause such a headache to bona fide users. Someone with a Netflix account in his/her country of residence and who simply wants to access Netflix on a smart TV should not have to jump through hoops or hit a brick wall. Clearly this is happening to many people.

On top of that, people such as myself who have to travel internationally frequently because of their work need to be certain that, if they subscribe to a streaming media service, it will work in whatever country they happen to be in at the time (except if blocked by Great Firewalls or content filters on proxy servers, of course) and not be purposely or inadvertently prevented from working by the media service provider’s network concept.

I myself had considered signing up for a Netflix account so that I could view films and TV programmes during my overseas work trips, but, after having to struggle for days to help a family member access a valid Netflix account on a smart TV in the country where the account was set up, will definitely not be giving Netflix my business. In this day and age it is ridiculous that users should have to try umpteen DNS server addresses and reset TVs, routers and modems in order to access their account with a media provider. Services such as Netflix will never have my business until their networking and DRM are sorted out properly and made to work reliably. Until Netflix changes its network delivery model, its service will remain a curate’s egg in my opinion.

NetworkManager: Failed to activate – The name org.freedesktop.NetworkManager was not provided by any .service files

Because I need to connect quickly and easily to numerous wired and wireless networks (DHCP or static IP addressing), I use NetworkManager in my Gentoo Linux amd64 installation running OpenRC and KDE 4. My Clevo W230SS laptop has an Intel Dual Band Wireless-AC 7260 Plus Bluetooth adapter card, and my installation uses the iwlwifi module:

# lspci -knn | grep Net -A2
03:00.0 Network controller [0280]: Intel Corporation Wireless 7260 [8086:08b1] (rev bb)
        Subsystem: Intel Corporation Dual Band Wireless-AC 7260 [8086:4070]
        Kernel driver in use: iwlwifi
# lsmod | grep iwl
iwlmvm                143919  0
iwlwifi                75747  1 iwlmvm

As I am using NetworkManager instead of netifrc, in accordance with the instructions in the Gentoo Wiki article on NetworkManager I do not have any net.* services enabled (not even net.lo):

# rc-update show -v
       NetworkManager |      default                 
                acpid |                              
            alsasound |                              
         avahi-daemon |                              
       avahi-dnsconfd |                              
               binfmt | boot                         
            bluetooth |      default                 
             bootmisc | boot                         
         busybox-ntpd |                              
     busybox-watchdog |                              
                clamd |                              
          consolefont |                              
           consolekit |      default                 
               cronie |      default                 
         cups-browsed |      default                 
                cupsd |      default                 
                 dbus |      default                 
                devfs |                       sysinit
               dhcpcd |                              
                dhcpd |                              
             dhcrelay |                              
            dhcrelay6 |                              
                dmesg |                       sysinit
              dropbox |                              
           fancontrol |                              
                 fsck | boot                         
                 fuse |                              
           git-daemon |                              
                  gpm |                              
              hddtemp |                              
             hostname | boot                         
              hwclock | boot                         
            ip6tables |                              
             iptables |                              
              keymaps | boot                         
            killprocs |              shutdown        
    kmod-static-nodes |                       sysinit
           lm_sensors |                              
                local |      default                 
           localmount | boot                         
             loopback | boot                         
      mit-krb5kadmind |                              
          mit-krb5kdc |                              
       mit-krb5kpropd |                              
              modules | boot                         
             mount-ro |              shutdown        
                 mtab | boot                         
                mysql |                              
                  nas |                              
         net.enp4s0f1 |                              
               net.lo |                              
             netmount |      default                 
           ntp-client |                              
                 ntpd |                              
           nullmailer |                              
              numlock |                              
  nvidia-persistenced |                              
           nvidia-smi |                              
              osclock |                              
              pciparm |                              
               procfs | boot                         
              pwcheck |                              
            pydoc-2.7 |                              
            pydoc-3.4 |                              
               rfcomm |                              
                 root | boot                         
               rsyncd |                              
            s6-svscan |                              
                samba |      default                 
                saned |                              
            saslauthd |                              
            savecache |              shutdown        
                 sntp |                              
                 sshd |      default                 
             svnserve |                              
                 swap | boot                         
            swapfiles | boot                         
              swclock |                              
               sysctl | boot                         
                sysfs |                       sysinit
            syslog-ng |      default                 
        teamviewerd10 |                              
         termencoding | boot                         
             timidity |                              
         tmpfiles.dev |                       sysinit
       tmpfiles.setup | boot                         
               twistd |                              
                 udev |                       sysinit
                  ufw | boot                         
              urandom | boot                         
       wpa_supplicant |                              
                  xdm |      default                 
            xdm-setup |

I have left the netmount service enabled in case I want to use network-attached file shares at home or in one of the various office locations where I work.

Networking works fine on my laptop with the many wired and wireless networks I have used except for one particular public wireless network (it is in an airport, has multiple Access Points, and its Access Points only support 802.11a/b/g, which may or may not be relevant) for which the following message would usually appear in a pop-up window when I tried to connect to the network from the KDE network management GUI after start-up:

Failed to activate
The name org.freedesktop.NetworkManager was not provided by any .service files

Error message displayed by KDE when trying to connect to one specific network

Error message displayed by KDE when trying to connect to one specific network

This occurred with both networkmanager-1.0.2-r1 and networkmanager-1.0.6, the two Stable Branch releases of NetworkManager currently available in Gentoo Linux.

The wireless network is not the only network at that particular location, and the ‘Failed to activate’ message occurred whichever network (wireless or wired) I tried to access at that location. When this problem occurred, it transpired that the NetworkManager service was not running (it had crashed):

$ nmcli d
Error: NetworkManager is not running.
$ rc-status
Runlevel: default
 dbus                   [  started  ]
 NetworkManager         [  crashed  ]
 netmount               [  started  ]
 syslog-ng              [  started  ]
 cupsd                  [  started  ]
 samba                  [  crashed  ]
 consolekit             [  started  ]
 cronie                 [  started  ]
 bluetooth              [  started  ]
 xdm                    [  started  ]
 cups-browsed           [  started  ]
 sshd                   [  started  ]
 local                  [  started  ]
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed
 xdm-setup              [  started  ]
 avahi-daemon           [  started  ]
Dynamic Runlevel: manual

(I am not bothered that Samba crashes in that particular location. It crashes even if a connection is established, because the public wireless network does not provide network file systems. Samba works fine when I connect the laptop to an office network or to my home network.)

Even if the ‘Failed to activate’ message occurred, sometimes (but not always) the laptop could still connect to networks after I restarted the NetworkManager service (albeit sometimes it was necessary to restart it more than once):

# /etc/init.d/NetworkManager restart

When it is possible to connect to networks, the NetworkManager service is of course running:

$ nmcli d
DEVICE    TYPE      STATE        CONNECTION           
sit0      sit       connected    sit0                 
wlp3s0    wifi      connected    Free_Airport_Internet
enp4s0f1  ethernet  unavailable  --                   
lo        loopback  unmanaged    --        
$ rc-status
Runlevel: default
 dbus                   [  started  ]
 NetworkManager         [  started  ]
 netmount               [  started  ]
 syslog-ng              [  started  ]
 cupsd                  [  started  ]
 samba                  [  crashed  ]
 consolekit             [  started  ]
 cronie                 [  started  ]
 bluetooth              [  started  ]
 xdm                    [  started  ]
 cups-browsed           [  started  ]
 sshd                   [  started  ]
 local                  [  started  ]
Dynamic Runlevel: hotplugged
Dynamic Runlevel: needed
 xdm-setup              [  started  ]
 avahi-daemon           [  started  ]
Dynamic Runlevel: manual

I searched the Web for the error message and, based on a recommendation on the Web page ‘nm-applet gives errors‘ claiming the problem is due to the iwlwifi driver when used with an Intel 7260 controller, I created a file /etc/modprobe.d/iwlwifi.conf containing the following line, and rebooted:

options iwlwifi power_save=0

However, the error message still occurred. So I changed the iwlwifi module options line to the following, as also recommended on that page, and rebooted:

options iwlwifi 11n_disable=1 power_save=0

However, the error message still occurred.

The default value for OpenRC’s rc_depend_strict variable is YES if rc_depend_strict is not declared in the file /etc/rc.conf, but I do not think that is the cause of the problem:

# Do we allow any started service in the runlevel to satisfy the dependency
# or do we want all of them regardless of state? For example, if net.eth0
# and net.eth1 are in the default runlevel then with rc_depend_strict="NO"
# both will be started, but services that depend on 'net' will work if either
# one comes up. With rc_depend_strict="YES" we would require them both to
# come up.

As already mentioned, sometimes just restarting the NetworkManager service once or more did enable the laptop to connect to the network. This made me wonder whether the problem had something to do either with the timing of the launch of the NetworkManager service or with the timing of the service establishing a connection. As netmount is the only other network-related service enabled at start-up, I checked the netmount service’s configuration file /etc/conf.d/netmount to see what it contained (it’s the same in both the latest stable openrc-0.17 and the latest testing openrc-0.18.2):

# You will need to set the dependencies in the netmount script to match
# the network configuration tools you are using. This should be done in
# this file by following the examples below, and not by changing the
# service script itself.
# Each of these examples is meant to be used separately. So, for
# example, do not set rc_need to something like "net.eth0 dhcpcd".
# If you are using newnet and configuring your interfaces with static
# addresses with the network script, you  should use this setting.
# If you are using oldnet, you must list the specific net.* services you
# need.
# This example assumes all of your netmounts can be reached on
# eth0.
# This example assumes some of your netmounts are on eth1 and some
# are on eth2.
#rc_need="net.eth1 net.eth2"
# If you are using a dynamic network management tool like
# networkmanager, dhcpcd in standalone mode, wicd, badvpn-ncd, etc, to
# manage the network interfaces with the routes to your netmounts, you
# should list that tool.
# The default setting is designed to be backward compatible with our
# current setup, but you are highly discouraged from using this. In
# other words, please change it to be more suited to your system.

As I am using NetworkManager rather than netifrc, I followed the instructions in the file’s comments and changed the file’s contents from:




After making the above change, the console messages at boot-up included a new message:

* ERROR: netmount needs service(s) networkmanager

That message made sense: rc_need had been set to "networkmanager" and, obviously, netmount can only do its job if NetworkManager is running (AND a network connection has been established). However, notice that the name of the NetworkManager service initscript is /etc/init.d/NetworkManager, not /etc/init.d/networkmanager. In other words, the instructions in /etc/conf.d/netmount are wrong: the name of the service is actually ‘NetworkManager‘, not ‘networkmanager‘. So I changed /etc/conf.d/netmount to contain rc_need="NetworkManager" instead of rc_need="networkmanager" and, unsurprisingly, the above-mentioned error message no longer occurs. I have filed Gentoo Bugzilla Bug Report No. 564846 requesting that the comment in the configuration file be changed.

Nevertheless, the ‘Failed to activate’ message still occurred when I tried to connect to any network at that location by using the DE’s network management GUI, and therefore I still needed to restart the NetworkManager service manually in order to be able to connect to any network there. Although I am not yet sure of the root cause and solution, I have found a work-around which avoids me having to manually restart the NetworkManager service, as explained below.

Although OpenRC correctly launches the NetworkManager service, that service remains inactive until it actually establishes a network connection. This is not a bug, it is the way OpenRC and NetworkManager work (see the explanation in the Gentoo Forums thread NetworkManager has started, but is inactive). This is why the following console message appears during boot-up:

* WARNING: NetworkManager has already started, but is inactive

If you did not configure NetworkManager to connect automatically to a network, after logging-in to the DE you will need to use the DE’s network management GUI (plasma-nm in the case if KDE, nm-applet in the case of e.g. Xfce) to tell NetworkManager to connect to the desired network. However, I found that waiting that long before trying to connect is too late to avoid the ‘Failed to activate’ problem, i.e. NetworkManager crashes after a while. I do not know why this happens, but it usually happens only when I am at the location covered by one specific wireless network (which is why I wonder if the problem is a result of that network only supporting 802.11a/b/g). By configuring NetworkManager to connect automatically to the wireless network which seemed to trigger the problem, the NetworkManager service tries to connect earlier. It is possible to configure NetworkManager to do this either by using the DE network GUI and ticking ‘Automatically connect to this network when it is available’ for the relevant network connection, or by directly editing the relevant connection’s file in the directory /etc/NetworkManager/system-connections/.

Of the various wired and wireless connections I had configured on the laptop, I had named the problematic wireless network’s connection ‘Free_Airport_Internet’. So I edited the file /etc/NetworkManager/system-connections/Free_Airport_Internet and deleted the line ‘autoconnect=false‘ in the [connections] section of the file (the default value of the autoconnect variable is TRUE – see man nm-settings). I could instead have done this by using the DE’s network manager GUI and ticking ‘Automatically connect to this network when it is available’ for that network connection. Now, when the laptop boots, NetworkManager tries to connect to that network and the ‘Failed to activate’ problem is avoided. This works with or without the iwlwifi driver options I mentioned above, so, despite the claim on the Web page I referenced above, the root cause of the problem does not appear to be the iwlwifi driver. What I don’t understand is why the problem only seems to occur with one particular network (a public wireless network which happens to only support 802.11a/b/g), i.e. even if none of the NetworkManager connection files in my installation have been configured to try to establish a connection automatically, with all the other wireless networks I have used in other locations (I believe those all support at least 802.11a/b/g/n) I have been able to establish a connection manually by using the DE’s network management GUI.

The bottom line

If your installation uses NetworkManager and you experience the ‘Failed to activate’ message when trying to connect to networks from the DE’s network management GUI, check if the NetworkManager service is running. You can check by using the command ‘nmcli d‘ in a console. If it is not running, try to restart the NetworkManager service from the command line. If the connection is not already configured to start automatically, configure it to start automatically in order to try to make NetworkManager become active at an early stage.

POSTSCRIPT (November 6, 2015)

The two links below are to old bug reports regarding earlier versions of NetworkManager having trouble using wireless networks with multiple Access Points. I wonder if the problem I saw with NetworkManager crashing when not configured to connect automatically to the specific network I mentioned above is somehow related to those problems:

background scanning causes drivers to disassociate – WiFi roaming causes NetworkManager to lose routing

network-manager roams to (none) ((none)) – background scanning

Roaming to BSSID “(none)” certainly happens with this particular network too, as shown by the messages in the laptop’s system log from yesterday when I was using the laptop with that network (the laptop was stationary the whole time):

# cat /var/log/messages | grep "Nov  5 11" | grep NetworkManager | grep \(none\)
Nov  5 11:01:22 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID 04:C5:A4:C3:F9:EE (Free_Airport_Internet) to (none) ((none))
Nov  5 11:01:22 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID (none) ((none)) to B8:BE:BF:69:89:6E (Free_Airport_Internet)
Nov  5 11:13:23 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID B8:BE:BF:69:89:6E (Free_Airport_Internet) to (none) ((none))
Nov  5 11:13:23 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID (none) ((none)) to 04:C5:A4:C3:F9:EE (Free_Airport_Internet)
Nov  5 11:15:23 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID 04:C5:A4:C3:F9:EE (Free_Airport_Internet) to (none) ((none))
Nov  5 11:15:23 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID (none) ((none)) to B8:BE:BF:69:89:6E (Free_Airport_Internet)
Nov  5 11:19:22 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID B8:BE:BF:69:89:6E (Free_Airport_Internet) to (none) ((none))
Nov  5 11:19:23 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID (none) ((none)) to B8:BE:BF:69:89:6E (Free_Airport_Internet)
Nov  5 11:49:50 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID B8:BE:BF:69:89:6E (Free_Airport_Internet) to (none) ((none))
Nov  5 11:49:50 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID (none) ((none)) to 68:BC:0C:A1:3C:DE (Free_Airport_Internet)
Nov  5 11:51:51 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID 68:BC:0C:A1:3C:DE (Free_Airport_Internet) to (none) ((none))
Nov  5 11:51:51 clevow230ss NetworkManager[2459]:   (wlp3s0): roamed from BSSID (none) ((none)) to B8:BE:BF:69:89:6E (Free_Airport_Internet)

Today I’m using a hotel network in my hotel room, and that does not roam to BSSID “(none)”, but I don’t know if my room is within range of more than one Access Point:

# cat /var/log/messages | grep "Nov  6" | grep NetworkManager | grep \(none\)

Anyway, with the work-around described in this post I have not had any further trouble accessing the particular network, but it would be interesting to know the root cause.

Using a keyboard shortcut in Linux to add an e-mail signature giving current location and local time

In my previous post I showed how to find the current time at any town or city Worldwide from the command line in Gentoo Linux. My interest in a command to do this is not to use it on the command line per se, but to use the command in a keyboard shortcut to insert a signature at the end of my e-mails.

I have to travel internationally frequently because of my work, but I leave my laptop’s hardware clock set to UTC and the system clock set to the local time of my home town. This means that, irrespective of where I am in the World, the e-mail client (Thunderbird, in my case) uses the local time of my home town in e-mail headers and calenders. It is not practical to reconfigure Linux for each timezone I happen to be in (see my post Configuring the Linux clock), and, in any case, I want the file system’s timestamps to use one timezone only and all the timestamps in my e-mails and the e-mail client’s calender to use one timezone only, so there is less chance of me getting confused. I could have configured the installation to use UTC for the system clock, but I prefer the system clock to use the timezone of my home town. Of course, even though the system clock is always set to the timezone of my home town, on the Panel clock I select the timezone of the location where I happen to be, so that the Panel clock displays the local time in that timezone.

I wanted to be able to insert a signature at the end of each e-mail, stating my current location and the current time at that location, so that the person receiving the e-mail could tell from where in the World I sent the e-mail and the local time it was sent, as that local time could differ from the time shown in the e-mail header. For example, let us assume that Jane, who lives in the UK and whose system clock is configured for the timezone Europe/London, is making a brief visit to Perth, Australia and sends an e-mail to Dave in the UK at 06:36 on 11 October (Perth time). The e-mail below illustrates the type of signature I wanted to achieve.

Subject: Site visit
From: Jane <jane@acompany.com>
To: Dave <dave@acompany.com>
Date: Sat Oct 10 2015 23:36:40 GMT+0100 (BST)

Hello Dave,

This is to let you know that I have just arrived in Perth and will be
visiting site at 09:00 local time to speak to the client. Tomorrow p.m.
I have a meeting scheduled with our local project manager, so I would
appreciate it if you would e-mail the latest documentation to me. I will
not have spare time until I’m in my room at the hotel tonight but will
read the documents tomorrow a.m. in readiness for the meeting with
the local project manager. Thanks in advance.

Current location: Perth (Australia)
Local time now: Sat Oct 11 06:36:31 2015 AWST

As you can see above, because the OS on Jane’s and Dave’s laptops is configured for the timezone Europe/London, the e-mail header shows the current time in the UK when the e-mail was sent, which was October 10, 23:36 British Summer Time (22:36 UTC), and the signature shows the corresponding local time in Perth, Australia, which was October 11, 06:36 Australian Western Standard Time. It becomes even more confusing if the computer of the person receiving the e-mail is configured for a third timezone. For example, let’s say Dave is based in Seattle, USA rather than the UK. His e-mail client would then display the time in that timezone when the e-mail was sent. This is usually my case, i.e. my Linux installation is configured for Timezone1 but I happen to be in Timezone2 when I send an e-mail to someone who is based in Timezone3 and whose OS is configured for that timezone.

I wanted to use a keyboard shortcut to add a signature to the end of my e-mails, as shown above. I therefore created the Bash script listed below, which I named timezone_signature_GeoNames.sh:


location=$(kdialog --title "Current Location" --inputbox "Enter your location:")

localtime=$(perl /home/fitzcarraldo/now1.pl $location)
place=`echo $localtime | cut -d'|' -f1`
place=$place" "`echo $localtime | cut -d'|' -f2`
timezone=`echo $localtime | cut -d'|' -f4`

if [ $location != "" ]; then
  echo -n "Current location: "
  echo $place
  echo -n "Local time now:"
  /usr/sbin/zdump ${timezone} | cut -d' ' -f2-

Notice that the Bash script uses the GUI dialogues utility kdialog to display a pop-up window prompting me to enter the name of a town/city. As I am using KDE I opted to use a dialogues utility developed for use in KDE, but I could have used Zenity instead.

The Perl script now1.pl is a variant of the Perl script now.pl described in my previous post, modified very slightly in order to facilitate formatting of the output by the Bash script, and is listed below.


use strict;
use warnings;

use DateTime;
use Geo::GeoNames;
use URI::Escape;
use Encode;

binmode STDOUT, ':encoding(UTF-8)';

my $city = decode("UTF-8", @ARGV ? shift : 'London');
# N.B. Replace London with your home town/city.

my $geo = Geo::GeoNames->new( username => '************' );
# N.B. Replace the asterisks with your GeoNames user name.

my $result = $geo->search(
q       => uri_escape_utf8($city),
maxRows => 1,
style   => 'FULL'

defined $result->[0] or die "Unrecognized city '$city'\n";

my $city_name    = $result->[0]->{name};
my $country_name = $result->[0]->{countryName};
my $time_zone    = $result->[0]->{timezone}{content};
my $time_now     = DateTime->now( time_zone => $time_zone );

#print "$city_name ($country_name) $time_now ($time_zone)\n";

print "$city_name|($country_name)|$time_now|$time_zone\n";

exit 0;

The only thing remaining was to configure a keyboard shortcut to launch the Bash script. I opted to use the key combination Ctrl-Alt-z for the shortcut. As I am using KDE I could have used KDE’s ‘System Settings’ > ‘Shortcuts and Gestures’> ‘Custom Shortcuts’ to specify the shortcut and the name of the script it launches. However, as I also use AutoKey for various shortcuts, I opted to use that instead, so I used the AutoKey GUI to create a shortcut named ‘Insert Current Time’ to use the following command:

output = system.exec_command("/home/fitzcarraldo/timezone_signature_GeoNames.sh")


I compose my e-mails as usual, and, after entering my name at the end of the e-mail, I press Ctrl-Alt-z. A window then pops up prompting me to enter my current location, which I do and then click on ‘OK’. The location and current time at that location are then added to the end of the e-mail, and it just remains for me to click on the ‘Send’ button in the e-mail client’s window. As the Perl script now1.pl uses the Internet to access the GeoNames database, my laptop must be connected to the Internet when I use the shortcut.

KDialog window that pops up when I use the keyboard shortcut

KDialog window that pops up when I use the keyboard shortcut

If the town/city name consists of more than one word (Rio de Janeiro, for example) then replace spaces with hyphens when you enter the location name in the pop-up window (Rio-de-Janeiro, for example) and then the keyboard shortcut will return the correct location and local time:

Current location: Rio de Janeiro (Brazil)
Local time now: Fri Oct 16 09:28:19 2015 BRT

How to group the entries in the right-click menu of a KDE file manager

This is easier to explain by giving an example. I will use PeaZip as my example, but the principle applies whatever the menu entries.

Immediately after installing PeaZip Portable on my main laptop running Gentoo Linux by using the steps in one of my earlier posts, the resulting right-click menu in KDE Dolphin looks like the screenshot below. Notice that the PeaZip entries in the Actions sub-menu are not listed contiguously.

Actions sub-menu of right-click menu in KDE

But in KDE it is relatively easy to group menu entries tidily in a sub-menu, as shown in the screenshot below.

Sub-menu of Actions sub-menu for right-click menu in KDE

The peazip*.desktop files for the five PeaZip actions shown in the above screenshots are located in the directory ~/.kde4/share/kde4/services/ServiceMenus/ and each file includes the line ‘X-KDE-Submenu='.

All I had to do was edit each of the five peazip*.desktop files and change that line in each file to ‘X-KDE-Submenu=PeaZip‘.

That’s it!

Making the X Windows cursor theme the same for KDM and KDE

For a long time it irritated me that the X Windows cursor theme on the KDM log-in screen differed to the X Windows cursor theme on the KDE Desktop. The former was usually the old-fashioned core X Windows cursor theme (or perhaps the ‘KDE Classic’ theme, I’m not sure which), whereas the latter is the theme I selected via ‘System Settings’ > ‘Workspace Appearance’ > ‘Cursor Theme’. To confuse me further, when I upgraded X Windows recently the X Windows cursor theme on the KDM log-in screen was Adwaita when I next booted my laptop, but susequently reverted to the classic cursor theme.

Anyway, I had to do the following in order to make the KDM cursor theme the same as the KDE cursor theme:

1. Create a directory /usr/share/icons/default if it does not already exist (it did not in my case):

# mkdir /usr/share/icons/default

2. Check which X Windows cursor themes are currently installed:

# ls /usr/share/icons
Adwaita HighContrast Humanity KDE_Classic Oxygen_Black Oxygen_Blue Oxygen_White Oxygen_Yellow Oxygen_Zion default gnome hicolor locolor mono nuvola oxygen ubuntu-mono-dark ubuntu-mono-light

I also find the three X Windows cursor themes ‘handhelds’, ‘redglass’ and ‘whiteglass’, installed when I installed the package x11-themes/xcursor-themes using the Portage package manager, in a different directory:

# ls /usr/share/cursors/xorg-x11/
Adwaita handhelds redglass whiteglass

The ‘Adwaita’ cursor theme was already in /usr/share/cursors/xorg-x11/ before I installed the package x11-themes/xcursor-themes, and also in the directory /usr/share/icons/ but I do not know why only that specific cursor theme is in both directories.

3. Create a file /usr/share/icons/default/index.theme with the following contents (I opted to use the Oxygen_White cursor theme, but you can choose whichever you want from the list of installed cursor themes):

[Icon Theme]
Name = Oxygen_White
Comment = Default icon theme
Inherits = Oxygen_White

4. Make sure ‘System Settings’ > ‘Worskspace Appearance’ > ‘Cursor Theme’ has the theme selected that you want for the KDE Desktop (I opted to use the Oxygen_White cursor theme).

For example, if I had wanted the cursor theme to be Adwaita, I would have selected Adwaita in KDE using ‘System Settings’ > ‘Worskspace Appearance’ > ‘Cursor Theme’ and then I would have edited /usr/share/icons/default/index.theme to contain the following:

[Icon Theme]
Name = Adwaita
Comment = Default icon theme
Inherits = Adwaita

Easy when you know how.

According to the Arch Linux Wiki, for user-specific configuration you should create or edit the file ~/.icons/default/index.theme, whereas for system-wide configuration you should create or edit the file /usr/share/icons/default/index.theme but the latter file is owned by libXcursor and user changes to it will be overwritten on update. However, in Gentoo Linux it would be possible to get around that by creating a script file in the directory /etc/local.d/ to revert the file change. For example, I could make the file /usr/share/icons/default/index.theme contain the following:

[Icon Theme]
Name = Oxygen_White
Comment = Default icon theme
Inherits = Oxygen_White

Then copy that file to somewhere safe that will not be overwritten:

# cp /usr/share/icons/default/index.theme /home/fitzcarraldo/

Then create a script file named, say, 80-xcursor.start in /etc/local.d/ with the following contents:

# Make sure X windows cursor theme on the KDM screen is the one I want:
cp /home/fitzcarraldo/index.theme /usr/share/icons/default/index.theme

and make the script file executable:

# chmod +x /etc/local.d/80-xcursor.start

Then, if something does overwrite or delete /usr/share/icons/default/index.theme in future, the script in /etc/local.d/ will restore it before the KDM log-in screen appears, so you would always see the cursor theme specified in /home/fitzcarraldo/index.theme.

Office 2007 mime-type problem in KDE

Although Microsoft Office 2007 file types are normally opened by the correct Office 2007 application (running with WINE) in my Gentoo Linux Stable amd64 installation, KDE 4.14.3 on my new Clevo notebook opened *.xlsm (Excel 2007 macro-enabled spreadsheet) files with Ark instead of Excel 2007. For some reason the *.xlsm filetype was registed in the xdg-mime database to use the Ark application:

$ file myspreadsheet.xlsm
myspreadsheet.xlsm: Microsoft Excel 2007+

$ xdg-mime query filetype myspreadsheet.xlsm

On the other hand, as you can see below, *.docx documents are correctly registed in the xdg-mime database:

$ file myworddocument.docx
myworddocument.docx: Microsoft Word 2007+

$ xdg-mime query filetype myworddocument.docx

The Office 2007 mime types are listed on the Web page Office 2007 File Format MIME Types for HTTP Content Streaming. Notice the uppercase ‘E’ in the mime-type application/vnd.ms-excel.sheet.macroEnabled.12 for *.xlsm files.

I had already used ‘System Settings’ > ‘File Associations’ in KDE to configure the file association for *.xlsm files, but this made no difference.

I searched my installation and found the file /usr/share/mime/application/vnd.openxmlformats-officedocument.wordprocessingml.document.xml (for *.docx) and the file vnd.ms-excel.sheet.binary.macroenabled.12.xml (for *.xlsb), but the file vnd.ms-excel.sheet.macroenabled.12.xml (for *.xlsm) did not exist.

Then I found the freedesktop.org bug report ‘subclasses declared have wrong case‘ about the package shared-mime-info. One of the commenters stated the problem is in fact due to a bug in KDE.

I followed the work-around given in the bug report:

# mv /usr/share/mime/subclasses /usr/share/mime/subclasses.BAK
# sed -e 's/macroEnabled/macroenabled/' /usr/share/mime/subclasses.BAK > /usr/share/mime/subclasses

I then used KDE ‘System Settings’ > ‘File associations’ again, searched for .xlsm and removed Ark from the list of applications for application/vnd.ms-excel.sheet.macroenabled.12, then logged-out and back in to KDE. Double-clicking on *.xlsm files now opens them in Excel 2007 again, the file /usr/share/mime/application/vnd.ms-excel.sheet.macroenabled.12.xml now exists and the mime-type has been set correctly:

$ xdg-mime query filetype myspreadsheet.xlsm

(I don’t have this problem opening *.xlsm files on my Compal laptop, which also has Version 1.4 of shared-mime-info installed and is also running KDE 4.14.3, albeit under Gentoo Testing ~amd64 rather than Gentoo Stable amd64, so perhaps the KDE bug has already been fixed in the Testing branch.)

More tools for creating QR Codes in Linux

In my previous post I showed how to install CuterCode and Qreator, two simple GUI applications for producing QR Codes, in Gentoo Linux. I have now found a couple of other GUI applications, both of which offer more features than the aforementioned two, such as allowing you to specify the amount of error correction to be incorporated into the QR Code. QR Code codewords are 8 bits long and use the Reed–Solomon error correction algorithm, with four error correction levels possible in the case of QR Codes:

Level L (Low): 7% of codewords can be restored.
Level M (Medium): 15% of codewords can be restored.
Level Q (Quartile): 25% of codewords can be restored.
Level H (High): 30% of codewords can be restored.

The higher the level of error correction, the lower the storage capacity of the QR Code.

And now to the two applications …

Portable QR-Code Generator

This is a Java application, so first make sure you have installed a Java run-time environment (or Java Development Toolkit, which will include the JRE) via Portage.

Download to your home directory the archive qrcodegen_1.14.2.zip containing the compiled Java application, not the archive qrcodegen_1.14.2_src.zip with the source code (‘quellcode’ in German), from the application’s Web site. Unzip it to the directory ~/qrcodegen_1.14.2/ then enter the directory and launch the Java application from the command line as shown below:

$ cd ~/qrcodegen_1.14.2/qrcodegen
$ java -jar QRCodeGen.jar

Alternatively you can create a Desktop Configuration file QRCodeGen.desktop containing the following (change ‘fitzcarraldo’ to your own user name, of course):

[Desktop Entry]
Comment[en_GB]=QR Code Generator is a program that lets you generate and print QR Codes easily.
Comment=QR Code Generator is a program that lets you generate and print QR Codes easily.
Exec=java -jar /home/fitzcarraldo/qrcodegen_1.14.2/qrcodegen/QRCodeGen.jar

and make it executable:

$ chmod +x QRCodeGen.desktop

You can choose a nice PNG icon by using Google Images to search for ‘qr code icon png’ and save the image with the file name icon.png in the same directory. Then you can launch QR code Generator by double-clicking on the Desktop Configuration file.

QtQR – QR Code Generator

Download the tarball qr-tools-1.2.tar.gz from the application’s Web site, unpack it to the directory ~/qr-tools-1.2/ and make the Python scripts executable:

$ cd ~/qr-tools-1.2/qr-tools
$ chmod +x qtqr.py
$ chmod +x qrtools.py

Make sure you have installed the package media-gfx/zbar with the python USE flag set, so that the Python zbar module is also installed:

# USE="python" emerge zbar

(You may as well add the python USE flag in the line for media-gfx/zbar in the Portage package.use file so that ZBar’s Python module is installed if you upgrade or re-install ZBar via Portage in future).

Check if the Python Imaging Library (fork) dev-python/pillow is already installed:

# emerge --search pillow

If it is not already installed, install it:

# emerge pillow

Now you can launch QtQR from the command line as follows:

$ cd ~/qr-tools-1.2/qr-tools
$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so PYTHONPATH=/usr/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages/PIL ./qtqr.py

Alternatively, you can create a Desktop Configuration file qtqr.desktop with the following contents (change ‘fitzcarraldo’ to your own user name, of course):

[Desktop Entry]
Comment[en_GB]=QtQR is a Qt based software that lets you generate QR Codes easily, scan an image file for a QR Code and decode it or use your webcam to scan a printed one.
Comment=QtQR is a Qt based software that lets you generate QR Codes easily, scan an image file for a QR Code and decode it or use your webcam to scan a printed one.
Exec=LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so PYTHONPATH=/usr/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages/PIL /home/fitzcarraldo/qr-tools-1.2/qr-tools/qtqr.py

and make it executable:

$ chmod +x qtqr.desktop

Then you can launch QtQR by double-clicking on the Desktop Configuration file.

The QtQR GUI has a feature for decoding a QR Code in an image file and for decoding a printed QR Code held in front of a Webcam. If I select ‘Decode’ > ‘Decode from Webcam’, QtQR launches ZBar and, although it is a bit fiddly, I can successfully decode a printed QR Code. However, I cannot get QtQR to decode a QR Code in an image file that QtQR itself created (or to decode a QR Code in a file created by any other application, for that matter), so there is a bug in QtQR. Looking at the application’s bug reports this appears to be Bug No. 811576. It’s not a big deal, though, because the zbarimg command provided by ZBar can be used to decode QR Codes (see my post Installing and using ZBar in Linux to scan bar codes with your Webcam).

$ cd ~/qr-tools-1.2/qr-tools
$ LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so PYTHONPATH=/usr/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages/PIL ./qtqr.py
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:127: RuntimeWarning: PyOS_InputHook is not available for interactive use of PyGTK
Object::connect: No such signal org::freedesktop::UPower::DeviceAdded(QDBusObjectPath)
Object::connect: No such signal org::freedesktop::UPower::DeviceRemoved(QDBusObjectPath)
kfilemodule(32309) KSambaSharePrivate::testparmParamValue: Running testparm ("-d0", "-s", "--parameter-name", "usershare path")
Traceback (most recent call last):
  File "./qtqr.py", line 481, in decodeFile
    if qr.decode():
  File "/home/fitzcarraldo/qr-tools-1.2/qr-tools/qrtools.py", line 147, in decode
    pil = Image.open(self.filename).convert('L')
  File "/usr/lib/python2.7/site-packages/PIL/Image.py", line 2256, in open
    % (filename if filename else fp))
IOError: cannot identify image file u'/home/fitzcarraldo/qr-tools-1.2/qr-tools/test.png'

Linux Magazine has a good article on these and other QR Code tools: Generating QR Codes in Linux.

UPDATE (March 30, 2015): You can download an updated working revision (Revision 20) of the Python script qrtools.py, and an updated working revision (Revision 21) of the Python script qtqr.py, from the QtQR and QR Tools developers’ repository where they have been working on an as-yet unreleased Version 1.4 of QtQR and QR Tools:


I have briefly tested qrtools.py Revision 20 and qtqr.py Revision 21 with the other QR Tools Version 1.2 files I downloaded earlier. I simply downloaded the Revison 20 qrtools.py file and the Revision 21 qtqr.py file and overwrote the qrtools.py and qtqr.py files I had extracted earlier from qr-tools-1.2.tar.gz into the directory /home/fitzcarraldo/qr-tools-1.2/qr-tools/ (and made them executable). With the new qrtools.py and new qtqr.py it is now possible for QtQR to decode QR Codes in image files as well as QR Codes scanned via a Webcam, so the bug I mentioned above should be fixed in the next official release of QtQR/QR Tools. So you may as well skip the official Version 1.2 and download all the files from the above-mentioned developers’ repository for the future Version 1.4.

How to create QR Codes easily in Gentoo Linux

QR Codes are two-dimensional bar codes that can store a surprising amount of information. CuterCode and Qreator are two applications that are easy to install and use to produce QR Codes that can be saved as image files for use on labels, posters, Web sites, business cards, documents, etc. Here is how to install CuterCode and Qreator in Gentoo Linux.

Example of a QR Code

A QR Code created using Qreator. You can read it using the Android app Barcode Scanner by ZXing Team and several other Android apps, and also using a Linux app (see my post on ZBar).


This is a Python script and simple GUI.


First download the script itself:

$ wget https://raw.githubusercontent.com/mnagel/cutercode/master/cutercode
$ wget https://raw.githubusercontent.com/mnagel/cutercode/master/cutercode.ui

Make the Python script exectuable:

$ chmod +x cutercode

Then install the package media-gfx/qrencode-python (it will pull-in the package media-gfx/qrencode) on which it depends:

# emerge qrencode-python

To launch the application:

$ ./cutercode

Use the Print Scrn key on your keyboard to launch KSnapshot (or whatever screen capture tool it is you use) and capture the QR Code to a JPG or PNG file for use in you documents. That’s it!


The UI of Qreator is more polished than CuterCode, and you have the options to save the QR Code as a PNG file, copy it to the clipboard, print it or edit its appearance.


Either merge it from Portage overlay dev-zero using layman:

# layman -S
# layman -a dev-zero
# emerge qreator

or download the dev-zero files into your local overlay and install it from there:

# mkdir -p /usr/local/portage/app-office/qreator/files
# cd /usr/local/portage/app-office/qreator
# wget http://data.gpo.zugaina.org/dev-zero/app-office/qreator/qreator-13.05.3.ebuild
# cd files
# wget http://data.gpo.zugaina.org/dev-zero/app-office/qreator/files/13.05.3-python-imaging.patch
# cd ..
# ebuild qreator-13.05.3.ebuild manifest
# emerge qreator

If you happen to be a KDE user, you will find a menu entry for Qreator is installed under ‘Applications’ > ‘Graphics’ in the KDE launcher, or you can launch it from the command line:

$ qreator

Background reading

QR Code – Wikipedia
QRcode.com – Answers to your questions about the QR Code


Get every new post delivered to your Inbox.

Join 68 other followers