Sunday, November 29, 2009

Transforming Caps Lock into the Super key

Crunchbang has a lot of great keyboard shortcuts configured by default, e.g. Super+W launches Firefox, Super+T launches the Terminal, and Super+F launches PCManFM, the greatest file manager ever.  I love the idea of using keyboard shortcuts to get stuff done faster but I think it is unfortunate that in Crunchbang they are paired with the Super key (a.k.a the "Windows" key).  There are still a few keyboards that don't have a Super key and on my Dell Inspiron 5100, it is located way out in the middle of nowhere above the Backspace key.

I have a few options to fix this, the most obvious being that I could go into my rc.xml file, which contains the key mappings, and change the paired key from Super to something else, like Ctrl, Shift, or Alt.  I was hesitant to do that for obvious reasons: I didn't want to lose the functionality currently provided by those keys.  So I decided to keep the keyboard shortcuts paired with Super but remap my Super key to Caps Lock to make it easier to get to.

Enter xmodmap.  Xmodmap is the Linux keyboard mapping tool and is probably part of every distribution.  Xmodmap is one of those tools that can do just about anything but it can be a little tricky to learn.  I started my quest with this fantastic tutorial, and ended up with a file called .Xmodmap in my home directory (i.e. /home/jizldrangs/.Xmodmap) that contained the following:

     keycode 66 = Super_L
     keycode 133 = Caps_Lock

According to the tutorial that should have worked, and it probably would have if I were trying to switch N and W, but as it turns out these utility keys, such as Super, Ctrl, Alt, and even Shift, require special steps because they are "modifiers".  To make a long story less long, here is what I ended up with in my .Xmodmap:

     clear lock
     add mod4 = Caps_Lock

After rebooting I have exactly what I wanted: Caps Lock is converted over to Super and doesn't turn on the Caps Lock or capitalize anything anymore.

Wednesday, November 25, 2009

Great command-line tools and tricks

This was on Hacker News this morning.  It is easily the best list of little-known command line tools and tricks I've seen.  Did you know that you can control MPlayer remotely from the command line?  Or that you can establish an SSH connection with a remote server, go to the server, and use the connection to access the client?  If not, you should check this out. 

http://www.tuxradar.com/content/command-line-tricks-smart-geeks

Saturday, November 21, 2009

My conkyrc file

I found a conkyrc file I really like and wanted to post it.

For those unfamiliar with conky, it is a utility that embeds information into your desktop. It was originally a system monitoring utility, but is very flexible and has been used to display things like the weather forecast, unread emails, rss feeds, playlists in Rhythmbox, text files that get modified frequently, and on and on. Conky is the name of the application itself and its config file is .conkyrc and is usually located in your home directory.  There are countless sites where people exchange their conkyrc files, so you don't even need to learn the conkyrc syntax to reap the benefits.  Just find one you like and slap it into your home directory.

I messed around with getting the weather on my desktop (which worked great after following a thread in the Ubuntu Forums), but when I was finished I realized that I only really wanted to do it to see if I could Get it Working and I wasn't really that attached to the idea of having the weather forecast on my desktop. In the end I settled on a more simplistic conky configuration: system information only. I found a really nice conkyrc file on the Crunchbang forums and am very happy with the results. I leared a lot about my system, mostly which processes are taking up resources and what kind of resources are being used most.

Anyways, here is the config file and I am providing a screenshot below.

# conky configuration
#
# The list of variables has been removed from this file in favour
# of keeping the documentation more maintainable.
# Check http://conky.sf.net for an up-to-date-list.
#
# For ideas about how to modify conky, please see:
# http://crunchbanglinux.org/forums/topic/59/my-conky-config/
#
# For help with conky, please see:
# http://crunchbanglinux.org/forums/topic/2047/conky-help/
#
# Enjoy! :)
##############################################
# Settings
##############################################
background yes
use_xft yes
xftfont Sans:size=8
xftalpha 1
update_interval 1.0
total_run_times 0
own_window yes
own_window_transparent yes
own_window_type desktop
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 200 200
maximum_width 200
draw_shades yes
draw_outline no
draw_borders no
draw_graph_borders yes
default_color white
default_shade_color black
default_outline_color white
alignment top_right
gap_x 12
gap_y 12
no_buffers yes
uppercase no
cpu_avg_samples 2
override_utf8_locale no

TEXT
${font sans-serif:bold:size=8}SYSTEM ${hr 2}
${font sans-serif:normal:size=8}$sysname $kernel $alignr $machine
Host:$alignr$nodename
Uptime:$alignr$uptime
File System: $alignr${fs_type}

${font sans-serif:bold:size=8}PROCESSORS ${hr 2}
${font sans-serif:normal:size=8}${cpugraph cpu1}
CPU1: ${cpu cpu1}% ${cpubar cpu1}

${font sans-serif:bold:size=8}MEMORY ${hr 2}
${font sans-serif:normal:size=8}RAM $alignc $mem / $memmax $alignr $memperc%
$membar

${font sans-serif:bold:size=8}DISKS ${hr 2}
${font sans-serif:normal:size=8}/ $alignc ${fs_used /} / ${fs_size /} $alignr ${fs_used_perc /}%
${fs_bar /}
SWAP $alignc ${swap} / ${swapmax} $alignr ${swapperc}%
${swapbar}

${font sans-serif:bold:size=8}TOP PROCESSES ${hr 2}
${font sans-serif:normal:size=8}${top name 1}${alignr}${top cpu 1} %
${top name 2}${alignr}${top cpu 2} %
$font${top name 3}${alignr}${top cpu 3} %
$font${top name 4}${alignr}${top cpu 4} %
$font${top name 5}${alignr}${top cpu 5} %

${font sans-serif:bold:size=8}NETWORK ${hr 2}
${font sans-serif:normal:size=8}IP address: $alignr ${addr wlan0}
ESSID: $alignr ${wireless_essid wlan0}
Connection quality: $alignr ${wireless_link_qual_perc wlan0}%
${downspeedgraph wlan0}
DLS:${downspeed wlan0} kb/s $alignr total: ${totaldown wlan0}
${upspeedgraph wlan0}
ULS:${upspeed wlan0} kb/s $alignr total: ${totalup wlan0}

Thursday, November 19, 2009

Introducing GSW Extreme 2009 (...or, The best game on Linux is Linux)!

I'm not a hard-core gamer, but I do enjoy an occasional game once in a while. There are a bunch of great ones available on Linux that I play once in a while, but I frequently find myself wondering which I enjoy more; the game or the joy of tinkering with Linux to get it to do more for me. Linux is so powerful and so flexible that what you do with it is only limited by your imagination (if you don't believe me, check these guys out). I'm frequently amazed at how often I will get an idea for what I would like Linux to do for me and after a little research I find someone who is doing it or something close enough that I can customize it for my purposes.

A friend of mine summed it up nicely in a blog post, "Linux can be the most addictive game ever devised". I totally agree. I refer to the "game" as GSW, Getting Stuff Working, and I can't stop playing. I'm a junkie (Mrs. Jizldrangs would back me up on that). I crave the feeling of personal achievement when I get some crazy idea in my head and then figure out how to Get it Working on my computer. I probably would have started this blog years ago if I hadn't.

It sounds pretty pathetic, and it is to a degree, but at the heart of it is a creative and inventive element that is part of human rationality. Our distinguishing characteristic as humans is to combine known, understood truths to form new, not-previously-known truths. I find the flexibility and power of the tools available on Linux to be a unique parallel to that activity. There are a bunch of little tools that "do one thing well" in accordance with the Unix tradition, and there are unlimited ways of combining them to do a lot of incredible things. Let your creativity roll!

As a matter of fact, if you're reading this blog, I'm probably in good company. So how are you going to get your next fix?

Saturday, November 14, 2009

When looking for hardware info, always turn to lshw first.

I recently discovered lshw, which is a tool that you run from the command line and it will print a lot of really useful information about the hardware attached to your computer. Not sure what model ATI video card came built-in with your laptop? Lshw knows.

It knows a lot more than that, too. It will also print information on your audio card, your network adapter(s), your processor(s), your expansion slots (such as PCI-E and PCI-X), your disk drive controllers, and on and on. It is really nice. Ask lshw first.

Hulu quest, Part 3: Crunchbang

In my quest for Flash that could handle Hulu videos, I started distro hopping and settled on Crunchbang 9.04. I've used Crunchbang before; it is basically a slimmed-down customization of Ubuntu, with all the bloat removed. Gnome and all of its various supporting applications such as Nautilus and Evolution have been stripped out and replaced with Openbox, a lightweight window manager and such applications as PCManFM, the lightening-fast file manager, Claws mail, Terminator, the terminal emulator, and a lot of the usual suspects like Firefox, Rhythmbox, VLC, AbiWord and Gnumeric, and Pidgin. It even comes with a few things that Ubuntu doesn't come with by default, such as Skype, MP3 and DVD playback capabilities, and our friend, the Adobe Flash plugin.

Crunchbang, like Ubuntu, automatically installed the drivers for my wireless card and I was back on the internet within minutes of completing the installation. I can't tell you what a relief it was to have wireless back after a few days of sitting in the corner of Mrs. Jizldrangs' office, tethered to the router with a LAN cable!

To make a long story short, I never did get Flash to where I could use Hulu. I tried a bunch of stuff after getting Crunchbang set up, such as installing libgl-mesa-dev, and after that didn't work I installed Hulu Desktop and that was pretty terrible.

The closest thing I had to success was when I went directly to Adobe's website and downloaded their Flash plugin for Linux. The version up there at the time of this posting is 10.0.32.18, and it didn't exactly give me smooth Hulu shows but the shows were the smoothest yet. You can get it by going to the Adobe's Flash Player Download Center, dropping down the menu at the bottom and selecting ".deb for Ubuntu 8.04+", then hitting "Agree and Install Now". That will download the package to your desktop. When it is finished you will have to install it using:

$ sudo dpkg -i /path-to-deb-package/install_flash_player_10_linux.deb

When I did that I received an error that there were 2 dependencies, libnspr4-dev and libnss3-dev that were not installed, so I did:

$ sudo apt-get install libnspr4-dev libnss3-dev

It took about 15 seconds to install those libraries, after which I reran the dpkg command above and I was in business (or, at least, as "in business" as I was going to get, considering that Hulu still wasn't watchable). If you do this, watch out for the update manager as it will try to "update" your flash player to the worse one in the repos.

So I spent several days distro hopping to get this working and came up empty-handed. I really don't understand why this is so difficult; I realize that this is an older laptop but it has been playing full-screen DVDs since Mrs. Jizldrangs bought it for grad school way back in 2003. It has a lot more memory now than it did back then, so it seems like it should definitely be able to handle these lower-quality videos on the web. On the other hand, my desktop, which is a quad-core machine with more RAM and a much newer graphics card, handles Flash just fine, so I guess that either my laptop doesn't have the resources or the hardware is not adequately supported under Linux (it has an ATI Radeon Mobility 7500, and I've seen several forum posts saying that ATI, now AMD, is dropping support for it after a certain version of Xorg; that angle may be worth chasing down).

Hopefully some of my future posts will be about how I was actually sucessfull in getting stuff to work...

Meet my personal Linux butler, Cron

I'm a busy man (who isn't?), so I find it important to be able to automate as many tasks as possible. That's why I have a personal Linux butler, Cron. Cron is the unix scheduler, and it has saved me a bunch of time by taking care of my backups, checking for updates, podcast aggregation, and file synching for me.

There are a lot of great tutorials on how to use Cron out there; I learned on Chess Griffin's fantastic but now-defunct Linux Reality podcast (which I highly recommend if you're just starting with Linux).

