Thursday, October 22, 2009

Don't need KDE4 Network Manager now

How I configured wpa_supplicant for my home network. The router is a Linksys, the wireless security is configured for WPA Personal using the TKIP algorithm. I'm running Ubuntu 9.04 on an IBM Thinkpad T60p. This entry is not about how to configure the wireless card, so I won't describe the hardware any further.

First, see if wpa_supplicant is already running. If it's running with the -u option, then get rid of that daemon because it will interfere with running wpa_supplicant manually. I mucked around /etc and modified or renamed the following files or directories until wpa_supplicant no longer started up after a reboot:
  • /etc/wpa_supplicant (renamed it)
  • /etc/rc*.d/*wpa_ifupdown (renamed them)
  • /etc/dbus-1/system.d/wpa_supplicant.conf (renamed it)
  • /etc/readahead/boot (remove the wpa_supplicant entry)
I don't have the time to go back and figure out exactly which one of those did the trick, so if you have any more information feel free to share it in the comments.

Next, create /etc/wpa_supplicant.conf. Here is mine, without the secret information:
ctrl_interface=/var/run/wpa_supplicant

network={
ssid="home_network_ssid"
scan_ssid=0
key_mgmt=WPA-PSK
pairwise=TKIP
psk=secret_psk_code_from_wpa_passphrase
# or: psk="home_network_psk_secret"
}
Use wpa_passphrase to generate the psk code. There are many other ways to configure wpa_supplicant, this is just what worked for me. Make sure the configuration file can only be read by root.

Once the configuration file has been created, run wpa_supplicant:
sudo wpa_supplicant -c /etc/wpa_supplicant.conf -i wlan0
Add -B to run it in the background.

At this point, iwconfig wlan0 should show sensible values for the ESSID and access point
wlan0     IEEE 802.11abg  ESSID:"home_network_ssid"
Mode:Managed Frequency:2.437 GHz Access Point: 00:1E:E5:85:F8:23
Bit Rate=54 Mb/s Tx-Power=15 dBm
Retry min limit:7 RTS thr:off Fragment thr=2352 B
Power Management:off
Link Quality=88/100 Signal level:-44 dBm Noise level=-86 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
If not, you need to reconfigure /etc/wpa_supplicant.conf and restart wpa_supplicant. If the output of iwconfig shows that wlan0 is now associated with the network, then use dhclient to get an IP address (assuming you are using DHCP):
sudo dhclient -1 wlan0
Note that's a "1" (number one) and not a "l" (letter el). If that is successful then ifconfig wlan0 should show an ip address:
wlan0 Link encap:Ethernet HWaddr 00:13:02:20:31:a7
inet addr:192.168.0.101 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::213:2ff:fe20:31a7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16236 errors:0 dropped:0 overruns:0 frame:0
TX packets:12213 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9357389 (9.3 MB) TX bytes:2011051 (2.0 MB)
and "route -n" should show something like this:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 wlan0

Saturday, July 18, 2009

Vi command completion with konsole and pdksh

For some reason, Konsole version 2.2.2 overrides the "set -o vi" in my .profile and .kshrc. I know .kshrc is being obeyed because I set an environment variable that is retained. And I know it's Konsole because when I log into a console the command line is in vi editing mode.

After an hour poking around while S made breakfast (blueberry buttermilk pancakes with sausages - yum!), I found a way that works:
  1. Go to Konsole's Settings->Edit Current Profile...
  2. In the General tab click the Edit... button next to the Environment label
  3. Add a new line that says "EDITMODE=vi", right under the one that says "TERM=xterm"
  4. Click OK, until all the dialog windows are closed, and you're done.
I could pop a blood vessel deriding Konsole, it's very sparse documentation, and how this change in behaviour seems to have slipped in unannounced, but then again, I love this program too much. All is forgiven, now that I (and you, in case you were looking for it) have a solution. Just please don't do it again.

Wednesday, May 13, 2009

F@H as a daemon

I wanted Folding@Home to start up automatically every time the computer is rebooted. Using /etc/rc.local did not work: F@H would start and then get killed when rc.local finished. Fortunately fahwiki.net has an entry on how to start F@H from the init scripts. Based on that I created this script, /etc/init.d/folding1:
#!/bin/sh
#
# $Id: folding.init.d,v 1.2 2008/02/27 13:20:31 est Exp $
### BEGIN INIT INFO
# Provides: folding1
# Required-Start: $local_fs,$network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0
# Short-Description: Start folding@home client
### END INIT INFO

#Adapted from dhcp3-server init file

PATH=/sbin:/bin:/usr/sbin:/usr/bin

test -f $DAEMON || exit 0

. /lib/lsb/init-functions

#Configure these variables to suit your needs

MYUSER='myname' #Run as this user (Change this!)
WORKING='/home/myname/folding1/' #Process Working Directory (This is where the FAH client is stored)
NAME='fah6' #Process Name (This is the Folding @ Home executable name)
FOLDING_OPTS='-forceasm -smp 4'

#No need to edit below this line

DESC='Folding @ Home Client' #Process Description (Brief line to describe FAH)
DAEMON="$WORKING$NAME" #Full Path to the Daemon
MYPID="/var/run/$NAME.1.pid" #PID file

# single arg is -v for messages, -q for none
check_status()
{
if [ ! -r "$MYPID" ]; then
test "$1" != -v || echo "$NAME is not running."
return 3
fi
if read pid < "$MYPID" && ps -p "$pid" > /dev/null 2>&1; then
test "$1" != -v || echo "$NAME is running."
return 0
else
test "$1" != -v || echo "$NAME is not running but $MYPID exists."
return 1
fi
}

case "$1" in
start)

log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon -b -m --start --chdir "$WORKING" --chuid "$MYUSER" --quiet --pidfile $MYPID \
--exec "$DAEMON" -- $FOLDING_OPTS; then
log_end_msg 0
else
log_end_msg 1
exit 1
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
start-stop-daemon --stop --quiet --pidfile $MYPID
log_end_msg $?
rm -f "$MYPID"
;;
restart | force-reload)
test_config
$0 stop
sleep 2
$0 start
if [ "$?" != "0" ]; then
exit 1
fi
;;
status)
echo -n "Status of $DESC: "
check_status -v
exit "$?"
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}"
exit 1
esac

exit 0
Then run "update-rc.d folding1 defaults".

The script is named "folding1" because I actually run multiple folding clients on the same box. It still showed ~15% idle when running the first client with -smp 4 despite having only three cores, so why not? So I created similar scripts, folding2 and folding3, then made the necessary changes to indicate the different directories, and to delete the smp option.

Wednesday, February 11, 2009

Hooray, /etc/resolv.conf fixed!

A few things have been bothering me about my Linux install recently, so I spent about an hour fixing them this morning.

First, when I mistype a domain name or tried to visit a work web site while disconnected from the intranet, up popped the infamous Rogers search page. I'd put up with it long enough, and finally did what I should have done long ago: modify my router with static DNS, using these addresses
  • 4.2.2.1
  • 4.2.2.2
  • 4.2.2.3
Now I just get a good old fashioned "address not found" page load error. To whoever pays for the upkeep and maintenance of this service, Thank you, Thank you, Thank you.

Second, now that I've upgraded to Ubuntu Intrepid, vpnc did not seem to work as well as it did with Hardy. I think the dots are connected like this:
  • My router is configured to use DHCP to get an IP address from Rogers.
  • DHCP tells my router to use domain phub.net.cable.rogers.com
  • Network Manager uses /sbin/dhclient-script to add "domain phub.net.cable.rogers.com" and "search phub.net.cable.rogers.com" to /etc/resolv.conf when it gets an IP address from my router.
  • When I connect to work with vpnc, the domain line is replaced, but the search line is not
  • Consequently, "ping foo" fails, while "ping foo.work.com" works
After a bit of searching, the thing to do is this: apt-get install resolvconf. That installs a package that, if your VPN gateway sends some DNS server data, will fix up /etc/resolv.conf. So now when I'm connected to work, rogers is no longer searched.

Monday, January 12, 2009

xrandr 1.2

Added this to xorg.conf:
Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"

SubSection "Display"
Depth 24
Modes "1600x1200" "1400x1050" "1280x1024" "1024x768"
Virtual 3000 1200
EndSubSection
EndSection

Restarted X

Ran this as joe-user:
xrandr --output LVDS --auto --output VGA-0 --auto --mode 1280x1024 --right-of LVDS
and voila, dual display.

Friday, September 26, 2008

Firefox and Java plugin

What is it with Firefox and Java, why can't the plugin be installed without having to use the terminal? I'm running Kubuntu 8.04 (Hardy Heron), and I still need to set up a symlink to the plugin:

/usr/lib/firefox-3.0.3/plugins/libjavaplugin_oji.so -> /someplace/libjavaplugin_oji.so

This morning I tried to add the Java plugin on my daughter's (admittedly out-of-date) Ubuntu setup, and although the Firefox Plugin installer said it went well, it didn't actually do anything. For someone who's trying to just keep his / her children busy while they should really be working, this is not helpful.

Wishlist: one-click install of the Java plugin on any Linux browser.