Thursday, 30 May 2013

Use etckeeper to version-control your config files

etckeeper is a utility which keeps copies of your Linux (etc.) box's configuration files in a version control system. It ties into apt-get so each time you update/upgrade your system, your files in /etc are backed up. Which is nice. And of course you can request a snapshot of your /etc-files manually, before you start experimenting. Which is nice. Especially after you've munged your etc-file and stuff doesn't seem to work anymore. Been there, done that. xorg.conf i remember thee with pain.

As we use etckeeper here at work, i decided to install it on my home box. It was remarkably painless with a little help from a post from Evil Routers. I see no reason to repeat what's written there, so just follow the link. It's a five minute exercise and you'll be safe(r).

Now if i need to pick up the habit of always doing a cd /etc && sudo etckeeper commit before i touch an /etc-file -- or to find some mechanism that does it for me automagically :)

Wednesday, 29 May 2013

Re-installing a Mac with an older OSX

TL;DR To re-install an older OSX on a newer one, you'll first need a newer OSX install media to wipe the disk.

The workflow for paving a Mac with an older version of OSX than it's currently running is this:

  • From an external medium, run an OSX installation that is at least as new as the OSX currently running. An older installation won't start.
  • Start Disk Tools and erase the Mac's hard disk. Use the Journalling file system.
  • Boot with the older OSX installation media inserted and the Alt key pressed.
  • Install the older OSX.

 Frustrating when software doesn't let me Do Dangerous Stuff :)

Next time i'll just use dban. Let's see how that goes.

Monday, 20 May 2013

You'll need a tray

I needed (ok, i wanted) to print a few configuration files from the command line (Linux/OSX). While Unix may provide us the command lpr, the path i wanted to follow was nc (ie netcat). This turned out, shall i say, into a Learning Experience&tm;.

Gear involved: a Mac, a Linux server, a HP printer, patience and google.

The problems i encountered were:

  • Line endings. My files ended in a \n newline, whereas the printer wanted \r\n carriage return + newlines.
  • The printer wanting me to press the green checkmark button that i indeed wanted to print the file
  • nc which seemed to hang (but didn't)

Transforming one kind of line endings to another seems like a trivial thing. That's why we have the unix2dos and dos2unix utilities. Except they weren't installed on my Mac or on the Linux server i was going to print from. But hey, that's why you have sed. Except that sed seems to care for lines, not for files, so i ended up transforming the files with perl, thusly:

for F in *.conf; do perl -p -e 's/\n/\n\r/g' $F > $F.lpr ; done

This created seemingly identical files from the original ones, but with linefeeds changed to cr+lf. To validate, i ran my new favourite spell: od -a filename.conf.lpr, which dumps out all characters, including the "invisible" ones, in a geekly manner.

I then tried to print a file, by chanting cat somefile.conf.lpr | nc printer 9100. Three things did not happen. Netcat seemed to hang, the printer didn't print, and ... well, the printer didn't print. It felt like three things anyway. The printer didn't print because a) it didn't know which tray to print from, b) it was probably confused of the paper size, and c) when i tried sending the printer all the files, it threw away all but the first. Or last. The result was that to print the files, i had to netcat them one at a time, then run to the printer, press the green button twice, get my hardcopy, walk back to my terminal, press ^C and netcat the next one. Which was neither convenient nor elegant.

To remedy, i tried adding a form feed to each document:

for F in *.lpr; do echo -e '\f' >> $F ; done

Not sure it did anything though, because the above problem remained.

Problem one: the paper must automagically come from the right tray. Problem two: netcat must do its thing in a netcatly manner, ie deliver the payload and quit.

In my search for an answer to problem two, i came upon the answer to problem one. When one talks with the printer (in a Jetdirect manner, so to speak), the printer waits for more data until we politely tell it that that'll be all thank you very much and close the door. Which is nice and all, but not very productive.

The solution is to tell netcat to deliver the stuff, wait a second, and then hang up. Thusly:

cat somefile.lpr | nc -q 1 printer 9100

This restored normality in one second flat. Nice.

The final trick was the hardest, and it involved PJL. To prepare a spell to switch to tray four, speak thusly:

echo -e "\033echo -e "\033%-12345X@PJL
" > select-tray4.pjl

To have the page print, cast the following:

(cat select-tray4.pjl & cat somefile.lpr ) | nc -q 1 printer 9100

As always, there is probably a More Elegant way to do this, but hey, it works on my machine :)

works on my machine, starburst

Migration pains

Much to my dismay and displeasure, my favorite blogging platform Posterous was unplugged by their new overlords, which means i will need to move my old tech blog (not that it ever was overly techy, but at least it was more techy than my regular one) to another platform. I was never very close with Blogger, but having read about how Blogger now integrates some bits and pieces with Google+, i thought i'd give it a try. So here. First post. I hope i can get my earlier ones imported to happen before this. Or something. Time continuum is tricky. Great success - the move is compleated. The operation was non-trivial and Documented Elsewhere&tm; (here and in a few other places). The steps involved were:
  1. From Posterous (RIP), export your blog. This is a two step operation, where you first ask the UI to prepare your blog for separation, then come back later (you should be emailed but probably won't) to download a zip file with everything.
  2. Import a file to Wordpress. This included registering for a blog (free plan). The option is well hidden in your WP Admin, under Tools / Export. The file in question is named wordpress_export_1.xml and lives inside the zip you downloaded above.
  3. Export (yup) the blog from Wordpress. Clues above.
  4. Transform your Wordpress file into Blogger format, online if you dare.
  5. Import your transformed file into Blogger (admin dashboard - Settings - Other - Import).
  6. Wait for your blog to rebuild. Wait some more. Refresh. And your blog should be moved.