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

[patch] Defining apt sources using codename instead of suite



Here are proposed patches for choose-mirror, cdrom-detect and iso-scan 
that determine the codename that goes with the suite that will be 
installed.

The idea is, when creating lines for /target/etc/apt/sources.list, to 
check if mirror/codename is set and, if it is, to use that instead of 
mirror/suite (as discussed after the release of Sarge).

There is some code duplication in choose-mirror.c, but my C skills are not 
sufficient to solve that.

Comments welcome. If OK, I will commit them.

Cheers,
FJP

Index: debian/cdrom-detect.templates
===================================================================
--- debian/cdrom-detect.templates	(revision 31641)
+++ debian/cdrom-detect.templates	(working copy)
@@ -106,6 +106,10 @@
  that receives many of the new versions from unstable if they are not too
  buggy.
 
+Template: mirror/codename
+Type: string
+Description: Codename for the selected suite (internal use)
+
 Template: prebaseconfig/progress/cdrom-detect
 Type: text
 # Prebaseconfig progress bar item
Index: debian/changelog
===================================================================
--- debian/changelog	(revision 31641)
+++ debian/changelog	(working copy)
@@ -1,3 +1,10 @@
+cdrom-detect (1.11) UNRELEASED; urgency=low
+
+  * Also determine de codename of the release. This can be used later to
+    set apt sources by codename.
+
+ -- Frans Pop <fjp@debian.org>  Sun, 23 Oct 2005 16:57:08 +0200
+
 cdrom-detect (1.10) unstable; urgency=low
 
   [ Colin Watson ]
Index: debian/cdrom-detect.postinst
===================================================================
--- debian/cdrom-detect.postinst	(revision 31641)
+++ debian/cdrom-detect.postinst	(working copy)
@@ -154,18 +154,20 @@
 done
 db_progress STOP
 
-# Set the suite used by base-installer and base-config to
-# the suite that is on the CD. This assumes that there will
-# be no more than one distribution on the CD, and that one of the
-# testing, stable, or unstable links will point to it. Since the
+# Set the suite and codename used by base-installer and base-config
+# to the suite/codename that is on the CD. This assumes that there
+# will be no more than one distribution on the CD, and that one of
+# the testing, stable, or unstable links will point to it. Since the
 # CDs currently have many links, parse the Release file to get the
 # actual suite name to use.
 for distlink in stable testing unstable ; do
 	relfile=/cdrom/dists/$distlink/Release
 	if [ -e $relfile ] ; then
 		suite=$(sed -n 's/^Suite: *//p' $relfile)
-		log "Detected CD with '$suite' distribution"
+		codename=$(sed -n 's/^Codename: *//p' $relfile)
+		log "Detected CD with '$suite' ($codename) distribution"
 		db_set mirror/suite $suite
+		db_set mirror/codename $codename
 
 		break
 	fi
Index: debian/changelog
===================================================================
--- debian/changelog	(revision 31641)
+++ debian/changelog	(working copy)
@@ -38,6 +38,8 @@
 
   [ Frans Pop ]
   * Make sure mirror/protocol template is included.
+  * After a suite has been selected, also determine its codename. This
+    can be used later to set apt sources by codename.
 
  -- Frans Pop <fjp@debian.org>  Sun, 23 Oct 2005 15:59:08 +0200
 
Index: debian/choose-mirror.templates-in
===================================================================
--- debian/choose-mirror.templates-in	(revision 31641)
+++ debian/choose-mirror.templates-in	(working copy)
@@ -17,6 +17,10 @@
  that receives many of the new versions from unstable if they are not too
  buggy.
 
+Template: mirror/codename
+Type: string
+Description: codename for the selected suite (internal use)
+
 Template: mirror/checking_title
 Type: text
 _Description: Checking the Debian archive mirror
Index: choose-mirror.c
===================================================================
--- choose-mirror.c	(revision 31641)
+++ choose-mirror.c	(working copy)
@@ -407,6 +407,56 @@
 	}
 }
 
+/* Get the codename for the selected suite. I think having the codename should
+ * be optional (at least for now), so return 0 on errors.
+ */
+int get_codename (void) {
+	char *command;
+	FILE *f = NULL;
+	char *hostname, *directory, *suite;
+	int i;
+
+	hostname = add_protocol("hostname");
+	debconf_get(debconf, hostname);
+	free(hostname);
+	hostname = strdup(debconf->value);
+	directory = add_protocol("directory");
+	debconf_get(debconf, directory);
+	free(directory);
+	directory = strdup(debconf->value);
+	/* The suite has been determined previously, so this should not fail */
+	debconf_get(debconf, DEBCONF_BASE "suite");
+	if (strlen(debconf->value) > 0) {
+		suite = strdup(debconf->value);
+	}
+	else {
+		return 0;
+	}
+
+	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_DEBUG, "codename set to: %s", buf);
+		}
+	}
+	pclose(f);
+
+	free(hostname);
+	free(directory);
+	free(suite);
+
+	return 0;
+}
+
 int main (void) {
 	/* Use a state machine with a function to run in each state */
 	int state = 0;
@@ -420,6 +470,7 @@
 		set_proxy,
 		validate_mirror,
 		choose_suite,
+		get_codename,
 		NULL,
 	};
 
Index: debian/changelog
===================================================================
--- debian/changelog	(revision 31641)
+++ debian/changelog	(working copy)
@@ -1,3 +1,10 @@
+iso-scan (1.10) UNRELEASED; urgency=low
+
+  * Also determine de codename of the release. This can be used later to
+    set apt sources by codename.
+
+ -- Frans Pop <fjp@debian.org>  Sun, 23 Oct 2005 16:58:23 +0200
+
 iso-scan (1.09) unstable; urgency=low
 
   * Queue apt-mirror-setup for install, this is part of the apt-setup
Index: debian/iso-scan.templates
===================================================================
--- debian/iso-scan.templates	(revision 31641)
+++ debian/iso-scan.templates	(working copy)
@@ -12,6 +12,10 @@
  that receives many of the new versions from unstable if they are not too
  buggy.
 
+Template: mirror/codename
+Type: string
+Description: Codename for the selected suite (internal use)
+
 Template: iso-scan/detect_progress_title
 Type: text
 _Description: Detecting hardware to find hard drives
Index: debian/iso-scan.postinst
===================================================================
--- debian/iso-scan.postinst	(revision 31641)
+++ debian/iso-scan.postinst	(working copy)
@@ -30,18 +30,20 @@
 }
 
 register_cd () {
-	# Set the suite used by base-installer and base-config to
-	# the suite that is on the CD. This assumes that there will
-	# be no more than one distribution on the CD, and that one of the
-	# testing, stable, or unstable links will point to it. Since the
+	# Set the suite and codename used by base-installer and base-config
+	# to the suite/codename that is on the CD. This assumes that there
+	# will be no more than one distribution on the CD, and that one of
+	# the testing, stable, or unstable links will point to it. Since the
 	# CDs currently have many links, parse the Release file to get the
 	# actual suite name to use.
 	for distlink in stable testing unstable ; do
 		relfile=/cdrom/dists/$distlink/Release
 		if [ -e $relfile ] ; then
 			suite=$(sed -n 's/^Suite: *//p' $relfile)
-			log "Detected ISO with '$suite' distribution"
+			codename=$(sed -n 's/^Codename: *//p' $relfile)
+			log "Detected ISO with '$suite' ($codename) distribution"
 			db_set mirror/suite $suite
+			db_set mirror/codename $codename
 			db_subst iso-scan/success SUITE $suite
 			
 			description=`sed -n 's/^Description: *//p' $relfile`

Attachment: pgpGjZVNQ4htY.pgp
Description: PGP signature


Reply to: