| 1 | #!/bin/sh |
| 2 | |
| 3 | # Copyright (C) 2014-2026 Daniel Baumann <[email protected]> |
| 4 | # |
| 5 | # SPDX-License-Identifier: GPL-3.0+ |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation, either version 3 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | |
| 20 | set -e |
| 21 | |
| 22 | if [ -e "${DEBCONF_TMPDIR}/debconf.default" ] |
| 23 | then |
| 24 | . "${DEBCONF_TMPDIR}/debconf.default" |
| 25 | fi |
| 26 | |
| 27 | if [ -z "${PRESEED_FILE}" ] |
| 28 | then |
| 29 | # user has not specified or selected any preseed files |
| 30 | exit 0 |
| 31 | fi |
| 32 | |
| 33 | # user has one or more preseed file specified through commandline option |
| 34 | # or debconf selection dialog. |
| 35 | PRESEED_FILES="$(echo ${PRESEED_FILE} | sed -e 's|,| |g')" |
| 36 | |
| 37 | DEBCONF_PRESEED_FILES="" |
| 38 | |
| 39 | for PRESEED_FILE in ${PRESEED_FILES} |
| 40 | do |
| 41 | if [ ! -e "${PRESEED_FILE}" ] |
| 42 | then |
| 43 | # preseed file does not exist |
| 44 | echo "W: ${PRESEED_FILE}: No such file." |
| 45 | |
| 46 | continue |
| 47 | fi |
| 48 | |
| 49 | # add preseed file to debconf |
| 50 | DEBCONF_PRESEED_FILES="${DEBCONF_PRESEED_FILES} ${PRESEED_FILE}" |
| 51 | |
| 52 | if ! grep -qs '^ *compute-tools *container/include-preseed-files' "${PRESEED_FILE}" |
| 53 | then |
| 54 | # preseed file has no includes |
| 55 | continue |
| 56 | fi |
| 57 | |
| 58 | # preseed file has includes |
| 59 | INCLUDE_PRESEED_FILES="$(grep '^ *compute-tools *container/include-preseed-files' ${PRESEED_FILE} | awk '{ $1=$2=$3=""; print $0 }' | sed -e 's|,| |g')" |
| 60 | |
| 61 | # only one include layer is supported, no nested/recursive includes |
| 62 | for FILE in ${INCLUDE_PRESEED_FILES} |
| 63 | do |
| 64 | if [ -e "${FILE}" ] |
| 65 | then |
| 66 | DEBCONF_PRESEED_FILES="${FILE} ${DEBCONF_PRESEED_FILES}" |
| 67 | else |
| 68 | # included preseed file does not exist |
| 69 | echo "W: ${INCLUDE_PRESEED_FILE}: No such file - included from ${PRESEED_FILE}" |
| 70 | fi |
| 71 | done |
| 72 | done |
| 73 | |
| 74 | for DEBCONF_PRESEED_FILE in ${DEBCONF_PRESEED_FILES} |
| 75 | do |
| 76 | if [ -e /usr/bin/kdig ] |
| 77 | then |
| 78 | DIG="/usr/bin/kdig" |
| 79 | elif [ -e /usr/bin/dig ] |
| 80 | then |
| 81 | DIG="/usr/bin/dig" |
| 82 | fi |
| 83 | |
| 84 | if [ -n "${DIG}" ] |
| 85 | then |
| 86 | IPV4_ADDRESS1="$(${DIG} A +short ${NAME} | tail -n1)" |
| 87 | IPV4_ADDRESS1_PART1="$(echo ${IPV4_ADDRESS1} | cut -d. -f1)" |
| 88 | IPV4_ADDRESS1_PART2="$(echo ${IPV4_ADDRESS1} | cut -d. -f2)" |
| 89 | IPV4_ADDRESS1_PART3="$(echo ${IPV4_ADDRESS1} | cut -d. -f3)" |
| 90 | IPV4_ADDRESS1_PART4="$(echo ${IPV4_ADDRESS1} | cut -d. -f4)" |
| 91 | |
| 92 | IPV6_ADDRESS1="$(${DIG} AAAA +short ${NAME} | tail -n1)" |
| 93 | fi |
| 94 | |
| 95 | sed -e "s|@NAME@|${NAME}|g" \ |
| 96 | -e "s|@HOST@|${HOST}|g" \ |
| 97 | -e "s|@IPV4_ADDRESS1@|${IPV4_ADDRESS1}|g" \ |
| 98 | -e "s|@IPV4_ADDRESS1_PART1@|${IPV4_ADDRESS1_PART1}|g" \ |
| 99 | -e "s|@IPV4_ADDRESS1_PART2@|${IPV4_ADDRESS1_PART2}|g" \ |
| 100 | -e "s|@IPV4_ADDRESS1_PART3@|${IPV4_ADDRESS1_PART3}|g" \ |
| 101 | -e "s|@IPV4_ADDRESS1_PART4@|${IPV4_ADDRESS1_PART4}|g" \ |
| 102 | -e "s|@IPV6_ADDRESS1@|${IPV6_ADDRESS1}|g" \ |
| 103 | "${DEBCONF_PRESEED_FILE}" > "${DIRECTORY}/preseed.cfg" |
| 104 | |
| 105 | # Apply user specified preseed files |
| 106 | debconf-set-selections "${DIRECTORY}/preseed.cfg" |
| 107 | |
| 108 | rm -f "${DIRECTORY}/preseed.cfg" |
| 109 | done |
| 110 | |
| 111 | # Write expanded list of debconf preseed files |
| 112 | echo "PRESEED_FILE=\"${DEBCONF_PRESEED_FILES}\"" >> "${DEBCONF_TMPDIR}/debconf.default" |