[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH 5/7] Use debconf rather than a preseed file



Using a preseed file prevents overriding questions on the kernel cmdline
which might be required to e.g. override the network setup from the
detected one (this can't be done via a preseed URL since network isn't
up yet).  Call debconf instead of using a preseed file, just like
lib/debian-installer-startup.d/S30env-preseed does to import environment
(passed to init which is busybox) into debconf.  Thanks Colin Watson for
the advice!

Remove all mentions of "preseed file" from comments, variables, and
function names.

Signed-off-by: Loïc Minier <lool@debian.org>
---
 functions                                      |   36 ++++++++++++++---------
 oldsys-preseed                                 |    9 ++++--
 tests/arm/dns323-dhcp.test                     |    2 +-
 tests/arm/dns323-static.test                   |    2 +-
 tests/arm/kuroboxpro_dhcp.test                 |    2 +-
 tests/arm/kuroboxpro_static.test               |    2 +-
 tests/arm/lspro_dhcp.test                      |    2 +-
 tests/arm/lspro_static.test                    |    2 +-
 tests/arm/mv2120_dhcp.test                     |    2 +-
 tests/arm/mv2120_static.test                   |    2 +-
 tests/arm/nslu2.test                           |    2 +-
 tests/arm/nslu2_invalid_hostname.test          |    2 +-
 tests/arm/nslu2_static.test                    |    2 +-
 tests/arm/nslu2_static_no_dns.test             |    2 +-
 tests/arm/nslu2_static_no_gw.test              |    2 +-
 tests/arm/nslu2_static_no_ip.test              |    2 +-
 tests/arm/nslu2_uninitialized.test             |    2 +-
 tests/arm/qnap_dhcp.test                       |    2 +-
 tests/arm/qnap_static.test                     |    2 +-
 tests/arm/qnap_static_unreachable_gateway.test |    2 +-
 tests/arm/thecus_dhcp.test                     |    2 +-
 tests/arm/thecus_static_not_default.test       |    2 +-
 22 files changed, 48 insertions(+), 37 deletions(-)

diff --git a/functions b/functions
index 893da63..e8d69e6 100644
--- a/functions
+++ b/functions
@@ -5,6 +5,9 @@
 # This code is covered by the GNU General Public License (version 2
 # or higher)
 
+# NB: Some functions ultimately call db_set or db_fset, so make sure you
+#     provide them e.g. by importing the debconf shell module
+
 # Reading
 
 # Check if a file exists and exit if it doesn't
