#!/bin/sh
set -eu

. /usr/share/debconf/confmodule

log() {
	logger -t "depthcharge-tools-installer" "$@"
}

error () {
	log "$@"
	exit 1
}

# Check if we have a board override.
db_get depthcharge-tools-installer/board
if [ -n "${RET:-}" ]; then
	log "Pretending this is a ChromeOS board '$RET'."
	exit 0
fi

# ChromeOS firmware injects one of these values into the cmdline based
# on which boot mechanism is used.
if ! grep "cros_secure" /proc/cmdline >/dev/null 2>&1; then
	error "Not installing to non-ChromeOS board."
fi
