#! /bin/sh
# Copyright (c) 2004 SuSE Linux AG Nuernberg, Germany.  All rights reserved.
#
# Author: Joachim Gleissner <jg@suse.de>, 2004

# 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

test -n "$ROOT" && exit 0

INITIALIZED=$( /sbin/scpm status | awk '{ if ($1 == "enabled") print $3 }' )
test $INITIALIZED = no && exit 0

NEEDS_UPDATE=$( /sbin/scpm status | awk '{ if (($1 == "needs") && ($2 == "reinit")) print $4 }'  )
test $NEEDS_UPDATE  = no && exit 0

TMP=$(mktemp /tmp/scpm_upate.XXXXXX)
test -z "$TMP" && TMP=/dev/stdout

/sbin/scpm -x db set 'status*system' "`head -n 1 /etc/SuSE-release`" > $TMP
/sbin/scpm -x update_resources > $TMP
RESULT=$?

if [ $RESULT -eq 0 ]; then
    echo "Your configuration profiles have been updated."
    echo "Output of the update command was:"
    echo
    cat $TMP
    echo
    echo "Please read the section about updating in the info pages."
    echo "You can read them by calling 'info scpm' or open the URL 'info://scpm'"
    echo "in konqueror."
else
    echo "Update of your configuration profiles failed."
    echo "Output of the update command was:"
    echo
    cat $TMP
    echo
    echo "You may need to do a full reinit of SCPM."
    echo "Please read the section about updating in the info pages."
    echo "You can read them by calling 'info scpm' or open the URL 'info://scpm'"
    echo "in konqueror."
fi | mail -s "SuSEconfig: Configuration profile update" root

#touch /var/lib/update-mssages/scpm

exit 0

# SuSEconfig.scpm ends here
