tapt caching proof of concept - libdevuansdk - common library for devuan's simple distro kits HTML git clone https://git.parazyd.org/libdevuansdk DIR Log DIR Files DIR Refs DIR Submodules DIR README DIR LICENSE --- DIR commit a92a5aee8dafe76cd0605d82521b0bd2b35c5204 DIR parent fa06bc6308eee6da3aecce1d42cb59afcbe5ca3a HTML Author: parazyd <parazyd@dyne.org> Date: Sun, 21 May 2017 19:11:10 +0200 apt caching proof of concept Diffstat: A apt-cache/Packages.gz | 0 M config | 7 +++++-- M zlibs/bootstrap | 2 -- M zlibs/helpers | 60 ++++++++++++++++++++++++++++++-- M zlibs/iso | 1 - M zlibs/sysconf | 2 ++ 6 files changed, 65 insertions(+), 7 deletions(-) --- DIR diff --git a/apt-cache/Packages.gz b/apt-cache/Packages.gz Binary files differ. DIR diff --git a/config b/config t@@ -20,15 +20,18 @@ ## libdevuansdk configuration vars+=(release version mirror section blend_name image_name vm_name) -vars+=(arch earch) +vars+=(arch earch aptcachedir APT_CACHE) vars+=(usercredentials rootcredentials) arrs+=(core_packages base_packages purge_packages blend_packages) +## enable local apt cache +APT_CACHE=1 +aptcachedir="$LIBPATH/apt-cache" os="devuan" release="jessie" -version="1.0.0-RC2" +version="1.0.0" mirror="http://auto.mirror.devuan.org/merged" section="main" DIR diff --git a/zlibs/bootstrap b/zlibs/bootstrap t@@ -100,7 +100,6 @@ apt-get --yes --force-yes install ${core_packages} apt-get --yes --force-yes install ${base_packages} apt-get --yes --force-yes purge ${purge_packages} apt-get --yes --force-yes autoremove -apt-get clean rm -f /debconf.set rm -f /etc/ssh/ssh_host_* t@@ -174,7 +173,6 @@ done apt-get --yes --force-yes upgrade apt-get --yes --force-yes install ${extra_packages} apt-get --yes --force-yes autoremove -apt-get clean EOF chroot-script -d postunpack || zerr DIR diff --git a/zlibs/helpers b/zlibs/helpers t@@ -60,6 +60,7 @@ build_iso_dist() { iso_write_isolinux_cfg || { zerr; wrapup } #[[ $INSTALLER = 1 ]] && iso_setup_installer || zerr blend_postinst || { zerr; wrapup } + fill_apt_cache || { zerr; wrapup } iso_squash_strap || { zerr; wrapup } iso_xorriso_build || { zerr; wrapup } } t@@ -257,7 +258,6 @@ for deb in ${custom_deb_packages}; do done cd / apt-get autoremove -apt-get clean rm -rf /debs EOF chroot-script install-debs t@@ -269,6 +269,7 @@ chroot-script() { ckreq || return 1 mkdir -p "$R/log" + case "x$1" in x-d) local script="$2" t@@ -278,6 +279,7 @@ chroot-script() { ## logging sudo sed -i "$strapdir/$script" \ -e 's@#!/bin/sh@#!/bin/sh\'$'\nset -x ; exec 2>/'$script'.log@' + notice "chrooting to execute $script..." sudo chmod +x "$strapdir/$script" || zerr sudo -E chroot "$strapdir" "/$script" || zerr t@@ -288,15 +290,18 @@ chroot-script() { ;; *) local script="$1" + [[ "$APT_CACHE" = 1 ]] && { aptcache on "$strapdir/mnt" || zerr } ## logging sudo sed -i "$strapdir/$script" \ -e 's@#!/bin/sh@#!/bin/sh\'$'\nset -x ; exec 2>/'$script'.log@' notice "chrooting to execute $script..." - sudo chmod +x "$strapdir/$script" || zerr + sudo chmod +x "$strapdir/$script" || zerr sudo -E chroot "$strapdir" "/$script" || zerr sudo mv -f "$strapdir/${script}.log" "$R/log/" + + [[ "$APT_CACHE" = 1 ]] && { aptcache off "$strapdir/mnt" || zerr } ;; esac t@@ -352,6 +357,57 @@ blend_postinst() { return 0 } +aptcache() { + fn aptcache "$*" + req=(aptcachedir watdo werdo APT_CACHE) + local watdo="$1" + local werdo="$2" + ckreq || return 1 + + [[ $APT_CACHE = 1 ]] || return 0 + + case "$watdo" in + on) + act "mounting local apt cache" + sudo mount -o bind "$aptcachedir" "$werdo" || zerr + ;; + off) + act "umounting local apt cache" + sudo umount "$werdo" || zerr + ;; + esac +} + +fill_apt_cache() { + fn fill_apt_cache + req=(strapdir APT_CACHE) + ckreq || return 1 + + [[ $APT_CACHE = 1 ]] || return 0 + + notice "filling local apt cache" + + cat <<EOF | sudo tee ${strapdir}/fill-apt-cache >/dev/null +#!/bin/sh + +# NOTE: do we need apt update or does it read the remote(s)? +apt-get update +apt-get install dpkg-dev + +cp -afv /var/cache/apt/archives/*.deb /mnt +cd /mnt +dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz +cd - + +apt-get purge dpkg-dev + +sed -i -e "@deb file:/mnt@d" /etc/apt/sources.list +apt-get update + +EOF + chroot-script fill-apt-cache || zerr +} + silly() { fn silly "$@" local arg1="$1" DIR diff --git a/zlibs/iso b/zlibs/iso t@@ -33,7 +33,6 @@ iso_prepare_strap() { apt-get update apt-get --yes --force-yes install dialog live-boot live-boot-initramfs-tools apt-get --yes --force-yes autoremove -apt-get clean EOF chroot-script -d isoprep || zerr DIR diff --git a/zlibs/sysconf b/zlibs/sysconf t@@ -118,6 +118,8 @@ conf_print_sourceslist() { ckreq || return 1 cat <<EOF +deb file:/mnt ./ + ## package repositories deb ${mirror} ${release} ${section} deb ${mirror} ${release}-updates ${section}