From 0d1b0d3da77db025e0ea860a7f7a51920d14f39c Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Sun, 8 Jun 2014 09:34:55 +0200 Subject: [PATCH] Generic config file handling. --- debian/local/extlinux-functions.sh | 15 +++++++++++++++ debian/local/extlinux.d/0000-defaults | 24 +++++++++++++++++++++--- debian/local/extlinux.d/0040-extlinux | 21 +++++++-------------- debian/syslinux-stuff.install | 1 + 4 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 debian/local/extlinux-functions.sh diff --git a/debian/local/extlinux-functions.sh b/debian/local/extlinux-functions.sh new file mode 100644 index 00000000..5059a5a1 --- /dev/null +++ b/debian/local/extlinux-functions.sh @@ -0,0 +1,15 @@ + +# config_file +config_to_var(){ + echo -n EXTLINUX_ ; echo "$1" | tr "a-z" "A-Z" | tr - _ +} + +# variable default +get_var(){ + eval echo "\"\${$1:-$2}\"" +} + +# variable value +set_var(){ + eval "$1=\"$2\"" +} diff --git a/debian/local/extlinux.d/0000-defaults b/debian/local/extlinux.d/0000-defaults index b294933f..535863cd 100755 --- a/debian/local/extlinux.d/0000-defaults +++ b/debian/local/extlinux.d/0000-defaults @@ -9,6 +9,7 @@ set -e +. /usr/share/extlinux/extlinux-functions.sh . /usr/share/extlinux/extlinux-update.sh # Checking extlinux directory @@ -27,6 +28,14 @@ else fi # Setting defaults +EXTLINUX_CONFIGS="${EXTLINUX_CONFIGS:-linux memdisk os-prober}" + +# Support old style enabler variables +for c in $EXTLINUX_CONFIGS ; do + var="$(config_to_var "$c")" + set_var "${var}" "$(get_var "${var}" true)" +done + EXTLINUX_ALTERNATIVES="${EXTLINUX_ALTERNATIVES:-default recovery}" EXTLINUX_DEFAULT="${EXTLINUX_DEFAULT:-l0}" EXTLINUX_ENTRIES="${EXTLINUX_ENTRIES:-all}" @@ -87,19 +96,28 @@ else fi # Writing new default file -cat > "/etc/default/extlinux" << EOF +_CONFIG_FILE="/etc/default/extlinux" +cat > "${_CONFIG_FILE}" << EOF ## /etc/default/extlinux - configuration file for extlinux-update(8) # This file is rewritten by a script. Any comments and unsuported options will be lost. EXTLINUX_UPDATE="${EXTLINUX_UPDATE}" +EXTLINUX_CONFIGS="${EXTLINUX_CONFIGS}" +EOF + +# Support old style enabler variables +for c in $EXTLINUX_CONFIGS ; do + var="$(config_to_var "$c")" + echo "${var}"=\""$(get_var "${var}" false)"\" >> "${_CONFIG_FILE}" +done + +cat >> "${_CONFIG_FILE}" << EOF EXTLINUX_ALTERNATIVES="${EXTLINUX_ALTERNATIVES}" EXTLINUX_DEFAULT="${EXTLINUX_DEFAULT}" EXTLINUX_ENTRIES="${EXTLINUX_ENTRIES}" -EXTLINUX_MEMDISK="${EXTLINUX_MEMDISK}" EXTLINUX_MEMDISK_DIRECTORY="${EXTLINUX_MEMDISK_DIRECTORY}" EXTLINUX_MENU_LABEL="${EXTLINUX_MENU_LABEL}" -EXTLINUX_OS_PROBER="${EXTLINUX_OS_PROBER}" EXTLINUX_PARAMETERS="$(echo -n ${EXTLINUX_PARAMETERS} | sed -e 's|\"|\\\"|g')" EXTLINUX_ROOT="${EXTLINUX_ROOT}" EXTLINUX_THEME="${EXTLINUX_THEME}" diff --git a/debian/local/extlinux.d/0040-extlinux b/debian/local/extlinux.d/0040-extlinux index fc2e82f1..df5ff325 100755 --- a/debian/local/extlinux.d/0040-extlinux +++ b/debian/local/extlinux.d/0040-extlinux @@ -9,6 +9,7 @@ set -e +. /usr/share/extlinux/extlinux-functions.sh . /usr/share/extlinux/extlinux-update.sh # Create the main extlinux.conf file @@ -57,24 +58,16 @@ include themes/${EXTLINUX_THEME}/theme.cfg" else _CONFIG="${_CONFIG} -display boot.txt -include linux.cfg" +display boot.txt" - if [ "${EXTLINUX_MEMDISK}" = "true" ] && [ -e "${_EXTLINUX_DIRECTORY}/memdisk.cfg" ] +for c in $EXTLINUX_CONFIGS ; do + var="$(config_to_var "$c")" + if [ "$(get_var "${var}" false)" = "true" ] && [ -e "${_EXTLINUX_DIRECTORY}/${c}.cfg" ] then - - _CONFIG="${_CONFIG} -include memdisk.cfg" - - fi - - if [ "${EXTLINUX_OS_PROBER}" = "true" ] && [ -e "${_EXTLINUX_DIRECTORY}/os-prober.cfg" ] - then - _CONFIG="${_CONFIG} -include os-prober.cfg" - +include ${c}.cfg" fi +done if [ ! -e "${_EXTLINUX_DIRECTORY}/boot.txt" ] then diff --git a/debian/syslinux-stuff.install b/debian/syslinux-stuff.install index 49b79f31..c85ba20b 100644 --- a/debian/syslinux-stuff.install +++ b/debian/syslinux-stuff.install @@ -5,4 +5,5 @@ debian/local/extlinux-install /usr/sbin debian/local/extlinux-install.8 /usr/share/man/man8 debian/local/extlinux-update /usr/sbin debian/local/extlinux-update.sh /usr/share/extlinux +debian/local/extlinux-functions.sh /usr/share/extlinux debian/local/extlinux-update.8 /usr/share/man/man8 -- 2.11.4.GIT