My phone’s bash.profile

Here is some automation that I put into my bash.profile. It’s all done with aliases, since with regular shell scripts, I would first have to remount /mnt/sdcard without ‘noexec’. Like this, I just need to open a ConnectBot “Local” connection, type the alias, and press enter(*).

(*) For this to work, the ‘post login automation’ entry of the ConnectBot “Local” profile needs to have
bash --rcfile /sdcard/bash.profile
in it.

Here is what I have in there:

alias bb="busybox"
alias top="bb top"
alias df="bb df"

alias ll="ls -l"
alias n="su -c \"netstat -ntupl\""

alias backupdata="su -c \"rsync -rP --delete --numeric-ids --chmod=u+rwX --exclude Music /sdcard/ pat@192.168.0.2:/data/pat/g2sd/\""

alias postflash="echo \"Mounting /system read-write\" && su -c \"mount -o rw,remount /system\" && echo \"Copying modified keyboard layout files...\" && su -c \"cp /sdcard/vision-keypad-wwe.kcm.bin /system/usr/keychars/\" && su -c \"cp /sdcard/vision-keypad-wwe.kl /system/usr/keylayout/\" && echo \"Deleting awful camera click sound...\" && su -c \"rm /system/media/audio/ui/camera_click.ogg\" && sync && echo \"All done. Please reboot now.\""

clear
uptime
echo

The first couple of aliases should be self-explanatory.
backupdata is, as the name suggests, to get my SD card’s content to my home server.
postflash is for after flashing a new ROM (usually a CyanogenMod nightly build). It gets my modified keyboard layout into place, and deletes the terrible sound file that gets played when I take a photo with the phone’s camera.

emerge output ends up as attachment.bin when sent with nail / Heirloom mailx

I really like the command line mailer Heirloom mailx (formerly nail), and now there is even a current version in portage again (still under the name mail-client/nail, but that doesn’t matter), so that’s even better. I use it on all servers, since it’s just convenient – it can handle attached files, UTF-8 etc. without any problems.

But there was one problem that bothered me for months already: It involved my check_updates.sh script, which basically just calls /usr/bin/emerge -upvDN --nospinner world for the host and all virtual servers, and then sends the output to me.

The problem: emerge’s output always ended up as ‘attachment.bin’, attached to the (otherwise empty) mail, although I piped it into mail -s "Updates for $DATE" root where it should come out as the mail body. I knew that Heirloom mailx does that, as soon as it doesn’t “like” one of the characters in the input, but I couldn’t think of a reason why it would do that with emerge’s supposedly plain-ASCII output.

Today I had enough of it, and fired up hexdump to investigate said ‘attachment.bin’, using the following command:
hexdump -e '1/1 "%03d \n"' attachment.bin | sort -u
It outputs the unique decimal values of any byte occurring in ‘attachment.bin’ as a sorted list. I expected to find something above 127 – but the highest occurring value was 122 (“z”). I then checked the top part of the list, and to my surprise, found 008 (backspace) there. After removing those by piping the output through tr -d '\010' (8dec = 10oct, and tr needs octal values), Heirloom mailx no longer put the text into ‘attachment.bin’. It now appears in the mail’s body, where it belongs.

By the way, those backspaces (when interpreted) change
Calculating dependencies ... done!
to
Calculating dependencies... done!
… so removing them is not a big loss. I’d like to know though, why they are there in the first place, even though the output doesn’t go to a TTY.

Geek-Symbole und Umlaute für G2 mit QWERTY-Tastatur

Ich habe mir ein neues Telefon zugelegt – wieder ein Android, nachdem Nokia MeeGo nicht durchzieht, und sich stattdessen zum Microsoft-OEM-Hersteller degradieren lässt…
Da ich viel und häufig Kommandos via SSH tippe, kam wieder nur ein Telefon mit voller Tastatur in Frage, und somit ist meine Smartphone-Historie nun 9300i → G1 → G2.

Auf der Tastatur des G2 (auch HTC Desire Z oder HTC Vision genannt) lässt es sich sehr gut tippen, doch leider fehlen essentielle Symbole, die jeder der irgendwas in eine Shell eintippen will, oder irgend etwas programmieren will, unbedingt braucht – beispielsweise geschweifte Klammern ({}), eckige Klammern ([]) und spitze Klammern (<>). Sogar die Pipe (|) fehlt. Ich fasse diese Symbole im Folgenden unter dem Begriff “Geek-Symbole” zusammen. Das war auf dem G1 übrigens anders – es gab dort alle Geek-Symbole, aber da hatte die Tastatur auch eine zusätzliche Tastenreihe.

Weiterhin hat mein G2 eine QWERTY-Tastatur, QWERTZ war hier nicht verfügbar – damit kann ich zwar über Taste-lang-drücken Umlaute schreiben, jedoch geht das z.B. im Terminal (ConnectBot) nicht, davon abgesehen dass es umständlicher ist als eine direkte Tastenkombination.

Um Problem 1 (fehlende Geek-Symbole) zu beheben, hat teferi das QWERTY-Layout modifiziert (Thanks, teferi!), und dabei auch die Tools und den Prozess den er verwendet hat, zur Verfügung gestellt / beschrieben. Sehr schön, so sollte das immer sein 🙂
Damit habe ich nun ein Layout gebastelt, das auch Problem 2 (fehlende Möglichkeit Umlaute einzugeben) löst. Nach Installation der Keymap-Datei hat man zusätzlich folgende Symbol-Tastenkombinationen:

\ left-soft
| shift left-soft
` alt left-soft
[ middle-soft
{ shift middle-soft
< alt middle-soft
] right-soft
} shift right-soft
> alt right-soft
^ alt z
ä shift alt a
ö shift alt o
ü shift alt u
Ä shift alt q (*)
Ö shift alt w
Ü shift alt e
ß shift alt s

(Bekommt man Tabellen in WordPress irgendwie besser hin als mit good old HTML?)

(*) Hier ist mir nichts besseres eingefallen, als einfach bei den ersten Buchstaben der Tastatur (Q, W, E) anzufangen – falls jemandem etwas besseres einfällt – bin für Vorschläge offen 🙂

Kurze Anleitung, wie man das Layout auf’s Telefon bekommt:

  1. g2-keymap-0.3-ger.zip herunterladen
  2. g2-keymap-0.3.zip auf das Telefon unter /sdcard entpacken
  3. Über ‘adb shell’ oder direkt im Terminal auf dem Telefon folgende Kommandos eingeben:

    mount -o remount,rw /system
    cp /sdcard/vision-keypad-wwe.kl /system/usr/keylayout/
    cp /sdcard/vision-keypad-wwe.kcm.bin /system/usr/keychars/
    sync
    reboot

Update (2011-05-23): Seit ca. CyanogenMod Nightly Build 80 funktionierte mein Keymapping nicht mehr. Ich habe nun herausgefunden, dass Android seit neuestem ein ‘-wwe’ im Dateinamen erwartet, also nun vision-keypad-wwe.kl und vision-keypad-wwe.kcm.bin anstatt wie bisher vision-keypad.kl und vision-keypad.kcm.bin. Ich habe die Dateien im obigen ZIP-Archiv umbenannt, und nun selbst eine leicht modifizierte Anleitung in den Artikel übernommen, sodass sie für aktuelle Builds funktioniert. Ich habe nicht getestet, ob ältere Builds mit dem ‘-wwe’ klarkommen, oder ob man das aus den Dateinamen dann wieder entfernen muss.