[186] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | # $Id: dasscm 929 2010-09-23 12:45:44Z joergs $
|
---|
| 4 |
|
---|
| 5 | use strict;
|
---|
| 6 |
|
---|
[208] | 7 | use Env
|
---|
[235] | 8 | qw($DASSCM_PROD $DASSCM_REPO $USER $DASSCM_USERNAME $DASSCM_USER $DASSCM_PASSWORD $SHELL);
|
---|
[186] | 9 | use Cwd;
|
---|
[907] | 10 | use Getopt::Long;
|
---|
[186] | 11 | use File::Basename;
|
---|
[209] | 12 | use File::Compare;
|
---|
[891] | 13 | ## used system("cp -a"), because File::Copy does not keep permissions
|
---|
| 14 | ##use File::Copy;
|
---|
[237] | 15 | use File::Find;
|
---|
[186] | 16 | use File::stat;
|
---|
| 17 | use File::Path;
|
---|
[214] | 18 | use Term::ReadKey;
|
---|
[239] | 19 |
|
---|
[894] | 20 | use Data::Dumper;
|
---|
[186] | 21 |
|
---|
[189] | 22 | #####################################################################
|
---|
| 23 | #
|
---|
[186] | 24 | # global
|
---|
[189] | 25 | #
|
---|
[205] | 26 |
|
---|
[253] | 27 | # shell exit codes
|
---|
[252] | 28 | my $RETURN_OK = 0;
|
---|
| 29 | my $RETURN_NOK = 1;
|
---|
| 30 |
|
---|
[277] | 31 | # Nagios return codes
|
---|
[290] | 32 | my $RETURN_WARN = 1;
|
---|
| 33 | my $RETURN_CRIT = 2;
|
---|
[277] | 34 | my $RETURN_UNKNOWN = 3;
|
---|
| 35 |
|
---|
[238] | 36 | # documentation file (for usage)
|
---|
| 37 | my $doc_file = "/usr/share/doc/packages/dasscm/dasscm_howto.txt";
|
---|
| 38 |
|
---|
[884] | 39 | my $config_file = "/etc/dasscm.conf";
|
---|
| 40 | my $config = get_config($config_file);
|
---|
[252] | 41 |
|
---|
[894] | 42 | my @OPTIONS_GLOBAL = ( 'help', 'verbose' );
|
---|
| 43 |
|
---|
[884] | 44 | my %COMMANDS = (
|
---|
[889] | 45 | 'help' => 'help',
|
---|
| 46 | 'login' => 'login',
|
---|
| 47 | 'init' => 'init',
|
---|
| 48 | 'ls' => 'ls',
|
---|
| 49 | 'update' => 'update',
|
---|
| 50 | 'up' => 'update',
|
---|
| 51 | 'add' => 'add',
|
---|
| 52 | 'commit' => 'commit',
|
---|
| 53 | 'checkin' => 'commit',
|
---|
| 54 | 'ci' => 'commit',
|
---|
| 55 | 'revert' => 'revert',
|
---|
| 56 | 'blame' => 'blame',
|
---|
| 57 | 'diff' => 'diff',
|
---|
| 58 | 'status' => 'status',
|
---|
| 59 | 'st' => 'status',
|
---|
| 60 | 'check' => 'check',
|
---|
| 61 | 'permissions' => 'permissions',
|
---|
| 62 | 'cleanup' => 'cleanup',
|
---|
| 63 | 'complete' => 'complete',
|
---|
| 64 | 'complete_path' => 'complete_path',
|
---|
[887] | 65 | 'complete_repopath' => 'complete_repopath',
|
---|
[916] | 66 | 'plugins' => 'plugins',
|
---|
[884] | 67 | );
|
---|
| 68 |
|
---|
| 69 | # desc: description (eg. for usage)
|
---|
| 70 | # params: parameters
|
---|
| 71 | # CMD
|
---|
| 72 | # USER
|
---|
[891] | 73 | # PATH_PROD
|
---|
| 74 | # PATH_REPO
|
---|
[889] | 75 | # require:
|
---|
[884] | 76 | # WRITE commands that require write access (and therefore a login)
|
---|
| 77 | my %COMMAND_DEFINITIONS = (
|
---|
| 78 | 'help' => {
|
---|
[914] | 79 | 'desc' => ["print help and usage information"],
|
---|
[889] | 80 | 'params' => ["CMD"],
|
---|
[884] | 81 | 'function' => \&help,
|
---|
| 82 | },
|
---|
| 83 | 'login' => {
|
---|
[914] | 84 | 'desc' => ["user login to Subversion repositoty"],
|
---|
[889] | 85 | 'params' => ["USER"],
|
---|
[884] | 86 | 'function' => \&login
|
---|
| 87 | },
|
---|
| 88 | 'init' => {
|
---|
[889] | 89 | 'desc' => [
|
---|
| 90 | "initialize local subversion checkout.",
|
---|
| 91 | "This is the first thing to do (after configuring $config_file)"
|
---|
| 92 | ],
|
---|
| 93 | 'params' => [],
|
---|
[884] | 94 | 'function' => \&init
|
---|
| 95 | },
|
---|
| 96 | 'ls' => {
|
---|
[914] | 97 | 'desc' => ["list file from repository"],
|
---|
[891] | 98 | 'params' => ["PATH_REPO"],
|
---|
[884] | 99 | 'function' => \&ls
|
---|
| 100 | },
|
---|
| 101 | 'update' => {
|
---|
[914] | 102 | 'desc' => [
|
---|
| 103 | "update local repository checkout",
|
---|
| 104 | "Normally, this is done automatically"
|
---|
| 105 | ],
|
---|
[891] | 106 | 'params' => ["PATH_REPO"],
|
---|
[884] | 107 | 'function' => \&update
|
---|
| 108 | },
|
---|
| 109 | 'add' => {
|
---|
[914] | 110 | 'desc' => [
|
---|
| 111 | "add a file to the subversion repository",
|
---|
| 112 | "Unlike the native svn command,",
|
---|
| 113 | "dasscm adds and immediatly submits a file to the subversion repository"
|
---|
| 114 | ],
|
---|
[891] | 115 | 'params' => ["PATH_PROD"],
|
---|
[893] | 116 | 'options' => [ 'verbose', 'message=s' ],
|
---|
[889] | 117 | 'require' => ["WRITE"],
|
---|
[884] | 118 | 'function' => \&add
|
---|
| 119 | },
|
---|
| 120 | 'commit' => {
|
---|
[914] | 121 | 'desc' => ["commit a changed file to the subversion repository"],
|
---|
[895] | 122 | ## TODO: only modified files
|
---|
[891] | 123 | 'params' => ["PATH_REPO"],
|
---|
[893] | 124 | 'options' => [ 'verbose', 'message=s' ],
|
---|
[889] | 125 | 'require' => ["WRITE"],
|
---|
[884] | 126 | 'function' => \&commit
|
---|
| 127 | },
|
---|
| 128 | 'revert' => {
|
---|
[914] | 129 | 'desc' => [
|
---|
| 130 | "revert local changes back to version from the repository (see diff)"
|
---|
| 131 | ],
|
---|
[891] | 132 | 'params' => ["PATH_REPO"],
|
---|
[884] | 133 | 'function' => \&revert
|
---|
| 134 | },
|
---|
| 135 | 'blame' => {
|
---|
[914] | 136 | 'desc' => ['like "svn blame"'],
|
---|
[891] | 137 | ## TODO: only files from PATH_REPO
|
---|
| 138 | 'params' => ["PATH_REPO"],
|
---|
[884] | 139 | 'function' => \&blame
|
---|
| 140 | },
|
---|
| 141 | 'diff' => {
|
---|
[914] | 142 | 'desc' => [
|
---|
| 143 | 'display the differences between files on the system and the repository'
|
---|
| 144 | ],
|
---|
[891] | 145 | 'params' => ["PATH_REPO"],
|
---|
[884] | 146 | 'function' => \&diff
|
---|
| 147 | },
|
---|
| 148 | 'status' => {
|
---|
[914] | 149 | 'desc' => [
|
---|
| 150 | 'display status information about modified and deleted files.',
|
---|
| 151 | 'If no path is given "/" is assumed',
|
---|
| 152 | '(in contract to "svn" with assumes ".")'
|
---|
| 153 | ],
|
---|
[891] | 154 | 'params' => ["PATH_REPO"],
|
---|
[884] | 155 | 'function' => \&status
|
---|
| 156 | },
|
---|
| 157 | 'check' => {
|
---|
[889] | 158 | 'desc' => ["perform Nagios NRPE conform check"],
|
---|
| 159 | 'params' => [],
|
---|
[884] | 160 | 'function' => \&check
|
---|
| 161 | },
|
---|
| 162 | 'permissions' => {
|
---|
[914] | 163 | 'desc' =>
|
---|
[918] | 164 | ["internal, print permissions for all files in the repository"],
|
---|
[889] | 165 | 'params' => [],
|
---|
[884] | 166 | 'function' => \&permissions
|
---|
| 167 | },
|
---|
| 168 | 'cleanup' => {
|
---|
[914] | 169 | 'desc' => ["internal, used to clean repository checkout"],
|
---|
[889] | 170 | 'params' => [],
|
---|
[884] | 171 | 'function' => \&cleanup
|
---|
| 172 | },
|
---|
| 173 | 'complete' => {
|
---|
[914] | 174 | 'desc' => ["internal, used for bash completion"],
|
---|
[889] | 175 | 'params' => ["CMD"],
|
---|
[884] | 176 | 'function' => \&complete
|
---|
| 177 | },
|
---|
[887] | 178 | 'complete_path' => {
|
---|
[914] | 179 | 'desc' => ["internal, used for bash completion"],
|
---|
[889] | 180 | 'params' => [],
|
---|
[887] | 181 | 'function' => \&complete_path
|
---|
| 182 | },
|
---|
| 183 | 'complete_repopath' => {
|
---|
[914] | 184 | 'desc' => ["internal, used for bash completion"],
|
---|
[889] | 185 | 'params' => [],
|
---|
[887] | 186 | 'function' => \&complete_repopath
|
---|
| 187 | },
|
---|
[916] | 188 | 'plugins' => {
|
---|
| 189 | 'desc' => ["internal, perform plugins"],
|
---|
| 190 | 'params' => [],
|
---|
| 191 | 'function' => \&perform_plugins
|
---|
| 192 | },
|
---|
| 193 |
|
---|
[884] | 194 | );
|
---|
| 195 |
|
---|
[215] | 196 | # configuration file
|
---|
[205] | 197 | my $DASSCM_LOCAL_REPOSITORY_BASE;
|
---|
| 198 | my $DASSCM_REPOSITORY_NAME;
|
---|
[916] | 199 | my $DASSCM_PLUGIN_RESULTS_PATH;
|
---|
[205] | 200 | my $DASSCM_SVN_REPOSITORY;
|
---|
[247] | 201 | my $DASSCM_CHECKOUT_USERNAME;
|
---|
| 202 | my $DASSCM_CHECKOUT_PASSWORD;
|
---|
[922] | 203 | my $DASSCM_GID;
|
---|
[918] | 204 | my @DASSCM_ADDITIONAL_FILES;
|
---|
[205] | 205 |
|
---|
[238] | 206 | # current directory at program start
|
---|
| 207 | my $StartDirectory = cwd();
|
---|
| 208 |
|
---|
[268] | 209 | my $diff = "diff --exclude .svn ";
|
---|
[205] | 210 | my $SVN = "svn ";
|
---|
| 211 | my $svnOptions = "";
|
---|
| 212 | my $svnCheckoutCredentials = "";
|
---|
| 213 | my $svnPasswordCredentials = "";
|
---|
[275] | 214 |
|
---|
[268] | 215 | # flag. Set to true by svn_update
|
---|
| 216 | # This prevents, that svn_update is called multiple times
|
---|
| 217 | my $svnRepositoryIsUptodate = 0;
|
---|
[205] | 218 |
|
---|
[196] | 219 | # command line options get stored in options hash
|
---|
[205] | 220 | my %options = ();
|
---|
| 221 |
|
---|
[197] | 222 | # subcommand, that gets executed (add, commit, ...)
|
---|
[196] | 223 | my $command;
|
---|
[186] | 224 |
|
---|
[205] | 225 | my $verbose = 0;
|
---|
| 226 |
|
---|
[189] | 227 | #####################################################################
|
---|
| 228 | #
|
---|
[186] | 229 | # util functions
|
---|
[189] | 230 | #
|
---|
[187] | 231 | sub usage()
|
---|
| 232 | {
|
---|
[283] | 233 | print '$Id: dasscm 929 2010-09-23 12:45:44Z joergs $';
|
---|
| 234 | print "\n\n";
|
---|
[205] | 235 | print "usage: dasscm <subcommand> [options] [args]\n";
|
---|
| 236 | print "\n";
|
---|
| 237 | print "dasscm is intended to help versioning configuration files\n";
|
---|
| 238 | print "\n";
|
---|
| 239 | print "Available subcommands:\n";
|
---|
[889] | 240 | foreach my $i ( sort keys(%COMMAND_DEFINITIONS) ) {
|
---|
| 241 | print " ", $i, " ", join( " ", get_command_possible_params($i) ),
|
---|
| 242 | "\n";
|
---|
[884] | 243 | foreach my $line ( get_command_desc($i) ) {
|
---|
[889] | 244 | print " " x 20, $line, "\n";
|
---|
[884] | 245 | }
|
---|
| 246 | }
|
---|
[205] | 247 | print "\n";
|
---|
[800] | 248 | print "If dasscm is not yet configured, read $doc_file\n";
|
---|
[187] | 249 | }
|
---|
| 250 |
|
---|
[233] | 251 | sub warning(@)
|
---|
| 252 | {
|
---|
| 253 | print "Warning: " . join( "\n ", @_ ) . "\n";
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | sub error(@)
|
---|
| 257 | {
|
---|
| 258 | print "Error: " . join( "\n ", @_ ) . "\n";
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | sub fatalerror(@)
|
---|
| 262 | {
|
---|
[239] | 263 | error(@_);
|
---|
| 264 |
|
---|
[233] | 265 | #print "Exiting\n";
|
---|
[239] | 266 | exit 1;
|
---|
[233] | 267 | }
|
---|
| 268 |
|
---|
[238] | 269 | #
|
---|
| 270 | # reading config file and return key/value pairs as hash
|
---|
| 271 | #
|
---|
[234] | 272 | sub get_config
|
---|
| 273 | {
|
---|
[239] | 274 | my $file = $_[0];
|
---|
[234] | 275 |
|
---|
[239] | 276 | if ( !$file ) {
|
---|
[234] | 277 | fatalerror( "failed to open config file" . $file );
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | my $data = {};
|
---|
| 281 |
|
---|
| 282 | # try to open config file
|
---|
| 283 | if ( !open( FH, $file ) ) {
|
---|
| 284 | fatalerror( "failed to open config file" . $file );
|
---|
| 285 | } else {
|
---|
| 286 | while (<FH>) {
|
---|
| 287 | chomp;
|
---|
| 288 | if (/^#/) {
|
---|
| 289 | next;
|
---|
| 290 | }
|
---|
| 291 | if ( $_ =~ /=/g ) {
|
---|
[239] | 292 |
|
---|
[238] | 293 | # splitting in 2 fields at maximum
|
---|
[234] | 294 | my ( $option, $value ) = split( /=/, $_, 2 );
|
---|
| 295 | $option =~ s/^\s+//g;
|
---|
| 296 | $option =~ s/\s+$//g;
|
---|
| 297 | $option =~ s/\"+//g;
|
---|
| 298 | $value =~ s/^\s+//g;
|
---|
| 299 | $value =~ s/\s+$//g;
|
---|
| 300 | $value =~ s/\"+//g;
|
---|
| 301 |
|
---|
| 302 | if ( length($option) ) {
|
---|
| 303 | $data->{$option} = $value;
|
---|
| 304 | }
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
| 307 | }
|
---|
| 308 | close(FH);
|
---|
| 309 |
|
---|
| 310 | return $data;
|
---|
| 311 | }
|
---|
| 312 |
|
---|
[270] | 313 | #
|
---|
| 314 | # check and evaluate environment variables
|
---|
| 315 | #
|
---|
[186] | 316 | sub check_env()
|
---|
| 317 | {
|
---|
[205] | 318 |
|
---|
| 319 | # DASSCM_PROD
|
---|
| 320 | if ( !$DASSCM_PROD ) {
|
---|
| 321 | $DASSCM_PROD = "/";
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | if ( !-d $DASSCM_PROD ) {
|
---|
| 325 | die "DASSCM_PROD ($DASSCM_PROD) is not set to a directory.\n";
|
---|
| 326 | }
|
---|
| 327 | if ($verbose) { print "DASSCM_PROD: " . $DASSCM_PROD . "\n"; }
|
---|
| 328 |
|
---|
| 329 | # DASSCM_REPOSITORY_NAME
|
---|
[208] | 330 | if ( !$DASSCM_REPOSITORY_NAME ) {
|
---|
| 331 | die
|
---|
| 332 | "Variable DASSCM_REPOSITORY_NAME is not defined.\nIt needs to be a unique name.\nNormally the full qualified host name is used.\nUse file $config_file to configure it.\n";
|
---|
| 333 | }
|
---|
[205] | 334 |
|
---|
| 335 | # DASSCM_REPO
|
---|
| 336 | if ( !$DASSCM_REPO ) {
|
---|
| 337 | if ( $DASSCM_LOCAL_REPOSITORY_BASE && $DASSCM_REPOSITORY_NAME ) {
|
---|
| 338 | $DASSCM_REPO =
|
---|
| 339 | $DASSCM_LOCAL_REPOSITORY_BASE . "/" . $DASSCM_REPOSITORY_NAME;
|
---|
| 340 | } else {
|
---|
| 341 | die
|
---|
| 342 | "Envirnonment variable DASSCM_REPO not set.\nSet DASSCM_REPO to the directory of the versioning system checkout for this machine.\n";
|
---|
| 343 | }
|
---|
| 344 | }
|
---|
[887] | 345 | $DASSCM_REPO = normalize_path($DASSCM_REPO);
|
---|
[215] | 346 | if ($verbose) { print "DASSCM_REPO: " . $DASSCM_REPO . "\n"; }
|
---|
[205] | 347 |
|
---|
| 348 | #
|
---|
[248] | 349 | # subversion checkout user
|
---|
| 350 | #
|
---|
[252] | 351 | if ( !$DASSCM_CHECKOUT_USERNAME ) {
|
---|
| 352 | fatalerror(
|
---|
[248] | 353 | "variable DASSCM_CHECKOUT_USERNAME is not defined.",
|
---|
[252] | 354 | "Use file $config_file to configure it."
|
---|
| 355 | );
|
---|
[248] | 356 | }
|
---|
| 357 |
|
---|
[252] | 358 | if ( !$DASSCM_CHECKOUT_PASSWORD ) {
|
---|
| 359 | fatalerror(
|
---|
[248] | 360 | "variable DASSCM_CHECKOUT_PASSWORD is not defined.",
|
---|
[252] | 361 | "Use file $config_file to configure it."
|
---|
| 362 | );
|
---|
[248] | 363 | }
|
---|
| 364 |
|
---|
| 365 | #
|
---|
[239] | 366 | # check if local repository directory exist
|
---|
[235] | 367 | # (if not creating by init)
|
---|
[205] | 368 | #
|
---|
| 369 | if ( $command ne "init" ) {
|
---|
| 370 | if ( not -d $DASSCM_REPO ) {
|
---|
[916] | 371 | fatalerror(
|
---|
[918] | 372 | "Can't access local repository DASSCM_REPO",
|
---|
| 373 | "($DASSCM_REPO)",
|
---|
| 374 | "Check configuration and execute",
|
---|
| 375 | "dasscm init"
|
---|
[916] | 376 | );
|
---|
[205] | 377 | }
|
---|
[208] | 378 |
|
---|
[205] | 379 | #
|
---|
| 380 | # user settings
|
---|
| 381 | #
|
---|
[208] | 382 |
|
---|
[205] | 383 | # DASSCM_USER is legacy. Use DASSCM_USERNAME instead
|
---|
[208] | 384 | if ( !$DASSCM_USERNAME ) {
|
---|
| 385 | $DASSCM_USERNAME = $DASSCM_USER;
|
---|
[205] | 386 | }
|
---|
| 387 |
|
---|
| 388 | # user root is not allowed for checkins.
|
---|
| 389 | # if user is root, DASSCM_USER has to be set,
|
---|
| 390 | # otherwise USER can be used
|
---|
| 391 | if ( "$USER" eq "root" ) {
|
---|
[252] | 392 | if ( ( not $DASSCM_USERNAME )
|
---|
[889] | 393 | and ( get_command_requires_write($command) ) )
|
---|
[252] | 394 | {
|
---|
| 395 |
|
---|
| 396 | #( $command ne "login" ) and ( $command ne "status" ) ) {
|
---|
| 397 | fatalerror(
|
---|
| 398 | "Envirnonment variable DASSCM_USERNAME not set.",
|
---|
| 399 | "Set DASSCM_USERNAME to your subversion user account or",
|
---|
| 400 | "use 'dasscm login'"
|
---|
| 401 | );
|
---|
[205] | 402 | }
|
---|
| 403 | $svnOptions .= " --no-auth-cache ";
|
---|
| 404 | } elsif ( !$DASSCM_USERNAME ) {
|
---|
| 405 | $DASSCM_USERNAME = $USER;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | #
|
---|
| 409 | # password
|
---|
| 410 | #
|
---|
[208] | 411 | if ($DASSCM_PASSWORD) {
|
---|
[267] | 412 | $svnPasswordCredentials = " --password '$DASSCM_PASSWORD' ";
|
---|
[205] | 413 | }
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | #$svnOptions .= " --username $DASSCM_USERNAME "
|
---|
[922] | 417 |
|
---|
| 418 | #
|
---|
| 419 | # prepare file permissions
|
---|
| 420 | # (read-write access for group "dasscm",
|
---|
| 421 | # if this group exists)
|
---|
| 422 | #
|
---|
| 423 | (my $gname, my $gpw, $DASSCM_GID, my $members) = getgrnam( "dasscm" );
|
---|
| 424 | if( $DASSCM_GID ) {
|
---|
| 425 | umask 0007
|
---|
| 426 | }
|
---|
[186] | 427 | }
|
---|
| 428 |
|
---|
[270] | 429 | #
|
---|
| 430 | # has been intendend,
|
---|
| 431 | # to check addtitional parameters.
|
---|
| 432 | # Currently not used.
|
---|
| 433 | #
|
---|
[186] | 434 | sub check_parameter(@)
|
---|
| 435 | {
|
---|
| 436 | }
|
---|
| 437 |
|
---|
[884] | 438 | sub get_command_uniform_name( $ )
|
---|
| 439 | {
|
---|
| 440 | my $command_abbrivation = $_[0];
|
---|
[889] | 441 | if ( defined( $COMMANDS{$command_abbrivation} ) ) {
|
---|
[884] | 442 | return $COMMANDS{$command_abbrivation};
|
---|
| 443 | }
|
---|
| 444 | return;
|
---|
| 445 | }
|
---|
| 446 |
|
---|
| 447 | sub get_command_desc( $ )
|
---|
| 448 | {
|
---|
[889] | 449 | my $command = get_command_uniform_name( $_[0] );
|
---|
| 450 | my @desc = ();
|
---|
| 451 | if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'desc'} ) ) {
|
---|
| 452 | @desc = @{ $COMMAND_DEFINITIONS{$command}{'desc'} };
|
---|
[884] | 453 | }
|
---|
| 454 | return @desc;
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | sub get_command_function( $ )
|
---|
| 458 | {
|
---|
[889] | 459 | my $command = get_command_uniform_name( $_[0] );
|
---|
[884] | 460 | my $func;
|
---|
[889] | 461 | if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'function'} ) ) {
|
---|
[884] | 462 | $func = $COMMAND_DEFINITIONS{$command}{'function'};
|
---|
| 463 | }
|
---|
| 464 | return $func;
|
---|
| 465 | }
|
---|
| 466 |
|
---|
| 467 | sub get_command_possible_params( $ )
|
---|
| 468 | {
|
---|
[889] | 469 | my $command = get_command_uniform_name( $_[0] );
|
---|
| 470 | my @params = ();
|
---|
| 471 | if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'params'} ) ) {
|
---|
| 472 | @params = @{ $COMMAND_DEFINITIONS{$command}{'params'} };
|
---|
[884] | 473 | }
|
---|
| 474 | return @params;
|
---|
| 475 | }
|
---|
| 476 |
|
---|
[893] | 477 | sub get_command_possible_options( $ )
|
---|
| 478 | {
|
---|
| 479 | my $command = get_command_uniform_name( $_[0] );
|
---|
| 480 | my @params = ();
|
---|
| 481 | if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'options'} ) ) {
|
---|
| 482 | @params = @{ $COMMAND_DEFINITIONS{$command}{'options'} };
|
---|
| 483 | }
|
---|
| 484 | return @params;
|
---|
| 485 | }
|
---|
| 486 |
|
---|
[884] | 487 | sub get_command_requirements( $ )
|
---|
| 488 | {
|
---|
[889] | 489 | my $command = get_command_uniform_name( $_[0] );
|
---|
[884] | 490 | my @requirements = ();
|
---|
[889] | 491 | if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'require'} ) ) {
|
---|
| 492 | @requirements = @{ $COMMAND_DEFINITIONS{$command}{'require'} };
|
---|
[884] | 493 | }
|
---|
| 494 | return @requirements;
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | sub get_command_requires_write( $ )
|
---|
| 498 | {
|
---|
[889] | 499 | return grep( /^WRITE$/, get_command_requirements( $_[0] ) );
|
---|
[884] | 500 | }
|
---|
| 501 |
|
---|
[238] | 502 | #
|
---|
[287] | 503 | # normalize path namens:
|
---|
| 504 | # - directories should end with "/"
|
---|
| 505 | # - use only single "/"
|
---|
| 506 | #
|
---|
| 507 | sub normalize_path($)
|
---|
| 508 | {
|
---|
| 509 | my $path = shift || "";
|
---|
| 510 |
|
---|
[290] | 511 | if ( $path =~ m|^/| ) {
|
---|
| 512 |
|
---|
[287] | 513 | # full path
|
---|
[290] | 514 | if ( -d $path ) {
|
---|
| 515 |
|
---|
[287] | 516 | # ensure, a directory ends with '/'
|
---|
| 517 | $path .= '/';
|
---|
| 518 | }
|
---|
[290] | 519 | } elsif ( -d cwd() . '/' . $path ) {
|
---|
| 520 |
|
---|
| 521 | # ensure, a directory ends with '/'
|
---|
| 522 | $path .= '/';
|
---|
[287] | 523 | }
|
---|
| 524 |
|
---|
| 525 | # remove double (triple) slashes (/)
|
---|
| 526 | $path =~ s|/[/]*|/|g;
|
---|
| 527 |
|
---|
[887] | 528 | # remove self reference path
|
---|
| 529 | $path =~ s|/./|/|g;
|
---|
| 530 |
|
---|
[287] | 531 | return $path;
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | #
|
---|
[239] | 535 | # generate from (relative) filename
|
---|
[238] | 536 | # all required file and directory names:
|
---|
| 537 | # $basename, $dirname_prod, $dirname_repo,
|
---|
| 538 | # $filename_prod, $filename_repo
|
---|
| 539 | #
|
---|
[187] | 540 | sub get_filenames(@)
|
---|
| 541 | {
|
---|
[250] | 542 | my $filename_prod = $_[0] || ".";
|
---|
[237] | 543 |
|
---|
[238] | 544 | # make filename absolut
|
---|
[205] | 545 | if ( !( $filename_prod =~ m/^\// ) ) {
|
---|
[270] | 546 | $filename_prod = cwd() . '/' . $filename_prod;
|
---|
[205] | 547 | }
|
---|
[187] | 548 |
|
---|
[889] | 549 | # file must be readable.
|
---|
| 550 | # The only exceptions are,
|
---|
[887] | 551 | # - if the file parameter is to be completed or
|
---|
| 552 | # - if a file should be reverted
|
---|
| 553 | if ( $command ne "revert" && $command !~ m/^complete/ ) {
|
---|
[800] | 554 | if ( not -r $filename_prod ) {
|
---|
| 555 | fatalerror( $filename_prod . " is not accessable" );
|
---|
| 556 | }
|
---|
[233] | 557 | }
|
---|
[205] | 558 |
|
---|
[274] | 559 | # dirname buggy: eg. "/etc/" is reduced to "/",
|
---|
| 560 | # "/etc" is used as filename
|
---|
| 561 | # herefore make sure, that if filename is a directory,
|
---|
| 562 | # it will end by "/"
|
---|
[290] | 563 | $filename_prod = normalize_path($filename_prod);
|
---|
[238] | 564 |
|
---|
[270] | 565 | ( my $basename, my $dirname_prod ) = fileparse($filename_prod);
|
---|
| 566 |
|
---|
[801] | 567 | # normalize path.
|
---|
[800] | 568 | # not done for reverting, because in this case, the directory may not exist
|
---|
| 569 | # and the correct path should already be stored in the repository
|
---|
| 570 | if ( $command ne "revert" ) {
|
---|
[801] | 571 |
|
---|
[800] | 572 | # uses chdir to determine real directory in a unique way
|
---|
[801] | 573 | chdir $dirname_prod
|
---|
| 574 | or fatalerror( "failed to access directory $dirname_prod: " . $! );
|
---|
[800] | 575 | $dirname_prod = normalize_path( cwd() );
|
---|
| 576 | chdir $StartDirectory;
|
---|
| 577 | }
|
---|
[238] | 578 |
|
---|
[287] | 579 | my $dirname_repo = normalize_path( $DASSCM_REPO . "/" . $dirname_prod );
|
---|
[290] | 580 | my $filename_repo = normalize_path("$dirname_repo/$basename");
|
---|
[287] | 581 |
|
---|
[214] | 582 | if ($verbose) {
|
---|
[287] | 583 | print "filename_repo: " . $filename_repo . "\n";
|
---|
[290] | 584 | print "dirname_repo: " . $dirname_repo . "\n";
|
---|
[287] | 585 | print "filename_prod: " . $filename_prod . "\n";
|
---|
[290] | 586 | print "dirname_prod: " . $dirname_prod . "\n";
|
---|
[287] | 587 | print "basename: " . $basename . "\n";
|
---|
[214] | 588 | }
|
---|
[205] | 589 |
|
---|
| 590 | return (
|
---|
| 591 | $basename, $dirname_prod, $dirname_repo,
|
---|
| 592 | $filename_prod, $filename_repo
|
---|
| 593 | );
|
---|
[187] | 594 | }
|
---|
| 595 |
|
---|
[271] | 596 | sub copy_file_to_repository( $ )
|
---|
| 597 | {
|
---|
| 598 | my $filename = shift;
|
---|
[256] | 599 |
|
---|
[271] | 600 | (
|
---|
| 601 | my $basename,
|
---|
| 602 | my $dirname_prod,
|
---|
| 603 | my $dirname_repo,
|
---|
| 604 | my $filename_prod,
|
---|
| 605 | my $filename_repo
|
---|
[801] | 606 | ) = get_filenames($filename);
|
---|
[271] | 607 |
|
---|
[802] | 608 | #copy( $filename_prod, $filename_repo )
|
---|
[889] | 609 | ( my $rc, my @result ) =
|
---|
| 610 | run_command("cp -a \"$filename_prod\" \"$filename_repo\"");
|
---|
| 611 | if ( $rc != 0 ) {
|
---|
[802] | 612 | error( "failed to copy $filename_prod to repository: ", @result );
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | # return success
|
---|
| 616 | return $rc == 0;
|
---|
[271] | 617 | }
|
---|
| 618 |
|
---|
[802] | 619 | sub copy_file_from_repository_to_system( $ )
|
---|
| 620 | {
|
---|
| 621 | my $filename = shift;
|
---|
| 622 |
|
---|
| 623 | (
|
---|
| 624 | my $basename,
|
---|
| 625 | my $dirname_prod,
|
---|
| 626 | my $dirname_repo,
|
---|
| 627 | my $filename_prod,
|
---|
| 628 | my $filename_repo
|
---|
| 629 | ) = get_filenames($filename);
|
---|
| 630 |
|
---|
[889] | 631 | ( my $rc, my @result ) =
|
---|
| 632 | run_command("cp -a \"$filename_repo\" \"$filename_prod\"");
|
---|
| 633 | if ( $rc != 0 ) {
|
---|
[802] | 634 | error( "failed to copy $filename_repo to $filename_prod: ", @result );
|
---|
| 635 | }
|
---|
| 636 |
|
---|
| 637 | # return success
|
---|
| 638 | return $rc == 0;
|
---|
| 639 | }
|
---|
| 640 |
|
---|
[256] | 641 | #
|
---|
| 642 | # creates a file with permissions
|
---|
| 643 | #
|
---|
[215] | 644 | sub generatePermissionList
|
---|
[209] | 645 | {
|
---|
| 646 |
|
---|
[215] | 647 | # generieren der Zeilen für Permission-Savefile
|
---|
| 648 | my @files = @_;
|
---|
| 649 | my @permlist = ();
|
---|
| 650 | foreach my $file (@files) {
|
---|
[227] | 651 | $file = "/" . $file;
|
---|
[239] | 652 | if ( -e $file ) {
|
---|
| 653 | my $info = stat($file) || die "failed to stat $file: aborting";
|
---|
| 654 | my $mode = get_type( $info->mode ) & 07777;
|
---|
[227] | 655 | my $modestring = sprintf( "%04o", $mode );
|
---|
[278] | 656 | my $uidnumber = $info->uid;
|
---|
| 657 | my $uid = getpwuid($uidnumber) || $uidnumber;
|
---|
| 658 | my $gidnumber = $info->gid;
|
---|
| 659 | my $gid = getgrgid($gidnumber) || $gidnumber;
|
---|
[227] | 660 | push(
|
---|
| 661 | @permlist,
|
---|
| 662 | sprintf( "%-55s %-17s %4d",
|
---|
[278] | 663 | $file, "${uid}:${gid}", $modestring )
|
---|
[227] | 664 | );
|
---|
| 665 | }
|
---|
[215] | 666 | }
|
---|
| 667 | return @permlist;
|
---|
| 668 | }
|
---|
[209] | 669 |
|
---|
[215] | 670 | sub get_type
|
---|
| 671 | {
|
---|
[209] | 672 |
|
---|
[215] | 673 | # Funktion übernommen aus /usr/bin/chkstat
|
---|
| 674 | my $S_IFLNK = 0120000; # symbolic link
|
---|
| 675 | my $S_IFREG = 0100000; # regular file
|
---|
| 676 | my $S_IFDIR = 0040000; # directory
|
---|
| 677 | my $S_IFCHAR = 0020000; # character device
|
---|
| 678 | my $S_IFBLK = 0060000; # block device
|
---|
| 679 | my $S_IFFIFO = 0010000; # fifo
|
---|
| 680 | my $S_IFSOCK = 0140000; # socket
|
---|
| 681 | my $S_IFMT = 0170000; # type of file
|
---|
[209] | 682 |
|
---|
[215] | 683 | my $S_m;
|
---|
| 684 | if ( ( $_[0] & $S_IFMT ) == $S_IFLNK ) { $S_m = $_[0] - $S_IFLNK; }
|
---|
| 685 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFREG ) { $S_m = $_[0] - $S_IFREG; }
|
---|
| 686 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFDIR ) { $S_m = $_[0] - $S_IFDIR; }
|
---|
| 687 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFCHAR ) { $S_m = $_[0] - $S_IFCHAR; }
|
---|
| 688 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFBLK ) { $S_m = $_[0] - $S_IFBLK; }
|
---|
| 689 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFFIFO ) { $S_m = $_[0] - $S_IFFIFO; }
|
---|
| 690 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFSOCK ) { $S_m = $_[0] - $S_IFSOCK; }
|
---|
| 691 | $S_m;
|
---|
[209] | 692 | }
|
---|
| 693 |
|
---|
[186] | 694 | sub run_command
|
---|
| 695 | {
|
---|
[205] | 696 | my $command = shift;
|
---|
[186] | 697 |
|
---|
[926] | 698 | if ($verbose) {
|
---|
| 699 | print "executing command: " . $command . "\n";
|
---|
| 700 | }
|
---|
[186] | 701 |
|
---|
[926] | 702 | my @result;
|
---|
| 703 | if( open( RESULT, $command . ' 2>&1 |' ) ) {
|
---|
| 704 | @result = <RESULT>;
|
---|
| 705 | close(RESULT);
|
---|
| 706 | }
|
---|
[205] | 707 | my $retcode = $? >> 8;
|
---|
[186] | 708 |
|
---|
[926] | 709 | if ($verbose) {
|
---|
| 710 | print @result;
|
---|
| 711 | if( $retcode ) { print "return code: " . $retcode . "\n"; }
|
---|
| 712 | }
|
---|
[186] | 713 |
|
---|
[205] | 714 | return ( $retcode, @result );
|
---|
[186] | 715 | }
|
---|
| 716 |
|
---|
[205] | 717 | sub run_interactive
|
---|
| 718 | {
|
---|
[186] | 719 |
|
---|
[208] | 720 | if ($verbose) {
|
---|
[205] | 721 | print "run_interactive:" . join( " ", @_ ) . "\n";
|
---|
| 722 | }
|
---|
[196] | 723 |
|
---|
[205] | 724 | system(@_);
|
---|
| 725 | if ( $? == -1 ) {
|
---|
| 726 | printf "failed to execute: $!\n";
|
---|
| 727 | } elsif ( $? & 127 ) {
|
---|
| 728 | printf "child died with signal %d, %s coredump\n", ( $? & 127 ),
|
---|
| 729 | ( $? & 128 ) ? 'with' : 'without';
|
---|
| 730 | } elsif ( $? >> 8 != 0 ) {
|
---|
| 731 | printf "child exited with value %d\n", $? >> 8;
|
---|
| 732 | }
|
---|
| 733 | return ( $? >> 8 );
|
---|
| 734 | }
|
---|
| 735 |
|
---|
[916] | 736 | #
|
---|
| 737 | # en- or disable echo mode.
|
---|
| 738 | # used for reading passwords from STDIN
|
---|
| 739 | #
|
---|
| 740 | sub setEchoMode( $ )
|
---|
| 741 | {
|
---|
| 742 | my $mode = shift;
|
---|
[918] | 743 | if ($mode) {
|
---|
| 744 | run_command("stty echo");
|
---|
[916] | 745 | } else {
|
---|
[918] | 746 | run_command("stty -echo");
|
---|
[916] | 747 | }
|
---|
| 748 | }
|
---|
| 749 |
|
---|
| 750 | sub write_array_to_file( $@ )
|
---|
| 751 | {
|
---|
| 752 | my $filename = shift;
|
---|
[918] | 753 | my @array = @_;
|
---|
[916] | 754 |
|
---|
[922] | 755 | if ( -e $filename && !-w $filename ) {
|
---|
| 756 | warning( "failed to write to $filename:", "permission denied" );
|
---|
| 757 | return;
|
---|
| 758 | }
|
---|
| 759 |
|
---|
[918] | 760 | if ( !-w dirname($filename) ) {
|
---|
[922] | 761 | warning( "failed to write to $filename:", "directory does not exist" );
|
---|
[916] | 762 | return;
|
---|
| 763 | }
|
---|
| 764 |
|
---|
| 765 | # directory exists => write
|
---|
[918] | 766 | if ( !open( OUTFILE, ">$filename" ) ) {
|
---|
| 767 | warning("failed to open $filename: $!");
|
---|
[916] | 768 | return;
|
---|
| 769 | }
|
---|
| 770 |
|
---|
| 771 | foreach my $line (@array) {
|
---|
| 772 | print OUTFILE "$line";
|
---|
| 773 | }
|
---|
| 774 | close(OUTFILE);
|
---|
| 775 |
|
---|
[922] | 776 | # if group dasscm exists,
|
---|
| 777 | # create plugin results with group membership dasscm
|
---|
| 778 | if( $DASSCM_GID ) {
|
---|
| 779 | chown( -1, $DASSCM_GID, $filename );
|
---|
| 780 | }
|
---|
| 781 |
|
---|
[916] | 782 | return 1;
|
---|
| 783 | }
|
---|
| 784 |
|
---|
| 785 | sub perform_plugins()
|
---|
| 786 | {
|
---|
| 787 | check_env();
|
---|
| 788 |
|
---|
| 789 | my @plugin_results = ();
|
---|
| 790 |
|
---|
| 791 | # get all defined plugins.
|
---|
| 792 | # Plugin definitions starting with DASSCM_PLUGIN_
|
---|
[918] | 793 | my @plugins = grep( /^DASSCM_PLUGIN_CMD_/, keys( %{$config} ) );
|
---|
[916] | 794 |
|
---|
| 795 | for my $plugin (@plugins) {
|
---|
[918] | 796 | my $plugin_name = substr( $plugin, length("DASSCM_PLUGIN_CMD_") );
|
---|
| 797 | my $plugin_test = $config->{ 'DASSCM_PLUGIN_TEST_' . $plugin_name };
|
---|
[916] | 798 | if ($verbose) { print "Plugin $plugin_name: "; }
|
---|
[926] | 799 | # all plugins are executed with LANG settings C
|
---|
| 800 | # bash -c is used, to supress all output
|
---|
| 801 | # (otherwise there are problem with && commands)
|
---|
| 802 | ( my $rc_test, my @result_test ) = run_command( "LANG=C bash -c " . $plugin_test);
|
---|
[918] | 803 | if ( $rc_test != 0 ) {
|
---|
[916] | 804 | if ($verbose) { print "skipped\n"; }
|
---|
| 805 | } else {
|
---|
| 806 | if ($verbose) { print "$config->{$plugin}\n"; }
|
---|
| 807 | ( my $rc, my @result ) = run_command( $config->{$plugin} );
|
---|
[918] | 808 | if ( $rc != 0 ) {
|
---|
| 809 | warning("failed to run plugin $plugin");
|
---|
[916] | 810 | } else {
|
---|
[918] | 811 | my $plugin_result_file =
|
---|
| 812 | $DASSCM_PLUGIN_RESULTS_PATH . "/" . $plugin_name;
|
---|
[916] | 813 | write_array_to_file( $plugin_result_file, @result );
|
---|
| 814 | push @plugin_results, $plugin_result_file;
|
---|
| 815 | }
|
---|
| 816 | }
|
---|
| 817 | }
|
---|
| 818 | return @plugin_results;
|
---|
| 819 | }
|
---|
| 820 |
|
---|
[247] | 821 | sub svn_check_credentials( $$;$$ )
|
---|
[196] | 822 | {
|
---|
[205] | 823 | my $username = shift;
|
---|
| 824 | my $password = shift;
|
---|
| 825 |
|
---|
[252] | 826 | # check silently are allow user interaction?
|
---|
[247] | 827 | my $interactive = shift || 0;
|
---|
[220] | 828 |
|
---|
[247] | 829 | # default: exit program, if repository is not accessable
|
---|
| 830 | # (do not exit for 'init')
|
---|
| 831 | my $fatalerror = shift || 1;
|
---|
| 832 |
|
---|
| 833 | print "checking credentials ";
|
---|
| 834 |
|
---|
[239] | 835 | if ( !$username ) {
|
---|
| 836 | fatalerror("no username given");
|
---|
[238] | 837 | }
|
---|
| 838 |
|
---|
[239] | 839 | if ( !$password ) {
|
---|
| 840 | fatalerror("no password given");
|
---|
[238] | 841 | }
|
---|
| 842 |
|
---|
[247] | 843 | print "for " . $username . "@" . $DASSCM_SVN_REPOSITORY . ": ";
|
---|
| 844 |
|
---|
[220] | 845 | # Options for "svn info" are not supported by subversion 1.0.0 (SLES9),
|
---|
| 846 | # therefore switching to "svn status"
|
---|
| 847 | # ( my $rc_update, my @result ) =
|
---|
| 848 | # run_command(
|
---|
| 849 | # "$SVN info --non-interactive --no-auth-cache --username $username --password $password $DASSCM_SVN_REPOSITORY"
|
---|
| 850 | # );
|
---|
| 851 | #print @result;
|
---|
| 852 |
|
---|
[247] | 853 | my $rc_update;
|
---|
[252] | 854 | if ($interactive) {
|
---|
[801] | 855 | $rc_update = run_interactive(
|
---|
[267] | 856 | "$SVN ls --no-auth-cache --username '$username' --password '$password' $DASSCM_SVN_REPOSITORY"
|
---|
[801] | 857 | );
|
---|
[247] | 858 | } else {
|
---|
[801] | 859 | ( $rc_update, my @result ) = run_command(
|
---|
[267] | 860 | "$SVN ls --non-interactive --no-auth-cache --username '$username' --password '$password' $DASSCM_SVN_REPOSITORY"
|
---|
[801] | 861 | );
|
---|
[252] | 862 |
|
---|
[247] | 863 | if ( $rc_update != 0 ) {
|
---|
| 864 | print "\n", @result;
|
---|
[252] | 865 | if ($fatalerror) {
|
---|
[247] | 866 | fatalerror();
|
---|
| 867 | }
|
---|
| 868 | return;
|
---|
| 869 | }
|
---|
[205] | 870 | }
|
---|
| 871 |
|
---|
[247] | 872 | # return success
|
---|
| 873 | return $rc_update == 0;
|
---|
[196] | 874 | }
|
---|
| 875 |
|
---|
[205] | 876 | sub svn_update( ;$ )
|
---|
| 877 | {
|
---|
[270] | 878 | my $update_path = shift || "";
|
---|
| 879 |
|
---|
[797] | 880 | # return value
|
---|
| 881 | my $update_ok = 1;
|
---|
| 882 |
|
---|
[270] | 883 | # use this flag to do only one update per run
|
---|
[275] | 884 | if ( !$svnRepositoryIsUptodate ) {
|
---|
[801] | 885 | ( my $rc_update, my @result ) = run_command(
|
---|
[275] | 886 | "$SVN update --non-interactive $svnCheckoutCredentials '$DASSCM_REPO/$update_path'"
|
---|
[801] | 887 | );
|
---|
[268] | 888 | print @result;
|
---|
| 889 | if ( $rc_update != 0 ) {
|
---|
[290] | 890 | error("failed to update local repository ($update_path)");
|
---|
[797] | 891 | $update_ok = 0;
|
---|
[270] | 892 | } elsif ( not $update_path ) {
|
---|
[275] | 893 |
|
---|
[270] | 894 | # set this flag if a full update is done
|
---|
[268] | 895 | $svnRepositoryIsUptodate = 1;
|
---|
| 896 | }
|
---|
[205] | 897 | }
|
---|
[797] | 898 | return $update_ok;
|
---|
[215] | 899 | }
|
---|
[196] | 900 |
|
---|
[271] | 901 | sub svn_ls( ;@ )
|
---|
[215] | 902 | {
|
---|
[270] | 903 | (
|
---|
| 904 | my $basename,
|
---|
| 905 | my $dirname_prod,
|
---|
| 906 | my $dirname_repo,
|
---|
| 907 | my $filename_prod,
|
---|
| 908 | my $filename_repo
|
---|
[801] | 909 | ) = get_filenames( $_[0] );
|
---|
[220] | 910 |
|
---|
[218] | 911 | # svn ls -R is better, but much, much slower
|
---|
| 912 | # ( my $rc, my @result ) = run_command("$SVN ls --recursive $svnCheckoutCredentials $path");
|
---|
[270] | 913 |
|
---|
[271] | 914 | my @files = ();
|
---|
| 915 | my @links = ();
|
---|
| 916 | my @dirs = ();
|
---|
| 917 | my @others = ();
|
---|
| 918 |
|
---|
[289] | 919 | find(
|
---|
| 920 | {
|
---|
| 921 | wanted => sub {
|
---|
| 922 | my $name = normalize_path($File::Find::name);
|
---|
| 923 | $name =~ s|^$dirname_repo||;
|
---|
[290] | 924 |
|
---|
[289] | 925 | #print "($name)\n";# . $File::Find::dir . "\n";
|
---|
| 926 | if ( not $name ) {
|
---|
[290] | 927 |
|
---|
[289] | 928 | # name string is empty (top directory).
|
---|
| 929 | # do nothing
|
---|
| 930 | } elsif ( $name =~ m/\.svn/ ) {
|
---|
[275] | 931 |
|
---|
[289] | 932 | # skip svn meta data
|
---|
| 933 | } elsif ( -l $_ ) {
|
---|
[275] | 934 |
|
---|
[289] | 935 | # soft link
|
---|
| 936 | # important: check for links first
|
---|
| 937 | # to exclude them from further checks
|
---|
| 938 | push( @links, $name );
|
---|
| 939 | } elsif ( -d $_ ) {
|
---|
[290] | 940 |
|
---|
| 941 | # directories
|
---|
| 942 | push( @dirs, $name );
|
---|
[289] | 943 | } elsif ( -f $_ ) {
|
---|
[275] | 944 |
|
---|
[289] | 945 | # regular file
|
---|
| 946 | push( @files, $name );
|
---|
| 947 | } else {
|
---|
| 948 | push( @others, $name );
|
---|
| 949 | }
|
---|
[290] | 950 | }
|
---|
[289] | 951 | },
|
---|
| 952 | ($filename_repo)
|
---|
| 953 | );
|
---|
[271] | 954 |
|
---|
[287] | 955 | return ( sort( @dirs, @files ) );
|
---|
[205] | 956 | }
|
---|
| 957 |
|
---|
[274] | 958 | sub svn_revert( ;$ )
|
---|
| 959 | {
|
---|
| 960 | my $path = shift || $DASSCM_REPO;
|
---|
| 961 |
|
---|
[275] | 962 | ( my $rc_update, my @result ) = run_command("$SVN revert -R '$path'");
|
---|
[274] | 963 |
|
---|
| 964 | if ( $rc_update != 0 ) {
|
---|
| 965 | print "\n", @result;
|
---|
[275] | 966 | error("failed to revert subversion repository changes");
|
---|
[274] | 967 | }
|
---|
| 968 | }
|
---|
| 969 |
|
---|
[285] | 970 | sub svn_remove_unknown_files( ;$ )
|
---|
| 971 | {
|
---|
| 972 | my $path = shift || $DASSCM_REPO;
|
---|
| 973 |
|
---|
[290] | 974 | ( my $rc_update, my @result ) = run_command("$SVN status '$path'");
|
---|
[285] | 975 |
|
---|
| 976 | if ( $rc_update != 0 ) {
|
---|
| 977 | print "\n", @result;
|
---|
| 978 | error("failed to receive subversion repository information");
|
---|
| 979 | } else {
|
---|
[290] | 980 | foreach (@result) {
|
---|
| 981 | if (s/^\? +//) {
|
---|
[285] | 982 | chomp;
|
---|
[290] | 983 |
|
---|
[285] | 984 | # if file is unknown to subversion (line starts with "?")
|
---|
| 985 | # remove it
|
---|
| 986 | print "removing $_\n";
|
---|
[801] | 987 |
|
---|
[800] | 988 | # unlink doesn't work recursive, there "rm -rf" is used
|
---|
| 989 | #unlink($_);
|
---|
[801] | 990 | system("rm -rf $_");
|
---|
[285] | 991 | }
|
---|
| 992 | }
|
---|
| 993 | }
|
---|
| 994 | }
|
---|
| 995 |
|
---|
[268] | 996 | sub getModifiedFiles( ;$ )
|
---|
| 997 | {
|
---|
[270] | 998 | (
|
---|
| 999 | my $basename,
|
---|
| 1000 | my $dirname_prod,
|
---|
| 1001 | my $dirname_repo,
|
---|
| 1002 | my $filename_prod,
|
---|
| 1003 | my $filename_repo
|
---|
[801] | 1004 | ) = get_filenames( $_[0] );
|
---|
[268] | 1005 |
|
---|
[275] | 1006 | my @files = svn_ls($filename_prod);
|
---|
[270] | 1007 |
|
---|
[268] | 1008 | # stores result from status (cvscheck)
|
---|
| 1009 | my %removedfiles = ();
|
---|
| 1010 | my %changedfiles = ();
|
---|
[278] | 1011 | my %unknownfiles = ();
|
---|
[268] | 1012 |
|
---|
| 1013 | # create list of modified files
|
---|
| 1014 | if (@files) {
|
---|
| 1015 |
|
---|
| 1016 | foreach my $file (@files) {
|
---|
| 1017 |
|
---|
[271] | 1018 | my $realfile = $dirname_prod . $file;
|
---|
| 1019 | my $cvsworkfile = $dirname_repo . $file;
|
---|
[268] | 1020 |
|
---|
| 1021 | if ( -d $realfile ) {
|
---|
[290] | 1022 |
|
---|
[278] | 1023 | # directory
|
---|
[290] | 1024 | if ( !-d "$cvsworkfile" ) {
|
---|
| 1025 |
|
---|
[278] | 1026 | # real is directory, repository is not. This is a problem
|
---|
| 1027 | $changedfiles{"$realfile"} = $cvsworkfile;
|
---|
| 1028 | }
|
---|
| 1029 | } elsif ( !-e $realfile ) {
|
---|
| 1030 | $removedfiles{"$realfile"} = $cvsworkfile;
|
---|
[268] | 1031 | } elsif ( !-r $realfile ) {
|
---|
[290] | 1032 |
|
---|
[278] | 1033 | # don't have permission to read the file,
|
---|
| 1034 | # can't check it
|
---|
| 1035 | $unknownfiles{"$realfile"} = $cvsworkfile;
|
---|
[268] | 1036 | } else {
|
---|
| 1037 | ( -r "$cvsworkfile" )
|
---|
[278] | 1038 | || fatalerror("failed to read $cvsworkfile");
|
---|
[268] | 1039 | if ( compare( $cvsworkfile, $realfile ) != 0 ) {
|
---|
| 1040 | $changedfiles{"$realfile"} = $cvsworkfile;
|
---|
| 1041 | }
|
---|
| 1042 | }
|
---|
| 1043 | }
|
---|
| 1044 | }
|
---|
| 1045 |
|
---|
[278] | 1046 | return ( \%changedfiles, \%removedfiles, \%unknownfiles );
|
---|
[268] | 1047 | }
|
---|
| 1048 |
|
---|
[238] | 1049 | #
|
---|
| 1050 | # from an array of files/dirs,
|
---|
| 1051 | # generates list of files
|
---|
| 1052 | # sorted by type
|
---|
| 1053 | #
|
---|
[237] | 1054 | sub get_files( @ )
|
---|
| 1055 | {
|
---|
| 1056 | my @files = ();
|
---|
| 1057 | my @links = ();
|
---|
| 1058 | my @dirs = ();
|
---|
| 1059 | my @others = ();
|
---|
| 1060 |
|
---|
[239] | 1061 | if (@_) {
|
---|
| 1062 | find(
|
---|
| 1063 | {
|
---|
| 1064 | wanted => sub {
|
---|
| 1065 | my $fullname = cwd() . "/" . $_;
|
---|
| 1066 | if ( -l $_ ) {
|
---|
| 1067 |
|
---|
| 1068 | # soft link
|
---|
| 1069 | # important: check for links first
|
---|
| 1070 | # to exclude them from further checks
|
---|
| 1071 | push( @links, $fullname );
|
---|
| 1072 | } elsif ( -d $_ ) {
|
---|
[271] | 1073 |
|
---|
| 1074 | # directories
|
---|
[239] | 1075 | push( @dirs, $fullname );
|
---|
| 1076 | } elsif ( -f $_ ) {
|
---|
| 1077 |
|
---|
| 1078 | # regular file
|
---|
| 1079 | push( @files, $fullname );
|
---|
| 1080 | } else {
|
---|
| 1081 | push( @others, $fullname );
|
---|
| 1082 | }
|
---|
| 1083 | }
|
---|
| 1084 | },
|
---|
| 1085 | @_
|
---|
| 1086 | );
|
---|
[237] | 1087 | }
|
---|
| 1088 |
|
---|
[239] | 1089 | # don't rely on others.
|
---|
[237] | 1090 | # If more specific file types are needed,
|
---|
| 1091 | # they will be added
|
---|
| 1092 | return {
|
---|
[239] | 1093 | files => \@files,
|
---|
| 1094 | links => \@links,
|
---|
| 1095 | dirs => \@dirs,
|
---|
| 1096 | others => \@others
|
---|
| 1097 | };
|
---|
[237] | 1098 | }
|
---|
| 1099 |
|
---|
[918] | 1100 | sub print_files_hash( $ )
|
---|
| 1101 | {
|
---|
| 1102 | my $href_files = shift;
|
---|
| 1103 |
|
---|
| 1104 | my @files = @{ $href_files->{files} };
|
---|
| 1105 | my @links = @{ $href_files->{links} };
|
---|
| 1106 |
|
---|
| 1107 | if (@files) {
|
---|
| 1108 | my $number = $#files + 1;
|
---|
| 1109 | print "files to check-in ($number): \n";
|
---|
| 1110 | print join( "\n", @files );
|
---|
| 1111 | print "\n";
|
---|
| 1112 | }
|
---|
| 1113 |
|
---|
| 1114 | # TODO: check in links and also link target? At least warn about link target
|
---|
| 1115 | if (@links) {
|
---|
| 1116 | my $number = $#links + 1;
|
---|
| 1117 | print "\n";
|
---|
| 1118 | print "ignoring links ($number):\n";
|
---|
| 1119 | print join( "\n", @links );
|
---|
| 1120 | print "\n";
|
---|
| 1121 | }
|
---|
| 1122 |
|
---|
| 1123 | }
|
---|
| 1124 |
|
---|
[888] | 1125 | #
|
---|
| 1126 | # use globbing to get lsit of files
|
---|
| 1127 | # that matches the given prefix
|
---|
| 1128 | # used for bash completion
|
---|
| 1129 | #
|
---|
| 1130 | sub get_complete_path_globbing( $ )
|
---|
| 1131 | {
|
---|
| 1132 | my $path = shift;
|
---|
| 1133 |
|
---|
| 1134 | # add globbing
|
---|
| 1135 | $path .= "*";
|
---|
| 1136 |
|
---|
| 1137 | # get files
|
---|
[889] | 1138 | my @files = glob($path);
|
---|
[888] | 1139 |
|
---|
[889] | 1140 | if ( $#files == 0 ) {
|
---|
[891] | 1141 |
|
---|
| 1142 | # if only one result is available
|
---|
| 1143 | # and this result is a directory,
|
---|
| 1144 | # add another result entry
|
---|
| 1145 | # (directory with and withour trainling /),
|
---|
| 1146 | # otherwise complete will stop here and continue with the next parameter
|
---|
| 1147 | my $path = normalize_path( $files[0] );
|
---|
[889] | 1148 | if ( -d $path ) {
|
---|
[891] | 1149 | @files = ( substr( $path, 0, -1 ), $path );
|
---|
[888] | 1150 | }
|
---|
[890] | 1151 | } else {
|
---|
[891] | 1152 |
|
---|
[890] | 1153 | # add "/" to all directories
|
---|
[891] | 1154 | @files = map( { normalize_path($_) } @files );
|
---|
[888] | 1155 | }
|
---|
| 1156 |
|
---|
| 1157 | return @files;
|
---|
| 1158 | }
|
---|
| 1159 |
|
---|
[189] | 1160 | #####################################################################
|
---|
| 1161 | #
|
---|
[186] | 1162 | # functions
|
---|
| 1163 | sub help(;@)
|
---|
| 1164 | {
|
---|
[893] | 1165 | if ( not @_ ) {
|
---|
[205] | 1166 | usage();
|
---|
| 1167 | } else {
|
---|
[893] | 1168 | print "help for ", join( " ", @_ ), ": ...\n";
|
---|
[214] | 1169 | usage();
|
---|
[205] | 1170 | }
|
---|
[929] | 1171 |
|
---|
| 1172 | return $RETURN_OK;
|
---|
[186] | 1173 | }
|
---|
| 1174 |
|
---|
[203] | 1175 | sub login(@)
|
---|
| 1176 | {
|
---|
[205] | 1177 | check_parameter( @_, 1 );
|
---|
| 1178 | check_env();
|
---|
[203] | 1179 |
|
---|
[235] | 1180 | my $input_username = $_[0];
|
---|
[214] | 1181 |
|
---|
| 1182 | if ( not $input_username ) {
|
---|
| 1183 | my $output_username = "";
|
---|
| 1184 | if ($DASSCM_USERNAME) {
|
---|
| 1185 | $output_username = " ($DASSCM_USERNAME)";
|
---|
| 1186 | }
|
---|
| 1187 |
|
---|
| 1188 | print "Enter DASSCM user name", $output_username, ": ";
|
---|
| 1189 | $input_username = <STDIN>;
|
---|
| 1190 | chomp($input_username);
|
---|
[247] | 1191 |
|
---|
| 1192 | $input_username = $input_username || $DASSCM_USERNAME;
|
---|
[205] | 1193 | }
|
---|
[203] | 1194 |
|
---|
[205] | 1195 | # hidden password input
|
---|
[916] | 1196 | print "Enter password for $input_username: ";
|
---|
[918] | 1197 | setEchoMode(0);
|
---|
[205] | 1198 | my $input_password = <STDIN>;
|
---|
[918] | 1199 | setEchoMode(1);
|
---|
[205] | 1200 | chomp($input_password);
|
---|
[220] | 1201 | print "\n";
|
---|
[203] | 1202 |
|
---|
[247] | 1203 | # checking checkout username/password
|
---|
[252] | 1204 | svn_check_credentials( $DASSCM_CHECKOUT_USERNAME,
|
---|
| 1205 | $DASSCM_CHECKOUT_PASSWORD );
|
---|
[247] | 1206 | print "checkout access okay\n";
|
---|
[205] | 1207 |
|
---|
[247] | 1208 | svn_check_credentials( $input_username, $input_password );
|
---|
| 1209 |
|
---|
[205] | 1210 | #
|
---|
| 1211 | # set environment variables
|
---|
| 1212 | #
|
---|
[267] | 1213 | $ENV{'DASSCM_USERNAME'} = "$input_username";
|
---|
| 1214 | $ENV{'DASSCM_PASSWORD'} = "$input_password";
|
---|
[205] | 1215 |
|
---|
[209] | 1216 | print "subversion access okay\n\n", "DASSCM_USERNAME: $input_username\n",
|
---|
| 1217 | "DASSCM_PASSWORD: (hidden)\n", "DASSCM_PROD: $DASSCM_PROD\n",
|
---|
| 1218 | "DASSCM_REPO: $DASSCM_REPO\n",
|
---|
[278] | 1219 | "Server Repository: $DASSCM_SVN_REPOSITORY\n", "\n";
|
---|
[205] | 1220 |
|
---|
[278] | 1221 | status();
|
---|
| 1222 |
|
---|
| 1223 | print "\n[dasscm shell]\n\n";
|
---|
[235] | 1224 | my $shell = $SHELL || "bash";
|
---|
| 1225 | exec($shell) or die "failed to start new shell";
|
---|
[203] | 1226 | }
|
---|
| 1227 |
|
---|
[260] | 1228 | #
|
---|
| 1229 | # initialize local checkout directory (initial checkout)
|
---|
| 1230 | #
|
---|
[205] | 1231 | sub init(@)
|
---|
| 1232 | {
|
---|
| 1233 | check_parameter( @_, 1 );
|
---|
| 1234 | check_env();
|
---|
| 1235 |
|
---|
[235] | 1236 | # don't do repository creation (svn mkdir) here,
|
---|
| 1237 | # because then their must be a lot of prior checks
|
---|
| 1238 |
|
---|
[205] | 1239 | # update complete repository
|
---|
[801] | 1240 | my $retcode = run_interactive(
|
---|
[918] | 1241 | "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY"
|
---|
[801] | 1242 | );
|
---|
[929] | 1243 |
|
---|
| 1244 | return $retcode;
|
---|
[205] | 1245 | }
|
---|
| 1246 |
|
---|
[215] | 1247 | sub ls(@)
|
---|
[186] | 1248 | {
|
---|
[929] | 1249 | my $return_code = $RETURN_OK;
|
---|
[205] | 1250 | check_parameter( @_, 1 );
|
---|
| 1251 | check_env();
|
---|
[186] | 1252 |
|
---|
[271] | 1253 | my @files = svn_ls(@_);
|
---|
[215] | 1254 |
|
---|
[275] | 1255 | if (@files) {
|
---|
[274] | 1256 | print join( "\n", @files );
|
---|
| 1257 | print "\n";
|
---|
| 1258 | }
|
---|
[929] | 1259 | return $return_code;
|
---|
[215] | 1260 | }
|
---|
| 1261 |
|
---|
| 1262 | sub update(@)
|
---|
| 1263 | {
|
---|
[929] | 1264 | my $return_code = $RETURN_OK;
|
---|
[215] | 1265 | check_parameter( @_, 1 );
|
---|
| 1266 | check_env();
|
---|
| 1267 |
|
---|
| 1268 | #
|
---|
| 1269 | # update local repository
|
---|
| 1270 | #
|
---|
[929] | 1271 | if( ! svn_update() ) {
|
---|
| 1272 | $return_code = $RETURN_NOK;
|
---|
| 1273 | }
|
---|
| 1274 | return $return_code;
|
---|
[215] | 1275 | }
|
---|
| 1276 |
|
---|
[237] | 1277 | #
|
---|
| 1278 | # helper function for "add" command
|
---|
| 1279 | #
|
---|
[215] | 1280 | sub add_helper(@)
|
---|
| 1281 | {
|
---|
[205] | 1282 | (
|
---|
| 1283 | my $basename,
|
---|
| 1284 | my $dirname_prod,
|
---|
| 1285 | my $dirname_repo,
|
---|
| 1286 | my $filename_prod,
|
---|
| 1287 | my $filename_repo
|
---|
[801] | 1288 | ) = get_filenames( $_[0] );
|
---|
[186] | 1289 |
|
---|
[274] | 1290 | mkpath($dirname_repo);
|
---|
[889] | 1291 | copy_file_to_repository($filename_prod);
|
---|
[186] | 1292 |
|
---|
[274] | 1293 | # already checked in?
|
---|
| 1294 | chdir $DASSCM_REPO;
|
---|
[205] | 1295 |
|
---|
[274] | 1296 | # also add the path to filename.
|
---|
| 1297 | for my $dir ( split( '/', $dirname_prod ) ) {
|
---|
| 1298 | if ($dir) {
|
---|
[275] | 1299 | my ( $rc, @out ) = run_command("$SVN add --non-recursive '$dir'");
|
---|
[274] | 1300 | if ( $rc > 0 ) {
|
---|
| 1301 | print join( "\n", @out );
|
---|
[205] | 1302 | }
|
---|
[274] | 1303 | chdir $dir;
|
---|
[205] | 1304 | }
|
---|
| 1305 | }
|
---|
[275] | 1306 | my ( $rc, @out ) = run_command("$SVN add '$basename'");
|
---|
[274] | 1307 | if ( $rc > 0 ) {
|
---|
| 1308 | print join( "\n", @out );
|
---|
| 1309 | }
|
---|
| 1310 | chdir $StartDirectory;
|
---|
| 1311 |
|
---|
[215] | 1312 | }
|
---|
[205] | 1313 |
|
---|
[918] | 1314 | sub add_helper_multi(@)
|
---|
[215] | 1315 | {
|
---|
| 1316 |
|
---|
[237] | 1317 | # get all regular files and links
|
---|
[239] | 1318 | my $href_files = get_files(@_);
|
---|
[220] | 1319 |
|
---|
[237] | 1320 | #print Dumper( $href_files );
|
---|
| 1321 |
|
---|
[239] | 1322 | my @files = @{ $href_files->{files} };
|
---|
| 1323 | my @links = @{ $href_files->{links} };
|
---|
[237] | 1324 |
|
---|
| 1325 | # copy files one by one to local repository
|
---|
| 1326 | for my $file (@files) {
|
---|
[239] | 1327 |
|
---|
[233] | 1328 | # add file
|
---|
[239] | 1329 | add_helper($file);
|
---|
[233] | 1330 | }
|
---|
| 1331 |
|
---|
[918] | 1332 | return $href_files;
|
---|
| 1333 | }
|
---|
[220] | 1334 |
|
---|
[918] | 1335 | #
|
---|
| 1336 | # adding new files (or directories)
|
---|
| 1337 | #
|
---|
| 1338 | sub add(@)
|
---|
| 1339 | {
|
---|
| 1340 | check_parameter( @_, 1 );
|
---|
| 1341 | check_env();
|
---|
[215] | 1342 |
|
---|
[918] | 1343 | #
|
---|
| 1344 | # update local repository
|
---|
| 1345 | #
|
---|
| 1346 | svn_update();
|
---|
[916] | 1347 |
|
---|
[918] | 1348 | # add files to repository, print information about added files
|
---|
| 1349 | print_files_hash( add_helper_multi(@_) );
|
---|
[916] | 1350 |
|
---|
[918] | 1351 | # perform plugins and add additional files, like plugin results
|
---|
| 1352 | perform_plugins();
|
---|
| 1353 | add_helper_multi(@DASSCM_ADDITIONAL_FILES);
|
---|
| 1354 |
|
---|
[205] | 1355 | if ( $options{'message'} ) {
|
---|
| 1356 | $svnOptions .= " --message \"$options{'message'}\" ";
|
---|
| 1357 | }
|
---|
| 1358 |
|
---|
[239] | 1359 | # commit calls $EDITOR.
|
---|
[237] | 1360 | # use "interactive" here, to display output
|
---|
[801] | 1361 | my $retcode = run_interactive(
|
---|
[267] | 1362 | "$SVN commit $svnOptions --username '$DASSCM_USERNAME' $svnPasswordCredentials $DASSCM_REPO"
|
---|
[801] | 1363 | );
|
---|
[205] | 1364 |
|
---|
[274] | 1365 | # svn commit does not deliever an error return code, if commit is canceld,
|
---|
| 1366 | # so a revert is performed in any case
|
---|
| 1367 | svn_revert();
|
---|
[929] | 1368 | return $retcode;
|
---|
[186] | 1369 | }
|
---|
| 1370 |
|
---|
[271] | 1371 | #
|
---|
| 1372 | # checks in all modified files
|
---|
| 1373 | #
|
---|
| 1374 | sub commit(@)
|
---|
| 1375 | {
|
---|
| 1376 | check_parameter( @_, 1 );
|
---|
| 1377 | check_env();
|
---|
| 1378 |
|
---|
| 1379 | (
|
---|
| 1380 | my $basename,
|
---|
| 1381 | my $dirname_prod,
|
---|
| 1382 | my $dirname_repo,
|
---|
| 1383 | my $filename_prod,
|
---|
| 1384 | my $filename_repo
|
---|
[801] | 1385 | ) = get_filenames( $_[0] );
|
---|
[271] | 1386 |
|
---|
| 1387 | #
|
---|
| 1388 | # update local repository
|
---|
| 1389 | #
|
---|
| 1390 | svn_update();
|
---|
| 1391 |
|
---|
[275] | 1392 | ( my $refChangedFiles, my $refRemovedFiles ) =
|
---|
| 1393 | getModifiedFiles($filename_prod);
|
---|
[271] | 1394 | my %changedfiles = %{$refChangedFiles};
|
---|
| 1395 | my %removedfiles = %{$refRemovedFiles};
|
---|
| 1396 |
|
---|
[275] | 1397 | if (%removedfiles) {
|
---|
| 1398 | my $removedFilesString =
|
---|
| 1399 | '"' . join( '" "', values(%removedfiles) ) . '"';
|
---|
| 1400 | my ( $rc, @out ) = run_command("$SVN rm $removedFilesString");
|
---|
[271] | 1401 | if ( $rc > 0 ) {
|
---|
| 1402 | print join( "\n", @out );
|
---|
| 1403 | }
|
---|
| 1404 | }
|
---|
| 1405 |
|
---|
| 1406 | # copy files one by one to local repository
|
---|
| 1407 | for my $file ( keys(%changedfiles) ) {
|
---|
[275] | 1408 | copy_file_to_repository($file);
|
---|
[271] | 1409 | }
|
---|
| 1410 |
|
---|
[918] | 1411 | perform_plugins();
|
---|
| 1412 | add_helper_multi(@DASSCM_ADDITIONAL_FILES);
|
---|
[271] | 1413 |
|
---|
| 1414 | if ( $options{'message'} ) {
|
---|
| 1415 | $svnOptions .= " --message \"$options{'message'}\" ";
|
---|
| 1416 | }
|
---|
| 1417 |
|
---|
| 1418 | # commit calls $EDITOR.
|
---|
| 1419 | # use "interactive" here, to display output
|
---|
[801] | 1420 | my $retcode = run_interactive(
|
---|
[271] | 1421 | "$SVN commit $svnOptions --username '$DASSCM_USERNAME' $svnPasswordCredentials $DASSCM_REPO"
|
---|
[801] | 1422 | );
|
---|
[274] | 1423 |
|
---|
| 1424 | # svn commit does not deliever an error return code, if commit is canceld,
|
---|
| 1425 | # so a revert is performed in any case
|
---|
| 1426 | svn_revert();
|
---|
[929] | 1427 | return $retcode;
|
---|
[271] | 1428 | }
|
---|
| 1429 |
|
---|
[800] | 1430 | #
|
---|
| 1431 | # revert: copies files back from repository to system
|
---|
| 1432 | #
|
---|
| 1433 | sub revert(@)
|
---|
| 1434 | {
|
---|
| 1435 | check_parameter( @_, 1 );
|
---|
| 1436 | check_env();
|
---|
| 1437 |
|
---|
| 1438 | (
|
---|
| 1439 | my $basename,
|
---|
| 1440 | my $dirname_prod,
|
---|
| 1441 | my $dirname_repo,
|
---|
| 1442 | my $filename_prod,
|
---|
| 1443 | my $filename_repo
|
---|
[801] | 1444 | ) = get_filenames( $_[0] );
|
---|
[800] | 1445 |
|
---|
| 1446 | # return code for the shell
|
---|
| 1447 | # default: error
|
---|
| 1448 | my $return_code = $RETURN_OK;
|
---|
| 1449 |
|
---|
| 1450 | # cleanup repository
|
---|
[801] | 1451 | cleanup();
|
---|
[889] | 1452 |
|
---|
[800] | 1453 | #svn_update();
|
---|
| 1454 |
|
---|
| 1455 | ( my $refChangedFiles, my $refRemovedFiles, my $refUnknownFiles ) =
|
---|
| 1456 | getModifiedFiles($filename_prod);
|
---|
| 1457 | my %changedfiles = %{$refChangedFiles};
|
---|
| 1458 | my %removedfiles = %{$refRemovedFiles};
|
---|
| 1459 | my %unknownfiles = %{$refUnknownFiles};
|
---|
| 1460 |
|
---|
| 1461 | if ( %removedfiles or %changedfiles or %unknownfiles ) {
|
---|
| 1462 |
|
---|
| 1463 | if (%removedfiles) {
|
---|
| 1464 | print "DELETED files and directories. Recreated from repository:\n";
|
---|
[801] | 1465 | my @removedPaths =
|
---|
| 1466 | ( sort { length $a > length $b } keys %removedfiles );
|
---|
[800] | 1467 | print join( "\n", @removedPaths ) . "\n\n";
|
---|
| 1468 |
|
---|
| 1469 | # copy files one by one from local repository to system
|
---|
| 1470 | # and also create directories
|
---|
| 1471 | # paths are sorted, so that directories are created first
|
---|
[801] | 1472 | for my $real_path (@removedPaths) {
|
---|
| 1473 | if ( -d $removedfiles{"$real_path"} ) {
|
---|
[800] | 1474 | mkpath("$real_path");
|
---|
| 1475 | } else {
|
---|
[889] | 1476 | copy_file_from_repository_to_system($real_path);
|
---|
[800] | 1477 | }
|
---|
| 1478 | }
|
---|
| 1479 | }
|
---|
| 1480 |
|
---|
| 1481 | if (%changedfiles) {
|
---|
| 1482 | print "MODIFIED files. Copied from repository to the system:\n";
|
---|
| 1483 | print join( "\n", ( keys %changedfiles ) ) . "\n\n";
|
---|
| 1484 |
|
---|
| 1485 | # copy files one by one from local repository to system
|
---|
| 1486 | for my $real_file ( keys(%changedfiles) ) {
|
---|
[889] | 1487 | copy_file_from_repository_to_system($real_file);
|
---|
[800] | 1488 | }
|
---|
| 1489 |
|
---|
| 1490 | }
|
---|
| 1491 |
|
---|
| 1492 | if (%unknownfiles) {
|
---|
| 1493 | print "UNKNOWN: insufficient permission to check files:\n";
|
---|
| 1494 | print join( "\n", ( keys %unknownfiles ) ) . "\n\n";
|
---|
| 1495 |
|
---|
| 1496 | $return_code = $RETURN_NOK;
|
---|
| 1497 | }
|
---|
| 1498 |
|
---|
| 1499 | } else {
|
---|
| 1500 | print "no modified files found in $dirname_repo\n";
|
---|
| 1501 | }
|
---|
| 1502 |
|
---|
| 1503 | return $return_code;
|
---|
| 1504 | }
|
---|
| 1505 |
|
---|
[193] | 1506 | sub blame(@)
|
---|
| 1507 | {
|
---|
[205] | 1508 | check_parameter( @_, 1 );
|
---|
| 1509 | check_env();
|
---|
[193] | 1510 |
|
---|
[205] | 1511 | (
|
---|
| 1512 | my $basename,
|
---|
| 1513 | my $dirname_prod,
|
---|
| 1514 | my $dirname_repo,
|
---|
| 1515 | my $filename_prod,
|
---|
| 1516 | my $filename_repo
|
---|
[801] | 1517 | ) = get_filenames( $_[0] );
|
---|
[205] | 1518 |
|
---|
[929] | 1519 | my $retcode = run_interactive("$SVN blame --non-interactive $svnCheckoutCredentials $svnOptions $filename_repo");
|
---|
| 1520 | return $retcode;
|
---|
[193] | 1521 | }
|
---|
| 1522 |
|
---|
[187] | 1523 | sub diff(@)
|
---|
| 1524 | {
|
---|
[205] | 1525 | check_parameter( @_, 1 );
|
---|
| 1526 | check_env();
|
---|
[187] | 1527 |
|
---|
[205] | 1528 | (
|
---|
| 1529 | my $basename,
|
---|
| 1530 | my $dirname_prod,
|
---|
| 1531 | my $dirname_repo,
|
---|
| 1532 | my $filename_prod,
|
---|
| 1533 | my $filename_repo
|
---|
[801] | 1534 | ) = get_filenames( $_[0] );
|
---|
[205] | 1535 |
|
---|
| 1536 | #print "$basename,$dirname_prod,$dirname_repo\n";
|
---|
| 1537 |
|
---|
[797] | 1538 | svn_update();
|
---|
[205] | 1539 |
|
---|
[238] | 1540 | ( my $rc_diff, my @diff_result ) =
|
---|
[239] | 1541 | run_command( $diff . " $filename_repo $filename_prod" );
|
---|
[238] | 1542 |
|
---|
| 1543 | print @diff_result;
|
---|
[929] | 1544 | return $rc_diff;
|
---|
[187] | 1545 | }
|
---|
| 1546 |
|
---|
[209] | 1547 | sub status(@)
|
---|
| 1548 | {
|
---|
| 1549 | check_parameter( @_, 1 );
|
---|
| 1550 | check_env();
|
---|
| 1551 |
|
---|
[270] | 1552 | (
|
---|
| 1553 | my $basename,
|
---|
| 1554 | my $dirname_prod,
|
---|
| 1555 | my $dirname_repo,
|
---|
| 1556 | my $filename_prod,
|
---|
| 1557 | my $filename_repo
|
---|
[801] | 1558 | ) = get_filenames( $_[0] || "/" );
|
---|
[270] | 1559 |
|
---|
[252] | 1560 | # return code for the shell
|
---|
| 1561 | # default: error
|
---|
| 1562 | my $return_code = $RETURN_NOK;
|
---|
| 1563 |
|
---|
[209] | 1564 | #
|
---|
| 1565 | # update local repository
|
---|
| 1566 | #
|
---|
[278] | 1567 | #svn_update( $filename_prod );
|
---|
[209] | 1568 |
|
---|
[918] | 1569 | # perform plugins (required to see changes in plugin results)
|
---|
[916] | 1570 | perform_plugins();
|
---|
[278] | 1571 |
|
---|
| 1572 | # get modified files
|
---|
| 1573 | ( my $refChangedFiles, my $refRemovedFiles, my $refUnknownFiles ) =
|
---|
[275] | 1574 | getModifiedFiles($dirname_prod);
|
---|
[268] | 1575 | my %changedfiles = %{$refChangedFiles};
|
---|
| 1576 | my %removedfiles = %{$refRemovedFiles};
|
---|
[278] | 1577 | my %unknownfiles = %{$refUnknownFiles};
|
---|
[209] | 1578 |
|
---|
[278] | 1579 | if ( %removedfiles or %changedfiles or %unknownfiles ) {
|
---|
| 1580 |
|
---|
[215] | 1581 | if (%removedfiles) {
|
---|
[278] | 1582 | print "DELETED: files found in repository, but not in system:\n";
|
---|
[800] | 1583 | print join( "\n", sort ( keys %removedfiles ) ) . "\n\n";
|
---|
[209] | 1584 | }
|
---|
| 1585 |
|
---|
[215] | 1586 | if (%changedfiles) {
|
---|
[278] | 1587 | print "MODIFIED: files differs between repository and system:\n";
|
---|
| 1588 | print join( "\n", ( keys %changedfiles ) ) . "\n\n";
|
---|
[209] | 1589 | }
|
---|
[278] | 1590 |
|
---|
| 1591 | if (%unknownfiles) {
|
---|
| 1592 | print "UNKNOWN: insufficient permission to check files:\n";
|
---|
| 1593 | print join( "\n", ( keys %unknownfiles ) ) . "\n\n";
|
---|
| 1594 | }
|
---|
| 1595 |
|
---|
[209] | 1596 | } else {
|
---|
[270] | 1597 | print "no modified files found in $dirname_repo\n";
|
---|
[252] | 1598 | $return_code = $RETURN_OK;
|
---|
[209] | 1599 | }
|
---|
[215] | 1600 |
|
---|
[252] | 1601 | return $return_code;
|
---|
[215] | 1602 | }
|
---|
[209] | 1603 |
|
---|
[277] | 1604 | #
|
---|
| 1605 | # return short status in Nagios plugin conform way
|
---|
| 1606 | #
|
---|
| 1607 | sub check()
|
---|
| 1608 | {
|
---|
| 1609 | check_env();
|
---|
| 1610 |
|
---|
| 1611 | # return code for the shell
|
---|
[290] | 1612 | my $return_code = $RETURN_OK;
|
---|
[277] | 1613 | my $return_string = "OK: no modified files";
|
---|
| 1614 |
|
---|
[918] | 1615 | # perform plugins (required to see changes in plugin results)
|
---|
[916] | 1616 | perform_plugins();
|
---|
[278] | 1617 |
|
---|
| 1618 | # get modified files
|
---|
| 1619 | ( my $refChangedFiles, my $refRemovedFiles, my $refUnknownFiles ) =
|
---|
[290] | 1620 | getModifiedFiles("/");
|
---|
[277] | 1621 | my %changedfiles = %{$refChangedFiles};
|
---|
| 1622 | my %removedfiles = %{$refRemovedFiles};
|
---|
[278] | 1623 | my %unknownfiles = %{$refUnknownFiles};
|
---|
[277] | 1624 |
|
---|
| 1625 | if ( %removedfiles or %changedfiles ) {
|
---|
| 1626 | $return_string = "Warning: ";
|
---|
[290] | 1627 | if (%changedfiles) {
|
---|
| 1628 | $return_string .=
|
---|
| 1629 | "changed: " . join( ", ", ( keys %changedfiles ) ) . ". ";
|
---|
[277] | 1630 | }
|
---|
[290] | 1631 | if (%removedfiles) {
|
---|
| 1632 | $return_string .=
|
---|
| 1633 | "removed: " . join( ", ", ( keys %removedfiles ) ) . ". ";
|
---|
[277] | 1634 | }
|
---|
[278] | 1635 | if (%unknownfiles) {
|
---|
[290] | 1636 | $return_string .=
|
---|
| 1637 | "unknown: " . join( ", ", ( keys %unknownfiles ) ) . ". ";
|
---|
[278] | 1638 | }
|
---|
[277] | 1639 | $return_code = $RETURN_WARN;
|
---|
| 1640 | }
|
---|
| 1641 |
|
---|
| 1642 | # addition nagios Service Status
|
---|
| 1643 | #Critical
|
---|
| 1644 | #Unknown
|
---|
| 1645 |
|
---|
[290] | 1646 | print "$return_string\n";
|
---|
[277] | 1647 | return $return_code;
|
---|
| 1648 | }
|
---|
| 1649 |
|
---|
[270] | 1650 | sub permissions()
|
---|
[215] | 1651 | {
|
---|
| 1652 | check_env();
|
---|
| 1653 |
|
---|
[278] | 1654 | my $return_code = $RETURN_OK;
|
---|
| 1655 |
|
---|
[215] | 1656 | #
|
---|
| 1657 | # update local repository
|
---|
| 1658 | #
|
---|
| 1659 | #svn_update();
|
---|
| 1660 |
|
---|
[220] | 1661 | my $dir = $DASSCM_REPO;
|
---|
[275] | 1662 | my @files = svn_ls("/");
|
---|
[215] | 1663 |
|
---|
| 1664 | if (@files) {
|
---|
| 1665 |
|
---|
[918] | 1666 | print "#\n";
|
---|
| 1667 | print "# created by dasscm permissions\n";
|
---|
| 1668 | print "# It is intended to be used for restoring permissions\n";
|
---|
| 1669 | print "#\n";
|
---|
[220] | 1670 |
|
---|
[918] | 1671 | # generate and print permissions
|
---|
| 1672 | foreach my $line ( generatePermissionList(@files) ) {
|
---|
| 1673 | print "$line\n";
|
---|
[215] | 1674 | }
|
---|
[278] | 1675 |
|
---|
[215] | 1676 | }
|
---|
[278] | 1677 |
|
---|
| 1678 | return $return_code;
|
---|
[209] | 1679 | }
|
---|
| 1680 |
|
---|
[274] | 1681 | #
|
---|
| 1682 | # remove all uncommited changes in the repository
|
---|
| 1683 | #
|
---|
| 1684 | sub cleanup()
|
---|
| 1685 | {
|
---|
[929] | 1686 | my $return_code = $RETURN_OK;
|
---|
| 1687 |
|
---|
[274] | 1688 | check_env();
|
---|
[268] | 1689 |
|
---|
[275] | 1690 | svn_revert($DASSCM_REPO);
|
---|
[285] | 1691 | svn_remove_unknown_files($DASSCM_REPO);
|
---|
[929] | 1692 |
|
---|
| 1693 | return $return_code;
|
---|
[274] | 1694 | }
|
---|
| 1695 |
|
---|
[884] | 1696 | #
|
---|
| 1697 | # used for bash completion
|
---|
| 1698 | # prints the next possible command line parameters
|
---|
| 1699 | #
|
---|
| 1700 | sub complete(@)
|
---|
| 1701 | {
|
---|
[889] | 1702 | my @input = @_;
|
---|
[894] | 1703 | my %options_complete = ();
|
---|
[884] | 1704 |
|
---|
[929] | 1705 | my $return_code = $RETURN_OK;
|
---|
| 1706 |
|
---|
[894] | 1707 | # check and remove global options. if options are wrong, nothing to do
|
---|
[907] | 1708 | @ARGV = @input;
|
---|
[914] | 1709 | if ( GetOptions( \%options_complete, @OPTIONS_GLOBAL ) ) {
|
---|
[894] | 1710 | my $number_arguments = @input;
|
---|
| 1711 | if ( $number_arguments <= 1 ) {
|
---|
[893] | 1712 |
|
---|
[894] | 1713 | # complete dasscm commands
|
---|
| 1714 | my $input = $input[0] || "";
|
---|
| 1715 | map { m/^$input/ && print $_, "\n" } ( keys %COMMANDS );
|
---|
| 1716 | } else {
|
---|
[914] | 1717 |
|
---|
[894] | 1718 | # complete dasscm parameter
|
---|
| 1719 | my $command = get_command_uniform_name( $input[0] );
|
---|
[914] | 1720 | if ($command) {
|
---|
| 1721 |
|
---|
[895] | 1722 | # remove command
|
---|
| 1723 | shift @input;
|
---|
[887] | 1724 |
|
---|
[895] | 1725 | # check and remove options
|
---|
[914] | 1726 | my @options = get_command_possible_options($command);
|
---|
[907] | 1727 | @ARGV = @input;
|
---|
[914] | 1728 | if ( ( not @options )
|
---|
| 1729 | || ( GetOptions( \%options_complete, @options ) ) )
|
---|
| 1730 | {
|
---|
[895] | 1731 |
|
---|
[914] | 1732 | my @params = get_command_possible_params($command);
|
---|
[895] | 1733 | if ($verbose) { print "params: ", Dumper(@params); }
|
---|
| 1734 |
|
---|
| 1735 | my $number_arguments = @input;
|
---|
| 1736 |
|
---|
| 1737 | #print "input: ", join( ",", @input ), " (", $number_arguments, ")\n";
|
---|
| 1738 |
|
---|
[914] | 1739 | if ( $number_arguments > 0 ) {
|
---|
[895] | 1740 | my $parameter_number = $number_arguments - 1;
|
---|
| 1741 | if ( defined( $params[$parameter_number] )
|
---|
| 1742 | && $params[$parameter_number] )
|
---|
| 1743 | {
|
---|
| 1744 | my $param = $params[$parameter_number];
|
---|
[914] | 1745 | if ($verbose) {
|
---|
| 1746 | print "param used: ", $param, "\n";
|
---|
| 1747 | }
|
---|
[895] | 1748 | if ( $param eq "PATH_PROD" ) {
|
---|
[914] | 1749 | complete_path(
|
---|
| 1750 | $input[ $number_arguments - 1 ] );
|
---|
[895] | 1751 | } elsif ( $param eq "PATH_REPO" ) {
|
---|
[914] | 1752 | complete_repopath(
|
---|
| 1753 | $input[ $number_arguments - 1 ] );
|
---|
[895] | 1754 | }
|
---|
| 1755 | }
|
---|
| 1756 | }
|
---|
[894] | 1757 | }
|
---|
[887] | 1758 | }
|
---|
[884] | 1759 | }
|
---|
| 1760 | }
|
---|
[929] | 1761 | return $return_code;
|
---|
[884] | 1762 | }
|
---|
| 1763 |
|
---|
[887] | 1764 | sub complete_path(@)
|
---|
| 1765 | {
|
---|
[929] | 1766 | my $return_code = $RETURN_OK;
|
---|
[887] | 1767 | check_parameter( @_, 1 );
|
---|
| 1768 | check_env();
|
---|
| 1769 |
|
---|
| 1770 | (
|
---|
| 1771 | my $basename,
|
---|
| 1772 | my $dirname_prod,
|
---|
| 1773 | my $dirname_repo,
|
---|
| 1774 | my $filename_prod,
|
---|
| 1775 | my $filename_repo
|
---|
| 1776 | ) = get_filenames( $_[0] );
|
---|
| 1777 |
|
---|
[889] | 1778 | my @files = get_complete_path_globbing($filename_prod);
|
---|
[887] | 1779 |
|
---|
| 1780 | if (@files) {
|
---|
| 1781 | print join( "\n", @files );
|
---|
| 1782 | print "\n";
|
---|
| 1783 | }
|
---|
[929] | 1784 | return $return_code;
|
---|
[887] | 1785 | }
|
---|
| 1786 |
|
---|
| 1787 | sub complete_repopath(@)
|
---|
| 1788 | {
|
---|
[929] | 1789 | my $return_code = $RETURN_OK;
|
---|
[887] | 1790 | check_parameter( @_, 1 );
|
---|
| 1791 | check_env();
|
---|
| 1792 |
|
---|
| 1793 | (
|
---|
| 1794 | my $basename,
|
---|
| 1795 | my $dirname_prod,
|
---|
| 1796 | my $dirname_repo,
|
---|
| 1797 | my $filename_prod,
|
---|
| 1798 | my $filename_repo
|
---|
| 1799 | ) = get_filenames( $_[0] );
|
---|
| 1800 |
|
---|
[889] | 1801 | my @files = get_complete_path_globbing($filename_repo);
|
---|
| 1802 |
|
---|
[887] | 1803 | if (@files) {
|
---|
[889] | 1804 |
|
---|
[887] | 1805 | # remove DASSCM_REPO path again
|
---|
[889] | 1806 | print join(
|
---|
| 1807 | "\n",
|
---|
| 1808 | map( {
|
---|
| 1809 | s|^${DASSCM_REPO}|/|;
|
---|
| 1810 | $_
|
---|
| 1811 | } @files )
|
---|
| 1812 | );
|
---|
[887] | 1813 | print "\n";
|
---|
| 1814 | }
|
---|
[929] | 1815 | return $return_code;
|
---|
[887] | 1816 | }
|
---|
| 1817 |
|
---|
[189] | 1818 | #####################################################################
|
---|
| 1819 | #
|
---|
[186] | 1820 | # main
|
---|
[189] | 1821 | #
|
---|
[186] | 1822 |
|
---|
[252] | 1823 | my $return_code = $RETURN_OK;
|
---|
[186] | 1824 | my $number_arguments = @ARGV;
|
---|
| 1825 |
|
---|
[893] | 1826 | # global options
|
---|
| 1827 | # stops at first non-option
|
---|
[914] | 1828 | Getopt::Long::Configure('require_order');
|
---|
| 1829 | if ( not GetOptions( \%options, @OPTIONS_GLOBAL ) ) {
|
---|
[893] | 1830 | usage();
|
---|
| 1831 | exit $RETURN_NOK;
|
---|
| 1832 | }
|
---|
| 1833 |
|
---|
| 1834 | # set verbose to command line option
|
---|
| 1835 | $verbose = $options{'verbose'};
|
---|
| 1836 |
|
---|
[914] | 1837 | if ( $options{'help'} ) {
|
---|
[893] | 1838 | help(@ARGV);
|
---|
| 1839 | exit;
|
---|
| 1840 | }
|
---|
| 1841 |
|
---|
[892] | 1842 | # get subcommand and remove it from @ARGV
|
---|
[914] | 1843 | if ( defined( $ARGV[0] ) ) {
|
---|
[889] | 1844 | $command = get_command_uniform_name( $ARGV[0] );
|
---|
[205] | 1845 | shift @ARGV;
|
---|
[892] | 1846 | }
|
---|
[893] | 1847 |
|
---|
[914] | 1848 | if ( not defined($command) ) {
|
---|
| 1849 | usage();
|
---|
| 1850 | exit $RETURN_NOK;
|
---|
[893] | 1851 | }
|
---|
[196] | 1852 |
|
---|
[893] | 1853 | $DASSCM_LOCAL_REPOSITORY_BASE = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'};
|
---|
| 1854 | $DASSCM_REPOSITORY_NAME = $config->{'DASSCM_REPOSITORY_NAME'};
|
---|
[205] | 1855 |
|
---|
[918] | 1856 | $DASSCM_PLUGIN_RESULTS_PATH =
|
---|
| 1857 | $config->{'DASSCM_LOCAL_REPOSITORY_BASE'} . "/" . "plugin-results/";
|
---|
[916] | 1858 |
|
---|
[918] | 1859 | # get list of additional directories and files, seperated by blank (" ")
|
---|
| 1860 | # these files are always stored in subversion
|
---|
| 1861 | if ( $config->{'DASSCM_ADDITIONAL_FILES'} ) {
|
---|
| 1862 | @DASSCM_ADDITIONAL_FILES = split / /, $config->{'DASSCM_ADDITIONAL_FILES'};
|
---|
| 1863 | } else {
|
---|
| 1864 | @DASSCM_ADDITIONAL_FILES = ( $DASSCM_PLUGIN_RESULTS_PATH );
|
---|
| 1865 | }
|
---|
| 1866 |
|
---|
[893] | 1867 | # TODO: check variables
|
---|
| 1868 | $DASSCM_SVN_REPOSITORY =
|
---|
[914] | 1869 | $config->{'DASSCM_SVN_REPOSITORY_BASE'} . "/" . $DASSCM_REPOSITORY_NAME;
|
---|
[205] | 1870 |
|
---|
[893] | 1871 | $DASSCM_CHECKOUT_USERNAME = $config->{'DASSCM_CHECKOUT_USERNAME'};
|
---|
| 1872 | $DASSCM_CHECKOUT_PASSWORD = $config->{'DASSCM_CHECKOUT_PASSWORD'};
|
---|
[205] | 1873 |
|
---|
[893] | 1874 | #
|
---|
| 1875 | # if a user is given by dasscm configuration file, we use it.
|
---|
| 1876 | # Otherwise we expect that read-only account is configured
|
---|
| 1877 | # as local subversion configuration.
|
---|
| 1878 | # If this is also not the case,
|
---|
| 1879 | # user is required to type username and password.
|
---|
| 1880 | # This will be stored as local subversion configuration thereafter.
|
---|
| 1881 | #
|
---|
| 1882 | if ( $DASSCM_CHECKOUT_USERNAME && $DASSCM_CHECKOUT_PASSWORD ) {
|
---|
| 1883 | $svnCheckoutCredentials =
|
---|
[914] | 1884 | " --username $DASSCM_CHECKOUT_USERNAME --password $DASSCM_CHECKOUT_PASSWORD ";
|
---|
[893] | 1885 | }
|
---|
[286] | 1886 |
|
---|
[893] | 1887 |
|
---|
| 1888 | # check for command options
|
---|
[914] | 1889 | my @cmd_options = get_command_possible_options($command);
|
---|
| 1890 | if (@cmd_options) {
|
---|
| 1891 |
|
---|
[205] | 1892 | # get command line options and store them in options hash
|
---|
[893] | 1893 | my $result = GetOptions( \%options, @cmd_options );
|
---|
[205] | 1894 |
|
---|
| 1895 | # print options
|
---|
| 1896 | foreach my $option ( keys %options ) {
|
---|
[215] | 1897 | print "${option}: $options{$option}\n";
|
---|
[205] | 1898 | }
|
---|
[893] | 1899 | }
|
---|
[205] | 1900 |
|
---|
[893] | 1901 | #
|
---|
| 1902 | # action accordinly to command are taken
|
---|
| 1903 | #
|
---|
[929] | 1904 | $return_code = &{ get_command_function($command) }(@ARGV);
|
---|
[214] | 1905 |
|
---|
[252] | 1906 | exit $return_code;
|
---|