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