#!/bin/sh
set -e
PREFFILE=/home/user/.mozilla/microb/prefs.js
PREFBACK="$PREFFILE.keywordurlstate"

OLDPREF='user_pref("keyword\.URL", "http:\/\/www\.google\.com\/search\?ie=UTF-8&oe=UTF-8&btnI=I%27m\+Feeling\+Lucky&q=");'
OLDPREFG='user_pref("keyword.URL", "http://www.google.com/search?ie=UTF-8&oe=UTF-8&btnI=I%27m+Feeling+Lucky&q=");'
NEWPREF='user_pref("keyword.URL", "http:\/\/www.google.com\/search?ie=UTF-8&oe=utf-8&q=");'
NEWPREFG='user_pref("keyword.URL", "http://www.google.com/search?ie=UTF-8&oe=utf-8&q=");'

umask 006

PREFSET=1
grep -F "$OLDPREFG" $PREFFILE > /dev/null && PREFSET=
cp $PREFFILE $PREFBACK
if test -z "$PREFSET" ; then
 sed -ie "s/$OLDPREF/$NEWPREF/" $PREFFILE
else
 echo "$NEWPREFG" >> $PREFFILE
fi
chown user:users $PREFFILE $PREFBACK
exit 0
