#!/usr/bin/bash

set -eu

check_slot() {
	local slot
	slot="$(abctl --boot_slot)"

	case "$slot" in
		"_a"|"_b")  ;;
		*) return 1 ;;
	esac
}

if ! command -v abctl >/dev/null 2>&1; then
	# Succeed and ignore A/B configuration if the tool isn't available.
	exit 0
fi

COMMAND="${1:-}"
case "$COMMAND" in
	"check-slot") check_slot ;;
	"set-success") abctl --set_success >/dev/null ;;
	*) exit 1;
esac
