#! /bin/sh
# fscfg_snapshot.sh -- take a snapshot of the filesystem configuration
#
# $Header: /src/cvs/www/genema/html/proj/fscfg_snapshot.sh,v 1.2 2002/11/16 02:48:40 ejritz Exp $
#
# Purpose:
#	Prior to upgrading an OS release I usually take a snapshot of 
#	the state of my disks so that I trash only the partitions I
#	don't care about.
#
# Usage:
#	./fscfg_snapshot.sh > fscfg-hostname-yymmdd.txt
#
# Files:
# 	depends on /sbin/fdisk and a number of other standard unix
# 	utilities.  Useful output is directed to stdout, so you decide
# 	where to put it.
#
# Exit Codes:
#	 0	-- success
#	-1	-- general failure
#
# Revision History:
#	$Log: fscfg_snapshot.sh,v $
#	Revision 1.2  2002/11/16 02:48:40  ejritz
#	redirect prompt to stderr
#	
#	021115 ejritz 0 created csrc 
#
# Todo:
#	Still very much in the quick and dirty stage.
#
#

# ===========================================================
# 								 
# Copyright (c)  2002  by Erich J. Ritzmann
#  
# This software in source or in binary form, is property of
# Erich J. Ritzmann and may not be sold or copied, in whole 
# or in part, without explicit, written permission from the 
# owner.  All rights are retained and any permission or 
# licence to use the software does not confer any rights 
# of ownership.
#
# Written permission given explicitly under the terms of 
# the GNU Public License (GPL) v2.0.  
# 								 
# ===========================================================
    
#
rcsidFSCFG_SNAPSHOT_SH="$Id: fscfg_snapshot.sh,v 1.2 2002/11/16 02:48:40 ejritz Exp $";
#
#
#
# --------------------------------------------------------------------
# description: 
#	called when an unrecoverable error is detected
#	displays a message and then exits
# arguments:
#	1	-- use exit code, -1, 1..127
#	2..n	-- error message text
# returns:	N/A
fatal ()
    {
    echo "${PSNAM}:ERR:$*" >&2
    exit $1
    }  # fatal()

# --------------------------------------------------------------------
# description:
# 	called when a recoverable error is detected
#	displays error message then returns to calling function
# arguments:
#	1	-- error code 
#	2..n	-- error message text
# returns:	N/A
warn ()
    {
    echo "${PSNAM}:WRN:$*" >&2
    sleep 2
    }  # warn() 

# --------------------------------------------------------------------
# description:
#	called when a recoverable error is detected at startup
#	displays error message then exits
# arguments:
#	1	-- exit code 
#	2..n	-- error message text
# returns:	N/A
usage ()
    {
    echo "$*"
    echo "usage: ${PSNAM} 
    Take a snapshot of the filesystem configuration prior to an OS
    install.  Simply redirect output to a printer.
    " | more
    exit $1
    }  # usage()


# --------------------------------------------------------------------
### main ###
#
PSNAM=`basename $0`	# preserve, as qnx looses this information
#
# option -t with argument sample
optAR="'t:h?'"
while getopts "$optAR" c 
do
    case $c in
        t) TYP=${OPTARG} 
            ;;
        *) usage 1
            ;;
    esac
done
shift `expr ${OPTIND} - 1`

FDISK="/sbin/fdisk"
if [ ! -x "$FDISK" ] ; then
    fatal 1 "missing $FDISK utility"
fi

echo "$USER: This must be run as root, continue (y/n)" >&2
read nn
if [ "$nn" = "y" ] ; then
    date
    echo "Taking a filesystem configuration snapshot..."

    echo " "
    echo "Disk free space:"
    df

    echo " "
    echo "Devices partitiioned as follows:"
    disks=$(df | awk '/^\/dev/{print $1} ' | cut -c1-8 | sort | uniq)
    for d in $disks ; do
	echo "$FDISK $d" >&2
	$FDISK $d <<-EOFF
	p
	q
	EOFF
    done

    echo " "
    echo "cat /etc/fstab "
    cat /etc/fstab 

    echo " "
    echo "procinfo -a"
    procinfo -a

fi



# --- eof --- #

