#!/bin/ash

# Script to make a emergency full restore from a previous cbkp archive
# Uncomment the options you want, follow comments.

# device to restore from, replace with your device
# /dev/rft0 for rewindable ftape, necessary for multivolume ftape archive
# (otherwise your tape will remain unwinded after first volume).
FULL_RESTORE_DEV=/dev/rft0

# where to restore, replace with your mounting point
# should be the same as for RestoreCat (0000_catalog.txt have to be here)
FULL_RESTORE_ROOT_DIR=/mnt

#####################################################################
# some warnings first

echo "*FULL* restore about to begin."
echo "If you have ToolDisk mounted and restore from tape then"
echo "exit this script (^C or Ctrl C) and unmount it."
echo "Make sure you have the partition you want to restore"
echo "mounted on $FULL_RESTORE_ROOT_DIR"
echo "Also make sure that you restored catalog first"
echo "MAKE SURE THAT YOU REMOVED THE CATALOG *ENTRY* FROM CATALOG FILE"
echo "(LINE: 0000_catalog.txt -- removed from FILE: 0000_catalog.txt)"
echo "Otherwise just press ENTER to start restoring."
read ans
echo "Starting full restore from archive ..."


# cd to target directory first
cd $FULL_RESTORE_ROOT_DIR

#####################################################################
# START OF TAR SECTION, comment it *ALL* if you use another archiver
# (search for END OF TAR SECTION) 

# uncomment one and only one line:
# FULL_RESTORE_VERBOSE=" "              # non verbose tar
FULL_RESTORE_VERBOSE="-v"               # verbose tar

# uncomment one and only one line:
FULL_RESTORE_COMPRESS=" "               # non compression tar
# FULL_RESTORE_COMPRESS="-z"            # compresion tar

# uncomment one and only one line:
# FULL_RESTORE_MULTIVOLUME=" "          # non multivolume tar
FULL_RESTORE_MULTIVOLUME="-M"           # multivolume tar

# if your device is ftape, set appropriate lenght 
# (in Kb) -- *REAL*, UNCOMPRESSED ("-L" is the lenght flag)
# uncomment one and only one line: 
# FULL_RESTORE_FTAPE_LENGHT=" "         # no lenght given
# FULL_RESTORE_FTAPE_LENGHT="-L 122880" # 120 Mb tape (QIC-80)
FULL_RESTORE_FTAPE_LENGHT="-L 204800"   # 200 Mb tape (QIC-Wide)

# permissions and ownership
#____________________________________________________________________
# WARNING: YOU WILL HAVE TO HAVE AN UP TO DATE /etc/passwd AND /etc/group
# FILES TO RESTORE TO FULL OWNERSHIP, OTHERWISE *YOU* WILL RECEIVE THE
# OWNERSHIP OF FILES WITH OWNERS WITHOUT ENTRY IN passwd AND group.
#____________________________________________________________________
# if set to " " then files with an owner missing from /etc/passwd
# will get your ownership; same for groups and /etc/group
# uncomment one and only one line: 
FULL_RESTORE_PERM_OWN="-p --same-owner" # preserve permissions and ownership
# FULL_RESTORE_PERM_OWN=" "             # files with unknown owner became yours

# this is an emergency restore so all files are restored
# otherwise, if you want a partial restore, 
# edit 0000_catalog.txt before starting this script 

tar -x \
    $FULL_RESTORE_VERBOSE \
    $FULL_RESTORE_COMPRESS \
    -f $FULL_RESTORE_DEV \
    $FULL_RESTORE_FTAPE_LENGHT \
    $FULL_RESTORE_PERM_OWN \
    -T 0000_catalog.txt

# END OF TAR SECTION
#####################################################################

echo "Done."
echo "Reboot from EmergencyKit, mount your freshly restored partition"
echo "as root dir (rw) and run LILO to finish the emergency recovery."
echo "(of course, CHECK /etc/lilo.conf FIRST)"

# return to home dir (you are root, of course)
cd /root
