From 5362e3a7e743ad85fc2b900ed0240e8e1eb58e12 Mon Sep 17 00:00:00 2001 From: Robert C Jennings Date: Thu, 5 Mar 2020 09:20:36 +0100 Subject: [PATCH 1/4] Use build env archive mirror in binary hooks --- live-build/functions | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/live-build/functions b/live-build/functions index e4b90425..65c2bc92 100644 --- a/live-build/functions +++ b/live-build/functions @@ -87,6 +87,25 @@ mount_image() { return 0 } +setup_sourceslist(){ + # Use the build environment apt mirror during the build, + # for both archive and security. + # live-build does this in the chroot (lb_chroot_archives) + # but not for the binary hooks + + . config/bootstrap # For the LB_MIRROR_* variables + cp -a "${mountpoint}/etc/apt/sources.list" sources.list.tmp + sed -i "s#http://archive.ubuntu.com/ubuntu#${LB_PARENT_MIRROR_CHROOT}#g" \ + "${mountpoint}/etc/apt/sources.list" + sed -i "s#http://security.ubuntu.com/ubuntu#${LB_PARENT_MIRROR_CHROOT}#g" \ + "${mountpoint}/etc/apt/sources.list" +} + +recover_sourceslist(){ + # Remove the build environment apt mirror from the image + mv sources.list.tmp "${mountpoint}/etc/apt/sources.list" +} + setup_mountpoint() { local mountpoint="$1" @@ -109,6 +128,7 @@ setup_mountpoint() { cp /etc/resolv.conf "$mountpoint/etc/resolv.conf" mv "$mountpoint/etc/nsswitch.conf" nsswitch.conf.tmp sed 's/systemd//g' nsswitch.conf.tmp > "$mountpoint/etc/nsswitch.conf" + setup_sourceslist "${mountpoint}" chroot "$mountpoint" apt-get update } @@ -125,6 +145,7 @@ teardown_mountpoint() { mount --make-private $submount umount $submount done + recover_sourceslist "${mountpoint}" mv resolv.conf.tmp "$mountpoint/etc/resolv.conf" mv nsswitch.conf.tmp "$mountpoint/etc/nsswitch.conf" } From 5190aff93210098168ad0a5ad492f93e6c080e21 Mon Sep 17 00:00:00 2001 From: Robert C Jennings Date: Fri, 6 Mar 2020 14:55:50 +0100 Subject: [PATCH 2/4] Ensure a binary hook has not changed the temporary sources.list --- live-build/functions | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/live-build/functions b/live-build/functions index 65c2bc92..b687a5f7 100644 --- a/live-build/functions +++ b/live-build/functions @@ -99,10 +99,19 @@ setup_sourceslist(){ "${mountpoint}/etc/apt/sources.list" sed -i "s#http://security.ubuntu.com/ubuntu#${LB_PARENT_MIRROR_CHROOT}#g" \ "${mountpoint}/etc/apt/sources.list" + + sha256sum "${mountpoint}/etc/apt/sources.list" > sources.list.sha } recover_sourceslist(){ # Remove the build environment apt mirror from the image + + # Check that the sources.list has not changed. If it has changed then the + # binary hook has modified the file that will be discarded. If the build + # fails here the binary hook needs to alter sources.list.tmp and regenerate + # sources.list.sha + sha256sum --check sources.list.sha + mv sources.list.tmp "${mountpoint}/etc/apt/sources.list" } From 32d5afc40aef3d7c98ecf1118bd845d9136a409e Mon Sep 17 00:00:00 2001 From: Pat Viafore Date: Wed, 8 Apr 2020 12:30:45 -0500 Subject: [PATCH 3/4] Expose a variable for sources.list backup MOUNTPOINT_BACKUP_SOURCE_LIST is exposed when you call setup_mountpoint. Consumers can use this variable if they need to explicitly change something in sources.list wihout relying on the name livecd-rootfs chooses. --- live-build/functions | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/live-build/functions b/live-build/functions index b687a5f7..46a80108 100644 --- a/live-build/functions +++ b/live-build/functions @@ -87,14 +87,19 @@ mount_image() { return 0 } -setup_sourceslist(){ +setup_sourceslist_to_use_lb_parent_mirror_chroot(){ # Use the build environment apt mirror during the build, # for both archive and security. # live-build does this in the chroot (lb_chroot_archives) # but not for the binary hooks + # + # To restore the sourceslist back to the original, call + # recover_sourceslist + mountpoint="${1}" + MOUNTPOINT_BACKUP_SOURCES_LIST="sources.list.tmp" . config/bootstrap # For the LB_MIRROR_* variables - cp -a "${mountpoint}/etc/apt/sources.list" sources.list.tmp + cp -a "${mountpoint}/etc/apt/sources.list" "${MOUNTPOINT_BACKUP_SOURCES_LIST}" sed -i "s#http://archive.ubuntu.com/ubuntu#${LB_PARENT_MIRROR_CHROOT}#g" \ "${mountpoint}/etc/apt/sources.list" sed -i "s#http://security.ubuntu.com/ubuntu#${LB_PARENT_MIRROR_CHROOT}#g" \ @@ -110,9 +115,12 @@ recover_sourceslist(){ # binary hook has modified the file that will be discarded. If the build # fails here the binary hook needs to alter sources.list.tmp and regenerate # sources.list.sha + + mountpoint="${1}" sha256sum --check sources.list.sha - mv sources.list.tmp "${mountpoint}/etc/apt/sources.list" + mv "${MOUNTPOINT_BACKUP_SOURCES_LIST}" "${mountpoint}/etc/apt/sources.list" + unset MOUNTPOINT_BACKUP_SOURCES_LIST } setup_mountpoint() { @@ -137,7 +145,7 @@ setup_mountpoint() { cp /etc/resolv.conf "$mountpoint/etc/resolv.conf" mv "$mountpoint/etc/nsswitch.conf" nsswitch.conf.tmp sed 's/systemd//g' nsswitch.conf.tmp > "$mountpoint/etc/nsswitch.conf" - setup_sourceslist "${mountpoint}" + setup_sourceslist_to_use_lb_parent_mirror_chroot "${mountpoint}" chroot "$mountpoint" apt-get update } From 78ced6b26eb2833ceaa9f3a1e6a56e6bf08b16d7 Mon Sep 17 00:00:00 2001 From: Pat Viafore Date: Mon, 11 May 2020 12:24:35 -0500 Subject: [PATCH 4/4] Rename function to be shorter --- debian/changelog | 9 +++++++++ live-build/functions | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 54346c47..06c89050 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +livecd-rootfs (2.689) UNRELEASED; urgency=medium + + [ Patrick Viafore ] + * Replace archive.ubuntu.com and security.ubuntu.com with launchpad + mirrors. This is only done inside a build context, and the original + sources.list file is restored at the end of the build + + -- Patrick Viafore Mon, 21 Sep 2020 12:08:11 -0500 + livecd-rootfs (2.688) groovy; urgency=medium * ubuntu-cpc: Fix spelling in vagrant file diff --git a/live-build/functions b/live-build/functions index 46a80108..aebeaa55 100644 --- a/live-build/functions +++ b/live-build/functions @@ -87,7 +87,7 @@ mount_image() { return 0 } -setup_sourceslist_to_use_lb_parent_mirror_chroot(){ +use_lp_archives_in_sourceslist(){ # Use the build environment apt mirror during the build, # for both archive and security. # live-build does this in the chroot (lb_chroot_archives) @@ -145,7 +145,7 @@ setup_mountpoint() { cp /etc/resolv.conf "$mountpoint/etc/resolv.conf" mv "$mountpoint/etc/nsswitch.conf" nsswitch.conf.tmp sed 's/systemd//g' nsswitch.conf.tmp > "$mountpoint/etc/nsswitch.conf" - setup_sourceslist_to_use_lb_parent_mirror_chroot "${mountpoint}" + use_lp_archives_in_sourceslist "${mountpoint}" chroot "$mountpoint" apt-get update }