#!/usr/bin/perl -w # =head1 NAME cbusterize - Creates the correct CasparBuster structure in your CMS environment =head1 SYNOPSIS cbusterize [options] --source /path/to/file/to/CasparBusterize Options: --debug |-d debug mode --help |-h brief help message --man full documentation --source |-s directory or file to copy in the CasparBuster tree --machine|-m machine to consider in the subtree =head1 OPTIONS =over 4 =item B<--debug> Enter debug mode. This will print what would be done. No commands are executed, so this is safe to use when testing. =item B<--help> Print a brief help message and exits. =item B<--man> Prints the manual page and exits. =item B<--machine> I Specify the machine to consider when dealing with the CasparBuster structure. The file will be taken from this machine, and a subdirectory named after the machine will be used under the basedir to host the directory structure to manage =item B<--source> I Specify the path to the source file or directory to manage with CasparBuster. =back =head1 DESCRIPTION Creates a directory under the machine dir passed as parameter in working directory or directory passed as parameter named like the last path element of the parameter, and creates the standard CasparBuster setup that refers to the parameter path in the new directory, and configuration files when possible. It also copies the original config file into the new dir. Is reasonably picky about path names, tries to avoid common errors. Schema looks like: Base dir | |- machine1 (optional) | | | |-- conf dir1 | | | | | |- conf file 1 | [...] [...] | |- machine2 (optional) | | | |-- conf dir2 | | | | | |- conf file 2 | [...] [...] Use of machines require use of option -m (if using cbusemachines in cb.conf) If not, the conf dirs are directly attached to the base dir =head1 EXAMPLES # this will create the appropriate CasparBuster environment # under the base ~/prj/musique-ancienne.org directory (Cf cbbasedir in cb.conf) # containing the directory victoria2 for this machine # under which it will copy the required structure if needed (/etc/ssh) # to finaly put a copy of the file sshd_conf in it from the victoria2 machine cbusterize -m victoria2 -s /etc/ssh/sshd_config =head1 AUTHOR =over 4 Bruno Cornec, http://brunocornec.wordpress.com =back =head1 LICENSE Copyright (C) 2012 Bruno Cornec Released under the GPLv2 or the Artistic license at your will. =cut use strict; use CasparBuster::Version; use CasparBuster::Env; #use Cwd 'realpath'; use File::Find; use File::Copy; use File::Basename; use File::Path; use File::Glob ':glob'; use Getopt::Long; use Pod::Usage; use Data::Dumper; use List::Util qw(first); use ProjectBuilder::Base; use ProjectBuilder::Conf; # settings my $debug = 0; my $help = undef; my $man = undef; my $source = undef; my $machine = undef; my $plugin = undef; my $quiet = undef; my $log = undef; my $LOG = undef; my ($cbver,$cbrev) = cb_version_init(); my $appname = "cb"; $ENV{'PBPROJ'} = $appname; pb_temp_init(); # Initialize the syntax string pb_syntax_init("$appname (aka CasparBuster) Version $cbver-$cbrev\n"); # parse command-line options GetOptions( 'machine|m=s' => \$machine, 'debug|d+' => \$debug, 'help|h' => \$help, 'quiet|q' => \$quiet, 'man' => \$man, 'log-files|l=s' => \$log, 'source|s=s' => \$source, 'plugin|p=s' => \$plugin, ) || pb_syntax(-1,0); if (defined $help) { pb_syntax(0,1); } if (defined $man) { pb_syntax(0,2); } if (defined $quiet) { $debug=-1; } if (defined $log) { open(LOG,"> $log") || die "Unable to log to $log: $!"; $LOG = \*LOG; $debug = 0 if ($debug == -1); } $pbdebug = $debug; pb_log_init($debug, $LOG); pb_log(0,"Starting cbusterize\n"); # Get conf file in context pb_conf_init($appname); # The personal one if there is such pb_conf_add("$ENV{'HOME'}/.cbrc") if (-f "$ENV{'HOME'}/.cbrc"); # The system one pb_conf_add(cb_env_conffile()); # Get configuration parameters my %cb; my $cb = \%cb; ($cb->{'basedir'},$cb->{'database'},$cb->{'usemachines'},$cb->{'pluginsdir'},$cb->{'cms'}) = pb_conf_get("cbbasedir","cbdatabase","cbusemachines","cbpluginssubdir","cbcms"); print Dumper($cb) if ($debug); # Check for mandatory params pod2usage("Error: --source or --plugin is a mandatory argument\n") if ((not defined $source) && (not defined $plugin)); pod2usage("Error: --machine is a mandatory argument when configure with cbusemachines = true\n") if (($cb->{'usemachines'}->{$appname} =~ /true/) && (not defined $machine)); if (defined $plugin) { # Load plugin conf } my $basedir = $cb->{'basedir'}->{$appname}; eval { $basedir =~ s/(\$ENV.+\})/$1/eeg }; # debug mode overview if ($debug) { print <