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
RevLine 
[186]1#!/usr/bin/perl -w
2
3# $Id: dasscm 238 2008-10-08 22:05:11Z joergs $
4
5use strict;
6
[208]7use Env
[235]8 qw($DASSCM_PROD $DASSCM_REPO $USER $DASSCM_USERNAME $DASSCM_USER $DASSCM_PASSWORD $SHELL);
[186]9use Cwd;
[214]10use Getopt::Long;
[186]11use File::Basename;
[209]12use File::Compare;
13use File::Copy;
[237]14use File::Find;
[186]15use File::stat;
16use File::Path;
[214]17use Term::ReadKey;
[234]18#use Data::Dumper;
[186]19
[189]20#####################################################################
21#
[186]22# global
[189]23#
[205]24
[215]25# file to store permissions
26my $permissions_file = "/etc/permissions.d/dasscm.permission_backup";
[220]27
[238]28# documentation file (for usage)
29my $doc_file = "/usr/share/doc/packages/dasscm/dasscm_howto.txt";
30
[215]31# configuration file
[205]32my $config_file = "/etc/dasscm.conf";
[234]33my $config = get_config($config_file);
[205]34my $DASSCM_LOCAL_REPOSITORY_BASE;
35my $DASSCM_REPOSITORY_NAME;
36my $DASSCM_SVN_REPOSITORY;
37
[238]38# current directory at program start
39my $StartDirectory = cwd();
40
[205]41my $SVN = "svn ";
42my $svnOptions = "";
43my $svnCheckoutCredentials = "";
44my $svnPasswordCredentials = "";
[238]45my $diff = "diff --exclude .svn ";
[205]46
[196]47# command line options get stored in options hash
[205]48my %options = ();
49
[197]50# subcommand, that gets executed (add, commit, ...)
[196]51my $command;
[186]52
[205]53my $verbose = 0;
54
[189]55#####################################################################
56#
[186]57# util functions
[189]58#
[187]59sub usage()
60{
[205]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";
[215]66 print " help <subcommand>\n";
[205]67 print " init\n";
68 print " login\n";
[215]69 print " up\n";
70 print " ls\n";
[205]71 print " add <filename>\n";
72 print " commit <filename>\n";
73 print " diff <filename>\n";
[236]74 print " status\n";
[215]75 print " permissions\n";
[205]76 print "\n";
[238]77 print "preparation:\n", " if dasscm is already configured,\n",
[236]78 " use 'dasscm login' and then eg. 'add'.\n",
[220]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",
[238]83 " $doc_file\n";
[187]84}
85
[233]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
[238]103
104#
105# reading config file and return key/value pairs as hash
106#
[234]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 ) {
[238]127 # splitting in 2 fields at maximum
[234]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
[186]148sub check_env()
149{
[205]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
[208]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 }
[205]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 }
[215]177 if ($verbose) { print "DASSCM_REPO: " . $DASSCM_REPO . "\n"; }
[205]178
179 #
[235]180 # check if local repository directory exist
181 # (if not creating by init)
[205]182 #
183 if ( $command ne "init" ) {
184 if ( not -d $DASSCM_REPO ) {
185 die
[208]186 "Can't access local repository DASSCM_REPO\n($DASSCM_REPO)\nCheck configuration and execute\n dasscm init\n";
[205]187 }
[208]188
[205]189 #
190 # user settings
191 #
[208]192
[205]193 # DASSCM_USER is legacy. Use DASSCM_USERNAME instead
[208]194 if ( !$DASSCM_USERNAME ) {
195 $DASSCM_USERNAME = $DASSCM_USER;
[205]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" ) {
[208]202 if ( ( not $DASSCM_USERNAME ) and ( $command ne "login" ) ) {
[205]203 die
[208]204 "Envirnonment variable DASSCM_USERNAME not set.\nSet DASSCM_USERNAME to your subversion user account.\n";
[205]205 }
206 $svnOptions .= " --no-auth-cache ";
207 } elsif ( !$DASSCM_USERNAME ) {
208 $DASSCM_USERNAME = $USER;
209 }
210
211 #
212 # password
213 #
[208]214 if ($DASSCM_PASSWORD) {
[205]215 $svnPasswordCredentials = " --password $DASSCM_PASSWORD ";
216 }
217 }
218
219 #$svnOptions .= " --username $DASSCM_USERNAME "
[186]220}
221
222sub check_parameter(@)
223{
224}
225
[238]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#
[187]233sub get_filenames(@)
234{
[205]235 my $filename_prod = $_[0];
[237]236
[238]237 # make filename absolut
[205]238 if ( !( $filename_prod =~ m/^\// ) ) {
239 $filename_prod = cwd() . "/" . $filename_prod;
240 }
[187]241
[233]242 if( not -r $filename_prod ) {
243 fatalerror( $filename_prod . " is not accessable" );
244 }
[205]245
246 # TODO: dirname buggy: eg. "/etc/" is reduced to "/",
247 # "/etc" is used as filename
248 my $dirname_prod = dirname($filename_prod);
[238]249
250 # uses chdir to determine real directory in a unique way
[205]251 chdir $dirname_prod or die $!;
252 $dirname_prod = cwd();
[238]253 chdir $StartDirectory;
254
[205]255 my $basename = basename($filename_prod);
256
[214]257 if ($verbose) {
258 print "dir: " . $dirname_prod . "\n";
259 print "fn: " . $basename . "\n";
260 }
[205]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 );
[187]269}
270
[215]271sub generatePermissionList
[209]272{
273
[215]274 # generieren der Zeilen für Permission-Savefile
275 my @files = @_;
276 my @permlist = ();
277 foreach my $file (@files) {
[227]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 }
[215]295 }
296 return @permlist;
297}
[209]298
[215]299sub get_type
300{
[209]301
[215]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
[209]311
[215]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;
[209]321}
322
[186]323sub run_command
324{
[205]325 my $command = shift;
[186]326
[205]327 #print "executing command: " . $command . "\n";
[186]328
[205]329 open( RESULT, $command . ' 2>&1 |' );
330 my @result = <RESULT>;
331 close(RESULT);
332 my $retcode = $? >> 8;
[186]333
[205]334 #print @result;
335 #if( $retcode ) { print "return code: " . $retcode . "\n"; }
[186]336
[205]337 return ( $retcode, @result );
[186]338}
339
[205]340sub run_interactive
341{
[186]342
[208]343 if ($verbose) {
[205]344 print "run_interactive:" . join( " ", @_ ) . "\n";
345 }
[196]346
[205]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( $$ )
[196]360{
[205]361 my $username = shift;
362 my $password = shift;
363
[220]364 print "checking credentials ... ";
365
[238]366 if( ! $username ) {
367 fatalerror( "no username given" );
368 }
369
370 if( ! $password ) {
371 fatalerror( "no password given" );
372 }
373
[220]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
[205]382 ( my $rc_update, my @result ) =
383 run_command(
[220]384 "$SVN ls --non-interactive --no-auth-cache --username $username --password $password $DASSCM_SVN_REPOSITORY"
[205]385 );
386
387 if ( $rc_update != 0 ) {
[238]388 print "\n", @result;
389 fatalerror();
[205]390 }
391
[196]392}
393
[205]394sub svn_update( ;$ )
395{
396 my $update_path = shift || $DASSCM_REPO;
397 ( my $rc_update, my @result ) =
[220]398 run_command(
399 "$SVN update --non-interactive $svnCheckoutCredentials $update_path");
[215]400 print @result;
[205]401 if ( $rc_update != 0 ) {
[238]402 fatalerror();
[205]403 }
[215]404}
[196]405
[215]406sub svn_getStoredFiles( ;$ )
407{
[220]408
[215]409 # TODO: get_filenames?
410 #my $rel_path = shift || "";
411 #my $path = "${DASSCM_REPO}/${rel_path}";
412 my $path = ${DASSCM_REPO};
[220]413
[218]414 # svn ls -R is better, but much, much slower
415 # ( my $rc, my @result ) = run_command("$SVN ls --recursive $svnCheckoutCredentials $path");
[220]416 ( my $rc, my @result ) =
417 run_command(
418 "cd $path && find | grep -v '/.svn' | sed -e 's/\.\\///' | grep -v '^\$'"
419 );
[215]420 if ( $rc != 0 ) {
421 print @result;
[238]422 fatalerror;
[215]423 }
424 chomp(@result);
425 return @result;
[205]426}
427
[237]428
[238]429#
430# from an array of files/dirs,
431# generates list of files
432# sorted by type
433#
[237]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
[189]473#####################################################################
474#
[186]475# functions
476
477sub help(;@)
478{
[205]479 if ( @_ == 0 ) {
480 usage();
481 } else {
482 print "help for @_: ...\n";
[214]483 usage();
[205]484 }
[186]485}
486
[203]487sub login(@)
488{
[205]489 check_parameter( @_, 1 );
490 check_env();
[203]491
[235]492 my $input_username = $_[0];
[214]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);
[205]503 }
[203]504
[205]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);
[220]511 print "\n";
[203]512
[238]513 svn_check_credentials( $input_username || $DASSCM_USERNAME, $input_password );
[205]514
515 #
516 # set environment variables
517 #
518 $ENV{'DASSCM_USERNAME'} = $input_username;
519 $ENV{'DASSCM_PASSWORD'} = $input_password;
520
[209]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";
[205]525
[235]526 my $shell = $SHELL || "bash";
527 exec($shell) or die "failed to start new shell";
[203]528}
529
[205]530sub init(@)
531{
532 check_parameter( @_, 1 );
533 check_env();
534
[235]535 # don't do repository creation (svn mkdir) here,
536 # because then their must be a lot of prior checks
537
[205]538 # update complete repository
[216]539 # and create permission file
[208]540 my $retcode =
541 run_interactive(
[225]542 "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY; touch $permissions_file"
[208]543 );
[205]544}
545
[215]546sub ls(@)
[186]547{
[205]548 check_parameter( @_, 1 );
549 check_env();
[186]550
[215]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
[237]568
569
570#
571# helper function for "add" command
572#
[215]573sub add_helper(@)
574{
[205]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] );
[186]583
[205]584 if ( $command eq "add" ) {
585 mkpath($dirname_repo);
586 }
[186]587
[238]588 # TODO: are permissions also copied?
[237]589 copy( $filename_prod, $filename_repo ) or error "failed to copy $filename_prod to repository: $!";
[205]590
591 if ( $command eq "add" ) {
592
593 # already checked in?
[238]594 chdir $DASSCM_REPO;
[205]595
596 # also add the path to filename.
597 for my $dir ( split( '/', $dirname_prod ) ) {
598 if ($dir) {
[226]599 my( $rc, @out ) = run_command("$SVN add --non-recursive \"" . $dir . "\"" );
600 if( $rc > 0 ) {
601 print join( "\n", @out );
602 }
[205]603 chdir $dir;
604 }
605 }
[226]606 my( $rc, @out ) = run_command("$SVN add \"" . $basename . "\"");
607 if( $rc > 0 ) {
608 print join( "\n", @out );
609 }
[238]610 chdir $StartDirectory;
[205]611 }
[215]612}
[205]613
[237]614
[215]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
[237]628 # get all regular files and links
629 my $href_files = get_files( @_ );
[220]630
[237]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
[238]651 # TODO: confirm
652
[237]653 # copy files one by one to local repository
654 for my $file (@files) {
[233]655 # add file
656 add_helper( $file );
657 }
658
[215]659 # create new permissions file
660 permissions();
[220]661
[215]662 # add permissions file
[220]663 add_helper($permissions_file);
[215]664
[205]665 if ( $options{'message'} ) {
666 $svnOptions .= " --message \"$options{'message'}\" ";
667 }
668
[237]669 # commit calls $EDITOR.
670 # use "interactive" here, to display output
[215]671 my $retcode =
[205]672 run_interactive(
[208]673 "$SVN commit $svnOptions --username $DASSCM_USERNAME $svnPasswordCredentials $DASSCM_REPO"
674 );
[205]675
[215]676 #print $filename_prod. "\n";
677 #print $dirname_repo. "\n";
[186]678}
679
[193]680sub blame(@)
681{
[205]682 check_parameter( @_, 1 );
683 check_env();
[193]684
[205]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");
[193]695}
696
[187]697sub diff(@)
698{
[205]699 check_parameter( @_, 1 );
700 check_env();
[187]701
[205]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
[238]719 ( my $rc_diff, my @diff_result ) =
720 run_command( $diff . " $filename_repo $filename_prod");
721
722 print @diff_result;
[187]723}
724
[209]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 ?
[220]736 my $dir = $DASSCM_REPO;
[215]737 my @files = svn_getStoredFiles($dir);
[209]738
739 # Liste der geänderten Files ausgeben, falls nicht leer
[215]740 if (@files) {
[209]741
[215]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 ) {
[209]768 print "$key\n";
769 }
770 print "\n";
771 }
772
[215]773 if (%changedfiles) {
[209]774 print "modified files:\n";
[215]775 foreach my $key ( keys %changedfiles ) {
[209]776 print "$key\n";
777 }
778 }
779 } else {
[215]780 print "no modified files found in $dir\n";
[209]781 }
[215]782
[209]783 print "\n";
[215]784}
[209]785
[215]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 ?
[220]797 my $dir = $DASSCM_REPO;
[215]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
[220]806
[215]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" )
[216]812 || die("failed to write to $permissions_file: $!");
[215]813 $tofile = 1; # Merken, daß in File geschrieben wird
814 print OUTFILE "#\n";
815 print OUTFILE "# created by dasscm permissions\n";
[220]816 print OUTFILE
817 "# It is intended to be used for restoring permissions\n";
[215]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
[220]828 if ($tofile) {
[215]829 close(OUTFILE);
830 }
831 }
[209]832}
833
[189]834#####################################################################
835#
[186]836# main
[189]837#
[186]838
839my $number_arguments = @ARGV;
840
[205]841if ( $number_arguments > 0 ) {
[186]842
[205]843 # get subcommand and remove it from @ARGV
844 $command = $ARGV[0];
845 shift @ARGV;
[196]846
[205]847 $DASSCM_LOCAL_REPOSITORY_BASE = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'};
848 $DASSCM_REPOSITORY_NAME = $config->{'DASSCM_REPOSITORY_NAME'};
[196]849
[205]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
[214]871 my $result = GetOptions( \%options, 'verbose', 'message=s' );
[205]872
873 # print options
874 foreach my $option ( keys %options ) {
[215]875 print "${option}: $options{$option}\n";
[205]876 }
877
[214]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 #
[205]886 $_ = $command;
887 if (m/help/i) {
888 help(@ARGV);
889 } elsif (m/login/i) {
[208]890 $command = "login";
[205]891 login(@ARGV);
892 } elsif (m/init/i) {
[208]893 $command = "init";
[205]894 init(@ARGV);
[215]895 } elsif (m/ls/i) {
896 $command = "ls";
897 ls(@ARGV);
[235]898 } elsif ( (m/update/i) || (m/up/i) ) {
[215]899 $command = "update";
900 update(@ARGV);
[205]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) {
[208]908 $command = "blame";
[205]909 blame(@ARGV);
910 } elsif (m/diff/i) {
[208]911 $command = "diff";
[205]912 diff(@ARGV);
[235]913 } elsif ( (m/status/i) || (m/st/i) ) {
[209]914 $command = "status";
915 status(@ARGV);
[215]916 } elsif (m/permissions/i) {
917 $command = "permissions";
918 permissions(@ARGV);
[205]919 } else {
[215]920 print "unknown command: $command\n\n";
[205]921 usage();
922 check_env();
923 }
924
[209]925 # cleanup (svn-commit.tmp)
[205]926 # commitall
927 # revert
[215]928 # activate
[227]929 # rm
[186]930}
Note: See TracBrowser for help on using the repository browser.