Packaging something with a PostgreSQL database.
Hi,
I am going to package odontolinux. This is a
management software for dental offices. I am
also the author of the software itself.
Odontolinux is written in PHP4 and uses PostgreSQL as dbms.
It is a non-US package because of PostgreSQL.
I looked for similar packages in debian sources...
but I found different ways of managing databases.
PHP files are not a problem since they go
in /var/www/dir with a simple copy command :-)
The problem is the database.
I used somethting from barracuda, something from mantis,
something from beancounter. But since I would like not to make
very big mistakes, I'd like to hear from you.
Here are my files:
preinst
postinst
makedb.sh (which is invoked by postinst)
prerm
I did not put gestionestudio.dump while is the empty PostgreSQL dump of
the database.
I am sorry for the lenght of this mail.
****************** 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)
#DEBHELPER#
****************** end preinst *******************
****************** 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
#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
if psql -ltq |grep 'gestionestudio'
then
echo "Database exists."
else
echo "Database does not exists, creating it."
createdb gestionestudio
echo "Creating postgres users..."
userid=`psql -qt -d gestionestudio -c "
DELETE FROM pg_shadow where usename ~ '^gestionestudio_' ;
DELETE FROM pg_group where groname ~ '^gestionestudio_';
create user gestionestudio createuser;"`
echo "Creating the database..."
psql -t -d gestionestudio <$SHAREDIR/gestionestudio.dump 2>&1 |tee $TMPDIR/makedb.out | grep ERR
if grep -sq ERR $TMPDIR/makedb.out
then
echo -n "Do you want to examine the error file ($TMPDIR/makedb.out) (y/N) ? "
read ANS
if [ -z "$ANS" -o "$ANS" = "N" -o "$ANS" = "n" ];
then
rm -f $TMPDIR/makedb.out
echo "$TMPDIR/makedb.out has been removed."
else
cat $TMPDIR/makedb.out
fi
else
rm -f $TMPDIR/makedb.out
fi
rmdir $TMPDIR
fi
echo "Done."
echo "Do not forget to check if /etc/postgresql/pg_hba conf contains"
echo "the following line:"
echo "host all 127.0.0.1 255.255.255.255 trust"
****************** end makedb.sh *******************
****************** begin prerm *******************
#!/bin/bash
PGPATH=/usr/lib/postgresql/bin
export PATH=$PATH:$PGPATH
export PGUSER=postgres
echo -n "Do you want to DESTROY the Odontolinux database [y/N] ? "
read YN
if [ "$YN" = "Y" -o "$YN" = "y" ]
then
echo "Destroying Odontolinux! database..."
if psql -ltq | grep 'gestionestudio'
then
psql -qt -d gestionestudio -c "DELETE FROM pg_shadow where usename = 'gestionestudio';"
dropdb gestionestudio
rm -rf ~gestionestudio
echo "Deleting gestionestudio user..."
userdel gestionestudio
else
echo "Database does not exist or other error."
fi
fi
#DEBHELPER#
****************** end prerm *******************
--
Gaetano Paolone GnuPG:69A5 548C 4145 1116 8CA9 2CB5 9448 3FA3 54DB 33D3
Debian developer - bigpaul@debian.org. Home: http://www.bigpaul.org
http://www.linuxfaq.it: LDR Linux Domande e Risposte.
http://www.gnutemberg.org - Linuxlinks: http://www.linuxlinks.it by robk
Reply to: