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

Bug#502821: oldsys-preseed: Extract values for DNS-323



Package: oldsys-preseed
Severity: normal
Tags: patch

The attached patch adds the ability to extract hostname and network
information from the "nvram" of a DNS-323 (tested on a rev B1 machine).

- Matt
>From 7a16c8d3b4fcaedb1bdcb4fe63bd134d1a98f372 Mon Sep 17 00:00:00 2001
From: Matt Palmer <mpalmer@hezmatt.org>
Date: Mon, 20 Oct 2008 14:40:28 +1100
Subject: [PATCH] Extend oldsys-preseed package to handle the DNS323

Modelled closely on the NSLU2 code, with new functions to parse the
alternate way that the DNS-323 stores it's configuration data.
---
 packages/oldsys-preseed/functions      |   26 ++++++++++++++++++++++++++
 packages/oldsys-preseed/oldsys-preseed |   19 ++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/packages/oldsys-preseed/functions b/packages/oldsys-preseed/functions
index 9e94589..19f8b3f 100644
--- a/packages/oldsys-preseed/functions
+++ b/packages/oldsys-preseed/functions
@@ -104,6 +104,15 @@ get_var() {
 	echo "$1" | grep "^$2=" | sed "s/^$2=//"
 }
 
+# Get the value from a string in the form of var = "value" from a file.
+# Named for the sib.conf file on the DNS-323 that this function was
+# originally written for.
+# $1 = file to read
+# $2 = var to read
+get_sib_var() {
+	grep "^$2[[:space:]]*=" $1 |sed "s/^$2[[:space:]]*=[[:space:]]*\"\(.*\)\"[[:space:]]*$/\1/"
+}
+
 # Add a string to a variable; deals with the fact when a string is empty
 # $1 = variable name
 # $2 = string
@@ -143,6 +152,23 @@ parse_sysconf() {
 	DOMAIN=$(get_var "$sysconf" "domain_name")
 }
 
+# Parse the sib.conf file, as found in the Dlink DNS-323
+# $1 = path to sib.conf
+parse_sib_conf() {
+	if [ "$(get_sib_var "$1" "CF-IP-DHCP-ENABLE")" = "0" ]; then
+		NET_CONFIG="static"
+	fi
+	IPADDRESS="$(get_sib_var "$1" "CF-IP-STATIC-IP")"
+	NETMASK="$(get_sib_var "$1" "CF-IP-STATIC-IP-NETMASK")"
+	GATEWAY="$(get_sib_var "$1" "CF-IP-STATIC-IP-GATEWAY")"
+	var_add NAMESERVERS "$(get_sib_var "$1" "CF-IP-DNS1")"
+	var_add NAMESERVERS "$(get_sib_var "$1" "CF-IP-DNS2")"
+	# Since we can't get at just the config file that we want (since we
+	# have no minix filesystem support), we're grepping the whole MTD
+	# device, and there's another config file that defines
+	# CF-SYS-MODEL-STR to be "DNS-323"... ick.
+	HOSTNAME="$(get_sib_var "$1" "CF-SYS-MODEL-STR" | grep -v "DNS-323")"
+}
 
 # Generating
 
diff --git a/packages/oldsys-preseed/oldsys-preseed b/packages/oldsys-preseed/oldsys-preseed
index 0c588c1..7788394 100755
--- a/packages/oldsys-preseed/oldsys-preseed
+++ b/packages/oldsys-preseed/oldsys-preseed
@@ -231,6 +231,24 @@ case "`archdetect`" in
 			fi
 			umount $path/sda1 || true
 			rmdir $path/sda1 $path || true
+		elif echo "$machine" | grep -q "^D-Link DNS-323"; then
+			check_file /proc/mtd
+			rootfs=$(get_mtdblock "MTD1")
+			if [ -z "$rootfs" ]; then
+				log "Can't find rootfs MTD partition"
+				exit 0
+			fi
+			# I can't see anywhere this is configured, so we'll hard-code it
+			# for now
+			INTERFACE="eth0"
+			parse_sib_conf "/dev/$rootfs"
+			sanity_check_static_config
+			if [ "$NET_CONFIG" != "static" ]; then
+				IPADDRESS=192.168.1.77
+				NETMASK=255.255.255.0
+				GATEWAY=192.168.1.254
+				[ -z "$NAMESERVERS" ] && NAMESERVERS=192.168.1.254
+			fi
 		else
 			exit_unknown
 		fi
@@ -258,4 +276,3 @@ fi
 add "$FILE" "partconf/already-mounted" "boolean" "false"
 
 generate_preseed_file $FILE
-
-- 
1.5.6.5


Reply to: