[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Packaging something with a PostgreSQL database.



* Gaetano Paolone 

| ******************  begin preinst  *******************
| #!/bin/bash
| # Pre-installation script for odontolinux debian package
| 
| grep -s -q '^gestionestudio:' /etc/group ||
|         (
|         echo "Adding gestionestudio group"
|         groupadd gestionestudio
|         grep '^gestionestudio:' /etc/group)
| grep -s -q '^gestionestudio:' /etc/passwd ||
|         ( echo "Adding gestionestudio user"
|         useradd -c "Odontolinux superuser" -d /home/gestionestudio -g gestionestudio -s /bin/bash gestionestudio
|         grep '^gestionestudio:' /etc/passwd)

use `id` instead of grepping the password and group files, or you'll
get a serious bug. :)

| ******************  begin postinst  *******************
| #!/bin/bash
| 
| if [ "$1" = "configure" ]; then
|  if [ -d /usr/doc -a ! -e /usr/doc/odontolinux -a -d /usr/share/doc/odontolinux ]; then
|   ln -sf ../share/doc/odontolinux /usr/doc/odontolinux
|  fi
| fi
| export PGUSER=postgres
| /usr/share/odontolinux/makedb.sh

su - postgres -c /usr/share/odontolinux/makedb.sh

| #DEBHELPER#
| ******************  end postinst  *******************
| 
| ******************  begin makedb.sh  *******************
| #!/bin/bash
| #set -e
| export SHAREDIR=/usr/share/odontolinux
| export TMPDIR=/var/tmp/odontolinux
| export PATH=$PATH:/usr/lib/postgresql/bin
| 
| mkdir -p $TMPDIR

mkdir -p $TMPDIR || exit 1, I presume?

| if psql -ltq |grep 'gestionestudio'
| then
| 	echo "Database exists."
| else
| 	echo "Database does not exists, creating it."
| 	createdb gestionestudio
| 	echo "Creating postgres users..."

What happens if I happen to have a db called gestionestudio?  I think
you should rather have the admin run this by hand.  It will be less
error prone.

Or you can ask whether he wants to run it automatically when
installing, but please don't just do it.

| 	userid=`psql -qt -d gestionestudio -c "
|                 DELETE FROM pg_shadow where usename ~ '^gestionestudio_' ;
|                 DELETE FROM pg_group where groname ~ '^gestionestudio_';
|                 create user gestionestudio createuser;"`

Deleting froma pg_shadow and pg_group is _evil_.

-- 
Tollef Fog Heen
Unix _IS_ user friendly... It's just selective about who its friends are.



Reply to: