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

Re: support-snapshots.debian.org-in-live-build



> >>       lb config -d squeeze --snapshot 20120601
> >>
> >> would make a live image where built with the repos on that date and with
> >> binary sources.list using that date snapshot repositories and not the
> >> latest repos, right?
> >
> > yes.
> >
> 

This new patch only have --snapshot option.

> >> should we try to get the "closest" daily installer or give an error if
> >> daily installer does not exist for that date?
> >
> > imho give a very prominent warning and fall back to the previous (=the
> > one which is the closest one before/older than the snapshot) available one.
> >

This new patch fallsback to the next older available daily d-i instead 
of returning an error when "lb config" is executed.

Also, the security mirror is set to snapshot date (it wasn't in the 
previous patches).

TODO:

  * "mute" wgets;

  * update man pages;

  * clean code (variables and function names, messages, etc)

I'm not happy with the functions and their names. I created them while I 
was creating the patch. They surely need some rework to meet live-build 
standards.
>From 50662dcbf67e74f7389c85edbe5b3640535e8e1a Mon Sep 17 00:00:00 2001
From: "Rui Miguel P. Bernardo" <rui.bernardo.pt@gmail.com>
Date: Sat, 16 Jun 2012 16:00:11 +0100
Subject: [PATCH] support snapshots.debian.org in live-build

---
 functions/debian-snapshots.sh            |  130 ++++++++++++++++++++++++++++++
 functions/defaults.sh                    |   24 ++++++
 scripts/build/lb_binary_debian-installer |    5 ++
 scripts/build/lb_chroot_apt              |   10 +++
 scripts/build/lb_config                  |   12 ++-
 5 files changed, 180 insertions(+), 1 deletion(-)
 create mode 100644 functions/debian-snapshots.sh

diff --git a/functions/debian-snapshots.sh b/functions/debian-snapshots.sh
new file mode 100644
index 0000000..219e521
--- /dev/null
+++ b/functions/debian-snapshots.sh
@@ -0,0 +1,130 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
+##
+## live-build comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+Short_date ()
+{
+	SHORT_DATE="${1}:-${LB_SNAPSHOT}}"
+	# returns the date as YYYYMMDD
+	echo "${SHORT_DATE}" | cut -c 1-8
+}
+
+Last_archive_entry ()
+{
+	# returns the last date link
+	LAST_ENTRY="$(cat /tmp/index.html | grep "$(date +%Y%m)" | sed 's|.*<a href="\([^"]*\)".*$|\1|' | tail -n 1 )"
+	echo "$( echo ${LAST_ENTRY} | sed 's|./||' | sed 's|/||' )"
+}
+
+First_archive_entry ()
+{
+	# returns the 1st date link (1st line is daily-images in daily installer html)
+	FIRST_ENTRY="$(cat /tmp/index.html | grep DIR | sed 's|.*<a href="\([^"]*\)".*$|\1|' | head -n 2 | tail -n 1 )"
+	echo "$( echo ${FIRST_ENTRY} | sed 's|./||' | sed 's|/||' )"
+}
+
+Previous_date ()
+{
+	INITIAL_DATE="${1}"
+
+	# convert date to seconds
+	UNIX_TIME=$(date -d "$INITIAL_DATE" +%s)
+	# one day is 86400 secs
+	#ONE_DAY=$(( 24 * 3600 ))
+	ONE_DAY=86400
+
+	# subtract one day to date
+	PREVIOUS_DATE=$(date -d "$INITIAL_DATE -$ONE_DAY sec" "+%Y%m%d")
+
+	# return previous date
+	echo "${PREVIOUS_DATE}"
+}
+
+Dated_archive_entry ()
+{
+	# returns the link for a specific date
+	WANTED_DATE="${1}:-${LB_SNAPSHOT}}"
+	DATED_ENTRY="$(cat /tmp/index.html | grep "$(Short_date ${WANTED_DATE})" | sed 's|.*<a href="\([^"]*\)".*$|\1|' | tail -n 1 )"
+	echo "$( echo ${DATED_ENTRY} | sed 's|./||' | sed 's|/||' )"
+}
+
+Previous_archive_entry ()
+{
+	# returns the link for the match or the previous entry before specific date
+	FIRST_DATE="$(Short_date $(First_archive_entry))"
+
+	DATE="$(Short_date ${LB_SNAPSHOT})"
+
+	while [ "${DATE}" != "${FIRST_DATE}" ]; do
+		LINK=$(cat /tmp/index.html |  grep "${DATE}" | sed 's|.*<a href="\([^"]*\)".*$|\1|' )
+
+		if [ -z "${LINK}" ]
+		then
+			# date was not found
+			# try previous date
+			DATE=$(Previous_date "${DATE}")
+		else
+			# a link was found
+			break
+		fi
+	done
+
+	# return link to matched date or previous daily installer date,
+	# the 1st one if no other younger d-i for that date was found
+	Dated_archive_entry "${DATE}"
+}
+
+Latest_debian_archive_snapshot_available ()
+{
+	# returns the complete date/time for the link of the latest (last) available debian archive snapshot date
+	wget 'http://snapshot.debian.org/archive/debian/?year='"$(date +%Y)"';month='"$(date +%m)" -O /tmp/index.html && true
+	LAST_ARCHIVE_SNAPSHOT="$(Last_archive_entry)"
+	echo "${LAST_ARCHIVE_SNAPSHOT}"
+}
+
+Dated_debian_archive_snapshot ()
+{
+	# returns the complete date/time for the link of the latest for a specific date in snapshots.debian.org
+	DATE_YEAR="$(Short_date ${LB_SNAPSHOT} | cut -c 1-4 )"
+	DATE_MONTH="$(Short_date ${LB_SNAPSHOT} | cut -c 5-6 )"
+	wget 'http://snapshot.debian.org/archive/debian/?year='"${DATE_YEAR}"';month='"${DATE_MONTH}" -O /tmp/index.html && true
+	LAST_ARCHIVE_SNAPSHOT="$(Dated_archive_entry)"
+	echo "${LAST_ARCHIVE_SNAPSHOT}"
+}
+
+Latest_debian_installer_snapshot_available ()
+{
+	# returns the date-hour for the latest date of debian-installer daily build available for an arch
+	# d-i archive uses different date links
+	wget 'http://d-i.debian.org/daily-images/'"${LB_ARCHITECTURES}" -O /tmp/index.html && true
+	LAST_INSTALLER_SNAPSHOT="$(Last_archive_entry)"
+	echo "${LAST_INSTALLER_SNAPSHOT}"
+}
+
+Dated_debian_installer_snapshot ()
+{
+	# returns the date-hour for the specific date of debian-installer daily build available for an arch
+	# d-i archive uses different date links
+	wget 'http://d-i.debian.org/daily-images/'"${LB_ARCHITECTURES}" -O /tmp/index.html && true
+	DATED_INSTALLER_SNAPSHOT="$(Dated_archive_entry)"
+	echo "${DATED_INSTALLER_SNAPSHOT}"
+}
+
+Available_daily_installer ()
+{
+	# returns the desired daily d-i date link or the previous existing daily d-i
+	DAILY_INSTALLER="$(Dated_debian_installer_snapshot)"
+	if [ -z "${DAILY_INSTALLER}" ]
+	then
+		# no wanted date was found, download available dates and search previous
+		wget 'http://d-i.debian.org/daily-images/'"${LB_ARCHITECTURES}" -O /tmp/index.html && true
+		DAILY_INSTALLER=$(Previous_archive_entry)
+	fi
+
+	echo "${DAILY_INSTALLER}"
+}
diff --git a/functions/defaults.sh b/functions/defaults.sh
index 5a55503..75eca04 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -381,6 +381,19 @@ Set_defaults ()
 	# Setting bootstrap keyring
 	# LB_BOOTSTRAP_KEYRING
 
+	# Setting snapshots.debian.org
+	if [ -n "${LB_SNAPSHOT}" ]
+	then
+		LB_MIRROR_BOOTSTRAP="${LB_MIRROR_BOOTSTRAP:-http://snapshot.debian.org/archive/debian/${LB_SNAPSHOT}}";
+		LB_PARENT_MIRROR_BOOTSTRAP="${LB_MIRROR_BOOTSTRAP}"
+		LB_MIRROR_CHROOT_SECURITY="${LB_MIRROR_CHROOT_SECURITY:-http://snapshot.debian.org/archive/debian-security/${LB_SNAPSHOT}}";
+		LB_PARENT_MIRROR_CHROOT_SECURITY="${LB_PARENT_MIRROR_CHROOT_SECURITY:-${LB_MIRROR_CHROOT_SECURITY}}"
+		LB_MIRROR_BINARY="${LB_MIRROR_BINARY:-http://snapshot.debian.org/archive/debian/${LB_SNAPSHOT}}";
+		LB_PARENT_MIRROR_BINARY="${LB_PARENT_MIRROR_BINARY:-${LB_MIRROR_BINARY}}"
+		LB_MIRROR_BINARY_SECURITY="${LB_MIRROR_BINARY_SECURITY:-http://snapshot.debian.org/archive/debian-security/${LB_SNAPSHOT}}";
+		LB_PARENT_MIRROR_BINARY_SECURITY="${LB_PARENT_MIRROR_BINARY_SECURITY:-${LB_MIRROR_BINARY_SECURITY}}"
+	fi
+
 	# Setting mirror to fetch packages from
 	case "${LB_MODE}" in
 		debian)
@@ -1257,6 +1270,17 @@ Check_defaults ()
 		fi
 	fi
 
+	if [ -n "${LB_SNAPSHOT}" ] && [ "${LB_DEBIAN_INSTALLER}" = "live" ] && [ "${LB_DEBIAN_INSTALLER_DISTRIBUTION}" = "daily" ]
+	then
+		DAILY_LIVE_INSTALLER="$(Dated_debian_installer_snapshot)"
+		# if there is no available daily installer
+		if [ -z "${DAILY_LIVE_INSTALLER}" ]
+		then
+			Echo_warning "You have selected debian-snapshots option with daily live-installer, but there is no daily live installer available at that date. The selected date was ${LB_SNAPSHOT}"
+			Echo_warning "The last available daily installer before ${LB_SNAPSHOT} will be used."
+		fi
+	fi
+
 	if [ "${LB_BOOTLOADER}" = "syslinux" ]
 	then
 		# syslinux + fat
diff --git a/scripts/build/lb_binary_debian-installer b/scripts/build/lb_binary_debian-installer
index 003051b..885a94d 100755
--- a/scripts/build/lb_binary_debian-installer
+++ b/scripts/build/lb_binary_debian-installer
@@ -261,6 +261,11 @@ case "${LB_DERIVATIVE}" in
 
 			# Debian Installer daily builds
 			URL="http://d-i.debian.org/daily-images/${LB_ARCHITECTURES}/daily/";
+			# use snapshot installer too
+			if [ -n "${LB_SNAPSHOT}" ]
+			then
+				URL="http://d-i.debian.org/daily-images/${LB_ARCHITECTURES}/$(Available_daily_installer)/"
+			fi
 		else
 			URL="${LB_MIRROR_DEBIAN_INSTALLER}/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/installer-${LB_ARCHITECTURES}/current/images/"
 		fi
diff --git a/scripts/build/lb_chroot_apt b/scripts/build/lb_chroot_apt
index 710b2e0..3ab8f38 100755
--- a/scripts/build/lb_chroot_apt
+++ b/scripts/build/lb_chroot_apt
@@ -54,6 +54,13 @@ case "${1}" in
 			echo "Acquire::http::Proxy \"${LB_APT_HTTP_PROXY}\";" > chroot/etc/apt/apt.conf.d/00http-proxy
 		fi
 
+		# Configuring snapshots.debian.org
+		if [ -n "${LB_SNAPSHOT}" ]
+		then
+			echo '// see bug #595801' > chroot/etc/apt/apt.conf.d/00debian-snapshots
+			echo 'Acquire::Check-Valid-Until "false";' >> chroot/etc/apt/apt.conf.d/00debian-snapshots
+		fi
+
 		# Configuring apt pipeline
 		if [ -n "${LB_APT_PIPELINE}" ]
 		then
@@ -240,6 +247,9 @@ EOF
 		# Deconfiguring aptitude http proxy
 		rm -f chroot/etc/apt/apt.conf.d/00http-proxy
 
+		# Deconfiguring snapshots.debian.org
+		rm -f chroot/etc/apt/apt.conf.d/00debian-snapshots
+
 		# Deconfiguring aptitude pipeline
 		rm -f chroot/etc/apt/apt.conf.d/00pipeline
 
diff --git a/scripts/build/lb_config b/scripts/build/lb_config
index f1ae30c..c32dbb6 100755
--- a/scripts/build/lb_config
+++ b/scripts/build/lb_config
@@ -66,6 +66,7 @@ USAGE="${PROGRAM}   [--apt apt|aptitude]\n\
 \t    [--debian-installer-distribution daily|CODENAME]\n\
 \t    [--debian-installer-preseedfile FILE|URL]\n\
 \t    [--debian-installer-gui true|false]\n\
+\t    [--snapshot yyyymmdd|yyyymmddThhmmssZ\n\
 \t    [--debug]\n\
 \t    [-d|--distribution CODENAME]\n\
 \t    [--parent-distribution CODENAME]\n\
@@ -175,7 +176,7 @@ Local_arguments ()
 		net-cow-server:,net-tarball:,firmware-binary:,firmware-chroot:,swap-file-path:,swap-file-size:,syslinux-theme:,
 		win32-loader:,source:,source-images:,breakpoints,conffile:,debug,force,
 		help,ignore-system-defaults,quiet,usage,verbose,version,bootstrap-qemu-static:,bootstrap-qemu-arch:,
-		bootstrap-qemu-exclude:"
+		bootstrap-qemu-exclude:,snapshot:"
 	# Remove spaces added by indentation
 	LONG_OPTIONS="$(echo ${LONG_OPTIONS} | tr -d ' ')"
 	ARGUMENTS="$(getopt --longoptions ${LONG_OPTIONS} --name="${PROGRAM}" --options a:f:d:m:l:k:p:b:e:s:c:huv --shell sh -- "${@}")"
@@ -323,6 +324,11 @@ Local_arguments ()
 				shift 2
 				;;
 
+			--snapshot)
+				LB_SNAPSHOT="${2}"
+				shift 2
+				;;
+
 			--initramfs)
 				LB_INITRAMFS="${2}"
 				shift 2
@@ -983,6 +989,10 @@ LB_DEBCONF_NOWARNINGS="${LB_DEBCONF_NOWARNINGS}"
 # (Default: ${LB_DEBCONF_PRIORITY})
 LB_DEBCONF_PRIORITY="${LB_DEBCONF_PRIORITY}"
 
+# \$LB_SNAPSHOT: set snapshots.debian.org date to use
+# (Default: empty or not set to not use archive snapshot, or a valid date in snapshots.debian.org URL format)
+LB_SNAPSHOT="${LB_SNAPSHOT}"
+
 # \$LB_INITRAMFS: set initramfs hook
 # (Default: ${LB_INITRAMFS})
 LB_INITRAMFS="${LB_INITRAMFS}"
-- 
1.7.10


Reply to: