#!/bin/sh

set -e

STATE="$1"

case "$STATE" in

    NeedsArtifactReboot)
        echo "Yes"
        ;;

    SupportsRollback)
        echo "Yes"
        ;;

    Download|ArtifactInstall|ArtifactRollback)
        ;;

    ArtifactReboot|ArtifactRollbackReboot)
        # This simulated reboot restarts the service in milliseconds. A failed
        # corrupt-version rollback fires ArtifactReboot and ArtifactRollbackReboot
        # back-to-back, which together with restarts from earlier deployments on the
        # same device trips systemd's default start rate-limit (5 starts / 10s) and
        # leaves mender-updated dead, so the deployment failure is never reported.
        # A real reboot never hits this; reset the counter so each one behaves like it.
        systemctl reset-failed mender-updated
        systemctl restart mender-updated
        ;;

esac

exit 0

