NAME
Sys::Config::Manage - Manages system configuration information.
VERSION
Version 0.3.1
SYNOPSIS
use Sys::Config::Manage;
my $foo = Sys::Config::Manage->new();
...
METHODS
new
args hash
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.
autoCreateConfigDir
If this is specified, the configuration directory will automatically be created under the base directory if needed.
This defaults to false, 0.
baseDir
The base directory the config base is stored in.
hostnameFallback
If the regexp selection method is being used, the hostname method will be used.
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);
}
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);
}
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');
}
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);
}
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);
}
getAutoCreateConfigDir
This returns the autoCreateConfigDir value.
my $autoCreateConfigDir=$foo->getBaseDir;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
getBaseDir
This returns what the base directory is set to.
my $baseDir=$foo->getBaseDir;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
getHostnameFallback
This returns the current value for hostnameFallback.
my $hostnameFallback=$foo->getHostnameFallback;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
getSelectionMethod
This returns the current selection method.
my $selectionMethod=$foo->getSelectionMethod;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
listConfigDirs
This lists the available configuration directories.
my @dirs=$foo->listConfigDirs;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
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);
}
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".
}
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');
}
}
selectConfigDir
This selects the configuration directory to use.
my $configDir=$foo->selectConfigDir;
if($foo->error){
warn('error:'.$foo->error.': '.$foo->errorString);
}
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);
}
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);
}
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);
}
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);
}
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";
}
ERROR CODES
1
No base directory specified.
2
No valid selection method specified.
3
Selection method not specified.
4
The specified directory does not exist or is not a directory.
5
The $baseDir.'/.mapping' file does not exist or is not a file.
6
Invalid config name.
7
No file specified.
8
The specified file does not exist or is not a file.
9
Makes sure the new path under the configuration directory is not a file.
10
The new path could not be created.
11
Copying the file failed.
12
The add command exited with a non-zero.
13
The selected configuration directory is a file.
14
The selected configuration directory could not be created.
15
The selected configuration directory does not exist and autoCreateConfigDir set to false.
16
The configuration directory does not exist.
17
Regexp selection did not match any thing and hostname fallback is not enabled.
18
One of the specified config files is not tracked.
19
Failed to copy a file for syncing.
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.
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.
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]$/
AUTHOR
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
BUGS
Please report any bugs or feature requests to bug-sys-config-manage at rt.cpan.org
, or through the web interface at 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.
SUPPORT
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
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
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.