summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@open-infrastructure.net>2017-10-27 12:19:02 +0000
committerDaniel Baumann <daniel.baumann@open-infrastructure.net>2017-11-01 03:35:15 +0000
commitded0021be3ed470a0498be5573cbf5622f51e9bc (patch)
tree8c194a4ea492460bdd143875197762ce61c155aa
parentSupporting using IP address parts of the container name in preseed files for ... (diff)
downloadcompute-tools-tmp-ip-from-dns.tar.xz
compute-tools-tmp-ip-from-dns.zip
Making IP address automatic substitutions in preseed files for container debconf create script aware of multiple interfaces (FIXME).tmp-ip-from-dns
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
-rwxr-xr-xshare/scripts/debconf48
-rwxr-xr-xshare/scripts/debconf.d/0003-debconf17
-rw-r--r--share/scripts/debconf.d/0003-debconf.templates6
3 files changed, 52 insertions, 19 deletions
diff --git a/share/scripts/debconf b/share/scripts/debconf
index 619d84c..8e332c5 100755
--- a/share/scripts/debconf
+++ b/share/scripts/debconf
@@ -613,35 +613,45 @@ EOF
Upgrade_system "${DIRECTORY}"
+ if [ -e /usr/bin/kdig ]
+ then
+ DIG="/usr/bin/kdig"
+ elif [ -e /usr/bin/dig ]
+ then
+ DIG="/usr/bin/dig"
+ fi
+
# Preseed system
if [ -n "${PRESEED_FILE}" ]
then
for FILE in ${PRESEED_FILE}
do
- if [ -e /usr/bin/kdig ]
- then
- DIG="/usr/bin/kdig"
- elif [ -e /usr/bin/dig ]
- then
- DIG="/usr/bin/dig"
- fi
+ cat "${FILE}" >> "${DIRECTORY}/preseed.cfg"
+ done
+
+ sed -i -e "s|@NAME@|${NAME}|g" "${DIRECTORY}/preseed.cfg"
+ NUMBER="1"
+
+ while grep -qs "@IPV4_ADDRESS${NUMBER}.*@" "${FILE}"
+ do
if [ -n "${DIG}" ]
then
- IPV4_ADDRESS="$(${DIG} +short ${NAME} | tail -n1)"
- IPV4_ADDRESS_PART1="$(echo ${IPV4_ADDRESS} | cut -d. -f1)"
- IPV4_ADDRESS_PART2="$(echo ${IPV4_ADDRESS} | cut -d. -f2)"
- IPV4_ADDRESS_PART3="$(echo ${IPV4_ADDRESS} | cut -d. -f3)"
- IPV4_ADDRESS_PART4="$(echo ${IPV4_ADDRESS} | cut -d. -f4)"
+ eval IPV4_ADDRESS${NUMBER}="$(${DIG} +short ${NAME} | tail -n1)"
+ eval IPV4_ADDRESS${NUMBER}_PART1="$(echo $`echo IPV4_ADDRESS${NUMBER}` | cut -d. -f1)"
+ eval IPV4_ADDRESS${NUMBER}_PART2="$(echo $`echo IPV4_ADDRESS${NUMBER}` | cut -d. -f2)"
+ eval IPV4_ADDRESS${NUMBER}_PART3="$(echo $`echo IPV4_ADDRESS${NUMBER}` | cut -d. -f3)"
+ eval IPV4_ADDRESS${NUMBER}_PART4="$(echo $`echo IPV4_ADDRESS${NUMBER}` | cut -d. -f4)"
fi
- sed -e "s|@NAME@|${NAME}|g" \
- -e "s|@IPV4_ADDRESS@|${IPV4_ADDRESS}|g" \
- -e "s|@IPV4_ADDRESS_PART1@|${IPV4_ADDRESS_PART1}|g" \
- -e "s|@IPV4_ADDRESS_PART2@|${IPV4_ADDRESS_PART2}|g" \
- -e "s|@IPV4_ADDRESS_PART3@|${IPV4_ADDRESS_PART3}|g" \
- -e "s|@IPV4_ADDRESS_PART4@|${IPV4_ADDRESS_PART4}|g" \
- "${FILE}" >> "${DIRECTORY}/preseed.cfg"
+ sed -i -e "s|@IPV4_ADDRESS${NUMBER}@|$`echo IPV4_ADDRESS${NUMBER}`|g" \
+ -e "s|@IPV4_ADDRESS${NUMBER}_PART1@|$`echo IPV4_ADDRESS${NUMBER}_PART1`|g" \
+ -e "s|@IPV4_ADDRESS${NUMBER}_PART2@|$`echo IPV4_ADDRESS${NUMBER}_PART2`|g" \
+ -e "s|@IPV4_ADDRESS${NUMBER}_PART3@|$`echo IPV4_ADDRESS${NUMBER}_PART3`|g" \
+ -e "s|@IPV4_ADDRESS${NUMBER}_PART4@|$`echo IPV4_ADDRESS${NUMBER}_PART4`|g" \
+ "${DIRECTORY}/preseed.cfg"
+
+ NUMBER="$((${NUMBER} + 1))"
done
Chroot "${DIRECTORY}" "debconf-set-selections preseed.cfg"
diff --git a/share/scripts/debconf.d/0003-debconf b/share/scripts/debconf.d/0003-debconf
index 1773b09..0eed489 100755
--- a/share/scripts/debconf.d/0003-debconf
+++ b/share/scripts/debconf.d/0003-debconf
@@ -716,6 +716,9 @@ Network_defaults ()
Network ()
{
+ db_get cnt-debconf/network1/dnsname
+ NETWORK1_DNSNAME="${RET}" # string (w/ empty)
+
db_get cnt-debconf/network1/bridge
NETWORK1_BRIDGE="${RET}" # string (w/o empty)
@@ -757,6 +760,9 @@ Network ()
Network_defaults
+ db_set cnt-debconf/network1/dnsname "${NETWORK1_DNSNAME}"
+ db_fset cnt-debconf/network1/dnsname seen false
+
db_set cnt-debconf/network1/bridge "${NETWORK1_BRIDGE}"
db_fset cnt-debconf/network1/bridge seen false
@@ -800,6 +806,9 @@ Network ()
db_input high cnt-debconf/network1/ipv4-method || true
db_go
+ db_get cnt-debconf/network1/dnsname
+ NETWORK1_DNSNAME="${RET}" # string
+
db_get cnt-debconf/network1/bridge
NETWORK1_BRIDGE="${RET}" # select
@@ -848,6 +857,11 @@ Network ()
while db_get cnt-debconf/network${NUMBER}/ipv4-method && [ "${RET}" ]
do
+ if db_get cnt-debconf/network${NUMBER}/dnsname
+ then
+ eval NETWORK${NUMBER}_DNSNAME="\"${RET}\"" # string (w/ empty)
+ fi
+
if db_get cnt-debconf/network${NUMBER}/bridge
then
eval NETWORK${NUMBER}_BRIDGE="\"${RET}\"" # string (w/o empty)
@@ -916,6 +930,9 @@ Network ()
for NUMBER in $(seq 1 ${NETWORK_NUMBER})
do
+ eval DNSNAME="$`echo NETWORK${NUMBER}_DNSNAME`"
+ echo "NETWORK${NUMBER}_DNSNAME=\"${DNSNAME}\"" >> "${DEBCONF_TMPDIR}/debconf.default"
+
eval BRIDGE="$`echo NETWORK${NUMBER}_BRIDGE`"
echo "NETWORK${NUMBER}_BRIDGE=\"${BRIDGE}\"" >> "${DEBCONF_TMPDIR}/debconf.default"
diff --git a/share/scripts/debconf.d/0003-debconf.templates b/share/scripts/debconf.d/0003-debconf.templates
index e3dbc24..96b5e7d 100644
--- a/share/scripts/debconf.d/0003-debconf.templates
+++ b/share/scripts/debconf.d/0003-debconf.templates
@@ -100,6 +100,12 @@ Default:
Description: Root password
Root password.
+Template: cnt-debconf/network1/dnsname
+Type: string
+Default:
+Description: DNS name.
+ DNS name.
+
Template: cnt-debconf/network1/bridge
Type: string
Default: