+# Copy addonfile $1 from either
+# * the chroot (via $2, the system path),
+# * or from TEMPLATE_DIRECTORY/compat (if exists),
+# * or from the host system (again, using $2),
+# or warn about the missing file.
+#
+# This is because:
+# * We assume that the chroot always has a "good" version of
+# the file. Also it makes sources handling easier.
+# * On unstable, we recommend the Debian packages containing
+# these files. The user can override them by putting his
+# "better" version into the chroot.
+# * With older releases the Debian packages are probably
+# not available, so we look in TEMPLATE_DIRECTORY/compat,
+# where a (custom) package might install current file versions.
+copy_addon_file() {
+ DEST="${BUILD_OUTPUT}/boot/$3"
+ if [ ! -d "${DEST}/" ]; then
+ mkdir -p "${DEST}"
+ fi
+ if [ -e "$CHROOT_OUTPUT/$2/$1" ]; then
+ log "Copying $1 from chroot"
+ cp "$CHROOT_OUTPUT/$2/$1" "${DEST}/"
+ return $?
+ fi
+ if [ -e "${TEMPLATE_DIRECTORY}/compat/$3/$1" ]; then
+ log "Copying $1 from ${TEMPLATE_DIRECTORY}/compat"
+ cp "${TEMPLATE_DIRECTORY}/compat/$3/$1" "${DEST}/"
+ return $?
+ fi
+ if [ -e "$2/$1" ]; then
+ log "Copying $1 from system"
+ cp "$2/$1" "${DEST}/"
+ return $?
+ fi
+
+ msg="Missing addon file: \"$1\""
+ ewarn "$msg" ; eend 1
+ log "copy_addon_file: $msg"
+}
+
+# replace placeholders in template files with actual information
+adjust_boot_files() {
+ if [ -z "$1" ] ; then
+ echo "Usage: adjust_boot_files <template_file>" >&2
+ exit 1
+ fi
+
+ for file in "$@" ; do
+ if [ -r "${file}" ] && [ -f "${file}" ] ; then
+ sed -i "s/%ARCH%/$ARCH/g" "${file}"
+ sed -i "s/%DATE%/$DATE/g" "${file}"
+ sed -i "s/%DISTRI_INFO%/$DISTRI_INFO/g" "${file}"
+ sed -i "s/%DISTRI_NAME%/$DISTRI_NAME/g" "${file}"
+ sed -i "s/%DISTRI_SPLASH%/$DISTRI_SPLASH/g" "${file}"
+ sed -i "s/%GRML_NAME%/$GRML_NAME/g" "${file}"
+ sed -i "s/%SQUASHFS_NAME%/$SQUASHFS_NAME/g" "${file}"
+ sed -i "s/%RELEASE_INFO%/$RELEASE_INFO/g" "${file}"
+ sed -i "s/%SHORT_NAME%/$SHORT_NAME/g" "${file}"
+ sed -i "s/%VERSION%/$VERSION/g" "${file}"
+ if [ -n "${BOOT_FILE}" ] ; then
+ sed -i "s;%BOOT_FILE%;$BOOT_FILE;g" "${file}"
+ fi
+
+ [ -n "$DEFAULT_BOOTOPTIONS" ] && sed -i "s; boot=live; boot=live $DEFAULT_BOOTOPTIONS;" "${file}"
+
+ if [ -n "$NO_BOOTID" ] ; then
+ sed -i "s/ bootid=%BOOTID%//g" "${file}" # drop bootid bootoption
+ else
+ sed -i "s/%BOOTID%/$BOOTID/g" "${file}" # adjust bootid=... argument
+ fi
+ fi
+ done
+}