Cron offers a lot of choices as to when jobs are run. You can have it run a job every minute, every third hour, at 4:15 in the morning on the second Saturday of the month. And since the Linux command line is so powerful, almost any task can be scripted, which makes Cron a viable option for almost any repetative task.

So any time you run up against some task that you find boring but feel the need to do every so often so that you don't fall behind, consider asking your personal Linux butler to take care of it for you.

Getting Cron to provide you with feedback, such as when updates are available, is another matter that I will discuss later...

Thursday, November 12, 2009

Update Notifications in Crunchbang

I've been running Crunchbang for just over a week now and I'm loving it. The slimmed-down, speedy configuration suits me perfectly.

There is one thing that we took for granted in Ubuntu that is sadly lacking in Crunchbang: update notifications. When updates are available in Ubuntu, you get an icon in the system tray or a window that pops up informing you that it is time to update. In Crunchbang, you're on your own when it comes to knowing when, or even remembering, to update.

Fortunately you've all met my personal Linux butler, Cron, and this is a perfect job for him. We could just have "apt-get update; apt-get upgrade" run every day, and all updated packages would be downloaded and installed without you having to lift a finger. I'm sure this will be the way many people prefer to do things, but I like to have a little more control than that. I like to have the final say as to what software is installed on my computer, so I would rather be notified when updates are available.

To accomplish this I am going to set up 2 cron jobs: one for the root account and one for my user account. In a terminal, run "sudo crontab -e" and enter the following line:

45 * * * * apt-get update; apt-get -s upgrade | grep -c ^Inst > /var/cache/apt/number-of-updates

This line runs every hour on the 45s and updates the apt-get database, then it does an upgrade with the -s option, which "simulates" the upgrade, meaning that it doesn't actually do the upgrade but it displays the text as though it did. This text is piped through grep, which searches for the "Inst" string at the beginning of the line (which indicates that a package is to be installed by the upgrade). The -c option tells grep to output the number of matches, which is stored in the text file located at /var/cache/apt.

Don't forget to create the text file and give all users read permissions to it:

sudo touch /var/cache/apt/number-0f-updates
sudo chmod 644 /var/cache/apt/number-of-updates

Thus far we have a way of getting the number of updates available saved to a text file. Now we need to display the number using the dbus notification system. This is going to require several lines of bash commands, so we will need to create a script to call from cron. Open a new text file and insert the following into it:

#! /bin/sh

NumOfUpdates=$( cat /var/cache/apt/number-of-updates )

if [ $NumOfUpdates != "0" ]; then
notify-send -u normal -t 5000 -i info "System Updates" "There is/are ${NumOfUpdates} update(s) available"
fi

This short bash script reads the number of available updates from the file specified above, and if the number is not 0, it uses notify-send to display a notification in the corner of your screen for 5 seconds. Go ahead and run it using "sh file-name" if you want to see the notification (note: notify-send is installed by default on Crunchbang but it wasn't installed by default in Ubuntu last time I checked; you will have to install the package bnotify-bin" if it isn't already installed).

Save it somewhere you will remember. Now go into your own cron config file by typing "crontab -e" and enter the following:

30 * * * * sh /path-to-your-script/script-file-name

If we were to save this change, cron would not be able to display the notification. That's because cron does not have a handle to the current display, so when notify-send tries to display the notification, it doesn't have a display to show it on and the notification is lost in the ether. This is easy to fix by making sure we set the appropriate environment variables before saving the crontab file. At the top of the crontab file, insert the following:

USER=yourr-user-name
HOME=/home/your-user-name
SHELL=/bin/sh
DISPLAY=:0.0
MAILTO=your-user-name
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/home/your-user-name/bin

There is a chance that not all of these variables are actually used, but I like to include them anyway; there's no reason not to. As an example, here is the entire contents of my crontab file:

