From c9a831c314bcc88a76c3f8ddf4804591ad19d0a6 Mon Sep 17 00:00:00 2001 From: Flavio Poletti Date: Mon, 12 Aug 2013 18:53:13 +0200 Subject: [PATCH] added and rationalized some options --- remote | 103 +++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 58 insertions(+), 45 deletions(-) diff --git a/remote b/remote index 3ea9a2c..19de5ac 100755 --- a/remote +++ b/remote @@ -3,7 +3,7 @@ use strict; use warnings; use 5.006_002; -our $VERSION = '0.0.3'; +our $VERSION = '0.2.0'; use English qw( -no_match_vars ); use Fatal qw( close chdir opendir closedir ); use File::Temp qw( tempdir ); @@ -16,41 +16,49 @@ use Cwd qw( getcwd ); use Fcntl qw( :seek ); # *** NOTE *** LEAVE EMPTY LINE ABOVE - my %default_config = ( # default values - workdir => '/tmp/our-deploy', - cleanup => 1, - deploy => 1, - tempdir => 1, + workdir => '/tmp/our-deploy', + cleanup => 1, + 'no-exec' => 0, + tempdir => 1, + passthrough => 0, + verbose => 0, ); -my %config; -GetOptions( - \%config, - qw( - usage|help|man! - version! - - bundle|all-exec|X! - cleanup|c! - deploy! - dryrun|dry-run|n! - filelist|list|l! - heretar|here-tar|H! - inspect|i=s - no-tar! - roottar|root-tar|R! - show|show-options|s! - tar|t=s - tempdir! - workdir|work-directory|deploy-directory|w=s - ), -) or short_usage(); + +my $DATA_POSITION = tell DATA; # GLOBAL VARIABLE +my %script_config = (%default_config, get_config()); + +my %config = %script_config; +if (! $config{passthrough}) { + my %cmdline_config; + GetOptions( + \%cmdline_config, + qw( + usage|help|man! + version! + + bundle|all-exec|X! + cleanup|c! + dryrun|dry-run|n! + filelist|list|l! + heretar|here-tar|H! + inspect|i=s + no-exec! + no-tar! + roottar|root-tar|R! + show|show-options|s! + tar|t=s + tempdir! + verbose! + workdir|work-directory|deploy-directory|w=s + ), + ) or short_usage(); + %config = (%config, %cmdline_config); +} usage() if $config{usage}; version() if $config{version}; -my $DATA_POSITION = tell DATA; - if ($config{roottar}) { binmode STDOUT; my ($fh, $size) = locate_file('root'); @@ -65,16 +73,12 @@ if ($config{heretar}) { exit 0; } ## end if ($config{heretar}) -my %script_config = (%default_config, get_config()); if ($config{show}) { require Data::Dumper; print {*STDOUT} Data::Dumper::Dumper(\%script_config); exit 1; } -# Merge configurations and go on -%config = (%script_config, %config); - if ($config{inspect}) { $config{cleanup} = 0; $config{'deploy'} = 0; @@ -101,7 +105,8 @@ if ($config{filelist}) { # go into the working directory, creating any intermediate if needed mkpath($config{workdir}); chdir($config{workdir}); -print {*STDERR} "### Got into working directory '$config{workdir}'\n\n"; +print {*STDERR} "### Got into working directory '$config{workdir}'\n\n" + if $config{verbose}; my $tempdir; if ($config{'tempdir'}) { # Only if allowed @@ -109,17 +114,21 @@ if ($config{'tempdir'}) { # Only if allowed $tempdir = tempdir($now . 'X' x 10, DIR => '.', CLEANUP => $config{cleanup}); - chdir $tempdir; - print {*STDERR} - "### Created and got into temporary directory '$tempdir'\n"; - print {*STDERR} "### (will clean it up later)\n" if $config{cleanup}; - print {*STDERR} "\n"; + chdir $tempdir + or die "chdir('$tempdir'): $OS_ERROR\n"; + + if ($config{verbose}) { + print {*STDERR} + "### Created and got into temporary directory '$tempdir'\n"; + print {*STDERR} "### (will clean it up later)\n" if $config{cleanup}; + print {*STDERR} "\n"; + } } ## end if ($config{'tempdir'}) eval { # Not really needed, but you know... $ENV{PATH} = '/bin:/usr/bin:/sbin:/usr/sbin'; save_files(); - execute_deploy_programs() if $config{'deploy'}; + execute_deploy_programs() unless $config{'no-exec'}; }; warn "$EVAL_ERROR\n" if $EVAL_ERROR; @@ -202,7 +211,8 @@ sub execute_deploy_programs { my @deploy_programs = @{$config{deploy} || []}; if ($config{bundle}) { # add all executable scripts in current directory - print {*STDERR} "### Auto-deploying all executables in main dir\n\n"; + print {*STDERR} "### Auto-deploying all executables in main dir\n\n" + if $config{verbose}; my %flag_for = map { $_ => 1 } @deploy_programs; opendir my $dh, '.'; for my $item (sort readdir $dh) { @@ -219,12 +229,15 @@ sub execute_deploy_programs { $deploy = catfile('.', $deploy) unless file_name_is_absolute($deploy); if (!-x $deploy) { - print {*STDERR} "### Skipping '$deploy', not executable\n\n"; + print {*STDERR} "### Skipping '$deploy', not executable\n\n" + if $config{verbose}; next DEPLOY; } - print {*STDERR} "### Executing '$deploy'...\n"; + print {*STDERR} "### Executing '$deploy'...\n" + if $config{verbose}; system {$deploy} $deploy, @ARGV; - print {*STDERR} "\n"; + print {*STDERR} "\n" + if $config{verbose}; } ## end for my $deploy (@deploy_programs) return; -- 2.11.4.GIT