diff --git a/CHANGELOG b/CHANGELOG index dc7ec032b99ec58a1be6fb7e514e471faed7d874..b3a72ab6e7c53d9fd28fd5f0602210116b8eac36 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +minerva (12.1.0~alpha.0) unstable; urgency=medium + * Feature: database connection configuration (login, password, host, etc) + can be modified using /etc/minerva/db.properties file + + -- Piotr Gawron <piotr.gawron@uni.lu> Mon, 9 Apr 2018 13:00:00 +0200 + minerva (12.0.0~beta.1) unstable; urgency=medium * Bug fix: issues that appeared in 12.0.0~beta.0 diff --git a/debian/create-debian-pkg.sh b/debian/create-debian-pkg.sh index 654df170b9de5f453019e137908583eb9650cc6b..1da14fa3436067f4a90d5deb5eecfa90b07266ec 100755 --- a/debian/create-debian-pkg.sh +++ b/debian/create-debian-pkg.sh @@ -70,6 +70,14 @@ then exit 1; fi + +#default connection params (if /etc/minerva/db.properties is not defined) +DB_HOST=`cat persist/src/main/resources/db.properties |grep "uri" |cut -f3 -d"/" |cut -f1 -d":"` +DB_PORT=`cat persist/src/main/resources/db.properties |grep "uri" |cut -f3 -d"/" |cut -f2 -d":"` +DB_DATABASE_NAME=`cat persist/src/main/resources/db.properties |grep "uri" |cut -f4 -d"/"` +DB_USERNAME=`cat persist/src/main/resources/db.properties |grep "username" |cut -f2 -d"="` +DB_PASSWORD=`cat persist/src/main/resources/db.properties |grep "password" |cut -f2 -d"="` + #------------------------------------------ # Now we have all db schema diff files. Let's start preparing # debian package @@ -107,11 +115,20 @@ sed -i "s/__LOG_FILE__/$LOG_FILE/g" common.sh #in the filesystem where package is installed sed -i "s/__DB_SCRIPT_DIR__/$DB_SCRIPT_DIR/g" common.sh +sed -i "s/__DB_HOST__/$DB_HOST/g" common.sh +sed -i "s/__DB_PORT__/$DB_PORT/g" common.sh +sed -i "s/__DB_DATABASE_NAME__/$DB_DATABASE_NAME/g" common.sh +sed -i "s/__DB_USERNAME__/$DB_USERNAME/g" common.sh +sed -i "s/__DB_PASSWORD__/$DB_PASSWORD/g" common.sh + sed -i -e "1r common.sh" debian/postinst sed -i -e "1r common.sh" debian/postrm sed -i -e "1r common.sh" debian/preinst sed -i -e "1r common.sh" debian/prerm + + + #put scripts into $DB_SCRIPT_DIR (it's a bit different than varaiable because it's not #escaped echo db_0.sql /usr/share\/minerva/schema >> debian/install diff --git a/debian/scripts/common.sh b/debian/scripts/common.sh index 246724cb9444cdf4d2c503fe804ab3d973ffa338..2b5d61837f794dd009b68265814570874af93999 100644 --- a/debian/scripts/common.sh +++ b/debian/scripts/common.sh @@ -27,3 +27,74 @@ if [ "$TOMCAT8_OK" != "" ]; then TOMCAT_PACKAGE='tomcat8' fi + +POSTGRES_OK=$(dpkg-query -W --showformat='${Status}\n' postgresql|grep "install ok installed") + +DB_HOST="__DB_HOST__" +DB_PORT="__DB_PORT__" +DB_DATABASE_NAME="__DB_DATABASE_NAME__" +DB_USERNAME="__DB_USERNAME__" +DB_PASSWORD="__DB_PASSWORD__" + + +if [ -f /etc/minerva/db.properties ]; then + DB_PROPERTIES_FILE="/etc/minerva/db.properties" + log "$DB_PROPERTIES_FILE file found" + DB_HOST=`cat $DB_PROPERTIES_FILE |grep "uri" |cut -f3 -d"/" |cut -f1 -d":"` + DB_PORT=`cat $DB_PROPERTIES_FILE |grep "uri" |cut -f3 -d"/" |cut -f2 -d":"` + DB_DATABASE_NAME=`cat $DB_PROPERTIES_FILE |grep "uri" |cut -f4 -d"/"` + DB_USERNAME=`cat $DB_PROPERTIES_FILE |grep "username" |cut -f2 -d"="` + DB_PASSWORD=`cat $DB_PROPERTIES_FILE |grep "password" |cut -f2 -d"="` +fi + + +#if we connect to something that is not in localhost then we need to provide login and password +#because we won't have access to it as postgres user +if [ "$DB_HOST" != "localhost" ] && [ "$DB_HOST" != "127.0.0.1" ] +then + log "DB is located on the remote server: $DB_HOST" + IS_REMOTE_DB=true +else + log "DB is at localhost: $DB_HOST" + IS_REMOTE_DB=false +fi + +exec_sql(){ + log "Execute SQL : '$1'" + echo "$1" |PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USERNAME $DB_DATABASE_NAME >>$LOG_FILE 2>>$LOG_FILE +} +exec_sql_file(){ + log "Execute SQL file: $1" + PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USERNAME $DB_DATABASE_NAME -f $1 >>$LOG_FILE 2>>$LOG_FILE +} +create_db(){ + if [ $IS_REMOTE_DB = false ] + then + su - postgres -c "createuser -d -r -s -p $DB_PORT $DB_USERNAME" >>$LOG_FILE 2>>$LOG_FILE + log "User created" + su - postgres -c "echo \"ALTER USER $DB_USERNAME WITH PASSWORD '$DB_PASSWORD';\"| psql -p $DB_PORT " >>$LOG_FILE 2>>$LOG_FILE + log "User credentials updated" + su - postgres -c "createdb -p $DB_PORT -O $DB_USERNAME $DB_DATABASE_NAME" >>$LOG_FILE 2>>$LOG_FILE + log "Db created" + + hba_conf=`su - postgres -c "psql -t -P format=unaligned -c 'show hba_file';"`; + cp $hba_conf $hba_conf".bac" + cat $hba_conf".bac" |grep -v "all[ \t]*peer" >$hba_conf + printf "local all all md5\n" >>$hba_conf + invoke-rc.d postgresql restart + else + log "HOST is remote, assuming db and user are already there" + fi +} +stop_postgres() { + if [ $IS_REMOTE_DB = false ] + then + invoke-rc.d postgresql stop || true + fi +} +start_postgres() { + if [ $IS_REMOTE_DB = false ] + then + invoke-rc.d postgresql restart + fi +} diff --git a/debian/template/postinst b/debian/template/postinst index 2f2c3863a88d87c25e0f49a67687296261a2a16e..35037021f7e211c44b71872a9db765295f72f101 100644 --- a/debian/template/postinst +++ b/debian/template/postinst @@ -21,29 +21,21 @@ set -e case "$1" in configure) - invoke-rc.d postgresql start + start_postgres #if we install if [ "$OLD_VERSION" = "" ] then - su - postgres -c "createuser -d -r -s map_viewer" >>$LOG_FILE 2>>$LOG_FILE - su - postgres -c "echo \"ALTER USER map_viewer WITH PASSWORD '123qweasdzxc';\"| psql" >>$LOG_FILE 2>>$LOG_FILE - su - postgres -c "createdb -O map_viewer map_viewer" >>$LOG_FILE 2>>$LOG_FILE - - hba_conf=`su - postgres -c "psql -t -P format=unaligned -c 'show hba_file';"`; - cp $hba_conf $hba_conf".bac" - cat $hba_conf".bac" |grep -v "all[ \t]*peer" >$hba_conf - printf "local all all md5\n" >>$hba_conf - invoke-rc.d postgresql restart + create_db #install base version of the framework - su - postgres -c "psql map_viewer -f $DB_SCRIPT_DIR/db_0.sql" >>$LOG_FILE 2>>$LOG_FILE + exec_sql_file "$DB_SCRIPT_DIR/db_0.sql" #install patch to current version - su - postgres -c "psql map_viewer -f $DB_SCRIPT_DIR/db_0_to_$CURRENT_VERSION\".sql\"" >>$LOG_FILE 2>>$LOG_FILE + exec_sql_file "$DB_SCRIPT_DIR/db_0_to_${CURRENT_VERSION}.sql" else #if we update the package - su - postgres -c "psql map_viewer -f $DB_SCRIPT_DIR/db_$OLD_VERSION\"_to_\"$CURRENT_VERSION\".sql\"" >>$LOG_FILE 2>>$LOG_FILE + exec_sql_file "$DB_SCRIPT_DIR/db_${OLD_VERSION}_to_${CURRENT_VERSION}.sql" fi #print a disclaimer diff --git a/debian/template/postrm b/debian/template/postrm index 89144fb629ef34fd3761bc2c749f6cebfcfd4840..6c517b351c62b103aaf36e2479c2f6cec49f9db0 100644 --- a/debian/template/postrm +++ b/debian/template/postrm @@ -10,15 +10,6 @@ log "Running postrm" $1 $2; -log "Checking postgresql..."; -POSTGRES_OK=$(dpkg-query -W --showformat='${Status}\n' postgresql|grep "install ok installed") -if [ "" = "$POSTGRES_OK" ] -then - log "postgresql not found"; -else - log "postgresql found"; -fi - # we execute it here because if some packages are missing then dpkg will return non-zero exit code set -e @@ -26,34 +17,41 @@ case "$1" in upgrade) rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva.war -# invoke-rc.d $TOMCAT_PACKAGE start || true -# invoke-rc.d postgresql start || true ;; remove) rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva rm -rf /var/lib/$TOMCAT_PACKAGE/webapps/minerva.war invoke-rc.d $TOMCAT_PACKAGE start || true - if [ "" = "$POSTGRES_OK" ] + if [ $IS_REMOTE_DB = true ] then - log "No postgresql package found."; + exec_sql "drop owned by $DB_USERNAME;" else - invoke-rc.d postgresql start - su - postgres -c "dropdb map_viewer" - su - postgres -c "dropuser map_viewer" + if [ "" = "$POSTGRES_OK" ] + then + log "No postgresql package found."; + else + start_postgres + su - postgres -c "dropdb -p $DB_PORT $DB_DATABASE_NAME" + su - postgres -c "dropuser -p $DB_PORT $DB_USERNAME" + fi fi - ;; - abort-install) + ;; + abort-install) invoke-rc.d $TOMCAT_PACKAGE start || true - - if [ "" = "$POSTGRES_OK" ]; + if [ $IS_REMOTE_DB = true ] then - log "No postgresql package found."; + exec_sql "drop owned by $DB_USER" else - invoke-rc.d postgresql restart - su - postgres -c "dropdb map_viewer" - su - postgres -c "dropuser map_viewer" + if [ "" = "$POSTGRES_OK" ]; + then + log "No postgresql package found."; + else + start_postgres + su - postgres -c "dropdb -p $DB_PORT $DB_DATABASE_NAME" + su - postgres -c "dropuser -p $DB_PORT $DB_USERNAME" + fi fi - ;; + ;; *) echo "postrm called with unknown argument \`$1'" >&2 exit 1 diff --git a/debian/template/preinst b/debian/template/preinst index c6ad957eb6803a810a043143bf5845e16a3017ef..84d76df53b7b63fb52764416c0e076a72484ccf9 100644 --- a/debian/template/preinst +++ b/debian/template/preinst @@ -24,12 +24,12 @@ ln -s $path $DEFAULT_JAVA_SYMLINK case "$1" in install|upgrade) - invoke-rc.d $TOMCAT_PACKAGE stop || true - invoke-rc.d postgresql stop || true + invoke-rc.d $TOMCAT_PACKAGE stop || true + stop_postgres ;; abort-upgrade) - invoke-rc.d $TOMCAT_PACKAGE stop || true - invoke-rc.d postgresql stop || true + invoke-rc.d $TOMCAT_PACKAGE stop || true + stop_postgres ;; *) echo "preinst called with unknown argument \`$1'" >&2 diff --git a/debian/template/prerm b/debian/template/prerm index c43b60f8fa2c3f996db03de69cc8b7e261d9220e..b131100dbb7790d8628054bd04fae91e19575a03 100644 --- a/debian/template/prerm +++ b/debian/template/prerm @@ -17,20 +17,20 @@ set -e log Running prerm $1 $2; invoke-rc.d postgresql start || true -TIMESTAMP=$(date +"%F") +TIMESTAMP=$(date +"%F_%H%M%S") DUMP_FILE=$DB_SCRIPT_DIR/dump_$TIMESTAMP -log "dump map_viewer database to file $DUMP_FILE" -su - postgres -c "pg_dump map_viewer" | gzip > "$DUMP_FILE".gz +log "dump $DB_DATABASE_NAME database to file $DUMP_FILE" +PGPASSWORD=$DB_PASSWORD pg_dump -h $DB_HOST -p $DB_PORT -U $DB_USERNAME $DB_DATABASE_NAME | gzip > "$DUMP_FILE".gz case "$1" in upgrade) - invoke-rc.d $TOMCAT_PACKAGE stop || true - invoke-rc.d postgresql stop || true + invoke-rc.d $TOMCAT_PACKAGE stop || true + stop_postgres ;; remove) - invoke-rc.d $TOMCAT_PACKAGE stop || true - invoke-rc.d postgresql stop || true + invoke-rc.d $TOMCAT_PACKAGE stop || true + stop_postgres ;; *) echo "prerm called with unknown argument \`$1'" >&2 diff --git a/frontend-js/package-lock.json b/frontend-js/package-lock.json index 0dd0f1e74aac85fab4f9168d4088aa539e9c2f66..d84bc1074518cb44283e90e34d2b94f587814a5d 100644 --- a/frontend-js/package-lock.json +++ b/frontend-js/package-lock.json @@ -45,38 +45,30 @@ "litemol": "github:dsehnal/LiteMol#67556b0de0d2428f9494136758cbf8a662f66412" }, "dependencies": { - "ProtVista": { - "version": "git://github.com/davidhoksza/protvista.git#4e4bb737ba1e183291505bd25f8bae2e651ce21e", - "dev": true, - "requires": { - "d3": "3.5.17", - "file-saver": "1.3.3", - "jquery": "2.2.4", - "jszip": "3.1.4", - "underscore": "1.8.3" - }, - "dependencies": { - "jquery": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/jquery/-/jquery-2.2.4.tgz", - "integrity": "sha1-LInWiJterFIqfuoywUUhVZxsvwI=", - "dev": true - } - } - }, "jquery": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz", "integrity": "sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==", "dev": true - }, - "litemol": { - "version": "github:dsehnal/LiteMol#67556b0de0d2428f9494136758cbf8a662f66412", - "dev": true, - "requires": { - "@types/react": "15.6.15", - "@types/react-dom": "15.5.7" - } + } + } + }, + "ProtVista": { + "version": "git://github.com/davidhoksza/protvista.git#4e4bb737ba1e183291505bd25f8bae2e651ce21e", + "dev": true, + "requires": { + "d3": "3.5.17", + "file-saver": "1.3.3", + "jquery": "2.2.4", + "jszip": "3.1.4", + "underscore": "1.8.3" + }, + "dependencies": { + "jquery": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-2.2.4.tgz", + "integrity": "sha1-LInWiJterFIqfuoywUUhVZxsvwI=", + "dev": true } } }, @@ -2058,6 +2050,14 @@ "immediate": "3.0.6" } }, + "litemol": { + "version": "github:dsehnal/LiteMol#67556b0de0d2428f9494136758cbf8a662f66412", + "dev": true, + "requires": { + "@types/react": "15.6.15", + "@types/react-dom": "15.5.7" + } + }, "lodash": { "version": "4.17.4", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", diff --git a/persist/src/db/12.1.0~alpha.0/fix_db_20180410.sql b/persist/src/db/12.1.0~alpha.0/fix_db_20180410.sql new file mode 100644 index 0000000000000000000000000000000000000000..a33b6ad89d4881c84fb355b8c56d309760e66b70 --- /dev/null +++ b/persist/src/db/12.1.0~alpha.0/fix_db_20180410.sql @@ -0,0 +1 @@ +-- empty file to force directory to be commited to git repo diff --git a/persist/src/main/resources/dataSource.xml b/persist/src/main/resources/dataSource.xml index 96e982f72af14cf984bdacb2f6bc2bca65d8feb6..5f6bc4799151317e0bd742c29acbd40b0f247f55 100644 --- a/persist/src/main/resources/dataSource.xml +++ b/persist/src/main/resources/dataSource.xml @@ -9,7 +9,8 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> - <context:property-placeholder location="classpath:db.properties" /> + <context:property-placeholder ignore-resource-not-found="true" location="classpath:db.properties,file:/etc/minerva/db.properties" /> + <!-- Data Source Declaration --> <bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">