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

more comments on INSTALL.manual re Postgresql



INSTALL talks about using either http://[host]/ledgersmb/initiate.pl or using install-mycompany.sh.

In some cases (e.g. Gentoo) the postgres userid does not have a password assigned (it's blocked from interactive login anyway) which renders initiate.pl unusable.

install-mycompany.sh, however, sets several key parameters (company name, and thus DB name, userid, etc.) that are neither discussed in the manual nor prompted for.

Since install.sh already prompts (and thus is interactive), and the only place install-mycompany.sh is referred to is INSTALL (i.e. not called from any distro pkg scripts that I could find) and thus also interactive...

I've modified install-mycompany.sh to be interactive, prompting for a few key variables, using pg_config to detect PostgreSQL parameters such as the contrib directory, and prompting the user for their appropriate CoA (since we don't all live in the USA).

Please see attached diff against SVN trunk.

--
Thank you,
-Adam Thompson
 <..hidden..>
 (204) 291-7950
Index: install-mycompany.sh
===================================================================
--- install-mycompany.sh	(revision 2916)
+++ install-mycompany.sh	(working copy)
@@ -1,36 +1,60 @@
-#!/bin/bash
+#!/bin/sh
 
+pg_config > /dev/null
+if [ $? -ne 0 ]; then
+	echo "Please ensure the PostgreSQL commands are in your path"
+	echo "before running this script."
+	exit 255
+fi
+
 CWD=`pwd`
 
-MYCOMPANY='cmd'
-MYUSER='lacey_cmd'
-PGVERSION=8.4
+echo "Enter a company name (this will also be the name of the PostgreSQL database):"
+read MYCOMPANY
+echo "Enter a user name (this user will be the 'superuser' for LedgerSMB):"
+read MYUSER
+echo "Enter your two-letter country code:"
+echo "(Must be one of: $(cd $CWD/sql/coa; echo ??))"
+read CCODE
+COA=$CWD/sql/coa/$CCODE/chart/General.sql
+while [ ! -f $COA ]; do
+   echo "Please choose a General Chart of Accounts for your country:"
+   echo "Must be one of: $(cd $CWD/sql/coa/$CCODE/chart; echo *.sql)"
+   read GENERAL
+   COA=$CWD/sql/coa/$CCODE/chart/$GENERAL
+done
 
+echo "This script will create a $MYCOMPANY dataset per INSTALL."
+echo "Press Enter to continue or Ctrl-C to cancel."
+read JUNK
+
+# Find PGVERSION in a POSIX-compatible way:
+PGVERSION=$(pg_config --version)
+PGVERSION=${PGVERSION#PostgreSQL }
+PGVERSION=${PGVERSION%.[0-9]}
+
 # The following path can vary per distribution
-# Debian/Ubuntu
-CONTRIB=/usr/share/postgresql/$PGVERSION/contrib/
-# Compiled from source.
-#CONTRIB=/usr/local/pgsql/share/contrib
+# Use pg_config to find this in a more portable way
+CONTRIB=$(pg_config --sharedir)/contrib
 
-echo "This script will create a $MYCOMPANY dataset per INSTALL. Ctrl-C to cancel."
-
 dropdb -i -U postgres $MYCOMPANY 
 for role in `psql -U postgres -t -c "SELECT rolname FROM pg_roles WHERE rolname LIKE 'lsmb_${MYCOMPANY}%';"`; do dropuser -U postgres $role; done
 dropuser -U postgres $MYUSER 
 dropuser -U postgres ledgersmb 
+echo "Please enter the password for the 'ledgersmb' role:"
 createuser --no-superuser --createdb --no-createrole -U postgres --pwprompt --encrypted ledgersmb 
 createdb -U postgres -O ledgersmb $MYCOMPANY  
 createlang -U postgres plpgsql -d $MYCOMPANY 
-if [[ "$PGVERSION" == "8.0" || "$PGVERSION" == "8.1" || "$PGVERSION" == "8.2" ]]; then
-   psql -U postgres -d $MYCOMPANY -f $CONTRIB/tsearch2.sql
-fi
+# tsearch2.sql still exists in 8.3+, now it creates function aliases for backwards compatibility
+psql -U postgres -d $MYCOMPANY -f $CONTRIB/tsearch2.sql
 psql -U postgres -d $MYCOMPANY -f $CONTRIB/tablefunc.sql
 psql -U postgres -d $MYCOMPANY -f $CONTRIB/pg_trgm.sql
 psql -U postgres -d $MYCOMPANY -f $CWD/sql/Pg-database.sql
 psql -U postgres -d $MYCOMPANY -f $CWD/sql/modules/install.sql 
-psql -U postgres -d $MYCOMPANY -f $CWD/sql/coa/us/chart/General.sql
+psql -U postgres -d $MYCOMPANY -f $COA
 sed  -e "s/<?lsmb dbname ?>/$MYCOMPANY/g" $CWD/sql/modules/Roles.sql > $CWD/${MYCOMPANY}_roles.sql 
 psql -U postgres -d $MYCOMPANY -f $CWD/${MYCOMPANY}_roles.sql  
+echo "Please enter the password for the $MYUSER role:"
 createuser --no-superuser --createdb --no-createrole -U postgres --pwprompt --encrypted $MYUSER 
 psql -U postgres -d $MYCOMPANY --tuples-only -t -c "INSERT INTO entity (name, entity_class, created, control_code, country_id) VALUES ('$MYUSER', 3, NOW(), '123', 238) RETURNING id;"
 psql -U postgres -d $MYCOMPANY -t -c "INSERT INTO person (entity_id, first_name, last_name, created) VALUES (1, 'Firstname', 'Lastname', NOW()) RETURNING entity_id, first_name, last_name, created;"