Changeset 215
- Timestamp:
- Jul 3, 2007, 4:55:06 PM (17 years ago)
- Location:
- trunk/dasscm
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dasscm/SOURCES
r214 r215 1 1 dasscm 2 dasscm_dumpperm3 2 Changes 4 3 servers.dass-it -
trunk/dasscm/dasscm
r214 r215 12 12 use File::Compare; 13 13 use File::Copy; 14 use File::Find;15 14 use File::stat; 16 15 use File::Path; … … 28 27 # 29 28 29 # file to store permissions 30 my $permissions_file = "/etc/permissions.d/dasscm.permission_backup"; 31 # configuration file 30 32 my $config_file = "/etc/dasscm.conf"; 31 33 my $config = ConfigFile::read_config_file($config_file); … … 47 49 my $verbose = 0; 48 50 49 # stores result from status (cvscheck)50 my %status_removedfiles = ();51 my %status_changedfiles = ();52 51 53 52 ##################################################################### … … 62 61 print "\n"; 63 62 print "Available subcommands:\n"; 63 print " help <subcommand>\n"; 64 64 print " init\n"; 65 65 print " login\n"; 66 print " up\n"; 67 print " ls\n"; 66 68 print " add <filename>\n"; 67 69 print " commit <filename>\n"; 68 70 print " status <filename>\n"; 69 71 print " diff <filename>\n"; 70 print " help <subcommand>\n";72 print " permissions\n"; 71 73 print "\n"; 72 74 print "preperation:\n"; … … 108 110 } 109 111 } 110 print "DASSCM_REPO: " . $DASSCM_REPO . "\n";112 if ($verbose) { print "DASSCM_REPO: " . $DASSCM_REPO . "\n"; } 111 113 112 114 # … … 186 188 } 187 189 188 # 189 # used by status 190 # checks for differences between PROD and (local) REPO 191 # 192 sub cvscheck 193 { 194 return unless -f; # keine Directories 195 return if $File::Find::dir =~ /\/CVS$/; # ignoriere CVS-Verzeichnisse 196 return 197 if $File::Find::dir =~ 198 /\/\.svn/; # ignoriere Subversion Verzeichnisse (inkl. Unterverzeichnisse) 199 my $cvsworkfile = "$File::Find::dir/$_"; 200 201 # Ursprungspfad ermitteln 202 # TODO: get_filename ? 203 $cvsworkfile =~ /${DASSCM_REPO}\/(.+)/; 204 my $realfile = "/" . $1; 205 206 # relativer Pfad zur CVS-Arbeitsdatei 207 my $relcvsworkfile = $1; 208 209 if ( !-r $realfile ) { 210 $status_removedfiles{"$realfile"} = $cvsworkfile; 211 } else { 212 ( -r "$cvsworkfile" ) || die("Fehler: $cvsworkfile ist nicht lesbar"); 213 if ( compare( $cvsworkfile, $realfile ) != 0 ) { 214 215 # Dateien unterscheiden sich 216 #(-w $cvsworkfile) || die("failed: no Fehler: kein Schreibrecht auf $cvsworkfile"); 217 # Arbeitskopie durch Kopie ersetzen 218 #copy($realfile,$cvsworkfile) || die("Fehler beim kopieren $realfile --> $cvsworkfile"); 219 $status_changedfiles{"$realfile"} = $cvsworkfile; 220 } 221 } 190 191 192 sub generatePermissionList 193 { 194 195 # generieren der Zeilen für Permission-Savefile 196 my @files = @_; 197 my @permlist = (); 198 foreach my $file (@files) { 199 my $info = stat( "/" . $file ) || die "$file: stat error"; 200 my $mode = get_type( $info->mode ) & 07777; 201 my $modestring = sprintf( "%04o", $mode ); 202 my $uid = $info->uid; 203 my $uidname = getpwuid($uid); 204 my $gid = $info->gid; 205 my $gidname = getgrgid($gid); 206 push( 207 @permlist, 208 sprintf( "%-55s %-17s %4d", 209 $file, "${uidname}:${gidname}", $modestring ) 210 ); 211 } 212 return @permlist; 213 } 214 215 sub get_type 216 { 217 218 # Funktion übernommen aus /usr/bin/chkstat 219 my $S_IFLNK = 0120000; # symbolic link 220 my $S_IFREG = 0100000; # regular file 221 my $S_IFDIR = 0040000; # directory 222 my $S_IFCHAR = 0020000; # character device 223 my $S_IFBLK = 0060000; # block device 224 my $S_IFFIFO = 0010000; # fifo 225 my $S_IFSOCK = 0140000; # socket 226 my $S_IFMT = 0170000; # type of file 227 228 my $S_m; 229 if ( ( $_[0] & $S_IFMT ) == $S_IFLNK ) { $S_m = $_[0] - $S_IFLNK; } 230 elsif ( ( $_[0] & $S_IFMT ) == $S_IFREG ) { $S_m = $_[0] - $S_IFREG; } 231 elsif ( ( $_[0] & $S_IFMT ) == $S_IFDIR ) { $S_m = $_[0] - $S_IFDIR; } 232 elsif ( ( $_[0] & $S_IFMT ) == $S_IFCHAR ) { $S_m = $_[0] - $S_IFCHAR; } 233 elsif ( ( $_[0] & $S_IFMT ) == $S_IFBLK ) { $S_m = $_[0] - $S_IFBLK; } 234 elsif ( ( $_[0] & $S_IFMT ) == $S_IFFIFO ) { $S_m = $_[0] - $S_IFFIFO; } 235 elsif ( ( $_[0] & $S_IFMT ) == $S_IFSOCK ) { $S_m = $_[0] - $S_IFSOCK; } 236 $S_m; 222 237 } 223 238 … … 271 286 272 287 if ( $rc_update != 0 ) { 273 print @result;274 288 die; 275 289 } … … 282 296 ( my $rc_update, my @result ) = 283 297 run_command("$SVN update $svnCheckoutCredentials $update_path"); 298 print @result; 284 299 if ( $rc_update != 0 ) { 300 die; 301 } 302 } 303 304 sub svn_getStoredFiles( ;$ ) 305 { 306 307 # TODO: get_filenames? 308 #my $rel_path = shift || ""; 309 #my $path = "${DASSCM_REPO}/${rel_path}"; 310 my $path = ${DASSCM_REPO}; 311 ( my $rc, my @result ) = 312 run_command("$SVN ls --recursive $svnCheckoutCredentials $path"); 313 if ( $rc != 0 ) { 285 314 print @result; 286 315 die; 287 316 } 288 289 print @result; 290 317 chomp(@result); 318 return @result; 291 319 } 292 320 … … 358 386 } 359 387 360 # 361 # add (is used for command add and commit) 362 # 363 sub add(@) 364 { 365 check_parameter( @_, 1 ); 366 check_env(); 367 388 sub ls(@) 389 { 390 check_parameter( @_, 1 ); 391 check_env(); 392 393 my @files = svn_getStoredFiles(@_); 394 395 print join( "\n", @files ); 396 print "\n"; 397 } 398 399 400 sub update(@) 401 { 402 check_parameter( @_, 1 ); 403 check_env(); 404 405 # 406 # update local repository 407 # 408 svn_update(); 409 } 410 411 412 sub add_helper(@) 413 { 368 414 ( 369 415 my $basename, … … 379 425 } 380 426 381 # update complete repository382 my $retcode = run_interactive("$SVN update $svnOptions $DASSCM_REPO");383 384 427 copy( $filename_prod, $filename_repo ) or die $!; 385 428 … … 398 441 run_command("$SVN add $basename"); 399 442 } 443 } 444 445 446 447 # 448 # add (is used for command add and commit) 449 # 450 sub add(@) 451 { 452 check_parameter( @_, 1 ); 453 check_env(); 454 455 # 456 # update local repository 457 # 458 svn_update(); 459 460 # add file 461 add_helper( $_[0] ); 462 # create new permissions file 463 permissions(); 464 # add permissions file 465 add_helper( $permissions_file ); 400 466 401 467 if ( $options{'message'} ) { … … 404 470 405 471 # commit calls $EDITOR. uses "interactive" here, to display output 406 $retcode =472 my $retcode = 407 473 run_interactive( 408 474 "$SVN commit $svnOptions --username $DASSCM_USERNAME $svnPasswordCredentials $DASSCM_REPO" 409 475 ); 410 476 411 print $filename_prod. "\n"; 412 print $dirname_repo. "\n"; 413 } 477 #print $filename_prod. "\n"; 478 #print $dirname_repo. "\n"; 479 } 480 481 414 482 415 483 sub blame(@) … … 468 536 469 537 # TODO: start at subdirectories ? 470 my $cvsworkdir = $DASSCM_REPO; 471 472 File::Find::find( \&cvscheck, $cvsworkdir ); 538 my $dir = $DASSCM_REPO; 539 my @files = svn_getStoredFiles($dir); 473 540 474 541 # Liste der geänderten Files ausgeben, falls nicht leer 475 # Anzahl Elemente im Hash??? 476 my @changedfiles = keys %status_changedfiles; 477 478 if ( %status_changedfiles or %status_removedfiles ) { 479 if (%status_removedfiles) { 480 print "deleted files:\n"; 481 foreach my $key ( values %status_removedfiles ) { 542 if (@files) { 543 544 # stores result from status (cvscheck) 545 my %removedfiles = (); 546 my %changedfiles = (); 547 548 foreach my $file (@files) { 549 550 my $realfile = "/" . $file; 551 my $cvsworkfile = "${DASSCM_REPO}/${file}"; 552 553 if ( -d $realfile ) { 554 555 # directory. do nothing 556 } elsif ( !-r $realfile ) { 557 $removedfiles{"$realfile"} = $cvsworkfile; 558 } else { 559 ( -r "$cvsworkfile" ) 560 || die("Fehler: $cvsworkfile ist nicht lesbar"); 561 if ( compare( $cvsworkfile, $realfile ) != 0 ) { 562 $changedfiles{"$realfile"} = $cvsworkfile; 563 } 564 } 565 } 566 567 if (%removedfiles) { 568 print "deleted files (found in repository, but not in system):\n"; 569 foreach my $key ( values %removedfiles ) { 482 570 print "$key\n"; 483 571 } … … 485 573 } 486 574 487 if (% status_changedfiles) {575 if (%changedfiles) { 488 576 print "modified files:\n"; 489 foreach my $key ( keys % status_changedfiles ) {577 foreach my $key ( keys %changedfiles ) { 490 578 print "$key\n"; 491 579 } 492 580 } 493 581 } else { 494 print "no modified files found in $cvsworkdir\n"; 495 } 582 print "no modified files found in $dir\n"; 583 } 584 496 585 print "\n"; 497 586 } 587 588 589 590 sub permissions(@) 591 { 592 check_parameter( @_, 1 ); 593 check_env(); 594 595 # 596 # update local repository 597 # 598 #svn_update(); 599 600 # TODO: start at subdirectories ? 601 my $dir = $DASSCM_REPO; 602 my @files = svn_getStoredFiles($dir); 603 604 if (@files) { 605 606 # generieren der Permissions 607 my @permissions = generatePermissionList(@files); 608 my $OUTFILE; 609 my $tofile = 0; # Status für schreiben in File 610 611 if ( -w dirname($permissions_file) ) { 612 613 # Verzeichnis existiert => schreiben 614 print "storing permissions in file $permissions_file\n"; 615 open( OUTFILE, ">$permissions_file" ) 616 || die("failed to write to $permissions_file"); 617 $tofile = 1; # Merken, daß in File geschrieben wird 618 print OUTFILE "#\n"; 619 print OUTFILE "# created by dasscm permissions\n"; 620 print OUTFILE "# It is intended to be used for restoring permissions\n"; 621 } else { 622 623 # Pfad für Sicherungsdatei existiert nicht => schreiben auf stdout 624 # Alias Filehandle für stdout erzeugen 625 *OUTFILE = *STDOUT; 626 } 627 foreach my $line (@permissions) { 628 print OUTFILE "$line\n"; 629 } 630 631 if ($tofile) { 632 close(OUTFILE); 633 } 634 } 498 635 } 499 636 … … 539 676 # print options 540 677 foreach my $option ( keys %options ) { 541 print $option. ": " . $options{$option} . "\n";678 print "${option}: $options{$option}\n"; 542 679 } 543 680 … … 559 696 $command = "init"; 560 697 init(@ARGV); 698 } elsif (m/ls/i) { 699 $command = "ls"; 700 ls(@ARGV); 701 } elsif (m/up/i) { 702 $command = "update"; 703 update(@ARGV); 561 704 } elsif (m/add/i) { 562 705 $command = "add"; … … 574 717 $command = "status"; 575 718 status(@ARGV); 576 577 # } elsif (m/activate/i) { 578 # ## TODO 579 # activate(@ARGV); 719 } elsif (m/permissions/i) { 720 $command = "permissions"; 721 permissions(@ARGV); 580 722 } else { 723 print "unknown command: $command\n\n"; 581 724 usage(); 582 725 check_env(); … … 587 730 # commitall 588 731 # revert 589 } 732 # activate 733 } -
trunk/dasscm/dasscm.spec
r214 r215 40 40 mkdir -p $RPM_BUILD_ROOT/usr/bin/ 41 41 install -m 755 dasscm $RPM_BUILD_ROOT/usr/bin/ 42 install -m 755 dasscm_dumpperm $RPM_BUILD_ROOT/usr/bin/43 42 mkdir -p $RPM_BUILD_ROOT/etc/subversion/ 44 43 install servers.dass-it $RPM_BUILD_ROOT/etc/subversion/ … … 55 54 %defattr(-,root,root) 56 55 %dir /var/lib/dasscm/ 57 /usr/bin/dasscm *56 /usr/bin/dasscm 58 57 /etc/subversion/servers.dass-it 59 58 %config(noreplace) /etc/dasscm.conf -
trunk/dasscm/doc/dasscm_howto.txt
r214 r215 44 44 # ermittelt, welche Dateien sich zwischenzeitlich auf dem System verändert haben 45 45 dasscm status 46 47 48 49 *** Dateirechte sichern 50 51 bei jeden dasscm add/commit 52 werden die Dateirechte unter /etc/permissions.d/dasscm.permissions_backup gesichert.
Note:
See TracChangeset
for help on using the changeset viewer.