source: trunk/dasscm/dasscm@ 237

Last change on this file since 237 was 237, checked in by joergs, on Oct 8, 2008 at 8:49:03 PM

handle directories in add

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