#!/bin/sh

# upgrade hook: distro-specific modules will add their upgrade tasks here
echo "starting upgrade hook"

export DRACUT_SYSTEMD=1
if [ -f /dracut-state.sh ]; then
    . /dracut-state.sh 2>/dev/null
fi
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh

source_conf /etc/conf.d

# NOTE: For debugging purposis. It's possible it will be changed in future.
getarg 'rd.upgrade.break=upgrade' 'rd.break=upgrade' 'rd.upgrade.break=leapp-initram' && \
    emergency_shell -n upgrade "Break right after getting to leapp dracut modules"

setstate() {
    export UPGRADE_STATE="$*"
    echo "$UPGRADE_STATE" > "${NEWROOT}/var/tmp/system-upgrade.state"
}

setstate running

trap 'setstate failed' EXIT
source_hook upgrade
trap - EXIT

setstate finished

exit 0