USER=jizldrangs
HOME=/home/jizldrangs
SHELL=/bin/sh
DISPLAY=:0.0
MAILTO=jizldrangs
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/home/jizldrangs/bin

# m h dom mon dow command
30 * * * * sh /home/jizldrangs/bin/notify-updates

Save your crontab file and you're done! Now whenever updates are available you will get a notification in the corner of your screen that looks something like this:


Wednesday, November 11, 2009

Hulu quest, Part 2: OpenSUSE

Ubuntu 9.04 was working just fine on my laptop. It did everything I needed it to do, and we lived happily until one fateful day when I tried to watch a show on Hulu. My Flash plugin couldn't handle the content, so I decided to do some distro hopping to see if I could get it working.

My first stop was OpenSUSE 11.1. I lost some time trying to use the network installer, which I chose because it was a smaller download, and after messing with it a bunch I was able to get it to start the install, but it got stuck on Step 2 of 6. It was probably doing stuff in the background, but I didn't feel like waiting all night for it to give me more feedback, so I abandoned the network installer and installed OpenSUSE using the KDE Live CD.

OpenSUSE showed a lot of promise for the first ten seconds or so, because that's how long I used it before I realized that my wireless card wasn't working. I have a Netgear PCMCIA wireless G card that I've had forever and have been able to get it working on multiple machines using Ubuntu, Debian, Fedora, and Slackware. It works right out of the box on Ubuntu, and for the other distros I've used ndiswrapper along with wpa_supplicant so that it will connect to my WPA wireless network with no problems. I've built up a decent bag of tricks for getting this card working over the years, so I was pretty confident that this would turn out to be a minor annoyance and I would be able to move on before long.

I installed the card drivers using ndiswrapper and went into knetworkmanager to connect it to the wireless. I could see the wireless network, and when trying to connect to it it looked like the WPA key was accepted but it hung and eventually failed trying to get an IP address. I got the same results using YaST2. I also tried using ifup from the command line but the laptop refused to pick up an IP address. I tried giving it a static IP address and that appeared to work but I couldn't browse the web from Firefox. This was clearly going to take some elbow grease, if I was going to get it working at all.

I pulled out all the stops and tried pretty much every set of instructions I could find, including totally removing knetworkmanager and installing Wicd. I've used Wicd before and it is a fantastic network manager but it couldn't detect the wireless card, which is odd because knetworkmanager detected it just fine under ndiswrapper.

At some point I decided to return to the initial goal of installing OpenSUSE, which was getting Hulu to work. I got the Adobe Flash plugin installed and browsed to Hulu, but it was worse than anything I saw on Ubuntu. My Hulu show looked more like a slideshow than a motion picture. I'm sure there are settings that can be tweeked to speed it up, but I was fed up. Just a few hours short of 2 days after installing OpenSUSE I wiped it and moved on to the next leg of my quest: Crunchbang.

Hulu quest, Part 1: Ubuntu gets the axe

I have an old Dell Inspiron 5100 laptop that has a Pentium 4 processor, and came with 256 megs of RAM, which I upgraded to 1 gig, the max for this unit. I'm not trying to game on it or anything (that's what my desktop PC is there for); I generally just use it for the less resource intensive computing tasks.

I was running the "flashplugin-nonfree" plugin, which is the official Flash plugin from Adobe, and to its credit it generally worked pretty well. Grooveshark and Homestar worked just fine, and YouTube worked OK as long as the video wasn't too long, so up until this point I didn't have any complaints. But suddenly my wife and I started watching a few shows a week on Hulu and my Flash plugin fell flat on its face.

It fell hard, too. The show would play for about 1 minute, then the picture would freeze for a few seconds, then pick up for a few seconds and freeze again, with the audio cutting in and out accordingly. Needless to say this does not make for a relaxing evening, so I started a quest to get Hulu working on my laptop.

