view release on metacpan or search on metacpan
Revision history for Sys-Config-Manage
0.3.1 2012-05-26/05:45
-Add Term::CallEditor as a dependency.
-Correct the POD for Sys::Config::Manage::Remove.
0.3.0 2011-11-26/18:00
-Make scripts editable and addable via cli.
-Minor bug and documentation fixes.
-Add the scripts below.
bin/scm-scripts-add
bin/scm-scripts-edit
0.2.2 2011-11-20/2:50
-Minor correction to "bin/scm-missing".
0.2.1 2011-11-03/05:20
-Add a missing dependency.
0.2.0 2011-11-02/13:30
-Fix some boolean login in regards to
the error checking in "Sys::Config::Manage".
-Add the modules below.
Sys::Config::Manage::Remove
Sys::Config::Manage::Scripts
-Add the scripts below.
bin/scm-scripts-list
bin/scm-scripts-run
bin/scm-own-down
bin/scm-own-get
bin/scm-own-list
bin/scm-own-up
bin/scm-getcd
bin/scm-missing
0.1.1 2011-08-13/11:30
-Convert the hostname to lowercase.
-Add 'Error::Helper' to the required module list.
0.1.0 2011-08-13/09:20
-Add the scripts below.
bin/scm-perms-get
bin/scm-perms-up
bin/scm-perms-down
bin/scm-perms-list
bin/scm-own-down
bin/scm-own-get
bin/scm-own-list
bin/scm-own-up
-POD updates.
-Misc cleanups.
-Add the modules below.
Sys::Config::Manage::Perms
Sys::Config::Manage::Ownership
0.0.1 2011-08-04/14:20
-Correct various issues with listing tracked files.
-Minor POD changes.
0.0.0 2011-07-31/09:30
-Initial release.
Changes
MANIFEST
Makefile.PL
README
lib/Sys/Config/Manage.pm
lib/Sys/Config/Manage/Perms.pm
lib/Sys/Config/Manage/Ownership.pm
lib/Sys/Config/Manage/Scripts.pm
lib/Sys/Config/Manage/Remove.pm
t/00-load.t
t/01-load.t
t/02-load.t
t/03-load.t
t/04-load.t
t/manifest.t
t/pod-coverage.t
t/pod.t
bin/scm-add
bin/scm-down
bin/scm-list
bin/scm-up
bin/scm-perms-get
bin/scm-perms-up
bin/scm-perms-down
bin/scm-perms-list
bin/scm-remove-add
bin/scm-remove-clean
bin/scm-remove-list
bin/scm-remove-remove
bin/scm-scripts-add
bin/scm-scripts-edit
bin/scm-scripts-list
bin/scm-scripts-run
bin/scm-own-down
bin/scm-own-get
bin/scm-own-list
bin/scm-own-up
bin/scm-getcd
bin/scm-missing
Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Sys::Config::Manage',
AUTHOR => q{Zane C. Bowers-Hadley <vvelox@vvelox.net>},
VERSION_FROM => 'lib/Sys/Config/Manage.pm',
ABSTRACT_FROM => 'lib/Sys/Config/Manage.pm',
($ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
: ()),
PL_FILES => {},
INST_SCRIPT => 'bin',
PREREQ_PM => {
'Test::More' => 0,
'Sys::Hostname'=>0,
'File::Copy'=>0,
'File::Find'=>0,
'File::Basename'=>0,
'File::Path'=>0,
'Cwd'=>0,
'String::ShellQuote'=>0,
'Error::Helper'=>0,
'File::Spec'=>0,
'Term::CallEditor'=>0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Sys-Config-Manage-*' },
);
Sys-Config-Manage
This modules provides a easy way to track configuration files.
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the
perldoc command.
perldoc Sys::Config::Manage
You can also look for information at:
RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Config-Manage
AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/Sys-Config-Manage
CPAN Ratings
http://cpanratings.perl.org/d/Sys-Config-Manage
Search CPAN
http://search.cpan.org/dist/Sys-Config-Manage/
LICENSE AND COPYRIGHT
Copyright (C) 2011 Zane C. Bowers-Hadley
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
bin/scm-add view on Meta::CPAN
#!/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 Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-add 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\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('c:b:', \%opts);
#
if ( ! defined( $ARGV[0] ) ) {
warn('scm-add: No files to add specified');
exit 254;
}
#real in the settings
my %args;
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'};
}
if (defined( $ENV{'SysConfigManage_autoCreateConfigDir'} )) {
$args{'autoCreateConfigDir'}=$ENV{'SysConfigManage_autoCreateConfigDir'};
}
#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-add: Failed to initiate the module');
exit 254;
}
#adds each one one
my $int=0;
my $error=0;
while (defined( $ARGV[$int] )) {
#adds it
$scm->add( $ARGV[$int], $opts{c} );
#sets the error if there is a problem
if ( $scm->error ) {
$error=1;
}
$int++;
}
#warns of errors upon exit
if ( $error ) {
warn( 'scm-add: Some errors were encountered' );
exit 253;
}
#if we get here, it has worked
exit 0;
=head1 NAME
scm-add - This adds a new file to a coniguration directory.
=head1 SYNOPSIS
scm-add [B<-b> <base directory>] [B<-c> <configuration directory] <file0> [<file1>]...
=head1 DESCRIPTION
This copies files from the file system up to the configuration directory.
More than one may be added at a time.
The add method will be invoked for each, regardless of the success of the previous.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
This is the configuration directory to use.
If not specified, one will automatically be choosen.
=head1 ENVIROMENTAL VARIABLES
=head2 SysConfigManage_addCommand
This command will be invoked on the file under the configuration directory
after it has been added.
'%%%file%%%' will be replaced with the escaped full path to the new file.
=head2 SysConfigManage_autoCreateConfigDir
Wether or not the configuration directory should automatically be
created if it does not exist.
=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 error codes.
=head2 253
Failed to copy one or more files to the configuration directory.
Check std err for any error output from Sys::Config::Manage.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-up - This copies files from the file system up to the configuration directory.
=cut
bin/scm-down view on Meta::CPAN
#!/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 Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-down 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n";
}
#gets the options
my %opts=();
getopts('c:b:', \%opts);
#real in the settings
my %args;
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'};
}
if (defined( $ENV{'SysConfigManage_autoCreateConfigDir'} )) {
$args{'autoCreateConfigDir'}=$ENV{'SysConfigManage_autoCreateConfigDir'};
}
#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-add: Failed to initiate the module');
exit 254;
}
$scm->downSync($opts{c}, \@ARGV);
if($scm->error){
warn('scm-downSync: Failed to sync');
exit $scm->error;
}
exit 0;
=head1 NAME
scm-down - This copies files from the configuration directory down to the file system.
=head1 SYNOPSIS
scm-down [B<-b> <base directory>] [B<-c> <configuration directory] [<file0>] [<file1>]...
=head1 DESCRIPTION
This copies files out of the configuration directory down to their proper location
on the file system.
If no files are specified, all will be copied.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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 error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-down - This copies files from the configuration directory down to the file system.
=cut
bin/scm-getcd view on Meta::CPAN
#!/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::Ownership;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-getcd 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n"
}
#real in the settings
my %args;
if (defined( $ENV{'SysConfigManage_baseDir'} )) {
$args{'baseDir'}=$ENV{'SysConfigManage_baseDir'};
}
if (defined( $ENV{'SysConfigManage_selectionMethod'} )) {
$args{'selectionMethod'}=$ENV{'SysConfigManage_selectionMethod'};
}
#initializes it
my $scm=Sys::Config::Manage->new(\%args);
if ( $scm->error ) {
warn('scm-getcd: Failed to initiate the module');
exit $scm->error;
}
my $configdir=$scm->selectConfigDir;
if ( $scm->error ){
warn('scm-getcd: Failed to select the configuration directory');
exit $scm->error;
}
print $configdir."\n";
#if we get here, it has worked
exit 0;
=head1 NAME
scm-getcd - prints what is returned by the selectConfigDir method
=head1 SYNOPSIS
scm-getcd
=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.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-getcd - prints what is returned by the selectConfigDir method
=cut
bin/scm-list view on Meta::CPAN
#!/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 Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-list 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n";
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#real in the settings
my %args;
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-list: Failed to initiate the module');
exit 254;
}
my @files=$scm->listConfigFiles( $opts{c} );
if ($scm->error) {
warn('scm-list: Errors encountered trying to list the config files');
exit 254;
}
print join("\n", @files)."\n";
#if we get here, it has worked
exit 0;
=head1 NAME
scm-list - Lists the files that are currently in a configuration directory.
=head1 SYNOPSIS
scm-list [B<-b> <base directory>] [B<-c> <configuration directory]
=head1 DESCRIPTION
This lists every file that is currently in a configuration directory.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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 error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-list - Lists the files that are currently in a configuration directory.
=cut
bin/scm-missing view on Meta::CPAN
#!/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 Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-missing 0.0.1\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n";
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#real in the settings
my %args;
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-list: Failed to initiate the module');
exit $scm->error;
}
my @files=$scm->listConfigFiles( $opts{c} );
if ($scm->error) {
warn('scm-missing: listConfigFiles failed');
exit $scm->error;
}
my $int=0;
while ( defined( $files[$int] ) ){
if ( ! -f $files[$int] ){
print $files[$int]."\n";
}
$int++;
}
#if we get here, it has worked
exit 0;
=head1 NAME
scm-missing - Lists the files that exist in under the configuration directory, but not the file system.
=head1 SYNOPSIS
scm-missing [B<-b> <base directory>] [B<-c> <configuration directory]
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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 error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-missing - Lists the files that exist in under the configuration directory, but not the file system.
=cut
bin/scm-own-down view on Meta::CPAN
#!/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::Perms;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-own-down 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"SysConfigManagePerms_defaultUID - The default UID\n".
"SysConfigManagePerms_defaultGID - The default GID\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n".
"SysConfigManagePerms_defaultUID - 0\n".
"SysConfigManagePerms_defaultGID - 0\n";
}
#gets the options
my %opts=();
getopts('c:b:', \%opts);
#real in the settings
my %args;
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-own-down: Failed to initiate Sys::Config::Manage');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
if( defined( $ENV{'SysConfigManagePerms_default'} ) ){
$oargs{default}=$ENV{'SysConfigManagePerms_default'};
}
if( defined( $ENV{'SysConfigManagePerms_defaultUID'} ) ){
$oargs{defaultUID}=$ENV{'SysConfigManagePerms_defaultUID'};
}
if( defined( $ENV{'SysConfigManagePerms_defaultGID'} ) ){
$oargs{defaultGID}=$ENV{'SysConfigManagePerms_defaultGID'};
}
my $scmo=Sys::Config::Manage::Ownership->new( \%oargs );
$scmo->downSync($opts{c}, \@ARGV);
if($scmo->error){
warn('scm-own-down: Failed to sync');
exit $scm->error;
}
exit 0;
=head1 NAME
scm-own-down - This copies file ownership down from down from the configuration directory to the file system.
=head1 SYNOPSIS
scm-own-up [B<-b> <base directory>] [B<-c> <configuration directory] [<file0>] [<file1>]...
=head1 DESCRIPTION
This copies file ownership down from down from the configuration directory to the file system.
If no files are specified, all will be copied.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-own-down - This copies file ownership down from down from the configuration directory to the file system.
=cut
bin/scm-own-get view on Meta::CPAN
#!/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::Ownership;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-own-get 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"SysConfigManagePerms_defaultUID - The default UID\n".
"SysConfigManagePerms_defaultGID - The default GID\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n".
"SysConfigManagePerms_defaultUID - 0\n".
"SysConfigManagePerms_defaultGID - 0\n";
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#real in the settings
my %args;
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-own-get: Failed to initiate the module');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
if( defined( $ENV{'SysConfigManagePerms_defaultUID'} ) ){
$oargs{defaultUID}=$ENV{'SysConfigManagePerms_defaultUID'};
}
if( defined( $ENV{'SysConfigManagePerms_defaultGID'} ) ){
$oargs{defaultGID}=$ENV{'SysConfigManagePerms_defaultGID'};
}
my $scmo=Sys::Config::Manage::Ownership->new( \%oargs );
my @files=$scmo->listConfigFiles;
if ($scmo->error) {
warn('scm-perms-get: Errors encountered trying to list the config files');
exit 254;
}
#lists each one
my $int=0;
while ( defined( $files[$int] ) ){
my $uid=$scmo->getUID( undef , $files[$int] );
my $gid=$scmo->getGID( undef , $files[$int] );
print $uid.':'.$gid.' '.$files[$int]."\n";
$int++;
}
#if we get here, it has worked
exit 0;
=head1 NAME
scm-owm-get - Gets ownership info for the files.
=head1 SYNOPSIS
scm-own-get [B<-b> <base directory>] [B<-c> <configuration directory]
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-owm-get - Gets ownership info for the files.
=cut
bin/scm-own-list view on Meta::CPAN
#!/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::Ownership;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-own-list 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n"
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#real in the settings
my %args;
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-perms-list: Failed to initiate the module');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
my $scmo=Sys::Config::Manage::Ownership->new( \%oargs );
my @files=$scmo->listConfigFiles;
if ($scmo->error) {
warn('scm-perms-list: Errors encountered trying to list the config files');
exit 254;
}
print join("\n", @files)."\n";
#if we get here, it has worked
exit 0;
=head1 NAME
scm-own-list - Lists the files that are currently with ownership perms value.
=head1 SYNOPSIS
scm-own-list [B<-b> <base directory>] [B<-c> <configuration directory]
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-own-list - Lists the files that are currently with specific ownership values.
=cut
bin/scm-own-up view on Meta::CPAN
#!/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::Ownership;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-own-up 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_addCommand - The add command to use.\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_addCommand - undef\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n";
}
#gets the options
my %opts=();
getopts('c:b:', \%opts);
#real in the settings
my %args;
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-perms-up: Failed to initiate Sys::Config::Manage');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
if( defined( $ENV{'SysConfigManagePerms_defaultUID'} ) ){
$oargs{defaultUID}=$ENV{'SysConfigManagePerms_defaultUID'};
}
if( defined( $ENV{'SysConfigManagePerms_defaultGID'} ) ){
$oargs{defaultGID}=$ENV{'SysConfigManagePerms_defaultGID'};
}
my $scmo=Sys::Config::Manage::Ownership->new( \%oargs );
$scmo->upSync($opts{c}, \@ARGV);
if($scmo->error){
warn('scm-own-up: Failed to sync');
exit $scmo->error;
}
exit 0;
=head1 NAME
scm-own-up - This copies file ownership from the file system up to the configuration directory.
=head1 SYNOPSIS
scm-own-up [B<-b> <base directory>] [B<-c> <configuration directory] [<file0>] [<file1>]...
=head1 DESCRIPTION
This copies file permissions from the file system up to the configuration directory.
If no files are specified, all will be copied.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
This is the configuration directory to use.
If not specified, one will automatically be choosen.
=head1 ENVIROMENTAL VARIABLES
=head2 SysConfigManage_addCommand
This is the add command to use.
=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.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-own-up - This copies file ownership from the file system up to the configuration directory.
=cut
bin/scm-perms-down view on Meta::CPAN
#!/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::Perms;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-perms-down 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n";
}
#gets the options
my %opts=();
getopts('c:b:', \%opts);
#real in the settings
my %args;
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-perms-down: Failed to initiate Sys::Config::Manage');
exit 254;
}
#gets the perms opts
my %pargs;
$pargs{scm}=$scm;
if( defined( $ENV{'SysConfigManagePerms_default'} ) ){
$pargs{default}=$ENV{'SysConfigManagePerms_default'};
}
my $scmp=Sys::Config::Manage::Perms->new( \%pargs );
$scmp->downSync($opts{c}, \@ARGV);
if($scm->error){
warn('scm-perms-down: Failed to sync');
exit $scm->error;
}
exit 0;
=head1 NAME
scm-perms-down - This copies file permissions down from down from the configuration directory to the file system.
=head1 SYNOPSIS
scm-perms-up [B<-b> <base directory>] [B<-c> <configuration directory] [<file0>] [<file1>]...
=head1 DESCRIPTION
This copies file permissions down from down from the configuration directory to the file system.
If no files are specified, all will be copied.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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::Perms error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-perms-down - This copies file permissions down from down from the configuration directory to the file system.
=cut
bin/scm-perms-get view on Meta::CPAN
#!/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::Perms;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-perms-get 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n"
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#real in the settings
my %args;
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-perms-get: Failed to initiate the module');
exit 254;
}
#gets the perms opts
my %pargs;
$pargs{scm}=$scm;
my $scmp=Sys::Config::Manage::Perms->new( \%pargs );
my @files=$scmp->listConfigFiles;
if ($scmp->error) {
warn('scm-perms-get: Errors encountered trying to list the config files');
exit 254;
}
#lists each one
my $int=0;
while ( defined( $files[$int] ) ){
my $perms=$scmp->getPerms( undef , $files[$int] );
print $perms.' '.$files[$int]."\n";
$int++;
}
#if we get here, it has worked
exit 0;
=head1 NAME
scm-perms-get - Gets permissions for the specified file.
=head1 SYNOPSIS
scm-perms-get [B<-b> <base directory>] [B<-c> <configuration directory]
=head1 DESCRIPTION
This lists every file that is currently in a configuration directory.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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::Perms error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-perms-get - Gets permissions for the specified file.
=cut
bin/scm-perms-list view on Meta::CPAN
#!/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::Perms;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-perms-list 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n"
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#real in the settings
my %args;
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-perms-list: Failed to initiate the module');
exit 254;
}
#gets the perms opts
my %pargs;
$pargs{scm}=$scm;
my $scmp=Sys::Config::Manage::Perms->new( \%pargs );
my @files=$scmp->listConfigFiles;
if ($scmp->error) {
warn('scm-perms-list: Errors encountered trying to list the config files');
exit 254;
}
print join("\n", @files)."\n";
#if we get here, it has worked
exit 0;
=head1 NAME
scm-perms-list - Lists the files that are currently with specific perms value.
=head1 SYNOPSIS
scm-perms-list [B<-b> <base directory>] [B<-c> <configuration directory]
=head1 DESCRIPTION
This lists every file that is currently in a configuration directory.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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 error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-perms-list - Lists the files that are currently with specific perms value.
=cut
bin/scm-perms-up view on Meta::CPAN
#!/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::Perms;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-perms-up 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_addCommand - The add command to use.\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_addCommand - undef\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n";
}
#gets the options
my %opts=();
getopts('c:b:', \%opts);
#real in the settings
my %args;
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-perms-up: Failed to initiate Sys::Config::Manage');
exit 254;
}
#gets the perms opts
my %pargs;
$pargs{scm}=$scm;
if( defined( $ENV{'SysConfigManagePerms_default'} ) ){
$pargs{default}=$ENV{'SysConfigManagePerms_default'};
}
my $scmp=Sys::Config::Manage::Perms->new( \%pargs );
$scmp->upSync($opts{c}, \@ARGV);
if($scmp->error){
warn('scm-perms-up: Failed to sync');
exit $scm->error;
}
exit 0;
=head1 NAME
scm-perms-up - This copies file permissions from the file system up to the configuration directory.
=head1 SYNOPSIS
scm-perms-up [B<-b> <base directory>] [B<-c> <configuration directory] [<file0>] [<file1>]...
=head1 DESCRIPTION
This copies file permissions from the file system up to the configuration directory.
If no files are specified, all will be copied.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
This is the configuration directory to use.
If not specified, one will automatically be choosen.
=head1 ENVIROMENTAL VARIABLES
=head2 SysConfigManage_addCommand
This is the add command to use.
=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::Perms error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-perms-up - This copies file permissions from the file system up to the configuration directory.
=cut
bin/scm-remove-add view on Meta::CPAN
#!/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::Remove;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-remove-add 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_addCommand - The add command to use.\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_addCommand - undef\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n"
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#makes sure that there is something to add
if ( ! defined( $ARGV[0] ) ) {
warn('scm-remove-add: No files to add specified');
exit 254;
}
#real in the settings
my %args;
if (defined( $ENV{'SysConfigManage_baseDir'} )) {
$args{'baseDir'}=$ENV{'SysConfigManage_baseDir'};
}
if (defined( $ENV{'SysConfigManage_selectionMethod'} )) {
$args{'selectionMethod'}=$ENV{'SysConfigManage_selectionMethod'};
}
if (defined( $ENV{'SysConfigManage_addCommand'} )) {
$args{'addCommand'}=$ENV{'SysConfigManage_addCommand'};
}
#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-remove-add: Failed to initiate Sys::Config::Manage');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
my $scmr=Sys::Config::Manage::Remove->new( \%oargs );
if ( $scmr->error ){
warn('scm-remove-add: Failed to initiate Sys::Config::Manage::Remove');
exit $scmr->error;
}
my $int=0;
my @errors;
while ( defined( $ARGV[$int] ) ){
$scmr->add( $opts{c}, $ARGV[$int] );
if ( $scmr->error ){
push( @errors, $ARGV[$int] );
}
$int++;
}
if ( defined($errors[0]) ){
exit 253;
};
#if we get here, it has worked
exit 0;
=head1 NAME
scm-remove-add - This adds a new path or paths to the remove list.
=head1 SYNOPSIS
scm-remove-add [B<-b> <base directory>] [B<-c> <configuration directory] <path0> [<path1>]...
=head1 DESCRIPTION
This adds one or more paths to the remove list. Paths can't contain a newline and must
start with a forward slash.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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::Remove or
Sys::Config::Manage error codes.
=head2 253
Sys::Config::Manage::Remove->add failed for one of the paths.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-remove-add - This adds a new path or paths to the remove list.
=cut
bin/scm-remove-clean view on Meta::CPAN
#!/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::Remove;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-remove-clean 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n"
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#real in the settings
my %args;
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-remove-clean: Failed to initiate the module');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
my $scmr=Sys::Config::Manage::Remove->new( \%oargs );
$scmr->clean;
if ($scmr->error) {
warn('scm-remove-clean: Errors encountered trying to remove the paths to clean');
exit 254;
}
#if we get here, it has worked
exit 0;
=head1 NAME
scm-remove-clean - Remove the list of the paths to be removed.
=head1 SYNOPSIS
scm-remove-clean [B<-b> <base directory>] [B<-c> <configuration directory]
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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::Remove or
Sys::Config::Manage error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-remove-clean - Remove the list of the paths to be removed.
=cut
bin/scm-remove-list view on Meta::CPAN
#!/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::Remove;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-remove-list 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n"
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#real in the settings
my %args;
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-remove-list: Failed to initiate the module');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
my $scmr=Sys::Config::Manage::Remove->new( \%oargs );
my @files=$scmr->list;
if ($scmr->error) {
warn('scm-remove-list: Errors encountered trying to list the config files');
exit 254;
}
if (defined($files[0])){
print join("\n", @files)."\n";
};
#if we get here, it has worked
exit 0;
=head1 NAME
scm-remove-list - Lists paths that should be removed.
=head1 SYNOPSIS
scm-remove-list [B<-b> <base directory>] [B<-c> <configuration directory]
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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::Remove or
Sys::Config::Manage error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-remove-list - Lists the paths to remove for a configuration directory.
=cut
bin/scm-remove-remove view on Meta::CPAN
#!/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::Remove;
use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-remove-remove 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n"
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#makes sure that there is something to add
if ( ! defined( $ARGV[0] ) ) {
warn('scm-remove-remove: No files to add specified');
exit 254;
}
#real in the settings
my %args;
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-remove-remove: Failed to initiate Sys::Config::Manage');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
my $scmr=Sys::Config::Manage::Remove->new( \%oargs );
if ( $scmr->error ){
warn('scm-remove-remove: Failed to initiate Sys::Config::Manage::Remove');
exit $scmr->error;
}
my $int=0;
my @errors;
while ( defined( $ARGV[$int] ) ){
$scmr->remove( $opts{c}, $ARGV[$int] );
if ( $scmr->error ){
push( @errors, $ARGV[$int] );
}
$int++;
}
if ( defined( $errors[0] ) ){
exit 253;
};
#if we get here, it has worked
exit 0;
=head1 NAME
scm-remove-add - This removes a path or paths from the remove list.
=head1 SYNOPSIS
scm-remove-add [B<-b> <base directory>] [B<-c> <configuration directory] <path0> [<path1>]...
=head1 DESCRIPTION
This removes one or more paths from the remove list. Paths can't contain a newline and must
start with a forward slash.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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::Remove or
Sys::Config::Manage error codes.
=head2 253
Sys::Config::Manage::Remove->remove failed for one of the paths.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-remove-add - This adds a new path or paths to the remove list.
=cut
bin/scm-scripts-add view on Meta::CPAN
#!/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 <config directory>\n".
"-b <base directory>\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, '<', $ARGV[1] ) ){
warn('scm-scripts-add: Failed to open the file, "'.$ARGV[1].'",');
return 254;
}
my $data=join('', <$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> <base directory>] [B<-c> <configuration directory] <script> <file>
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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 <vvelox@vvelox.net>
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
bin/scm-scripts-edit view on Meta::CPAN
#!/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-edit 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\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-edit: No script specified');
exit 253;
}
#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-edit: Failed to initiate the module');
exit 254;
}
#gets the perms opts
my %oargs;
$oargs{scm}=$scm;
my $scms=Sys::Config::Manage::Scripts->new( \%oargs );
$scms->editScript( $opts{c}, $ARGV[0] );
#if we get here, it has worked
exit 0;
=head1 NAME
scm-scripts-edit - Edits the specified script.
=head1 SYNOPSIS
scm-scripts-run [B<-b> <base directory>] [B<-c> <configuration directory] <script>
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-edit - Edits the specified script.
=cut
bin/scm-scripts-list view on Meta::CPAN
#!/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-list 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n"
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
#real in the settings
my %args;
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-list: 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 @files=$scms->listScripts;
if ($scms->error) {
warn('scm-scripts-list: Errors encountered trying to list the config files');
exit 254;
}
if (defined($files[0])){
print join("\n", @files)."\n";
};
#if we get here, it has worked
exit 0;
=head1 NAME
scm-scripts-list - Lists the scripts for a configuration directory.
=head1 SYNOPSIS
scm-scripts-list [B<-b> <base directory>] [B<-c> <configuration directory]
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-list - Lists the scripts for a configuration directory.
=cut
bin/scm-scripts-run view on Meta::CPAN
#!/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-run 0.0.1\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\n".
"Enviromental Variables...\n".
"SysConfigManage_baseDir - The base directory.\n".
"SysConfigManage_selectionMethod - Selection method.\n".
"\n".
"\n".
"Default...\n".
"SysConfigManage_baseDir - undef\n".
"SysConfigManage_selectionMethod - hostname\n";
}
#gets the options
my %opts=();
getopts('b:c:', \%opts);
if(!defined( $ARGV[0] )){
warn('scm-scripts-run: No script specified');
exit 253;
}
#real in the settings
my %args;
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-run: 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 $exitInt=$scms->runScript( $opts{c}, $ARGV[0] );
if( $scms->error ){
warn('scm-scripts-run: Sys::Config::Manage::Scripts errored. error="'.
$scms->error.'" errorString="'.$scms->errorString.'"');
exit $scms->error;
}
if ( $exitInt ne '0' ){
warn( 'scm-scripts-run: The script existed with a integer of "'.$exitInt.'"' );
exit $exitInt;
}
#if we get here, it has worked
exit 0;
=head1 NAME
scm-scripts-run - This runs a specified script.
=head1 SYNOPSIS
scm-scripts-run [B<-b> <base directory>] [B<-c> <configuration directory] <script>
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-run - Lists specific scripts for the host in question.
=cut
#!/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 Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
#version function
sub main::VERSION_MESSAGE {
print "scm-up 0.0.0\n";
}
#print help
sub main::HELP_MESSAGE {
print "\n".
"Switches...\n".
"-c <config directory>\n".
"-b <base directory>\n".
"\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('c:b:', \%opts);
#real in the settings
my %args;
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'};
}
if (defined( $ENV{'SysConfigManage_autoCreateConfigDir'} )) {
$args{'autoCreateConfigDir'}=$ENV{'SysConfigManage_autoCreateConfigDir'};
}
#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-add: Failed to initiate the module');
exit 254;
}
$scm->upSync($opts{c}, \@ARGV);
if($scm->error){
warn('scm-downSync: Failed to sync');
exit $scm->error;
}
exit 0;
=head1 NAME
scm-up - This copies files from the file system up to the configuration directory.
=head1 SYNOPSIS
scm-up [B<-b> <base directory>] [B<-c> <configuration directory] [<file0>] [<file1>]...
=head1 DESCRIPTION
This copies files from the file system up to the configuration directory.
If no files are specified, all will be copied.
=head1 SWITCHES
=head2 -b <base directory>
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 <configuration directory>
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 error codes.
=head2 254
Something script specific.
=head1 AUTHOR
Copyright (c) 2011, Zame C. Bowers-Hadley <vvelox@vvelox.net>
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-up - This copies files from the file system up to the configuration directory.
=cut
blib*
Makefile
Makefile.old
Build
Build.bat
_build*
pm_to_blib*
*.tar.gz
.lwpcookies
cover_db
pod2htm*.tmp
Sys-Config-Manage-*
lib/Sys/Config/Manage.pm view on Meta::CPAN
package Sys::Config::Manage;
use warnings;
use strict;
use Sys::Hostname;
use File::Copy;
use File::Find;
use File::Basename;
use File::Path 'make_path';
use Cwd 'abs_path';
use String::ShellQuote;
use base 'Error::Helper';
=head1 NAME
Sys::Config::Manage - Manages system configuration information.
=head1 VERSION
Version 0.3.1
=cut
our $VERSION = '0.3.1';
=head1 SYNOPSIS
use Sys::Config::Manage;
my $foo = Sys::Config::Manage->new();
...
=head1 METHODS
=head2 new
=head3 args hash
=head4 addCommand
This is the command to call on the file once it is copied over.
If not defined, nothing will be attempted after it is copied over.
=head4 autoCreateConfigDir
If this is specified, the configuration directory will automatically
be created under the base directory if needed.
This defaults to false, 0.
=head4 baseDir
The base directory the config base is stored in.
=head4 hostnameFallback
If the regexp selection method is being used, the hostname method will
be used.
=head4 selectionMethod
This is the selection method to use for selecting a system directory.
The valid methods are listed below.
hostname
regexp
If not specified, the hostname method is used.
my $foo=$Sys::Config::Manage->new(\%args);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub new{
my %args;
if(defined($_[1])){
%args= %{$_[1]};
};
my $method='new';
my $self = {
module=>'Sys-Config-Manage',
perror=>undef,
error=>undef,
errorString=>"",
addCommand=>undef,
baseDir=>undef,
selectionMethod=>'hostname',
autoCreateConfigDir=>0,
hostnameFallback=>1,
};
bless $self;
#make sure a base directory is set
if (!defined( $args{baseDir} )) {
$self->{perror}=1;
$self->{error}=1;
$self->{errorString}='No base directory specified';
$self->warn;
return $self;
}
$self->{baseDir}=$args{baseDir};
#clean it up
$self->{baseDir} =~ s/\/\/*/\//g;
#makes sure the base directory
if (! -d $self->{baseDir}) {
$self->{perror}=1;
$self->{error}=4;
$self->{errorString}='"'.$self->{baseDir}.'" does not exist or is not a directory';
$self->warn;
return $self;
}
#copies the addcommand if needed
if (defined( $args{addCommand} )) {
$self->{addCommand}=$args{addCommand};
}
#copies the hostnameFallback if needed
if (defined( $args{hostnameFallback} )) {
$self->{hostnameFallback}=$args{hostnameFallback};
}
#sets the autoCreateConfigDir value if needed
if (defined( $args{autoCreateConfigDir} )) {
$self->{autoCreateConfigDir}=$args{autoCreateConfigDir};
}
#make sure the selection
if (defined( $args{selectionMethod} )) {
if (
( $args{selectionMethod} ne 'hostname' ) &&
( $args{selectionMethod} ne 'regexp' )
) {
$self->{perror}=1;
$self->{error}=2;
$self->{errorString}='"'.$args{selectionMethod}.'" is not a valid selection method';
$self->warn;
return $self;
}
$self->{selectionMethod}=$args{selectionMethod};
}
#gets the hostname as it will be used later most likely...
$self->{hostname}=hostname;
return $self;
}
=head2 add
This adds a new file.
Two arguments are taken. The first is the file to added
and the second is the configuration directory to use. If
no configuration directory is specified, one will
automatically selected.
#add it with a automatically selected config dir
$foo->add($file);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
#add it with a automatically specified config dir
$foo->add($file, $configDir);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub add{
my $self=$_[0];
my $file=$_[1];
my $configDir=$_[2];
my $method='add';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a file
if (!defined($file)) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure it is a file and it exists
if (! -f $file ) {
$self->{error}=8;
$self->{errorString}='"'.$file.'" does not exist or is not a file';
$self->warn;
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->selectConfigDir;
if ($self->error) {
warn($self->{module}.' '.$method.': Unable to select a config dir');
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->validConfigDirName($configDir);
if ($self->error) {
warn($self->{module}.' '.$method.':'.$self->error.': Errored checking if the configuration directory name is valid');
return undef;
}
if (defined( $valid )) {
$self->{error}=6;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure the specified config directory is not a file
if ( -f $self->{baseDir}.'/'.$configDir ) {
$self->{error}=13;
$self->{errorString}='"'.$self->{baseDir}.'/'.$configDir.'" is a file and thusly can not be used as a configuration directory';
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{baseDir}.'/'.$configDir ) {
if ( $self->getAutoCreateConfigDir ) {
if (! mkdir( $self->{baseDir}.'/'.$configDir ) ) {
$self->{error}=14;
$self->{errorString}='"'.$self->{baseDir}.'/'.$configDir.'" could not be created';
$self->warn;
return undef;
}
}else {
$self->{error}=15;
$self->{errorString}='"'.$self->{baseDir}.'/'.$configDir.'" could not be created as autoCreateConfigDir is set to false';
$self->warn;
return undef;
}
}
#get the full path
$file=abs_path($file);
#makes the new path
my $newfile=$self->{baseDir}.'/'.$configDir.'/'.$file;
$newfile=~s/\/\/*/\//g;
#figures out what the new directory will be
my ($name,$path,$suffix) = fileparse( $file );
my $newpath=$self->{baseDir}.'/'.$configDir.'/'.$path;
$newfile=~s/\/\/*/\//g;
#make sure the new path does not exist as a file
#while this may look stupid, it makes sure i
if ( -f $newpath ) {
$self->{error}=9;
$self->{errorString}='"'.$newpath.'" is a file, so unable to create the directory';
$self->warn;
return undef;
}
#handles it if the directory path does not yet exist in the configuration directory
if (! -d $newpath ) {
if (! make_path($newpath) ) {
$self->{error}=10;
$self->{errorString}='The path "'.$newpath.'" could not be created';
$self->warn;
return undef;
}
}
#copies the file
if (! copy($file, $newfile) ) {
$self->{error}=11;
$self->{errorString}='Unable to copy "'.$file.'" to "'.$newfile.'"';
$self->warn;
return undef;
}
#adds it
if (defined( $self->{addCommand} )) {
my $command=$self->{addCommand};
$newfile=shell_quote($newfile);
$command=~s/\%\%\%file\%\%\%/$newfile/g;
system($command);
my $exit = $?<<8;
if ($exit ne '0') {
$self->{error}=12;
$self->{errorString}='The add command failed. command="'.$command.'" exit="'.$exit.'"';
$self->warn;
return undef;
}
}
#it has been added now
return 1;
}
=head2 configDirExists
This verifies that the specified config directory exists.
my $returned=$foo->configDirExists($dir);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
if (!$returned){
warn('The config dir does not exist or is not a directory');
}
=cut
sub configDirExists{
my $self=$_[0];
my $configDir=$_[1];
my $method='getSelectionMethod';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#it does not exist or is not a directory
if (! -d $self->{baseDir}.'/'.$configDir) {
return undef;
}
#it exists
return 1;
}
=head2 downSync
This syncs the configs down from the configuration
directory to the system.
Two arguments can be used.
The first is the configuration directory. If not specified, it will
be automaticallly choosen.
The second is the files to sync. If not specifiedm, all files will
be synced.
#sync the specified files
$foo->downSync( $configDir, \@files);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
#syncs all the files
$foo->downSync
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub downSync{
my $self=$_[0];
my $configDir=$_[1];
my @files;
if (defined($_[2])) {
@files=@{$_[2]};
}
my $method='downSync';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->selectConfigDir;
if ($self->error) {
warn($self->{module}.' '.$method.': Unable to select a config dir');
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->validConfigDirName($configDir);
if ($self->error) {
warn($self->{module}.' '.$method.':'.$self->error.': Errored checking if the configuration directory name is valid');
return undef;
}
if (defined( $valid )) {
$self->{error}=6;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{baseDir}.'/'.$configDir ) {
$self->{error}=16;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#get the files if if none is specified
if (!defined( $files[0] )) {
@files=$self->listConfigFiles($configDir);
}
#get the files if if none is specified
my @allFiles=$self->listConfigFiles($configDir);
#makes sure all the files exist
my $int=0;
while (defined( $files[$int] )) {
my $matched=0;
my $int2=0;
while (defined( $allFiles[$int2] )) {
if ( $files[$int] eq $allFiles[$int2] ) {
$matched=1;
}
$int2++;
}
#figures out what the new directory will be and checks
my ($name,$path,$suffix) = fileparse( $files[$int] );
if( -f $path ){
$self->{error}=19;
$self->{errorString}='"'.$path.'" should be a directory, but it is a file ';
$self->warn;
return undef;
}
#make sure it is matched
if (!$matched) {
$self->{error}=18;
$self->{errorString}='"'.$files[$int].'" is not tracked';
$self->warn;
return undef;
}
$int++;
}
#copies each file from the repo to the FS
$int=0;
while( defined( $files[$int] ) ){
my $repofile=$self->{baseDir}.'/'.$configDir.'/'.$files[$int];
$repofile=~s/\/\/*/\//g;
#figures out what the new directory will be
my ($name,$path,$suffix) = fileparse( $files[$int] );
#make the path if it does not exist
if(! -e $path){
if(!make_path( $path )){
$self->{error}=10;
$self->{errorString}='"'.$path.'" could not be created as a directory';
$self->warn;
return undef;
}
}
#
if(! copy($repofile, $files[$int]) ){
$self->{error}=19;
$self->{errorString}='"'.$files[$int].'" could not be synced';
$self->warn;
return undef;
}
$int++;
}
return 1;
}
=head2 getAddCommand
This returns the current add command.
If none is set, undef will be returned.
my $addCommand=$foo->getAddCommand;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub getAddCommand{
my $self=$_[0];
my $method='getAddCommand';
#blank any previous errors
if (! $self->errorblank) {
return undef;
}
return $self->{addCommand};
}
=head2 getAutoCreateConfigDir
This returns the autoCreateConfigDir value.
my $autoCreateConfigDir=$foo->getBaseDir;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub getAutoCreateConfigDir{
my $self=$_[0];
my $method='autoCreateConfigDir';
#blank any previous errors
if (! $self->errorblank) {
return undef;
}
return $self->{autoCreateConfigDir};
}
=head2 getBaseDir
This returns what the base directory is set to.
my $baseDir=$foo->getBaseDir;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub getBaseDir{
my $self=$_[0];
my $method='getBaseDir';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
return $self->{baseDir};
}
=head2 getHostnameFallback
This returns the current value for hostnameFallback.
my $hostnameFallback=$foo->getHostnameFallback;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub getHostnameFallback{
my $self=$_[0];
my $method='getHostnameFallback';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
return $self->{baseDir};
}
=head2 getSelectionMethod
This returns the current selection method.
my $selectionMethod=$foo->getSelectionMethod;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub getSelectionMethod{
my $self=$_[0];
my $method='getSelectionMethod';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
return $self->{selectionMethod};
}
=head2 listConfigDirs
This lists the available configuration directories.
my @dirs=$foo->listConfigDirs;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub listConfigDirs{
my $self=$_[0];
my $method='listConfigDirs';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#opens the directory for reading
my $dh=undef;
if (! opendir( $dh, $self->{baseDir} ) ) {
$self->{error}=5;
$self->{errorString}='Unable to open "'.$self->{baseDir}.'"';
$self->warn;
return undef;
}
#reads each entry and check if it should be added
my @dirs;
my $entry=readdir($dh);
while ( defined($entry) ) {
if (
( $entry ne '.SysConfigManage' ) &&
( -d $entry )
) {
push( @dirs, $entry );
}
$entry=readdir($dh);
}
#close the directory
closedir($dh);
return @dirs;
}
=head2 listConfigFiles
This lists the various config files that are currently being tracked.
my @files=$foo->listConfigFiles;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub listConfigFiles{
my $self=$_[0];
my $configDir=$_[1];
my $method='listConfigFiles';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->selectConfigDir;
if ($self->error) {
warn($self->{module}.' '.$method.':'.$self->error.': Unable to select a directory');
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->validConfigDirName($configDir);
if ($self->error) {
warn($self->{module}.' '.$method.':'.$self->error.': Errored checking if the configuration directory name is valid');
return undef;
}
if (defined( $valid )) {
$self->{error}=6;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{baseDir}.'/'.$configDir ) {
$self->{error}=16;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#holds what will be returned
my @found;
#find the file
find( {
wanted => sub{
#don't match .svn stuff
if ( $_ eq ".svn" ) {
return;
}
if($File::Find::dir =~ /\.svn$/){
return;
}
if($File::Find::dir =~ /\.svn\//){
return;
}
#don't match .SysConfigManage stuff
if ( $_ eq ".SysConfigManage" ) {
return;
}
if($File::Find::dir =~ /\.SysConfigManage$/){
return;
}
if($File::Find::dir =~ /\.SysConfigManage\//){
return;
}
#don't match .git stuff
if ( $_ eq ".git" ) {
return;
}
if($File::Find::dir =~ /\.git$/){
return;
}
if($File::Find::dir =~ /\.git\//){
return;
}
#only list files
if ( ! -f $_ ) {
return;
}
my $foundfile=$File::Find::dir."/".$_;
#$foundfile=~s/\/\//\//g;
my $regexp='^'.$self->{baseDir}.'/'.$configDir;
$foundfile=~s/$regexp//;
push(@found, $foundfile);
}
}, $self->{baseDir}.'/'.$configDir
);
return @found;
}
=head2 notUnderBase
This makes sure that the a file is not under the base directory.
If it returns true, then the file is not under the base directory.
If it returns false, then it is under the base directory.
my $returned=$foo->notUnderBase($file);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
if ( ! $returned ){
print "The file is under the base directory.\n".
}
=cut
sub notUnderBase{
my $self=$_[0];
my $file=$_[1];
my $method='notUnderBase';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a file specified
if( ! defined( $file ) ){
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
}
#clean up the path
$file=~s/\/\/*/\//g;
my $regexp="^".quotemeta($self->{baseDir}."/");
$regexp=~s/\/\/*/\//g;
#if it matches, then it
if( $file =~ /$regexp/ ){
return 0;
}
return 1;
}
=head2 regexpSelectConfigDir
This reads $baseDir.'/.mapping' and returns the selected configuration
directory.
A optional hostname may be specified to check for.
A return of undef with out a error means it was not matched
my $configDir=$foo->regexpSelect;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}else{
if(!defined(configDir)){
warn('No match found');
}
}
=cut
sub regexpSelectConfigDir{
my $self=$_[0];
my $hostname=$_[1];
my $method='regexpSelectSelectConfigDir';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
if (!defined( $hostname )) {
$hostname=$self->{hostname};
}
#make sure it exists or is readable
if ( -f $self->{baseDir}.'/.mapping' ) {
$self->{error}=5;
$self->{error}='"'.$self->{baseDir}.'/.mapping" does not exist or is not a file';
$self->warn;
return undef;
}
#tries to open it
my $dh;
if ( ! open( $dh, '<', $self->{baseDir}.'/.mapping' ) ) {
$self->{error}=6;
$self->{error}='"'.$self->{baseDir}.'/.mapping" could not be opened';
$self->warn;
return undef;
}
#read it and close it
my @lines=<$dh>;
close $dh;
#process each line
my $int=0;
while ( defined( $lines[$int] ) ) {
my ($dir, $regexp)=split(/ /, $lines[$int], 2);
if ( $hostname =~ /$regexp/ ) {
return $dir;
}
$int++;
}
return undef;
}
=head2 selectConfigDir
This selects the configuration directory to use.
my $configDir=$foo->selectConfigDir;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub selectConfigDir{
my $self=$_[0];
my $method='setSelectionMethod';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
my $selectionMethod=$self->getSelectionMethod;
if( $selectionMethod eq 'hostname' ){
return lc(hostname);
}
if ( $selectionMethod eq 'regexp' ){
my $configDir=$self->regexpSelect;
if ( $self->error ) {
warn($self->{module}.' '.$method.': regexpSelect failed');
return undef;
}
if (!defined($configDir)) {
if ($self->getHostnameFallback) {
return hostname;
}
$self->{error}=17;
$self->{errorString}='Hostname is disabled and regexp selection did not find any thing';
$self->warn;
return undef;
}
return $configDir;
}
return undef;
}
=head2 setAddCommand
This changes the add command.
If nothing is specified, it will be set to undef, meaning
nothing will be done to add it.
#sets nothing to be added
$foo->setAddMethod();
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
#sets it to 'svn add --parents %%%file%%%'
$foo->setAddMethod('svn add --parents %%%file%%%');
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub setAddCommand{
my $self=$_[0];
my $command=$_[1];
my $method='setAddCommand';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
$self->{addCommand}=$command;
return 1;
}
=head2 setAutoCreateConfigDir
This changes the add command.
If nothing is specified, it will be set to undef, meaning
nothing will be done to add it.
#sets nothing to be added
$foo->setAddMethod();
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
#sets it to 'svn add --parents %%%file%%%'
$foo->setAddMethod('svn add --parents %%%file%%%');
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub setAutoCreateConfigDir{
my $self=$_[0];
my $autocreate=$_[1];
my $method='setAutoCreateConfigDir';
#blank any pre1;3Avious errors
if (!$self->errorblank) {
return undef;
}
$self->{autoCreateConfigDir}=$autocreate;
return 1;
}
=head2 setSelectionMethod
This sets the selection method to use.
The valid methods are listed below.
hostname
regexp
$foo->setSelectionMethod($method);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub setSelectionMethod{
my $self=$_[0];
my $selectionMethod=$_[1];
my $method='setSelectionMethod';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure a method is specified
if (!defined($selectionMethod)) {
$self->{error}=3;
$self->{errorString}='No selection method specified';
$self->warn;
return undef;
}
#make sure it is valid
if (
( $selectionMethod ne 'hostname' ) &&
( $selectionMethod ne 'regexp' )
) {
$self->{error}=2;
$self->{errorString}='"'.$selectionMethod.'" is not a valid selection method';
$self->warn;
return undef;
}
#saves the selection method
$self->{selectionMethod}=$selectionMethod;
return 1;
}
=head2 upSync
This syncs the configs up from the system to the configuration
directory
Two arguments can be used.
The first is the configuration directory. If not specified, it will
be automaticallly choosen.
The second is the files to sync. If not specifiedm, all files will
be synced.
#sync the specified files
$foo->downSync( $configDir, \@files);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
#syncs all the files
$foo->downSync($configDir);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub upSync{
my $self=$_[0];
my $configDir=$_[1];
my @files;
if (defined($_[2])) {
@files=@{$_[2]};
}
my $method='downSync';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->selectConfigDir;
if ($self->error) {
warn($self->{module}.' '.$method.': Unable to select a config dir');
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->validConfigDirName($configDir);
if ($self->error) {
warn($self->{module}.' '.$method.':'.$self->error.': Errored checking if the configuration directory name is valid');
return undef;
}
if (defined( $valid )) {
$self->{error}=6;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{baseDir}.'/'.$configDir ) {
$self->{error}=16;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#get the files if if none is specified
if (!defined( $files[0] )) {
@files=$self->listConfigFiles($configDir);
}
#get the files if if none is specified
my @allFiles=$self->listConfigFiles($configDir);
#makes sure all the files exist
my $int=0;
while (defined( $files[$int] )) {
my $matched=0;
my $int2=0;
while (defined( $allFiles[$int2] )) {
if ( $files[$int] eq $allFiles[$int2] ) {
$matched=1;
}
$int2++;
}
#figures out what the new directory will be and checks
my ($name,$path,$suffix) = fileparse( $files[$int] );
if( -f $path ){
$self->{error}=19;
$self->{errorString}='"'.$path.'" should be a directory, but it is a file ';
$self->warn;
return undef;
}
#make sure it is matched
if (!$matched) {
$self->{error}=18;
$self->{errorString}='"'.$files[$int].'" is not tracked';
$self->warn;
return undef;
}
$int++;
}
#copies each file from the fs to the repo
$int=0;
while( defined( $files[$int] ) ){
my $repofile=$self->{baseDir}.'/'.$configDir.'/'.$files[$int];
$repofile=~s/\/\/*/\//g;
#figures out what the new directory will be
my ($name,$path,$suffix) = fileparse( $files[$int] );
#copy it back up from the FS and into the repo
if(! copy($files[$int], $repofile) ){
$self->{error}=19;
$self->{errorString}='"'.$files[$int].'" could not be synced';
$self->warn;
return undef;
}
$int++;
}
return 1;
}
=head2 validConfigDirName
This checks to make sure configuration directory name
is valid.
my $returned=$foo->validConfigDirName($name);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
if(defined( $returned )){
print 'Invalid name... '.$returned."\n";
}
=cut
sub validConfigDirName{
my $self=$_[0];
my $name=$_[1];
my $method='validConfigDirName';
#blank any previous errors
$self->errorblank; # don't really care if a permanent error is set here
#always needs defined...
if (!defined( $name )) {
return 'not defined'
}
#make sure it is not not contain a slash
if ( $name =~ /^\// ) {
return 'matched /^\//';
}
#makes sure the mapping file is not specified
if ($name eq '.mapping' ) {
return 'matched ".mapping"';
}
#can't be any where in the path
if ( $name =~ /\.SysConfigManage/ ) {
return 'matched /\.SysConfigManage/';
}
#make sure it does not start with a period
if ( $name =~ /^\./ ) {
return 'mathced /^\./';
}
return undef;
}
=head1 ERROR CODES
=head2 1
No base directory specified.
=head2 2
No valid selection method specified.
=head2 3
Selection method not specified.
=head2 4
The specified directory does not exist or is not a directory.
=head2 5
The $baseDir.'/.mapping' file does not exist or is not a file.
=head2 6
Invalid config name.
=head2 7
No file specified.
=head2 8
The specified file does not exist or is not a file.
=head2 9
Makes sure the new path under the configuration directory is not a file.
=head2 10
The new path could not be created.
=head2 11
Copying the file failed.
=head2 12
The add command exited with a non-zero.
=head2 13
The selected configuration directory is a file.
=head2 14
The selected configuration directory could not be created.
=head2 15
The selected configuration directory does not exist and autoCreateConfigDir set to false.
=head2 16
The configuration directory does not exist.
=head2 17
Regexp selection did not match any thing and hostname fallback is not enabled.
=head2 18
One of the specified config files is not tracked.
=head2 19
Failed to copy a file for syncing.
=head1 Config Storage
Each config is stored under $baseDir.'/'.$configDir and then each config
is saved under the the configuration directory with the path on the file
system mapped onto the configuration directory.
Lets say the base directory is '/root/configs/' and the configuration
directory is 'foo.bar', with a config file of '/etc/rc.conf', then the
resulting path of the added file is '/root/configs/foo.bar/etc/rc.conf'.
The configuration directory can then be selected by three different methods.
The first method is manually, the third is the regexp method, and the third
is the hostname method. The name of the configuration directory may not
contain any forward slashes or start with a period.
The regexp method reads $baseDir.'/.mapping'. Each line contains two fields.
The first field is the configuration directory under the base directory. The
next field is a regular expression. If the regular expression matches the
hostname, the configuration directory in the first field is used. The first
match is used. Any line starting with a "#" is a comment.
The hostname method uses the hostname for the configuration directory. It also
converts the hostname to lowercase.
Any where in the path, the regexp /\.SysConfigManage/ maynot be found. This
is a reserved directory that will be used some time in the future.
After a file is added, a add command can be used. The add command prior to being
ran will have any instance of '%%%file%%%' replaced with a escaped file name.
Lets say the base directory is '/root/configs/' and the configuration
directory is 'foo.bar', with a config file of '/etc/rc.conf', and a add command
of 'svn add --parents %%%file%%%', then the executed command will be
'svn add --parents /root/configs/foo.bar/etc/rc.conf'.
To help integrate with subversion and git, directories matching /^.git$/ and
/^.svn$/ are ignored.
=head2 Ownership Storage
The path under which the configuration file is stored, under the configuration directory,
has a '.SysConfigManage/UID/' and '.SysConfigManage/GID/' directory. Each directory
contains a corresponding file that mirrors the name of the file in question.
Each file contains either the numeric GID or UID of the file in question.
=head2 Permission Storage
The path under which the configuration file is stored, under the configuration directory,
has a '.SysConfigManage/Perms/'. The directory contains a corresponding file that mirrors
the name of the file in question.
Each file contains either the numeric mode of the file in question.
The regexp below is used for verification.
/^[01246][01234567][01234567][01234567]$/
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-sys-config-manage at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sys-Config-Manage>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Sys::Config::Manage
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Config-Manage>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Sys-Config-Manage>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Sys-Config-Manage>
=item * Search CPAN
L<http://search.cpan.org/dist/Sys-Config-Manage/>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2011 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1; # End of Sys::Config::Manage
lib/Sys/Config/Manage/Ownership.pm view on Meta::CPAN
package Sys::Config::Manage::Ownership;
use warnings;
use strict;
use File::Basename;
use base 'Error::Helper';
use String::ShellQuote;
=head1 NAME
Sys::Config::Manage::Ownership - Handles file user/group ownership for files in the configuration directory.
=head1 VERSION
Version 0.0.0
=cut
our $VERSION = '0.0.0';
=head1 METHODS
=head2 new
This initiates the object.
One argument is required and it is a hash reference.
=head3 args hash ref
=head4 scm
This is a initiated Sys::Config::Manage object.
=head4 defaultUID
This is the default user ID for a file.
If not specified, the default is '0'.
=head4 defaultGID
This is the default group ID for a file.
If not specified, the default is '0'.
$foo=Sys::Config::Manage::Ownership->new(\%args);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub new{
my %args;
if(defined($_[1])){
%args= %{$_[1]};
};
my $method='new';
my $self = {
module=>'Sys-Config-Manage-Ownership',
perror=>undef,
error=>undef,
errorString=>"",
defaultUID=>'0',
defaultGID=>'0',
};
bless $self;
#make sure we have a Sys::Config::Manage
if(!defined( $args{scm} ) ){
$self->{perror}=1;
$self->{error}=1;
$self->{errorString}='Nothing passed for the Sys::Config::Manage object';
$self->warn;
return $self;
}
#make sure that it is really a Sys::Config::Manage object
if( ref( $args{scm} ) ne "Sys::Config::Manage" ){
$self->{perror}=1;
$self->{error}=2;
$self->{errorString}='$args{scm} is not a Sys::Config::Manage object';
$self->warn;
return $self;
}
#figures out what the defualt is
if ( defined( $args{defaultUID} ) ){
#make sure the perms are sane
if ( $args{default} !~ /^[0123456789]*$/ ){
$self->{perror}=1;
$self->{error}=12;
$self->{errorString}='"'.$args{default}.'" does not appear to be a valid value';
$self->warn;
return $self;
}
$self->{defaultUID}=$args{defaultUID};
}
#figures out what the defualt is
if ( defined( $args{defaultGID} ) ){
#make sure the perms are sane
if ( $args{default} !~ /^[0123456789]*$/ ){
$self->{perror}=1;
$self->{error}=12;
$self->{errorString}='"'.$args{default}.'" does not appear to be a valid value';
$self->warn;
return $self;
}
$self->{defaultGID}=$args{defaultGID};
}
$self->{scm}=$args{scm};
return $self;
}
=head2 downSync
This syncs the group/user ownership down from the configuration
directory to the system.
Two arguments can be used.
The first is the configuration directory. If not specified, it will
be automaticallly choosen.
The second is the files to sync. If not specifiedm, all files will
be synced.
#sync the specified files
$foo->downSync( $configDir, \@files);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
#syncs all the files
$foo->downSync( $configDir );
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub downSync{
my $self=$_[0];
my $configDir=$_[1];
my @files;
if (defined($_[2])) {
@files=@{$_[2]};
}
my $method='downSync';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#checks and make sure all the files exist
my $int=0;
if(defined( $files[$int] )){
my @allfiles=$self->{scm}->listConfigFiles($configDir);
if( $self->{scm}->error ){
$self->{error}='16';
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
#make sure each file asked to be synced is tracked
while(defined( $files[$int] )){
my $matched=0;
my $int2=0;
while(defined( $allfiles[$int2] )){
if( $files[$int] eq $allfiles[$int2] ){
$matched=1;
}
$int2++;
}
if(! $matched){
$self->{error}='8';
$self->{errorString}='"'.$files[$int].'" does not exist under the configuration directory, "'.$configDir.'",';
$self->warn;
return undef;
}
$int++;
}
}else{
#if we get here, no files have been specified so we do them all
@files=$self->{scm}->listConfigFiles($configDir);
if( $self->{scm}->error ){
$self->{error}='16';
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#process each file
$int=0;
while( defined( $files[$int] ) ){
#get the perms for the file we will set it on
my $uid=$self->getUID( $configDir, $files[$int] );
if( $self->error ){
warn($self->{module}.' '.$method.': Sys::Config::Manage::Ownership->getUID errored');
return undef;
}
#get the perms for the file we will set it on
my $gid=$self->getGID( $configDir, $files[$int] );
if( $self->error ){
warn($self->{module}.' '.$method.': Sys::Config::Manage::Ownership->getGID errored');
return undef;
}
#try to chmod it
if(!chmod( $uid, $gid, $files[$int] )){
$self->{error}='17';
$self->{errorString}='chown( '.$uid.', '.$gid.', "'.$files[$int].'") errored';
$self->warn;
return undef;
}
$int++;
}
return 1;
}
=head2 getGID
This retrieves the GID for a file.
Two arguments are taken.The first is the configuration directory,
which if not defined is automatically chosen. The second is the
file in question.
my $gid=$foo->getGID( $configDir, $file );
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub getGID{
my $self=$_[0];
my $configDir=$_[1];
my $file=$_[2];
my $method='getGID';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#make value for the file is specified
if (!defined( $file )) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure the file exists, under the config dir
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) {
$self->{error}=8;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#figure out what the perms file is
my ($name,$path,$suffix) = fileparse($file);
my $idfile=$self->{scm}->{baseDir}.'/'.$configDir.'/'.$path.'/.SysConfigManage/GID/'.$name;
#make sure the file has some perms
if (! -f $idfile ){
return $self->{defaultGID};
}
#read the file
my $fh;
if ( ! open( $fh, '<', $idfile ) ){
$self->{error}=15;
$self->{errorString}='Unable to open "'.$idfile.'"';
$self->warn;
return undef;
}
my $id=<$fh>;
chomp($id);
close( $fh );
return $id;
}
=head2 getUID
This retrieves the UID for a file.
Two arguments are taken.The first is the configuration directory,
which if not defined is automatically chosen. The second is the
file in question.
my $UID=$foo->getUID( $configDir, $file );
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub getUID{
my $self=$_[0];
my $configDir=$_[1];
my $file=$_[2];
my $method='getUID';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#make value for the file is specified
if (!defined( $file )) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure the file exists, under the config dir
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) {
$self->{error}=8;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#figure out what the perms file is
my ($name,$path,$suffix) = fileparse($file);
my $idfile=$self->{scm}->{baseDir}.'/'.$configDir.'/'.$path.'/.SysConfigManage/UID/'.$name;
#make sure the file has some perms
if (! -f $idfile ){
return $self->{defaultUID};
}
#read the file
my $fh;
if ( ! open( $fh, '<', $idfile ) ){
$self->{error}=15;
$self->{errorString}='Unable to open "'.$idfile.'"';
$self->warn;
return undef;
}
my $id=<$fh>;
chomp($id);
close( $fh );
return $id;
}
=head2 listConfigFiles
This lists the various config files that are being
tracked that actually have a value specified.
Not all files returned by Sys::Config::Manage->listConfigFiles
will have a value specified.
my @files=$foo->listConfigFiles;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub listConfigFiles{
my $self=$_[0];
my $configDir=$_[1];
my $method='listConfigFiles';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#holds what will be returned
my @found;
#get a list of files
my @files=$self->{scm}->listConfigFiles($configDir);
#process every found file
my $int=0;
while (defined( $files[$int] )) {
my ($name,$path,$suffix)=fileparse($self->{scm}->{baseDir}
.'/'.$configDir.'/'.$files[$int]);
my $UIDfile=$path.'/.SysConfigManage/UID/'.$name;
$UIDfile=~s/\/\/*/\//g;
my $GIDfile=$path.'/.SysConfigManage/GID/'.$name;
$GIDfile=~s/\/\/*/\//g;
#make sure the perms file exists and if so add it
if (
( -f $UIDfile ) ||
( -f $GIDfile )
) {
push(@found, $files[$int]);
}
$int++;
}
return @found;
}
=head2 setGID
This sets the GID for a file. This does require the numeric value.
Three arguments are taken.
The first one is the configuration directory to use. If none is
specified, it will automatically be choosen.
The second is the config file to add the perms for.
The third numeric value for the GID.
$foo->setGID($configDir, $file, $gid);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub setGID{
my $self=$_[0];
my $configDir=$_[1];
my $file=$_[2];
my $id=$_[3];
my $method='setGID';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#make value for the file is specified
if (!defined( $file )) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure the file exists, under the config dir
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) {
$self->{error}=8;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#make sure we have a some perms passed
if ( ! defined( $id ) ){
$self->{error}=11;
$self->{errorString}='No value for the permissions specified';
$self->warn;
return undef;
}
#make sure the perms are sane
if ( $id !~ /^[0123456789]*$/ ){
$self->{error}=12;
$self->{errorString}='"'.$id.'" does not appear to be a valid value';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
#creates the .SysConfigManage if needed
my ($name,$path,$suffix) = fileparse($file);
my $scmd=$self->{scm}->{baseDir}.'/'.$configDir.'/'.$path.'/.SysConfigManage';
if ( ! -d $scmd ){
if ( ! mkdir( $scmd ) ){
$self->{error}=13;
$self->{errorString}='Unable to create "'.$scmd.'"';
$self->warn;
return undef;
}
}
#makes sure that the perms dir exists
my $iddir=$scmd.'/GID';
if ( ! -d $iddir ){
if ( ! mkdir( $iddir ) ){
$self->{error}=14;
$self->{errorString}='Unable to create "'.$iddir.'"';
$self->warn;
return undef;
}
}
#this is the file that will store the perms
my $idfile=$iddir.'/'.$name;
#check if it exists
my $exists=0;
if ( -f $idfile ){
$exists=1;
}
my $fh;
if ( ! open( $fh, '>', $idfile ) ){
$self->{error}=15;
$self->{errorString}='Unable to open "'.$idfile.'"';
$self->warn;
return undef;
}
print $fh $id;
close( $fh );
#add it if it, if it did not exist previously
if ( ! $exists ){
if (defined( $self->{scm}->{addCommand} )) {
my $command=$self->{scm}->{addCommand};
my $newfile=shell_quote($idfile);
$command=~s/\%\%\%file\%\%\%/$newfile/g;
system($command);
my $exit = $?<<8;
if ($exit ne '0') {
$self->{error}=16;
$self->{errorString}='The add command failed. command="'.$command.'" exit="'.$exit.'"';
$self->warn;
return undef;
}
}
}
return 1;
}
=head2 setUID
This sets the UID for a file. This does require the numeric value.
Three arguments are taken.
The first one is the configuration directory to use. If none is
specified, it will automatically be choosen.
The second is the config file to add the perms for.
The third numeric value for the UID.
$foo->setUID($configDir, $file, $uid);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub setUID{
my $self=$_[0];
my $configDir=$_[1];
my $file=$_[2];
my $id=$_[3];
my $method='setUID';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#make value for the file is specified
if (!defined( $file )) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure the file exists, under the config dir
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) {
$self->{error}=8;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#make sure we have a some perms passed
if ( ! defined( $id ) ){
$self->{error}=11;
$self->{errorString}='No value for the permissions specified';
$self->warn;
return undef;
}
#make sure the perms are sane
if ( $id !~ /^[0123456789]*$/ ){
$self->{error}=12;
$self->{errorString}='"'.$id.'" does not appear to be a valid value';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
#creates the .SysConfigManage if needed
my ($name,$path,$suffix) = fileparse($file);
my $scmd=$self->{scm}->{baseDir}.'/'.$configDir.'/'.$path.'/.SysConfigManage';
if ( ! -d $scmd ){
if ( ! mkdir( $scmd ) ){
$self->{error}=13;
$self->{errorString}='Unable to create "'.$scmd.'"';
$self->warn;
return undef;
}
}
#makes sure that the perms dir exists
my $iddir=$scmd.'/UID';
if ( ! -d $iddir ){
if ( ! mkdir( $iddir ) ){
$self->{error}=14;
$self->{errorString}='Unable to create "'.$iddir.'"';
$self->warn;
return undef;
}
}
#this is the file that will store the perms
my $idfile=$iddir.'/'.$name;
#check if it exists
my $exists=0;
if ( -f $idfile ){
$exists=1;
}
my $fh;
if ( ! open( $fh, '>', $idfile ) ){
$self->{error}=15;
$self->{errorString}='Unable to open "'.$idfile.'"';
$self->warn;
return undef;
}
print $fh $id;
close( $fh );
#add it if it, if it did not exist previously
if ( ! $exists ){
if (defined( $self->{scm}->{addCommand} )) {
my $command=$self->{scm}->{addCommand};
my $newfile=shell_quote($idfile);
$command=~s/\%\%\%file\%\%\%/$newfile/g;
system($command);
my $exit = $?<<8;
if ($exit ne '0') {
$self->{error}=16;
$self->{errorString}='The add command failed. command="'.$command.'" exit="'.$exit.'"';
$self->warn;
return undef;
}
}
}
return 1;
}
=head2 setGIDfromFile
This sets the GID for a file, from a already existing file.
Three arguments are taken.
The first one is the configuration directory to use. If none is
specified, it will automatically be choosen.
The second is the config file to add the perms for.
$foo->setUIDfromFile($configDir, $file);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub setGIDfromFile{
my $self=$_[0];
my $configDir=$_[1];
my $file=$_[2];
my $method='setGIDfromFile';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#make value for the file is specified
if (!defined( $file )) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure the file exists, under the config dir
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) {
$self->{error}=8;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#make sure the file exists, on the fs
if (! -f $file ) {
$self->{error}=9;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#make sure it is not under the base directory
if ( ! $self->{scm}->notUnderBase($file) ){
$self->{error}=10;
$self->{errorString}='"'.$file.'" exists under the base directory, "'.$self->{scm}->{baseDir}.'"';
$self->warn;
return undef;
}
#stat the file
my $id = (stat($file))[5];
$self->setGID($configDir, $file, $id);
if ( $self->error ){
warn($self->{module}.' '.$method.': : setUID errored');
return undef;
}
return 1;
}
=head2 setUIDfromFile
This sets the UID for a file, from a already existing file.
Three arguments are taken.
The first one is the configuration directory to use. If none is
specified, it will automatically be choosen.
The second is the config file to add the perms for.
$foo->setUIDfromFile($configDir, $file);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub setUIDfromFile{
my $self=$_[0];
my $configDir=$_[1];
my $file=$_[2];
my $method='setUIDfromFile';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#make value for the file is specified
if (!defined( $file )) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure the file exists, under the config dir
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) {
$self->{error}=8;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#make sure the file exists, on the fs
if (! -f $file ) {
$self->{error}=9;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#make sure it is not under the base directory
if ( ! $self->{scm}->notUnderBase($file) ){
$self->{error}=10;
$self->{errorString}='"'.$file.'" exists under the base directory, "'.$self->{scm}->{baseDir}.'"';
$self->warn;
return undef;
}
#stat the file
my $id = (stat($file))[4];
$self->setUID($configDir, $file, $id);
if ( $self->error ){
warn($self->{module}.' '.$method.': : setUID errored');
return undef;
}
return 1;
}
=head2 upSync
This syncs the file user/group up from the file system to
configuration directory.
Two arguments can be used.
The first is the configuration directory. If not specified, it will
be automaticallly choosen.
The second is the files to sync. If not specified, all files will
be synced.
#sync the specified files
$foo->upSync( $configDir, \@files);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
#syncs all the files
$foo->upSync( $configDir );
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub upSync{
my $self=$_[0];
my $configDir=$_[1];
my @files;
if (defined($_[2])) {
@files=@{$_[2]};
}
my $method='upSync';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#checks and make sure all the files exist
my $int=0;
if(defined( $files[$int] )){
my @allfiles=$self->{scm}->listConfigFiles($configDir);
if( $self->{scm}->error ){
$self->{error}='16';
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
#make sure each file asked to be synced is tracked
while(defined( $files[$int] )){
my $matched=0;
my $int2=0;
while(defined( $allfiles[$int2] )){
if( $files[$int] eq $allfiles[$int2] ){
$matched=1;
}
$int2++;
}
if(! $matched){
$self->{error}='8';
$self->{errorString}='"'.$files[$int].'" does not exist under the configuration directory, "'.$configDir.'",';
$self->warn;
return undef;
}
$int++;
}
}else{
#if we get here, no files have been specified so we do them all
@files=$self->{scm}->listConfigFiles($configDir);
if( $self->{scm}->error ){
$self->{error}='16';
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#process each file
$int=0;
while( defined( $files[$int] ) ){
#try to sync the UID from what it currently is
$self->setUIDfromFile( $configDir, $files[$int] );
if( $self->error ){
warn( $self->{module}.' '.$method.': $self->setUIDfromFile( $configDir, $files[$int] ) errored' );
return undef;
}
#try to sync the GID from what it currently is
$self->setGIDfromFile( $configDir, $files[$int] );
if( $self->error ){
warn( $self->{module}.' '.$method.': $self->setGIDfromFile( $configDir, $files[$int] ) errored' );
return undef;
}
$int++;
}
return 1;
}
=head1 ERROR CODES
=head2 1
Nothing passed for the Sys::Config::Manage object.
=head2 2
$args{scm} is not a Sys::Config::Manage object.
=head2 3
Invalid configuration directory name.
=head2 4
The configuration directory does not exist.
=head2 5
Sys::Config::Manage->selectConfigDir errored.
=head2 6
Sys::Config::Manage->validConfigDirName errored.
=head2 7
No filename specified.
=head2 8
The specified file does not exist under the configuration directory.
=head2 9
The specified file does not exist on the file system.
=head2 10
The file specified file is under the base directory.
=head2 11
No value for the permissions specified.
=head2 12
The value specified for the [UG]ID does not appear to be valid.
Validity is checked via the regexp below.
/^[0123456789]*$/
=head2 13
The ".SysConfigManage" directory does not exist and could not be created.
=head2 14
The ".SysConfigManage/UID" directory does not exist and could not be created.
=head2 15
Unable to opens the [GU]ID file.
=head2 16
The add command failed.
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-sys-config-manage-perms at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sys-Config-Manage-Ownership>. I will
be notified, and then you'll automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Sys::Config::Manage::Ownership
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Config-Manage>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Sys-Config-Manage>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Sys-Config-Manage>
=item * Search CPAN
L<http://search.cpan.org/dist/Sys-Config-Manage/>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2011 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1; # End of Sys::Config::Manage::Ownership
lib/Sys/Config/Manage/Perms.pm view on Meta::CPAN
package Sys::Config::Manage::Perms;
use warnings;
use strict;
use File::Basename;
use base 'Error::Helper';
use String::ShellQuote;
=head1 NAME
Sys::Config::Manage::Perms - Handles file permissions for files in a configuration directory.
=head1 VERSION
Version 0.0.0
=cut
our $VERSION = '0.0.0';
=head1 SYNOPSIS
use Sys::Config::Manage::Perms;
my $foo = Sys::Config::Manage::Perms->new();
...
=head1 METHODS
=head2 new
This initiates the object.
One argument is required and it is a hash reference.
=head3 args hash ref
=head4 scm
This is a initiated Sys::Config::Manage object.
=head4 default
Default value to use for the mode.
If not specified, it defaults to '0644'.
$foo=Sys::Config::Manage::Perms->new(\%args);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub new{
my %args;
if(defined($_[1])){
%args= %{$_[1]};
};
my $method='new';
my $self = {
module=>'Sys-Config-Manage-Perms',
perror=>undef,
error=>undef,
errorString=>"",
default=>'0644',
};
bless $self;
#make sure we have a Sys::Config::Manage
if(!defined( $args{scm} ) ){
$self->{perror}=1;
$self->{error}=1;
$self->{errorString}='Nothing passed for the Sys::Config::Manage object';
$self->warn;
return $self;
}
#make sure that it is really a Sys::Config::Manage object
if( ref( $args{scm} ) ne "Sys::Config::Manage" ){
$self->{perror}=1;
$self->{error}=2;
$self->{errorString}='$args{scm} is not a Sys::Config::Manage object';
$self->warn;
return $self;
}
#figures out what the defualt is
if ( defined( $args{default} ) ){
#make sure the perms are sane
if ( $args{default} !~ /^[01246][01234567][01234567][01234567]$/ ){
$self->{perror}=1;
$self->{error}=12;
$self->{errorString}='"'.$args{default}.'" does not appear to be a valid value';
$self->warn;
return $self;
}
$self->{default}=$args{default};
}
$self->{scm}=$args{scm};
return $self;
}
=head2 downSync
This syncs the file permissions down from the configuration
directory to the system.
Two arguments can be used.
The first is the configuration directory. If not specified, it will
be automaticallly choosen.
The second is the files to sync. If not specifiedm, all files will
be synced.
#sync the specified files
$foo->downSync( $configDir, \@files);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
#syncs all the files
$foo->downSync( $configDir );
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub downSync{
my $self=$_[0];
my $configDir=$_[1];
my @files;
if (defined($_[2])) {
@files=@{$_[2]};
}
my $method='downSync';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#checks and make sure all the files exist
my $int=0;
if(defined( $files[$int] )){
my @allfiles=$self->{scm}->listConfigFiles($configDir);
if( $self->{scm}->error ){
$self->{error}='16';
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
#make sure each file asked to be synced is tracked
while(defined( $files[$int] )){
my $matched=0;
my $int2=0;
while(defined( $allfiles[$int2] )){
if( $files[$int] eq $allfiles[$int2] ){
$matched=1;
}
$int2++;
}
if(! $matched){
$self->{error}='8';
$self->{errorString}='"'.$files[$int].'" does not exist under the configuration directory, "'.$configDir.'",';
$self->warn;
return undef;
}
$int++;
}
}else{
#if we get here, no files have been specified so we do them all
@files=$self->{scm}->listConfigFiles($configDir);
if( $self->{scm}->error ){
$self->{error}='16';
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#process each file
$int=0;
while( defined( $files[$int] ) ){
#get the perms for the file we will set it on
my $perms=$self->getPerms( $configDir, $files[$int] );
if( $self->error ){
warn($self->{module}.' '.$method.': Sys::Config::Manage::Perms->getPerms errored');
return undef;
}
#try to chmod it
if(!chmod( oct($perms), $files[$int] )){
$self->{error}='17';
$self->{errorString}='chmod( '.$perms.', "'.$files[$int].'") errored';
$self->warn;
return undef;
}
$int++;
}
return 1;
}
=head2 getPerms
This retrieves the mode for a file.
Two arguments are taken.The first is the configuration directory,
which if not defined is automatically chosen. The second is the
file in question.
my $mode=$foo->getPerms( $configDir, $file );
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub getPerms{
my $self=$_[0];
my $configDir=$_[1];
my $file=$_[2];
my $method='getPerms';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#make value for the file is specified
if (!defined( $file )) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure the file exists, under the config dir
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) {
$self->{error}=8;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#figure out what the perms file is
my ($name,$path,$suffix) = fileparse($file);
my $permsfile=$self->{scm}->{baseDir}.'/'.$configDir.'/'.$path.'/.SysConfigManage/Perms/'.$name;
#make sure the file has some perms
if (! -f $permsfile ){
return $self->{default};
}
#read the file
my $fh;
if ( ! open( $fh, '<', $permsfile ) ){
$self->{error}=15;
$self->{errorString}='Unable to open "'.$permsfile.'"';
$self->warn;
return undef;
}
my $perms=<$fh>;
chomp($perms);
close( $fh );
return $perms;
}
=head2 listConfigFiles
This lists the various config files that are being
tracked that actually have a value specified.
Not all files returned by Sys::Config::Manage->listConfigFiles
will have a value specified.
my @files=$foo->listConfigFiles;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub listConfigFiles{
my $self=$_[0];
my $configDir=$_[1];
my $method='listConfigFiles';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#holds what will be returned
my @found;
#get a list of files
my @files=$self->{scm}->listConfigFiles($configDir);
#process every found file
my $int=0;
while (defined( $files[$int] )) {
my ($name,$path,$suffix)=fileparse($self->{scm}->{baseDir}
.'/'.$configDir.'/'.$files[$int]);
my $permsFile=$path.'/.SysConfigManage/Perms/'.$name;
$permsFile=~s/\/\/*/\//g;
#make sure the perms file exists and if so add it
if ( -f $permsFile ) {
push(@found, $files[$int]);
}
$int++;
}
return @found;
}
=head2 setPerms
This sets the permissions for a file. This does require the numeric value.
Three arguments are taken.
The first one is the configuration directory to use. If none is
specified, it will automatically be choosen.
The second is the config file to add the perms for.
The third numeric value for the permissions.
$foo->setPerms($configDir, $file, '0640');
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub setPerms{
my $self=$_[0];
my $configDir=$_[1];
my $file=$_[2];
my $perms=$_[3];
my $method='setPerms';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#make value for the file is specified
if (!defined( $file )) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure the file exists, under the config dir
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) {
$self->{error}=8;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#make sure we have a some perms passed
if ( ! defined( $perms ) ){
$self->{error}=11;
$self->{errorString}='No value for the permissions specified';
$self->warn;
return undef;
}
#make sure the perms are sane
if ( $perms !~ /^[01246][01234567][01234567][01234567]$/ ){
$self->{error}=12;
$self->{errorString}='"'.$perms.'" does not appear to be a valid value';
warn($self->{module}.' '.$method.':'.$self->error.': '.$self->errorString);
return undef;
}
#creates the .SysConfigManage if needed
my ($name,$path,$suffix) = fileparse($file);
my $scmd=$self->{scm}->{baseDir}.'/'.$configDir.'/'.$path.'/.SysConfigManage';
if ( ! -d $scmd ){
if ( ! mkdir( $scmd ) ){
$self->{error}=13;
$self->{errorString}='Unable to create "'.$scmd.'"';
$self->warn;
return undef;
}
}
#makes sure that the perms dir exists
my $permsdir=$scmd.'/Perms';
if ( ! -d $permsdir ){
if ( ! mkdir( $permsdir ) ){
$self->{error}=14;
$self->{errorString}='Unable to create "'.$permsdir.'"';
$self->warn;
return undef;
}
}
#this is the file that will store the perms
my $permsfile=$permsdir.'/'.$name;
#check if it exists
my $exists=0;
if ( -f $permsfile ){
$exists=1;
}
my $fh;
if ( ! open( $fh, '>', $permsfile ) ){
$self->{error}=15;
$self->{errorString}='Unable to open "'.$permsfile.'"';
$self->warn;
return undef;
}
print $fh $perms;
close( $fh );
#add it if it, if it did not exist previously
if ( ! $exists ){
if (defined( $self->{scm}->{addCommand} )) {
my $command=$self->{scm}->{addCommand};
my $newfile=shell_quote($permsfile);
$command=~s/\%\%\%file\%\%\%/$newfile/g;
system($command);
my $exit = $?<<8;
if ($exit ne '0') {
$self->{error}=16;
$self->{errorString}='The add command failed. command="'.$command.'" exit="'.$exit.'"';
$self->warn;
return undef;
}
}
}
return 1;
}
=head2 setPermsFromFile
This sets the permissions for a file, from a already existing file.
Three arguments are taken.
The first one is the configuration directory to use. If none is
specified, it will automatically be choosen.
The second is the config file to add the perms for.
$foo->setPermsFromFile($configDir, $file);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub setPermsFromFile{
my $self=$_[0];
my $configDir=$_[1];
my $file=$_[2];
my $method='setPermsFromFile';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#make value for the file is specified
if (!defined( $file )) {
$self->{error}=7;
$self->{errorString}='No file specified';
$self->warn;
return undef;
}
#make sure the file exists, under the config dir
if (! -f $self->{scm}->{baseDir}.'/'.$configDir.'/'.$file ) {
$self->{error}=8;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#make sure the file exists, on the fs
if (! -f $file ) {
$self->{error}=9;
$self->{errorString}='The file does not exist in the configuration directory';
$self->warn;
return undef;
}
#make sure it is not under the base directory
if ( ! $self->{scm}->notUnderBase($file) ){
$self->{error}=10;
$self->{errorString}='"'.$file.'" exists under the base directory, "'.$self->{scm}->{baseDir}.'"';
$self->warn;
return undef;
}
#stat the file
my $mode = (stat($file))[2] & 07777;
$mode=sprintf("%04o", $mode);
$self->setPerms($configDir, $file, $mode);
if ( $self->error ){
warn($self->{module}.' '.$method.': : setPerm errored');
return undef;
}
return 1;
}
=head2 upSync
This syncs the file permissions up from the file system to
configuration directory.
Two arguments can be used.
The first is the configuration directory. If not specified, it will
be automaticallly choosen.
The second is the files to sync. If not specifiedm, all files will
be synced.
#sync the specified files
$foo->upSync( $configDir, \@files);
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
#syncs all the files
$foo->upSync( $configDir );
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
=cut
sub upSync{
my $self=$_[0];
my $configDir=$_[1];
my @files;
if (defined($_[2])) {
@files=@{$_[2]};
}
my $method='downSync';
#blank any previous errors
if (!$self->errorblank) {
return undef;
}
#make sure we have a directory to use
if (!defined($configDir)) {
$configDir=$self->{scm}->selectConfigDir;
if ($self->{scm}->error) {
$self->{error}=5;
$self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#make sure the config directory is valid
my $valid=$self->{scm}->validConfigDirName($configDir);
if ($self->{scm}->error) {
$self->{error}=6;
$self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
if (defined( $valid )) {
$self->{error}=3;
$self->{errorString}='The configuration directory name '.$valid;
$self->warn;
return undef;
}
#makes sure it exists
if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) {
$self->{error}=4;
$self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist';
$self->warn;
return undef;
}
#checks and make sure all the files exist
my $int=0;
if(defined( $files[$int] )){
my @allfiles=$self->{scm}->listConfigFiles($configDir);
if( $self->{scm}->error ){
$self->{error}='16';
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
#make sure each file asked to be synced is tracked
while(defined( $files[$int] )){
my $matched=0;
my $int2=0;
while(defined( $allfiles[$int2] )){
if( $files[$int] eq $allfiles[$int2] ){
$matched=1;
}
$int2++;
}
if(! $matched){
$self->{error}='8';
$self->{errorString}='"'.$files[$int].'" does not exist under the configuration directory, "'.$configDir.'",';
$self->warn;
return undef;
}
$int++;
}
}else{
#if we get here, no files have been specified so we do them all
@files=$self->{scm}->listConfigFiles($configDir);
if( $self->{scm}->error ){
$self->{error}='16';
$self->{errorString}='Sys::Config::Manage->listConfigFiles errored error="'.
$self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"';
$self->warn;
return undef;
}
}
#process each file
$int=0;
while( defined( $files[$int] ) ){
#try to sync it from what it currently is
$self->setPermsFromFile( $configDir, $files[$int] );
if( $self->error ){
warn( $self->{module}.' '.$method.': $self->setPermsFromFile( $configDir, $files[$int] ) errored' );
return undef;
}
$int++;
}
return 1;
}
=head1 ERROR CODES
=head2 1
Nothing passed for the Sys::Config::Manage object.
=head2 2
$args{scm} is not a Sys::Config::Manage object.
=head2 3
Invalid configuration directory name.
=head2 4
The configuration directory does not exist.
=head2 5
Sys::Config::Manage->selectConfigDir errored.
=head2 6
Sys::Config::Manage->validConfigDirName errored.
=head2 7
No filename specified.
=head2 8
The specified file does not exist under the configuration directory.
=head2 9
The specified file does not exist on the file system.
=head2 10
The file specified file is under the base directory.
=head2 11
No value for the permissions specified.
=head2 12
The value specified for the permissions does not appear to be valid.
Validity is checked via the regexp below.
/^[01246][01234567][01234567][01234567]$/
=head2 13
The ".SysConfigManage" directory does not exist and could not be created.
=head2 14
The ".SysConfigManage/Perms" directory does not exist and could not be created.
=head2 15
Unable to opens the permissions file.
=head2 16
The add command failed.
=head1 AUTHOR
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-sys-config-manage-perms at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sys-Config-Manage-Perms>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Sys::Config::Manage::Perms
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Config-Manage>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Sys-Config-Manage>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Sys-Config-Manage>
=item * Search CPAN
L<http://search.cpan.org/dist/Sys-Config-Manage/>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2011 Zane C. Bowers-Hadley.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1; # End of Sys::Config::Manage::Perms