source: dasscm/trunk/usr/bin/dasscm@ 891

Last change on this file since 891 was 891, checked in by joergs, on Jun 26, 2010 at 12:57:52 PM

cleanup

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