lxc-alpine.in revision eee3ba81c88e64b8a732694fc4843a39d5bde491
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa cp -r ${keys_dir:-/etc/apk/keys} "$rootfs"/etc/apk/
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa echo "$repository" > "$rootfs"/etc/apk/repositories
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
670c6ab8caac48ce5cf043796dd8908114b7f607Natanael Copa ${APK:-apk} add -U --initdb --root $rootfs $opt_arch "$@" alpine-base
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa::sysinit:/sbin/rc sysinit
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa::wait:/sbin/rc default
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copatty1:12345:respawn:/sbin/getty 38400 tty1
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa::ctrlaltdel:/sbin/reboot
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa::shutdown:/sbin/rc shutdown
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa grep nameserver /etc/resolv.conf > "$rootfs/etc/resolv.conf"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copaiface lo inet loopback
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copaiface eth0 inet dhcp
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# mknod -m 600 "$rootfs/dev/initctl" p
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa ln -s /etc/init.d/syslog "$rootfs"/etc/runlevels/default/syslog
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa grep -q "^lxc.rootfs" $path/config 2>/dev/null \
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa || echo "lxc.rootfs = $rootfs" >> $path/config
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa lxc_network_link_line="# lxc.network.link = br0"
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa if [ -d /sys/class/net/$br/bridge ]; then
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa lxc_network_link_line="lxc.network.link = $br"
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa if ! grep -q "^lxc.network.type" $path/config 2>/dev/null; then
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copalxc.network.type = veth
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa$lxc_network_link_line
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copalxc.network.flags = up
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa # if there is exactly one veth network entry, make sure it has an
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa nics=$(grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l)
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa if [ "$nics" -eq 1 ] && ! grep -q "^lxc.network.hwaddr" $path/config; then
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa # see http://sourceforge.net/tracker/?func=detail&aid=3411497&group_id=163076&atid=826303
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa hwaddr="fe:$(dd if=/dev/urandom bs=8 count=1 2>/dev/null |od -t x8 | \
d42277f769d1bed8a4a198a49dbe96582a4fa2ecNatanael Copa echo "lxc.network.hwaddr = $hwaddr" >> $path/config
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.pts = 1024
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.utsname = $hostname
eee3ba81c88e64b8a732694fc4843a39d5bde491Serge Hallynlxc.cap.drop = sys_module mac_admin mac_override sys_time
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# When using LXC with apparmor, uncomment the next line to run unconfined:
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa#lxc.aa_profile = unconfined
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.deny = a
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# /dev/null and zero
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 1:3 rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 1:5 rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 5:1 rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 5:0 rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 4:0 rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 4:1 rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# /dev/{,u}random
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 1:9 rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 1:8 rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 136:* rwm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.cgroup.devices.allow = c 5:2 rwm
eee3ba81c88e64b8a732694fc4843a39d5bde491Serge Hallynlxc.cgroup.devices.allow = c 254:0 rm
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa# mounts point
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.mount.entry=proc proc proc nodev,noexec,nosuid 0 0
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.mount.entry=run run tmpfs nodev,noexec,nosuid,relatime,size=1m,mode=0755 0 0
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copalxc.mount.entry=none dev/pts devpts gid=5,mode=620 0 0
2b49de9a3ff182c208148d780f6b26cf8cdd09d8Natanael CopaUsage: $(basename $0) [-h|--help] [-r|--repository <url>] [-a|--arch <arch>]
670c6ab8caac48ce5cf043796dd8908114b7f607Natanael Copa -p|--path <path> -n|--name <name> [PKG...]
b1aa0624bae5a81d6f6bbc2653a388d148cffef8Natanael Copa # split --myopt=foo=bar into --myopt foo=bar
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa # split opts -abc into -a -b -c
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copa set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copaif [ -z "${path}" ]; then
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Coparootfs=`awk -F= '$1 ~ /^lxc.rootfs/ { print $2 }' "$path/config" 2>/dev/null`
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copaif [ -z "$rootfs" ]; then
670c6ab8caac48ce5cf043796dd8908114b7f607Natanael Copainstall_alpine "$rootfs" "$@" || die "Failed to install rootfs for $name"
2a9a0a08077d88ee1d70ca46ca122216f3d1c89aNatanael Copaconfigure_alpine "$rootfs" "$name" || die "Failed to configure $name"