#! /bin/sh
# $Id: softupdate,v 1.5 2003/12/29 11:58:07 lange Exp $
#*********************************************************************
#
# softupdate -- update software packages on a running system
#
# This script is part of FAI (Fully Automatic Installation)
# (c) 2001-2002 by Thomas Lange, lange@informatik.uni-koeln.de
# Universitaet zu Koeln
#
#*********************************************************************
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# A copy of the GNU General Public License is available as
# `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
# or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html.  You
# can also obtain it by writing to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#*********************************************************************

# assuming that the install client now belongs to the same classes the time
# it was installed. If the host should belong to other classes, please
# reinstall it. (TODO: a feature to redefine the classes by calling
# the scripts in class/)

# this is a first hack of an update script. It's not tested yet!!!

set -e # abort on any error
set -a # export all variables

instlogs=/var/log/fai/localhost/install

die () {

    echo "$@"
    exit 99
}

# currently the subroutine definitions aren't install by default
source /usr/share/fai/subroutines

[ ! -d $instlogs ] && die "Can't find $instlog. Seems that this host wasn't installed with FAI."

[ -f $instlogs/bootp.log ] && source $instlogs/bootp.log
[ -f $instlogs/dhcp.log ] && source $instlogs/dhcp.log

# TODO: only try if renew flag set
# renew flag will mean, reevaluate scripts for class definition and don't use them from a file
# grep -q "Sending DHCP requests" $instlogs/dmesg.log && get_dhcp_info
# grep -q "Sending BOOTP requests" $instlogs/dmesg.log && get_bootp_info

# overwrite values from bootp,dhcp
FAI_ROOT=/
target=/
ROOTCMD=

[ -f /etc/fai/fai.conf ] && source /etc/fai/fai.conf
[ "$FAI_LOCATION" ] || die "\$FAI_LOCATION not defined."
[ -d /fai ] || mkdir /fai
mount -o ro $FAI_LOCATION /fai &&
      echo "/fai mounted from $FAI_LOCATION"

# source user specific subroutines
[ -f /fai/hooks/subroutines ] && . /fai/hooks/subroutines

task mirror
# if renew define_classes else
classes=$(cat /var/log/fai/localhost/FAI_CLASSES)


# now update the packages
apt-get update
task_instsoft
apt-get -f -y dist-upgrade </dev/null

umount /fai
if [ "$FAI_DEBMIRROR" ] && umount $MNTPOINT
echo "Update finished."
