summaryrefslogtreecommitdiffstats
path: root/share/build-scripts/debconf.d/0001-preseed-file
diff options
context:
space:
mode:
Diffstat (limited to 'share/build-scripts/debconf.d/0001-preseed-file')
-rwxr-xr-xshare/build-scripts/debconf.d/0001-preseed-file131
1 files changed, 131 insertions, 0 deletions
diff --git a/share/build-scripts/debconf.d/0001-preseed-file b/share/build-scripts/debconf.d/0001-preseed-file
new file mode 100755
index 0000000..aa2c3c7
--- /dev/null
+++ b/share/build-scripts/debconf.d/0001-preseed-file
@@ -0,0 +1,131 @@
+#!/bin/sh
+
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+#
+# SPDX-License-Identifier: GPL-3.0+
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+set -e
+
+PROJECT="open-infrastructure"
+SOFTWARE="compute-tools"
+PROGRAM="container"
+
+CONFIG="/etc/${SOFTWARE}/config"
+DEBCONF="/etc/${SOFTWARE}/debconf"
+
+DEBCONF_NOWARNINGS="true"
+export DEBCONF_NOWARNINGS
+
+. /usr/share/debconf/confmodule
+
+# debconf template hierarchy (first match wins):
+#
+# 1. user specified a preseed file through commandline options
+# 2. /etc/compute-tools/debconf/${NAME}.cfg exists
+# 3. /etc/compute-tools/debconf/links/${NAME}.cfg exists
+# 4. /etc/compute-tools/debconf/*/${NAME}.cfg exists (only one file!)
+# 5. /etc/compute-tools/debconf/default.cfg exists
+# 6. user chooses from list of available (if any) *.cfg files
+# (recursively) found in /etc/compute-tools/debconf,
+# /etc/compute-tools/debconf/links is excluded.
+
+if [ -n "${PRESEED_FILE}" ]
+then
+ # user specified one or more preseed files through commandline option
+ db_set container/preseed-file "${PRESEED_FILE}"
+ db_fset container/preseed-file seen true
+elif [ -e "${DEBCONF}/${NAME}.cfg" ]
+then
+ # user did not specify a pressed file, but there is a matching one
+ # available on the system matching the container name
+ db_set container/preseed-file "${DEBCONF}/${NAME}.cfg"
+ db_fset container/preseed-file seen true
+elif [ -e "${DEBCONF}/links/${NAME}.cfg" ]
+then
+ # user did not specify a pressed file, but there is a matching one
+ # in /etc/${SOFTWARE}/debconf/links directory
+ db_set container/preseed-file "${DEBCONF}/links/${NAME}.cfg"
+ db_fset container/preseed-file seen true
+elif [ "$(ls ${DEBCONF}/*/${NAME}.cfg 2>/dev/null | wc -l)" -eq 1 ]
+then
+ # user did not specify a pressed file, but there is 1 (and only 1)
+ # matching in a sub-directory of /etc/${SOFTWARE}/debconf
+
+ FILE="$(ls ${DEBCONF}/*/${NAME}.cfg)"
+
+ db_set container/preseed-file "${FILE}"
+ db_fset container/preseed-file seen true
+elif [ -e "${DEBCONF}/default.cfg" ]
+then
+ # user did not specify a pressed file, but there is a default one
+ db_set container/preseed-file "${DEBCONF}/default.cfg"
+ db_fset container/preseed-file seen true
+elif ls "${DEBCONF}"/*.cfg > /dev/null 2>&1 || ls "${DEBCONF}"/*/*.cfg > /dev/null 2>&1
+then
+ # user has not specified preseed files through commandline option,
+ # showing debconf selection dialog for global preseed file.
+
+ FILES="$(cd ${DEBCONF} && find . -type f -name '*.cfg' -printf '%P\n' | grep -v '^links\/' | LC_ALL=C sort -V)"
+ PRESEED_FILES="$(for FILE in ${FILES}; do echo -n "$(echo ${FILE} | sed -e 's|.cfg$||'), "; done | sed -e 's|, $||')"
+
+ if [ -n "${PRESEED_FILES}" ]
+ then
+ db_subst container/preseed-files CHOICES "custom, exit, none, , ${PRESEED_FILES}"
+
+ db_settitle container/title
+ db_input high container/preseed-files || true
+ db_go
+
+ db_get container/preseed-files
+ PRESEED_FILE="${RET}" # select
+
+ case "${PRESEED_FILE}" in
+ custom|none)
+ ;;
+
+ exit)
+ rm -f "${CONFIG}/${NAME}.conf"
+ exit 1
+ ;;
+
+ *)
+ # user specified preseed file through debconf select
+ db_set container/preseed-file "${DEBCONF}/${PRESEED_FILE}.cfg"
+ db_fset container/preseed-file seen true
+ ;;
+ esac
+ fi
+fi
+
+case "${PRESEED_FILE}" in
+ none)
+ ;;
+
+ *)
+ # ask user for a preseed file
+ db_settitle container/title
+ db_input high container/preseed-file || true
+ db_go
+
+ db_get container/preseed-file
+ PRESEED_FILE="${RET}" # string (w/ empty)
+
+ echo "PRESEED_FILE=\"${PRESEED_FILE}\"" >> "${DEBCONF_TMPDIR}/debconf.default"
+ export PRESEED_FILE
+ ;;
+esac
+
+db_stop