I Googled all over the place and tried a bunch of stuff to get it working. I created the config file /etc/adobe/mms.cfg and added "OverrideGPUValidation=true" to it and that didn't work. I tried Gnash and Swfdec and both were worse than the Adobe plugin. I tried installing libflashsupport but that didn't help (I found out later that this library was created for earlier versions of Flash and Flash 10 no longer needs it). I even tried using Hulu in Seamonkey to see if the problem was in Firefox, but no dice. I read in several locations that recent versions of Ubuntu had messed with some of the PulseAudio settings and this was the cause of the problem, so I decided to do a little distro hopping to see if the grass really was greener on the other side.

More on that later...

How I finally got my Samba share mounted under Crunchbang

I've been running Crunchbang 9.04 for a little less than a week and although almost everything has worked like a charm so far, I had a heck of a time getting my Samba share to mount. Crunchbang does not come with Nautilus installed; it comes with PCManFM, which is very fast and I love using it normally, but it is totally unable to mount Samba shares like Nautilus can.

There are a wide vareity of tools available under Linux that will connect to a Samba share, most of which don't actually mount the share, instead connecting over the smb protocol (you have probabably seen "smb://" in the address bar of Nautilus or Konquerer at some point; that's why). I could have tried something like that but actually mounting the drive seemed like the way to go on Crunchbang, since that way any file manager would be able to browse it, and the Samba mounting utilities have been part of Linux forever, so they should work pretty well under any distro, right? I've used "mount -t smbfs", "mount -t cifs", "mount.smb", "mount.cifs" in other distros with no problems, but for some reason on Crunchbang each time I got various error messages that I didn't record.

I spent several days Googling and trying out various alternative options like fusesmb, smbnetfs, and gigolo. Fusesmb and smbnetfs are supposed to be userspace apps where you give it a directory and it sets up all of the shares on your local network inside that directory. It seemed great; I didn't even need root permissions! Filled with hope, I ran "smbnetfs ~/network" and then browsed into the "network" folder, only to find my wife's Windows laptop listed but not the Samba share I'm trying to get to. It was insanely frustrating and I almost gave up and went back to Ubuntu.

To make a long story short, I eventually got it working in 3 steps:
  1. I installed smbfs, which is not included in Crunchbang by default, by running "sudo apt-get install smbfs"
  2. I created a new directory to mount my samba share by running "mkdir ~/smbshare"
  3. I mounted the share inside the new directory by running "sudo mount.cifs //ServerIPAddress/jizldrangs ~/smbshare -o username=jizldrangs, password=mypassword".
Concerning Step #3, you may be thinking what I thought: "I don't want to type in my password into the line because it will be displayed on the screen; I'll just run the base command without the options and wait for it to prompt me for a password." Hold on there, hotshot, you are about to subject yourself to the same several hours of frustration that I subjected myself to. You have to put the username and password into the command the way I specified above; I read somewhere that there is a bug with the mount command when used with smbfs such that it won't work unless you actually type you username and password into the command. Major bummer, huh?

I only needed to do this once, so it worked out just fine for me, but if you have to do this a lot, or want to script it and don't feel comfortable storing your password in a script, you can also do the following:
  1. Create a new text file containing the username and password in the format specified above except on separate lines (i.e. put "username=yourUserName" on the first line and "password=yourPassword" on the second line).
  2. Save it somewhere out-of-the-way.
  3. Change the owner to root by running, "sudo chown root /path-to-file/file-name"
  4. Remove all permissions except read and write by the owner (which we just set to root) by running "sudo chmod 600 /path-to-file/file-name". This will ensure that only the root user can read the file containing your credentials.
  5. Modify the mount command above to, "sudo mount.cifs //ServerIPAddresss/share-name /path-to-mount-directory/mount-directory-name -o credentials=/path-to-file/file-name"
HTH!

Hello World!

The Linux Rhino is intended to be a place where I can share tips on how I got stuff to work in Linux. I have been using Linux for the past 4 years and figured that it is past time to start giving back to the community. I hope you find something helpful here!