diff --git a/package/rpm/HIRS.spec b/package/rpm/HIRS.spec index d55aa8ec..5e407811 100644 --- a/package/rpm/HIRS.spec +++ b/package/rpm/HIRS.spec @@ -160,7 +160,7 @@ mkdir -p /opt/hirs/scripts/common/ cp -f /opt/hirs/scripts/common/aca/* /opt/hirs/scripts/common/ # run these only on a fresh install of the package -if [ "$1" = "1" ]; then +if [ $1 == 1 ]; then # open necessary ports sh /opt/hirs/scripts/common/firewall_configure_tomcat.sh @@ -178,11 +178,31 @@ if [ "$1" = "1" ]; then sh /opt/hirs/scripts/common/db_create.sh fi +# modify mysql schema accordingly on upgrade +if [ $1 -gt 1 ]; then + echo "Upgrading hirs_db schema!" + if [ %{version} == "1.0.4" ]; then + if (mysql -u root hirs_db < /opt/hirs/scripts/common/upgrade_schema_1.0.4.sql); then + echo "Upgrade to version 1.0.4" + else + echo "Error upgrading HIRS database schema to 1.0.4!" + exit 1; + fi + elif [ %{version} == "1.1.0" ]; then + if (mysql -u root hirs_db < /opt/hirs/scripts/common/upgrade_schema_1.0.4.sql && mysql -u root hirs_db < /opt/hirs/scripts/common/upgrade_schema_1.1.0.sql); then + echo "Upgrade to version 1.1.0" + else + echo "Error upgrading HIRS database schema to 1.1.0!" + exit 1; + fi + fi +fi + sh /opt/hirs/scripts/aca/certificate_generate.sh %preun -n HIRS_AttestationCA # don't run these during an upgrade -if [ "$1" = "0" ]; then +if [ $1 == 0 ]; then # if the Server isn't installed, deconfigure Tomcat and MySQL SSL and drop the database if [[ -z `rpm -qa HIRS_Server` ]]; then echo 'Restoring Tomcat and MySQL configuration' @@ -195,7 +215,7 @@ fi %postun -n HIRS_AttestationCA # don't run these during an upgrade -if [ "$1" = "0" ]; then +if [ $1 == 0 ]; then # Removes WARS from the Tomcat installation as well as ACA configuration files and certificates # (/etc/hirs/aca), and ACA installation (/opt/hirs/attestation-ca). Do not run during an upgrade rm -f %{prefix}/webapps/HIRS_AttestationCA*.war diff --git a/package/scripts/common/upgrade_schema_1.0.4.sql b/package/scripts/common/upgrade_schema_1.0.4.sql new file mode 100644 index 00000000..abf8bf5f --- /dev/null +++ b/package/scripts/common/upgrade_schema_1.0.4.sql @@ -0,0 +1,30 @@ +DROP PROCEDURE IF EXISTS upgrade_schema_to_1_0_4; +DELIMITER '//' + +CREATE PROCEDURE upgrade_schema_to_1_0_4() +BEGIN +IF(NOT EXISTS(SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='hirs_db' AND TABLE_NAME='Certificate' AND COLUMN_NAME='isDeltaChain')) THEN +ALTER TABLE Certificate ADD isDeltaChain bit(1) DEFAULT NULL; +END IF; + +IF(NOT EXISTS(SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='hirs_db' AND TABLE_NAME='Certificate' AND COLUMN_NAME='platformBase')) THEN +ALTER TABLE Certificate ADD platformBase bit(1) DEFAULT NULL; +END IF; + +IF(NOT EXISTS(SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='hirs_db' AND TABLE_NAME='Certificate' AND COLUMN_NAME='platformChainType')) THEN +ALTER TABLE Certificate ADD platformChainType varchar(255) DEFAULT NULL; +END IF; + +IF(NOT EXISTS(SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='hirs_db' AND TABLE_NAME='SupplyChainValidationSummary' AND COLUMN_NAME='message')) THEN +ALTER TABLE SupplyChainValidationSummary ADD message longtext; +END IF; + +IF(NOT EXISTS(SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='hirs_db' AND TABLE_NAME='TPMReport' AND COLUMN_NAME='rawQuote')) THEN +ALTER TABLE TPMReport ADD rawQuote blob; +END IF; +END// +DELIMITER ';' + +CALL upgrade_schema_to_1_0_4; +DROP PROCEDURE upgrade_schema_to_1_0_4; + diff --git a/package/scripts/common/upgrade_schema_1.1.0.sql b/package/scripts/common/upgrade_schema_1.1.0.sql new file mode 100644 index 00000000..57deb632 --- /dev/null +++ b/package/scripts/common/upgrade_schema_1.1.0.sql @@ -0,0 +1,16 @@ +#commands here if there are schema changes in 1.1.0 +DROP PROCEDURE IF EXISTS upgrade_schema_to_1_1_0; +DELIMITER '//' + +CREATE PROCEDURE upgrade_schema_to_1_1_0() +BEGIN +IF(NOT EXISTS(SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='hirs_db' AND TABLE_NAME='Certificate' AND COLUMN_NAME='componentFailures')) THEN +ALTER TABLE Certificate ADD componentFailures varchar(255) DEFAULT NULL; +END IF; + +END// +DELIMITER ';' + +CALL upgrade_schema_to_1_1_0; +DROP PROCEDURE upgrade_schema_to_1_1_0; +