#!/bin/sh
set -e
. /usr/share/debconf/confmodule

makelist() {
	if [ -f /tmp/tasksel_tasks ]; then
		question="tasksel/tasks"
	else
		question="tasksel/first"
	fi
	
#	if echo $feat | grep -q "enhanced audit subsystem"; then
#		echo -n "parsec-aud parsec-log " 1>&5
#		db_get $question || true
#		if echo $RET | grep -q "Fly desktop"; then
#			echo -n "fly-admin-viewaudit " 1>&5
#		fi
#	fi
#	if echo $feat | grep -q "kiosk mode"; then
#		echo -n "parsec-kiosk " 1>&5
#		db_get $question || true
#		if echo $RET | grep -q "Fly desktop"; then
#			echo -n "fly-admin-kiosk " 1>&5
#		fi
#	fi
#	if echo $feat | grep -q "extended security settings"; then
#		echo -n "astra-safepolicy " 1>&5
#	fi
	if echo $feat | grep -q "ALD"; then
		db_get tasksel/astra-feat-setup-ald || true
		if echo $RET | grep -q "Клиент"; then
			echo -n "ald-client-common " 1>&5
			db_get $question || true
			if echo $RET | grep -q "Fly desktop"; then
				echo -n "fly-admin-ald-client " 1>&5
			fi
		else
			echo -n "ald-server-common " 1>&5
			db_get $question || true
			if echo $RET | grep -q "Fly desktop"; then
				echo -n "fly-admin-ald-server " 1>&5
			fi
		fi
	fi
	if echo $feat | grep -q "Astra Linux Directory"; then
		db_get tasksel/astra-feat-setup-ald || true
		if echo $RET | grep -q "client"; then
			echo -n "ald-client-common " 1>&5
			db_get $question || true
			if echo $RET | grep -q "Fly desktop"; then
				echo -n "fly-admin-ald-client " 1>&5
			fi
		else
			echo -n "ald-server-common " 1>&5
			db_get $question || true
			if echo $RET | grep -q "Fly desktop"; then
				echo -n "fly-admin-ald-server smolensk-security-ald " 1>&5
			fi
		fi
	fi
	echo
	rm -f /tmp/tasksel_newinstall
}

db_capb backup

db_fset tasksel/astra-feat-setup seen false
db_fset tasksel/astra-feat-setup-ald seen false

while [ 1 ]; do
	db_input high tasksel/astra-feat-setup || true
	if ! db_go; then
		exit 10
	fi

	db_get tasksel/astra-feat-setup || true
	feat=$RET
	if echo $feat | grep -q "Astra Linux Directory"; then
		db_input high tasksel/astra-feat-setup-ald || true
		if db_go; then
			makelist $feat;
			exit 0
		fi
	else
		makelist $feat;
		exit 0
	fi
done

