[Mapbender-commits] r4287 - branches/2.6/resources/db
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Jul 2 14:00:11 EDT 2009
Author: tbaschetti
Date: 2009-07-02 14:00:11 -0400 (Thu, 02 Jul 2009)
New Revision: 4287
Modified:
branches/2.6/resources/db/install_2.6.sh
Log:
rewritten to use functions
Modified: branches/2.6/resources/db/install_2.6.sh
===================================================================
--- branches/2.6/resources/db/install_2.6.sh 2009-07-02 11:28:22 UTC (rev 4286)
+++ branches/2.6/resources/db/install_2.6.sh 2009-07-02 18:00:11 UTC (rev 4287)
@@ -1,232 +1,244 @@
#!/bin/bash
#
+# create database for mapbender
+#
-rm log_*.txt
-rm err_*.txt
+function show_disclaimer() {
+ # Disclaimer
+ echo ""
+ echo "DISCLAIMER: this Mapbender database setup script is not stable. 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 ""
+ echo "To run this script you have to set the following options"
+ # echo " * set the right to execute on this install script"
+ # echo " * set the right to execute on mapbender/tools/i18n_update_mo.sh"
+ # echo " * write access to mapbender/log"
+ # echo " * write access to mapbender/http/tmp"
+ # echo " * write access to mapbender/resources/locale/ and subdirectories"
+ echo " * provide a database user that can create a database"
+ echo ""
+ echo ""
+ echo "If everything is prepared you can continue."
+ echo ""
+}
-# Disclaimer
-echo ""
-echo "DISCLAIMER: this Mapbender database setup script is not stable. 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 ""
-echo "To run this script you have to set the following options"
-# echo " * set the right to execute on this install script"
-# echo " * set the right to execute on mapbender/tools/i18n_update_mo.sh"
-# echo " * write access to mapbender/log"
-# echo " * write access to mapbender/http/tmp"
-# echo " * write access to mapbender/resources/locale/ and subdirectories"
-echo " * provide a database user that can create a database"
-echo ""
-echo ""
-echo "If everything is prepared you can continue."
-echo ""
-echo "Continue? (y)es or (n)o"
-read disclaimer
+function del_logfile() {
+ rm log_*.txt
+ rm err_*.txt
-if test $disclaimer != "y"
-then
- exit 1
-fi
+}
-# ask for db version
-echo ""
-echo "Database version? (p)ostgresql or (m)ysql?"
-read dbversion
+#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
-if test $dbversion != "p" -a $dbversion != "m"
-then
- echo ""
- echo "Incorrect database type. Terminating the script..."
- exit 1
-fi
+ # 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
-# ask for db character encoding-U $dbuser
-echo ""
-echo "Database character encoding? (i)so-8859-1 or (u)tf-8?"
-read dbenc
+ #nicer vars
+ if [ "$DBVERSION" = "p" ]
+ then
+ DBVERSION="pgsql"
+ else
+ DBVERSION="mysql"
+ fi
-if test $dbenc != "i" -a $dbenc != "u"
-then
- echo ""
- echo "Incorrect database character encoding. Terminating the script..."
- exit 1
-fi
+ if [ "$DBENCODING" = "i" ]
+ then
+ DBENCODING="ISO-8859-1"
+ else
+ DBENCODING="UTF-8"
+ fi
-# ask for database name
-echo ""
-echo "Name of database?"
-read dbname
+ 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
+# echo ""
+# echo "Password for $DBUSER (will not be shown)?"
+# stty -echo
+# read DBPASSWORD
+# stty echo
-if test $dbversion = "m"
-then
+}
- echo "Not available!!!"
- exit 1
+#show Database Configuration
+function show_db_config(){
+ echo ""
+ echo "Database Configuration:"
+ echo "version:" $DBVERSION
+ echo "encoding:" $DBENCODING
+ if [ $DBTEMPLATE ]
+ then
+ echo "postgres template:" $DBTEMPLATE
+ fi
+ echo "dbname:" $DBNAME
+ echo "user:" $DBUSER
+ echo ""
- echo ""
- echo "Enter your MySQL password:"
- stty -echo
- read password
- stty echo
- echo ""
+}
- if test $dbenc = "i"
- then
- echo ""
- echo "Installing Mapbender with MySQL (ISO-8859-1) in database $dbname";
- echo ""
+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
- mysql -e "create database $dbname CHARACTER SET latin1 COLLATE latin1_german1_ci;" -p$password
- mysql $dbname -p$password < mysql/mysql_schema_2.5.sql > log_schema.txt 2> err_schema.txt
- mysql $dbname -p$password < mysql/ISO-8859-1/mysql_data_2.5.sql > log_data.txt 2> err_data.txt
- mysql $dbname -p$password < mysql/ISO-8859-1/update/update_2.5_to_2.5.1rc1_mysql_ISO-8859-1.sql > log_update.txt 2> err_update.txt
- mysql $dbname -p$password < mysql/ISO-8859-1/update/update_2.5.1rc1_to_2.5.1_mysql_ISO-8859-1.sql >> log_update.txt 2>> err_update.txt
- mysql $dbname -p$password < mysql/ISO-8859-1/update/update_2.5.1_to_2.6rc1_mysql_ISO-8859-1.sql >> log_update.txt 2>> err_update.txt
+ echo "MYSQL-Version not available!!!"
+ echo ""
+ exit 1
+ if [ $DBENCODING = "ISO-8859-1" ]
+ then
+ mysql -e "create database $DBNAME CHARACTER SET latin1 COLLATE latin1_german1_ci;" -p$DBPASSWORD
+ else
+ mysql -e "create database $DBNAME CHARACTER SET utf8 COLLATE utf8_general_ci;" -p$DBPASSWORD
+ fi
+ mysql $DBNAME -p$DBPASSWORD < mysql/mysql_schema_2.5.sql > log_schema.txt 2> err_schema.txt
+ mysql $DBNAME -p$DBPASSWORD < mysql/$DBENCODING/mysql_data_2.5.sql > log_data.txt 2> err_data.txt
+ mysql $DBNAME -p$DBPASSWORD < mysql/$DBENCODING/update/update_2.5_to_2.5.1rc1_mysql_$DBENCODING.sql > log_update.txt 2> err_update.txt
+ mysql $DBNAME -p$DBPASSWORD < mysql/$DBENCODING/update/update_2.5.1rc1_to_2.5.1_mysql_$DBENCODING.sql >> log_update.txt 2>> err_update.txt
+ mysql $DBNAME -p$DBPASSWORD < mysql/$DBENCODING/update/update_2.5.1_to_2.6rc1_mysql_$DBENCODING.sql >> log_update.txt 2>> err_update.txt
- elif test $dbenc = "u"
- then
- echo ""
- echo "Installing Mapbender with MySQL (UTF-8) in database $dbname";
- echo ""
+}
- mysql -e "create database $dbname CHARACTER SET utf8 COLLATE utf8_general_ci;" -p$password
- mysql $dbname -p$password < mysql/mysql_schema_2.5.sql > log_schema.txt 2> err_schema.txt
- mysql $dbname -p$password < mysql/UTF-8/mysql_data_2.5.sql > log_data.txt 2> err_data.txt
- mysql $dbname -p$password < mysql/UTF-8/update/update_2.5_to_2.5.1rc1_mysql_UTF-8.sql > log_update.txt 2> err_update.txt
- mysql $dbname -p$password < mysql/UTF-8/update/update_2.5.1rc1_to_2.5.1_mysql_UTF-8.sql >> log_update.txt 2>> err_update.txt
- mysql $dbname -p$password < mysql/UTF-8/update/update_2.5.1_to_2.6rc1_mysql_UTF-8.sql >> log_update.txt 2>> err_update.txt
- fi
-elif test $dbversion = "p" -a $dbenc = "i"
-then
- #Creating database user with rw access
- echo "Please specify a user for the database"
- read mapbenderuser
-
-
-
- echo ""
- echo "Installing Mapbender with PostgreSQL (ISO-8859-1) in database $dbname";
- echo ""
-
- # ask for database user
+#Datenbank erzeugen
+function create_pgsql_db(){
+ which psql createdb > /dev/null
+ if [ $? -ne 0 ]
+ then
+ echo "commando pgsql or createdb needed, but not found, exiting..."
+ echo "is PostgreSQL installed?"
echo ""
- echo "Name of database user?"
- read dbuser
+ exit 1;
+ fi
+ echo "Your password will be asked several times, this is normal (unless .pgpass is used)"
+ echo "creating database"
+ createdb -U $DBUSER -E $DBENCODING $DBNAME -T $DBTEMPLATE
+ echo "creating schema"
+ psql -U $DBUSER -f pgsql/pgsql_schema_2.5.sql $DBNAME > log_schema.txt 2> err_schema.txt
+ echo "loading data"
+ psql -U $DBUSER -f pgsql/$DBENCODING/pgsql_data_2.5.sql $DBNAME > log_data.txt 2> err_data.txt
+ echo "setting sequences"
+ psql -U $DBUSER -f pgsql/pgsql_serial_set_sequences_2.5.sql $DBNAME > log_sequences.txt 2> err_squences.txt
+ echo "update to 2.5.1rc1"
+ psql -U $DBUSER -f pgsql/$DBENCODING/update/update_2.5_to_2.5.1rc1_pgsql_$DBENCODING.sql $DBNAME > log_update.txt 2> err_update.txt
+ echo "update to 2.5.1"
+ psql -U $DBUSER -f pgsql/$DBENCODING/update/update_2.5.1rc1_to_2.5.1_pgsql_$DBENCODING.sql $DBNAME >> log_update.txt 2>> err_update.txt
+ echo "update to 2.6rc1"
+ psql -U $DBUSER -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.6rc2"
+ psql -U $DBUSER -f pgsql/$DBENCODING/update/update_2.6rc1_to_2.6rc2_pgsql_$DBENCODING.sql $DBNAME >> log_update.txt 2>> err_update.txt
- #ask for database template
- echo ""
- echo "Do you want to use a database template? (y)es or (n)o "
- read dbtemplateuse
- if test $dbtemplateuse = "y"
- then
- #ask for template name
- echo ""
- echo "Name of the template?"
- read dbtemplate
- fi
-
- if test -n "$dbtemplate"
- then
- createdb -U $dbuser -E ISO-8859-1 $dbname -T $dbtemplate
- else
- createdb -U $dbuser -E ISO-8859-1 $dbname
- fi
+}
- psql -U $dbuser -f pgsql/pgsql_schema_2.5.sql $dbname > log_schema.txt 2> err_schema.txt
- psql -U $dbuser -f pgsql/ISO-8859-1/pgsql_data_2.5.sql $dbname > log_data.txt 2> err_data.txt
- psql -U $dbuser -f pgsql/pgsql_serial_set_sequences_2.5.sql $dbname > log_sequences.txt 2> err_squences.txt
- psql -U $dbuser -f pgsql/ISO-8859-1/update/update_2.5_to_2.5.1rc1_pgsql_ISO-8859-1.sql $dbname > log_update.txt 2> err_update.txt
- psql -U $dbuser -f pgsql/ISO-8859-1/update/update_2.5.1rc1_to_2.5.1_pgsql_ISO-8859-1.sql $dbname >> log_update.txt 2>> err_update.txt
- psql -U $dbuser -f pgsql/ISO-8859-1/update/update_2.5.1_to_2.6rc1_pgsql_ISO-8859-1.sql $dbname >> log_update.txt 2>> err_update.txt
+function set_permissions(){
+ echo "The installer can set the permissions to the files"
+ echo "and directory for you. If you want the installer to"
+ echo "do this please enter (y)es else (n)o"
+ echo "Please note, to do this you have to be"
+ echo "read write access to the Mapbender directory"
+ echo "set permissions, (y)es or (n)?"
+ read automatic
-elif test $dbversion = "p" -a $dbenc = "u"
-then
- echo ""
- echo "Installing Mapbender with PostgreSQL (UTF-8) in database $dbname";
- echo ""
-
- # ask for database user
- echo ""
- echo "Name of database user?"
- read dbuser
+ if test $automatic != "n"
+ then
+ echo "Do you want that all files are owned by the apache webserver? (y)es or (n)o"
+ read setowner
+ if test $setowner != "n"
+ then
+ echo "Please specify the webserver user"
+ read webservuser
+ chown -R $webservuser:$webservuser ../../
+ fi
+ echo "setting permissions on /resources/locale/ and subdirectories"
+ chmod -R o+rw ../locale
+ echo "setting execute rights on mapbender/tools/i18n_update_mo.sh"
+ chmod -R o+rx ../../tools/i18n_update_mo.sh
+ # creating mapbender.conf
+ cp ../../conf/mapbender.conf-dist ../../conf/mapbender.conf
+
+ fi
+}
- #ask for database template
- echo ""
- echo "Do you want to use a database template? (y)es or (n)o "
- read dbtemplateuse
+function compile_po(){
+ echo ""
+ echo "Compiling .po files..."
+ cd ../../tools/
+ sh ./i18n_update_mo.sh
+ cd ../resources/db/
+ echo "removing permissions on /resources/locale/ and subdirectories"
+ chmod -R o-rw ../locale
+ echo "removing execute rights on mapbender/tools/i18n_update_mo.sh"
+ chmod -R o-rx ../../tools/i18n_update_mo.sh
+ echo ""
+}
- if test $dbtemplateuse = "y"
- then
- #ask for template name
- echo ""
- echo "Name of the template?"
- read dbtemplate
- fi
-
- echo "The script will ask you several times for your database password. Don't be confused about this."
-
- if test -n "$dbtemplate"
- then
- createdb -U $dbuser -E UTF-8 $dbname -T $dbtemplate
- else
- createdb -U $dbuser -E UTF-8 $dbname
- fi
+#magic starts here
+show_disclaimer;
- echo "creating schema"
- psql -U $dbuser -f pgsql/pgsql_schema_2.5.sql $dbname > log_schema.txt 2> err_schema.txt
- echo "importing 2.5 data"
- psql -U $dbuser -f pgsql/UTF-8/pgsql_data_2.5.sql $dbname > log_data.txt 2> err_data.txt
- echo "setting sequences"
- psql -U $dbuser -f pgsql/pgsql_serial_set_sequences_2.5.sql $dbname > log_sequences.txt 2> err_sequences.txt
- echo "update to 2.5.1rc1"
- psql -U $dbuser -f pgsql/UTF-8/update/update_2.5_to_2.5.1rc1_pgsql_UTF-8.sql $dbname > log_update.txt 2> err_update.txt
- echo "update to 2.5.1"
- psql -U $dbuser -f pgsql/UTF-8/update/update_2.5.1rc1_to_2.5.1_pgsql_UTF-8.sql $dbname >> log_update.txt 2>> err_update.txt
- echo "update to 2.6rc1"
- psql -U $dbuser -f pgsql/UTF-8/update/update_2.5.1_to_2.6rc1_pgsql_UTF-8.sql $dbname >> log_update.txt 2>> err_update.txt
- echo "update to 2.6rc2"
- psql -U $dbuser -f pgsql/UTF-8/update/update_2.6rc1_to_2.6rc2_pgsql_UTF-8.sql $dbname >> log_update.txt 2>> err_update.txt
+echo "Continue? (y)es or (n)o"
+read disclaimer
+if test $disclaimer != "y"
+then
+ exit 1
fi
+get_db_config;
+show_db_config;
+echo "Look ok? Start Install? (y)es or (n)o"
+read ANSWER
+if [ $ANSWER != "y" ]
+then
+ exec $0
+fi
-echo "The installer can set the permissions to the files"
-echo "and directory for you. If you want the installer to"
-echo "do this please enter (y)es else (n)o"
-echo "Please note, to do this you have to be"
-echo "read write access to the Mapbender directory"
-read automatic
-
-if test $automatic != "n"
+if [ $DBVERSION = "pgsql" ]
then
- echo "Do you want that all files are owned by the apache webserver? (y)es or (n)o"
- read setowner
- if test $setowner != "n"
- then
- echo "Please specify the webserver user"
- read webservuser
- chown -R $webservuser:$webservuser ../../
- fi
- echo "setting permissions on /resources/locale/ and subdirectories"
- chmod -R o+rw ../locale
- echo "setting execute rights on mapbender/tools/i18n_update_mo.sh"
- chmod -R o+rx ../../tools/i18n_update_mo.sh
- # creating mapbender.conf
- cp ../../conf/mapbender.conf-dist ../../conf/mapbender.conf
-
+ echo "Creating Postgres Database with encoding:$DBENCODING"
+ create_pgsql_db;
+else
+ echo "Creating Mysql Database with encoding:$DBENCODING"
+ create_mysql_db;
+ echo ""
fi
+set_permissions;
+compile_po;
+
echo ""
-echo "Compiling .po files..."
-cd ../../tools/
-sh ./i18n_update_mo.sh
-cd ../resources/db/
-echo "removing permissions on /resources/locale/ and subdirectories"
-chmod -R o-rw ../locale
-echo "removing execute rights on mapbender/tools/i18n_update_mo.sh"
-chmod -R o-rx ../../tools/i18n_update_mo.sh
-echo ""
-echo ""
-echo "Finished...check the log files to see if an error occured.";
+echo "Finished...check the log and error files to see if an error occured.";
+
+
More information about the Mapbender_commits
mailing list