#!/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&q=");'
OLDPREFG='user_pref("keyword.URL", "http://www.google.com/search?ie=UTF-8&oe=utf-8&q=");'
NEWPREF='user_pref("keyword.URL", "http:\/\/www.google.com\/search?ie=UTF-8&oe=UTF-8&btnI=I%27m+Feeling+Lucky&q=");'

umask 006

if test -f $PREFBACK; then
 PREFSET=1
 grep -F "$OLDPREFG" $PREFBACK > /dev/null && PREFSET=
 if test -z "$PREFSET" ; then
  sed -ie "s/$OLDPREF/$NEWPREF/" $PREFFILE
 else 
  NEWPREFS=`grep -v -F "$OLDPREFG" $PREFFILE`
  echo "$NEWPREFS" > $PREFFILE
 fi
 rm -f $PREFBACK
 chown user:users $PREFFILE
fi

exit 0
