source: trunk/dasscm/dasscm@ 238

Last change on this file since 238 was 238, checked in by joergs, on Oct 9, 2008 at 12:05:11 AM

cleanup

  • Property keyword set to id
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 22.9 KB
Line 
1#!/usr/bin/perl -w
2
3# $Id: dasscm 238 2008-10-08 22:05:11Z 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;
13use File::Copy;
14use File::Find;
15use File::stat;
16use File::Path;
17use Term::ReadKey;
18#use Data::Dumper;
19
20#####################################################################
21#
22# global
23#
24
25# file to store permissions
26my $permissions_file = "/etc/permissions.d/dasscm.permission_backup";
27
28# documentation file (for usage)
29my $doc_file = "/usr/share/doc/packages/dasscm/dasscm_howto.txt";
30
31# configuration file
32my $config_file = "/etc/dasscm.conf";
33my $config = get_config($config_file);
34my $DASSCM_LOCAL_REPOSITORY_BASE;
35my $DASSCM_REPOSITORY_NAME;
36my $DASSCM_SVN_REPOSITORY;
37
38# current directory at program start
39my $StartDirectory = cwd();
40
41my $SVN = "svn ";
42my $svnOptions = "";
43my $svnCheckoutCredentials = "";
44my $svnPasswordCredentials = "";
45my $diff = "diff --exclude .svn ";
46
47# command line options get stored in options hash
48my %options = ();
49
50# subcommand, that gets executed (add, commit, ...)
51my $command;
52
53my $verbose = 0;
54
55#####################################################################
56#
57# util functions
58#
59sub usage()
60{
61 print "usage: dasscm <subcommand> [options] [args]\n";
62 print "\n";
63 print "dasscm is intended to help versioning configuration files\n";
64 print "\n";
65 print "Available subcommands:\n";
66 print " help <subcommand>\n";
67 print " init\n";
68 print " login\n";
69 print " up\n";
70 print " ls\n";
71 print " add <filename>\n";
72 print " commit <filename>\n";
73 print " diff <filename>\n";
74 print " status\n";
75 print " permissions\n";
76 print "\n";
77 print "preparation:\n", " if dasscm is already configured,\n",
78 " use 'dasscm login' and then eg. 'add'.\n",
79 " The environment variables\n", " DASSCM_REPO\n", " DASSCM_PROD\n",
80 " DASSCM_USERNAME\n", " DASSCM_PASSWORD\n",
81 " are evaluated, but set automatically by 'dasscm login'.\n", "\n",
82 " If dasscm is not yet configured, read",
83 " $doc_file\n";
84}
85
86sub warning(@)
87{
88 print "Warning: " . join( "\n ", @_ ) . "\n";
89}
90
91sub error(@)
92{
93 print "Error: " . join( "\n ", @_ ) . "\n";
94}
95
96sub fatalerror(@)
97{
98 error( @_ );
99 #print "Exiting\n";
100 exit 1
101}
102
103
104#
105# reading config file and return key/value pairs as hash
106#
107sub get_config
108{
109 my $file = $_[0];
110
111 if( ! $file ) {
112 fatalerror( "failed to open config file" . $file );
113 }
114
115 my $data = {};
116
117 # try to open config file
118 if ( !open( FH, $file ) ) {
119 fatalerror( "failed to open config file" . $file );
120 } else {
121 while (<FH>) {
122 chomp;
123 if (/^#/) {
124 next;
125 }
126 if ( $_ =~ /=/g ) {
127 # splitting in 2 fields at maximum
128 my ( $option, $value ) = split( /=/, $_, 2 );
129 $option =~ s/^\s+//g;
130 $option =~ s/\s+$//g;
131 $option =~ s/\"+//g;
132 $value =~ s/^\s+//g;
133 $value =~ s/\s+$//g;
134 $value =~ s/\"+//g;
135
136 if ( length($option) ) {
137 $data->{$option} = $value;
138 }
139 }
140 }
141 }
142 close(FH);
143
144 return $data;
145}
146
147
148sub check_env()
149{
150
151 # DASSCM_PROD
152 if ( !$DASSCM_PROD ) {
153 $DASSCM_PROD = "/";
154 }
155
156 if ( !-d $DASSCM_PROD ) {
157 die "DASSCM_PROD ($DASSCM_PROD) is not set to a directory.\n";
158 }
159 if ($verbose) { print "DASSCM_PROD: " . $DASSCM_PROD . "\n"; }
160
161 # DASSCM_REPOSITORY_NAME
162 if ( !$DASSCM_REPOSITORY_NAME ) {
163 die
164 "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";
165 }
166
167 # DASSCM_REPO
168 if ( !$DASSCM_REPO ) {
169 if ( $DASSCM_LOCAL_REPOSITORY_BASE && $DASSCM_REPOSITORY_NAME ) {
170 $DASSCM_REPO =
171 $DASSCM_LOCAL_REPOSITORY_BASE . "/" . $DASSCM_REPOSITORY_NAME;
172 } else {
173 die
174 "Envirnonment variable DASSCM_REPO not set.\nSet DASSCM_REPO to the directory of the versioning system checkout for this machine.\n";
175 }
176 }
177 if ($verbose) { print "DASSCM_REPO: " . $DASSCM_REPO . "\n"; }
178
179 #
180 # check if local repository directory exist
181 # (if not creating by init)
182 #
183 if ( $command ne "init" ) {
184 if ( not -d $DASSCM_REPO ) {
185 die
186 "Can't access local repository DASSCM_REPO\n($DASSCM_REPO)\nCheck configuration and execute\n dasscm init\n";
187 }
188
189 #
190 # user settings
191 #
192
193 # DASSCM_USER is legacy. Use DASSCM_USERNAME instead
194 if ( !$DASSCM_USERNAME ) {
195 $DASSCM_USERNAME = $DASSCM_USER;
196 }
197
198 # user root is not allowed for checkins.
199 # if user is root, DASSCM_USER has to be set,
200 # otherwise USER can be used
201 if ( "$USER" eq "root" ) {
202 if ( ( not $DASSCM_USERNAME ) and ( $command ne "login" ) ) {
203 die
204 "Envirnonment variable DASSCM_USERNAME not set.\nSet DASSCM_USERNAME to your subversion user account.\n";
205 }
206 $svnOptions .= " --no-auth-cache ";
207 } elsif ( !$DASSCM_USERNAME ) {
208 $DASSCM_USERNAME = $USER;
209 }
210
211 #
212 # password
213 #
214 if ($DASSCM_PASSWORD) {
215 $svnPasswordCredentials = " --password $DASSCM_PASSWORD ";
216 }
217 }
218
219 #$svnOptions .= " --username $DASSCM_USERNAME "
220}
221
222sub check_parameter(@)
223{
224}
225
226
227#
228# generate from (relative) filename
229# all required file and directory names:
230# $basename, $dirname_prod, $dirname_repo,
231# $filename_prod, $filename_repo
232#
233sub get_filenames(@)
234{
235 my $filename_prod = $_[0];
236
237 # make filename absolut
238 if ( !( $filename_prod =~ m/^\// ) ) {
239 $filename_prod = cwd() . "/" . $filename_prod;
240 }
241
242 if( not -r $filename_prod ) {
243 fatalerror( $filename_prod . " is not accessable" );
244 }
245
246 # TODO: dirname buggy: eg. "/etc/" is reduced to "/",
247 # "/etc" is used as filename
248 my $dirname_prod = dirname($filename_prod);
249
250 # uses chdir to determine real directory in a unique way
251 chdir $dirname_prod or die $!;
252 $dirname_prod = cwd();
253 chdir $StartDirectory;
254
255 my $basename = basename($filename_prod);
256
257 if ($verbose) {
258 print "dir: " . $dirname_prod . "\n";
259 print "fn: " . $basename . "\n";
260 }
261
262 my $dirname_repo = $DASSCM_REPO . "/" . $dirname_prod;
263 my $filename_repo = "$dirname_repo/$basename";
264
265 return (
266 $basename, $dirname_prod, $dirname_repo,
267 $filename_prod, $filename_repo
268 );
269}
270
271sub generatePermissionList
272{
273
274 # generieren der Zeilen für Permission-Savefile
275 my @files = @_;
276 my @permlist = ();
277 foreach my $file (@files) {
278 $file = "/" . $file;
279 if( -e $file ) {
280 my $info = stat( $file ) || die "failed to stat $file: aborting";
281 my $mode = get_type( $info->mode ) & 07777;
282 my $modestring = sprintf( "%04o", $mode );
283 my $uid = $info->uid;
284 my $uidname = getpwuid($uid);
285 my $gid = $info->gid;
286 my $gidname = getgrgid($gid);
287 push(
288 @permlist,
289 sprintf( "%-55s %-17s %4d",
290 $file, "${uidname}:${gidname}", $modestring )
291 );
292 } else {
293 print "failed to get status of $file. It exists in the repository, but not on the system\n";
294 }
295 }
296 return @permlist;
297}
298
299sub get_type
300{
301
302 # Funktion übernommen aus /usr/bin/chkstat
303 my $S_IFLNK = 0120000; # symbolic link
304 my $S_IFREG = 0100000; # regular file
305 my $S_IFDIR = 0040000; # directory
306 my $S_IFCHAR = 0020000; # character device
307 my $S_IFBLK = 0060000; # block device
308 my $S_IFFIFO = 0010000; # fifo
309 my $S_IFSOCK = 0140000; # socket
310 my $S_IFMT = 0170000; # type of file
311
312 my $S_m;
313 if ( ( $_[0] & $S_IFMT ) == $S_IFLNK ) { $S_m = $_[0] - $S_IFLNK; }
314 elsif ( ( $_[0] & $S_IFMT ) == $S_IFREG ) { $S_m = $_[0] - $S_IFREG; }
315 elsif ( ( $_[0] & $S_IFMT ) == $S_IFDIR ) { $S_m = $_[0] - $S_IFDIR; }
316 elsif ( ( $_[0] & $S_IFMT ) == $S_IFCHAR ) { $S_m = $_[0] - $S_IFCHAR; }
317 elsif ( ( $_[0] & $S_IFMT ) == $S_IFBLK ) { $S_m = $_[0] - $S_IFBLK; }
318 elsif ( ( $_[0] & $S_IFMT ) == $S_IFFIFO ) { $S_m = $_[0] - $S_IFFIFO; }
319 elsif ( ( $_[0] & $S_IFMT ) == $S_IFSOCK ) { $S_m = $_[0] - $S_IFSOCK; }
320 $S_m;
321}
322
323sub run_command
324{
325 my $command = shift;
326
327 #print "executing command: " . $command . "\n";
328
329 open( RESULT, $command . ' 2>&1 |' );
330 my @result = <RESULT>;
331 close(RESULT);
332 my $retcode = $? >> 8;
333
334 #print @result;
335 #if( $retcode ) { print "return code: " . $retcode . "\n"; }
336
337 return ( $retcode, @result );
338}
339
340sub run_interactive
341{
342
343 if ($verbose) {
344 print "run_interactive:" . join( " ", @_ ) . "\n";
345 }
346
347 system(@_);
348 if ( $? == -1 ) {
349 printf "failed to execute: $!\n";
350 } elsif ( $? & 127 ) {
351 printf "child died with signal %d, %s coredump\n", ( $? & 127 ),
352 ( $? & 128 ) ? 'with' : 'without';
353 } elsif ( $? >> 8 != 0 ) {
354 printf "child exited with value %d\n", $? >> 8;
355 }
356 return ( $? >> 8 );
357}
358
359sub svn_check_credentials( $$ )
360{
361 my $username = shift;
362 my $password = shift;
363
364 print "checking credentials ... ";
365
366 if( ! $username ) {
367 fatalerror( "no username given" );
368 }
369
370 if( ! $password ) {
371 fatalerror( "no password given" );
372 }
373
374 # Options for "svn info" are not supported by subversion 1.0.0 (SLES9),
375 # therefore switching to "svn status"
376 # ( my $rc_update, my @result ) =
377 # run_command(
378 # "$SVN info --non-interactive --no-auth-cache --username $username --password $password $DASSCM_SVN_REPOSITORY"
379 # );
380 #print @result;
381
382 ( my $rc_update, my @result ) =
383 run_command(
384 "$SVN ls --non-interactive --no-auth-cache --username $username --password $password $DASSCM_SVN_REPOSITORY"
385 );
386
387 if ( $rc_update != 0 ) {
388 print "\n", @result;
389 fatalerror();
390 }
391
392}
393
394sub svn_update( ;$ )
395{
396 my $update_path = shift || $DASSCM_REPO;
397 ( my $rc_update, my @result ) =
398 run_command(
399 "$SVN update --non-interactive $svnCheckoutCredentials $update_path");
400 print @result;
401 if ( $rc_update != 0 ) {
402 fatalerror();
403 }
404}
405
406sub svn_getStoredFiles( ;$ )
407{
408
409 # TODO: get_filenames?
410 #my $rel_path = shift || "";
411 #my $path = "${DASSCM_REPO}/${rel_path}";
412 my $path = ${DASSCM_REPO};
413
414 # svn ls -R is better, but much, much slower
415 # ( my $rc, my @result ) = run_command("$SVN ls --recursive $svnCheckoutCredentials $path");
416 ( my $rc, my @result ) =
417 run_command(
418 "cd $path && find | grep -v '/.svn' | sed -e 's/\.\\///' | grep -v '^\$'"
419 );
420 if ( $rc != 0 ) {
421 print @result;
422 fatalerror;
423 }
424 chomp(@result);
425 return @result;
426}
427
428
429#
430# from an array of files/dirs,
431# generates list of files
432# sorted by type
433#
434sub get_files( @ )
435{
436 my @files = ();
437 my @links = ();
438 my @dirs = ();
439 my @others = ();
440
441 if( @_ ) {
442 find( { wanted => sub {
443 my $fullname = cwd() . "/" . $_;
444 if ( -l $_ ) {
445 # soft link
446 # important: check for links first
447 # to exclude them from further checks
448 push( @links, $fullname );
449 } elsif ( -d $_ ) {
450 push( @dirs, $fullname );
451 } elsif( -f $_ ) {
452 # regular file
453 push( @files, $fullname );
454 } else {
455 push( @others, $fullname );
456 }
457 } }, @_ );
458 }
459
460 # don't rely on others.
461 # If more specific file types are needed,
462 # they will be added
463 return {
464 files => \@files,
465 links => \@links,
466 dirs => \@dirs,
467 others => \@others
468 };
469}
470
471
472
473#####################################################################
474#
475# functions
476
477sub help(;@)
478{
479 if ( @_ == 0 ) {
480 usage();
481 } else {
482 print "help for @_: ...\n";
483 usage();
484 }
485}
486
487sub login(@)
488{
489 check_parameter( @_, 1 );
490 check_env();
491
492 my $input_username = $_[0];
493
494 if ( not $input_username ) {
495 my $output_username = "";
496 if ($DASSCM_USERNAME) {
497 $output_username = " ($DASSCM_USERNAME)";
498 }
499
500 print "Enter DASSCM user name", $output_username, ": ";
501 $input_username = <STDIN>;
502 chomp($input_username);
503 }
504
505 # hidden password input
506 print "Enter DASSCM user password: ";
507 ReadMode('noecho');
508 my $input_password = <STDIN>;
509 ReadMode('normal');
510 chomp($input_password);
511 print "\n";
512
513 svn_check_credentials( $input_username || $DASSCM_USERNAME, $input_password );
514
515 #
516 # set environment variables
517 #
518 $ENV{'DASSCM_USERNAME'} = $input_username;
519 $ENV{'DASSCM_PASSWORD'} = $input_password;
520
521 print "subversion access okay\n\n", "DASSCM_USERNAME: $input_username\n",
522 "DASSCM_PASSWORD: (hidden)\n", "DASSCM_PROD: $DASSCM_PROD\n",
523 "DASSCM_REPO: $DASSCM_REPO\n",
524 "Server Repository: $DASSCM_SVN_REPOSITORY\n", "\n", "[dasscm shell]\n\n";
525
526 my $shell = $SHELL || "bash";
527 exec($shell) or die "failed to start new shell";
528}
529
530sub init(@)
531{
532 check_parameter( @_, 1 );
533 check_env();
534
535 # don't do repository creation (svn mkdir) here,
536 # because then their must be a lot of prior checks
537
538 # update complete repository
539 # and create permission file
540 my $retcode =
541 run_interactive(
542 "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY; touch $permissions_file"
543 );
544}
545
546sub ls(@)
547{
548 check_parameter( @_, 1 );
549 check_env();
550
551 my @files = svn_getStoredFiles(@_);
552
553 print join( "\n", @files );
554 print "\n";
555}
556
557sub update(@)
558{
559 check_parameter( @_, 1 );
560 check_env();
561
562 #
563 # update local repository
564 #
565 svn_update();
566}
567
568
569
570#
571# helper function for "add" command
572#
573sub add_helper(@)
574{
575 (
576 my $basename,
577 my $dirname_prod,
578 my $dirname_repo,
579 my $filename_prod,
580 my $filename_repo
581 )
582 = get_filenames( $_[0] );
583
584 if ( $command eq "add" ) {
585 mkpath($dirname_repo);
586 }
587
588 # TODO: are permissions also copied?
589 copy( $filename_prod, $filename_repo ) or error "failed to copy $filename_prod to repository: $!";
590
591 if ( $command eq "add" ) {
592
593 # already checked in?
594 chdir $DASSCM_REPO;
595
596 # also add the path to filename.
597 for my $dir ( split( '/', $dirname_prod ) ) {
598 if ($dir) {
599 my( $rc, @out ) = run_command("$SVN add --non-recursive \"" . $dir . "\"" );
600 if( $rc > 0 ) {
601 print join( "\n", @out );
602 }
603 chdir $dir;
604 }
605 }
606 my( $rc, @out ) = run_command("$SVN add \"" . $basename . "\"");
607 if( $rc > 0 ) {
608 print join( "\n", @out );
609 }
610 chdir $StartDirectory;
611 }
612}
613
614
615#
616# add (is used for command add and commit)
617#
618sub add(@)
619{
620 check_parameter( @_, 1 );
621 check_env();
622
623 #
624 # update local repository
625 #
626 svn_update();
627
628 # get all regular files and links
629 my $href_files = get_files( @_ );
630
631 #print Dumper( $href_files );
632
633 my @files = @{$href_files->{files}};
634 my @links = @{$href_files->{links}};
635
636 if( @files ) {
637 my $number = $#files + 1;
638 print "files to check-in ($number): \n";
639 print join( "\n", @files );
640 print "\n";
641 }
642
643 if( @links ) {
644 my $number = $#links + 1;
645 print "\n";
646 print "ignoring links ($number):\n";
647 print join( "\n", @links );
648 print "\n";
649 }
650
651 # TODO: confirm
652
653 # copy files one by one to local repository
654 for my $file (@files) {
655 # add file
656 add_helper( $file );
657 }
658
659 # create new permissions file
660 permissions();
661
662 # add permissions file
663 add_helper($permissions_file);
664
665 if ( $options{'message'} ) {
666 $svnOptions .= " --message \"$options{'message'}\" ";
667 }
668
669 # commit calls $EDITOR.
670 # use "interactive" here, to display output
671 my $retcode =
672 run_interactive(
673 "$SVN commit $svnOptions --username $DASSCM_USERNAME $svnPasswordCredentials $DASSCM_REPO"
674 );
675
676 #print $filename_prod. "\n";
677 #print $dirname_repo. "\n";
678}
679
680sub blame(@)
681{
682 check_parameter( @_, 1 );
683 check_env();
684
685 (
686 my $basename,
687 my $dirname_prod,
688 my $dirname_repo,
689 my $filename_prod,
690 my $filename_repo
691 )
692 = get_filenames( $_[0] );
693
694 my $retcode = run_interactive("$SVN blame $svnOptions $filename_repo");
695}
696
697sub diff(@)
698{
699 check_parameter( @_, 1 );
700 check_env();
701
702 (
703 my $basename,
704 my $dirname_prod,
705 my $dirname_repo,
706 my $filename_prod,
707 my $filename_repo
708 )
709 = get_filenames( $_[0] );
710
711 #print "$basename,$dirname_prod,$dirname_repo\n";
712
713 ( my $rc_update, my @result ) = run_command("$SVN update $filename_repo");
714 if ( $rc_update != 0 ) {
715 print @result;
716 die;
717 }
718
719 ( my $rc_diff, my @diff_result ) =
720 run_command( $diff . " $filename_repo $filename_prod");
721
722 print @diff_result;
723}
724
725sub status(@)
726{
727 check_parameter( @_, 1 );
728 check_env();
729
730 #
731 # update local repository
732 #
733 svn_update();
734
735 # TODO: start at subdirectories ?
736 my $dir = $DASSCM_REPO;
737 my @files = svn_getStoredFiles($dir);
738
739 # Liste der geänderten Files ausgeben, falls nicht leer
740 if (@files) {
741
742 # stores result from status (cvscheck)
743 my %removedfiles = ();
744 my %changedfiles = ();
745
746 foreach my $file (@files) {
747
748 my $realfile = "/" . $file;
749 my $cvsworkfile = "${DASSCM_REPO}/${file}";
750
751 if ( -d $realfile ) {
752
753 # directory. do nothing
754 } elsif ( !-r $realfile ) {
755 $removedfiles{"$realfile"} = $cvsworkfile;
756 } else {
757 ( -r "$cvsworkfile" )
758 || die("Fehler: $cvsworkfile ist nicht lesbar");
759 if ( compare( $cvsworkfile, $realfile ) != 0 ) {
760 $changedfiles{"$realfile"} = $cvsworkfile;
761 }
762 }
763 }
764
765 if (%removedfiles) {
766 print "deleted files (found in repository, but not in system):\n";
767 foreach my $key ( values %removedfiles ) {
768 print "$key\n";
769 }
770 print "\n";
771 }
772
773 if (%changedfiles) {
774 print "modified files:\n";
775 foreach my $key ( keys %changedfiles ) {
776 print "$key\n";
777 }
778 }
779 } else {
780 print "no modified files found in $dir\n";
781 }
782
783 print "\n";
784}
785
786sub permissions(@)
787{
788 check_parameter( @_, 1 );
789 check_env();
790
791 #
792 # update local repository
793 #
794 #svn_update();
795
796 # TODO: start at subdirectories ?
797 my $dir = $DASSCM_REPO;
798 my @files = svn_getStoredFiles($dir);
799
800 if (@files) {
801
802 # generieren der Permissions
803 my @permissions = generatePermissionList(@files);
804 my $OUTFILE;
805 my $tofile = 0; # Status für schreiben in File
806
807 if ( -w dirname($permissions_file) ) {
808
809 # Verzeichnis existiert => schreiben
810 print "storing permissions in file $permissions_file\n";
811 open( OUTFILE, ">$permissions_file" )
812 || die("failed to write to $permissions_file: $!");
813 $tofile = 1; # Merken, daß in File geschrieben wird
814 print OUTFILE "#\n";
815 print OUTFILE "# created by dasscm permissions\n";
816 print OUTFILE
817 "# It is intended to be used for restoring permissions\n";
818 } else {
819
820 # Pfad für Sicherungsdatei existiert nicht => schreiben auf stdout
821 # Alias Filehandle für stdout erzeugen
822 *OUTFILE = *STDOUT;
823 }
824 foreach my $line (@permissions) {
825 print OUTFILE "$line\n";
826 }
827
828 if ($tofile) {
829 close(OUTFILE);
830 }
831 }
832}
833
834#####################################################################
835#
836# main
837#
838
839my $number_arguments = @ARGV;
840
841if ( $number_arguments > 0 ) {
842
843 # get subcommand and remove it from @ARGV
844 $command = $ARGV[0];
845 shift @ARGV;
846
847 $DASSCM_LOCAL_REPOSITORY_BASE = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'};
848 $DASSCM_REPOSITORY_NAME = $config->{'DASSCM_REPOSITORY_NAME'};
849
850 # TODO: check variables
851 $DASSCM_SVN_REPOSITORY =
852 $config->{'DASSCM_SVN_REPOSITORY_BASE'} . "/" . $DASSCM_REPOSITORY_NAME;
853
854 my $DASSCM_CHECKOUT_USERNAME = $config->{'DASSCM_CHECKOUT_USERNAME'};
855 my $DASSCM_CHECKOUT_PASSWORD = $config->{'DASSCM_CHECKOUT_PASSWORD'};
856
857 #
858 # if a user is given by dasscm configuration file, we use it.
859 # Otherwise we expect that read-only account is configured
860 # as local subversion configuration.
861 # If this is also not the case,
862 # user is required to type username and password.
863 # This will be stored as local subversion configuration thereafter.
864 #
865 if ( $DASSCM_CHECKOUT_USERNAME && $DASSCM_CHECKOUT_PASSWORD ) {
866 $svnCheckoutCredentials =
867 " --username $DASSCM_CHECKOUT_USERNAME --password $DASSCM_CHECKOUT_PASSWORD ";
868 }
869
870 # get command line options and store them in options hash
871 my $result = GetOptions( \%options, 'verbose', 'message=s' );
872
873 # print options
874 foreach my $option ( keys %options ) {
875 print "${option}: $options{$option}\n";
876 }
877
878 # set verbose to command line option
879 $verbose = $options{'verbose'};
880
881 #
882 # action accordinly to command are taken
883 # $command is rewritten in standard format,
884 # so we can test for it later on more simply
885 #
886 $_ = $command;
887 if (m/help/i) {
888 help(@ARGV);
889 } elsif (m/login/i) {
890 $command = "login";
891 login(@ARGV);
892 } elsif (m/init/i) {
893 $command = "init";
894 init(@ARGV);
895 } elsif (m/ls/i) {
896 $command = "ls";
897 ls(@ARGV);
898 } elsif ( (m/update/i) || (m/up/i) ) {
899 $command = "update";
900 update(@ARGV);
901 } elsif (m/add/i) {
902 $command = "add";
903 add(@ARGV);
904 } elsif (m/commit/i) {
905 $command = "commit";
906 add(@ARGV);
907 } elsif (m/blame/i) {
908 $command = "blame";
909 blame(@ARGV);
910 } elsif (m/diff/i) {
911 $command = "diff";
912 diff(@ARGV);
913 } elsif ( (m/status/i) || (m/st/i) ) {
914 $command = "status";
915 status(@ARGV);
916 } elsif (m/permissions/i) {
917 $command = "permissions";
918 permissions(@ARGV);
919 } else {
920 print "unknown command: $command\n\n";
921 usage();
922 check_env();
923 }
924
925 # cleanup (svn-commit.tmp)
926 # commitall
927 # revert
928 # activate
929 # rm
930}
Note: See TracBrowser for help on using the repository browser.