[186] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | # $Id: dasscm 267 2009-03-03 14:51:23Z 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) {
|
---|
[267] | 249 | $svnPasswordCredentials = " --password '$DASSCM_PASSWORD' ";
|
---|
[205] | 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 |
|
---|
[256] | 304 |
|
---|
| 305 |
|
---|
| 306 | #
|
---|
| 307 | # creates a file with permissions
|
---|
| 308 | #
|
---|
[215] | 309 | sub generatePermissionList
|
---|
[209] | 310 | {
|
---|
| 311 |
|
---|
[215] | 312 | # generieren der Zeilen für Permission-Savefile
|
---|
| 313 | my @files = @_;
|
---|
| 314 | my @permlist = ();
|
---|
| 315 | foreach my $file (@files) {
|
---|
[227] | 316 | $file = "/" . $file;
|
---|
[239] | 317 | if ( -e $file ) {
|
---|
| 318 | my $info = stat($file) || die "failed to stat $file: aborting";
|
---|
| 319 | my $mode = get_type( $info->mode ) & 07777;
|
---|
[227] | 320 | my $modestring = sprintf( "%04o", $mode );
|
---|
| 321 | my $uid = $info->uid;
|
---|
| 322 | my $uidname = getpwuid($uid);
|
---|
| 323 | my $gid = $info->gid;
|
---|
| 324 | my $gidname = getgrgid($gid);
|
---|
| 325 | push(
|
---|
| 326 | @permlist,
|
---|
| 327 | sprintf( "%-55s %-17s %4d",
|
---|
| 328 | $file, "${uidname}:${gidname}", $modestring )
|
---|
| 329 | );
|
---|
| 330 | } else {
|
---|
[239] | 331 | print
|
---|
| 332 | "failed to get status of $file. It exists in the repository, but not on the system\n";
|
---|
[227] | 333 | }
|
---|
[215] | 334 | }
|
---|
| 335 | return @permlist;
|
---|
| 336 | }
|
---|
[209] | 337 |
|
---|
[215] | 338 | sub get_type
|
---|
| 339 | {
|
---|
[209] | 340 |
|
---|
[215] | 341 | # Funktion übernommen aus /usr/bin/chkstat
|
---|
| 342 | my $S_IFLNK = 0120000; # symbolic link
|
---|
| 343 | my $S_IFREG = 0100000; # regular file
|
---|
| 344 | my $S_IFDIR = 0040000; # directory
|
---|
| 345 | my $S_IFCHAR = 0020000; # character device
|
---|
| 346 | my $S_IFBLK = 0060000; # block device
|
---|
| 347 | my $S_IFFIFO = 0010000; # fifo
|
---|
| 348 | my $S_IFSOCK = 0140000; # socket
|
---|
| 349 | my $S_IFMT = 0170000; # type of file
|
---|
[209] | 350 |
|
---|
[215] | 351 | my $S_m;
|
---|
| 352 | if ( ( $_[0] & $S_IFMT ) == $S_IFLNK ) { $S_m = $_[0] - $S_IFLNK; }
|
---|
| 353 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFREG ) { $S_m = $_[0] - $S_IFREG; }
|
---|
| 354 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFDIR ) { $S_m = $_[0] - $S_IFDIR; }
|
---|
| 355 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFCHAR ) { $S_m = $_[0] - $S_IFCHAR; }
|
---|
| 356 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFBLK ) { $S_m = $_[0] - $S_IFBLK; }
|
---|
| 357 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFFIFO ) { $S_m = $_[0] - $S_IFFIFO; }
|
---|
| 358 | elsif ( ( $_[0] & $S_IFMT ) == $S_IFSOCK ) { $S_m = $_[0] - $S_IFSOCK; }
|
---|
| 359 | $S_m;
|
---|
[209] | 360 | }
|
---|
| 361 |
|
---|
[186] | 362 | sub run_command
|
---|
| 363 | {
|
---|
[205] | 364 | my $command = shift;
|
---|
[186] | 365 |
|
---|
[205] | 366 | #print "executing command: " . $command . "\n";
|
---|
[186] | 367 |
|
---|
[205] | 368 | open( RESULT, $command . ' 2>&1 |' );
|
---|
| 369 | my @result = <RESULT>;
|
---|
| 370 | close(RESULT);
|
---|
| 371 | my $retcode = $? >> 8;
|
---|
[186] | 372 |
|
---|
[205] | 373 | #print @result;
|
---|
| 374 | #if( $retcode ) { print "return code: " . $retcode . "\n"; }
|
---|
[186] | 375 |
|
---|
[205] | 376 | return ( $retcode, @result );
|
---|
[186] | 377 | }
|
---|
| 378 |
|
---|
[205] | 379 | sub run_interactive
|
---|
| 380 | {
|
---|
[186] | 381 |
|
---|
[208] | 382 | if ($verbose) {
|
---|
[205] | 383 | print "run_interactive:" . join( " ", @_ ) . "\n";
|
---|
| 384 | }
|
---|
[196] | 385 |
|
---|
[205] | 386 | system(@_);
|
---|
| 387 | if ( $? == -1 ) {
|
---|
| 388 | printf "failed to execute: $!\n";
|
---|
| 389 | } elsif ( $? & 127 ) {
|
---|
| 390 | printf "child died with signal %d, %s coredump\n", ( $? & 127 ),
|
---|
| 391 | ( $? & 128 ) ? 'with' : 'without';
|
---|
| 392 | } elsif ( $? >> 8 != 0 ) {
|
---|
| 393 | printf "child exited with value %d\n", $? >> 8;
|
---|
| 394 | }
|
---|
| 395 | return ( $? >> 8 );
|
---|
| 396 | }
|
---|
| 397 |
|
---|
[247] | 398 | sub svn_check_credentials( $$;$$ )
|
---|
[196] | 399 | {
|
---|
[205] | 400 | my $username = shift;
|
---|
| 401 | my $password = shift;
|
---|
| 402 |
|
---|
[252] | 403 | # check silently are allow user interaction?
|
---|
[247] | 404 | my $interactive = shift || 0;
|
---|
[220] | 405 |
|
---|
[247] | 406 | # default: exit program, if repository is not accessable
|
---|
| 407 | # (do not exit for 'init')
|
---|
| 408 | my $fatalerror = shift || 1;
|
---|
| 409 |
|
---|
| 410 | print "checking credentials ";
|
---|
| 411 |
|
---|
[239] | 412 | if ( !$username ) {
|
---|
| 413 | fatalerror("no username given");
|
---|
[238] | 414 | }
|
---|
| 415 |
|
---|
[239] | 416 | if ( !$password ) {
|
---|
| 417 | fatalerror("no password given");
|
---|
[238] | 418 | }
|
---|
| 419 |
|
---|
[247] | 420 | print "for " . $username . "@" . $DASSCM_SVN_REPOSITORY . ": ";
|
---|
| 421 |
|
---|
[220] | 422 | # Options for "svn info" are not supported by subversion 1.0.0 (SLES9),
|
---|
| 423 | # therefore switching to "svn status"
|
---|
| 424 | # ( my $rc_update, my @result ) =
|
---|
| 425 | # run_command(
|
---|
| 426 | # "$SVN info --non-interactive --no-auth-cache --username $username --password $password $DASSCM_SVN_REPOSITORY"
|
---|
| 427 | # );
|
---|
| 428 | #print @result;
|
---|
| 429 |
|
---|
[247] | 430 | my $rc_update;
|
---|
[252] | 431 | if ($interactive) {
|
---|
| 432 | $rc_update =
|
---|
| 433 | run_interactive(
|
---|
[267] | 434 | "$SVN ls --no-auth-cache --username '$username' --password '$password' $DASSCM_SVN_REPOSITORY"
|
---|
[252] | 435 | );
|
---|
[247] | 436 | } else {
|
---|
| 437 | ( $rc_update, my @result ) =
|
---|
[252] | 438 | run_command(
|
---|
[267] | 439 | "$SVN ls --non-interactive --no-auth-cache --username '$username' --password '$password' $DASSCM_SVN_REPOSITORY"
|
---|
[252] | 440 | );
|
---|
| 441 |
|
---|
[247] | 442 | if ( $rc_update != 0 ) {
|
---|
| 443 | print "\n", @result;
|
---|
[252] | 444 | if ($fatalerror) {
|
---|
[247] | 445 | fatalerror();
|
---|
| 446 | }
|
---|
| 447 | return;
|
---|
| 448 | }
|
---|
[205] | 449 | }
|
---|
| 450 |
|
---|
[247] | 451 | # return success
|
---|
| 452 | return $rc_update == 0;
|
---|
[196] | 453 | }
|
---|
| 454 |
|
---|
[205] | 455 | sub svn_update( ;$ )
|
---|
| 456 | {
|
---|
| 457 | my $update_path = shift || $DASSCM_REPO;
|
---|
| 458 | ( my $rc_update, my @result ) =
|
---|
[220] | 459 | run_command(
|
---|
| 460 | "$SVN update --non-interactive $svnCheckoutCredentials $update_path");
|
---|
[215] | 461 | print @result;
|
---|
[205] | 462 | if ( $rc_update != 0 ) {
|
---|
[238] | 463 | fatalerror();
|
---|
[205] | 464 | }
|
---|
[215] | 465 | }
|
---|
[196] | 466 |
|
---|
[215] | 467 | sub svn_getStoredFiles( ;$ )
|
---|
| 468 | {
|
---|
[220] | 469 |
|
---|
[215] | 470 | # TODO: get_filenames?
|
---|
| 471 | #my $rel_path = shift || "";
|
---|
| 472 | #my $path = "${DASSCM_REPO}/${rel_path}";
|
---|
| 473 | my $path = ${DASSCM_REPO};
|
---|
[220] | 474 |
|
---|
[218] | 475 | # svn ls -R is better, but much, much slower
|
---|
| 476 | # ( my $rc, my @result ) = run_command("$SVN ls --recursive $svnCheckoutCredentials $path");
|
---|
[220] | 477 | ( my $rc, my @result ) =
|
---|
| 478 | run_command(
|
---|
[249] | 479 | "cd $path && find | grep -v '/.svn' | sed -e 's/\.\\///' | grep -v '^[\.]\$'"
|
---|
[220] | 480 | );
|
---|
[215] | 481 | if ( $rc != 0 ) {
|
---|
| 482 | print @result;
|
---|
[238] | 483 | fatalerror;
|
---|
[215] | 484 | }
|
---|
| 485 | chomp(@result);
|
---|
| 486 | return @result;
|
---|
[205] | 487 | }
|
---|
| 488 |
|
---|
[238] | 489 | #
|
---|
| 490 | # from an array of files/dirs,
|
---|
| 491 | # generates list of files
|
---|
| 492 | # sorted by type
|
---|
| 493 | #
|
---|
[237] | 494 | sub get_files( @ )
|
---|
| 495 | {
|
---|
| 496 | my @files = ();
|
---|
| 497 | my @links = ();
|
---|
| 498 | my @dirs = ();
|
---|
| 499 | my @others = ();
|
---|
| 500 |
|
---|
[239] | 501 | if (@_) {
|
---|
| 502 | find(
|
---|
| 503 | {
|
---|
| 504 | wanted => sub {
|
---|
| 505 | my $fullname = cwd() . "/" . $_;
|
---|
| 506 | if ( -l $_ ) {
|
---|
| 507 |
|
---|
| 508 | # soft link
|
---|
| 509 | # important: check for links first
|
---|
| 510 | # to exclude them from further checks
|
---|
| 511 | push( @links, $fullname );
|
---|
| 512 | } elsif ( -d $_ ) {
|
---|
| 513 | push( @dirs, $fullname );
|
---|
| 514 | } elsif ( -f $_ ) {
|
---|
| 515 |
|
---|
| 516 | # regular file
|
---|
| 517 | push( @files, $fullname );
|
---|
| 518 | } else {
|
---|
| 519 | push( @others, $fullname );
|
---|
| 520 | }
|
---|
| 521 | }
|
---|
| 522 | },
|
---|
| 523 | @_
|
---|
| 524 | );
|
---|
[237] | 525 | }
|
---|
| 526 |
|
---|
[239] | 527 | # don't rely on others.
|
---|
[237] | 528 | # If more specific file types are needed,
|
---|
| 529 | # they will be added
|
---|
| 530 | return {
|
---|
[239] | 531 | files => \@files,
|
---|
| 532 | links => \@links,
|
---|
| 533 | dirs => \@dirs,
|
---|
| 534 | others => \@others
|
---|
| 535 | };
|
---|
[237] | 536 | }
|
---|
| 537 |
|
---|
[189] | 538 | #####################################################################
|
---|
| 539 | #
|
---|
[186] | 540 | # functions
|
---|
| 541 |
|
---|
| 542 | sub help(;@)
|
---|
| 543 | {
|
---|
[205] | 544 | if ( @_ == 0 ) {
|
---|
| 545 | usage();
|
---|
| 546 | } else {
|
---|
| 547 | print "help for @_: ...\n";
|
---|
[214] | 548 | usage();
|
---|
[205] | 549 | }
|
---|
[186] | 550 | }
|
---|
| 551 |
|
---|
[203] | 552 | sub login(@)
|
---|
| 553 | {
|
---|
[205] | 554 | check_parameter( @_, 1 );
|
---|
| 555 | check_env();
|
---|
[203] | 556 |
|
---|
[235] | 557 | my $input_username = $_[0];
|
---|
[214] | 558 |
|
---|
| 559 | if ( not $input_username ) {
|
---|
| 560 | my $output_username = "";
|
---|
| 561 | if ($DASSCM_USERNAME) {
|
---|
| 562 | $output_username = " ($DASSCM_USERNAME)";
|
---|
| 563 | }
|
---|
| 564 |
|
---|
| 565 | print "Enter DASSCM user name", $output_username, ": ";
|
---|
| 566 | $input_username = <STDIN>;
|
---|
| 567 | chomp($input_username);
|
---|
[247] | 568 |
|
---|
| 569 | $input_username = $input_username || $DASSCM_USERNAME;
|
---|
[205] | 570 | }
|
---|
[203] | 571 |
|
---|
[205] | 572 | # hidden password input
|
---|
[247] | 573 | print "Enter password for $input_username: ";
|
---|
[205] | 574 | ReadMode('noecho');
|
---|
| 575 | my $input_password = <STDIN>;
|
---|
| 576 | ReadMode('normal');
|
---|
| 577 | chomp($input_password);
|
---|
[220] | 578 | print "\n";
|
---|
[203] | 579 |
|
---|
[247] | 580 | # checking checkout username/password
|
---|
[252] | 581 | svn_check_credentials( $DASSCM_CHECKOUT_USERNAME,
|
---|
| 582 | $DASSCM_CHECKOUT_PASSWORD );
|
---|
[247] | 583 | print "checkout access okay\n";
|
---|
[205] | 584 |
|
---|
[247] | 585 | svn_check_credentials( $input_username, $input_password );
|
---|
| 586 |
|
---|
[205] | 587 | #
|
---|
| 588 | # set environment variables
|
---|
| 589 | #
|
---|
[267] | 590 | $ENV{'DASSCM_USERNAME'} = "$input_username";
|
---|
| 591 | $ENV{'DASSCM_PASSWORD'} = "$input_password";
|
---|
[205] | 592 |
|
---|
[209] | 593 | print "subversion access okay\n\n", "DASSCM_USERNAME: $input_username\n",
|
---|
| 594 | "DASSCM_PASSWORD: (hidden)\n", "DASSCM_PROD: $DASSCM_PROD\n",
|
---|
| 595 | "DASSCM_REPO: $DASSCM_REPO\n",
|
---|
| 596 | "Server Repository: $DASSCM_SVN_REPOSITORY\n", "\n", "[dasscm shell]\n\n";
|
---|
[205] | 597 |
|
---|
[235] | 598 | my $shell = $SHELL || "bash";
|
---|
| 599 | exec($shell) or die "failed to start new shell";
|
---|
[203] | 600 | }
|
---|
| 601 |
|
---|
[260] | 602 |
|
---|
| 603 | #
|
---|
| 604 | # initialize local checkout directory (initial checkout)
|
---|
| 605 | #
|
---|
[205] | 606 | sub init(@)
|
---|
| 607 | {
|
---|
| 608 | check_parameter( @_, 1 );
|
---|
| 609 | check_env();
|
---|
| 610 |
|
---|
[235] | 611 | # don't do repository creation (svn mkdir) here,
|
---|
| 612 | # because then their must be a lot of prior checks
|
---|
| 613 |
|
---|
[205] | 614 | # update complete repository
|
---|
[216] | 615 | # and create permission file
|
---|
[208] | 616 | my $retcode =
|
---|
| 617 | run_interactive(
|
---|
[252] | 618 | "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY; mkdir -p `dirname $permissions_file`; touch $permissions_file"
|
---|
[208] | 619 | );
|
---|
[205] | 620 | }
|
---|
| 621 |
|
---|
[260] | 622 |
|
---|
| 623 |
|
---|
[215] | 624 | sub ls(@)
|
---|
[186] | 625 | {
|
---|
[205] | 626 | check_parameter( @_, 1 );
|
---|
| 627 | check_env();
|
---|
[186] | 628 |
|
---|
[215] | 629 | my @files = svn_getStoredFiles(@_);
|
---|
| 630 |
|
---|
| 631 | print join( "\n", @files );
|
---|
| 632 | print "\n";
|
---|
| 633 | }
|
---|
| 634 |
|
---|
[267] | 635 |
|
---|
| 636 |
|
---|
[215] | 637 | sub update(@)
|
---|
| 638 | {
|
---|
| 639 | check_parameter( @_, 1 );
|
---|
| 640 | check_env();
|
---|
| 641 |
|
---|
| 642 | #
|
---|
| 643 | # update local repository
|
---|
| 644 | #
|
---|
| 645 | svn_update();
|
---|
| 646 | }
|
---|
| 647 |
|
---|
[237] | 648 | #
|
---|
| 649 | # helper function for "add" command
|
---|
| 650 | #
|
---|
[215] | 651 | sub add_helper(@)
|
---|
| 652 | {
|
---|
[205] | 653 | (
|
---|
| 654 | my $basename,
|
---|
| 655 | my $dirname_prod,
|
---|
| 656 | my $dirname_repo,
|
---|
| 657 | my $filename_prod,
|
---|
| 658 | my $filename_repo
|
---|
| 659 | )
|
---|
| 660 | = get_filenames( $_[0] );
|
---|
[186] | 661 |
|
---|
[205] | 662 | if ( $command eq "add" ) {
|
---|
| 663 | mkpath($dirname_repo);
|
---|
| 664 | }
|
---|
[186] | 665 |
|
---|
[238] | 666 | # TODO: are permissions also copied?
|
---|
[239] | 667 | copy( $filename_prod, $filename_repo )
|
---|
| 668 | or error "failed to copy $filename_prod to repository: $!";
|
---|
[205] | 669 |
|
---|
| 670 | if ( $command eq "add" ) {
|
---|
| 671 |
|
---|
| 672 | # already checked in?
|
---|
[238] | 673 | chdir $DASSCM_REPO;
|
---|
[205] | 674 |
|
---|
| 675 | # also add the path to filename.
|
---|
| 676 | for my $dir ( split( '/', $dirname_prod ) ) {
|
---|
| 677 | if ($dir) {
|
---|
[239] | 678 | my ( $rc, @out ) =
|
---|
| 679 | run_command( "$SVN add --non-recursive \"" . $dir . "\"" );
|
---|
| 680 | if ( $rc > 0 ) {
|
---|
[226] | 681 | print join( "\n", @out );
|
---|
[239] | 682 | }
|
---|
[205] | 683 | chdir $dir;
|
---|
| 684 | }
|
---|
| 685 | }
|
---|
[239] | 686 | my ( $rc, @out ) = run_command( "$SVN add \"" . $basename . "\"" );
|
---|
| 687 | if ( $rc > 0 ) {
|
---|
[226] | 688 | print join( "\n", @out );
|
---|
[239] | 689 | }
|
---|
[238] | 690 | chdir $StartDirectory;
|
---|
[205] | 691 | }
|
---|
[215] | 692 | }
|
---|
[205] | 693 |
|
---|
[215] | 694 | #
|
---|
| 695 | # add (is used for command add and commit)
|
---|
| 696 | #
|
---|
| 697 | sub add(@)
|
---|
| 698 | {
|
---|
| 699 | check_parameter( @_, 1 );
|
---|
| 700 | check_env();
|
---|
| 701 |
|
---|
| 702 | #
|
---|
| 703 | # update local repository
|
---|
| 704 | #
|
---|
| 705 | svn_update();
|
---|
| 706 |
|
---|
[237] | 707 | # get all regular files and links
|
---|
[239] | 708 | my $href_files = get_files(@_);
|
---|
[220] | 709 |
|
---|
[237] | 710 | #print Dumper( $href_files );
|
---|
| 711 |
|
---|
[239] | 712 | my @files = @{ $href_files->{files} };
|
---|
| 713 | my @links = @{ $href_files->{links} };
|
---|
[237] | 714 |
|
---|
[239] | 715 | if (@files) {
|
---|
[237] | 716 | my $number = $#files + 1;
|
---|
| 717 | print "files to check-in ($number): \n";
|
---|
| 718 | print join( "\n", @files );
|
---|
| 719 | print "\n";
|
---|
| 720 | }
|
---|
| 721 |
|
---|
[239] | 722 | if (@links) {
|
---|
[237] | 723 | my $number = $#links + 1;
|
---|
| 724 | print "\n";
|
---|
| 725 | print "ignoring links ($number):\n";
|
---|
| 726 | print join( "\n", @links );
|
---|
| 727 | print "\n";
|
---|
| 728 | }
|
---|
| 729 |
|
---|
[238] | 730 | # TODO: confirm
|
---|
| 731 |
|
---|
[237] | 732 | # copy files one by one to local repository
|
---|
| 733 | for my $file (@files) {
|
---|
[239] | 734 |
|
---|
[233] | 735 | # add file
|
---|
[239] | 736 | add_helper($file);
|
---|
[233] | 737 | }
|
---|
| 738 |
|
---|
[215] | 739 | # create new permissions file
|
---|
| 740 | permissions();
|
---|
[220] | 741 |
|
---|
[215] | 742 | # add permissions file
|
---|
[220] | 743 | add_helper($permissions_file);
|
---|
[215] | 744 |
|
---|
[205] | 745 | if ( $options{'message'} ) {
|
---|
| 746 | $svnOptions .= " --message \"$options{'message'}\" ";
|
---|
| 747 | }
|
---|
| 748 |
|
---|
[239] | 749 | # commit calls $EDITOR.
|
---|
[237] | 750 | # use "interactive" here, to display output
|
---|
[215] | 751 | my $retcode =
|
---|
[205] | 752 | run_interactive(
|
---|
[267] | 753 | "$SVN commit $svnOptions --username '$DASSCM_USERNAME' $svnPasswordCredentials $DASSCM_REPO"
|
---|
[208] | 754 | );
|
---|
[205] | 755 |
|
---|
[215] | 756 | #print $filename_prod. "\n";
|
---|
| 757 | #print $dirname_repo. "\n";
|
---|
[186] | 758 | }
|
---|
| 759 |
|
---|
[193] | 760 | sub blame(@)
|
---|
| 761 | {
|
---|
[205] | 762 | check_parameter( @_, 1 );
|
---|
| 763 | check_env();
|
---|
[193] | 764 |
|
---|
[205] | 765 | (
|
---|
| 766 | my $basename,
|
---|
| 767 | my $dirname_prod,
|
---|
| 768 | my $dirname_repo,
|
---|
| 769 | my $filename_prod,
|
---|
| 770 | my $filename_repo
|
---|
| 771 | )
|
---|
| 772 | = get_filenames( $_[0] );
|
---|
| 773 |
|
---|
| 774 | my $retcode = run_interactive("$SVN blame $svnOptions $filename_repo");
|
---|
[193] | 775 | }
|
---|
| 776 |
|
---|
[187] | 777 | sub diff(@)
|
---|
| 778 | {
|
---|
[205] | 779 | check_parameter( @_, 1 );
|
---|
| 780 | check_env();
|
---|
[187] | 781 |
|
---|
[205] | 782 | (
|
---|
| 783 | my $basename,
|
---|
| 784 | my $dirname_prod,
|
---|
| 785 | my $dirname_repo,
|
---|
| 786 | my $filename_prod,
|
---|
| 787 | my $filename_repo
|
---|
| 788 | )
|
---|
| 789 | = get_filenames( $_[0] );
|
---|
| 790 |
|
---|
| 791 | #print "$basename,$dirname_prod,$dirname_repo\n";
|
---|
| 792 |
|
---|
| 793 | ( my $rc_update, my @result ) = run_command("$SVN update $filename_repo");
|
---|
| 794 | if ( $rc_update != 0 ) {
|
---|
| 795 | print @result;
|
---|
| 796 | die;
|
---|
| 797 | }
|
---|
| 798 |
|
---|
[238] | 799 | ( my $rc_diff, my @diff_result ) =
|
---|
[239] | 800 | run_command( $diff . " $filename_repo $filename_prod" );
|
---|
[238] | 801 |
|
---|
| 802 | print @diff_result;
|
---|
[187] | 803 | }
|
---|
| 804 |
|
---|
[209] | 805 | sub status(@)
|
---|
| 806 | {
|
---|
| 807 | check_parameter( @_, 1 );
|
---|
| 808 | check_env();
|
---|
| 809 |
|
---|
[252] | 810 | # return code for the shell
|
---|
| 811 | # default: error
|
---|
| 812 | my $return_code = $RETURN_NOK;
|
---|
| 813 |
|
---|
[209] | 814 | #
|
---|
| 815 | # update local repository
|
---|
| 816 | #
|
---|
| 817 | svn_update();
|
---|
| 818 |
|
---|
| 819 | # TODO: start at subdirectories ?
|
---|
[220] | 820 | my $dir = $DASSCM_REPO;
|
---|
[215] | 821 | my @files = svn_getStoredFiles($dir);
|
---|
[209] | 822 |
|
---|
| 823 | # Liste der geänderten Files ausgeben, falls nicht leer
|
---|
[215] | 824 | if (@files) {
|
---|
[209] | 825 |
|
---|
[215] | 826 | # stores result from status (cvscheck)
|
---|
| 827 | my %removedfiles = ();
|
---|
| 828 | my %changedfiles = ();
|
---|
| 829 |
|
---|
| 830 | foreach my $file (@files) {
|
---|
| 831 |
|
---|
| 832 | my $realfile = "/" . $file;
|
---|
| 833 | my $cvsworkfile = "${DASSCM_REPO}/${file}";
|
---|
| 834 |
|
---|
| 835 | if ( -d $realfile ) {
|
---|
| 836 |
|
---|
| 837 | # directory. do nothing
|
---|
| 838 | } elsif ( !-r $realfile ) {
|
---|
| 839 | $removedfiles{"$realfile"} = $cvsworkfile;
|
---|
| 840 | } else {
|
---|
| 841 | ( -r "$cvsworkfile" )
|
---|
| 842 | || die("Fehler: $cvsworkfile ist nicht lesbar");
|
---|
| 843 | if ( compare( $cvsworkfile, $realfile ) != 0 ) {
|
---|
| 844 | $changedfiles{"$realfile"} = $cvsworkfile;
|
---|
| 845 | }
|
---|
| 846 | }
|
---|
| 847 | }
|
---|
| 848 |
|
---|
| 849 | if (%removedfiles) {
|
---|
| 850 | print "deleted files (found in repository, but not in system):\n";
|
---|
| 851 | foreach my $key ( values %removedfiles ) {
|
---|
[209] | 852 | print "$key\n";
|
---|
| 853 | }
|
---|
| 854 | print "\n";
|
---|
| 855 | }
|
---|
| 856 |
|
---|
[215] | 857 | if (%changedfiles) {
|
---|
[209] | 858 | print "modified files:\n";
|
---|
[215] | 859 | foreach my $key ( keys %changedfiles ) {
|
---|
[209] | 860 | print "$key\n";
|
---|
| 861 | }
|
---|
| 862 | }
|
---|
| 863 | } else {
|
---|
[215] | 864 | print "no modified files found in $dir\n";
|
---|
[252] | 865 | $return_code = $RETURN_OK;
|
---|
[209] | 866 | }
|
---|
[215] | 867 |
|
---|
[209] | 868 | print "\n";
|
---|
[252] | 869 |
|
---|
| 870 | return $return_code;
|
---|
[215] | 871 | }
|
---|
[209] | 872 |
|
---|
[215] | 873 | sub permissions(@)
|
---|
| 874 | {
|
---|
| 875 | check_parameter( @_, 1 );
|
---|
| 876 | check_env();
|
---|
| 877 |
|
---|
| 878 | #
|
---|
| 879 | # update local repository
|
---|
| 880 | #
|
---|
| 881 | #svn_update();
|
---|
| 882 |
|
---|
| 883 | # TODO: start at subdirectories ?
|
---|
[220] | 884 | my $dir = $DASSCM_REPO;
|
---|
[215] | 885 | my @files = svn_getStoredFiles($dir);
|
---|
| 886 |
|
---|
| 887 | if (@files) {
|
---|
| 888 |
|
---|
| 889 | # generieren der Permissions
|
---|
| 890 | my @permissions = generatePermissionList(@files);
|
---|
| 891 | my $OUTFILE;
|
---|
| 892 | my $tofile = 0; # Status für schreiben in File
|
---|
[220] | 893 |
|
---|
[215] | 894 | if ( -w dirname($permissions_file) ) {
|
---|
| 895 |
|
---|
| 896 | # Verzeichnis existiert => schreiben
|
---|
| 897 | print "storing permissions in file $permissions_file\n";
|
---|
| 898 | open( OUTFILE, ">$permissions_file" )
|
---|
[216] | 899 | || die("failed to write to $permissions_file: $!");
|
---|
[215] | 900 | $tofile = 1; # Merken, daß in File geschrieben wird
|
---|
| 901 | print OUTFILE "#\n";
|
---|
| 902 | print OUTFILE "# created by dasscm permissions\n";
|
---|
[220] | 903 | print OUTFILE
|
---|
| 904 | "# It is intended to be used for restoring permissions\n";
|
---|
[215] | 905 | } else {
|
---|
| 906 |
|
---|
| 907 | # Pfad für Sicherungsdatei existiert nicht => schreiben auf stdout
|
---|
| 908 | # Alias Filehandle für stdout erzeugen
|
---|
| 909 | *OUTFILE = *STDOUT;
|
---|
| 910 | }
|
---|
| 911 | foreach my $line (@permissions) {
|
---|
| 912 | print OUTFILE "$line\n";
|
---|
| 913 | }
|
---|
| 914 |
|
---|
[220] | 915 | if ($tofile) {
|
---|
[215] | 916 | close(OUTFILE);
|
---|
| 917 | }
|
---|
| 918 | }
|
---|
[209] | 919 | }
|
---|
| 920 |
|
---|
[189] | 921 | #####################################################################
|
---|
| 922 | #
|
---|
[186] | 923 | # main
|
---|
[189] | 924 | #
|
---|
[186] | 925 |
|
---|
[252] | 926 | my $return_code = $RETURN_OK;
|
---|
[186] | 927 | my $number_arguments = @ARGV;
|
---|
| 928 |
|
---|
[205] | 929 | if ( $number_arguments > 0 ) {
|
---|
[186] | 930 |
|
---|
[205] | 931 | # get subcommand and remove it from @ARGV
|
---|
| 932 | $command = $ARGV[0];
|
---|
| 933 | shift @ARGV;
|
---|
[196] | 934 |
|
---|
[205] | 935 | $DASSCM_LOCAL_REPOSITORY_BASE = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'};
|
---|
| 936 | $DASSCM_REPOSITORY_NAME = $config->{'DASSCM_REPOSITORY_NAME'};
|
---|
[196] | 937 |
|
---|
[205] | 938 | # TODO: check variables
|
---|
| 939 | $DASSCM_SVN_REPOSITORY =
|
---|
| 940 | $config->{'DASSCM_SVN_REPOSITORY_BASE'} . "/" . $DASSCM_REPOSITORY_NAME;
|
---|
| 941 |
|
---|
[247] | 942 | $DASSCM_CHECKOUT_USERNAME = $config->{'DASSCM_CHECKOUT_USERNAME'};
|
---|
| 943 | $DASSCM_CHECKOUT_PASSWORD = $config->{'DASSCM_CHECKOUT_PASSWORD'};
|
---|
[205] | 944 |
|
---|
| 945 | #
|
---|
| 946 | # if a user is given by dasscm configuration file, we use it.
|
---|
| 947 | # Otherwise we expect that read-only account is configured
|
---|
| 948 | # as local subversion configuration.
|
---|
| 949 | # If this is also not the case,
|
---|
| 950 | # user is required to type username and password.
|
---|
| 951 | # This will be stored as local subversion configuration thereafter.
|
---|
| 952 | #
|
---|
| 953 | if ( $DASSCM_CHECKOUT_USERNAME && $DASSCM_CHECKOUT_PASSWORD ) {
|
---|
| 954 | $svnCheckoutCredentials =
|
---|
| 955 | " --username $DASSCM_CHECKOUT_USERNAME --password $DASSCM_CHECKOUT_PASSWORD ";
|
---|
| 956 | }
|
---|
| 957 |
|
---|
| 958 | # get command line options and store them in options hash
|
---|
[214] | 959 | my $result = GetOptions( \%options, 'verbose', 'message=s' );
|
---|
[205] | 960 |
|
---|
| 961 | # print options
|
---|
| 962 | foreach my $option ( keys %options ) {
|
---|
[215] | 963 | print "${option}: $options{$option}\n";
|
---|
[205] | 964 | }
|
---|
| 965 |
|
---|
[214] | 966 | # set verbose to command line option
|
---|
| 967 | $verbose = $options{'verbose'};
|
---|
| 968 |
|
---|
| 969 | #
|
---|
| 970 | # action accordinly to command are taken
|
---|
| 971 | # $command is rewritten in standard format,
|
---|
| 972 | # so we can test for it later on more simply
|
---|
| 973 | #
|
---|
[205] | 974 | $_ = $command;
|
---|
| 975 | if (m/help/i) {
|
---|
| 976 | help(@ARGV);
|
---|
| 977 | } elsif (m/login/i) {
|
---|
[208] | 978 | $command = "login";
|
---|
[205] | 979 | login(@ARGV);
|
---|
| 980 | } elsif (m/init/i) {
|
---|
[208] | 981 | $command = "init";
|
---|
[205] | 982 | init(@ARGV);
|
---|
[215] | 983 | } elsif (m/ls/i) {
|
---|
| 984 | $command = "ls";
|
---|
| 985 | ls(@ARGV);
|
---|
[235] | 986 | } elsif ( (m/update/i) || (m/up/i) ) {
|
---|
[215] | 987 | $command = "update";
|
---|
| 988 | update(@ARGV);
|
---|
[205] | 989 | } elsif (m/add/i) {
|
---|
| 990 | $command = "add";
|
---|
| 991 | add(@ARGV);
|
---|
[251] | 992 | } elsif ( (m/commit/i) || (m/ci/i) ) {
|
---|
[205] | 993 | $command = "commit";
|
---|
| 994 | add(@ARGV);
|
---|
| 995 | } elsif (m/blame/i) {
|
---|
[208] | 996 | $command = "blame";
|
---|
[205] | 997 | blame(@ARGV);
|
---|
| 998 | } elsif (m/diff/i) {
|
---|
[208] | 999 | $command = "diff";
|
---|
[205] | 1000 | diff(@ARGV);
|
---|
[235] | 1001 | } elsif ( (m/status/i) || (m/st/i) ) {
|
---|
[252] | 1002 | $command = "status";
|
---|
| 1003 | $return_code = status(@ARGV);
|
---|
[215] | 1004 | } elsif (m/permissions/i) {
|
---|
| 1005 | $command = "permissions";
|
---|
| 1006 | permissions(@ARGV);
|
---|
[205] | 1007 | } else {
|
---|
[215] | 1008 | print "unknown command: $command\n\n";
|
---|
[205] | 1009 | usage();
|
---|
| 1010 | check_env();
|
---|
[252] | 1011 | $return_code = $RETURN_NOK;
|
---|
[205] | 1012 | }
|
---|
| 1013 |
|
---|
[209] | 1014 | # cleanup (svn-commit.tmp)
|
---|
[205] | 1015 | # commitall
|
---|
| 1016 | # revert
|
---|
[215] | 1017 | # activate
|
---|
[227] | 1018 | # rm
|
---|
[252] | 1019 |
|
---|
[186] | 1020 | }
|
---|
[252] | 1021 |
|
---|
| 1022 | exit $return_code;
|
---|