aboutsummaryrefslogtreecommitdiffstats
path: root/main/util-vserver
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2010-01-06 08:45:11 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2010-01-06 08:45:11 +0000
commit73281af4d137533d84ab57a40a548a5f0fb56bb9 (patch)
tree55c36b96a393de7070a42aff9956eebe103488f1 /main/util-vserver
parent975f1475c36b7994ec614ab09b083c4f91d2720d (diff)
downloadaports-73281af4d137533d84ab57a40a548a5f0fb56bb9.tar.bz2
aports-73281af4d137533d84ab57a40a548a5f0fb56bb9.tar.xz
main/*-vserver: move from testing
good enough for main now
Diffstat (limited to 'main/util-vserver')
-rw-r--r--main/util-vserver/APKBUILD67
-rw-r--r--main/util-vserver/alpine.patch26
-rw-r--r--main/util-vserver/busybox.patch11
-rw-r--r--main/util-vserver/chmod.patch12
-rw-r--r--main/util-vserver/ensc_pathprog.patch14
-rw-r--r--main/util-vserver/setup-vs-guest306
-rw-r--r--main/util-vserver/setup-vs-template44
-rw-r--r--main/util-vserver/util-vserver.post-install15
l---------main/util-vserver/util-vserver.post-upgrade1
-rw-r--r--main/util-vserver/validate.patch10
10 files changed, 506 insertions, 0 deletions
diff --git a/main/util-vserver/APKBUILD b/main/util-vserver/APKBUILD
new file mode 100644
index 0000000000..24d8150ae8
--- /dev/null
+++ b/main/util-vserver/APKBUILD
@@ -0,0 +1,67 @@
+# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
+pkgname=util-vserver
+pkgver=0.30.216_pre2864
+_realver=0.30.216-pre2864
+pkgrel=5
+pkgdesc="Linux-VServer admin utilities"
+url="http://www.nongnu.org/util-vserver/"
+license="GPL"
+install="$pkgname.post-install $pkgname.post-upgrade"
+makedepends="iptables-dev e2fsprogs-dev beecrypt-dev autoconf automake
+ pkgconfig libtool"
+depends="bash make"
+
+source="http://people.linux-vserver.org/~dhozac/t/uv-testing/util-vserver-$_realver.tar.bz2
+ busybox.patch
+ chmod.patch
+ ensc_pathprog.patch
+ validate.patch
+ alpine.patch
+ setup-vs-template
+ setup-vs-guest
+ "
+subpackages="$pkgname-doc $pkgname-dev"
+
+_builddir="$srcdir"/$pkgname-$_realver
+
+build() {
+ local i
+ cd "$_builddir"
+ for i in ../*.patch; do
+ [ -r "$i" ] || continue
+ msg "Applying $i"
+ patch -p1 -i $i || return 1
+ done
+ msg "Running autotools..."
+ aclocal -I m4 && autoconf && automake && libtoolize || return 1
+
+ # this is an ugly workaround
+ sed -i -e "s:as_echo=.*:as_echo=echo:g" configure
+
+ ./configure --prefix=/usr \
+ --mandir=/usr/share/man \
+ --sysconfdir=/etc \
+ --with-initscripts=gentoo \
+ --localstatedir=/var \
+ || return 1
+
+ # use busybox ionice rather than util-linux-ng
+ sed -i -e 's:/usr/bin/ionice:/bin/ionice:' Makefile
+ make || return 1
+}
+
+package() {
+ cd "$_builddir"
+ make DESTDIR="$pkgdir/" install install-distribution
+ install -Dm755 ../setup-vs-template "$pkgdir"/usr/sbin/setup-vs-template
+ install -Dm755 ../setup-vs-guest "$pkgdir"/usr/sbin/setup-vs-guest
+}
+
+md5sums="f686d72b39399fba96bbabd7debab549 util-vserver-0.30.216-pre2864.tar.bz2
+62b7b9bbe5902b95f4614272af003dfd busybox.patch
+73c7437dea6937a57cf38d166ef83c09 chmod.patch
+ff8f561f672524eb46fe633f584ef60e ensc_pathprog.patch
+da8b70c4fd40e68894b3903ffd121397 validate.patch
+04000261fd990a3963b0e98260b481bd alpine.patch
+49bca7969cc284adf68e0ef284c0660e setup-vs-template
+838511f74983453ef9827ed875b70d59 setup-vs-guest"
diff --git a/main/util-vserver/alpine.patch b/main/util-vserver/alpine.patch
new file mode 100644
index 0000000000..eacc2cb624
--- /dev/null
+++ b/main/util-vserver/alpine.patch
@@ -0,0 +1,26 @@
+Index: distrib/alpine/initpost
+===================================================================
+--- a/distrib/alpine/initpost (revision 2855)
++++ b/distrib/alpine/initpost (working copy)
+@@ -1,6 +1,6 @@
+ #!/bin/bash
+
+-# Copyright (C) 2007 Natanael Copa <ncopa@alpinelinux.org>
++# Copyright (C) 2007, 2009 Natanael Copa <ncopa@alpinelinux.org>
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+@@ -37,7 +37,12 @@
+ $_VSERVER "$vserver" stop &>/dev/null || true
+ $_VSERVER "$vserver" start --rescue --rescue-init /bin/busybox sh -c '
+ /bin/busybox --install -s
+- /sbin/rc_add -s 20 -k syslog
++ if [ -x /sbin/rc-update ]; then
++ /sbin/rc-update add syslog boot
++ /bin/rmdir /etc/rcL.d /etc/rcK.d
++ else
++ /sbin/rc_add -s 20 -k syslog
++ fi
+ '
+
+ # set up hostname
diff --git a/main/util-vserver/busybox.patch b/main/util-vserver/busybox.patch
new file mode 100644
index 0000000000..cc471cc4eb
--- /dev/null
+++ b/main/util-vserver/busybox.patch
@@ -0,0 +1,11 @@
+--- a/scripts/start-vservers Mon Oct 26 13:58:40 2009
++++ b/scripts/start-vservers Mon Oct 26 13:59:31 2009
+@@ -131,7 +131,7 @@
+ d=$__CONFDIR/${vservers[$i]}/apps/init
+ f=$d/mark
+ { test -n "$OPTION_MARK_ANY"; } || \
+- { test -n "$OPTION_MARK" -a -r "$f" && grep -qx "$OPTION_MARK" "$f"; } || \
++ { test -n "$OPTION_MARK" -a -r "$f" && grep -q "^${OPTION_MARK}$" "$f"; } || \
+ { test -z "$OPTION_MARK" && test ! -e "$f"; } || \
+ unset vservers[$i]
+ done
diff --git a/main/util-vserver/chmod.patch b/main/util-vserver/chmod.patch
new file mode 100644
index 0000000000..53861e8932
--- /dev/null
+++ b/main/util-vserver/chmod.patch
@@ -0,0 +1,12 @@
+diff -ru a/Makefile.am b/Makefile.am
+--- a/Makefile.am 2009-09-29 13:48:10.000000000 +0000
++++ b/Makefile.am 2009-09-29 13:50:00.000000000 +0000
+@@ -149,7 +149,7 @@
+ @mkdir -p $$(dirname '$@')
+ @echo "$(SED) -e '...' $*.pathsubst >$*"
+ @$(SED) -e '$(pathsubst_RULES)' '$<' >'$@.tmp'
+- @-chmod --reference='$<' '$@.tmp'
++ @-chmod $$(stat -c %a '$<') '$@.tmp'
+ @if cmp -s '$@.tmp' '$*'; then \
+ echo "... no changes, reusing old version"; \
+ rm -f '$@.tmp'; \
diff --git a/main/util-vserver/ensc_pathprog.patch b/main/util-vserver/ensc_pathprog.patch
new file mode 100644
index 0000000000..e14c1f6dab
--- /dev/null
+++ b/main/util-vserver/ensc_pathprog.patch
@@ -0,0 +1,14 @@
+diff -ru a/m4/ensc_pathprog.m4 b/m4/ensc_pathprog.m4
+--- a/m4/ensc_pathprog.m4 2009-10-02 17:25:49.000000000 +0000
++++ b/m4/ensc_pathprog.m4 2009-10-02 17:31:28.000000000 +0000
+@@ -61,7 +61,9 @@
+
+ if test "x$5" = x; then
+ if test -h "${$1}"; then
+- $1=`readlink -f "${$1}"`
++ case `readlink "{$1}"` in
++ ../*) $1=`readlink -f "${$1}"`;;
++ esac
+ fi
+ fi
+
diff --git a/main/util-vserver/setup-vs-guest b/main/util-vserver/setup-vs-guest
new file mode 100644
index 0000000000..dffd3c8804
--- /dev/null
+++ b/main/util-vserver/setup-vs-guest
@@ -0,0 +1,306 @@
+#!/bin/sh
+
+# simple script to set up a new vserver 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() {
+ [ "$1" ] || return 0
+ ipcalc -s $1
+}
+
+# ask for hostname
+#
+# $1 = default
+#
+# retrusn hostname in global var $resp
+#
+ask_hostname() {
+ while true; do
+ ask "Hostname for new vserver:" $1
+ if [ -d /etc/vservers/$resp ]; then
+ echo "/etc/vservers/$resp already exist"
+ continue
+ fi
+ if [ -d /vservers/$resp ]; then
+ echo "/vservers/$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 $resp && break
+ echo "$resp is not a valid IPv4 address/mask"
+ done
+ _ip_mask=$resp
+ ifaceopts="$ifaceopts --interface $_iface:$_ip_mask"
+
+ # suggest context from last digit in first ip address
+ if [ -z "$_context" ]; then
+ _ip=${_ip_mask%/*}
+ _last_digit=${_ip##*.}
+ _context=$((10000 + $_last_digit))
+ fi
+ done
+ resp="$ifacesopts"
+}
+
+ask_context() {
+ # get context id
+ while true; do
+ ask "Enter context id for $_hostname:" $_context
+ if echo "$resp" | egrep -q "[0-9]+"; then
+ [ $resp -ge 0 ] && [ $resp -lt 65535 ] && break
+ fi
+ echo "Context id must be a 0-65534 number"
+ done
+}
+
+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=/vservers/template.tar.gz
+ echo -n "Generating template..."
+ if setup-vs-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
+ _ifaceopts=$resp
+
+ ask_context
+ _context=$resp
+
+ ask_template
+ _template=$resp
+
+ vserver $_hostname build \
+ --hostname $_hostname \
+ $_ifaceopts \
+ --context $_context \
+ -m template -- -t "$_template" -d alpine \
+ && cp /etc/resolv.conf /vservers/$_hostname/etc/ \
+ && cp /etc/apk/repositories /vservers/$_hostname/etc/apk/ \
+ || exit 1
+
+ shift
+ [ $# -le 0 ] && exit 0
+done
diff --git a/main/util-vserver/setup-vs-template b/main/util-vserver/setup-vs-template
new file mode 100644
index 0000000000..8ad7f3fae8
--- /dev/null
+++ b/main/util-vserver/setup-vs-template
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# create a vserver 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-vs-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
+
diff --git a/main/util-vserver/util-vserver.post-install b/main/util-vserver/util-vserver.post-install
new file mode 100644
index 0000000000..9c8aad1e4c
--- /dev/null
+++ b/main/util-vserver/util-vserver.post-install
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+if [ -f /etc/vservers/.defaults/rlimits/nproc ]; then
+ exit 0
+fi
+
+# calculate the nproc limit from amount of ram
+memtotal=$(awk '$1 == "MemTotal:" {print $2}' /proc/meminfo 2>/dev/null)
+nproc=$(( ${memtotal:-524288} / 256 ))
+
+# set a "sane" default nproc limit
+echo "Setting default nproc limit to $nproc"
+mkdir -p /etc/vservers/.defaults/rlimits
+echo $nproc > /etc/vservers/.defaults/rlimits/nproc
+
diff --git a/main/util-vserver/util-vserver.post-upgrade b/main/util-vserver/util-vserver.post-upgrade
new file mode 120000
index 0000000000..c5db4163fd
--- /dev/null
+++ b/main/util-vserver/util-vserver.post-upgrade
@@ -0,0 +1 @@
+util-vserver.post-install \ No newline at end of file
diff --git a/main/util-vserver/validate.patch b/main/util-vserver/validate.patch
new file mode 100644
index 0000000000..081dce5a31
--- /dev/null
+++ b/main/util-vserver/validate.patch
@@ -0,0 +1,10 @@
+diff -ru a/m4/validate.am b/m4/validate.am
+--- a/m4/validate.am 2009-10-02 17:57:03.000000000 +0000
++++ b/m4/validate.am 2009-10-02 17:58:15.000000000 +0000
+@@ -26,5 +26,5 @@
+ .%-up-to-date:
+ @rm -f .*-up-to-date
+ @$(MAKE) -s clean
+- @touch -t 197001020000 '$@'
++ @cp -a Makefile.am '$@'
+ @$(MAKE) -s $(BUILT_SOURCES)