Annotation of pkgsrc/databases/postgresql/scripts/createuser, revision 1.1
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:
! 13: if( getpwnam( "pgsql" ) ) {
! 14: ( $null, $null, $pgUID ) = getpwnam( "pgsql" );
! 15: } else {
! 16: $pgUID = 70;
! 17: while( getpwuid( $pgUID ) ) {
! 18: $pgUID++;
! 19: }
! 20: }
! 21:
! 22: if( getgrnam( "pgsql" ) ) {
! 23: ( $null, $null, $pgGID ) = getgrnam( "pgsql" );
! 24: } else {
! 25: $pgGID = 70;
! 26: while( getgrgid( $pgGID ) ) {
! 27: $pgGID++;
! 28: }
! 29: &append_file( "/etc/group", "pgsql:*:$pgGID:" );
! 30: }
! 31:
! 32: print "pgsql user using uid $pgUID\n";
! 33: print "pgsql user using gid $pgGID\n";
! 34:
! 35: system( "/usr/bin/chpass -a \"pgsql:*:$pgUID:$pgGID::0:0:PostgreSQL pseudo-user:$ENV{'PREFIX'}/pgsql:/bin/sh\"" );
! 36:
! 37: sub append_file {
! 38: local($file,@list) = @_;
! 39: local($LOCK_EX) = 2;
! 40: local($LOCK_NB) = 4;
! 41: local($LOCK_UN) = 8;
! 42:
! 43: open(F, ">> $file") || die "$file: $!\n";
! 44: while( ! flock( F, $LOCK_EX | $LOCK_NB ) ) {
! 45: exit 1;
! 46: }
! 47: print F join( "\n", @list) . "\n";
! 48: close F;
! 49: flock( F, $LOCK_UN );
! 50: }
CVSweb <webmaster@jp.NetBSD.org>