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

Bug#635053: Choose-mirror overrides mirror/suite and mirror/codename



Hello,
Please test it and if it works ping us to review and commit it;
I have tested the patch, found one bug, so I am attaching the updated patch. It worked in my environment, though I might have not considered all use cases.
regarding debootstrap you can preseed it using:

d-i base-installer/debootstrap_script string squeeze

This ought to work.
Great, thanks for the tip. I will give it a try, looks like it is going to save me another hacked package.

Best regards,
Boleslaw Tokarski

diff --git a/choose-mirror.c b/choose-mirror.c
index 6237cfb..389be20 100644
--- a/choose-mirror.c
+++ b/choose-mirror.c
@@ -558,29 +558,33 @@ int get_codename (void) {
 	free(directory);
 	directory = strdup(debconf->value);
 
-	/* As suite has been determined previously, this should not fail */
-	debconf_get(debconf, DEBCONF_BASE "suite");
-	if (strlen(debconf->value) > 0) {
-		suite = strdup(debconf->value);
-
-		asprintf(&command, "wget -q %s://%s%s/dists/%s/Release -O - | grep ^Codename: | cut -d' ' -f 2",
-			 protocol, hostname, directory, suite);
-		di_log(DI_LOG_LEVEL_DEBUG, "command: %s", command);
-		f = popen(command, "r");
-		free(command);
-
-		if (f != NULL) {
-			char buf[SUITE_LENGTH];
-			if (fgets(buf, SUITE_LENGTH - 1, f)) {
-				if (buf[strlen(buf) - 1] == '\n')
-					buf[strlen(buf) - 1] = '\0';
-				debconf_set(debconf, DEBCONF_BASE "codename", buf);
-				di_log(DI_LOG_LEVEL_INFO, "codename set to: %s", buf);
-				ret = 0;
+        /* If preseed specifies codename, omit the codename check */
+	debconf_get(debconf, DEBCONF_BASE "codename");
+	if ( ! strlen(debconf->value) > 0) {
+		/* As suite has been determined previously, this should not fail */
+		debconf_get(debconf, DEBCONF_BASE "suite");
+		if (strlen(debconf->value) > 0) {
+			suite = strdup(debconf->value);
+
+			asprintf(&command, "wget -q %s://%s%s/dists/%s/Release -O - | grep ^Codename: | cut -d' ' -f 2",
+				 protocol, hostname, directory, suite);
+			di_log(DI_LOG_LEVEL_DEBUG, "command: %s", command);
+			f = popen(command, "r");
+			free(command);
+
+			if (f != NULL) {
+				char buf[SUITE_LENGTH];
+				if (fgets(buf, SUITE_LENGTH - 1, f)) {
+					if (buf[strlen(buf) - 1] == '\n')
+						buf[strlen(buf) - 1] = '\0';
+					debconf_set(debconf, DEBCONF_BASE "codename", buf);
+					di_log(DI_LOG_LEVEL_INFO, "codename set to: %s", buf);
+					ret = 0;
+				}
 			}
+			pclose(f);
 		}
-		pclose(f);
-	}
+	} else ret = 0;
 
 	free(hostname);
 	free(directory);
diff --git a/debian/choose-mirror.postinst b/debian/choose-mirror.postinst
index 4a85a78..4689ab0 100644
--- a/debian/choose-mirror.postinst
+++ b/debian/choose-mirror.postinst
@@ -3,10 +3,12 @@
 
 anna-install apt-mirror-setup || true
 
-if [ -f /etc/lsb-release ]; then
-	. /etc/lsb-release
-	if [ -n "$DISTRIB_CODENAME" ]; then
-		db_set mirror/suite "$DISTRIB_CODENAME"
+if ! db_get mirror/suite || ! [ "$RET" ]; then
+	if [ -f /etc/lsb-release ]; then
+		. /etc/lsb-release
+		if [ -n "$DISTRIB_CODENAME" ]; then
+			db_set mirror/suite "$DISTRIB_CODENAME"
+		fi
 	fi
 fi
 

Reply to: