diff --git a/snap/hooks/post-refresh b/snap/hooks/post-refresh old mode 100644 new mode 100755 index c7188c3677..e5c09f7066 --- a/snap/hooks/post-refresh +++ b/snap/hooks/post-refresh @@ -1,4 +1,28 @@ #!/bin/bash -e +TAG=$SNAP_INSTANCE_NAME.$(basename "$0") + +# read revision/version of the previous installation, set in the pre-refresh hook +pre_rev=$(snapctl get pre-refresh.revision) +pre_ver=$(snapctl get pre-refresh.version) +# read the revision from the legacy lastrev option (EdgeX <2.3) +[ -z "$pre_rev" ] && pre_rev=$(snapctl get lastrev) + +logger --tag $TAG "Refreshing from $pre_ver ($pre_rev) to $SNAP_VERSION ($SNAP_REVISION)" + # set up postgres, if we are upgrading it $SNAP/bin/kong-postgres-setup.sh "post-refresh" + +# Install the Unit of Measure config file when upgrading from an old version +# UoM was added in v2.3.0-dev.45 (snap revision 3900): +# https://github.com/edgexfoundry/edgex-go/pull/4119 +if (( pre_rev < 3900 )); then + uom="config/core-metadata/res/uom.toml" + logger --tag $TAG "Installing $SNAP/$uom" + if [ -f "$SNAP/$uom" ]; then + # --no-clobber: copy if missing from target + cp --no-clobber "$SNAP/$uom" "$SNAP_DATA/$uom" + else + logger --stderr --tag $TAG "$SNAP/$uom does not exit." + fi +fi diff --git a/snap/hooks/pre-refresh b/snap/hooks/pre-refresh index bb3b821616..ded288f1cc 100755 --- a/snap/hooks/pre-refresh +++ b/snap/hooks/pre-refresh @@ -1,11 +1,13 @@ #!/bin/bash -e -# save this revision for when we run again in the post-refresh -snapctl set lastrev="$SNAP_REVISION" +# save these for use in the post-refresh hook +snapctl set pre-refresh.revision=$SNAP_REVISION +snapctl set pre-refresh.version=$SNAP_VERSION + +# unset legacy EdgeX <2.3 options +snapctl unset lastrev release -snapctl set release="jakarta" - # back up the Kong database, so that if the new snap contains a newer # postgresql, then the configuration can be imported into the new database # in the post-refresh hook. -$SNAP/bin/kong-postgres-setup.sh "pre-refresh" \ No newline at end of file +$SNAP/bin/kong-postgres-setup.sh "pre-refresh"