#!/bin/bash
-# $Id: mir-setup,v 1.1 2005/06/13 22:23:43 zak Exp $
+# $Id: mir-setup,v 1.2 2005/09/25 11:59:24 zak Exp $
# Script to install a new Mir site
if [ -n "$MIRVERSION" ]; then MIRVERSIONOPT="-r$MIRVERSION"; fi
if [ -n "$SITEVERSION" ]; then SITEVERSIONOPT="-r$SITEVERSION"; fi
-if [ -z "$DBNAME" ]; then DBNAME="$SITE"; fi
-if [ -z "$DBUSER" ]; then DBUSER="$SITE"; fi
-if [ -z "$DBPASS" ]; then DBPASS="`pwgen -s 8 1`"; fi
+if [ -n "$SHAREDB" ]; then
+ if [ -n "$DBNAME" ]; then optdie "$PROG: SHAREDB and DBNAME set"; fi
+ if [ -n "$DBUSER" ]; then optdie "$PROG: SHAREDB and DBUSER set"; fi
+ if [ -n "$DBPASS" ]; then optdie "$PROG: SHAREDB and DBPASS set"; fi
+
+ DBNAME="`perl -ne 'if (/\s*Database\.Name\s*=\s*(\S+)/) { print "$1\n" }' /mir/uk/setup_uk/etc/config.properties`"
+ DBUSER="`perl -ne 'if (/\s*Database\.Username\s*=\s*(\S+)/) { print "$1\n" }' /mir/uk/setup_uk/etc/config.properties`"
+ DBPASS="`perl -ne 'if (/\s*Database\.Password\s*=\s*(\S+)/) { print "$1\n" }' /mir/uk/setup_uk/etc/config.properties`"
+else
+ if [ -z "$DBNAME" ]; then DBNAME="$SITE"; fi
+ if [ -z "$DBUSER" ]; then DBUSER="$SITE"; fi
+ if [ -z "$DBPASS" ]; then DBPASS="`pwgen -s 8 1`"; fi
+fi
if [ -z "$CONFIGPROPERTIES" ]; then CONFIGPROPERTIES="$CONFDIR/config.properties"; fi
if [ ! -e "$CONFIGPROPERTIES" ]; then
ln -snf "../$SITEOVERLAYDIR/etc"
fi
-checkpoint "Create database"
-if [ -n "$RUNNING" ]; then
- sudo -u postgres createdb --encoding=unicode "$DBNAME"
- sudo -u postgres psql "$DBNAME" <<EOF
+if [ -n "$SHAREDB" ]; then
+ checkpoint "Sharing existing database (not creating)"
+ checkpoint "Sharing existing database (not importing/installing)"
+ checkpoint "Sharing existing database (not setting permissions)"
+else
+ checkpoint "Create database"
+ if [ -n "$RUNNING" ]; then
+ sudo -u postgres createdb --encoding=unicode "$DBNAME"
+ sudo -u postgres psql "$DBNAME" <<EOF
CREATE USER $DBUSER WITH PASSWORD '$DBPASS' NOCREATEDB NOCREATEUSER;
UPDATE pg_database SET datdba=(SELECT usesysid FROM pg_user WHERE usename='$DBUSER') WHERE datname='$DBNAME';
EOF
-fi
-
-if [ -n "$DBDUMP" ]; then
- checkpoint "Import database dump"
- if [ -n "$RUNNING" ]; then
- zcat "$DBDUMP" | sudo -u postgres pg_restore -d "$DBNAME" -O -x
fi
-else
- checkpoint "Install default database"
- if [ -n "$RUNNING" ]; then
- for i in "$INSTALLDIR"/mir/dbscripts/{create_pg,help*,populate*}.sql; do
- sudo -u postgres psql -f $i "$DBNAME"
- done
+
+ if [ -n "$DBDUMP" ]; then
+ checkpoint "Import database dump"
+ if [ -n "$RUNNING" ]; then
+ zcat "$DBDUMP" | sudo -u postgres pg_restore -d "$DBNAME" -O -x
+ fi
+ else
+ checkpoint "Install default database"
+ if [ -n "$RUNNING" ]; then
+ for i in "$INSTALLDIR"/mir/dbscripts/{create_pg,help*,populate*}.sql; do
+ sudo -u postgres psql -f $i "$DBNAME"
+ done
+ fi
fi
-fi
-checkpoint "Set database permissions"
-if [ -n "$RUNNING" ]; then
- # Clumsy -- produces errors which we should ignore
- echo >&2 "Don't worry about errors from some of the GRANTs here"
- sudo -u postgres psql -qto "|psql \"$DBNAME\"" "$DBNAME" <<EOF
+ checkpoint "Set database permissions"
+ if [ -n "$RUNNING" ]; then
+ # Clumsy -- produces errors which we should ignore
+ echo >&2 "Don't worry about errors from some of the GRANTs here"
+ sudo -u postgres psql -qto "|psql \"$DBNAME\"" "$DBNAME" <<EOF
SELECT 'GRANT ALL ON '||relname||' TO $DBUSER;'
FROM pg_class
WHERE relname not like 'pg%'
ORDER by relname;
EOF
+ fi
fi
checkpoint "Install config.properties"