#!/bin/sh
#******************************************************************
# edit-ns-preferences Time-stamp: <01/02/10 14:52:35 bav>
#******************************************************************
#                            Gerd Bavendiek  bav@epost.de  99-09-03
#
# Tiny hack for editing Netscape's preferences. Takes one of
# 1 manual
# 2 automatic
# 3 direct
# as an argument.
#-------------------------------------------------------------------

# Check argument 
case $1 in
   1|2|3 )
      TMPFIL=/tmp/.edit-ns-preferences.$$
      cp -p ~/.netscape/preferences.js ~/.netscape/preferences.js.pre
   ;;
   *)
      echo -e $0: 'Usage: edit-ns-preferences [1|2|3]\nwherein 1 is manual, 2 automatic and 3 direct'
      exit 1
   ;;
esac

# If network.proxy.type _not_ defined, put it in.
if grep ^user_pref\(\"network.proxy.type ~/.netscape/preferences.js > /dev/null; then
   # it's defined

    awk -v NETSCAPE_PROXY_TYPE=$1 '/^user_pref\(\"network.proxy.type\"\,/ {printf "%s %d);\n", $1, NETSCAPE_PROXY_TYPE; next}
{print $0}' ~/.netscape/preferences.js > $TMPFIL
else
   # not yet defined
    awk -v NETSCAPE_PROXY_TYPE=$1 '/^user_pref\(\"network.proxy.no_proxies_on\"\,/ {printf "%s\nuser_pref\(\"network.proxy.type\", %d);\n", $0, NETSCAPE_PROXY_TYPE; next}
{print $0}' ~/.netscape/preferences.js > $TMPFIL

fi

mv $TMPFIL ~/.netscape/preferences.js

exit 0


#  3) echo direkt
#  # wenn was drinsteht, rausschmeissen. wenn nicht, dann nicht.
#    awk '/^user_pref\(\"network.proxy.type\"\,/ {next}
# {print $0}' ~/.netscape/preferences.js > $TMPFIL
 


exit 0

   # The following line count shall make things a little bit saver
   if [ `cat ~/.netscape/preferences.js | wc -l` -ne `cat $TMPFIL | wc -l` ]; then
      echo $0: Error in editing ~/.netscape/preferences.js: linecount does not match
   else
      echo $0: ~/.netscape/preferences.js has been edited !
      mv $TMPFIL ~/.netscape/preferences
   fi
