#!/bin/sh
# gfsadd -- install a package.

# Copyright (C) 2004 Henrik S. Hansen

# Author: Henrik S. Hansen <hsh@freecode.dk>
# $Date: 2004/10/24 13:57:55 $
# $Revision: 1.5 $

# This file is part of gfs.

# gfs 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.

# gfs 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.

# You should have received a copy of the GNU General Public License
# along with gfs; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


# Synopsis: gfsadd install_command package.

# Log the installation of a package.  Creates a log of files installed
# by the package.  The log is called /usr/share/gfs/<package>.addlog.
# Usually, the install command is 'make install', or similar.  First
# line of the log file is '# install_command', second line is '#
# current_date.  Subsequent lines are files installed.  If the log
# file exists, it is appended to.

# If package was previously deleted, the files <package>.dellog and
# <package>.deleted exists.  They are now deleted, to ensure consistency.


if [ $# -ne 2 -o -z "$1" -o -z "$2" ] ; then
    echo "Usage: $0 command package"
    exit 1
fi

inst=$1                         # Install command
log="/usr/share/gfs/$2.addlog"  # Log file

# Remove stale .dellog and .deleted files
rm -fv /usr/share/gfs/$2.dellog /usr/share/gfs/$2.deleted >&2

# Ignore these dirs
ignore="/proc /tmp /root /home /usr/src /dev /mnt /var/lock /var/log /var/run /var/spool"
ignore=$(echo $ignore | \
    sed -e 's@ @$\\\)\\\|\\\(^@g' -e 's@^@\\\(^@' -e 's@$@$\\\)@')

startdate=$(mktemp)
touch "$startdate"
sleep 1                         # Make sure timestamps are newer
$inst

tmplog=$(mktemp)
find / -regex "$ignore" -prune -o -newer $startdate -print > $tmplog
echo -e "# $inst\n# $(date)" | cat - $tmplog >> $log

rm -f $startdate
rm -f $tmplog
