diff --git a/alpine-make-vm-image b/alpine-make-vm-image index 239b96a..0445b35 100755 --- a/alpine-make-vm-image +++ b/alpine-make-vm-image @@ -290,6 +290,10 @@ prepare_chroot() { mount_bind /dev "$dest"/dev mount_bind /sys "$dest"/sys + if [ -n "$apk_cache_dir" ]; then + mount_bind "$apk_cache_dir" "$dest/$apk_cache_dir" + fi + install -D -m 644 /etc/resolv.conf "$dest"/etc/resolv.conf echo "$RESOLVCONF_MARK" >> "$dest"/etc/resolv.conf } @@ -592,8 +596,10 @@ else fi # Use APK cache if available. +apk_cache_dir= if [ -L /etc/apk/cache ]; then - ln -s "$(realpath /etc/apk/cache)" etc/apk/cache + apk_cache_dir="$(realpath /etc/apk/cache)" + ln -s "$apk_cache_dir" etc/apk/cache fi _apk add --root . ${ARCH:+--arch "$ARCH"} --update-cache --initdb alpine-base @@ -696,11 +702,6 @@ if [ "$PACKAGES" ]; then _apk add --root . $PACKAGES fi -#----------------------------------------------------------------------- -if [ -L /etc/apk/cache ]; then - rm etc/apk/cache >/dev/null 2>&1 -fi - #----------------------------------------------------------------------- if [ "$FS_SKEL_DIR" ]; then einfo "Copying content of $FS_SKEL_DIR into image" @@ -738,7 +739,14 @@ if grep -qw "$RESOLVCONF_MARK" etc/resolv.conf 2>/dev/null; then EOF fi -rm -Rf var/cache/apk/* ||: +if [ -n "$apk_cache_dir" ]; then + # remove symlink and dir created by bind mount + rm etc/apk/cache >/dev/null ||: + umount $mount_dir/$apk_cache_dir ||: + rm $mount_dir/$apk_cache_dir ||: +else + rm -Rf var/cache/apk/* ||: +fi einfo 'Completed'