]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxc-archlinux: support different architectures
authorJohn Lane <john@lane.uk.net>
Thu, 12 Dec 2013 11:26:19 +0000 (11:26 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 14 Jan 2014 22:22:38 +0000 (17:22 -0500)
Signed-off-by: John Lane <john@lane.uk.net>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
templates/lxc-archlinux.in [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index d220a1d..3d50981
@@ -166,10 +166,32 @@ EOF
 
 # 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
 }
@@ -185,6 +207,7 @@ Optional args:
   -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
@@ -192,7 +215,7 @@ EOF
     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
@@ -208,6 +231,7 @@ do
     --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 ;;