#!/bin/sh

. /lib/partman/lib/base.sh
. /lib/partman/lib/crypto-base.sh

dev=$2
disk=$(cat $dev/device)

if ! /sbin/cryptsetup --help | grep -q hw-opal-factory-reset || ! blockdev-opal-supported $disk; then
	exit 0
fi

psid=$(query_opal_psid)

[ -n "$psid" ] || exit 0

echo $psid | /sbin/cryptsetup luksErase --hw-opal-factory-reset -q $disk || true
