lxc-alpine.in revision 691ac4a3397a652dc163e4014720f3c6f4836052
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo#!/bin/bash
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yookey_sha256sums="9c102bcc376af1498d549b77bdbfa815ae86faa1d2d82f040e616b18ef2df2d4 alpine-devel@lists.alpinelinux.org-4a6a0840.rsa.pub
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo2adcf7ce224f476330b5360ca5edb92fd0bf91c92d83292ed028d7c4e26333ab alpine-devel@lists.alpinelinux.org-4d07755e.rsa.pub"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yooget_static_apk () {
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo wget="wget -q -O -"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo pkglist=alpine-keys:apk-tools-static
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo auto_repo_dir=
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -z "$repository" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo url=http://wiki.alpinelinux.org/cgi-bin/dl.cgi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -z "$release" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo -n "Determining the latest release... "
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo release=$($wget $url/.latest.$apk_arch.txt | \
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo cut -d " " -f 3 | cut -d / -f 1 | uniq)
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -z "$release" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo failed
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo return 1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo $release
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo auto_repo_dir=$release/main
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo repository=$url/$auto_repo_dir
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo pkglist=$pkglist:alpine-mirrors
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo rootfs="$1"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo "Using static apk from $repository/$apk_arch"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo wget="$wget $repository/$apk_arch"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo # parse APKINDEX to find the current versions
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo static_pkgs=$($wget/APKINDEX.tar.gz | \
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo tar -Oxz APKINDEX | \
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo awk -F: -v pkglist=$pkglist '
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo BEGIN { split(pkglist,pkg) }
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo $0 != "" { f[$1] = $2 }
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo $0 == "" { for (i in pkg)
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if (pkg[i] == f["P"])
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo print(f["P"] "-" f["V"] ".apk") }')
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo [ "$static_pkgs" ] || return 1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mkdir -p "$rootfs" || return 1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo for pkg in $static_pkgs; do
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo "Downloading $pkg"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo $wget/$pkg | tar -xz -C "$rootfs"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo done
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo # clean up .apk meta files
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo rm -f "$rootfs"/.[A-Z]*
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo # verify checksum of the key
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo keyname=$(echo $rootfs/sbin/apk.static.*.pub | sed 's/.*\.SIGN\.RSA\.//')
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo checksum=$(echo "$key_sha256sums" | grep -w "$keyname")
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -z "$checksum" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo "ERROR: checksum is missing for $keyname"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo return 1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo (cd $rootfs/etc/apk/keys && echo "$checksum" | sha256sum -c -) || return 1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo # verify the static apk binary signature
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo APK=$rootfs/sbin/apk.static
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo openssl dgst -verify $rootfs/etc/apk/keys/$keyname \
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo -signature "$APK.SIGN.RSA.$keyname" "$APK" || return 1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ "$auto_repo_dir" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mirror_list=$rootfs/usr/share/alpine-mirrors/MIRRORS.txt
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mirror_count=$(wc -l $mirror_list | cut -d " " -f 1)
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo repository=$(sed $(expr $RANDOM % $mirror_count + 1)\!d \
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo $mirror_list)$auto_repo_dir
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo "Selecting mirror $repository"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo}
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yooinstall_alpine() {
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo rootfs="$1"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo shift
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mkdir -p "$rootfs"/etc/apk || return 1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo : ${keys_dir:=/etc/apk/keys}
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if ! [ -d "$rootfs"/etc/apk/keys ] && [ -d "$keys_dir" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo cp -r "$keys_dir" "$rootfs"/etc/apk/keys
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -n "$repository" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo "$repository" > "$rootfs"/etc/apk/repositories
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo else
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -n "$release" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo sed -i -e "s:/[^/]\+/\([^/]\+\)$:/$release/\1:" \
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo "$rootfs"/etc/apk/repositories
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo opt_arch=
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -n "$apk_arch" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo opt_arch="--arch $apk_arch"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo $APK add -U --initdb --root $rootfs $opt_arch "$@" alpine-base
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo}
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yooconfigure_alpine() {
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo rootfs="$1"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo "Setting up /etc/inittab"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo cat >"$rootfs"/etc/inittab<<EOF
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo::sysinit:/sbin/rc sysinit
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo::wait:/sbin/rc default
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yootty1:12345:respawn:/sbin/getty 38400 tty1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yootty2:12345:respawn:/sbin/getty 38400 tty2
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yootty3:12345:respawn:/sbin/getty 38400 tty3
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yootty4:12345:respawn:/sbin/getty 38400 tty4
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo::ctrlaltdel:/sbin/reboot
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo::shutdown:/sbin/rc shutdown
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae YooEOF
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo # set up timezone
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -f /etc/TZ ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo cp /etc/TZ "$rootfs/etc/TZ"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo # set up nameserver
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo grep nameserver /etc/resolv.conf > "$rootfs/etc/resolv.conf"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo # configure the network using the dhcp
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo cat <<EOF > $rootfs/etc/network/interfaces
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yooauto lo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yooiface lo inet loopback
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yooauto eth0
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yooiface eth0 inet dhcp
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae YooEOF
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo # set the hostname
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo $hostname > $rootfs/etc/hostname
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo # missing device nodes
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo "Setting up device nodes"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mkdir -p -m 755 "$rootfs/dev/pts"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mkdir -p -m 1777 "$rootfs/dev/shm"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mknod -m 666 "$rootfs/dev/zero" c 1 5
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mknod -m 666 "$rootfs/dev/full" c 1 7
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mknod -m 666 "$rootfs/dev/random" c 1 8
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mknod -m 666 "$rootfs/dev/urandom" c 1 9
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mknod -m 666 "$rootfs/dev/tty0" c 4 0
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo mknod -m 666 "$rootfs/dev/tty1" c 4 1
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo mknod -m 666 "$rootfs/dev/tty2" c 4 2
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo mknod -m 666 "$rootfs/dev/tty3" c 4 3
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo mknod -m 666 "$rootfs/dev/tty4" c 4 4
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo# mknod -m 600 "$rootfs/dev/initctl" p
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo mknod -m 666 "$rootfs/dev/tty" c 5 0
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo mknod -m 666 "$rootfs/dev/console" c 5 1
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo mknod -m 666 "$rootfs/dev/ptmx" c 5 2
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo # start services
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo ln -s /etc/init.d/bootmisc "$rootfs"/etc/runlevels/boot/bootmisc
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo ln -s /etc/init.d/syslog "$rootfs"/etc/runlevels/boot/syslog
2aeb28ec17b8973de3b0d52463f661985a6332d6Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo return 0
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo}
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoocopy_configuration() {
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo path=$1
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo rootfs=$2
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo hostname=$3
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo grep -q "^lxc.rootfs" $path/config 2>/dev/null \
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo || echo "lxc.rootfs = $rootfs" >> $path/config
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -n "$lxc_arch" ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo echo "lxc.arch = $lxc_arch" >> $path/config
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo lxc_network_link_line="# lxc.network.link = br0"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo for br in lxcbr0 virbr0 br0; do
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo if [ -d /sys/class/net/$br/bridge ]; then
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo lxc_network_link_line="lxc.network.link = $br"
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo break
2b371b262f7272266ff18cc2aff65176a2c16383Sungbae Yoo fi
done
if ! grep -q "^lxc.network.type" $path/config 2>/dev/null; then
cat <<EOF >> $path/config
lxc.network.type = veth
$lxc_network_link_line
lxc.network.flags = up
EOF
fi
# if there is exactly one veth or macvlan network entry, make sure
# it has an associated mac address.
nics=$(awk -F '[ \t]*=[ \t]*' \
'$1=="lxc.network.type" && ($2=="veth" || $2=="macvlan") {print $2}' \
$path/config | wc -l)
if [ "$nics" -eq 1 ] && ! grep -q "^lxc.network.hwaddr" $path/config; then
# see http://sourceforge.net/tracker/?func=detail&aid=3411497&group_id=163076&atid=826303
hwaddr="fe:$(dd if=/dev/urandom bs=8 count=1 2>/dev/null |od -t x8 | \
head -1 |awk '{print $2}' | cut -c1-10 |\
sed 's/\(..\)/\1:/g; s/.$//')"
echo "lxc.network.hwaddr = $hwaddr" >> $path/config
fi
cat <<EOF >> $path/config
lxc.tty = 4
lxc.pts = 1024
lxc.utsname = $hostname
lxc.cap.drop = sys_module mac_admin mac_override sys_time
# When using LXC with apparmor, uncomment the next line to run unconfined:
#lxc.aa_profile = unconfined
# devices
lxc.cgroup.devices.deny = a
# /dev/null, zero and full
lxc.cgroup.devices.allow = c 1:3 rwm
lxc.cgroup.devices.allow = c 1:5 rwm
lxc.cgroup.devices.allow = c 1:7 rwm
# consoles
lxc.cgroup.devices.allow = c 5:1 rwm
lxc.cgroup.devices.allow = c 5:0 rwm
lxc.cgroup.devices.allow = c 4:0 rwm
lxc.cgroup.devices.allow = c 4:1 rwm
# /dev/{,u}random
lxc.cgroup.devices.allow = c 1:9 rwm
lxc.cgroup.devices.allow = c 1:8 rwm
lxc.cgroup.devices.allow = c 136:* rwm
lxc.cgroup.devices.allow = c 5:2 rwm
# rtc
lxc.cgroup.devices.allow = c 254:0 rm
# mounts point
lxc.mount.entry=proc proc proc nodev,noexec,nosuid 0 0
lxc.mount.entry=run run tmpfs nodev,noexec,nosuid,relatime,size=1m,mode=0755 0 0
lxc.mount.entry=none dev/pts devpts gid=5,mode=620 0 0
EOF
return 0
}
die() {
echo "$@" >&2
exit 1
}
usage() {
cat >&2 <<EOF
Usage: $(basename $0) [-h|--help] [-r|--repository <url>]
[-R|--release <release>] [-a|--arch <arch>]
[--rootfs <rootfs>] -p|--path <path> -n|--name <name>
[PKG...]
EOF
}
usage_err() {
usage
exit 1
}
optarg_check() {
if [ -z "$2" ]; then
usage_err "option '$1' requires an argument"
fi
}
default_path=@LXCPATH@
release=
arch=$(uname -m)
# template mknods, requires root
if [ $(id -u) -ne 0 ]; then
echo "$(basename $0): must be run as root" >&2
exit 1
fi
while [ $# -gt 0 ]; do
opt="$1"
shift
case "$opt" in
-h|--help)
usage
exit 0
;;
-n|--name)
optarg_check $opt "$1"
name=$1
shift
;;
--rootfs)
optarg_check $opt "$1"
rootfs=$1
shift
;;
-p|--path)
optarg_check $opt "$1"
path=$1
shift
;;
-r|--repository)
optarg_check $opt "$1"
repository=$1
shift
;;
-R|--release)
optarg_check $opt "$1"
release=$1
shift
;;
-a|--arch)
optarg_check $opt "$1"
arch=$1
shift
;;
--)
break;;
--*=*)
# split --myopt=foo=bar into --myopt foo=bar
set -- ${opt%=*} ${opt#*=} "$@"
;;
-?)
usage_err "unknown option '$opt'"
;;
-*)
# split opts -abc into -a -b -c
set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
;;
esac
done
[ -z "$name" ] && usage_err
if [ -z "${path}" ]; then
path="${default_path}/${name}"
fi
if [ -z "$rootfs" ]; then
rootfs=`awk -F= '$1 ~ /^lxc.rootfs/ { print $2 }' "$path/config" 2>/dev/null`
if [ -z "$rootfs" ]; then
rootfs="${path}/rootfs"
fi
fi
lxc_arch=$arch
apk_arch=$arch
case "$arch" in
i[3-6]86)
apk_arch=x86
;;
x86)
lxc_arch=i686
;;
x86_64|"")
;;
*)
die "unsupported architecture: $arch"
;;
esac
: ${APK:=apk}
if ! which $APK >/dev/null; then
get_static_apk "$rootfs" || die "Failed to download a valid static apk"
fi
install_alpine "$rootfs" "$@" || die "Failed to install rootfs for $name"
configure_alpine "$rootfs" "$name" || die "Failed to configure $name"
copy_configuration "$path" "$rootfs" "$name"