#
# Copyright (c) 1990,1991,1992 The Ohio State University.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that: (1) source distributions retain this entire copyright
# notice and comment, and (2) distributions including binaries display
# the following acknowledgement:  ``This product includes software
# developed by The Ohio State University and its contributors''
# in the documentation or other materials provided with the distribution
# and in all advertising materials mentioning features or use of this
# software. Neither the name of the University nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#

#
# restore-dump.perl - handle restores for dump archives
#

$options = "d:IFf:";
$usage = 
"usage: restore-dump [-d debuglevel] [-I] [-F] [-f host:tape] [file...]
    -d debuglevel	print debug messages
    -I			interactive restore (ala '/usr/ucb/restore i')
    -F			full restore
    -f host:tape	tape host and device to use
    file...		optional list of files to extract\n";

require 'global.defs';
require 'local.defs';
require $yagrip_perl; 
require $backuplib_perl;

#
# Make sure that we clean up after ourselves if someone wants to kill us.
#
$SIG{'INT'} = 'handle_interrupts';
$SIG{'HUP'} = 'handle_interrupts';
$SIG{'TERM'} = 'handle_interrupts';
$SIG{'QUIT'} = 'handle_interrupts';

#
# Deal with args and switches
#

&getopt($options) ||
  die $usage;

$file_list = join(' ', @ARGV);	# make a list of the file on the command line
				# for later use

if (! defined($opt_f)) {
    die "error (restore-dump): the -f option must be used to specify host:device\n";
}
($tape_user, $tape_host, $tape_dev) = &splittapedev($opt_f);
if ($tape_host eq $hostname) {
    $tape_spec = $tape_dev;
} else {
    if ($tape_user ne "" && $dump_does_remote_users) {
	$tape_spec = "$tape_user@$tape_host:$tape_dev";
    } else {
	$tape_spec = "$tape_host:$tape_dev";
    }
}

if (defined($opt_I) && defined($opt_F)) {
    die "error (restore-dump): you can only specify -I or -F, not both.\n$usage";
}

if (! defined($opt_I) && ! defined($opt_F)) {
    die "error (restore-dump): you must give either the -I or the -F option.\n";
}

if (defined($opt_I)) {
    $restore_option = "i";
} else {
    $restore_option = "r";
}

if ($#ARGV >= 0) {
    $restore_option = "x";
}

#
# Now the fun begins.
#

if ($riscos && $tape_spec !~ /:/) {
    $dump_restore_prog =~ s/rrest/rest/;
}

$command = sprintf("%s %sf%s %s %s %s",
		   $dump_restore_prog,
		   $restore_option,
		   $restore_extra_keys,
		   $tape_spec,
		   $restore_extra_args,
		   $file_list);
&my_system($command);

exit(0);


