#!/bin/sh
# RDisk - Rescue Disk: use "mkbootdisk" to make a rescue disk for this system
#         an gather other useful information.
# http://www.jpsdomain.org/linux/OnStream_DI-30-RedHat_Backup_mini-HOWTO.html
# v1.0 08-Nov-1998 JPV
# v1.3 28-Nov-1999 JPV Updated for new Disk (hdc1)
# v1.4 21-Sep-2000 JPV, updated for new RH 6.2 Kernel
# v1.5 21-Sep-2000 JPV, added "fdisk.info" stuff
# v1.6 16-Feb-2001 JPV, added "rpm -qa" stuff, updated kernel
# v1.7 20-Feb-2001 JPV, added nofpy parameter and variables for cmd paths

# Copyright 2001 JP Vossen
# This script 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.

# In no event shall the author be liable for any damages whatsoever
# (including, without limitation, damages for loss of business profits,
# business interruption, loss of business information, or any other
# pecuniary loss) arising out of the use of or inability to use this script.

# NOTES:
# 1. This script requires that you have a working floppy drive, with an
#     appropriate /etc/fstab entry.  My /etc/fstab has this:
#      /dev/fd0       /mnt/floppy_ext2      ext2    noauto,owner    0 0
#      /dev/fd0       /mnt/floppy_dos       vfat    noauto,owner    0 0
#     I have symlinks /a -> /mnt/floppy_dos and /fpy -> /mnt/floppy_ext2
#     This lets people who expect to find stuff in /mnt be OK, but is easier
#     and gives me more control over floppy mounts.  Since your system is
#     probably different, you'll have to edit the mount/umount lines.
# 2. Every time you update the kernel, you have to update the mkbootdisk
#     line too.  See /lib/modules/
# 3. I only grab fdisk -l info from /dev/hda, if you have more hard
#     drives, add them too.
# 4. You can do everything but the floppy stuff by "$0 nofpy"
# 5. Since this may not always run "su -" I have included paths.  You'll
#     have to adjust them if your system is different.

MKBOOTDISK=/sbin/mkbootdisk
FDISK=/sbin/fdisk
MKKICKSTART=/usr/sbin/mkkickstart

if [ -z "$1" ]; then
    echo ""
    echo Making boot disk...

    # mkbootdisk --device /dev/fd0 2.2.14-5.0smp
    # mkbootdisk --device /dev/fd0 2.2.16-3smp
    ${MKBOOTDISK} --device /dev/fd0 2.2.18
fi

# Gather some disk info
date > /root/rdisk/fdisk.info

echo Getting fdisk info...
echo "" >> /root/rdisk/fdisk.info
echo "fdisk -l /dev/hda" >> /root/rdisk/fdisk.info
echo "-----------------" >> /root/rdisk/fdisk.info
echo "" >> /root/rdisk/fdisk.info
${FDISK} -l /dev/hda >> /root/fdisk.info

echo 	Adding df -h...
echo "" >> /root/rdisk/fdisk.info
echo "df -h" >> /root/rdisk/fdisk.info
echo "-----" >> /root/rdisk/fdisk.info
df -h >> /root/rdisk/fdisk.info

echo 	Adding fstab...
echo "" >> /root/rdisk/fdisk.info
echo "/etc/fstab" >> /root/rdisk/fdisk.info
echo "----------" >> /root/rdisk/fdisk.info
cat /etc/fstab >> /root/rdisk/fdisk.info
echo "" >> /root/rdisk/fdisk.info

# Create KickStart info too, can use to rebuild from CD-ROM
echo Making kickstart file...
${MKKICKSTART} > /root/rdisk/kickstart.info

# Create RPM Info
echo Getting RPM info...
date    >  /root/rdisk/rpm-qa.info
echo "" >> /root/rdisk/rpm-qa.info
rpm -qa >> /root/rdisk/rpm-qa.info

if [ -z "$1" ]; then
    echo Copying files to floppy...
    # Copy the fdisk.info & kickstart files to the floppy
    mount /fpy
    cp /root/rdisk/*.info  /fpy
    umount /fpy
fi

echo ""
echo "$0 Finished..."
echo ""
