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

Last change on this file since 889 was 889, checked in by joergs, on Jun 26, 2010 at 12:19:34 AM

perltidy

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