Last active
August 29, 2015 13:57
-
-
Save hasithaa/9873179 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # | |
| # Copyright (c) 2014. | |
| # This file is licensed under the Apache License, | |
| # Version 2.0 (the "License"); you may not use this file except | |
| # in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Author : Hasitha Aravinda (GitHub: https://github.com/hasitha-aravinda) | |
| # Date: 30/03/2014 | |
| # | |
| database="na" | |
| bpsZipFile="na" | |
| bpsVersion="na" | |
| #Current Directory | |
| workingDir=$(pwd) | |
| SCRIPT=$(readlink -f "$0") | |
| # Absolute path this script is in | |
| home=$(dirname "$SCRIPT") | |
| echo "==========================================================" | |
| echo " Configuring WSO2-BPS with H2/MySQL/Oracle Database" | |
| echo "==========================================================" | |
| echo "Script HOME $home" | |
| echo "Working direcory $workingDir" | |
| echo " " | |
| sleep 1 | |
| echo ">> Checking for previous BPS installation(s) in working directory..." | |
| sleep 1 | |
| cd $workingDir | |
| #Cleaning previous unzipped directories. | |
| if [ "`find -iname "wso2bps-3*" -type d`" ]; then | |
| echo "[Warning] Found following BPS installation(s) in the working directory." | |
| find `pwd` -iname "wso2bps-3*" -type d | xargs printf "\t* %s\t\n" | |
| echo " " | |
| read -p "Do you want to delete these directories (yes/no, default yes)? " yes_no_response; yes_no_response=${yes_no_response:-y} | |
| if [ $yes_no_response = "y" ] || [ $yes_no_response = "yes" ]; then | |
| echo " " | |
| echo ">> Cleaning directories..." | |
| #Deleting directories. | |
| find `pwd` -iname "wso2bps-3*" -type d | xargs rm -rf | |
| echo ">> Cleaning directories is completed..." | |
| elif [ $yes_no_response = "n" ] || [ $yes_no_response = "no" ]; then | |
| echo ">> Exiting script, since previous installation exists in working directory...!!!" | |
| exit 1; | |
| else | |
| echo "[Error] Invalid input, exiting script ...!!! " | |
| exit 1; | |
| fi | |
| fi | |
| sleep 1 | |
| echo " " | |
| echo "--------------------------------------" | |
| echo " Installing WSO2BPS" | |
| echo "--------------------------------------" | |
| cd $home | |
| if [ "`find -iname wso2bps*.zip`" ]; then | |
| echo "Available BPS zip files in script home" | |
| find `pwd` -iname "wso2bps*.zip" | xargs printf " %s\n" | |
| # Picking last one as default | |
| defaultZip=$(find `pwd` -iname "wso2bps*.zip" | tail -1) | |
| echo " " | |
| read -p "Enter wso2bps zip file path to continue. ( Default $defaultZip ): " bpsZipFile; bpsZipFile=${bpsZipFile:-$defaultZip} | |
| echo " " | |
| echo ">> Unzipping $bpsZipFile to working directory $workingDir" | |
| unzip -q -d $workingDir $bpsZipFile | |
| if [ $? -ne 0 ]; then | |
| echo "[Error] previous operation failed. Exiting script." | |
| exit 1; | |
| fi | |
| #Validating folder. | |
| cd $workingDir | |
| if [ "`find -iname "wso2bps*" -type d`" ]; then | |
| bpsVersion=$(ls wso2bps* -d | head -1) | |
| else | |
| echo "Unzipped folder validation failed." | |
| exit 1; | |
| fi | |
| sleep 1 | |
| else | |
| echo "Can't find wso2bps zip in working directory. Exiting script." | |
| exit 1; | |
| fi | |
| echo " " | |
| echo " " | |
| echo "--------------------------------------" | |
| echo " Select Database for $bpsZipFile" | |
| echo "--------------------------------------" | |
| echo " " | |
| echo " 1 - H2" | |
| echo " 2 - MySQL " | |
| echo " 3 - Oracle" | |
| echo " " | |
| read -p "Enter Database number (1,2 or 3 , default h2) :" databaseInput; databaseInput=${databaseInput:-h} | |
| if [ $databaseInput = "1" ] || [ $databaseInput = "h" ] || [ $databaseInput = "h2" ]; then | |
| database="h2" | |
| elif [ $databaseInput = "2" ] || [ $databaseInput = "m" ] || [ $databaseInput = "mysql" ]; then | |
| database="mysql" | |
| elif [ $databaseInput = "3" ] || [ $databaseInput = "o" ] || [ $databaseInput = "oracle" ]; then | |
| database="oracle" | |
| else | |
| echo "[Error] Invalid input, exiting script ...!!! " | |
| exit 1; | |
| fi | |
| #H2 logic | |
| if [ $database = "h2" ]; then | |
| echo "By Default WSO2 BPS is configured with H2 database" | |
| fi | |
| #MySQL logic | |
| if [ $database = "mysql" ]; then | |
| echo " " | |
| echo "--------------------------------------" | |
| echo " Copying jdbc connector" | |
| echo "--------------------------------------" | |
| echo ">> Searching for mysql-connector jar" | |
| cd $home | |
| if [ "`find -iname mysql-connector-java-5.*-bin.jar`" ]; then | |
| connectorJar=$(find `pwd` -iname mysql-connector-java-5.*-bin.jar | head -1) | |
| echo " Found $connectorJar" | |
| echo ">> Copying $connectorJar" | |
| cp $connectorJar $workingDir/$bpsVersion/repository/components/lib -v | |
| if [ $? -ne 0 ]; then | |
| echo "[Error] previous operation failed. Exiting script." | |
| exit 1; | |
| fi | |
| else | |
| echo "Can't find mysql-connector jar in working directory." | |
| exit 1; | |
| fi | |
| echo " " | |
| echo "--------------------------------------" | |
| echo " Setting up $database database." | |
| echo "--------------------------------------" | |
| read -p "Enter MySQL DB name : " db_name; | |
| read -p "Enter MySQL DB user name : " db_user; | |
| read -p "Enter MySQL DB user password : " db_password; | |
| cd $workingDir | |
| echo "" | |
| echo ">> Setting up datasources.properties for Mysql " | |
| echo ">> Setting up datasources url : jdbc:mysql://localhost:3306/$db_name" | |
| sed -i "s/jdbc:h2:file:repository\/database\/jpadb;MVCC=TRUE/jdbc:mysql:\/\/localhost:3306\/$db_name/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| echo ">> Setting up datasources driverClassName : com.mysql.jdbc.Driver" | |
| sed -i "s/org.h2.Driver/com.mysql.jdbc.Driver/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| echo ">> Setting up datasources user name : $db_user" | |
| sed -i "s/synapse.datasources.bpsds.username=wso2carbon/synapse.datasources.bpsds.username=$db_user/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| echo ">> Setting up datasources user password : $db_password" | |
| sed -i "s/synapse.datasources.bpsds.password=wso2carbon/synapse.datasources.bpsds.password=$db_password/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| echo "" | |
| echo ">> Creating MySql database" | |
| sleep 1 | |
| mysql -u $db_user -p$db_password -e "DROP DATABASE IF EXISTS $db_name; CREATE DATABASE $db_name; use $db_name; source $workingDir/$bpsVersion/dbscripts/bps/mysql.sql; commit;" | |
| if [ $? -ne 0 ]; then | |
| echo "Database creation problem detected. Exiting script." | |
| exit 1; | |
| fi | |
| fi | |
| #Oracle logic | |
| if [ $database = "oracle" ]; then | |
| echo " " | |
| echo "--------------------------------------" | |
| echo " Copying jdbc connector" | |
| echo "--------------------------------------" | |
| echo "Searching for oracle jdbc 6 jar" | |
| cd $home | |
| if [ "`find -iname ojdbc6.jar`" ]; then | |
| connectorJar=$(find `pwd` -iname ojdbc6.jar | head -1) | |
| cp $connectorJar $workingDir/$bpsVersion/repository/components/lib -v | |
| if [ $? -ne 0 ]; then | |
| echo "[Error] previous operation failed. Exiting script." | |
| exit 1; | |
| fi | |
| else | |
| echo "Can't find ojdbc6.jar in working directory." | |
| exit 1; | |
| fi | |
| echo " " | |
| echo "--------------------------------------" | |
| echo " Setting up $database database." | |
| echo "--------------------------------------" | |
| read -p "Enter Oracle sys admin name : " db_sysdba; | |
| read -p "Enter Oracle sys admin password : " db_sysdbapass; | |
| read -p "Enter Oracle DB user name : " db_user; | |
| read -p "Enter Oracle DB user password : " db_password; | |
| echo " " | |
| echo ">> Restarting oracle instance" | |
| sudo /etc/init.d/oracle-xe restart | |
| echo ">> Creating database" | |
| sleep 1 | |
| if [ $? -ne 0 ]; then | |
| echo "Database creation problem detected. Exiting script." | |
| exit 1; | |
| fi | |
| cd $workingDir | |
| echo ">> Setting up datasources.properties for Oracle " | |
| read -p "Enter datasources url, Press ENTER to use jdbc:oracle:thin:@localhost:1521/XE : " ds_url; ds_url=${ds_url:-xe} | |
| if [ $ds_url = "xe" ]; then | |
| echo ">> Setting up datasources url : jdbc:oracle:thin:@localhost:1521/XE" | |
| sed -i "s/jdbc:h2:file:repository\/database\/jpadb;MVCC=TRUE/jdbc:oracle:thin:@localhost:1521\/XE/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| else | |
| echo ">> Setting up datasources url : $ds_url" | |
| sed -i "s/jdbc:h2:file:repository\/database\/jpadb;MVCC=TRUE/$ds_url/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| fi | |
| echo ">> Setting up datasources driverClassName : oracle.jdbc.driver.OracleDriver" | |
| sed -i "s/org.h2.Driver/oracle.jdbc.driver.OracleDriver/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| echo ">> Setting up datasources user name : $db_user" | |
| sed -i "s/synapse.datasources.bpsds.username=wso2carbon/synapse.datasources.bpsds.username=$db_user/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| echo ">> Setting up datasources user password : $db_password" | |
| sed -i "s/synapse.datasources.bpsds.password=wso2carbon/synapse.datasources.bpsds.password=$db_password/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| echo ">> Setting up validation Query : SELECT 1 FROM DUAL" | |
| sed -i "s/SELECT 1/SELECT 1 FROM DUAL/g" $workingDir/$bpsVersion/repository/conf/datasources.properties | |
| echo "" | |
| echo ">> Creating Oracle database. Dropping user if exists." | |
| sleep 1 | |
| sqlplus -s /nolog << ENDOFSQL | |
| CONNECT $db_sysdba/$db_sysdbapass AS sysdba; | |
| DEF username = $db_user | |
| DEF default_ts = USERS | |
| DEF temp_ts = TEMP | |
| DECLARE | |
| v_count INTEGER := 0; | |
| v_statement VARCHAR2 (500); | |
| BEGIN | |
| SELECT COUNT (1) INTO v_count FROM dba_users WHERE username = UPPER ('&username'); | |
| IF v_count != 0 | |
| THEN | |
| EXECUTE IMMEDIATE ('DROP USER &username CASCADE'); | |
| END IF; | |
| v_count := 0; | |
| EXCEPTION | |
| WHEN OTHERS | |
| THEN | |
| DBMS_OUTPUT.put_line (SQLERRM); | |
| DBMS_OUTPUT.put_line (' '); | |
| END; | |
| / | |
| COMMIT; | |
| CREATE USER $db_user IDENTIFIED BY $db_password ACCOUNT UNLOCK; | |
| GRANT CONNECT TO $db_user; | |
| GRANT CREATE SESSION, dba TO $db_user; | |
| COMMIT; | |
| CONNECT $db_user/$db_password | |
| @$workingDir/$bpsVersion/dbscripts/bps/oracle.sql; | |
| ENDOFSQL | |
| fi | |
| read -p "Do you want to apply patches to $bpsVersion (yes/no , default no): " installPatch; installPatch=${installPatch:-n} | |
| if [ $installPatch = "y" ] || [ $installPatch = "yes" ]; then | |
| echo " " | |
| echo "--------------------------------------" | |
| echo " Installing patches $bpsVersion" | |
| echo "--------------------------------------" | |
| sleep 1 | |
| cd $home | |
| echo "Available patches in Script Home" | |
| echo "" | |
| find `pwd` -iname *patch* -type d | xargs tree -L 2 | |
| echo " " | |
| read -p "Enter parent folder of patches. Press Enter to skip. : " patchPathInput; patchPathInput=${patchPathInput:-s} | |
| if [ $patchPathInput = "s" ] ; then | |
| echo ">> Skipping patches!!!" | |
| else | |
| echo ">> Copying patches..." | |
| cp -r $patchPathInput/patch* $workingDir/$bpsVersion/repository/components/patches -v | |
| if [ $? -ne 0 ]; then | |
| echo "[Error] previous operation failed. Exiting script." | |
| exit 1; | |
| fi | |
| fi | |
| fi | |
| echo "" | |
| echo "--------------------------------------" | |
| echo " Completed." | |
| echo "--------------------------------------" | |
| echo " Setting up $bpsVersion with $database database is completed" | |
| echo " BPS home : $workingDir/$bpsVersion" | |
| echo " Database configuration can be found at $workingDir/$bpsVersion/repository/conf/datasources.properties" | |
| echo "" | |
| exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment