diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2013-02-13 13:48:16 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2013-02-13 13:48:16 +0000 |
commit | 9a0f772cccb6c79c35fdb85551f353cec8015eea (patch) | |
tree | 80fb92e675bd897a2183cdd6da603a002a01014d | |
parent | e1d45827504c8e215a3869aa1ab9b900d310dd30 (diff) | |
download | aports-9a0f772cccb6c79c35fdb85551f353cec8015eea.tar.bz2 aports-9a0f772cccb6c79c35fdb85551f353cec8015eea.tar.xz |
main/lxc: misc fixes for lxc-alpine template
-rw-r--r-- | main/lxc/APKBUILD | 8 | ||||
-rwxr-xr-x | main/lxc/lxc-alpine | 107 |
2 files changed, 82 insertions, 33 deletions
diff --git a/main/lxc/APKBUILD b/main/lxc/APKBUILD index ec2c576ef0..65ca9da86e 100644 --- a/main/lxc/APKBUILD +++ b/main/lxc/APKBUILD @@ -3,7 +3,7 @@ pkgname=lxc pkgver=0.8.0 _mypkgver=${pkgver/_rc/-rc} -pkgrel=6 +pkgrel=7 pkgdesc="linux containers - tools" url="http://lxc.sourceforge.net/" arch="all" @@ -65,7 +65,7 @@ c3f11f58e97ead80c855c88d6999ad65 bb-shutdown.patch f3c6998798b13425b8d0647bad0834a8 lxc.initd 45d0f604310e58a1359f1745a4739843 setup-lxc-template c3f7fd7e85d40c4a4b1b427048ff9652 setup-lxc-guest -8dd4bc67ff8eda641804671df5796622 lxc-alpine" +0bafb693507f965c21f78f28da13f27b lxc-alpine" sha256sums="eac833730b94e423d4bef6834bc4a716437d2abd6ab8b24334c506aaaa08692c lxc-0.8.0.tar.gz e25b074eb09fdb471a2a816ab88df2f247f61ae8208a42044eaf91d1d5cc2fcc bb-rm.patch 0c3d8b40db692993b5d20dc9e6d6174579af8a2304e8f895bc5bce94eab4d6df 0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch @@ -74,7 +74,7 @@ d4434b6c36578bffe24d477896a2d4b284c57b9b67214a3cd826d6af2f5d1e53 bb-find.patch 77c64e6137457be89c150b82d681a3eb5c7c1f06af142a321703fc9a43bff200 lxc.initd e027a75881d720f705c5b844b80b815de0db78df9deafde36dedb1e079d6387a setup-lxc-template 7a2aa24263efd925f90f4e7c3277f9f195465f121ff9557ae0c3408a5f95b328 setup-lxc-guest -198b5a20952e7ef233f2b464e132a16a8d4bc314adb867479cc1c96fe382263f lxc-alpine" +5993758b7723000368ee6987d3c6bfee28920667d860350d3db3ed90117370a4 lxc-alpine" sha512sums="47333e2010d0f4488b8876ba933f2d26304874bec0371a7ab3b6e5bd1a50a7d2312ff8507e273f1ee2341a7f2e3b79cd71e5e19ac31006a4e429ee96b01733f6 lxc-0.8.0.tar.gz fd6c34a8775832b42e4b0a9f1e294a1bb54ecc6117277f8f02c1a24e4fc956480fe652aa889d0edf7d50fc1f36db3b7bca21d87a0365ab7b8763a20b0879806c bb-rm.patch f097d17eb306c25790fb4acfe48e3af86cca40c9250a94cbe5012321d0f07019fc5af0b31443352d0d458c9bfef7e05707263b381911a97285eeab49098176f0 0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch @@ -83,4 +83,4 @@ b011d16a19cf3efd64aaf8f9ecba8f78320d8a57bb8fbb28d2a1787a2936b30b5d21d5c1581cd6a9 4e56f7b869345f936df54c4359abdd3b8d0244c0fd71a9a787bc2393c4caabca22ca8417f16da47f02c86294750986fd674d0d2e7c1b1d096076873b22c07a29 lxc.initd d9c4d20cc4e07b7bf53361c7ea51043c578faef09a8ed588e77362ce2f7d531348300a190d22f3787f41ed8bea24d1734c00a5a7143791a49451dde88b06d51b setup-lxc-template a3fa846878f9fb897a607a20ae6847c067dc651eaf8c3d8a75ecee1057638226591825723c7fe7ad38a6647c158b870101d72c660e8bebedbdc1fa95a1c5cf5c setup-lxc-guest -60a039369dc0e6d18b6495e4df7276dcfcbba6d65df28281e0a51a1cde18398f7622a4f88b1cf55c86297dc775fd447038a26defc7d29693f2e7ff2369fd45d1 lxc-alpine" +304721a7b720a41be1884c9f96f881ff9ccc07737c45a2e2b3a3ec5fcd5f991109911051ca021d60b697f31f0da8ef23a83d6c1233f3ad292a1b0b257c864197 lxc-alpine" diff --git a/main/lxc/lxc-alpine b/main/lxc/lxc-alpine index 96eb53d39c..3c2db7cd79 100755 --- a/main/lxc/lxc-alpine +++ b/main/lxc/lxc-alpine @@ -2,6 +2,7 @@ install_alpine() { rootfs="$1" + shift mkdir -p "$rootfs"/etc/apk || return 1 cp -r ${keys_dir:-/etc/apk/keys} "$rootfs"/etc/apk/ if [ -n "$repository" ]; then @@ -9,7 +10,11 @@ install_alpine() { else cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1 fi - ${APK:-apk} add -U --initdb --root $rootfs alpine-base + opt_arch= + if [ -n "$apk_arch" ]; then + opt_arch="--arch $apk_arch" + fi + ${APK:-apk} add -U --initdb --root $rootfs $opt_arch "$@" alpine-base } configure_alpine() { @@ -68,7 +73,39 @@ copy_configuration() { grep -q "^lxc.rootfs" $path/config 2>/dev/null \ || echo "lxc.rootfs = $rootfs" >> $path/config + if [ -n "$lxc_arch" ]; then + echo "lxc.arch = $lxc_arch" >> $path/config + fi + + lxc_network_link_line="# lxc.network.link = br0" + for br in lxcbr0 virbr0 br0; do + if [ -d /sys/class/net/$br/bridge ]; then + lxc_network_link_line="lxc.network.link = $br" + break + 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 network entry, make sure it has an + # associated mac address. + nics=$(grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $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 @@ -76,15 +113,6 @@ lxc.utsname = $hostname # When using LXC with apparmor, uncomment the next line to run unconfined: #lxc.aa_profile = unconfined -# network interface -#lxc.network.name = eth0 -lxc.network.type = veth -lxc.network.flags = up -# enable for bridging -#lxc.network.link = br0 -#lxc.network.ipv4 = n.n.n.n -#lxc.network.ipv4.gateway = auto - # devices lxc.cgroup.devices.deny = a # /dev/null and zero @@ -119,7 +147,10 @@ die() { } usage() { - echo "Usage: $(basename $0) [-h|--help] -p|--path <path> -n|--name <name>" >&2 + cat >&2 <<EOF +Usage: $(basename $0) [-h|--help] [-r|--repository <url>] [-a|--arch <arch>] + -p|--path <path> -n|--name <name> [PKG...] +EOF } usage_err() { @@ -136,41 +167,47 @@ optarg_check() { default_path=/var/lib/lxc while [ $# -gt 0 ]; do - opt="$1" - shift - case "$opt" in - -h|--help) + opt="$1" + shift + case "$opt" in + -h|--help) usage exit 0 ;; - -n|--name) + -n|--name) optarg_check $opt "$1" name=$1 shift ;; - -p|--path) + -p|--path) optarg_check $opt "$1" path=$1 shift ;; - --) + -r|--repository) + optarg_check $opt "$1" + repository=$1 + shift + ;; + -a|--arch) + optarg_check $opt "$1" + arch=$1 + shift + ;; + --) break;; - --*=*) - # split --myopt=foo=bar into --myopt foo=bar - set -- ${opt%=*} ${opt#*=} "$@" + --*=*) + # 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') "$@" ;; - *) - usage - exit 1 - ;; - esac + esac done @@ -185,6 +222,18 @@ if [ -z "$rootfs" ]; then rootfs="${path}/rootfs" fi -install_alpine "$rootfs" || die "Failed to install rootfs for $name" +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 + +install_alpine "$rootfs" "$@" || die "Failed to install rootfs for $name" configure_alpine "$rootfs" "$name" || die "Failed to configure $name" copy_configuration "$path" "$rootfs" "$name" |