#!/bin/sh
# This is the config file that specifies several settings that the
# scripts in `/etc/npll.d` will embed into the final config file.


# This gets sourced by npll-mkconfig, so there's no need to export
# shellcheck disable=2034

# Function to format a generic boot entry
# Looking to change the names of entries?  Don't modify this!
# You're probably looking for either the names of kernel entries,
# in which case, look at `write_kentry` below, or you're looking for
# the names of the auxilary entries, in `/etc/npll.d/99_footer`.
write_entry() {
	printf "\n[%s]\n%s\n" "$1" "$2"
}

# Function to format specifically a kernel entry
# You may modify the naming convention here as you wish.
# Arguments:
# - $1: "Short" kernel name, this is the file name, except for the extension,
#   of every file related to this kernel.
#   
# - $2: "Full" kernel name, probably pulled from `/boot/$1.txt
#   For example: "7.2.3"
#
# - $3: Entry ID
#
# TODO: generate config with other platform keys (GameCube, Wii U)
# TODO: generate config with initrd keys
# TODO: stop hardcoding ArchPOWER
write_kentry() {
	title="$(printf "ArchPOWER Wii-Linux (Kernel %s)" "$2")"
	content="$(cat << EOF
	name=$title
	platforms=wii
	type_wii=linux
	exec_wii=self:boot/$1.krn
EOF
)"
	if [ -f "/boot/$1.dtb" ]; then
		content="$content
	dtb_wii=self:boot/$1.dtb"
	fi

	write_entry "$3" "$content"
}
