#! /bin/sh
# Copyright (c) 2000-2002 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# Author: Burchard Steinbild, 1996-97
#         Bernhard Kaindl <bk@suse.de>, 1999
#         Rüdiger Oertel <ro@suse.de>, 2000-01
#
# This module generates some files for the news subsystem

# check if we are started as root
# only one of UID and USER must be set correctly
if test "$UID" != 0 -a "$USER" != root; then
    echo "You must be root to start $0."
    exit 1
fi

r=$ROOT

test -f $r/lib/YaST/SuSEconfig.functions || {
    echo "ERROR - can not find $r/lib/YaST/SuSEconfig.functions!!"
    echo "This should not happen.  Exit..."
    exit 1
}
. $r/lib/YaST/SuSEconfig.functions

for i in $r/etc/sysconfig/suseconfig $r/etc/sysconfig/mail $r/etc/sysconfig/news ; do
  if test ! -f $i ; then
    echo "No $i found."
    exit 1
  fi

  . $i
done

if test -n "$ENABLE_SUSECONFIG" -a "$ENABLE_SUSECONFIG" = "no" ; then
    echo "SuSEconfig is disabled in $r/etc/sysconfig/suseconfig."
    echo "Exit..."
    exit 0
fi

my_test_for_space $r/var/lib/news || exit 1

test -n "$ORGANIZATION" && {
    echo "$ORGANIZATION" > /etc/organization.SuSEconfig
    check_md5_and_move /etc/organization
}

test -n "$NNTPSERVER" && {
    echo "$NNTPSERVER" > $r/etc/nntpserver.SuSEconfig
    check_md5_and_move $r/etc/nntpserver
}

test -n "$FROM_HEADER" && {
    echo "$FROM_HEADER" > $r/etc/inews_mail_gateway.SuSEconfig
    check_md5_and_move $r/etc/inews_mail_gateway
}

if test -n "$FROM_HEADER" -a -d $r/var/lib/news/ ; then
    echo "$FROM_HEADER" > $r/var/lib/news/mailname.SuSEconfig
    check_md5_and_move $r/var/lib/news/mailname
    echo "$FROM_HEADER" > $r/var/lib/news/whoami.SuSEconfig
    check_md5_and_move $r/var/lib/news/whoami
fi