@@ -171,23 +174,28 @@ parse_sib_conf() {
 
 # Generating
 
-# Set a debconf question to a value in the preseed file
-# NB: debconf-set-selections will consider every question set in a preseed file
-#     as seen
+# Preseed a debconf question to a value and also set it as seen if we're in
+# non-interactive mode
 # $1 = question
-# $2 = type
+# $2 = type -- unused
 # $3 = value
 op_db_set() {
-	echo "d-i $1 $2 $3" | sed 's/ *$//' >> "$OLDSYS_PRESEED_FILE"
+	if ! db_set "$1" "$3"; then
+		db_register debian-installer/dummy "$1"
+		db_set "$1" "$3"
+	fi
+	if [ "$NONINTERACTIVE" = "yes" ]; then
+		db_fset "$1" "seen" "true"
+	fi
 }
 
-# Set a debconf question as seen, but don't set its value
-# NB: this relies on the special "seen" type as documented in the Debian
-#     Installation Guide, Automating the installation using preseeding,
-#     Advanced options, Using preseeding to change default values
+# Preseed a debconf question as seen, but don't set its value
 # $1 = question
 op_db_seen() {
-	op_db_set "$1" "seen" "true"
+	if ! db_fset "$1" "seen" "true"; then
+		db_register debian-installer/dummy "$1"
+		db_fset "$1" "seen" "true"
+	fi
 }
 
 # Set a debconf question if it's a note or its value isn't empty
@@ -204,7 +212,7 @@ add() {
 # non-interactive mode, otherwise set its value
 # NB: doesn't handle the note type specially
 # $1 = question
-# $2 = type
+# $2 = type -- unused
 # $3 = value
 add_or_set_seen() {
 	if [ -z "$3" -a "$NONINTERACTIVE" = "yes" ]; then
@@ -214,7 +222,7 @@ add_or_set_seen() {
 	fi
 }
 
-# Write a static network configuration to the preseed file
+# Preseed a static network configuration
 write_static_network() {
 	add "netcfg/get_ipaddress" "string" "$IPADDRESS"
 	add_or_set_seen "netcfg/get_netmask" "string" "$NETMASK"
@@ -232,8 +240,8 @@ dhcp_fallback() {
 	write_static_network
 }
 
-# Generate the preseed file
-generate_preseed_file() {
+# Do the actual preseeding
+do_oldsys_preseed() {
 	add "netcfg/choose_interface" "select" "$INTERFACE"
 	if [ "$NET_CONFIG" = "static" ]; then
 		write_static_network
diff --git a/oldsys-preseed b/oldsys-preseed
index 97a8304..90ac9fd 100755
--- a/oldsys-preseed
+++ b/oldsys-preseed
@@ -8,6 +8,10 @@
 
 set -e
 
+# for db_set and db_fset
+export DEBIAN_FRONTEND=noninteractive
+. /usr/share/debconf/confmodule
+
 . /usr/lib/oldsys-preseed/functions
 
 log() {
@@ -15,7 +19,7 @@ log() {
 }
 
 exit_unknown() {
-	log "Unknown system - not writing preseed file"
+	log "Unknown system - skipping oldsys-preseed"
 	exit 0
 }
 
@@ -24,7 +28,6 @@ exit_unknown() {
 # is not optimal but which will ensure that network-console is reached
 # without prompting for user input.
 NONINTERACTIVE="yes"
-OLDSYS_PRESEED_FILE="/preseed.cfg"
 
 case "`archdetect`" in
 	arm*/ixp4xx)
@@ -320,5 +323,5 @@ fi
 # Workaround for broken partconf
 add "partconf/already-mounted" "boolean" "false"
 
-generate_preseed_file
+do_oldsys_preseed
 
diff --git a/tests/arm/dns323-dhcp.test b/tests/arm/dns323-dhcp.test
index e54a877..83b388a 100644
--- a/tests/arm/dns323-dhcp.test
+++ b/tests/arm/dns323-dhcp.test
@@ -3,7 +3,7 @@ parse_sib_conf $TEST_DIR/dns323-dhcp_sib.conf
 unset_matching_var "HOSTNAME" "DNS-323"
 unset_matching_var "HOSTNAME" "CH3SNAS"
 sanity_check_static_config
-generate_preseed_file
+do_oldsys_preseed
 if [ "$NET_CONFIG" != "static" ]; then
 	IPADDRESS=192.168.0.32
 	NETMASK=255.255.255.0
diff --git a/tests/arm/dns323-static.test b/tests/arm/dns323-static.test
index 22da397..fbb2d11 100644
--- a/tests/arm/dns323-static.test
+++ b/tests/arm/dns323-static.test
@@ -3,7 +3,7 @@ parse_sib_conf $TEST_DIR/dns323-static_sib.conf
 unset_matching_var "HOSTNAME" "DNS-323"
 unset_matching_var "HOSTNAME" "CH3SNAS"
 sanity_check_static_config
-generate_preseed_file
+do_oldsys_preseed
 if [ "$NET_CONFIG" != "static" ]; then
 	IPADDRESS=192.168.0.32
 	NETMASK=255.255.255.0
diff --git a/tests/arm/kuroboxpro_dhcp.test b/tests/arm/kuroboxpro_dhcp.test
index 285196f..a4c5bfe 100644
--- a/tests/arm/kuroboxpro_dhcp.test
+++ b/tests/arm/kuroboxpro_dhcp.test
@@ -27,5 +27,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.11.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 rm -rf $path
diff --git a/tests/arm/kuroboxpro_static.test b/tests/arm/kuroboxpro_static.test
index 557a108..638e1c5 100644
--- a/tests/arm/kuroboxpro_static.test
+++ b/tests/arm/kuroboxpro_static.test
@@ -27,5 +27,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.11.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 rm -rf $path
diff --git a/tests/arm/lspro_dhcp.test b/tests/arm/lspro_dhcp.test
index 8c1c7e1..9fcaf9e 100644
--- a/tests/arm/lspro_dhcp.test
+++ b/tests/arm/lspro_dhcp.test
@@ -27,5 +27,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.11.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 rm -rf $path
diff --git a/tests/arm/lspro_static.test b/tests/arm/lspro_static.test
index 7ac0ada..c376071 100644
--- a/tests/arm/lspro_static.test
+++ b/tests/arm/lspro_static.test
@@ -27,5 +27,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.11.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 rm -rf $path
diff --git a/tests/arm/mv2120_dhcp.test b/tests/arm/mv2120_dhcp.test
index 2b7b1b6..a068bdb 100644
--- a/tests/arm/mv2120_dhcp.test
+++ b/tests/arm/mv2120_dhcp.test
@@ -19,4 +19,4 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
diff --git a/tests/arm/mv2120_static.test b/tests/arm/mv2120_static.test
index fb07db7..ca4e1e7 100644
--- a/tests/arm/mv2120_static.test
+++ b/tests/arm/mv2120_static.test
@@ -22,4 +22,4 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
diff --git a/tests/arm/nslu2.test b/tests/arm/nslu2.test
index f3fe557..b808f2d 100644
--- a/tests/arm/nslu2.test
+++ b/tests/arm/nslu2.test
@@ -8,5 +8,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 
diff --git a/tests/arm/nslu2_invalid_hostname.test b/tests/arm/nslu2_invalid_hostname.test
index 9daf8be..39987e0 100644
--- a/tests/arm/nslu2_invalid_hostname.test
+++ b/tests/arm/nslu2_invalid_hostname.test
@@ -8,5 +8,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 
diff --git a/tests/arm/nslu2_static.test b/tests/arm/nslu2_static.test
index bf99731..2a5b87d 100644
--- a/tests/arm/nslu2_static.test
+++ b/tests/arm/nslu2_static.test
@@ -8,5 +8,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 
diff --git a/tests/arm/nslu2_static_no_dns.test b/tests/arm/nslu2_static_no_dns.test
index b232ced..233118f 100644
--- a/tests/arm/nslu2_static_no_dns.test
+++ b/tests/arm/nslu2_static_no_dns.test
@@ -8,5 +8,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 
diff --git a/tests/arm/nslu2_static_no_gw.test b/tests/arm/nslu2_static_no_gw.test
index 62d78c8..4411fae 100644
--- a/tests/arm/nslu2_static_no_gw.test
+++ b/tests/arm/nslu2_static_no_gw.test
@@ -8,5 +8,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 
diff --git a/tests/arm/nslu2_static_no_ip.test b/tests/arm/nslu2_static_no_ip.test
index 6e0d6df..7274b5e 100644
--- a/tests/arm/nslu2_static_no_ip.test
+++ b/tests/arm/nslu2_static_no_ip.test
@@ -8,5 +8,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 
diff --git a/tests/arm/nslu2_uninitialized.test b/tests/arm/nslu2_uninitialized.test
index 0d1525c..a38085e 100644
--- a/tests/arm/nslu2_uninitialized.test
+++ b/tests/arm/nslu2_uninitialized.test
@@ -8,5 +8,5 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
 
diff --git a/tests/arm/qnap_dhcp.test b/tests/arm/qnap_dhcp.test
index 82d9c43..14e38fb 100644
--- a/tests/arm/qnap_dhcp.test
+++ b/tests/arm/qnap_dhcp.test
@@ -28,4 +28,4 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
diff --git a/tests/arm/qnap_static.test b/tests/arm/qnap_static.test
index af18ddf..5a7d0de 100644
--- a/tests/arm/qnap_static.test
+++ b/tests/arm/qnap_static.test
@@ -28,4 +28,4 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
diff --git a/tests/arm/qnap_static_unreachable_gateway.test b/tests/arm/qnap_static_unreachable_gateway.test
index f42bfbd..9cf4892 100644
--- a/tests/arm/qnap_static_unreachable_gateway.test
+++ b/tests/arm/qnap_static_unreachable_gateway.test
@@ -28,4 +28,4 @@ if [ "$NET_CONFIG" != "static" ]; then
 	[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.1
 	dhcp_fallback
 fi
-generate_preseed_file
+do_oldsys_preseed
diff --git a/tests/arm/thecus_dhcp.test b/tests/arm/thecus_dhcp.test
index 62a1c3c..a0b25d1 100644
--- a/tests/arm/thecus_dhcp.test
+++ b/tests/arm/thecus_dhcp.test
@@ -35,5 +35,5 @@ unset_matching_var "DOMAIN" "thecus.com"
 rm -rf $path/mnt
 rm -rf $path/defaults
 rmdir $path || true
-generate_preseed_file
+do_oldsys_preseed
 
diff --git a/tests/arm/thecus_static_not_default.test b/tests/arm/thecus_static_not_default.test
index 54a3888..d4d1a8c 100644
--- a/tests/arm/thecus_static_not_default.test
+++ b/tests/arm/thecus_static_not_default.test
@@ -35,5 +35,5 @@ unset_matching_var "DOMAIN" "thecus.com"
 rm -rf $path/mnt
 rm -rf $path/defaults
 rmdir $path || true
-generate_preseed_file
+do_oldsys_preseed
 
-- 
1.7.5.4


Reply to: