changing user within a post install.

Auke Kok sofar at lunar-linux.org
Thu Apr 1 20:55:17 GMT 2004


Dennis Veatch wrote:
> I have a POST_INSTALL module for postgresql but can't get one part to work. It 
> looks like this;
> 
> -----------------------------------------------------------------------------------------------------------------
> # Check the default directory exists, if not create and set owner.
> 
> if [ ! -d "/var/lib/pgsql" ]; then
>    mkdir -p /var/lib/pgsql
>    chown postgres:postgres /var/lib/pgsql	
> fi
> 
> # login as postgres and intitialize the database, if it does not exist.
> 
> su postgres &&
> cd /var/lib/pgsql &&
> /usr/bin/initdb -D /var/lib/pgsql/data
> 
> ---------------------------------------------------------------------------------------------------------------------
> 
> It does create /var/lib/pgsql. It seems to be changing to the postgres user as 
> the prompt changes from "root at driller" to "sh-2.05". But that's all it seems 
> to do at this point. Doing the commands manually, works fine. No clue how to 
> handle this within POST_INSTALL.

su called from a shell script *must* be passed a command to perform. you 
can either perform it as root and do a chown on the files later, or do 
something like:

su postgres -c 'cd /var/lib/pgsql && /usr/bin/initdb -D /var/lib/pgsql/data'

try it!

sofar


More information about the Lunar-dev mailing list