a blog by Marius Gedminas

Sysadmin's diary

Many texts on Linux/Unix system administration advise you to have a diary and write down everything you do. I have finally realized the wisdom of this advice.

I use a simple shell script /usr/local/sbin/new-changelog-entry. This script adds the current date and time to a file /root/Changelog and opens it in a text editor. I usually have two terminals (or two tabs in GNOME Terminal): one has a root shell where I do things, the other has vi with /root/Changelog. I write down everything I change, and usually copy the exact commands I executed. This lets me redo the same thing very easily after OS upgrades, or on a different server.

Here are a couple of sample entries from my laptop:

2005-09-23 11:44 +0300: mg
  #
  # Overcoming the 2 GB limit with Samba: http://brianpuccio.net/node/664
  #
  vi /etc/auto.misc
    added 'lfs' to the options of all smbfs filesystems
  /etc/init.d/autofs reload

2006-02-17 10:48 +0200: mg
  #
  # Installing Firefox 1.5 (from Dapper) on Ubuntu Breezy
  #
  # (I do not want to upgrade half of my system, so I'll compile the Dapper
  # debs from source)
  sudo -u mg -s
    cd /home/mg/src/apt-sources/
    apt-get source firefox
    cd firefox-1.5.dfsg+1.5.0.1/
    dpkg-buildpackage -uc -us -b -rfakeroot
    # ...45 minutes later...
  cd /home/mg/src/apt-sources/
  dpkg -i firefox_1.5.dfsg+1.5.0.1-1ubuntu3_i386.deb \
          firefox-dev_1.5.dfsg+1.5.0.1-1ubuntu3_i386.deb \
          firefox-dom-inspector_1.5.dfsg+1.5.0.1-1ubuntu3_i386.deb \
          firefox-gnome-support_1.5.dfsg+1.5.0.1-1ubuntu3_i386.deb \
          libnspr4_1.firefox1.5.dfsg+1.5.0.1-1ubuntu3_i386.deb \
          libnspr-dev_1.firefox1.5.dfsg+1.5.0.1-1ubuntu3_i386.deb \
          libnss3_1.firefox1.5.dfsg+1.5.0.1-1ubuntu3_i386.deb \
          libnss-dev_1.firefox1.5.dfsg+1.5.0.1-1ubuntu3_i386.deb

Update: here's a similar idea that goes further (not just changelogs, but also description pages for each machine): My electronic sysadmin notebook for an entire fleet by Rachel Kroll.

Update 2: I packaged new-changelog-entry with a few other tools into a Debian package pov-admin-tools.

Unbreaking Firefox's address bar

I've always been annoyed that Firefox deletes the whole URL if you hit Ctrl+Backspace in the location bar. I'd like it to delete the last URL segment. It turns out that I can get this, if I go to about:config and set layout.word_select.stop_at_punctuation to true. Yay!

Sources:

Lightspeed EDGE-100M GPRS PCMCIA Card on Linux

Google doesn't know how to set up this card on Linux yet, so...

I use Ubuntu. Debian uses the same structure for pppd config files. Users of other distributions may have to adjust some things.

Here are the PPPD configuration files that work for me. They may contain some unnecessary things, but at least they work.

Substitute providername with any name you like, 1234 with your PIN, and apn with your GPRS APN ('banga' for Bite GSM users in Lithuania). Also, the device name might be different from /dev/ttyS2; check with dmesg | tail after you insert the card.

/etc/ppp/peers/providername:

# PPPD config file for Lightspeed EDGE-100M PCMCIA card
hide-passwd
noauth
connect "/usr/sbin/chat -v -f /etc/chatscripts/providername"
debug
/dev/ttyS2
460800
crtscts
defaultroute
noipdefault
user ignored
remotename whatever
ipparam whatever

usepeerdns

# These seem to be needed to avoid spontaneous automatic disconnects after 2
# minutes on some GPRS devices.
lcp-echo-interval 0
lcp-echo-failure 0

/etc/chatscripts/providername:

# Chat file for Lightspeed EDGE-100M PCMCIA card
# (it uses the Siemens MC75 GPRS module)
ABORT BUSY ABORT 'NO CARRIER' ABORT VOICE ABORT 'NO DIALTONE' ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT DELAYED
'' AT
OK AT+CFUN=1,1
SYSSTART AT+CPIN="1234"
OK '\c'
## # wait until the card registers with the network
## '' AT+CGREG=1
## OK '\c'
## '+CGREG: 1' '\c'
'' ATZ
OK ATX3
OK 'AT+CGDCONT=1,"IP","APN"'
OK ATDT*99***1#
CONNECT ""

You also need to add this line to /etc/ppp/pap-secrets:

ignored * ignored

To connect, type pon providername. If you get a permission error, make sure your user account belongs to the dialout group. You may monitor the progress of the connection with plog -f.

PySpaceWar lives!

During the last week I hacked on PySpaceWar extensively. I just released version 0.9.0 with these nice features:

  • Added an in-game menu.
  • You can drag the viewport around with the mouse (use the right button).
  • Automatic zoom in.
  • Much better source code organisation (and unit tests).
  • Distutils setup script.

It's the first time I've ever used distutils, so please let me know if it works for you.

screenshot

PySpaceWar, a game loosely inspired by the original Spacewar.

Seven segments

An interesting Python programming contest ended today. The task was to write the shortest Python module for converting a string of digits to seven-segment display format. The module was to be used like this:

>>> from seven_seg import seven_seg
>>> print seven_seg('0123456789')
 _     _  _     _  _  _  _  _
| |  | _| _||_||_ |_   ||_||_|
|_|  ||_  _|  | _||_|  ||_| _|

Solutions were measured with the Unix command wc -c seven_seg.py.

The shortest solution (by André Roberge, who is apparenly some kind of a genius) is 117 characters long. My best try was this 120-character-long one-liner of obfuscated Python:

seven_seg=lambda i,j=''.join:j(j(' _   _|_|_  | |'[ord('f\xda($\xbaDFZ64'[int(d)])>>r&14:][:3]for d in i)+'\n'for r in[6,3,0])

(Replace \xda and \xba with actual 8-bit characters, and make sure the file has no trailing newline to get a 120-byte long file.)

There is also a 30-character-long cheat that fools the test suite into thinking it is a valid solution:

class seven_seg(str):__eq__=id

It was fun to read about various solutions by other people in this thread on comp.lang.python, and in other places.

Update: Read André's Deconstruction of the 117-character solution (with insightful readers' comments about the Chinese Remainder Theorem).