# install packages within container chroot
install_arch() {
+ [ "${arch}" != "$(uname -m)" ] && different_arch=true
+
+ if [ "${different_arch}" = "true" ]; then
+ container_pacman_config=$(mktemp)
+ container_mirrorlist=$(mktemp)
+ sed -e "s:Architecture =.*:Architecture = ${arch}:g" \
+ -e "s:/etc/pacman.d/mirrorlist:${container_mirrorlist}:g" \
+ "${pacman_config}" > "${container_pacman_config}"
+ sed -e "s:\(x86_64\|\$arch\):${arch}:g" \
+ /etc/pacman.d/mirrorlist > "${container_mirrorlist}"
+
+ pacman_config="${container_pacman_config}"
+ fi
+
if ! pacstrap -dcC "${pacman_config}" "${rootfs_path}" ${base_packages[@]}; then
echo "Failed to install container packages"
return 1
fi
+
+ if [ "${different_arch}" = "true" ]; then
+ sed -i -e "s:Architecture =.*:Architecture = ${arch}:g" \
+ "${rootfs_path}"/etc/pacman.conf
+ cp "${container_mirrorlist}" "${rootfs_path}"/etc/pacman.d/mirrorlist
+ rm "${container_pacman_config}" "${container_mirrorlist}"
+ fi
+
[ -d "${rootfs_path}/lib/modules" ] && ldconfig -r "${rootfs_path}"
return 0
}
-p,--path path to where the container rootfs will be created, defaults to ${default_path}/rootfs. The container config will go under ${default_path} in that case
-P,--packages preinstall additional packages, comma-separated list
-c,--config use specified pacman config when installing container packages
+ -a,--arch use specified architecture instead of host's architecture
-t,--network_type set container network interface type (${lxc_network_type})
-l,--network_link set network link device (${lxc_network_link})
-h,--help print this help
return 0
}
-options=$(getopt -o hp:P:n:c:l:t: -l help,rootfs:,path:,packages:,name:,config:,network_type:,network_link: -- "${@}")
+options=$(getopt -o hp:P:n:c:a:l:t: -l help,rootfs:,path:,packages:,name:,config:,arch:,network_type:,network_link: -- "${@}")
if [ ${?} -ne 0 ]; then
usage $(basename ${0})
exit 1
--rootfs) rootfs_path=${2}; shift 2;;
-P|--packages) additional_packages=${2}; shift 2;;
-c|--config) pacman_config=${2}; shift 2;;
+ -a|--arch) arch=${2}; shift 2;;
-t|--network_type) lxc_network_type=${2}; shift 2;;
-l|--network_link) lxc_network_link=${2}; shift 2;;
--) shift 1; break ;;