View Full Version : iLiad My First SED Script (modifying er_registry)


Adam B.
07-17-2007, 03:39 PM
Soon (hopefully), everyone will be able to reflash their iLiad. This means that shell scripts that modify the internal configuration won't be dangerous. To that effect, adding new viewers to the registry will be useful.

I've started playing with SED in order to add new viewers to the registry. I've tested this on my PC, but I forgot my iLiad at home. It seems to work pretty well. Does anyone have any comments, suggestions, etc, for my scripts? This is literally the first exposure I've had to sed, so it may look a bit ugly.

run.sh
#!/bin/sh
export scriptdir=`/usr/bin/dirname $0`
cd $scriptdir
cp /mnt/settings/er_registry.txt /mnt/settings/er_registry.txt.orig
sed -i -f update.sed /mnt/settings/er_registry.txt

update.sed
s\uaIDList=\uaIDList=FBREADER;\g
/uaIDList=/ {
a\
[FBREADER]\
category=viewer\
arguments=<FILENAME>\
exec=/usr/local/programs/FBReader/fbreader.sh\
xResourceName=sh\
channel=14\
extensions=chm;CHM;fb2;FB2;rtf;RTF;tcr;TCR;oeb;OEB
}
/EXTENSION_INFO/ {
a\
chm=/usr/share/contentlister/Icon_books.png\
CHM=/usr/share/contentlister/Icon_books.png\
rtf=/usr/share/contentlister/Icon_books.png\
RTF=/usr/share/contentlister/Icon_books.png\
fb2=/usr/share/contentlister/Icon_books.png\
FB2=/usr/share/contentlister/Icon_books.png\
tcr=/usr/share/contentlister/Icon_books.png\
TCR=/usr/share/contentlister/Icon_books.png\
oeb=/usr/share/contentlister/Icon_books.png\
OEB=/usr/share/contentlister/Icon_books.png
}

Once an update comes that gives everyone unbricking support, I'll release this as a package. Or, if you'd like it to install or to test, and have the developer's version of the unbricking package, send me a PM.

Adam B.
07-19-2007, 07:54 AM
So I tried running this script on my iLiad with the busybox sed. It gave me the output: "sed: bad format in substitution expression"

However, I compiled the GNU version of Sed, ran that on the iLiad, and it did the replacement without a problem. I can distribute the gnu sed with the package, but I'd like to know why busybox doesn't like my sed script. Any ideas?

Antartica
07-19-2007, 10:18 AM
So I tried running this script on my iLiad with the busybox sed. It gave me the output: "sed: bad format in substitution expression"

However, I compiled the GNU version of Sed, ran that on the iLiad, and it did the replacement without a problem. I can distribute the gnu sed with the package, but I'd like to know why busybox doesn't like my sed script. Any ideas?

This one is easy: the separator you're using for the first sed command is not recognized by busybox's sed.

Just put the first command like this:
s:aIDList=:aIDList=FBREADER;:g

That is, using ':' as separator. For the rest of the readers: you can use any character you wish, usually it's chosen so that it minimises the need to escape characters in the regular expression or the substitution string..

Happy sed'ing :)

P.S.: I'm a big fan of sed -- it's a really useful command (and usually available, unlike awk or even perl :grin2:).
P.S.2: Not bad for your first exposure to sed :-o

Antartica
07-19-2007, 10:33 AM
I've started playing with SED in order to add new viewers to the registry. I've tested this on my PC, but I forgot my iLiad at home. It seems to work pretty well. Does anyone have any comments, suggestions, etc, for my scripts?

Suggestion: make it idempotent (that is, appliying twice the script have nil effect).

For that the easiest way is to first "unsinstall" the script changes (just in case it has been run before), and only then do the changes.

Examples:

For deleting and then re-adding the uaIDList part:
s/\(uaIDList=.*\)FBREADER;\(.*\)/\1\2/g;s/\(uaIDList=\)/\1FBREADER/g

For deleting the chunk:
/^\[FBREADER\]/,/extensions=chm;CHM;fb2;FB2;rtf;RTF;tcr;TCR;oeb;OEB/d