@hook 'upgrade-charm'
function check_fixpack(){
# The upgrade-charm hook will fire when a new resource is pushed for this
# charm. This is a good time to determine if we need to deal with a new
# fixpack.
if ! charms.reactive is_state 'ibm-was-base.updated'; then
# If there is no prior fixpack installed (because ibm-was-base.updated is not
# set), do nothing since install_was_base_fixpack will handle that case.
juju-log "IBM WAS Base: no fixpack has been installed; nothing to upgrade."
exit 0
else
# If we have a fixpack packges already (because ibm-was-base.updated is set),
# we should fetch the latest fixpack packages and determine if it is new.
# - If it is new, set our states so install_was_base_fixpack is called again
# - If it is not new, do nothing
juju-log "IBM WAS Base: scanning for new fixpacks to install"
WAS_FP1_DIR="$CHARM_DIR/../resources/ibm_was_base_fp1"
WAS_FP2_DIR="$CHARM_DIR/../resources/ibm_was_base_fp2"
CUR_FP1="$WAS_FP1_DIR/ibm_was_base_fp1.zip"
CUR_FP2="$WAS_FP2_DIR/ibm_was_base_fp2.zip"
if [ -f $CUR_FP1 -a -f $CUR_FP2 ]; then
CUR_FP1_MD5=`md5sum "$CUR_FP1" | awk '{print $1}'`
CUR_FP2_MD5=`md5sum "$CUR_FP2" | awk '{print $1}'`
fi
NEW_FP1=`resource-get 'ibm_was_base_fp1' || echo unavailable`
NEW_FP2=`resource-get 'ibm_was_base_fp2' || echo unavailable`
if [ "$NEW_FP1" = "unavailable" -a "$NEW_FP2" = "unavailable" ]; then
juju-log "IBM WAS Base: no fixpacks to install"
elif [ -f $NEW_FP1 -a -f $NEW_FP2 ]; then
NEW_FP1_MD5=`md5sum "$NEW_FP1" | awk '{print $1}'`
NEW_FP2_MD5=`md5sum "$NEW_FP2" | awk '{print $1}'`
fi
if [ "$CUR_FP1_MD5" != "$NEW_FP1_MD5" -a "$CUR_FP2_MD5" != "$NEW_FP2_MD5" ]; then
juju-log "IBM WAS Base: new fixpack detected ($CUR_FP1 with $CUR_FP1_MD5 versus $NEW_FP1 with $NEW_FP1_MD5 and $CUR_FP2 with $CUR_FP2_MD5 versus $NEW_FP2 with $NEW_FP2_MD5)"
rm -rf $CHARM_DIR/../resources/WAS_BASE/FP
remove_state 'ibm-was-base.updated'
else
juju-log "IBM WAS Base: no new fixpack to install"
fi
fi
}