#!/bin/sh
#
# Control behavior for a task based on simple-cdd profiles.
#
# For example, to enable a task and mark it for installation
# only if 'kali-purple' is part of the simple-cdd profiles,
# use this stanza:
#
#   Test-simple-cdd-profile: kali-purple mark skip
#
# This will cause the task to be available and marked for
# installation if the simple-cdd profile 'kali-purple' was
# enabled, otherwise the task won't be available.
#
# This test is effective only for new install, it has no
# effect otherwise.

set -e

PROFILE=$2

if ! [ "$NEW_INSTALL" ]; then
	exit 3 # display task, not marked for installation
fi

ALL_PROFILES=$(cat /proc/cmdline \
	| grep -E -o "(^| )simple-cdd/profiles=\S*" \
	| cut -d= -f2 | tr , " ")
if echo " $ALL_PROFILES " | grep -q " $PROFILE "; then
	VAR=$3
else
	VAR=$4
fi

case "$VAR" in
	install) exit 0 ;; # do not display, but do install task
	skip)    exit 1 ;; # do not display task
	mark)    exit 2 ;; # display task, marked for installation
	show)    exit 3 ;; # display task, not marked for installation
	*)       exit 1 ;; # unknown value, skip the task
esac
