diff --git a/HIRS_AttestationCAPortal/build.gradle b/HIRS_AttestationCAPortal/build.gradle index 0468a476..b60c4488 100644 --- a/HIRS_AttestationCAPortal/build.gradle +++ b/HIRS_AttestationCAPortal/build.gradle @@ -159,8 +159,7 @@ ospackage { // Copy files to /tmp that package manager will be expecting them there preUninstall 'mkdir -p /tmp/aca/default-properties/' preUninstall 'cp /opt/hirs/default-properties/* /tmp/aca/default-properties/.' - // postUninstall file(/opt/hirs/scripts/common/db_drop.sql) - + preUninstall file('../package/scripts/common/db_drop.sh') buildRpm.dependsOn ':HIRS_AttestationCA:war' diff --git a/package/scripts/common/db_create.sh b/package/scripts/common/db_create.sh index 7cb66df8..bfc2aef7 100644 --- a/package/scripts/common/db_create.sh +++ b/package/scripts/common/db_create.sh @@ -1,5 +1,19 @@ #!/bin/bash -DB_DEFAULT_PWD="hirs_db" +# +############################################### +# HIRS DB creation +# Conditions to address +# a. Install is called mutiple times +# b. Another app sets the root password +# c. ACA is updated +# d. ACA is updated after a DB password change +################################################ + +if [ -z ${HIRS_DB_PWD+x} ]; then + DB_DEFAULT_PWD="hirs_db"; + else + DB_DEFAULT_PWD=$HIRS_DB_PWD; +fi # Check if we're in a Docker container if [ -f /.dockerenv ]; then @@ -25,10 +39,11 @@ if [[ $(pgrep -c -u mysql mysqld) -eq 0 ]]; then systemctl $SQL_SERVICE enable systemctl $SQL_SERVICE start fi - # Set intial password - mysqladmin -u root password $DB_DEFAULT_PWD fi -# Initialize the hirs_db database +# Set intial passwor, ingore result in case its already been set +mysqladmin -u root --silent password $DB_DEFAULT_PWD || true > /dev/null 2>&1 + +# Create the hirs_db database DB_CREATE_SCRIPT=/opt/hirs/scripts/common/db_create.sql.el7 mysql -u root --password="$DB_DEFAULT_PWD" < $DB_CREATE_SCRIPT diff --git a/package/scripts/common/db_drop.sh b/package/scripts/common/db_drop.sh index 80e3868f..e74ae943 100644 --- a/package/scripts/common/db_drop.sh +++ b/package/scripts/common/db_drop.sh @@ -1,4 +1,15 @@ -#!/usr/bin/env bash +#!/bin/bash -# delete the database -mysql -u root < /opt/hirs/scripts/common/db_drop.sql +# Get the current password from the perstence.properties file +file="/etc/hirs/persistence.properties" +# Change java key/value pairs into valid bash key/value pairs +function prop { + grep "${1}" ${file} | cut -d'=' -f2 | xargs +} + +user="root" +# user=$(prop 'persistence.db.user') +pwd=$(prop 'persistence.db.password') + +# drop the database +mysql -u "$user" --password="$pwd" < /opt/hirs/scripts/common/db_drop.sql