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

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



Hello,

I am no developer and I admit I do not know the very internals of the d-i system, but you can have a look at the attached patch.

This checks if mirror/suite was already set and does not set the value in such a case in choose-mirror.postinst.

I have also modified the choose-mirror.c file to skip setting of mirror/codename if it was already set. I think this is a good idea - if someone has explicitly set miror/codename in preseed, then he would better know what he was doing. Otherwise the codename is assessed as per the original method.

I will try to test this in my environment.

Best regards,
Boleslaw Tokarski
diff --git a/choose-mirror.c b/choose-mirror.c
index 6841ff0..0236128 100644
--- a/choose-mirror.c
+++ b/choose-mirror.c
@@ -708,29 +708,34 @@ int set_codename (void) {
 	char *suite;
 	int i;
 
-	/* 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);
-
-		for (i=0; releases[i].name != NULL; i++) {
-			if (strcmp(releases[i].name, suite) == 0 ||
-			    strcmp(releases[i].suite, suite) == 0) {
-				char *codename;
-
-				if (releases[i].status & GET_CODENAME)
-					codename = releases[i].name;
-				else
-					codename = releases[i].suite;
-				debconf_set(debconf, DEBCONF_BASE "codename", codename);
-				di_log(DI_LOG_LEVEL_INFO,
-					"suite/codename set to: %s/%s",
-					suite, codename);
-				break;
+        /* 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);
+
+			for (i=0; releases[i].name != NULL; i++) {
+				if (strcmp(releases[i].name, suite) == 0 ||
+				    strcmp(releases[i].suite, suite) == 0) {
+					char *codename;
+
+					if (releases[i].status & GET_CODENAME)
+						codename = releases[i].name;
+					else
+						codename = releases[i].suite;
+					debconf_set(debconf, DEBCONF_BASE "codename", codename);
+					di_log(DI_LOG_LEVEL_INFO,
+						"suite/codename set to: %s/%s",
+						suite, codename);
+					break;
+				}
 			}
-		}
 
-		free(suite);
+			free(suite);
+		}
 	}
 
 	return 0;
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: