diff --git a/arch-nspawn.in b/arch-nspawn.in index 6900382..c100b35 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -45,16 +45,29 @@ shift 1 [[ -z $working_dir ]] && die 'Please specify a working directory.' -if [[ -z $cache_dir ]]; then - cache_dirs=($(pacman -v 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g')) -else - cache_dirs=("$cache_dir") -fi - host_mirror=$(pacman -Sddp extra/devtools 2>/dev/null | sed -r 's#(.*/)extra/os/.*#\1$repo/os/$arch#') [[ $host_mirror == *file://* ]] && host_mirror_path=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g') # {{{ functions +set_cache_dir() { + if [[ -z $cache_dir && -z $pac_conf ]]; then + chroot_cache_dirs=($(sed '/^\s*CacheDir/!d;s/^\s*CacheDir\s*=\s*//g;s/\s//g' "$working_dir/etc/pacman.conf")) + system_cache_dirs=($(pacman -v 2>&1 | sed '/Cache Dirs:/!d;s/Cache Dirs:\s*//g')) + if [ "${system_cache_dirs[@]:-/var/cache/pacman/pkg/}" != "/var/cache/pacman/pkg/" -a "${chroot_cache_dirs[@]:-/var/cache/pacman/pkg/}" == "/var/cache/pacman/pkg/" ]; then + cache_dirs=("${system_cache_dirs[@]}") + elif [ "${chroot_cache_dirs[@]:-/var/cache/pacman/pkg/}" != "/var/cache/pacman/pkg/" ]; then + cache_dirs=("${chroot_cache_dirs[@]}") + else + cache_dirs=("${system_cache_dirs[@]:-/var/cache/pacman/pkg/}") + fi + elif [[ -z $cache_dirs && -n $pac_conf ]];then + cache_dirs=($(sed '/^\s*CacheDir/!d;s/^\s*CacheDir\s*=\s*//g;s/\s//g' "$pac_conf")) + else + cache_dirs=("$cache_dir") + fi + +} + build_mount_args() { declare -g mount_args=() @@ -89,6 +102,7 @@ elif [[ $(cat "$working_dir/.arch-chroot") != $CHROOT_VERSION ]]; then die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "$CHROOT_VERSION" fi +set_cache_dir build_mount_args copy_hostconf