aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2013-04-15 07:51:11 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2013-04-15 07:51:11 +0000
commit52144f7f3d47d0c88bdf25eaf7e831bf8ecd4223 (patch)
tree1f6af829b2b4af25e20539f553f8a140911929ba /main
parent3cd85e98dcec98821e9c0d5c28f33f3ed2633db2 (diff)
downloadaports-52144f7f3d47d0c88bdf25eaf7e831bf8ecd4223.tar.bz2
aports-52144f7f3d47d0c88bdf25eaf7e831bf8ecd4223.tar.xz
main/lxc: upgrade to 0.9.0
Diffstat (limited to 'main')
-rw-r--r--main/lxc/0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch142
-rw-r--r--main/lxc/APKBUILD53
-rw-r--r--main/lxc/bb-find.patch11
-rw-r--r--main/lxc/bb-rm.patch23
-rw-r--r--main/lxc/bb-shutdown.patch12
-rwxr-xr-xmain/lxc/lxc-alpine239
-rwxr-xr-xmain/lxc/setup-lxc-guest282
-rwxr-xr-xmain/lxc/setup-lxc-template44
8 files changed, 31 insertions, 775 deletions
diff --git a/main/lxc/0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch b/main/lxc/0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch
deleted file mode 100644
index 50e6cccf1c..0000000000
--- a/main/lxc/0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch
+++ /dev/null
@@ -1,142 +0,0 @@
-From 3f3c1b2ad94338ba974477f53b2ee6f462aa77ae Mon Sep 17 00:00:00 2001
-From: Natanael Copa <ncopa@alpinelinux.org>
-Date: Tue, 13 Nov 2012 13:48:57 +0100
-Subject: [PATCH] lxc-start: add option -p, --pidfile=FILE for use with
- --daemon
-
-Add option to create a pidfile for lxc-start daemon. This is helpful
-for init scripts and process monitors.
-
-Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
----
- doc/lxc-start.sgml.in | 12 ++++++++++++
- src/lxc/arguments.h | 1 +
- src/lxc/lxc_start.c | 24 ++++++++++++++++++++++++
- 3 files changed, 37 insertions(+)
-
-diff --git a/doc/lxc-start.sgml.in b/doc/lxc-start.sgml.in
-index 2b6778f..bd875d6 100644
---- a/doc/lxc-start.sgml.in
-+++ b/doc/lxc-start.sgml.in
-@@ -53,6 +53,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- <arg choice="opt">-f <replaceable>config_file</replaceable></arg>
- <arg choice="opt">-c <replaceable>console_file</replaceable></arg>
- <arg choice="opt">-d</arg>
-+ <arg choice="opt">-p <replaceable>pid_file</replaceable></arg>
- <arg choice="opt">-s KEY=VAL</arg>
- <arg choice="opt">-C</arg>
- <arg choice="opt">command</arg>
-@@ -109,6 +110,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- <varlistentry>
- <term>
-+ <option>-p, --pidfile <replaceable>pid_file</replaceable></option>
-+ </term>
-+ <listitem>
-+ <para>
-+ Create a pidfile when running as daemon.
-+ </para>
-+ </listitem>
-+ </varlistentry>
-+
-+ <varlistentry>
-+ <term>
- <option>-f, --rcfile <replaceable>config_file</replaceable></option>
- </term>
- <listitem>
-diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h
-index 40f0d6c..789ccd9 100644
---- a/src/lxc/arguments.h
-+++ b/src/lxc/arguments.h
-@@ -45,6 +45,7 @@ struct lxc_arguments {
- int daemonize;
- const char *rcfile;
- const char *console;
-+ const char *pidfile;
-
- /* for lxc-checkpoint/restart */
- const char *statefile;
-diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
-index 81a5774..a031ee1 100644
---- a/src/lxc/lxc_start.c
-+++ b/src/lxc/lxc_start.c
-@@ -62,6 +62,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
- case 'f': args->rcfile = arg; break;
- case 'C': args->close_all_fds = 1; break;
- case 's': return lxc_config_define_add(&defines, arg);
-+ case 'p': args->pidfile = arg; break;
- }
- return 0;
- }
-@@ -72,6 +73,7 @@ static const struct option my_longopts[] = {
- {"define", required_argument, 0, 's'},
- {"console", required_argument, 0, 'c'},
- {"close-all-fds", no_argument, 0, 'C'},
-+ {"pidfile", required_argument, 0, 'p'},
- LXC_COMMON_OPTIONS
- };
-
-@@ -85,6 +87,7 @@ lxc-start start COMMAND in specified container NAME\n\
- Options :\n\
- -n, --name=NAME NAME for name of the container\n\
- -d, --daemon daemonize the container\n\
-+ -p, --pidfile=FILE Create pidfile when daemonized\n\
- -f, --rcfile=FILE Load configuration file FILE\n\
- -c, --console=FILE Set the file output for the container console\n\
- -C, --close-all-fds If any fds are inherited, close them\n\
-@@ -95,6 +98,7 @@ Options :\n\
- .parser = my_parser,
- .checker = NULL,
- .daemonize = 0,
-+ .pidfile = NULL,
- };
-
- int main(int argc, char *argv[])
-@@ -200,6 +204,7 @@ int main(int argc, char *argv[])
- }
-
- if (my_args.daemonize) {
-+ FILE *pid_fp;
- /* do an early check for needed privs, since otherwise the
- * user won't see the error */
-
-@@ -208,10 +213,26 @@ int main(int argc, char *argv[])
- return err;
- }
-
-+ if (my_args.pidfile != NULL) {
-+ pid_fp = fopen(my_args.pidfile, "w");
-+ if (pid_fp == NULL) {
-+ SYSERROR("failed to create '%s'", my_args.name);
-+ return err;
-+ }
-+ }
-+
- if (daemon(0, 0)) {
- SYSERROR("failed to daemonize '%s'", my_args.name);
- return err;
- }
-+
-+ if (my_args.pidfile != NULL) {
-+ if (fprintf(pid_fp, "%d\n", getpid()) < 0) {
-+ SYSERROR("failed to write '%s'", my_args.pidfile);
-+ return err;
-+ }
-+ fclose(pid_fp);
-+ }
- }
-
- if (my_args.close_all_fds)
-@@ -230,6 +251,9 @@ int main(int argc, char *argv[])
- err = -1;
- }
-
-+ if (my_args.daemonize && my_args.pidfile)
-+ unlink(my_args.pidfile);
-+
- return err;
- }
-
---
-1.8.0
-
diff --git a/main/lxc/APKBUILD b/main/lxc/APKBUILD
index 65ca9da86e..054fbe2c82 100644
--- a/main/lxc/APKBUILD
+++ b/main/lxc/APKBUILD
@@ -1,9 +1,9 @@
# Contributor: William Pitcock <nenolod@dereferenced.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lxc
-pkgver=0.8.0
+pkgver=0.9.0
_mypkgver=${pkgver/_rc/-rc}
-pkgrel=7
+pkgrel=0
pkgdesc="linux containers - tools"
url="http://lxc.sourceforge.net/"
arch="all"
@@ -15,13 +15,8 @@ install=""
subpackages="$pkgname-dev $pkgname-doc"
source="http://lxc.sourceforge.net/download/lxc/$pkgname-$_mypkgver.tar.gz
bb-rm.patch
- 0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch
bb-shutdown.patch
- bb-find.patch
lxc.initd
- setup-lxc-template
- setup-lxc-guest
- lxc-alpine
"
_builddir="${srcdir}/${pkgname}-${_mypkgver}"
@@ -49,38 +44,18 @@ package() {
cd "$_builddir"
make DESTDIR="$pkgdir" install || return 1
install -d "$pkgdir"/var/lib/lxc
- install -Dm755 "$srcdir"/lxc-alpine \
- "$pkgdir"/usr/share/lxc/templates/lxc-alpine || return 1
install -Dm755 "$srcdir"/lxc.initd "$pkgdir"/etc/init.d/lxc
- install -Dm755 "$srcdir"/setup-lxc-template \
- "$pkgdir"/usr/bin/setup-lxc-template
- install -Dm755 "$srcdir"/setup-lxc-guest "$pkgdir"/usr/bin/setup-lxc-guest
}
-md5sums="7304fa57146ce687f749b5df876bb20d lxc-0.8.0.tar.gz
-f0f675456a1751aded10aa428bda9e16 bb-rm.patch
-1bf081cd9d66c65f3611ed4af58ef48f 0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch
-c3f11f58e97ead80c855c88d6999ad65 bb-shutdown.patch
-6a1a27c473274d422ec27364bd3580c3 bb-find.patch
-f3c6998798b13425b8d0647bad0834a8 lxc.initd
-45d0f604310e58a1359f1745a4739843 setup-lxc-template
-c3f7fd7e85d40c4a4b1b427048ff9652 setup-lxc-guest
-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
-4847e4395a72737a6f94d2a1d835e246a7fb6925a961fa82022dd62358b34ecb bb-shutdown.patch
-d4434b6c36578bffe24d477896a2d4b284c57b9b67214a3cd826d6af2f5d1e53 bb-find.patch
-77c64e6137457be89c150b82d681a3eb5c7c1f06af142a321703fc9a43bff200 lxc.initd
-e027a75881d720f705c5b844b80b815de0db78df9deafde36dedb1e079d6387a setup-lxc-template
-7a2aa24263efd925f90f4e7c3277f9f195465f121ff9557ae0c3408a5f95b328 setup-lxc-guest
-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
-bfd6aa6c02396115dd603f1ec93aae0cd8378e9d249adfa5ac543448f94f05452df00ef749ffc2264c2f6c16b4b32a9cfb3d5de67b70c364d641159261b7dd7f bb-shutdown.patch
-b011d16a19cf3efd64aaf8f9ecba8f78320d8a57bb8fbb28d2a1787a2936b30b5d21d5c1581cd6a98422d2a0666788f7228d4fa285c3dcbfac0de739718f016f bb-find.patch
-4e56f7b869345f936df54c4359abdd3b8d0244c0fd71a9a787bc2393c4caabca22ca8417f16da47f02c86294750986fd674d0d2e7c1b1d096076873b22c07a29 lxc.initd
-d9c4d20cc4e07b7bf53361c7ea51043c578faef09a8ed588e77362ce2f7d531348300a190d22f3787f41ed8bea24d1734c00a5a7143791a49451dde88b06d51b setup-lxc-template
-a3fa846878f9fb897a607a20ae6847c067dc651eaf8c3d8a75ecee1057638226591825723c7fe7ad38a6647c158b870101d72c660e8bebedbdc1fa95a1c5cf5c setup-lxc-guest
-304721a7b720a41be1884c9f96f881ff9ccc07737c45a2e2b3a3ec5fcd5f991109911051ca021d60b697f31f0da8ef23a83d6c1233f3ad292a1b0b257c864197 lxc-alpine"
+md5sums="8552a4479090616f4bc04d8473765fc9 lxc-0.9.0.tar.gz
+a0894c2ddf9133c3cc33c264e4596a3c bb-rm.patch
+e96514860ee34b62d1b208ab03c569bc bb-shutdown.patch
+f3c6998798b13425b8d0647bad0834a8 lxc.initd"
+sha256sums="1e1767eae6cc5fbf892c0e193d25da420ba19f2db203716c38f7cdea3b654120 lxc-0.9.0.tar.gz
+c9caea06b87baf5e335821c7e9ce3caca849b33f8176fbd48126c605583e78fc bb-rm.patch
+0e5706cb077f750afdd6a5a4fd2afdf0b9113126c85e130d92680bed4ce9c20e bb-shutdown.patch
+77c64e6137457be89c150b82d681a3eb5c7c1f06af142a321703fc9a43bff200 lxc.initd"
+sha512sums="a96133660ca6ea45dc4b8d167267120328577339e933ff9510f03e9d368ca5db77031dc1e7e4529b3e506f63f79c2ce3f8f72571a7dfdbeb2a8799777782a606 lxc-0.9.0.tar.gz
+b8fe47af6b1341ca472b6337c304f52402c53d400fc1d13895f2f568dd4d81b9ff281efc70bc1ddc221ac457db3bed4a199491059a15f66755deddc93ce91bf1 bb-rm.patch
+86df52e380a01d6d3f588ca395925e8f774529c72e5b4c8dcb701d79fad7697ed8800f0ff51fded2896b2d2af49faa7f26960234fc8c1a6b4bc8f42d85078e6d bb-shutdown.patch
+4e56f7b869345f936df54c4359abdd3b8d0244c0fd71a9a787bc2393c4caabca22ca8417f16da47f02c86294750986fd674d0d2e7c1b1d096076873b22c07a29 lxc.initd"
diff --git a/main/lxc/bb-find.patch b/main/lxc/bb-find.patch
deleted file mode 100644
index 663a81e070..0000000000
--- a/main/lxc/bb-find.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- ./src/lxc/lxc-ls.in.orig 2013-02-09 17:22:38.811308444 +0000
-+++ ./src/lxc/lxc-ls.in 2013-02-09 17:25:00.665833613 +0000
-@@ -87,7 +87,7 @@
-
- containers=""
- if [ ! -z "$directory" ]; then
-- containers=$(find $directory -mindepth 1 -maxdepth 1 -type d -printf "%f\n" 2>/dev/null)
-+ containers=$(find $directory -mindepth 1 -maxdepth 1 -type d -print 2>/dev/null | sed 's:.*/::')
- fi
-
- if [ -z "$containers" ]; then
diff --git a/main/lxc/bb-rm.patch b/main/lxc/bb-rm.patch
index b354d48c47..c93adb33a8 100644
--- a/main/lxc/bb-rm.patch
+++ b/main/lxc/bb-rm.patch
@@ -1,16 +1,15 @@
-diff --git a/src/lxc/lxc-destroy.in b/src/lxc/lxc-destroy.in
-index 846266c..f8f4b48 100644
---- a/src/lxc/lxc-destroy.in
-+++ b/src/lxc/lxc-destroy.in
-@@ -122,9 +122,9 @@ if [ -n "$rootdev" ]; then
- btrfs subvolume delete "$rootdev"
- else
- # In case rootfs is not under $lxc_path/$lxc_name, remove it
-- rm -rf --one-file-system --preserve-root $rootdev
-+ find $rootdev -xdev -delete
- fi
- fi
+--- ./src/lxc/lxc-destroy.in.orig 2013-04-15 07:38:58.383545701 +0000
++++ ./src/lxc/lxc-destroy.in 2013-04-15 07:42:22.552123148 +0000
+@@ -137,10 +137,10 @@
+ btrfs subvolume delete "$rootdev"
+ else
+ # In case rootfs is not under $lxc_path/$lxc_name, remove it
+- rm -rf --one-file-system --preserve-root $rootdev
++ find $rootdev -xdev -delete
+ fi
+ fi
fi
+
# recursively remove the container to remove old container configuration
-rm -rf --one-file-system --preserve-root $lxc_path/$lxc_name
+find $lxc_path/$lxc_name -xdev -delete
diff --git a/main/lxc/bb-shutdown.patch b/main/lxc/bb-shutdown.patch
index bfda20e11b..4063032159 100644
--- a/main/lxc/bb-shutdown.patch
+++ b/main/lxc/bb-shutdown.patch
@@ -1,6 +1,6 @@
---- ./src/lxc/lxc-shutdown.in.orig 2013-02-08 13:28:28.489406380 +0000
-+++ ./src/lxc/lxc-shutdown.in 2013-02-08 13:30:31.910466926 +0000
-@@ -113,11 +113,21 @@
+--- ./src/lxc/lxc-shutdown.in.orig 2013-04-15 07:43:04.709177850 +0000
++++ ./src/lxc/lxc-shutdown.in 2013-04-15 07:45:43.213958405 +0000
+@@ -118,11 +118,21 @@
exit 1
fi
@@ -15,11 +15,11 @@
+esac
+
if [ $reboot -eq 1 ]; then
-- kill -INT $pid
-+ kill -s $signal_reboot $pid
+- kill -s INT $pid
++ kill -s $signal_reboot $pid
exit 0
else
-- kill -PWR $pid
+- kill -s PWR $pid
+ kill -s $signal_poweroff $pid
fi
diff --git a/main/lxc/lxc-alpine b/main/lxc/lxc-alpine
deleted file mode 100755
index 3c2db7cd79..0000000000
--- a/main/lxc/lxc-alpine
+++ /dev/null
@@ -1,239 +0,0 @@
-#!/bin/sh
-
-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
- echo "$repository" > "$rootfs"/etc/apk/repositories
- else
- cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
- fi
- 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() {
- rootfs="$1"
- echo "Setting up /etc/inittab"
- cat >"$rootfs"/etc/inittab<<EOF
-::sysinit:/sbin/rc sysinit
-::wait:/sbin/rc default
-tty1:12345:respawn:/sbin/getty 38400 tty1
-::ctrlaltdel:/sbin/reboot
-::shutdown:/sbin/rc shutdown
-EOF
- # set up nameserver
- grep nameserver /etc/resolv.conf > "$rootfs/etc/resolv.conf"
-
- # configure the network using the dhcp
- # note that lxc will set up lo interface
- cat <<EOF > $rootfs/etc/network/interfaces
-#auto lo
-iface lo inet loopback
-
-auto eth0
-iface eth0 inet dhcp
-EOF
-
- # set the hostname
- echo $hostname > $rootfs/etc/hostname
-
- # missing device nodes
- echo "Setting up device nodes"
- mkdir -p -m 755 "$rootfs/dev/pts"
- mkdir -p -m 1777 "$rootfs/dev/shm"
- mknod -m 666 "$rootfs/dev/full" c 1 7
- mknod -m 666 "$rootfs/dev/random" c 1 8
- mknod -m 666 "$rootfs/dev/urandom" c 1 9
- mknod -m 666 "$rootfs/dev/tty0" c 4 0
- mknod -m 666 "$rootfs/dev/tty1" c 4 1
- mknod -m 666 "$rootfs/dev/tty2" c 4 2
- mknod -m 666 "$rootfs/dev/tty3" c 4 3
- mknod -m 666 "$rootfs/dev/tty4" c 4 4
-# mknod -m 600 "$rootfs/dev/initctl" p
- mknod -m 666 "$rootfs/dev/tty" c 5 0
- mknod -m 666 "$rootfs/dev/console" c 5 1
- mknod -m 666 "$rootfs/dev/ptmx" c 5 2
-
- # start services
- ln -s /etc/init.d/syslog "$rootfs"/etc/runlevels/default/syslog
-
- return 0
-}
-
-copy_configuration() {
- path=$1
- rootfs=$2
- hostname=$3
-
- 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
-
-# When using LXC with apparmor, uncomment the next line to run unconfined:
-#lxc.aa_profile = unconfined
-
-# devices
-lxc.cgroup.devices.deny = a
-# /dev/null and zero
-lxc.cgroup.devices.allow = c 1:3 rwm
-lxc.cgroup.devices.allow = c 1:5 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 rwm
-
-# 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>] [-a|--arch <arch>]
- -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=/var/lib/lxc
-
-while [ $# -gt 0 ]; do
- opt="$1"
- shift
- case "$opt" in
- -h|--help)
- usage
- exit 0
- ;;
- -n|--name)
- optarg_check $opt "$1"
- name=$1
- shift
- ;;
- -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#*=} "$@"
- ;;
- -?)
- 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
-
-rootfs=`awk -F= '$1 ~ /^lxc.rootfs/ { print $2 }' "$path/config" 2>/dev/null`
-if [ -z "$rootfs" ]; then
- rootfs="${path}/rootfs"
-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
-
-install_alpine "$rootfs" "$@" || die "Failed to install rootfs for $name"
-configure_alpine "$rootfs" "$name" || die "Failed to configure $name"
-copy_configuration "$path" "$rootfs" "$name"
diff --git a/main/lxc/setup-lxc-guest b/main/lxc/setup-lxc-guest
deleted file mode 100755
index 0519ae0299..0000000000
--- a/main/lxc/setup-lxc-guest
+++ /dev/null
@@ -1,282 +0,0 @@
-#!/bin/sh
-
-# simple script to set up a new lxc guest
-# test the first argument against the remaining ones, return success on a match
-isin() {
- local _a=$1 _b
-
- shift
- for _b; do
- [ "$_a" = "$_b" ] && return 0
- done
- return 1
-}
-
-# remove all occurrences of first argument from list formed by
-# the remaining arguments
-rmel() {
- local _a=$1 _b
-
- shift
- for _b; do
- [ "$_a" != "$_b" ] && echo -n "$_b "
- done
-}
-
-# Issue a read into the global variable $resp.
-_ask() {
- local _redo=0
-
- read resp
- case "$resp" in
- !) echo "Type 'exit' to return to setup."
- sh
- _redo=1
- ;;
- !*) eval "${resp#?}"
- _redo=1
- ;;
- esac
- return $_redo
-}
-
-# Ask for user input.
-#
-# $1 = the question to ask the user
-# $2 = the default answer
-#
-# Save the user input (or the default) in $resp.
-#
-# Allow the user to escape to shells ('!') or execute commands
-# ('!foo') before entering the input.
-ask() {
- local _question=$1 _default=$2
-
- while :; do
- echo -n "$_question "
- [ -z "$_default" ] || echo -n "[$_default] "
- _ask && : ${resp:=$_default} && break
- done
-}
-
-# Ask for user input until a non-empty reply is entered.
-#
-# $1 = the question to ask the user
-# $2 = the default answer
-#
-# Save the user input (or the default) in $resp.
-ask_until() {
- resp=
- while [ -z "$resp" ] ; do
- ask "$1" "$2"
- done
-}
-
-# Ask for the user to select one value from a list, or 'done'.
-#
-# $1 = name of the list items (disk, cd, etc.)
-# $2 = question to ask
-# $3 = list of valid choices
-# $4 = default choice, if it is not specified use the first item in $3
-#
-# N.B.! $3 and $4 will be "expanded" using eval, so be sure to escape them
-# if they contain spooky stuff
-#
-# At exit $resp holds selected item, or 'done'
-ask_which() {
- local _name=$1 _query=$2 _list=$3 _def=$4 _dynlist _dyndef
-
- while :; do
- # Put both lines in ask prompt, rather than use a
- # separate 'echo' to ensure the entire question is
- # re-ask'ed after a '!' or '!foo' shell escape.
- eval "_dynlist=\"$_list\""
- eval "_dyndef=\"$_def\""
-
- # Clean away whitespace and determine the default
- set -o noglob
- set -- $_dyndef; _dyndef="$1"
- set -- $_dynlist; _dynlist="$*"
- set +o noglob
- [ $# -lt 1 ] && resp=done && return
-
- : ${_dyndef:=$1}
- echo "Available ${_name}s are: $_dynlist."
- echo -n "Which one $_query? (or 'done') "
- [ -n "$_dyndef" ] && echo -n "[$_dyndef] "
- _ask || continue
- [ -z "$resp" ] && resp="$_dyndef"
-
- # Quote $resp to prevent user from confusing isin() by
- # entering something like 'a a'.
- isin "$resp" $_dynlist done && break
- echo "'$resp' is not a valid choice."
- done
-}
-
-# Ask for user input until a non-empty reply is entered.
-#
-# $1 = the question to ask the user
-# $2 = the default answer
-#
-# Save the user input (or the default) in $resp.
-ask_until() {
- resp=
- while [ -z "$resp" ] ; do
- ask "$1" "$2"
- done
-}
-
-# http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
-valid_hostname() {
- # check length
- if [ $(echo "$1" | wc -c) -gt 63 ]; then
- echo "Hostname '$1' is too long."
- return 1
- fi
- # check that it only contains valid chars
- if ! [ -z "$(echo $1 | sed 's/[0-9a-z-]//g')" ]; then
- echo "Hostname must only contain letters (a-z), digits (0-9) or -"
- return 1
- fi
- # must not start with -
- case "$1" in
- -*) echo "Hostname must not start with a '-'"; return 1;;
- esac
- return 0
-}
-
-# return last ipv4 address and mask
-#
-# $1 = interface
-#
-last_ipv4_addr_mask() {
- local _iface=$1
- ip addr show dev $_iface | awk '$1 == "inet" {print $2}' | tail -n1
-}
-
-valid_ip_and_prefix() {
- [ "$1" ] || return 0
- ipcalc -s -m $1 >/dev/null 2>&1 && ! ipcalc -s -m $1/0 >/dev/null 2>&1
-}
-
-# ask for hostname
-#
-# $1 = default
-#
-# retrusn hostname in global var $resp
-#
-ask_hostname() {
- while true; do
- ask "Hostname for new lxc container:" $1
- if [ -d /var/lib/lxc/$resp ]; then
- echo "/var/lib/lxc/$resp already exist"
- continue
- fi
- if [ -d /lxc/$resp ]; then
- echo "/lxc/$resp already exist"
- continue
- fi
- valid_hostname $resp && break
- done
-}
-
-ask_ifaceopts() {
- # get ip address(es)
- resp=
- local ifaceopts= _def= _iface=
- local ifaces=$(ip addr | awk -F: '$1 ~ /^[0-9]/ {printf "%s" $2} END {printf "\n"}')
- local last_iface=$(echo $ifaces | sed 's/.* //')
- while [ "$resp" != "done" ]; do
- if [ -z "$ifaces" ] || [ "$ifaces" = "lo " ] || [ -n "$ifaceopts" ]; then
- _def="done"
- else
- _def=$(echo $ifaces | sed 's/.* //')
- fi
- ask_which "network interface" "to use for $_hostname" \
- "$ifaces" $_def
- [ "$resp" = "done" ] && break
-
- _iface=$resp
- ifaces=$(rmel $_iface $ifaces)
- # suggested ip by last digit + 1
- _last_ip_mask=$(last_ipv4_addr_mask $_iface)
- _last_ip=${_last_ip_mask%/*}
- _last_ip_digit=${_last_ip##*.}
- _ip=${_last_ip%.*}.$((($_last_ip_digit + 1) % 256))
- _mask=${_last_ip_mask#*/}
- while true; do
- ask "Enter IP address/mask for $_iface:" $_ip/$_mask
- valid_ip_and_prefix "$resp" 2>&1 && break
- echo "$resp is not a valid IPv4 address/mask"
- done
- _ip_mask=$resp
- ifaceopts="$ifaceopts --interface $_iface:$_ip_mask"
- echo "lxc.network.ipv4 = $_iface/$_ip_mask" >> /tmp/lxc-$hostname.conf
- conffile=/tmp/lxc-$hostname.conf
- done
- resp="$conffile"
-}
-
-ask_template() {
- local temp
- # get template
- while true; do
- ask "Enter template file (or empty for generate a new):" \
- $_template
- if [ -z "$resp" ] || [ -r "$resp" ]; then
- break
- fi
- echo "Can not read $resp"
- done
- temp=$resp
- if [ -z "$temp" ]; then
- temp=/tmp/template.tar.gz
- echo "Generating template..."
- if setup-lxc-template -q -o $temp; then
- echo "ok"
- else
- echo "Failed to create template"
- exit 1
- fi
- fi
- resp=$temp
-}
-
-usage() {
- echo "Usage: ${0##*/} [-h] [HOSTNAME...]"
- exit 1
-}
-
-while getopts "h" opt; do
- case "$opt" in
- h) usage;;
- ?) usage;;
- esac
-done
-
-shift $(($OPTIND - 1))
-
-if [ "$(whoami)" != "root" ]; then
- echo "Need to be root. Sorry."
- exit 1
-fi
-
-while true; do
- ask_hostname $1
- _hostname=$resp
-
- ask_ifaceopts
- _conffile=$resp
-
- ask_template
- _template=$resp
-
- lxc-create -n $_hostname \
- -f $_conffile \
- -t "$_template" \
- || exit 1
-
- shift
- [ $# -le 0 ] && exit 0
-done
diff --git a/main/lxc/setup-lxc-template b/main/lxc/setup-lxc-template
deleted file mode 100755
index f8e9fe4a39..0000000000
--- a/main/lxc/setup-lxc-template
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/sh
-
-# create a lxc template
-PROG=$0
-
-usage() {
- echo "usage: $PROG [-fhq] [-o OUTFILE] [-X repository] [packages...]"
- exit $1
-}
-
-clean_exit() {
- rm -rf "$tmpdir"
- exit $1
-}
-
-outfile=template.tar.gz
-fakeroot=
-repos=
-while getopts "ho:qX:" opt; do
- case "$opt" in
- h) usage 0;;
- o) outfile="$OPTARG";;
- q) quiet=-q;;
- X) repos="$repos --repository $OPTARG";;
- esac
-done
-shift $(( $OPTIND - 1 ))
-
-if [ "$(whoami)" != "root" ]; then
- echo "Warning: you need root permissions" >&2
-fi
-
-tmpdir=$(mktemp -d ${TMPDIR:-/tmp}/setup-lxc-template-XXXXXX)
-
-apk add --root "$tmpdir" --initdb --keys-dir /etc/apk/keys -U \
- $quiet ${repos:---repositories-file /etc/apk/repositories} \
- alpine-base $@ \
- || clean_exit 1
-
-tar -czf "$outfile" -C "$tmpdir" $(ls "$tmpdir") || clean_exit 1
-
-[ -z "$quiet" ] && echo "Created $outfile"
-clean_exit 0
-