#!@PERL@
#
-# Copyright (c) 2006 Zmanda Inc. All Rights Reserved.
+# Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# Contact information: Zmanda Inc, 505 N Mathlida Ave, Suite 120
-# Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
+# Contact information: Zmanda Inc, 465 S Mathlida Ave, Suite 300
+# Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
#
+use lib '@amperldir@';
use Getopt::Long;
use Time::Local;
use File::Copy;
use Socket; # for gethostbyname
+use Amanda::Paths;
-my $confdir="@CONFIG_DIR@";
-my $prefix="@prefix@";
-my $tmpdir="@AMANDA_DBGDIR@";
-$prefix=$prefix; # avoid warnings about possible typo
-my $exec_prefix="@exec_prefix@";
-$exec_prefix=$exec_prefix; # ditto
-my $sbindir="@sbindir@";
-my $localstatedir="@localstatedir@";
+my $confdir="$CONFIG_DIR";
+my $tmpdir="$AMANDA_DBGDIR";
my $amandahomedir="$localstatedir/lib/amanda";
-my $datadir="$amandahomedir/template.d"; #rpm install template files here
-my $def_tapedev="file:/$amandahomedir/vtapes";
+my $templatedir="$amdatadir/template.d"; #rpm install template files here
+my $def_tapedev="file:$amandahomedir/vtapes";
my $amanda_user="@CLIENT_LOGIN@";
my $def_config="@DEFAULT_CONFIG@";
&log_and_die ("ERROR: template is missing\n", 1);
}
# create and update amanda.conf
- open(CONF, "$datadir/amanda-$tplate.conf")
- || &log_and_die ("ERROR: Cannot open $datadir/amanda-$tplate.conf: $!\n", 1);
+ open(CONF, "$templatedir/amanda-$tplate.conf")
+ || &log_and_die ("ERROR: Cannot open $templatedir/amanda-$tplate.conf: $!\n", 1);
open(NEWCONF, ">$confdir/$config/amanda.conf") ||
&log_and_die ("ERROR: Cannot create $confdir/$config/amanda.conf: $!\n", 1);
chmod ($amanda_conf_perm, "$confdir/$config/amanda.conf") ||
if ( $template eq "single-tape" && !defined $changerfile && !defined $tpchanger)
{
my $my_changerfile="$confdir/$config/chg-manual.conf";
- copy("$datadir/chg-manual.conf", $my_changerfile) ||
- &mprint ("copy $datadir/chg-manual.conf to $my_changerfile failed: $!\n");
+ copy("$templatedir/chg-manual.conf", $my_changerfile) ||
+ &mprint ("copy $templatedir/chg-manual.conf to $my_changerfile failed: $!\n");
}
}
}
-&create_conf_dir;
-
+my $need_changer = 0;
if ( defined $template ) {
-# validate user input to template
+
+ # validate user input to template
chomp($template);
my $found = 0;
- @valid_templates = ( "harddisk", "single-tape", "tape-changer", "s3");
+ @valid_templates = ( "harddisk", "single-tape", "tape-changer", "s3" );
foreach $elt (@valid_templates) {
- if ($elt eq lc($template)) {
- $found = 1;
- last;
- }
+ if ( $elt eq lc($template) ) {
+ $found = 1;
+ last;
+ }
+ }
+ unless ($found) {
+ print STDERR
+ "valid inputs to --templates are harddisk, single-tape, tape-changer or S3\n";
+ &usage;
+ exit 1;
}
- unless ( $found ) {
- print STDERR "valid inputs to --templates are harddisk, single-tape, tape-changer or S3\n";
- &usage;
- exit 1;
-}
-# if tape-changer is chosen, check if mtx is installed
- if ($template eq "tape-changer") {
- my $ok = 0;
- for $dir ("/usr/sbin", "/usr/local/sbin", "/usr/local/bin", "/usr/bin", "/bin","/opt/csw/sbin",split(":",$oldPATH)) {
- if ( -e "$dir/mtx" ) {
- $ok = 1;
- last;
- }
- }
- unless ($ok) {
- &mprint ("ERROR: mtx binary not found, tape-changer template will not work and is not installed.\n");
- &log_and_die ("ERROR: Please install mtx and rerun the same command.\n", 0);
- }
- unless ($changerfile) {$changerfile="$confdir/$config/changer.conf";}
- open (CCONF, ">$changerfile")
- || &log_and_die ("ERROR: Cannot create $changerfile: $!\n", 1);
- close (CCONF);
- } elsif ($template eq "S3" ) {
- unless ($changerfile) {$changerfile="$confdir/$config/changer.conf";}
- open (CCONF, ">$changerfile")
- || &log_and_die ("ERROR: Cannot create $changerfile: $!\n", 1);
- close (CCONF);
+ # if tape-changer is chosen, check if mtx is installed
+ if ( $template eq "tape-changer" ) {
+ my $ok = 0;
+ for $dir ( "/usr/sbin", "/usr/local/sbin", "/usr/local/bin",
+ "/usr/bin", "/bin", "/opt/csw/sbin", split( ":", $oldPATH ) )
+ {
+ if ( -e "$dir/mtx" ) {
+ $ok = 1;
+ last;
+ }
+ }
+ unless ($ok) {
+ &mprint(
+ "ERROR: mtx binary not found, tape-changer template will not work and is not installed.\n"
+ );
+ &log_and_die(
+ "ERROR: Please install mtx and rerun the same command.\n",
+ 0 );
+ }
+ $need_changer = 1;
+ }
+ elsif ( $template eq "S3" ) {
+ $need_changer = 1;
+ }
- }
+}
+
+&create_conf_dir;
+if ($need_changer) {
+ unless ($changerfile) {
+ $changerfile = "$confdir/$config/changer.conf";
+ }
+ open( CCONF, ">$changerfile" )
+ || &log_and_die( "ERROR: Cannot create $changerfile: $!\n", 1 );
+ close(CCONF);
}
&check_gnutarlist_dir;
my $ttype="$confdir/template.d/tapetypes";
unless ( -e $dtype ) {
- copy("$datadir/dumptypes", $dtype ) ||
+ copy("$templatedir/dumptypes", $dtype ) ||
&log_and_die ("ERROR: copy dumptypes failed: $!\n", 1);
}
unless ( -e $ttype ) {
- copy("$datadir/tapetypes", $ttype ) ||
+ copy("$templatedir/tapetypes", $ttype ) ||
&log_and_die ("ERROR: copy tapetypes file to $ttype failed: $!\n", 1);
}
# update $def_config value to the specified config value in advanced.conf
- open(ADV, "$datadir/advanced.conf") || &log_and_die ("ERROR: Cannot open advanced.conf file: $!\n", 1);
+ open(ADV, "$templatedir/advanced.conf") || &log_and_die ("ERROR: Cannot open advanced.conf file: $!\n", 1);
open(NEWADV, ">$confdir/$config/advanced.conf") ||
&log_and_die ("ERROR: Cannot create advanced.conf file: $!\n", 1);
while (<ADV>) {