#!/bin/sh
# $Id: sbc_disk_info_backup,v 1.3 2004/10/07 10:21:38 sesam Exp $
#   linux 'disk_info' backup
#   (partitions, format, mount and bootloader)
#
#   SEP AG 2004-09-01
#
tmp_info_dir=$1/$2
curr_work_dir=`pwd`
system_name=`uname -s`
if [ "$#" -lt "2" ]; then
  echo "Not enough arguments" >&2
  exit 2
fi

case $system_name in
 Linux)
  ;;
 *)
   echo "" >&2
   echo "Error: Unknown operating system type: $system_name" >&2
   echo "Exiting ..." >&2
   exit 2
   ;;
esac
if [ ! `whoami` = "root" ] ; then
  echo "" >&2
  echo "You need to be root to run this, otherwise"
  echo "sfdisk produces no output. Continuing anyway ..."
  echo ""
fi

#
#  First collect the disk_info
#
echo "Start collecting linux 'disk_info'" >&2
mkdir -p $tmp_info_dir
cd $tmp_info_dir || { echo "ERROR: Could not change to $tmp_info_dir. Exiting ..." ;  exit 2 ; }
rm -f -v *.sdi
mount -l >mount.sdi
mount -l -t ext2 >mount.ext2.sdi
mount -l -t ext3 >mount.ext3.sdi
mount -l -t reiserfs >mount.reiserfs.sdi
mount -l -t xfs >mount.xfs.sdi
cp -v /etc/fstab fstab.sdi
cp -v /etc/mtab  mtab.sdi
echo "------ fstab -------" >&2
cat fstab.sdi >&2
echo "--- end of fstab ---" >&2
#cp -v /etc/lilo.conf  lilo.sdi
#cp -v /etc/grub.conf  grub.sdi
#tar cvf grub.tar.sdi /boot/grub/* /usr/sbin/grub* /usr/lib/grub/*
df -Tl >df.sdi
sfdisk -s >sfdisk.disks.sdi
grep "^/dev/" sfdisk.disks.sdi | sed -n 's/\(^.*\):.*$/\1/p' >disks.sdi
for i in `cat disks.sdi`; do
   j=`echo $i | cut -c6-`
   sfdisk -l $i >sfdisk.$j.sdi
   sfdisk -d $i >sfdisk.make.$j.sdi
   dd if=$i of=dd.mbr12.$j.sdi bs=512 count=2 >/dev/null 2>&1
done
route -n >route.sdi
ifconfig >ifconfig.sdi
echo "Done collecting linux 'disk_info'"

#
#

