#!/bin/sh

set -e

if [ "$1" != configure ]; then exit 0; fi

if [ -x /usr/bin/update-menus ]; then 
    update-menus
fi

if [ -x /usr/sbin/update-mime ]; then
    update-mime
fi

if [ -f /usr/sbin/dhelp_parse ]; then
  dhelp_parse -a /usr/doc/lynx
fi

if [ -z "`dnsdomainname`" ]; then
    DEFAULT="http://www/"
else
    DEFAULT="http://www.`dnsdomainname`/"
fi

trap "rm -f /etc/lynx.cfg-$$-[12] >/dev/null 2>/dev/null" 0 1 2 3 15

LINE1=`fgrep -n "STARTFILE:Not-Configured-Yet" \
    /etc/lynx.cfg | awk -F: '{print $1;}'`
if [ ! -z $LINE1 ]; then
    while true; do
	echo "Please enter the default URL to use if none is given when invoking lynx."
	echo "Default is $DEFAULT"
	echo -n "> "
	read STARTURL || true
	if [ -z "$STARTURL" ]; then
	    STARTURL="$DEFAULT"
	fi
	case "$STARTURL" in
	    http:*|ftp:*|news:*|nntp:*|gopher:*|file:*|/*)     URL=`echo "$STARTURL" | sed -e 's/\//\\\\\//g'`;\
		sed -e "$LINE1 s/Not-Configured-Yet/$URL/" /etc/lynx.cfg \
		> /etc/lynx.cfg-$$-1 && mv -f /etc/lynx.cfg-$$-1 /etc/lynx.cfg;\
		break;;
	    *) echo 'Error! You must enter either a full URL (including the "http://", etc.)';\
	       echo "or an absolute pathname."; echo;;
	esac
    done
fi

LINE2=`fgrep -n "#NNTPSERVER:news.server.dom" \
    /etc/lynx.cfg | awk -F: '{print $1;}'`
if [ ! -z "$LINE2" ]; then
    if [ -f "/etc/news/server" ]; then
	sed -e "$LINE2 s/#NNTPSERVER:news.server.dom/NNTPSERVER:`cat \
	    /etc/news/server`/" /etc/lynx.cfg \
	    > /etc/lynx.cfg-$$-2 && mv -f /etc/lynx.cfg-$$-2 /etc/lynx.cfg
    fi
fi

