Changeset 918 for dasscm/trunk/usr
- Timestamp:
- Jul 26, 2010, 6:16:32 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
dasscm/trunk/usr/bin/dasscm
r916 r918 162 162 'permissions' => { 163 163 'desc' => 164 ["internal, used to update information about file permissions"],164 ["internal, print permissions for all files in the repository"], 165 165 'params' => [], 166 166 'function' => \&permissions … … 201 201 my $DASSCM_CHECKOUT_USERNAME; 202 202 my $DASSCM_CHECKOUT_PASSWORD; 203 my $DASSCM_PERMISSION_FILE;203 my @DASSCM_ADDITIONAL_FILES; 204 204 205 205 # current directory at program start … … 369 369 if ( not -d $DASSCM_REPO ) { 370 370 fatalerror( 371 "Can't access local repository DASSCM_REPO",372 "($DASSCM_REPO)",373 "Check configuration and execute",374 "dasscm init"371 "Can't access local repository DASSCM_REPO", 372 "($DASSCM_REPO)", 373 "Check configuration and execute", 374 "dasscm init" 375 375 ); 376 376 } … … 724 724 { 725 725 my $mode = shift; 726 if ( $mode) {727 run_command( "stty echo");726 if ($mode) { 727 run_command("stty echo"); 728 728 } else { 729 run_command( "stty -echo" ); 730 } 731 } 732 729 run_command("stty -echo"); 730 } 731 } 733 732 734 733 sub write_array_to_file( $@ ) 735 734 { 736 735 my $filename = shift; 737 my @array = @_;738 739 if ( ! 736 my @array = @_; 737 738 if ( !-w dirname($filename) ) { 740 739 warning( "failed to write to $filename", "directory does not exist" ); 741 740 return; … … 743 742 744 743 # directory exists => write 745 if ( !open( OUTFILE, ">$filename" ) ) {746 warning( "failed to open $filename: $!");744 if ( !open( OUTFILE, ">$filename" ) ) { 745 warning("failed to open $filename: $!"); 747 746 return; 748 747 } … … 756 755 } 757 756 758 759 757 sub perform_plugins() 760 758 { … … 765 763 # get all defined plugins. 766 764 # Plugin definitions starting with DASSCM_PLUGIN_ 767 my @plugins = grep( /^DASSCM_PLUGIN_CMD_/, keys( %{$config} ));765 my @plugins = grep( /^DASSCM_PLUGIN_CMD_/, keys( %{$config} ) ); 768 766 769 767 for my $plugin (@plugins) { 770 my $plugin_name = substr( $plugin, length( "DASSCM_PLUGIN_CMD_") );771 my $plugin_test = $config->{ 'DASSCM_PLUGIN_TEST_' . $plugin_name};772 ( my $rc_test, my @result_test ) = run_command( $plugin_test);768 my $plugin_name = substr( $plugin, length("DASSCM_PLUGIN_CMD_") ); 769 my $plugin_test = $config->{ 'DASSCM_PLUGIN_TEST_' . $plugin_name }; 770 ( my $rc_test, my @result_test ) = run_command($plugin_test); 773 771 if ($verbose) { print "Plugin $plugin_name: "; } 774 if ( $rc_test != 0 ) {772 if ( $rc_test != 0 ) { 775 773 if ($verbose) { print "skipped\n"; } 776 774 } else { 777 775 if ($verbose) { print "$config->{$plugin}\n"; } 778 776 ( my $rc, my @result ) = run_command( $config->{$plugin} ); 779 if ( $rc != 0 ) {780 warning( "failed to run plugin $plugin");777 if ( $rc != 0 ) { 778 warning("failed to run plugin $plugin"); 781 779 } else { 782 my $plugin_result_file = $DASSCM_PLUGIN_RESULTS_PATH . "/" . $plugin_name; 780 my $plugin_result_file = 781 $DASSCM_PLUGIN_RESULTS_PATH . "/" . $plugin_name; 783 782 write_array_to_file( $plugin_result_file, @result ); 784 783 push @plugin_results, $plugin_result_file; … … 788 787 return @plugin_results; 789 788 } 790 791 792 789 793 790 sub svn_check_credentials( $$;$$ ) … … 1070 1067 } 1071 1068 1069 sub print_files_hash( $ ) 1070 { 1071 my $href_files = shift; 1072 1073 my @files = @{ $href_files->{files} }; 1074 my @links = @{ $href_files->{links} }; 1075 1076 if (@files) { 1077 my $number = $#files + 1; 1078 print "files to check-in ($number): \n"; 1079 print join( "\n", @files ); 1080 print "\n"; 1081 } 1082 1083 # TODO: check in links and also link target? At least warn about link target 1084 if (@links) { 1085 my $number = $#links + 1; 1086 print "\n"; 1087 print "ignoring links ($number):\n"; 1088 print join( "\n", @links ); 1089 print "\n"; 1090 } 1091 1092 } 1093 1072 1094 # 1073 1095 # use globbing to get lsit of files … … 1140 1162 # hidden password input 1141 1163 print "Enter password for $input_username: "; 1142 setEchoMode( 0);1164 setEchoMode(0); 1143 1165 my $input_password = <STDIN>; 1144 setEchoMode( 1);1166 setEchoMode(1); 1145 1167 chomp($input_password); 1146 1168 print "\n"; … … 1183 1205 1184 1206 # update complete repository 1185 # and create permission file1186 1207 my $retcode = run_interactive( 1187 "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY ; mkdir -p `dirname $DASSCM_PERMISSION_FILE`; touch $DASSCM_PERMISSION_FILE"1208 "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY" 1188 1209 ); 1189 1210 } … … 1250 1271 } 1251 1272 1273 sub add_helper_multi(@) 1274 { 1275 1276 # get all regular files and links 1277 my $href_files = get_files(@_); 1278 1279 #print Dumper( $href_files ); 1280 1281 my @files = @{ $href_files->{files} }; 1282 my @links = @{ $href_files->{links} }; 1283 1284 # copy files one by one to local repository 1285 for my $file (@files) { 1286 1287 # add file 1288 add_helper($file); 1289 } 1290 1291 return $href_files; 1292 } 1293 1252 1294 # 1253 1295 # adding new files (or directories) … … 1263 1305 svn_update(); 1264 1306 1265 # get all regular files and links 1266 my $href_files = get_files(@_); 1267 1268 #print Dumper( $href_files ); 1269 1270 my @files = @{ $href_files->{files} }; 1271 my @links = @{ $href_files->{links} }; 1272 1273 if (@files) { 1274 my $number = $#files + 1; 1275 print "files to check-in ($number): \n"; 1276 print join( "\n", @files ); 1277 print "\n"; 1278 } 1279 1280 # TODO: check in links and also link target? At least warn about link target 1281 if (@links) { 1282 my $number = $#links + 1; 1283 print "\n"; 1284 print "ignoring links ($number):\n"; 1285 print join( "\n", @links ); 1286 print "\n"; 1287 } 1288 1289 # TODO: confirm 1290 1291 # copy files one by one to local repository 1292 for my $file (@files) { 1293 1294 # add file 1295 add_helper($file); 1296 } 1297 1298 # create new permissions file 1299 permissions(); 1300 1301 # add permissions file 1302 add_helper($DASSCM_PERMISSION_FILE); 1303 1304 for my $file ( perform_plugins() ) { 1305 add_helper($file); 1306 } 1307 1307 # add files to repository, print information about added files 1308 print_files_hash( add_helper_multi(@_) ); 1309 1310 # perform plugins and add additional files, like plugin results 1311 perform_plugins(); 1312 add_helper_multi(@DASSCM_ADDITIONAL_FILES); 1308 1313 1309 1314 if ( $options{'message'} ) { … … 1362 1367 } 1363 1368 1364 # create new permissions file 1365 permissions(); 1366 1367 # add permissions file 1368 add_helper($DASSCM_PERMISSION_FILE); 1369 1370 for my $file ( perform_plugins() ) { 1371 add_helper($file); 1372 } 1373 1374 1369 perform_plugins(); 1370 add_helper_multi(@DASSCM_ADDITIONAL_FILES); 1375 1371 1376 1372 if ( $options{'message'} ) { … … 1526 1522 #svn_update( $filename_prod ); 1527 1523 1528 # check, if permissions have changed 1529 permissions(); 1524 # perform plugins (required to see changes in plugin results) 1530 1525 perform_plugins(); 1531 1526 … … 1573 1568 my $return_string = "OK: no modified files"; 1574 1569 1575 # check, if permissions have changed 1576 permissions(); 1570 # perform plugins (required to see changes in plugin results) 1577 1571 perform_plugins(); 1578 1572 … … 1625 1619 if (@files) { 1626 1620 1627 # generieren der Permissions 1628 my @permissions = generatePermissionList(@files); 1629 my $OUTFILE; 1630 my $tofile = 0; # Status für schreiben in File 1631 1632 if ( -w dirname($DASSCM_PERMISSION_FILE) ) { 1633 1634 # Verzeichnis existiert => schreiben 1635 open( OUTFILE, ">$DASSCM_PERMISSION_FILE" ) 1636 || die("failed to write to $DASSCM_PERMISSION_FILE: $!"); 1637 $tofile = 1; # Merken, daß in File geschrieben wird 1638 print OUTFILE "#\n"; 1639 print OUTFILE "# created by dasscm permissions\n"; 1640 print OUTFILE 1641 "# It is intended to be used for restoring permissions\n"; 1642 print OUTFILE "#\n"; 1643 } else { 1644 1645 if ( $command eq "permission" ) { 1646 1647 # Pfad für Sicherungsdatei existiert nicht => schreiben auf stdout 1648 # Alias Filehandle für stdout erzeugen 1649 $return_code = $RETURN_WARN; 1650 *OUTFILE = *STDOUT; 1651 } else { 1652 1653 # TODO: improve this. Check for diff? 1654 $return_code = $RETURN_CRIT; 1655 return $return_code; 1656 } 1657 } 1658 1659 foreach my $line (@permissions) { 1660 print OUTFILE "$line\n"; 1661 } 1662 1663 if ($tofile) { 1664 close(OUTFILE); 1665 } 1621 print "#\n"; 1622 print "# created by dasscm permissions\n"; 1623 print "# It is intended to be used for restoring permissions\n"; 1624 print "#\n"; 1625 1626 # generate and print permissions 1627 foreach my $line ( generatePermissionList(@files) ) { 1628 print "$line\n"; 1629 } 1630 1666 1631 } 1667 1632 … … 1834 1799 $DASSCM_REPOSITORY_NAME = $config->{'DASSCM_REPOSITORY_NAME'}; 1835 1800 1836 $DASSCM_PLUGIN_RESULTS_PATH = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'} . "/" . "plugin-results/"; 1801 $DASSCM_PLUGIN_RESULTS_PATH = 1802 $config->{'DASSCM_LOCAL_REPOSITORY_BASE'} . "/" . "plugin-results/"; 1803 1804 # get list of additional directories and files, seperated by blank (" ") 1805 # these files are always stored in subversion 1806 if ( $config->{'DASSCM_ADDITIONAL_FILES'} ) { 1807 @DASSCM_ADDITIONAL_FILES = split / /, $config->{'DASSCM_ADDITIONAL_FILES'}; 1808 } else { 1809 @DASSCM_ADDITIONAL_FILES = ( $DASSCM_PLUGIN_RESULTS_PATH ); 1810 } 1837 1811 1838 1812 # TODO: check variables … … 1856 1830 } 1857 1831 1858 $DASSCM_PERMISSION_FILE = $config->{'DASSCM_PERMISSION_FILE'}1859 || "/etc/permissions.d/dasscm.permission_backup";1860 1832 1861 1833 # check for command options
Note:
See TracChangeset
for help on using the changeset viewer.