lxc-alpine.in revision 569bee5cc3d647032573db8f72734faa9307d577
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka#!/bin/sh
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
5845ac2bb83c2d509cbcb9a869d94b793f18ccccJakub Jirutkakey_sha256sums="9c102bcc376af1498d549b77bdbfa815ae86faa1d2d82f040e616b18ef2df2d4 alpine-devel@lists.alpinelinux.org-4a6a0840.rsa.pub
5845ac2bb83c2d509cbcb9a869d94b793f18ccccJakub Jirutka2adcf7ce224f476330b5360ca5edb92fd0bf91c92d83292ed028d7c4e26333ab alpine-devel@lists.alpinelinux.org-4d07755e.rsa.pub"
5845ac2bb83c2d509cbcb9a869d94b793f18ccccJakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaget_static_apk () {
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka rootfs="$1"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka echo "Using static apk from $repository/$apk_arch"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka wget="wget -q -O - $repository/$apk_arch"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # parse APKINDEX to find the current versions
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka static_pkgs=$($wget/APKINDEX.tar.gz | \
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka tar -Oxz APKINDEX | \
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka awk -F: -v pkglist="alpine-keys:apk-tools-static" '
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka BEGIN { split(pkglist,pkg) }
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka $0 != "" { f[$1] = $2 }
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka $0 == "" { for (i in pkg)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if (pkg[i] == f["P"])
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka print(f["P"] "-" f["V"] ".apk") }')
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka [ "$static_pkgs" ] || return 1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka mkdir -p "$rootfs" || return 1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka for pkg in $static_pkgs; do
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka echo "Downloading $pkg"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka $wget/$pkg | tar -xz -C "$rootfs"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka done
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # clean up .apk meta files
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa rm -f "$rootfs"/.[A-Z]*
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # verify checksum of the key
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber keyname=$(echo $rootfs/sbin/apk.static.*.pub | sed 's/.*\.SIGN\.RSA\.//')
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber checksum=$(echo "$key_sha256sums" | grep -w "$keyname")
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if [ -z "$checksum" ]; then
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka echo "ERROR: checksum is missing for $keyname"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka return 1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka fi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka (cd $rootfs/etc/apk/keys && echo "$checksum" | sha256sum -c -) || return 1
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # verify the static apk binary signature
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka APK=$rootfs/sbin/apk.static
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka openssl dgst -verify $rootfs/etc/apk/keys/$keyname \
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copa -signature "$APK.SIGN.RSA.$keyname" "$APK" || return 1
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copa}
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copa
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copainstall_alpine() {
6460d3c5f006d6cdae72e5c01e3a844986d20ff7Natanael Copa rootfs="$1"
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka shift
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka mkdir -p "$rootfs"/etc/apk || return 1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka : ${keys_dir:=/etc/apk/keys}
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if ! [ -d "$rootfs"/etc/apk/keys ] && [ -d "$keys_dir" ]; then
5845ac2bb83c2d509cbcb9a869d94b793f18ccccJakub Jirutka cp -r "$keys_dir" "$rootfs"/etc/apk/keys
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka fi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if [ -n "$repository" ]; then
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka echo "$repository" > "$rootfs"/etc/apk/repositories
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka else
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka fi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka opt_arch=
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if [ -n "$apk_arch" ]; then
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka opt_arch="--arch $apk_arch"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka fi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka $APK add -U --initdb --root $rootfs $opt_arch "$@" alpine-base
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka}
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaconfigure_alpine() {
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka rootfs="$1"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka echo "Setting up /etc/inittab"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka cat >"$rootfs"/etc/inittab<<EOF
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutka::sysinit:/sbin/rc sysinit
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutka::wait:/sbin/rc default
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutkatty1:12345:respawn:/sbin/getty 38400 tty1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka::ctrlaltdel:/sbin/reboot
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka::shutdown:/sbin/rc shutdown
6515faa115664909351ac241763bcb374ff62608Jakub JirutkaEOF
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # set up nameserver
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka grep nameserver /etc/resolv.conf > "$rootfs/etc/resolv.conf"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # configure the network using the dhcp
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # note that lxc will set up lo interface
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka cat <<EOF > $rootfs/etc/network/interfaces
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka#auto lo
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaiface lo inet loopback
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaauto eth0
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaiface eth0 inet dhcp
6515faa115664909351ac241763bcb374ff62608Jakub JirutkaEOF
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # set the hostname
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka echo $hostname > $rootfs/etc/hostname
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # missing device nodes
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa echo "Setting up device nodes"
569bee5cc3d647032573db8f72734faa9307d577Natanael Copa mkdir -p -m 755 "$rootfs/dev/pts"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka mkdir -p -m 1777 "$rootfs/dev/shm"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka mknod -m 666 "$rootfs/dev/full" c 1 7
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka mknod -m 666 "$rootfs/dev/random" c 1 8
5845ac2bb83c2d509cbcb9a869d94b793f18ccccJakub Jirutka mknod -m 666 "$rootfs/dev/urandom" c 1 9
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka mknod -m 666 "$rootfs/dev/tty0" c 4 0
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa mknod -m 666 "$rootfs/dev/tty1" c 4 1
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa mknod -m 666 "$rootfs/dev/tty2" c 4 2
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka mknod -m 666 "$rootfs/dev/tty3" c 4 3
5845ac2bb83c2d509cbcb9a869d94b793f18ccccJakub Jirutka mknod -m 666 "$rootfs/dev/tty4" c 4 4
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka# mknod -m 600 "$rootfs/dev/initctl" p
691ac4a3397a652dc163e4014720f3c6f4836052Kaarle Ritvanen mknod -m 666 "$rootfs/dev/tty" c 5 0
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka mknod -m 666 "$rootfs/dev/console" c 5 1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka mknod -m 666 "$rootfs/dev/ptmx" c 5 2
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # start services
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka ln -s /etc/init.d/syslog "$rootfs"/etc/runlevels/default/syslog
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka return 0
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa}
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkacopy_configuration() {
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka path=$1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka rootfs=$2
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka hostname=$3
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka grep -q "^lxc.rootfs" $path/config 2>/dev/null \
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa || echo "lxc.rootfs = $rootfs" >> $path/config
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if [ -n "$lxc_arch" ]; then
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka echo "lxc.arch = $lxc_arch" >> $path/config
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka fi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
ff48886e1d46d86ee8b16ef38672bd4368474706Carlo Landmeter lxc_network_link_line="# lxc.network.link = br0"
ff48886e1d46d86ee8b16ef38672bd4368474706Carlo Landmeter for br in lxcbr0 virbr0 br0; do
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if [ -d /sys/class/net/$br/bridge ]; then
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka lxc_network_link_line="lxc.network.link = $br"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka break
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka fi
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa done
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka if ! grep -q "^lxc.network.type" $path/config 2>/dev/null; then
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka cat <<EOF >> $path/config
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.network.type = veth
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa$lxc_network_link_line
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.network.flags = up
6515faa115664909351ac241763bcb374ff62608Jakub JirutkaEOF
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka fi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # if there is exactly one veth network entry, make sure it has an
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # associated mac address.
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa nics=$(grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if [ "$nics" -eq 1 ] && ! grep -q "^lxc.network.hwaddr" $path/config; then
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # see http://sourceforge.net/tracker/?func=detail&aid=3411497&group_id=163076&atid=826303
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka hwaddr="fe:$(dd if=/dev/urandom bs=8 count=1 2>/dev/null |od -t x8 | \
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka head -1 |awk '{print $2}' | cut -c1-10 |\
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka sed 's/\(..\)/\1:/g; s/.$//')"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka echo "lxc.network.hwaddr = $hwaddr" >> $path/config
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka fi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka cat <<EOF >> $path/config
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.tty = 4
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.pts = 1024
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.utsname = $hostname
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cap.drop = sys_module mac_admin mac_override sys_time
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka# When using LXC with apparmor, uncomment the next line to run unconfined:
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka#lxc.aa_profile = unconfined
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka# devices
5845ac2bb83c2d509cbcb9a869d94b793f18ccccJakub Jirutkalxc.cgroup.devices.deny = a
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka# /dev/null and zero
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 1:3 rwm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 1:5 rwm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka# consoles
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 5:1 rwm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 5:0 rwm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 4:0 rwm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 4:1 rwm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka# /dev/{,u}random
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 1:9 rwm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 1:8 rwm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 136:* rwm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.cgroup.devices.allow = c 5:2 rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# rtc
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 254:0 rm
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka# mounts point
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.mount.entry=proc proc proc nodev,noexec,nosuid 0 0
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.mount.entry=run run tmpfs nodev,noexec,nosuid,relatime,size=1m,mode=0755 0 0
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc.mount.entry=none dev/pts devpts gid=5,mode=620 0 0
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub JirutkaEOF
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka return 0
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka}
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkadie() {
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka echo "$@" >&2
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka exit 1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka}
5845ac2bb83c2d509cbcb9a869d94b793f18ccccJakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkausage() {
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka cat >&2 <<EOF
6515faa115664909351ac241763bcb374ff62608Jakub JirutkaUsage: $(basename $0) [-h|--help] [-r|--repository <url>] [-a|--arch <arch>]
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka [--rootfs <rootfs>] -p|--path <path> -n|--name <name>
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka [PKG...]
6515faa115664909351ac241763bcb374ff62608Jakub JirutkaEOF
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka}
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkausage_err() {
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka usage
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka exit 1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka}
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaoptarg_check() {
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if [ -z "$2" ]; then
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka usage_err "option '$1' requires an argument"
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka fi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka}
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkadefault_path=@LXCPATH@
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaarch=$(uname -m)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkawhile [ $# -gt 0 ]; do
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka opt="$1"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka shift
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka case "$opt" in
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka -h|--help)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka usage
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka exit 0
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka ;;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka -n|--name)
04fa4e125397e022d99cd8448b221caef3c92452Jakub Jirutka optarg_check $opt "$1"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka name=$1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka shift
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka ;;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka --rootfs)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka optarg_check $opt "$1"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka rootfs=$1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka shift
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka ;;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka -p|--path)
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutka optarg_check $opt "$1"
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka path=$1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka shift
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka ;;
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka -r|--repository)
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka optarg_check $opt "$1"
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka repository=$1
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka shift
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka ;;
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka -a|--arch)
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka optarg_check $opt "$1"
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka arch=$1
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka shift
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka ;;
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka --)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka break;;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka --*=*)
d8953e37edd4128fb0edc3165f98b61e78d245f4roedie # split --myopt=foo=bar into --myopt foo=bar
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka set -- ${opt%=*} ${opt#*=} "$@"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka ;;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka -?)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka usage_err "unknown option '$opt'"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka ;;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka -*)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka # split opts -abc into -a -b -c
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka ;;
20f39db782ec0d2197cf3a81e6038fb908159ef6Jakub Jirutka esac
5845ac2bb83c2d509cbcb9a869d94b793f18ccccJakub Jirutkadone
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutka[ -z "$name" ] && usage_err
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutka
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutkaif [ -z "${path}" ]; then
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutka path="${default_path}/${name}"
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutkafi
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutka
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutkaif [ -z "$rootfs" ]; then
1125e053fb0dbaad73437ed02e435f36e766fc2bJakub Jirutka rootfs=`awk -F= '$1 ~ /^lxc.rootfs/ { print $2 }' "$path/config" 2>/dev/null`
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka if [ -z "$rootfs" ]; then
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka rootfs="${path}/rootfs"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka fi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkafi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkalxc_arch=$arch
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaapk_arch=$arch
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkacase "$arch" in
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka i[3-6]86)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka apk_arch=x86;;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka x86)
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka lxc_arch=i686;;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka x86_64|"") ;;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka *) die "unsupported architecture: $arch";;
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaesac
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka: ${APK:=apk}
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaif ! which $APK >/dev/null; then
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka get_static_apk "$rootfs" || die "Failed to download a valid static apk"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkafi
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkainstall_alpine "$rootfs" "$@" || die "Failed to install rootfs for $name"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkaconfigure_alpine "$rootfs" "$name" || die "Failed to configure $name"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutkacopy_configuration "$path" "$rootfs" "$name"
6515faa115664909351ac241763bcb374ff62608Jakub Jirutka