Changeset 252 for trunk


Ignore:
Timestamp:
Dec 22, 2008, 6:10:02 PM (16 years ago)
Author:
joergs
Message:

added return code, don't require login so often, init creates missing directories, perltidy

Location:
trunk/dasscm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/dasscm/dasscm

    r251 r252  
    2424#
    2525
     26my $RETURN_OK  = 0;
     27my $RETURN_NOK = 1;
     28
    2629# file to store permissions
    2730my $permissions_file = "/etc/permissions.d/dasscm.permission_backup";
     
    2932# documentation file (for usage)
    3033my $doc_file = "/usr/share/doc/packages/dasscm/dasscm_howto.txt";
     34
     35my @COMMANDS_REQUIRE_WRITE = ( 'add', "commit" );
    3136
    3237# configuration file
     
    3843my $DASSCM_CHECKOUT_USERNAME;
    3944my $DASSCM_CHECKOUT_PASSWORD;
    40 
    4145
    4246# current directory at program start
     
    180184    if ($verbose) { print "DASSCM_REPO: " . $DASSCM_REPO . "\n"; }
    181185
    182 
    183186    #
    184187    # subversion checkout user
    185188    #
    186     if( ! $DASSCM_CHECKOUT_USERNAME ) {
    187         fatalerror( 
     189    if ( !$DASSCM_CHECKOUT_USERNAME ) {
     190        fatalerror(
    188191            "variable DASSCM_CHECKOUT_USERNAME is not defined.",
    189             "Use file $config_file to configure it." );
    190     }
    191 
    192     if( ! $DASSCM_CHECKOUT_PASSWORD ) {
    193         fatalerror(
     192            "Use file $config_file to configure it."
     193        );
     194    }
     195
     196    if ( !$DASSCM_CHECKOUT_PASSWORD ) {
     197        fatalerror(
    194198            "variable DASSCM_CHECKOUT_PASSWORD is not defined.",
    195             "Use file $config_file to configure it." );
    196     }
    197    
     199            "Use file $config_file to configure it."
     200        );
     201    }
    198202
    199203    #
     
    220224        # otherwise USER can be used
    221225        if ( "$USER" eq "root" ) {
    222             if ( ( not $DASSCM_USERNAME ) and ( $command ne "login" ) ) {
    223                 fatalerror( "Envirnonment variable DASSCM_USERNAME not set.", "Set DASSCM_USERNAME to your subversion user account or", "use 'dasscm login'" );
     226            if (    ( not $DASSCM_USERNAME )
     227                and ( grep { m|^$command$| } @COMMANDS_REQUIRE_WRITE ) )
     228            {
     229
     230                #( $command ne "login" ) and ( $command ne "status" ) ) {
     231                fatalerror(
     232                    "Envirnonment variable DASSCM_USERNAME not set.",
     233                    "Set DASSCM_USERNAME to your subversion user account or",
     234                    "use 'dasscm login'"
     235                );
    224236            }
    225237            $svnOptions .= " --no-auth-cache ";
     
    376388}
    377389
    378 
    379 
    380390sub svn_check_credentials( $$;$$ )
    381391{
     
    383393    my $password = shift;
    384394
    385     # check silently are allow user interaction? 
     395    # check silently are allow user interaction?
    386396    my $interactive = shift || 0;
    387397
     
    389399    #   (do not exit for 'init')
    390400    my $fatalerror = shift || 1;
    391 
    392 
    393401
    394402    print "checking credentials ";
     
    413421
    414422    my $rc_update;
    415     if( $interactive ) {
    416         $rc_update = run_interactive( "$SVN ls --no-auth-cache --username $username --password $password $DASSCM_SVN_REPOSITORY" );
     423    if ($interactive) {
     424        $rc_update =
     425          run_interactive(
     426            "$SVN ls --no-auth-cache --username $username --password $password $DASSCM_SVN_REPOSITORY"
     427          );
    417428    } else {
    418429        ( $rc_update, my @result ) =
    419         run_command(
     430          run_command(
    420431            "$SVN ls --non-interactive --no-auth-cache --username $username --password $password $DASSCM_SVN_REPOSITORY"
    421         );
    422    
     432          );
     433
    423434        if ( $rc_update != 0 ) {
    424435            print "\n", @result;
    425             if( $fatalerror ) {
     436            if ($fatalerror) {
    426437                fatalerror();
    427438            }
     
    433444    return $rc_update == 0;
    434445}
    435 
    436 
    437446
    438447sub svn_update( ;$ )
     
    562571
    563572    # checking checkout username/password
    564     svn_check_credentials( $DASSCM_CHECKOUT_USERNAME, $DASSCM_CHECKOUT_PASSWORD );
     573    svn_check_credentials( $DASSCM_CHECKOUT_USERNAME,
     574        $DASSCM_CHECKOUT_PASSWORD );
    565575    print "checkout access okay\n";
    566576
     
    594604    my $retcode =
    595605      run_interactive(
    596         "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY; touch $permissions_file"
     606        "cd $DASSCM_LOCAL_REPOSITORY_BASE; $SVN checkout $svnCheckoutCredentials $svnOptions $DASSCM_SVN_REPOSITORY; mkdir -p `dirname $permissions_file`; touch $permissions_file"
    597607      );
    598608}
     
    782792    check_env();
    783793
     794    # return code for the shell
     795    # default: error
     796    my $return_code = $RETURN_NOK;
     797
    784798    #
    785799    # update local repository
     
    833847    } else {
    834848        print "no modified files found in $dir\n";
     849        $return_code = $RETURN_OK;
    835850    }
    836851
    837852    print "\n";
     853
     854    return $return_code;
    838855}
    839856
     
    891908#
    892909
     910my $return_code      = $RETURN_OK;
    893911my $number_arguments = @ARGV;
    894912
     
    966984        diff(@ARGV);
    967985    } elsif ( (m/status/i) || (m/st/i) ) {
    968         $command = "status";
    969         status(@ARGV);
     986        $command     = "status";
     987        $return_code = status(@ARGV);
    970988    } elsif (m/permissions/i) {
    971989        $command = "permissions";
     
    975993        usage();
    976994        check_env();
     995        $return_code = $RETURN_NOK;
    977996    }
    978997
     
    9821001    # activate
    9831002    # rm
    984 }
     1003
     1004}
     1005
     1006exit $return_code;
  • trunk/dasscm/debian/control

    r240 r252  
    88Package: dasscm
    99Architecture: any
    10 Depends: subversion, perl, libterm-readkey-perl, libconfig-inifiles-perl
     10Depends: subversion, perl, libterm-readkey-perl
    1111Description: dass configuration management tool
    1212 tools for handling configuration files with subversion
  • trunk/dasscm/debian/rules

    r240 r252  
    6363        install -d $(CURDIR)/debian/dasscm/etc
    6464        install -d $(CURDIR)/debian/dasscm/etc/subversion
     65        install -d $(CURDIR)/var/lib/dasscm/
    6566        install -m 0755 dasscm $(CURDIR)/debian/dasscm/usr/bin
    6667        install -m 0644 dasscm.conf $(CURDIR)/debian/dasscm/etc
Note: See TracChangeset for help on using the changeset viewer.