#!/bin/sh
if [ -z "$TESTSUITE" ]; then
	CMDLINE=/proc/cmdline
	ALIASES=/etc/preseed_aliases
else
	CMDLINE=user-params.in
	ALIASES=user-params.aliases
fi

# sed out multi-word quoted value settings
for item in $(sed -e 's/[^ =]*="[^"]*[ ][^"]*"//g' \
		  -e "s/[^ =]*='[^']*[ ][^']*'//g" $CMDLINE); do
	var="${item%=*}"
	# Remove trailing '?' for debconf variables set with '?='
	var="${var%\?}"

	if [ "$item" = "--" ] || [ "$item" = "---" ]; then
		inuser=1
		collect=""
	elif [ "$inuser" ]; then
		# BOOT_IMAGE is added by syslinux
		if [ "$var" = "BOOT_IMAGE" ]; then
			continue
		fi

		# init is not generally useful to pass on
		if [ "$var" = init ]; then
			continue
		fi

		# suppress installer-specific parameters
		if [ "$var" = BOOT_DEBUG ] || [ "$var" = DEBIAN_FRONTEND ] || \
		   [ "$var" = INSTALL_MEDIA_DEV ] || [ "$var" = lowmem ] || \
		   [ "$var" = noshell ]; then
			continue
		fi

		# brltty settings shouldn't be passed since
		# they are already recorded in /etc/brltty.conf
		if [ "$var" = brltty ]; then
			continue
		fi

		# ks is only useful to kickseed in the first stage.
		if [ "$var" = ks ]; then
			continue
		fi

		# Skip debconf variables
		varnoslash="${var##*/*}"
		if [ "$varnoslash" = "" ]; then
			continue
		fi

		# Skip preseed aliases
		if [ -e "$ALIASES" ] && \
		   grep -q "^$var[[:space:]]" "$ALIASES"; then
			continue
		fi

		if [ -z "$collect" ]; then
			collect="$item"
		else
			collect="$collect $item"
		fi
	fi
done

if [ -z "$TESTSUITE" ]; then
	# Include default parameters
	RET=`debconf-get debian-installer/add-kernel-opts || true`
	if [ "$RET" ]; then
	        collect="$collect $RET"
	fi
fi

for word in $collect; do
	echo "$word"
done
