Updates to mir-setup scripts
authorzak <zak>
Sun, 25 Sep 2005 11:59:24 +0000 (11:59 +0000)
committerzak <zak>
Sun, 25 Sep 2005 11:59:24 +0000 (11:59 +0000)
scripts/mir-setup/conf/config-examplesite
scripts/mir-setup/mir-setup

index 5e023dd..a69aa10 100755 (executable)
@@ -1,10 +1,18 @@
-# $Id: config-examplesite,v 1.1 2005/06/13 22:23:43 zak Exp $
+# $Id: config-examplesite,v 1.2 2005/09/25 11:59:24 zak Exp $
 
 # Example site configuration file for mir-setup script
 
 # Short site name
 SITE=examplesite
 
+# Database dump (.tar.gz format) to import rather than using default one
+# DBDUMP=/path/to/dump.tar.gz
+
+# Share database from this config file. Note that this is probably a bad
+# idea, since articles won't get regenerated properly on all installs.
+# However it is how the UK dev server used to work.
+# SHAREDB=/path/to/other/install/config.properties
+
 # Full canonical domain name of production site
 FQDN="publish.$SITE.indymedia.org"
 
index 55ad3f3..69451a1 100755 (executable)
@@ -1,5 +1,5 @@
 #!/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
 
@@ -96,9 +96,19 @@ fi
 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
@@ -210,39 +220,45 @@ if [ -n "$RUNNING" ]; 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"