From 87f5eb6300d07541a20cd590b3308c233ab027d7 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Tue, 17 Aug 2010 19:23:16 +0200 Subject: Use host mirror in chroot environment * Set first enabled mirror found mirrorlist as mirror within the chroot. * If the mirror is local bind its directory read-only into the chroot. * Fallback is the kernel.org mirror. --- mkarchroot | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'mkarchroot') diff --git a/mkarchroot b/mkarchroot index b7249a4..fcb65db 100755 --- a/mkarchroot +++ b/mkarchroot @@ -72,6 +72,16 @@ if [ -z "$cache_dir" ]; then unset cache_conf fi +if [ -f /etc/pacman.d/mirrorlist ]; then + host_mirror=$(grep -v '^#' -m1 /etc/pacman.d/mirrorlist | sed -E 's#/os/(i686|x86_64)#/os/\$arch#g') +fi +if [ -z "${host_mirror}" ]; then + host_mirror='Server = http://mirrors.kernel.org/archlinux/$repo/os/$arch' +fi +if echo "${host_mirror}" | grep -q 'file://'; then + host_mirror_path=$(echo "${host_mirror}" | sed -E 's#Server\s=\sfile://(/.*)/\$repo/os/(\$arch|i686|x86_64)#\1#g') +fi + # {{{ functions chroot_mount() { @@ -94,12 +104,19 @@ chroot_mount() { [ -e "${working_dir}/${cache_dir}" ] || mkdir -p "${working_dir}/${cache_dir}" mount -o bind "${cache_dir}" "${working_dir}/${cache_dir}" + if [ -n "${host_mirror_path}" ]; then + [ -e "${working_dir}/${host_mirror_path}" ] || mkdir -p "${working_dir}/${host_mirror_path}" + mount -o bind "${host_mirror_path}" "${working_dir}/${host_mirror_path}" + mount -o remount,ro,bind "${host_mirror_path}" "${working_dir}/${host_mirror_path}" + fi + trap 'chroot_umount' 0 1 2 15 } copy_hostconf () { cp /etc/mtab "${working_dir}/etc/mtab" cp /etc/resolv.conf "${working_dir}/etc/resolv.conf" + echo "${host_mirror}" > ${working_dir}/etc/pacman.d/mirrorlist } chroot_umount () { @@ -109,6 +126,7 @@ chroot_umount () { umount "${working_dir}/dev/shm" umount "${working_dir}/dev" umount "${working_dir}/${cache_dir}" + [ -n "${host_mirror_path}" ] && umount "${working_dir}/${host_mirror_path}" } # }}} -- cgit v1.2.3-70-g09d2