[186] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | # $Id: dasscm 216 2007-07-16 13:55:29Z joergs $
|
---|
| 4 |
|
---|
| 5 | use strict;
|
---|
| 6 |
|
---|
[208] | 7 | use Env
|
---|
| 8 | qw($DASSCM_PROD $DASSCM_REPO $USER $DASSCM_USERNAME $DASSCM_USER $DASSCM_PASSWORD);
|
---|
[186] | 9 | use Cwd;
|
---|
[214] | 10 | use Getopt::Long;
|
---|
[186] | 11 | use File::Basename;
|
---|
[209] | 12 | use File::Compare;
|
---|
| 13 | use File::Copy;
|
---|
[186] | 14 | use File::stat;
|
---|
| 15 | use File::Path;
|
---|
[214] | 16 | use Term::ReadKey;
|
---|
[186] | 17 |
|
---|
[205] | 18 | #
|
---|
| 19 | # used ConfigFile instead of SmartClient::Config,
|
---|
| 20 | # because the huge amount of SmartClient dependencies
|
---|
| 21 | #use SmartClient::Config;
|
---|
| 22 | use ConfigFile;
|
---|
| 23 |
|
---|
[189] | 24 | #####################################################################
|
---|
| 25 | #
|
---|
[186] | 26 | # global
|
---|
[189] | 27 | #
|
---|
[205] | 28 |
|
---|
[215] | 29 | # file to store permissions
|
---|
| 30 | my $permissions_file = "/etc/permissions.d/dasscm.permission_backup";
|
---|
| 31 | # configuration file
|
---|
[205] | 32 | my $config_file = "/etc/dasscm.conf";
|
---|
[214] | 33 | my $config = ConfigFile::read_config_file($config_file);
|
---|
[205] | 34 | my $DASSCM_LOCAL_REPOSITORY_BASE;
|
---|
| 35 | my $DASSCM_REPOSITORY_NAME;
|
---|
| 36 | my $DASSCM_SVN_REPOSITORY;
|
---|
| 37 |
|
---|
| 38 | my $SVN = "svn ";
|
---|
| 39 | my $svnOptions = "";
|
---|
| 40 | my $svnCheckoutCredentials = "";
|
---|
| 41 | my $svnPasswordCredentials = "";
|
---|
| 42 |
|
---|
[196] | 43 | # command line options get stored in options hash
|
---|
[205] | 44 | my %options = ();
|
---|
| 45 |
|
---|
[197] | 46 | # subcommand, that gets executed (add, commit, ...)
|
---|
[196] | 47 | my $command;
|
---|
[186] | 48 |
|
---|
[205] | 49 | my $verbose = 0;
|
---|
| 50 |
|
---|
[209] | 51 |
|
---|
[189] | 52 | #####################################################################
|
---|
| 53 | #
|
---|
[186] | 54 | # util functions
|
---|
[189] | 55 | #
|
---|
[187] | 56 | sub usage()
|
---|
| 57 | {
|
---|
[205] | 58 | print "usage: dasscm <subcommand> [options] [args]\n";
|
---|
| 59 | print "\n";
|
---|
| 60 | print "dasscm is intended to help versioning configuration files\n";
|
---|
| 61 | print "\n";
|
---|
| 62 | print "Available subcommands:\n";
|
---|
[215] | 63 | print " help <subcommand>\n";
|
---|
[205] | 64 | print " init\n";
|
---|
| 65 | print " login\n";
|
---|
[215] | 66 | print " up\n";
|
---|
| 67 | print " ls\n";
|
---|
[205] | 68 | print " add <filename>\n";
|
---|
| 69 | print " commit <filename>\n";
|
---|
[214] | 70 | print " status <filename>\n";
|
---|
[205] | 71 | print " diff <filename>\n";
|
---|
[215] | 72 | print " permissions\n";
|
---|
[205] | 73 | print "\n";
|
---|
| 74 | print "preperation:\n";
|
---|
| 75 | print "check out the configuration repository, e.g.\n";
|
---|
| 76 | print
|
---|
| 77 | "svn checkout --no-auth-cache --username USERNAME https://dass-it.de/svn/dasscm/HOSTNAME\n";
|
---|
[214] | 78 | print "environment variables\n", " DASSCM_REPO\n", " DASSCM_PROD\n",
|
---|
[208] | 79 | " DASSCM_USERNAME\n", " DASSCM_PASSWORD\n", "are evaluated.\n";
|
---|
[205] | 80 | print "\n";
|
---|
[187] | 81 | }
|
---|
| 82 |
|
---|
[186] | 83 | sub check_env()
|
---|
| 84 | {
|
---|
[205] | 85 |
|
---|
| 86 | # DASSCM_PROD
|
---|
| 87 | if ( !$DASSCM_PROD ) {
|
---|
| 88 | $DASSCM_PROD = "/";
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | if ( !-d $DASSCM_PROD ) {
|
---|
| 92 | die "DASSCM_PROD ($DASSCM_PROD) is not set to a directory.\n";
|
---|
| 93 | }
|
---|
| 94 | if ($verbose) { print "DASSCM_PROD: " . $DASSCM_PROD . "\n"; }
|
---|
| 95 |
|
---|
| 96 | # DASSCM_REPOSITORY_NAME
|
---|
[208] | 97 | if ( !$DASSCM_REPOSITORY_NAME ) {
|
---|
| 98 | die
|
---|
| 99 | "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";
|
---|
| 100 | }
|
---|
[205] | 101 |
|
---|
| 102 | # DASSCM_REPO
|
---|
| 103 | if ( !$DASSCM_REPO ) {
|
---|
| 104 | if ( $DASSCM_LOCAL_REPOSITORY_BASE && $DASSCM_REPOSITORY_NAME ) {
|
---|
| 105 | $DASSCM_REPO =
|
---|
| 106 | $DASSCM_LOCAL_REPOSITORY_BASE . "/" . $DASSCM_REPOSITORY_NAME;
|
---|
| 107 | } else {
|
---|
| 108 | die
|
---|
| 109 | "Envirnonment variable DASSCM_REPO not set.\nSet DASSCM_REPO to the directory of the versioning system checkout for this machine.\n";
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
[215] | 112 | if ($verbose) { print "DASSCM_REPO: " . $DASSCM_REPO . "\n"; }
|
---|
[205] | 113 |
|
---|
| 114 | #
|
---|
| 115 | # check if local repository directory exist (if not creating by init)
|
---|
| 116 | #
|
---|
| 117 | if ( $command ne "init" ) {
|
---|
| 118 | if ( not -d $DASSCM_REPO ) {
|
---|
| 119 | die
|
---|
[208] | 120 | "Can't access local repository DASSCM_REPO\n($DASSCM_REPO)\nCheck configuration and execute\n dasscm init\n";
|
---|
[205] | 121 | }
|
---|
[208] | 122 |
|
---|
[205] | 123 | #
|
---|
| 124 | # user settings
|
---|
| 125 | #
|
---|
[208] | 126 |
|
---|
[205] | 127 | # DASSCM_USER is legacy. Use DASSCM_USERNAME instead
|
---|
[208] | 128 | if ( !$DASSCM_USERNAME ) {
|
---|
| 129 | $DASSCM_USERNAME = $DASSCM_USER;
|
---|
[205] | 130 | }
|
---|
| 131 |
|
---|
| 132 | # user root is not allowed for checkins.
|
---|
| 133 | # if user is root, DASSCM_USER has to be set,
|
---|
| 134 | # otherwise USER can be used
|
---|
| 135 | if ( "$USER" eq "root" ) {
|
---|
[208] | 136 | if ( ( not $DASSCM_USERNAME ) and ( $command ne "login" ) ) {
|
---|
[205] | 137 | die
|
---|
[208] | 138 | "Envirnonment variable DASSCM_USERNAME not set.\nSet DASSCM_USERNAME to your subversion user account.\n";
|
---|
[205] | 139 | }
|
---|
| 140 | $svnOptions .= " --no-auth-cache ";
|
---|
| 141 | } elsif ( !$DASSCM_USERNAME ) {
|
---|
| 142 | $DASSCM_USERNAME = $USER;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | #
|
---|
| 146 | # password
|
---|
| 147 | #
|
---|
[208] | 148 | if ($DASSCM_PASSWORD) {
|
---|
[205] | 149 | $svnPasswordCredentials = " --password $DASSCM_PASSWORD ";
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | #$svnOptions .= " --username $DASSCM_USERNAME "
|
---|
[186] | 154 | }
|
---|
| 155 |
|
---|
| 156 | sub check_parameter(@)
|
---|
| 157 | {
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[187] | 160 | sub get_filenames(@)
|
---|
| 161 | {
|
---|
[205] | 162 | my $filename_prod = $_[0];
|
---|
| 163 | if ( !( $filename_prod =~ m/^\// ) ) {
|
---|
| 164 | $filename_prod = cwd() . "/" . $filename_prod;
|
---|
| 165 | }
|
---|
[187] | 166 |
|
---|
[205] | 167 | -r $filename_prod or die "$filename_prod is not accessable";
|
---|
| 168 |
|
---|
| 169 | # TODO: dirname buggy: eg. "/etc/" is reduced to "/",
|
---|
| 170 | # "/etc" is used as filename
|
---|
| 171 | my $dirname_prod = dirname($filename_prod);
|
---|
| 172 | chdir $dirname_prod or die $!;
|
---|
| 173 | $dirname_prod = cwd();
|
---|
| 174 | my $basename = basename($filename_prod);
|
---|
| 175 |
|
---|
[214] | 176 | if ($verbose) {
|
---|
| 177 | print "dir: " . $dirname_prod . "\n";
|
---|
| 178 | print "fn: " . $basename . "\n";
|
---|
| 179 | }
|
---|
[205] | 180 |
|
---|
| 181 | my $dirname_repo = $DASSCM_REPO . "/" . $dirname_prod;
|
---|
| 182 | my $filename_repo = "$dirname_repo/$basename";
|
---|
| 183 |
|
---|
| 184 | return (
|
---|
| 185 | $basename, $dirname_prod, $dirname_repo,
|
---|
| 186 | $filename_prod, $filename_repo
|
---|
| 187 | );
|
---|
[187] | 188 | }
|
---|
| 189 |
|
---|
[215] | 190 |
|
---|
| 191 |
|
---|
| 192 | sub generatePermissionList
|
---|
[209] | 193 | {
|
---|
| 194 |
|
---|
[215] | 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 | }
|
---|
[209] | 214 |
|
---|
[215] | 215 | sub get_type
|
---|
| 216 | {
|
---|
[209] | 217 |
|
---|
[215] | 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
|
---|
[209] | 227 |
|
---|
[215] | 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;
|
---|
[209] | 237 | }
|
---|
| 238 |
|
---|
[186] | 239 | sub run_command
|
---|
| 240 | {
|
---|
[205] | 241 | my $command = shift;
|
---|
[186] | 242 |
|
---|
[205] | 243 | #print "executing command: " . $command . "\n";
|
---|
[186] | 244 |
|
---|
[205] | 245 | open( RESULT, $command . ' 2>&1 |' );
|
---|
| 246 | my @result = <RESULT>;
|
---|
| 247 | close(RESULT);
|
---|
| 248 | my $retcode = $? >> 8;
|
---|
[186] | 249 |
|
---|
[205] | 250 | #print @result;
|
---|
| 251 | #if( $retcode ) { print "return code: " . $retcode . "\n"; }
|
---|
[186] | 252 |
|
---|
[205] | 253 | return ( $retcode, @result );
|
---|
[186] | 254 | }
|
---|
| 255 |
|
---|
[205] | 256 | sub run_interactive
|
---|
| 257 | {
|
---|
[186] | 258 |
|
---|
[208] | 259 | if ($verbose) {
|
---|
[205] | 260 | print "run_interactive:" . join( " ", @_ ) . "\n";
|
---|
| 261 | }
|
---|
[196] | 262 |
|
---|
[205] | 263 | system(@_);
|
---|
| 264 | if ( $? == -1 ) {
|
---|
| 265 | printf "failed to execute: $!\n";
|
---|
| 266 | } elsif ( $? & 127 ) {
|
---|
| 267 | printf "child died with signal %d, %s coredump\n", ( $? & 127 ),
|
---|
| 268 | ( $? & 128 ) ? 'with' : 'without';
|
---|
| 269 | } elsif ( $? >> 8 != 0 ) {
|
---|
| 270 | printf "child exited with value %d\n", $? >> 8;
|
---|
| 271 | }
|
---|
| 272 | return ( $? >> 8 );
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | sub svn_check_credentials( $$ )
|
---|
[196] | 276 | {
|
---|
[205] | 277 | my $username = shift;
|
---|
| 278 | my $password = shift;
|
---|
| 279 |
|
---|
| 280 | ( my $rc_update, my @result ) =
|
---|
| 281 | run_command(
|
---|
| 282 | "$SVN info --non-interactive --no-auth-cache --username $username --password $password $DASSCM_SVN_REPOSITORY"
|
---|
| 283 | );
|
---|
| 284 |
|
---|
| 285 | print @result;
|
---|
| 286 |
|
---|
| 287 | if ( $rc_update != 0 ) {
|
---|
| 288 | die;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
[196] | 291 | }
|
---|
| 292 |
|
---|
[205] | 293 | sub svn_update( ;$ )
|
---|
| 294 | {
|
---|
| 295 | my $update_path = shift || $DASSCM_REPO;
|
---|
| 296 | ( my $rc_update, my @result ) =
|
---|
| 297 | run_command("$SVN update $svnCheckoutCredentials $update_path");
|
---|
[215] | 298 | print @result;
|
---|
[205] | 299 | if ( $rc_update != 0 ) {
|
---|
| 300 | die;
|
---|
| 301 | }
|
---|
[215] | 302 | }
|
---|
[196] | 303 |
|
---|
[215] | 304 | sub svn_getStoredFiles( ;$ )
|
---|
| 305 | {
|
---|
[205] | 306 |
|
---|
[215] | 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 ) {
|
---|
| 314 | print @result;
|
---|
| 315 | die;
|
---|
| 316 | }
|
---|
| 317 | chomp(@result);
|
---|
| 318 | return @result;
|
---|
[205] | 319 | }
|
---|
| 320 |
|
---|
[189] | 321 | #####################################################################
|
---|
| 322 | #
|
---|
[186] | 323 | # functions
|
---|
| 324 |
|
---|
| 325 | sub help(;@)
|
---|
| 326 | {
|
---|
[205] | 327 | if ( @_ == 0 ) {
|
---|
| 328 | usage();
|
---|
| 329 | } else {
|
---|
| 330 | print "help for @_: ...\n";
|
---|
[214] | 331 | usage();
|
---|
[205] | 332 | }
|
---|
[186] | 333 | }
|
---|
| 334 |
|
---|
[203] | 335 | sub login(@)
|
---|
| 336 | {
|
---|
[205] | 337 | check_parameter( @_, 1 );
|
---|
| 338 | check_env();
|
---|
[203] | 339 |
|
---|
[214] | 340 | my $input_username = $1;
|
---|
| 341 |
|
---|
| 342 | if ( not $input_username ) {
|
---|
| 343 | my $output_username = "";
|
---|
| 344 | if ($DASSCM_USERNAME) {
|
---|
| 345 | $output_username = " ($DASSCM_USERNAME)";
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | print "Enter DASSCM user name", $output_username, ": ";
|
---|
| 349 | $input_username = <STDIN>;
|
---|
| 350 | chomp($input_username);
|
---|
[205] | 351 | }
|
---|
[203] | 352 |
|
---|
[205] | 353 | # hidden password input
|
---|
| 354 | print "Enter DASSCM user password: ";
|
---|
| 355 | ReadMode('noecho');
|
---|
| 356 | my $input_password = <STDIN>;
|
---|
| 357 | ReadMode('normal');
|
---|
| 358 | chomp($input_password);
|
---|
[203] | 359 |
|
---|
[205] | 360 | svn_check_credentials( $input_username, $input_password );
|
---|
| 361 |
|
---|
| 362 | #
|
---|
| 363 | # set environment variables
|
---|
| 364 | #
|
---|
| 365 | $ENV{'DASSCM_USERNAME'} = $input_username;
|
---|
| 366 | $ENV{'DASSCM_PASSWORD'} = $input_password;
|
---|
| 367 |
|
---|
[209] | 368 | print "subversion access okay\n\n", "DASSCM_USERNAME: $input_username\n",
|
---|
| 369 | "DASSCM_PASSWORD: (hidden)\n", "DASSCM_PROD: $DASSCM_PROD\n",
|
---|
| 370 | "DASSCM_REPO: $DASSCM_REPO\n",
|
---|
| 371 | "Server Repository: $DASSCM_SVN_REPOSITORY\n", "\n", "[dasscm shell]\n\n";
|
---|
[205] | 372 |
|
---|
[209] | 373 | exec("bash") or die "failed to start new shell";
|
---|
[203] | 374 | }
|
---|
| 375 |
|
---|
[205] | 376 | sub init(@)
|
---|
| 377 | {
|
---|
| 378 | check_parameter( @_, 1 );
|
---|
| 379 | check_env();
|
---|
| 380 |
|
---|
| 381 | # update complete repository
|
---|
[216] | 382 | # and create permission file
|
---|
[208] | 383 | my $retcode =
|
---|
| 384 | run_interactive(
|
---|
[216] | 385 | "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY; touch $permissions_file"
|
---|
[208] | 386 | );
|
---|
[205] | 387 | }
|
---|
| 388 |
|
---|
[215] | 389 | sub ls(@)
|
---|
[186] | 390 | {
|
---|
[205] | 391 | check_parameter( @_, 1 );
|
---|
| 392 | check_env();
|
---|
[186] | 393 |
|
---|
[215] | 394 | my @files = svn_getStoredFiles(@_);
|
---|
| 395 |
|
---|
| 396 | print join( "\n", @files );
|
---|
| 397 | print "\n";
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 |
|
---|
| 401 | sub update(@)
|
---|
| 402 | {
|
---|
| 403 | check_parameter( @_, 1 );
|
---|
| 404 | check_env();
|
---|
| 405 |
|
---|
| 406 | #
|
---|
| 407 | # update local repository
|
---|
| 408 | #
|
---|
| 409 | svn_update();
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 |
|
---|
| 413 | sub add_helper(@)
|
---|
| 414 | {
|
---|
[205] | 415 | (
|
---|
| 416 | my $basename,
|
---|
| 417 | my $dirname_prod,
|
---|
| 418 | my $dirname_repo,
|
---|
| 419 | my $filename_prod,
|
---|
| 420 | my $filename_repo
|
---|
| 421 | )
|
---|
| 422 | = get_filenames( $_[0] );
|
---|
[186] | 423 |
|
---|
[205] | 424 | if ( $command eq "add" ) {
|
---|
| 425 | mkpath($dirname_repo);
|
---|
| 426 | }
|
---|
[186] | 427 |
|
---|
[205] | 428 | copy( $filename_prod, $filename_repo ) or die $!;
|
---|
| 429 |
|
---|
| 430 | if ( $command eq "add" ) {
|
---|
| 431 |
|
---|
| 432 | # already checked in?
|
---|
| 433 | chdir($DASSCM_REPO);
|
---|
| 434 |
|
---|
| 435 | # also add the path to filename.
|
---|
| 436 | for my $dir ( split( '/', $dirname_prod ) ) {
|
---|
| 437 | if ($dir) {
|
---|
| 438 | run_command("$SVN add --non-recursive $dir");
|
---|
| 439 | chdir $dir;
|
---|
| 440 | }
|
---|
| 441 | }
|
---|
| 442 | run_command("$SVN add $basename");
|
---|
| 443 | }
|
---|
[215] | 444 | }
|
---|
[205] | 445 |
|
---|
[215] | 446 |
|
---|
| 447 |
|
---|
| 448 | #
|
---|
| 449 | # add (is used for command add and commit)
|
---|
| 450 | #
|
---|
| 451 | sub add(@)
|
---|
| 452 | {
|
---|
| 453 | check_parameter( @_, 1 );
|
---|
| 454 | check_env();
|
---|
| 455 |
|
---|
| 456 | #
|
---|
| 457 | # update local repository
|
---|
| 458 | #
|
---|
| 459 | svn_update();
|
---|
| 460 |
|
---|
| 461 | # add file
|
---|
| 462 | add_helper( $_[0] );
|
---|
| 463 | # create new permissions file
|
---|
| 464 | permissions();
|
---|
| 465 | # add permissions file
|
---|
| 466 | add_helper( $permissions_file );
|
---|
| 467 |
|
---|
[205] | 468 | if ( $options{'message'} ) {
|
---|
| 469 | $svnOptions .= " --message \"$options{'message'}\" ";
|
---|
| 470 | }
|
---|
| 471 |
|
---|
| 472 | # commit calls $EDITOR. uses "interactive" here, to display output
|
---|
[215] | 473 | my $retcode =
|
---|
[205] | 474 | run_interactive(
|
---|
[208] | 475 | "$SVN commit $svnOptions --username $DASSCM_USERNAME $svnPasswordCredentials $DASSCM_REPO"
|
---|
| 476 | );
|
---|
[205] | 477 |
|
---|
[215] | 478 | #print $filename_prod. "\n";
|
---|
| 479 | #print $dirname_repo. "\n";
|
---|
[186] | 480 | }
|
---|
| 481 |
|
---|
[215] | 482 |
|
---|
| 483 |
|
---|
[193] | 484 | sub blame(@)
|
---|
| 485 | {
|
---|
[205] | 486 | check_parameter( @_, 1 );
|
---|
| 487 | check_env();
|
---|
[193] | 488 |
|
---|
[205] | 489 | (
|
---|
| 490 | my $basename,
|
---|
| 491 | my $dirname_prod,
|
---|
| 492 | my $dirname_repo,
|
---|
| 493 | my $filename_prod,
|
---|
| 494 | my $filename_repo
|
---|
| 495 | )
|
---|
| 496 | = get_filenames( $_[0] );
|
---|
| 497 |
|
---|
| 498 | my $retcode = run_interactive("$SVN blame $svnOptions $filename_repo");
|
---|
[193] | 499 | }
|
---|
| 500 |
|
---|
[187] | 501 | sub diff(@)
|
---|
| 502 | {
|
---|
[205] | 503 | check_parameter( @_, 1 );
|
---|
| 504 | check_env();
|
---|
[187] | 505 |
|
---|
[205] | 506 | (
|
---|
| 507 | my $basename,
|
---|
| 508 | my $dirname_prod,
|
---|
| 509 | my $dirname_repo,
|
---|
| 510 | my $filename_prod,
|
---|
| 511 | my $filename_repo
|
---|
| 512 | )
|
---|
| 513 | = get_filenames( $_[0] );
|
---|
| 514 |
|
---|
| 515 | #print "$basename,$dirname_prod,$dirname_repo\n";
|
---|
| 516 |
|
---|
| 517 | ( my $rc_update, my @result ) = run_command("$SVN update $filename_repo");
|
---|
| 518 | if ( $rc_update != 0 ) {
|
---|
| 519 | print @result;
|
---|
| 520 | die;
|
---|
| 521 | }
|
---|
| 522 |
|
---|
| 523 | ( my $rc_diff, my @diff ) =
|
---|
| 524 | run_command("diff $filename_repo $filename_prod");
|
---|
| 525 | print @diff;
|
---|
[187] | 526 | }
|
---|
| 527 |
|
---|
[209] | 528 | sub status(@)
|
---|
| 529 | {
|
---|
| 530 | check_parameter( @_, 1 );
|
---|
| 531 | check_env();
|
---|
| 532 |
|
---|
| 533 | #
|
---|
| 534 | # update local repository
|
---|
| 535 | #
|
---|
| 536 | svn_update();
|
---|
| 537 |
|
---|
| 538 | # TODO: start at subdirectories ?
|
---|
[215] | 539 | my $dir = $DASSCM_REPO;
|
---|
| 540 | my @files = svn_getStoredFiles($dir);
|
---|
[209] | 541 |
|
---|
| 542 | # Liste der geänderten Files ausgeben, falls nicht leer
|
---|
[215] | 543 | if (@files) {
|
---|
[209] | 544 |
|
---|
[215] | 545 | # stores result from status (cvscheck)
|
---|
| 546 | my %removedfiles = ();
|
---|
| 547 | my %changedfiles = ();
|
---|
| 548 |
|
---|
| 549 | foreach my $file (@files) {
|
---|
| 550 |
|
---|
| 551 | my $realfile = "/" . $file;
|
---|
| 552 | my $cvsworkfile = "${DASSCM_REPO}/${file}";
|
---|
| 553 |
|
---|
| 554 | if ( -d $realfile ) {
|
---|
| 555 |
|
---|
| 556 | # directory. do nothing
|
---|
| 557 | } elsif ( !-r $realfile ) {
|
---|
| 558 | $removedfiles{"$realfile"} = $cvsworkfile;
|
---|
| 559 | } else {
|
---|
| 560 | ( -r "$cvsworkfile" )
|
---|
| 561 | || die("Fehler: $cvsworkfile ist nicht lesbar");
|
---|
| 562 | if ( compare( $cvsworkfile, $realfile ) != 0 ) {
|
---|
| 563 | $changedfiles{"$realfile"} = $cvsworkfile;
|
---|
| 564 | }
|
---|
| 565 | }
|
---|
| 566 | }
|
---|
| 567 |
|
---|
| 568 | if (%removedfiles) {
|
---|
| 569 | print "deleted files (found in repository, but not in system):\n";
|
---|
| 570 | foreach my $key ( values %removedfiles ) {
|
---|
[209] | 571 | print "$key\n";
|
---|
| 572 | }
|
---|
| 573 | print "\n";
|
---|
| 574 | }
|
---|
| 575 |
|
---|
[215] | 576 | if (%changedfiles) {
|
---|
[209] | 577 | print "modified files:\n";
|
---|
[215] | 578 | foreach my $key ( keys %changedfiles ) {
|
---|
[209] | 579 | print "$key\n";
|
---|
| 580 | }
|
---|
| 581 | }
|
---|
| 582 | } else {
|
---|
[215] | 583 | print "no modified files found in $dir\n";
|
---|
[209] | 584 | }
|
---|
[215] | 585 |
|
---|
[209] | 586 | print "\n";
|
---|
[215] | 587 | }
|
---|
[209] | 588 |
|
---|
[215] | 589 |
|
---|
| 590 |
|
---|
| 591 | sub permissions(@)
|
---|
| 592 | {
|
---|
| 593 | check_parameter( @_, 1 );
|
---|
| 594 | check_env();
|
---|
| 595 |
|
---|
| 596 | #
|
---|
| 597 | # update local repository
|
---|
| 598 | #
|
---|
| 599 | #svn_update();
|
---|
| 600 |
|
---|
| 601 | # TODO: start at subdirectories ?
|
---|
| 602 | my $dir = $DASSCM_REPO;
|
---|
| 603 | my @files = svn_getStoredFiles($dir);
|
---|
| 604 |
|
---|
| 605 | if (@files) {
|
---|
| 606 |
|
---|
| 607 | # generieren der Permissions
|
---|
| 608 | my @permissions = generatePermissionList(@files);
|
---|
| 609 | my $OUTFILE;
|
---|
| 610 | my $tofile = 0; # Status für schreiben in File
|
---|
| 611 |
|
---|
| 612 | if ( -w dirname($permissions_file) ) {
|
---|
| 613 |
|
---|
| 614 | # Verzeichnis existiert => schreiben
|
---|
| 615 | print "storing permissions in file $permissions_file\n";
|
---|
| 616 | open( OUTFILE, ">$permissions_file" )
|
---|
[216] | 617 | || die("failed to write to $permissions_file: $!");
|
---|
[215] | 618 | $tofile = 1; # Merken, daß in File geschrieben wird
|
---|
| 619 | print OUTFILE "#\n";
|
---|
| 620 | print OUTFILE "# created by dasscm permissions\n";
|
---|
| 621 | print OUTFILE "# It is intended to be used for restoring permissions\n";
|
---|
| 622 | } else {
|
---|
| 623 |
|
---|
| 624 | # Pfad für Sicherungsdatei existiert nicht => schreiben auf stdout
|
---|
| 625 | # Alias Filehandle für stdout erzeugen
|
---|
| 626 | *OUTFILE = *STDOUT;
|
---|
| 627 | }
|
---|
| 628 | foreach my $line (@permissions) {
|
---|
| 629 | print OUTFILE "$line\n";
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 | if ($tofile) {
|
---|
| 633 | close(OUTFILE);
|
---|
| 634 | }
|
---|
| 635 | }
|
---|
[209] | 636 | }
|
---|
| 637 |
|
---|
[189] | 638 | #####################################################################
|
---|
| 639 | #
|
---|
[186] | 640 | # main
|
---|
[189] | 641 | #
|
---|
[186] | 642 |
|
---|
| 643 | my $number_arguments = @ARGV;
|
---|
| 644 |
|
---|
[205] | 645 | if ( $number_arguments > 0 ) {
|
---|
[186] | 646 |
|
---|
[205] | 647 | # get subcommand and remove it from @ARGV
|
---|
| 648 | $command = $ARGV[0];
|
---|
| 649 | shift @ARGV;
|
---|
[196] | 650 |
|
---|
[205] | 651 | $DASSCM_LOCAL_REPOSITORY_BASE = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'};
|
---|
| 652 | $DASSCM_REPOSITORY_NAME = $config->{'DASSCM_REPOSITORY_NAME'};
|
---|
[196] | 653 |
|
---|
[205] | 654 | # TODO: check variables
|
---|
| 655 | $DASSCM_SVN_REPOSITORY =
|
---|
| 656 | $config->{'DASSCM_SVN_REPOSITORY_BASE'} . "/" . $DASSCM_REPOSITORY_NAME;
|
---|
| 657 |
|
---|
| 658 | my $DASSCM_CHECKOUT_USERNAME = $config->{'DASSCM_CHECKOUT_USERNAME'};
|
---|
| 659 | my $DASSCM_CHECKOUT_PASSWORD = $config->{'DASSCM_CHECKOUT_PASSWORD'};
|
---|
| 660 |
|
---|
| 661 | #
|
---|
| 662 | # if a user is given by dasscm configuration file, we use it.
|
---|
| 663 | # Otherwise we expect that read-only account is configured
|
---|
| 664 | # as local subversion configuration.
|
---|
| 665 | # If this is also not the case,
|
---|
| 666 | # user is required to type username and password.
|
---|
| 667 | # This will be stored as local subversion configuration thereafter.
|
---|
| 668 | #
|
---|
| 669 | if ( $DASSCM_CHECKOUT_USERNAME && $DASSCM_CHECKOUT_PASSWORD ) {
|
---|
| 670 | $svnCheckoutCredentials =
|
---|
| 671 | " --username $DASSCM_CHECKOUT_USERNAME --password $DASSCM_CHECKOUT_PASSWORD ";
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | # get command line options and store them in options hash
|
---|
[214] | 675 | my $result = GetOptions( \%options, 'verbose', 'message=s' );
|
---|
[205] | 676 |
|
---|
| 677 | # print options
|
---|
| 678 | foreach my $option ( keys %options ) {
|
---|
[215] | 679 | print "${option}: $options{$option}\n";
|
---|
[205] | 680 | }
|
---|
| 681 |
|
---|
[214] | 682 | # set verbose to command line option
|
---|
| 683 | $verbose = $options{'verbose'};
|
---|
| 684 |
|
---|
| 685 | #
|
---|
| 686 | # action accordinly to command are taken
|
---|
| 687 | # $command is rewritten in standard format,
|
---|
| 688 | # so we can test for it later on more simply
|
---|
| 689 | #
|
---|
[205] | 690 | $_ = $command;
|
---|
| 691 | if (m/help/i) {
|
---|
| 692 | help(@ARGV);
|
---|
| 693 | } elsif (m/login/i) {
|
---|
[208] | 694 | $command = "login";
|
---|
[205] | 695 | login(@ARGV);
|
---|
| 696 | } elsif (m/init/i) {
|
---|
[208] | 697 | $command = "init";
|
---|
[205] | 698 | init(@ARGV);
|
---|
[215] | 699 | } elsif (m/ls/i) {
|
---|
| 700 | $command = "ls";
|
---|
| 701 | ls(@ARGV);
|
---|
| 702 | } elsif (m/up/i) {
|
---|
| 703 | $command = "update";
|
---|
| 704 | update(@ARGV);
|
---|
[205] | 705 | } elsif (m/add/i) {
|
---|
| 706 | $command = "add";
|
---|
| 707 | add(@ARGV);
|
---|
| 708 | } elsif (m/commit/i) {
|
---|
| 709 | $command = "commit";
|
---|
| 710 | add(@ARGV);
|
---|
| 711 | } elsif (m/blame/i) {
|
---|
[208] | 712 | $command = "blame";
|
---|
[205] | 713 | blame(@ARGV);
|
---|
| 714 | } elsif (m/diff/i) {
|
---|
[208] | 715 | $command = "diff";
|
---|
[205] | 716 | diff(@ARGV);
|
---|
[209] | 717 | } elsif (m/status/i) {
|
---|
| 718 | $command = "status";
|
---|
| 719 | status(@ARGV);
|
---|
[215] | 720 | } elsif (m/permissions/i) {
|
---|
| 721 | $command = "permissions";
|
---|
| 722 | permissions(@ARGV);
|
---|
[205] | 723 | } else {
|
---|
[215] | 724 | print "unknown command: $command\n\n";
|
---|
[205] | 725 | usage();
|
---|
| 726 | check_env();
|
---|
| 727 | }
|
---|
| 728 |
|
---|
| 729 | # up
|
---|
[209] | 730 | # cleanup (svn-commit.tmp)
|
---|
[205] | 731 | # commitall
|
---|
| 732 | # revert
|
---|
[215] | 733 | # activate
|
---|
[186] | 734 | }
|
---|