source: trunk/dasscm/dasscm@ 249

Last change on this file since 249 was 249, checked in by joergs, on Oct 13, 2008 at 6:55:15 PM

bugfix: remove . from permission file list

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