1# vim:ft=perl
2# Copyright (c) 2008-2013 Zmanda, Inc.  All Rights Reserved.
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License
6# as published by the Free Software Foundation; either version 2
7# of the License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12# for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17#
18# Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19# Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
20
21package Amanda::Script;
22use base qw(Amanda::Script_App);
23
24use strict;
25use warnings;
26
27=head1 NAME
28
29Amanda::Script - perl utility functions for Scripts.
30
31=head1 SYNOPSIS
32
33  package Amanda::Script::my_script;
34  use base qw(Amanda::Script);
35
36  sub new {
37    my $class = shift;
38    my ($execute_where, $foo, $bar) = @_;
39    my $self = $class->SUPER::new($execute_where);
40    $self->{'execute_where'} = $execute_where;
41    $self->{'foo'} = $foo;
42    $self->{'bar'} = $bar;
43
44    return $self;
45  }
46
47  # Define all command_* subs that you need, e.g.,
48  sub command_pre_dle_amcheck {
49    my $self = shift;
50    # ...
51  }
52
53  package main;
54
55  # .. parse arguments ..
56  my $script = Amanda::Script::my_script->new($opt_execute_where, $opt_foo, $opt_bar);
57  $script->do($cmd);
58
59=cut
60
61sub new {
62    my $class = shift;
63    my ($execute_where, $config_name) = @_;
64
65    my $self = Amanda::Script_App::new($class, $execute_where, "script", $config_name);
66
67    $self->{known_commands} = {
68        support             => 1,
69        pre_amcheck         => 1,
70        pre_dle_amcheck     => 1,
71        pre_host_amcheck    => 1,
72        post_amcheck        => 1,
73        post_dle_amcheck    => 1,
74        post_host_amcheck   => 1,
75        pre_dle_estimate    => 1,
76        pre_estimate        => 1,
77        pre_host_estimate   => 1,
78        post_estimate       => 1,
79        post_dle_estimate   => 1,
80        post_host_estimate  => 1,
81        pre_backup          => 1,
82        pre_dle_backup      => 1,
83        pre_host_backup     => 1,
84        post_dle_backup     => 1,
85        post_backup         => 1,
86        post_host_backup    => 1,
87        pre_recover         => 1,
88        post_recover        => 1,
89        pre_level_recover   => 1,
90        post_level_recover  => 1,
91        inter_level_recover => 1,
92    };
93    return $self;
94}
95
96sub _set_mesgout {
97    my $self = shift;
98
99    my $mesgout_fd;
100    open ($mesgout_fd, '>&=1') || die("Can't open mesgout_fd: $!");
101    $self->{mesgout} = $mesgout_fd;
102}
103
1041;
105