#!/bin/bash -eu
#
# Remove firmware files and/or directories
#

if [ $# -ne 1 ] ; then
	echo "Usage: remove-firmware <dirname>" >&2
	exit 2
fi

if ! [ -d "${1}" ] ; then
	echo "No such directory: ${1}" >&2
	exit 1
fi

echo "Remove firmware files in ${1} ..."

while IFS= read -r item ; do
	# Don't quote 'item' to allow globs in remove-firmware.list
	# shellcheck disable=SC2086
	for fw in "${1:?}"/${item} ; do
		if [ -e "${fw}" ] ; then
			echo "  ${fw}"
			rm -rf "${fw}"
		fi
	done
done < <(sed -E '/^#|^$/d' debian/remove-firmware.list)
