[Mapbender-commits] r5792 - branches/2.6/resources/db

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Mar 16 13:46:43 EDT 2010


Author: astrid_emde
Date: 2010-03-16 13:46:42 -0400 (Tue, 16 Mar 2010)
New Revision: 5792

Modified:
   branches/2.6/resources/db/install_2.6.sh
Log:
took new install.sh from trunk - no iso, no mysql

Modified: branches/2.6/resources/db/install_2.6.sh
===================================================================
--- branches/2.6/resources/db/install_2.6.sh	2010-03-16 17:03:26 UTC (rev 5791)
+++ branches/2.6/resources/db/install_2.6.sh	2010-03-16 17:46:42 UTC (rev 5792)
@@ -6,7 +6,7 @@
 function show_disclaimer() {
     # Disclaimer
     echo ""
-    echo "DISCLAIMER: this Mapbender database setup script is not stable. USE AT YOUR OWN RISK!"
+    echo "DISCLAIMER: Mapbender database setup script. USE AT YOUR OWN RISK!"
     echo "The script will create a database for you and will import the Mapbender data to the new database"
     echo "It will also compile the Mapbender.mo files"
     echo ""
@@ -20,7 +20,16 @@
     echo ""
     echo ""
     echo "If everything is prepared you can continue."
+    echo "-------"
     echo ""
+    echo "You can give nearly all arguments on commandline:"
+    echo "$0 <HOST> <PORT> <DBNAME> <DBTEMPLATE> <DBUSER>"
+    echo ""
+    echo "e.g."
+    echo "$0 localhost 5432 mapbender template0 postgres"
+    echo ""
+    echo "------"
+    echo ""
 }
 
 function del_logfile() {
@@ -31,67 +40,39 @@
 
 #get Database Configuration
 function get_db_config(){
-    until [ "$DBVERSION" = "p" -o "$DBVERSION" = "m" ]
-    do
-        echo ""
-        echo "database version? (p)ostgresql or (m)ysql?"
-        read DBVERSION
-    done
 
-    # db encoding
-    until [ "$DBENCODING" = "i" -o "$DBENCODING" = "u" ]
-    do
-        echo ""
-        echo "database character encoding? (i)so-8859-1 or (u)tf-8?"
-        read DBENCODING
-    done
- 
-   #ask for database template
-    if [ "$DBVERSION" = "p" ]
-    then
-        echo ""
-        echo "database template to use (just hit return for default template0)?"
-        read DBTEMPLATE
-        : ${DBTEMPLATE:="template0"}
-    fi
-    # db name
-    until [ -n "$DBNAME" ]
-    do
-        echo ""
-        echo "database name?"
-        read DBNAME
-    done
-
-    #nicer vars
-    if [  "$DBVERSION" = "p" ]
-    then
-        DBVERSION="pgsql" 
-    else
-        DBVERSION="mysql" 
-    fi
-
-    if [  "$DBENCODING" = "i" ]
-    then
-        DBENCODING="ISO-8859-1" 
-    else
-        DBENCODING="UTF-8" 
-    fi
-
+   #ask for database host
     echo ""
     echo "database host (e.g. localhost)?"
     read DBHOST
 	: ${DBHOST:="localhost"}
 
+   #ask for database port
     echo ""
-    echo "database port (e.g. 5432 for postgres, 3306 for mysql)?"
+    echo "database port (e.g. 5432 for postgres)?"
     read DBPORT
-	: ${DBPORT:="5432"}
+	: ${DBPORT:="5432"}     
+        
+    # db name
+    until [ -n "$DBNAME" ]
+    do
+        echo ""
+        echo "database name?"
+        read DBNAME
+    done    
 
+	#ask for database template
+        echo ""
+        echo "database template to use (just hit return for default template0)?"
+        read DBTEMPLATE
+        : ${DBTEMPLATE:="template0"}
+   
     echo ""
     echo "database user?"
     read DBUSER
 
 #using a password via commandline oder as shell var could lead to security problems, so we don't do it
+#see  http://www.postgresql.org/docs/current/static/libpq-pgpass.html for a convenient way
 #    echo ""
 #    echo "Password for $DBUSER (will not be shown)?"
 #	stty -echo
@@ -100,6 +81,18 @@
 
 }
 
+#set Database Configuration from commandline
+function set_db_config(){
+	echo ""
+    echo "set variables to input:"
+	DBHOST=$1
+	DBPORT=$2
+	DBNAME=$3
+	DBTEMPLATE=$4
+	DBUSER=$5
+}
+
+
 #show Database Configuration
 function show_db_config(){
     echo ""
@@ -118,46 +111,14 @@
 
 }
 
-function create_mysql_db(){
-    which mysql > /dev/null
-    if [ $? -ne 0 ]
-    then
-        echo "commando mysql, but not found, exiting..."
-        echo "is mysql installed?"
-        echo ""
-        exit 1;
-    fi
 
-    echo "Your password will be asked several times, this is normal"
-    echo "creating database"
-    if [ $DBENCODING = "ISO-8859-1" ]
-    then
-        mysql -e "create database $DBNAME CHARACTER SET latin1 COLLATE latin1_german1_ci;" -p$DBPASSWORD -u $DBUSER
-    else
-        mysql -e "create database $DBNAME CHARACTER SET utf8 COLLATE utf8_general_ci;" -p$DBPASSWORD -u $DBUSER
-    fi
-	echo "creating schema"
-	mysql $DBNAME -p$DBPASSWORD -u $DBUSER -h $DBHOST -P $DBPORT < mysql/mysql_schema_2.5.sql > log_schema.txt 2> err_schema.txt
-	echo "loading data"
-	mysql $DBNAME -p$DBPASSWORD -u $DBUSER -h $DBHOST -P $DBPORT < mysql/$DBENCODING/mysql_data_2.5.sql > log_data.txt 2> err_data.txt
-	echo "update to 2.5.1rc1"
-	mysql $DBNAME -p$DBPASSWORD -u $DBUSER -h $DBHOST -P $DBPORT < mysql/$DBENCODING/update/update_2.5_to_2.5.1rc1_mysql_$DBENCODING.sql > log_update.txt 2> err_update.txt
-	echo "update to 2.5.1"
-	mysql $DBNAME -p$DBPASSWORD -u $DBUSER -h $DBHOST -P $DBPORT < mysql/$DBENCODING/update/update_2.5.1rc1_to_2.5.1_mysql_$DBENCODING.sql >> log_update.txt 2>> err_update.txt
-	echo "update to 2.6rc1"
-	mysql $DBNAME -p$DBPASSWORD -u $DBUSER -h $DBHOST -P $DBPORT < mysql/$DBENCODING/update/update_2.5.1_to_2.6rc1_mysql_$DBENCODING.sql >> log_update.txt 2>> err_update.txt
-	echo "update to 2.6"
-	mysql $DBNAME -p$DBPASSWORD -u $DBUSER -h $DBHOST -P $DBPORT < mysql/$DBENCODING/update/update_2.6rc1_to_2.6_mysql_$DBENCODING.sql >> log_update.txt 2>> err_update.txt
 
-	
-}
-
 #Create Database (Postgres)
 function create_pgsql_db(){
     which psql createdb > /dev/null
     if [ $? -ne 0 ]
     then
-        echo "commando pgsql or createdb needed, but not found, exiting..."
+        echo "commando psql or createdb needed, but not found, exiting..."
         echo "is PostgreSQL installed?"
         echo ""
         exit 1;
@@ -167,7 +128,7 @@
     createdb -U $DBUSER  -h $DBHOST -p $DBPORT -E $DBENCODING $DBNAME -T $DBTEMPLATE
     echo "creating schema"
 	psql -U $DBUSER  -h $DBHOST -p $DBPORT -f pgsql/pgsql_schema_2.5.sql $DBNAME > log_schema.txt 2> err_schema.txt
-    echo "loading data"	
+    echo "loading data"
     psql -U $DBUSER  -h $DBHOST -p $DBPORT -f pgsql/$DBENCODING/pgsql_data_2.5.sql $DBNAME > log_data.txt 2> err_data.txt
 	echo "setting sequences"
     psql -U $DBUSER  -h $DBHOST -p $DBPORT -f pgsql/pgsql_serial_set_sequences_2.5.sql $DBNAME > log_sequences.txt 2> err_squences.txt
@@ -179,8 +140,8 @@
 	psql -U $DBUSER  -h $DBHOST -p $DBPORT -f pgsql/$DBENCODING/update/update_2.5.1_to_2.6rc1_pgsql_$DBENCODING.sql $DBNAME >> log_update.txt 2>> err_update.txt
 	echo "update to 2.6"
 	psql -U $DBUSER  -h $DBHOST -p $DBPORT -f pgsql/$DBENCODING/update/update_2.6rc1_to_2.6_pgsql_$DBENCODING.sql $DBNAME >> log_update.txt 2>> err_update.txt
-
-
+	echo "update to 2.6.1"
+	psql -U $DBUSER  -h $DBHOST -p $DBPORT -f pgsql/$DBENCODING/update/update_2.6_to_2.6.1_pgsql_$DBENCODING.sql $DBNAME >> log_update.txt 2>> err_update.txt
 }
 
 function set_permissions(){
@@ -218,7 +179,7 @@
           fi
           echo ""
           echo "please check and edit the entries in your mapbender.conf manually!"
-          
+
     fi
 }
 
@@ -239,13 +200,23 @@
 #magic starts here
 show_disclaimer;
 
-echo "Continue? (y)es or (n)o"
-read disclaimer
-if test $disclaimer != "y"
+# we only support postgresql and utf-8
+DBENCODING="UTF-8"
+DBVERSION="pgsql"
+if [ $# -ne 5 ]
 then
-	exit 1
-fi
-get_db_config;
+	echo "Continue? (y)es or (n)o"
+	read disclaimer
+	if test $disclaimer != "y"
+	then
+		exit 1
+	fi
+	echo "get_db_config - variables have to be set"	
+	get_db_config;
+else
+	echo "set_db_config - variables where passed when the script was called"
+	set_db_config $@;
+fi;
 show_db_config;
 echo "Look ok? Start Install? (y)es or (n)o"
 read ANSWER
@@ -254,15 +225,8 @@
     exec $0
 fi
 
-if [ $DBVERSION = "pgsql" ]
-then
-    echo "Creating Postgres Database with encoding:$DBENCODING"
-    create_pgsql_db;
-else
-    echo "Creating Mysql Database with encoding:$DBENCODING"
-    create_mysql_db;
-    echo ""
-fi
+echo "Creating Mapbender administration database"
+create_pgsql_db;
 
 set_permissions;
 compile_po;



More information about the Mapbender_commits mailing list