#!/usr/bin/perl
#Copyright (c) 2011, Zane C. Bowers-Hadley
#All rights reserved.
#
#Redistribution and use in source and binary forms, with or without modification,
#are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
#INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
#LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
#THE POSSIBILITY OF SUCH DAMAGE.
use strict;
use warnings;
use Sys::Config::Manage;
use Sys::Config::Manage::Scripts;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-scripts-add 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c \n".
"-b \n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_addCommand - The add command to use.\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"SysConfigManage_autoCreateConfigDir - Automatically create a config dir if it does not exist.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_addCommand - undef\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n".
"SysConfigManage_autoCreateConfigDir - 0\n";
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
if (!defined( $ARGV[0] )){
warn('scm-scripts-add: No script specified');
exit 253;
}
if(!defined( $ARGV[1] )){
warn('scm-scripts-add: No file specified');
exit 252;
}
#real in the settings
my %args;
if (defined( $ENV{'SysConfigManage_autoCreateConfigDir'} )) {
$args{'autoCreateConfigDir'}=$ENV{'SysConfigManage_autoCreateConfigDir'};
}
if (defined( $ENV{'SysConfigManage_addCommand'} )) {
$args{'addCommand'}=$ENV{'SysConfigManage_addCommand'};
}
if (defined( $ENV{'SysConfigManage_baseDir'} )) {
$args{'baseDir'}=$ENV{'SysConfigManage_baseDir'};
}
if (defined( $ENV{'SysConfigManage_selectionMethod'} )) {
$args{'selectionMethod'}=$ENV{'SysConfigManage_selectionMethod'};
}
#sets the base directory if requested command line
if (defined( $opts{b} )) {
$args{baseDir}=$opts{b};
}
#initializes it
my $scm=Sys::Config::Manage->new(\%args);
if ( $scm->error ) {
warn('scm-scripts-add: Failed to initiate the module');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
my $scms=Sys::Config::Manage::Scripts->new( \%oargs );
my $fh;
if (! open( $fh, ');
close( $fh );
$scms->writeScript( $opts{c}, $ARGV[0], $data );
if ( $scms->error ){
warn('scm-scripts-add: Failed to write the script out');
exit $scms->error;
}
#if we get here, it has worked
exit 0;
=head1 NAME
scm-scripts-add - Adds a new script from a file.
=head1 SYNOPSIS
scm-scripts-add [B ] [B
=head1 SWITCHES
=head2 -b
The -b switch can be used to to specify a base directory.
If not specified via switch, the enviromental variable will be used.
=head2 -c
This is the configuration directory to use.
If not specified, one will automatically be choosen.
=head1 ENVIROMENTAL VARIABLES
=head2 SysConfigManage_baseDir
This is the base directory to use.
=head2 SysConfigManage_selectionMethod
This is the election method to use.
If not specified, the default will be used.
=head1 EXIT CODES
Any error codes not specified below are Sys::Config::Manage::Ownership error codes.
=head2 254
Something script specific.
=head2 253
No scripts specified.
=head2 252
No file specified.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS` OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=head1 README
scm-scripts-add - Adds a new script from a file.
=cut