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

Last change on this file since 890 was 890, checked in by joergs, on Jun 26, 2010 at 12:17:42 PM

bash completion: add / to directories

  • Property keyword set to id
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 42.7 KB
Line 
1#!/usr/bin/perl -w
2
3# $Id: dasscm 890 2010-06-26 10:17:42Z 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
14# used system("cp -a"), because File::Copy does not keep permissions
15#use File::Copy;
16use File::Find;
17use File::stat;
18use File::Path;
19use Term::ReadKey;
20
21#use Data::Dumper;
22
23#####################################################################
24#
25# global
26#
27
28# shell exit codes
29my $RETURN_OK = 0;
30my $RETURN_NOK = 1;
31
32# Nagios return codes
33my $RETURN_WARN = 1;
34my $RETURN_CRIT = 2;
35my $RETURN_UNKNOWN = 3;
36
37# documentation file (for usage)
38my $doc_file = "/usr/share/doc/packages/dasscm/dasscm_howto.txt";
39
40my $config_file = "/etc/dasscm.conf";
41my $config = get_config($config_file);
42
43my %COMMANDS = (
44 '--help' => 'help',
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',
65 'complete_repopath' => 'complete_repopath',
66);
67
68# desc: description (eg. for usage)
69# params: parameters
70# CMD
71# USER
72# PATH
73# REPOPATH
74# require:
75# WRITE commands that require write access (and therefore a login)
76my %COMMAND_DEFINITIONS = (
77 'help' => {
78 'desc' => [],
79 'params' => ["CMD"],
80 'function' => \&help,
81 },
82 'login' => {
83 'desc' => [],
84 'params' => ["USER"],
85 'function' => \&login
86 },
87 'init' => {
88 'desc' => [
89 "initialize local subversion checkout.",
90 "This is the first thing to do (after configuring $config_file)"
91 ],
92 'params' => [],
93 'function' => \&init
94 },
95 'ls' => {
96 'desc' => [],
97 'params' => ["REPOPATH"],
98 'function' => \&ls
99 },
100 'update' => {
101 'desc' => [],
102 'params' => ["PATH"],
103 'function' => \&update
104 },
105 'add' => {
106 'desc' => [],
107 'params' => ["PATH"],
108 'require' => ["WRITE"],
109 'function' => \&add
110 },
111 'commit' => {
112 'desc' => [],
113 'params' => ["REPOPATH"],
114 'require' => ["WRITE"],
115 'function' => \&commit
116 },
117 'revert' => {
118 'desc' => ["revert local changes back to version from repository"],
119 'params' => ["REPOPATH"],
120 'function' => \&revert
121 },
122 'blame' => {
123 'desc' => [],
124 'params' => ["PATH"],
125 'function' => \&blame
126 },
127 'diff' => {
128 'desc' => [],
129 'params' => ["PATH"],
130 'function' => \&diff
131 },
132 'status' => {
133 'desc' => [],
134 'params' => ["PATH"],
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 890 2010-06-26 10:17:42Z 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 only one result is available
972 # and this result is a directory,
973 # add another result entry
974 # (otherwise complete will stop here and continue with the next parameter)
975 if ( $#files == 0 ) {
976 my $path = $files[0];
977 if ( -d $path ) {
978 push( @files, $path . "/" );
979 }
980 } else {
981 # add "/" to all directories
982 @files = map( { -d $_ && $_ ."/" || $_ } @files );
983 }
984
985 return @files;
986}
987
988#####################################################################
989#
990# functions
991sub help(;@)
992{
993 if ( @_ == 0 ) {
994 usage();
995 } else {
996 print "help for @_: ...\n";
997 usage();
998 }
999}
1000
1001sub login(@)
1002{
1003 check_parameter( @_, 1 );
1004 check_env();
1005
1006 my $input_username = $_[0];
1007
1008 if ( not $input_username ) {
1009 my $output_username = "";
1010 if ($DASSCM_USERNAME) {
1011 $output_username = " ($DASSCM_USERNAME)";
1012 }
1013
1014 print "Enter DASSCM user name", $output_username, ": ";
1015 $input_username = <STDIN>;
1016 chomp($input_username);
1017
1018 $input_username = $input_username || $DASSCM_USERNAME;
1019 }
1020
1021 # hidden password input
1022 print "Enter password for $input_username: ";
1023 ReadMode('noecho');
1024 my $input_password = <STDIN>;
1025 ReadMode('normal');
1026 chomp($input_password);
1027 print "\n";
1028
1029 # checking checkout username/password
1030 svn_check_credentials( $DASSCM_CHECKOUT_USERNAME,
1031 $DASSCM_CHECKOUT_PASSWORD );
1032 print "checkout access okay\n";
1033
1034 svn_check_credentials( $input_username, $input_password );
1035
1036 #
1037 # set environment variables
1038 #
1039 $ENV{'DASSCM_USERNAME'} = "$input_username";
1040 $ENV{'DASSCM_PASSWORD'} = "$input_password";
1041
1042 print "subversion access okay\n\n", "DASSCM_USERNAME: $input_username\n",
1043 "DASSCM_PASSWORD: (hidden)\n", "DASSCM_PROD: $DASSCM_PROD\n",
1044 "DASSCM_REPO: $DASSCM_REPO\n",
1045 "Server Repository: $DASSCM_SVN_REPOSITORY\n", "\n";
1046
1047 status();
1048
1049 print "\n[dasscm shell]\n\n";
1050 my $shell = $SHELL || "bash";
1051 exec($shell) or die "failed to start new shell";
1052}
1053
1054#
1055# initialize local checkout directory (initial checkout)
1056#
1057sub init(@)
1058{
1059 check_parameter( @_, 1 );
1060 check_env();
1061
1062 # don't do repository creation (svn mkdir) here,
1063 # because then their must be a lot of prior checks
1064
1065 # update complete repository
1066 # and create permission file
1067 my $retcode = run_interactive(
1068 "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY; mkdir -p `dirname $DASSCM_PERMISSION_FILE`; touch $DASSCM_PERMISSION_FILE"
1069 );
1070}
1071
1072sub ls(@)
1073{
1074 check_parameter( @_, 1 );
1075 check_env();
1076
1077 my @files = svn_ls(@_);
1078
1079 if (@files) {
1080 print join( "\n", @files );
1081 print "\n";
1082 }
1083}
1084
1085sub update(@)
1086{
1087 check_parameter( @_, 1 );
1088 check_env();
1089
1090 #
1091 # update local repository
1092 #
1093 svn_update();
1094}
1095
1096#
1097# helper function for "add" command
1098#
1099sub add_helper(@)
1100{
1101 (
1102 my $basename,
1103 my $dirname_prod,
1104 my $dirname_repo,
1105 my $filename_prod,
1106 my $filename_repo
1107 ) = get_filenames( $_[0] );
1108
1109 mkpath($dirname_repo);
1110 copy_file_to_repository($filename_prod);
1111
1112 # already checked in?
1113 chdir $DASSCM_REPO;
1114
1115 # also add the path to filename.
1116 for my $dir ( split( '/', $dirname_prod ) ) {
1117 if ($dir) {
1118 my ( $rc, @out ) = run_command("$SVN add --non-recursive '$dir'");
1119 if ( $rc > 0 ) {
1120 print join( "\n", @out );
1121 }
1122 chdir $dir;
1123 }
1124 }
1125 my ( $rc, @out ) = run_command("$SVN add '$basename'");
1126 if ( $rc > 0 ) {
1127 print join( "\n", @out );
1128 }
1129 chdir $StartDirectory;
1130
1131}
1132
1133#
1134# adding new files (or directories)
1135#
1136sub add(@)
1137{
1138 check_parameter( @_, 1 );
1139 check_env();
1140
1141 #
1142 # update local repository
1143 #
1144 svn_update();
1145
1146 # get all regular files and links
1147 my $href_files = get_files(@_);
1148
1149 #print Dumper( $href_files );
1150
1151 my @files = @{ $href_files->{files} };
1152 my @links = @{ $href_files->{links} };
1153
1154 if (@files) {
1155 my $number = $#files + 1;
1156 print "files to check-in ($number): \n";
1157 print join( "\n", @files );
1158 print "\n";
1159 }
1160
1161 # TODO: check in links and also link target? At least warn about link target
1162 if (@links) {
1163 my $number = $#links + 1;
1164 print "\n";
1165 print "ignoring links ($number):\n";
1166 print join( "\n", @links );
1167 print "\n";
1168 }
1169
1170 # TODO: confirm
1171
1172 # copy files one by one to local repository
1173 for my $file (@files) {
1174
1175 # add file
1176 add_helper($file);
1177 }
1178
1179 # create new permissions file
1180 permissions();
1181
1182 # add permissions file
1183 add_helper($DASSCM_PERMISSION_FILE);
1184
1185 if ( $options{'message'} ) {
1186 $svnOptions .= " --message \"$options{'message'}\" ";
1187 }
1188
1189 # commit calls $EDITOR.
1190 # use "interactive" here, to display output
1191 my $retcode = run_interactive(
1192 "$SVN commit $svnOptions --username '$DASSCM_USERNAME' $svnPasswordCredentials $DASSCM_REPO"
1193 );
1194
1195 # svn commit does not deliever an error return code, if commit is canceld,
1196 # so a revert is performed in any case
1197 svn_revert();
1198}
1199
1200#
1201# checks in all modified files
1202#
1203sub commit(@)
1204{
1205 check_parameter( @_, 1 );
1206 check_env();
1207
1208 (
1209 my $basename,
1210 my $dirname_prod,
1211 my $dirname_repo,
1212 my $filename_prod,
1213 my $filename_repo
1214 ) = get_filenames( $_[0] );
1215
1216 #
1217 # update local repository
1218 #
1219 svn_update();
1220
1221 ( my $refChangedFiles, my $refRemovedFiles ) =
1222 getModifiedFiles($filename_prod);
1223 my %changedfiles = %{$refChangedFiles};
1224 my %removedfiles = %{$refRemovedFiles};
1225
1226 if (%removedfiles) {
1227 my $removedFilesString =
1228 '"' . join( '" "', values(%removedfiles) ) . '"';
1229 my ( $rc, @out ) = run_command("$SVN rm $removedFilesString");
1230 if ( $rc > 0 ) {
1231 print join( "\n", @out );
1232 }
1233 }
1234
1235 # copy files one by one to local repository
1236 for my $file ( keys(%changedfiles) ) {
1237 copy_file_to_repository($file);
1238 }
1239
1240 # create new permissions file
1241 permissions();
1242
1243 # add permissions file
1244 add_helper($DASSCM_PERMISSION_FILE);
1245
1246 if ( $options{'message'} ) {
1247 $svnOptions .= " --message \"$options{'message'}\" ";
1248 }
1249
1250 # commit calls $EDITOR.
1251 # use "interactive" here, to display output
1252 my $retcode = run_interactive(
1253 "$SVN commit $svnOptions --username '$DASSCM_USERNAME' $svnPasswordCredentials $DASSCM_REPO"
1254 );
1255
1256 # svn commit does not deliever an error return code, if commit is canceld,
1257 # so a revert is performed in any case
1258 svn_revert();
1259}
1260
1261#
1262# revert: copies files back from repository to system
1263#
1264sub revert(@)
1265{
1266 check_parameter( @_, 1 );
1267 check_env();
1268
1269 (
1270 my $basename,
1271 my $dirname_prod,
1272 my $dirname_repo,
1273 my $filename_prod,
1274 my $filename_repo
1275 ) = get_filenames( $_[0] );
1276
1277 # return code for the shell
1278 # default: error
1279 my $return_code = $RETURN_OK;
1280
1281 # cleanup repository
1282 cleanup();
1283
1284 #svn_update();
1285
1286 ( my $refChangedFiles, my $refRemovedFiles, my $refUnknownFiles ) =
1287 getModifiedFiles($filename_prod);
1288 my %changedfiles = %{$refChangedFiles};
1289 my %removedfiles = %{$refRemovedFiles};
1290 my %unknownfiles = %{$refUnknownFiles};
1291
1292 if ( %removedfiles or %changedfiles or %unknownfiles ) {
1293
1294 if (%removedfiles) {
1295 print "DELETED files and directories. Recreated from repository:\n";
1296 my @removedPaths =
1297 ( sort { length $a > length $b } keys %removedfiles );
1298 print join( "\n", @removedPaths ) . "\n\n";
1299
1300 # copy files one by one from local repository to system
1301 # and also create directories
1302 # paths are sorted, so that directories are created first
1303 for my $real_path (@removedPaths) {
1304 if ( -d $removedfiles{"$real_path"} ) {
1305 mkpath("$real_path");
1306 } else {
1307 copy_file_from_repository_to_system($real_path);
1308 }
1309 }
1310 }
1311
1312 if (%changedfiles) {
1313 print "MODIFIED files. Copied from repository to the system:\n";
1314 print join( "\n", ( keys %changedfiles ) ) . "\n\n";
1315
1316 # copy files one by one from local repository to system
1317 for my $real_file ( keys(%changedfiles) ) {
1318 copy_file_from_repository_to_system($real_file);
1319 }
1320
1321 }
1322
1323 if (%unknownfiles) {
1324 print "UNKNOWN: insufficient permission to check files:\n";
1325 print join( "\n", ( keys %unknownfiles ) ) . "\n\n";
1326
1327 $return_code = $RETURN_NOK;
1328 }
1329
1330 } else {
1331 print "no modified files found in $dirname_repo\n";
1332 }
1333
1334 return $return_code;
1335}
1336
1337sub blame(@)
1338{
1339 check_parameter( @_, 1 );
1340 check_env();
1341
1342 (
1343 my $basename,
1344 my $dirname_prod,
1345 my $dirname_repo,
1346 my $filename_prod,
1347 my $filename_repo
1348 ) = get_filenames( $_[0] );
1349
1350 my $retcode = run_interactive("$SVN blame $svnOptions $filename_repo");
1351}
1352
1353sub diff(@)
1354{
1355 check_parameter( @_, 1 );
1356 check_env();
1357
1358 (
1359 my $basename,
1360 my $dirname_prod,
1361 my $dirname_repo,
1362 my $filename_prod,
1363 my $filename_repo
1364 ) = get_filenames( $_[0] );
1365
1366 #print "$basename,$dirname_prod,$dirname_repo\n";
1367
1368 svn_update();
1369
1370 ( my $rc_diff, my @diff_result ) =
1371 run_command( $diff . " $filename_repo $filename_prod" );
1372
1373 print @diff_result;
1374}
1375
1376sub status(@)
1377{
1378 check_parameter( @_, 1 );
1379 check_env();
1380
1381 (
1382 my $basename,
1383 my $dirname_prod,
1384 my $dirname_repo,
1385 my $filename_prod,
1386 my $filename_repo
1387 ) = get_filenames( $_[0] || "/" );
1388
1389 # return code for the shell
1390 # default: error
1391 my $return_code = $RETURN_NOK;
1392
1393 #
1394 # update local repository
1395 #
1396 #svn_update( $filename_prod );
1397
1398 # check, if permissions have changed
1399 permissions();
1400
1401 # get modified files
1402 ( my $refChangedFiles, my $refRemovedFiles, my $refUnknownFiles ) =
1403 getModifiedFiles($dirname_prod);
1404 my %changedfiles = %{$refChangedFiles};
1405 my %removedfiles = %{$refRemovedFiles};
1406 my %unknownfiles = %{$refUnknownFiles};
1407
1408 if ( %removedfiles or %changedfiles or %unknownfiles ) {
1409
1410 if (%removedfiles) {
1411 print "DELETED: files found in repository, but not in system:\n";
1412 print join( "\n", sort ( keys %removedfiles ) ) . "\n\n";
1413 }
1414
1415 if (%changedfiles) {
1416 print "MODIFIED: files differs between repository and system:\n";
1417 print join( "\n", ( keys %changedfiles ) ) . "\n\n";
1418 }
1419
1420 if (%unknownfiles) {
1421 print "UNKNOWN: insufficient permission to check files:\n";
1422 print join( "\n", ( keys %unknownfiles ) ) . "\n\n";
1423 }
1424
1425 } else {
1426 print "no modified files found in $dirname_repo\n";
1427 $return_code = $RETURN_OK;
1428 }
1429
1430 return $return_code;
1431}
1432
1433#
1434# return short status in Nagios plugin conform way
1435#
1436sub check()
1437{
1438 check_env();
1439
1440 # return code for the shell
1441 my $return_code = $RETURN_OK;
1442 my $return_string = "OK: no modified files";
1443
1444 # check, if permissions have changed
1445 permissions();
1446
1447 # get modified files
1448 ( my $refChangedFiles, my $refRemovedFiles, my $refUnknownFiles ) =
1449 getModifiedFiles("/");
1450 my %changedfiles = %{$refChangedFiles};
1451 my %removedfiles = %{$refRemovedFiles};
1452 my %unknownfiles = %{$refUnknownFiles};
1453
1454 if ( %removedfiles or %changedfiles ) {
1455 $return_string = "Warning: ";
1456 if (%changedfiles) {
1457 $return_string .=
1458 "changed: " . join( ", ", ( keys %changedfiles ) ) . ". ";
1459 }
1460 if (%removedfiles) {
1461 $return_string .=
1462 "removed: " . join( ", ", ( keys %removedfiles ) ) . ". ";
1463 }
1464 if (%unknownfiles) {
1465 $return_string .=
1466 "unknown: " . join( ", ", ( keys %unknownfiles ) ) . ". ";
1467 }
1468 $return_code = $RETURN_WARN;
1469 }
1470
1471 # addition nagios Service Status
1472 #Critical
1473 #Unknown
1474
1475 print "$return_string\n";
1476 return $return_code;
1477}
1478
1479sub permissions()
1480{
1481 check_env();
1482
1483 my $return_code = $RETURN_OK;
1484
1485 #
1486 # update local repository
1487 #
1488 #svn_update();
1489
1490 my $dir = $DASSCM_REPO;
1491 my @files = svn_ls("/");
1492
1493 if (@files) {
1494
1495 # generieren der Permissions
1496 my @permissions = generatePermissionList(@files);
1497 my $OUTFILE;
1498 my $tofile = 0; # Status für schreiben in File
1499
1500 if ( -w dirname($DASSCM_PERMISSION_FILE) ) {
1501
1502 # Verzeichnis existiert => schreiben
1503 open( OUTFILE, ">$DASSCM_PERMISSION_FILE" )
1504 || die("failed to write to $DASSCM_PERMISSION_FILE: $!");
1505 $tofile = 1; # Merken, daß in File geschrieben wird
1506 print OUTFILE "#\n";
1507 print OUTFILE "# created by dasscm permissions\n";
1508 print OUTFILE
1509 "# It is intended to be used for restoring permissions\n";
1510 print OUTFILE "#\n";
1511 } else {
1512
1513 if ( $command eq "permission" ) {
1514
1515 # Pfad für Sicherungsdatei existiert nicht => schreiben auf stdout
1516 # Alias Filehandle für stdout erzeugen
1517 $return_code = $RETURN_WARN;
1518 *OUTFILE = *STDOUT;
1519 } else {
1520
1521 # TODO: improve this. Check for diff?
1522 $return_code = $RETURN_CRIT;
1523 return $return_code;
1524 }
1525 }
1526
1527 foreach my $line (@permissions) {
1528 print OUTFILE "$line\n";
1529 }
1530
1531 if ($tofile) {
1532 close(OUTFILE);
1533 }
1534 }
1535
1536 return $return_code;
1537}
1538
1539#
1540# remove all uncommited changes in the repository
1541#
1542sub cleanup()
1543{
1544 check_env();
1545
1546 svn_revert($DASSCM_REPO);
1547 svn_remove_unknown_files($DASSCM_REPO);
1548}
1549
1550#
1551# used for bash completion
1552# prints the next possible command line parameters
1553#
1554sub complete(@)
1555{
1556 use Data::Dumper;
1557
1558 my $number_arguments = @_;
1559 my @input = @_;
1560
1561 if ( $number_arguments <= 1 ) {
1562
1563 # complete dasscm commands
1564 my $input = $input[0] || "";
1565 foreach my $i ( keys %COMMANDS ) {
1566 $_ = $i;
1567 if (m/^$input/) {
1568 my $command = get_command_uniform_name($i);
1569 print $command, "\n";
1570 }
1571 }
1572 } else {
1573
1574 # complete dasscm parameter
1575 my $command = get_command_uniform_name( $input[0] );
1576 my @params = get_command_possible_params( $input[0] );
1577 if ($verbose) { print "params: ", Dumper(@params); }
1578 if ( defined( $params[ $number_arguments - 2 ] )
1579 && $params[ $number_arguments - 2 ] )
1580 {
1581 my $param = $params[ $number_arguments - 2 ];
1582 if ( $param eq "PATH" ) {
1583 complete_path( $input[ $number_arguments - 1 ] );
1584 } elsif ( $param eq "REPOPATH" ) {
1585 complete_repopath( $input[ $number_arguments - 1 ] );
1586 } else {
1587 print "param: $param\n";
1588 print Dumper($param);
1589 }
1590 }
1591 }
1592}
1593
1594sub complete_path(@)
1595{
1596 check_parameter( @_, 1 );
1597 check_env();
1598
1599 (
1600 my $basename,
1601 my $dirname_prod,
1602 my $dirname_repo,
1603 my $filename_prod,
1604 my $filename_repo
1605 ) = get_filenames( $_[0] );
1606
1607 my @files = get_complete_path_globbing($filename_prod);
1608
1609 if (@files) {
1610 print join( "\n", @files );
1611 print "\n";
1612 }
1613}
1614
1615sub complete_repopath(@)
1616{
1617 check_parameter( @_, 1 );
1618 check_env();
1619
1620 (
1621 my $basename,
1622 my $dirname_prod,
1623 my $dirname_repo,
1624 my $filename_prod,
1625 my $filename_repo
1626 ) = get_filenames( $_[0] );
1627
1628 my @files = get_complete_path_globbing($filename_repo);
1629
1630 if (@files) {
1631
1632 # remove DASSCM_REPO path again
1633 print join(
1634 "\n",
1635 map( {
1636 s|^${DASSCM_REPO}|/|;
1637 $_
1638 } @files )
1639 );
1640 print "\n";
1641 }
1642
1643}
1644
1645#####################################################################
1646#
1647# main
1648#
1649
1650my $return_code = $RETURN_OK;
1651my $number_arguments = @ARGV;
1652
1653if ( $number_arguments > 0 ) {
1654
1655 # get subcommand and remove it from @ARGV
1656 $command = get_command_uniform_name( $ARGV[0] );
1657 shift @ARGV;
1658
1659 $DASSCM_LOCAL_REPOSITORY_BASE = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'};
1660 $DASSCM_REPOSITORY_NAME = $config->{'DASSCM_REPOSITORY_NAME'};
1661
1662 # TODO: check variables
1663 $DASSCM_SVN_REPOSITORY =
1664 $config->{'DASSCM_SVN_REPOSITORY_BASE'} . "/" . $DASSCM_REPOSITORY_NAME;
1665
1666 $DASSCM_CHECKOUT_USERNAME = $config->{'DASSCM_CHECKOUT_USERNAME'};
1667 $DASSCM_CHECKOUT_PASSWORD = $config->{'DASSCM_CHECKOUT_PASSWORD'};
1668
1669 #
1670 # if a user is given by dasscm configuration file, we use it.
1671 # Otherwise we expect that read-only account is configured
1672 # as local subversion configuration.
1673 # If this is also not the case,
1674 # user is required to type username and password.
1675 # This will be stored as local subversion configuration thereafter.
1676 #
1677 if ( $DASSCM_CHECKOUT_USERNAME && $DASSCM_CHECKOUT_PASSWORD ) {
1678 $svnCheckoutCredentials =
1679 " --username $DASSCM_CHECKOUT_USERNAME --password $DASSCM_CHECKOUT_PASSWORD ";
1680 }
1681
1682 $DASSCM_PERMISSION_FILE = $config->{'DASSCM_PERMISSION_FILE'}
1683 || "/etc/permissions.d/dasscm.permission_backup";
1684
1685 # get command line options and store them in options hash
1686 my $result = GetOptions( \%options, 'verbose', 'message=s' );
1687
1688 # print options
1689 foreach my $option ( keys %options ) {
1690 print "${option}: $options{$option}\n";
1691 }
1692
1693 # set verbose to command line option
1694 $verbose = $options{'verbose'};
1695
1696 #
1697 # action accordinly to command are taken
1698 # $command is rewritten in standard format,
1699 # so we can test for it later on more simply
1700 #
1701
1702 if ( get_command_function($command) ) {
1703 &{ get_command_function($command) }(@ARGV);
1704 } else {
1705 print "unknown command: $command\n\n";
1706 usage();
1707 check_env();
1708 $return_code = $RETURN_NOK;
1709 }
1710}
1711
1712exit $return_code;
Note: See TracBrowser for help on using the repository browser.