Annotation of pkgsrc/databases/postgresql/scripts/createuser, revision 1.2

1.1       agc         1: #!/usr/bin/perl
                      2: #
                      3: 
                      4: eval '(exit $?0)' && eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
                      5: & eval 'exec /usr/bin/perl -S $0 $argv:q'
                      6: if 0;
                      7: 
                      8: if( $> ) {
                      9:        print "\nYou must be root to run this step!\n\n";
                     10:        exit 1;
                     11: } 
                     12: 
1.2     ! agc        13: @ARGV = "pgsql" unless @ARGV;
        !            14: 
        !            15: $pgsql = $ARGV[0];
        !            16: 
        !            17: if( getpwnam( $pgsql ) ) {
        !            18:        ( $null, $null, $pgUID ) = getpwnam( $pgsql );
        !            19:        $addname = 0;
1.1       agc        20: } else {
                     21:        $pgUID = 70;
                     22:        while( getpwuid( $pgUID ) ) {
                     23:                $pgUID++;
                     24:        }
1.2     ! agc        25:        $addname = 1;
1.1       agc        26: }
                     27: 
1.2     ! agc        28: if( getgrnam( $pgsql ) ) {
        !            29:        ( $null, $null, $pgGID ) = getgrnam( $pgsql );
1.1       agc        30: } else {
                     31:        $pgGID = 70;
                     32:        while( getgrgid( $pgGID ) ) {
                     33:                $pgGID++;
                     34:        }
1.2     ! agc        35:        &append_file( "/etc/group", "${pgsql}:*:${pgGID}:" );
1.1       agc        36: }
                     37: 
1.2     ! agc        38: print "pgsql user $pgsql using uid $pgUID\n";
        !            39: print "pgsql user $pgsql using gid $pgGID\n";
1.1       agc        40: 
1.2     ! agc        41: if ($addname) {
        !            42:        system( "/usr/bin/chpass -a \"$pgsql:tgeuR/ly70tJo:${pgUID}:${pgGID}::0:0:PostgreSQL pseudo-user:$ENV{'PREFIX'}/$pgsql:/bin/sh\"" );
        !            43: }
1.1       agc        44: 
                     45: sub append_file {
                     46:        local($file,@list) = @_;
                     47:        local($LOCK_EX) = 2;
                     48:        local($LOCK_NB) = 4;
                     49:        local($LOCK_UN) = 8;
                     50: 
                     51:        open(F, ">> $file") || die "$file: $!\n";
                     52:        while( ! flock( F, $LOCK_EX | $LOCK_NB ) ) {
                     53:                exit 1;
                     54:        }
                     55:        print F join( "\n", @list) . "\n";
                     56:        close F;
                     57:        flock( F, $LOCK_UN );
                     58: }

CVSweb <webmaster@jp.NetBSD.org>