--- vserver-0.21.orig/Makefile +++ vserver-0.21/Makefile @@ -1,3 +1,6 @@ +# Packages for Debian by Paul Sladen +RPM_BUILD_ROOT=$(DESTDIR) + PACKAGE_REV=0.21 MANDIR=/usr/share/man PROGS=chbind chcontext reducecap rebootmgr vreboot readlink vunify vbuild \ @@ -78,13 +81,28 @@ listdevip: listdevip.cc gcc $(GCCOPTS) -DVERSION=\"$(PACKAGE_REV)\" listdevip.cc -o listdevip +tests: tests-target +tests-target: + make -C tests + +MISSING_MANPAGES = filetime.8 ifspec.8 listdevip.8 newvserver.8 readlink.8 \ + save_s_context.8 showattr.8 showperm.8 vbuild.8 vdu.8 vfiles.8 vkill.8 \ + vreboot.8 vunify.8 + +missing-manpages: missing-manpages-target $(MISSING_MANPAGES) + +missing-manpages-target: man/man8/vserver-host-utils.8 + for MANPAGE in $(MISSING_MANPAGES) ; do + ln -s man/man8/$MANPAGE man/man8/vserver-host-utils.8 + done + clean: rm -f $(PROGS) *.bak *~ *.o */*.bak */*~ make -C tests clean USR_SBIN=/usr/sbin USR_LIB_VSERVER=/usr/lib/vserver -install: +install: $(PROGS) mkdir -p $(RPM_BUILD_ROOT)$(USR_SBIN) mkdir -p $(RPM_BUILD_ROOT)$(USR_LIB_VSERVER) mkdir -p $(RPM_BUILD_ROOT)/etc/init.d @@ -95,6 +113,7 @@ install -m 755 rebootmgr $(RPM_BUILD_ROOT)$(USR_SBIN) ./install-fix.sh vserver $(RPM_BUILD_ROOT)$(USR_SBIN) $(USR_SBIN) $(USR_LIB_VSERVER) ./install-fix.sh newvserver $(RPM_BUILD_ROOT)$(USR_SBIN) $(USR_SBIN) $(USR_LIB_VSERVER) + mv $(RPM_BUILD_ROOT)$(USR_SBIN)/newvserver{,-redhat} install -m 755 vpstree $(RPM_BUILD_ROOT)$(USR_SBIN) install -m 755 vtop $(RPM_BUILD_ROOT)$(USR_SBIN) install -m 755 vkill $(RPM_BUILD_ROOT)$(USR_SBIN) @@ -128,9 +147,19 @@ ./install-fix.sh rebootmgr.sysv $(RPM_BUILD_ROOT)/etc/init.d/rebootmgr $(USR_SBIN) $(USR_LIB_VSERVER) ./install-fix.sh vsysvwrapper $(RPM_BUILD_ROOT)/usr/lib/vserver/vsysvwrapper $(USR_SBIN) $(USR_LIB_VSERVER) ./install-fix.sh vservers.grabinfo.sh $(RPM_BUILD_ROOT)/usr/lib/vserver $(USR_SBIN) $(USR_LIB_VSERVER) - install -m 644 man/*.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 - install -m 644 distrib/sample.conf $(RPM_BUILD_ROOT)$(USR_LIB_VSERVER) - install -m 644 distrib/sample.sh $(RPM_BUILD_ROOT)$(USR_LIB_VSERVER) +# install -m 644 man/*.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/chbind.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/chcontext.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/rebootmgr.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/reducecap.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/vps.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/vpstree.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/vserver-stat.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/vserver.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/vtop.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 man/vrpm.8 $(RPM_BUILD_ROOT)/$(MANDIR)/man8 + install -m 644 distrib/sample.conf $(RPM_BUILD_ROOT)/$(USR_LIB_VSERVER) + install -m 644 distrib/sample.sh $(RPM_BUILD_ROOT)/$(USR_LIB_VSERVER) ./install-fix.sh distrib/install-rh7.2 $(RPM_BUILD_ROOT)$(USR_LIB_VSERVER) $(USR_SBIN) $(USR_LIB_VSERVER) ./install-fix.sh distrib/install-rh7.3 $(RPM_BUILD_ROOT)$(USR_LIB_VSERVER) $(USR_SBIN) $(USR_LIB_VSERVER) ./install-fix.sh distrib/install-rh8.0 $(RPM_BUILD_ROOT)$(USR_LIB_VSERVER) $(USR_SBIN) $(USR_LIB_VSERVER) @@ -140,7 +169,7 @@ install -m 644 distrib/rh7.3-minimum $(RPM_BUILD_ROOT)$(USR_LIB_VSERVER) install -m 644 distrib/rh8.0-minimum $(RPM_BUILD_ROOT)$(USR_LIB_VSERVER) install -m 644 distrib/mdk8.2-minimum $(RPM_BUILD_ROOT)$(USR_LIB_VSERVER) - + install -m 755 newvserver-debian $(RPM_BUILD_ROOT)$(USR_SBIN) buildrpm: buildspec --- vserver-0.21.orig/vserver +++ vserver-0.21/vserver @@ -17,8 +17,14 @@ { mkdir -p $1/proc $1/dev/pts if [ ! -d $1/proc/1 ] ; then - mount -t proc none $1/proc - mount -t devpts none $1/dev/pts + mount -t proc proc $1/proc + if [ -f "$1/etc/default/devpts" ]; then + # Debian system ? + eval `cat "$1/etc/default/devpts" | grep -E '^TTY(GRP|MODE)='` + mount -t devpts devpts "$1/dev/pts" -o "rw,gid=$TTYGRP,mode=$TTYMODE" + else + mount -t devpts devpts "$1/dev/pts" + fi fi } umountproc() --- vserver-0.21.orig/man/man8/vserver-host-utils.8 +++ vserver-0.21/man/man8/vserver-host-utils.8 @@ -0,0 +1,114 @@ +.\" Hey, EMACS: -*- nroff -*- +.\" First parameter, NAME, should be all caps +.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection +.\" other parameters are allowed: see man(7), man(1) +.TH VSERVER-HOST-UTILS 8 "August 23, 2002" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +vserver-host-utils \- programs that support virtual servers +.SH SYNOPSIS +.\" chbind.8 chcontext.8 rebootmgr.8 reducecap.8 vps.8 vpstree.8 vrpm.8 vserver-stat.8 vserver.8 vtop.8 +.B capchroot +.br +.B filetime +.br +.B ifspec +.br +.B listdevip +.br +.B newvserver +.br +.B readlink +.br +.B save_s_context +.br +.B showattr +.br +.B showperm +.br +.B vbuild +.br +.B vdu +.br +.B vfiles +.br +.B vkill +.br +.B vreboot +.br +.B vunify +.br +.B vserverkillall +.SH DESCRIPTION +This manual page documents briefly the +.B vserver host utilities. + +This manual page was written for the Debian distribution +because the original program does not have a manual page. +Instead, it has documentation in the GNU Info format; see below. +.PP + +.B vserver host utilities + +These are the userspace utilities to support the `\fBvservers\fP' linux +kernel patch. + +The patch adds vservers (seperate contexts) for running multiple +virtual servers on one host machine at full speed using only one +kernel. + +This works on Intel (i386) and possibley Sparc (sparc32). + + Vserver: http://www.solucorp.qc.ca/miscprj/s_context.hc + Mailing List: http://www.solucorp.qc.ca/mlist/index.hc?list=vserver + FTP Downloads: ftp://ftp.solucorp.qc.ca/pub/vserver/ + + My Links/Stuff: http://www.paul.sladen.org/vserver/ + + -- Paul Sladen , Fri, 23 Aug 2002 01:47:41 +0100 + +.SH OPTIONS +These programs follow the usual GNU command line syntax, with long +options starting with two dashes (`-'). +A summary of options is included below. +.TP +.B \-h, \-\-help +Show summary of options. +.SH SEE ALSO +.BR vserver (8), +.sp +.BR chbind (8), +.br +.BR chcontext (8), +.br +.BR rebootmgr (8), +.br +.BR reducecap (8), +.br +.BR vps (8), +.br +.BR vpstree (8), +.br +.BR vrpm (8), +.br +.BR vserver-vstat (8), +.br +.BR vtop (8) + +The programs are documented fully by +http://www.solucorp.qc.ca/miscprj/s_context.hc +available via the interweb. +.SH AUTHOR +This manual page was written by Paul Sladen , +for the Debian GNU/Linux system (but may be used by others). --- vserver-0.21.orig/debian/README.Debian +++ vserver-0.21/debian/README.Debian @@ -0,0 +1,19 @@ +vserver for Debian +------------------ + +These are the userspace utilities to support the `vservers' linux +kernel patch. + +The patch adds vservers (seperate contexts) for running multiple +virtual servers on one host machine at full speed using only one +kernel. + +This works on Intel and possibley Sparc (and possibley PPC). + + Vserver: http://www.solucorp.qc.ca/miscprj/s_context.hc + Mailing List: http://www.solucorp.qc.ca/mlist/index.hc?list=vserver + FTP Downloads: ftp://ftp.solucorp.qc.ca/pub/vserver/ + + My Links/Stuff: http://www.paul.sladen.org/vserver/ + + -- Paul Sladen , Fri, 23 Aug 2002 01:47:41 +0100 --- vserver-0.21.orig/debian/changelog +++ vserver-0.21/debian/changelog @@ -0,0 +1,12 @@ +vserver (0.21-1) experimental; urgency=low + + * Initial Packaging for Debian + * Adjusted the Makefile to fix $DESTDIR problems.. + * installed newvserver as newvserver-redhat + * Patch vserver mountproc() with devpts -o gid=5,mode=620 + and others from http://www.paul.sladen.org/vserver/debian/ + * Added top-level "make tests" + * Now fetchs FAQ and Changelog down from the interweb by wget + + + -- Paul Sladen Fri, 23 Aug 2002 01:47:41 +0100 --- vserver-0.21.orig/debian/dirs +++ vserver-0.21/debian/dirs @@ -0,0 +1,6 @@ +usr/bin +usr/sbin +etc/vservers +var/lock/subsys/rebootmgr +var/lock/subsys/vservers +vservers --- vserver-0.21.orig/debian/docs +++ vserver-0.21/debian/docs @@ -0,0 +1,5 @@ +README +TODO +doc/FAQ.txt +doc/changelog.txt +doc/intro.txt --- vserver-0.21.orig/debian/rules +++ vserver-0.21/debian/rules @@ -0,0 +1,130 @@ +#!/usr/bin/make -f +# Sample debian/rules that uses debhelper. +# GNU copyright 1997 by Joey Hess. +# +# This version is for a hypothetical package that builds an +# architecture-dependant package, as well as an architecture-independent +# package. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# This is the debhelper compatibility version to use. +export DH_COMPAT=3 + + + +ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS))) + CFLAGS += -g +endif +ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) + INSTALL_PROGRAM += -s +endif + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build-arch: configure-stamp build-arch-stamp +build-arch-stamp: + dh_testdir + + $(MAKE) install DESTDIR=$(CURDIR)/debian/vserver + + touch build-arch-stamp + +build-indep: configure-stamp build-indep-stamp +build-indep-stamp: + dh_testdir + touch build-indep-stamp + +build: build-arch build-indep + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + -$(MAKE) clean + + dh_clean + +install: DH_OPTIONS= +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/vserver. + $(MAKE) install DESTDIR=$(CURDIR)/debian/vserver + +# dh_movefiles + +# Build architecture-independent files here. +# Pass -i to all debhelper commands in this target to reduce clutter. +binary-indep: build install +# dh_testdir -i +# dh_testroot -i +# dh_installdebconf -i +# dh_installdocs -i +# dh_installexamples -i +# dh_installmenu -i +# dh_installlogrotate -i +# dh_installemacsen -i +# dh_installpam -i +# dh_installmime -i +# dh_installinit -i +# dh_installcron -i +# dh_installman -i +# dh_installinfo -i +# dh_undocumented -i +# dh_installchangelogs -i +# dh_link -i +# dh_compress -i +# dh_fixperms -i +# dh_installdeb -i +# dh_perl -i +# dh_gencontrol -i +# dh_md5sums -i +# dh_builddeb -i + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir -a + dh_testroot -a +# dh_installdebconf -a + dh_installdocs -a +# dh_installexamples -a +# dh_installmenu -a +# dh_installlogrotate -a +# dh_installemacsen -a +# dh_installpam -a +# dh_installmime -a + dh_installinit -a +# dh_installcron -a +# dh_installman -a +# dh_installinfo -a +# dh_undocumented -a filetime.8 ifspec.8 listdevip.8 newvserver.8 \ + readlink.8 save_s_context.8 showattr.8 showperm.8 vbuild.8 \ + vdu.8 vfiles.8 vkill.8 vreboot.8 vunify.8 + dh_installchangelogs -a + dh_strip -a + dh_link -a + dh_compress -a + dh_fixperms -a +# dh_makeshlibs -a + dh_installdeb -a +# dh_perl -a + dh_shlibdeps -a + dh_gencontrol -a + dh_md5sums -a + dh_builddeb -a + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure --- vserver-0.21.orig/debian/control +++ vserver-0.21/debian/control @@ -0,0 +1,44 @@ +Source: vserver +Section: admin +Priority: optional +Maintainer: Paul Sladen +Build-Depends: debhelper (>> 3.0.0) +Standards-Version: 3.5.2 + +Package: vserver +Architecture: any +Depends: ${shlibs:Depends}, libc6 (>= 2.2.5-5 ) +Description: multiple vservers on one host, at full speed + These are the userspace utilities to support the vservers linux + kernel patch. + . + The patch adds vservers (separate contexts) for running multiple + virtual servers on one host machine at full speed using only one + kernel. + . + This works on Intel and possibley Sparc. + . + Vserver: http://www.solucorp.qc.ca/miscprj/s_context.hc + Mailing List: http://www.solucorp.qc.ca/mlist/index.hc?list=vserver + FTP Downloads: ftp://ftp.solucorp.qc.ca/pub/vserver/ + . + My Links/Stuff: http://www.paul.sladen.org/vserver/ + +Package: vserver-doc +Architecture: all +Description: Documentation for vserver + These are the userspace utilities to support the `vservers' linux + kernel patch. + . + The patch adds vservers (separate contexts) for running multiple + virtual servers on one host machine at full speed using only one + kernel. + . + This works on Intel and possibley Sparc. + . + Vserver: http://www.solucorp.qc.ca/miscprj/s_context.hc + Mailing List: http://www.solucorp.qc.ca/mlist/index.hc?list=vserver + FTP Downloads: ftp://ftp.solucorp.qc.ca/pub/vserver/ + . + My Links/Stuff: http://www.paul.sladen.org/vserver/ + --- vserver-0.21.orig/debian/copyright +++ vserver-0.21/debian/copyright @@ -0,0 +1,27 @@ +This package was debianized by Paul Sladen on +Fri, 23 Aug 2002 01:54:44 +0000. + +It was downloaded from: ftp://ftp.solucorp.qc.ca/pub/vserver/ + +Upstream Author(s): Jacques Gelinas + +Copyright: + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 dated June, 1991. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. + +On Debian GNU/Linux systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. + + --- vserver-0.21.orig/debian/vserver-doc.docs +++ vserver-0.21/debian/vserver-doc.docs @@ -0,0 +1,2 @@ +#DOCS# + --- vserver-0.21.orig/debian/vserver-doc.files +++ vserver-0.21/debian/vserver-doc.files @@ -0,0 +1,2 @@ +#DOCS# + --- vserver-0.21.orig/debian/watch +++ vserver-0.21/debian/watch @@ -0,0 +1,3 @@ +# Site Directory Pattern Version Script +version=2 +ftp.solucorp.qc.ca /pub/vserver/ vserver-(.*)\.tar\.gz debian uupdate --- vserver-0.21.orig/missing-manpages.list +++ vserver-0.21/missing-manpages.list @@ -0,0 +1,14 @@ +filetime.8 +ifspec.8 +listdevip.8 +newvserver.8 +readlink.8 +save_s_context.8 +showattr.8 +showperm.8 +vbuild.8 +vdu.8 +vfiles.8 +vkill.8 +vreboot.8 +vunify.8 --- vserver-0.21.orig/newvserver-debian +++ vserver-0.21/newvserver-debian @@ -0,0 +1,569 @@ +#!/bin/sh +VERSION='0.3.2' +# +# Copyright (C) 2002, Mark Lawrence +# Copyright (C) 2002, Paul Sladen +# +# Install a virtual debian server (vserver) from a debian HTTP/FTP archive +# +# ---------------------------------------------------------------- +# Configurable items: + +# Root directory of your virtual servers (probably shouldn't change this) +VSERVER_ROOT="/vservers" + +# Packages to install in addition to the base defaults +# MUST INCLUDE ALL DEPENDENCIES (seperated by "," commas) +INSTALL_PACKAGES="less,dnsutils,wget,bzip2,ssh,rsync,libssl0.9.6,libdns5,libisc4,liblwres1,bind9-host,zlib1g,libbz2-1.0,traceroute" + +# Packages installed from within the vserver after it has +# been setup (seperated by "," commas) +EXTRA_PACKAGES="emacs20,lynx-ssl" + +# Packages to remove from the base defaults (seperated by "," commas) +REMOVE_PACKAGES="dhcp-client,lilo,makedev,pcmcia-cs,ppp,pppconfig,pppoe,pppoeconf,setserial,syslinux,nano,fdutils,iptables,libpcap0,pciutils" + +# sysvinit services relating to hardware access to remove +REMOVE_LINKS="klogd hwclock.sh setserial urandom networking umountfs halt reboot" + +# Architecture: overide on non-Debian host such as Redhat +# otherwise dpkg will detect whether we are i386/powerpc/sparc/etc +ARCH="" + +# Which debian distribution (warning: this has only been tested with woody) +DIST="woody" + +# Local or nearest location of a debian mirror (must include the `/debian') +MIRROR="http://ftp.uk.debian.org/debian" + +# Default network interface for vservers: +INTERFACE="eth0" + +# Copy vreboot/vhalt/vshutdown utility into /usr/local/sbin/ +COPY_VREBOOT="true" + +# ---------------------------------------------------------------- +# Nothing from here on should need changing. +# ---------------------------------------------------------------- + +# NOTE: debootstrap handles multiple MIRRORs, so there is no reason why +# we shouldn't too--that way we could just let it build /etc/apt/sources.list + +usage () +{ + cat << EOF 1>&2 +usage: ${0##*/} [OPTIONS] --hostname x --domain y.z --ip 1.2.3.4 + (see --help for more information) +EOF +} +full_usage () +{ + cat << EOF +Usage: ${0##*/} [OPTIONS] --hostname x --domain y.z --ip 1.2.3.4 +Creates a new Debian vserver by downloading packages via HTTP/FTP + +Options: + -h, --help this help + -V, --version copyright and version information + --arch set target architecture (eg. --arch "i386") + (autodetected on Debian host if dpkg available) + --copy-vreboot install "vreboot/vshutdown/vhalt" + --no-copy-vreboot don't install "vreboot/vshutdown/vhalt" + --dist defaults to "woody", passed to debootstrap. + --fakeinit use "/sbin/init" to boot vserver + --interface interface for IP addresses (if not "eth0") + --mirror Debian HTTP/FTP mirror (including the /debian) + --sshkeys copy pub-keys to "/root/.ssh/authorized_keys" + -v, --verbose show extra output during setup + --vsroot location of "/vserver/" directory +Required: + --hostname hostname for new vserver (eg. "alpha") + --domain dns domain for new vserver (eg. "example.com") + --ip IPv4 address for new vserver + +EOF +} +full_version () +{ + cat << EOF +${0##*/} version $VERSION +Copyright (c) 2002 Mark Lawrence +Copyright (c) 2002 Paul Sladen + +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 +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +EOF +} +parse_args () +{ + while [ $# -gt 0 ] ; do + #echo "parse_args() doing :$#: :$1: :$*:" + case "$1" in + --help|-h) + full_usage + shift + exit 0 + ;; + --version|-V) + full_version + shift + exit 0 + ;; + --arch) + case "$2" in + [a-z]*) + ARCH="$2" + ;; + *) + echo "${0##*/} error: $1 overrides dpkg autodetect on non-Debian host-servers" 1>&2 + echo 'e.g. "i386"' 1>&2 + exit 1 + ;; + esac + shift 2 + ;; + --copy-vreboot) + COPY_VREBOOT="true" + shift + ;; + --no-copy-vreboot) + COPY_VREBOOT="" + shift + ;; + --dist) + case "$2" in + [a-z]*) + DIST="$2" + if [ "woody" != "$2" ]; then + echo "${0##*/} warning: I only know how to do \"woody\", be careful!" 1>&2 + fi + ;; + *) + echo "${0##*/} error: $1 requires a Debian distribution" 1>&2 + echo 'e.g. "woody"' 1>&2 + exit 1 + ;; + esac + shift 2 + ;; + --domain) + case "$2" in + [a-z]*[a-z]) + VDOMAIN="$2" + ;; + *) + echo "${0##*/} error: $1 requires a dns domain-name" 1>&2 + echo 'e.g. "example.com"' 1>&2 + exit 1 + ;; + esac + shift 2 + ;; + --fakeinit) + # Note space at beginning--this gets tagged straight on + FAKEINIT=" fakeinit" + shift + ;; + --hostname) + case "$2" in + [a-z]*[a-z0-9]) + VHOST="$2" + ;; + *) + echo "${0##*/} error: $1 must be a hostname for the vserver" 1>&2 + echo 'e.g. "alpha"' 1>&2 + exit 1 + ;; + esac + shift 2 + ;; + --interface) + case "$2" in + [a-z]*) + INTERFACE="$2" + ;; + *) + echo "${0##*/} error: $1 must be followed by a network interface" 1>&2 + echo 'e.g. "eth1"' 1>&2 + exit 1 + ;; + esac + shift 2 + ;; + --ip) + # This does for an octet: ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) ;-) + case "$2" in + [0-9]*.[0-9]*.[0-9]*.[0-9]*) + IP="$2" + ;; + *) + echo "${0##*/} error: $1 requires a single IPv4 e.g. \"192.168.100.1\"" 1>&2 + exit 1 + ;; + esac + shift 2 + ;; + --mirror) + case "$2" in + [hf]*://*) + MIRROR="$2" + ;; + *) + echo "${0##*/} error: $1 requires a debian mirror" 1>&2 + echo 'e.g. "http://ftp.uk.debian.org/debian"' 1>&2 + exit 1 + ;; + esac + shift 2 + ;; + --verbose|-v) + export verbose="true" + shift + ;; + --sshkeys) + if [ -f "$2" ]; then + SSH_KEYS="$2" + else + echo "${0##*/} error: $1 must be followed by a valid public-key-file!" 1>&2 + echo 'e.g. "/root/.ssh/id_dsa.pub"' 1>&2 + exit 1 + fi + shift 2 + ;; + --vsroot) + case "$2" in + /*) + if [ -d "$2" ]; then + VSERVER_ROOT="$2" + else + echo "${0##*/} error: $1 needs a valid absolute directory" 1>&2 + echo 'e.g. "/vservers"' 1>&2 + exit 1 + fi + ;; + *) + echo "${0##*/} error: $1 needs a valid absolute directory" 1>&2 + echo 'e.g. "/vservers"' 1>&2 + exit 1 + ;; + esac + shift 2 + ;; + -*) + usage + exit 1 + ;; + ?*) + usage + exit 1 + ;; + esac + done +} + +parse_args $@ + +if ! [ -n "$VHOST" -a -n "$VDOMAIN" -a -n "$IP" ]; then + echo "${0##*/} error: --hostname, --domain and --ip are required" 1>&2 + usage + exit 1 +fi + +# Strip final slashes off a couple of things +MIRROR="${MIRROR%/}" +VSERVER_ROOT="${VSERVER_ROOT%/}" + +# Check we've got debootstrap available +if [ ! -x /usr/sbin/debootstrap ]; then + cat << EOF 1>&2 +${0##*/}: Requires the debootstrap package to bootstrap Debian + Debian Host: apt-get install debootstrap + RPM Host: rpm -i http://people.debian.org/~blade/install/debootstrap/debootstrap-0.1.17.3-2.i386.rpm +EOF + exit 1 +fi + +if ! cat /proc/self/status | grep '^s_context:[^0-9]0$'; then + echo "${0##*/} error:" + echo " Must be run from the host server (security context 0)" 1>&2 + echo ' on a "vserver/ctx-patch" enabled kernel' 1>&2 + echo ' See: http://www.solucorp.qc.ca/miscprj/s_context.hc' 1>&2 + exit 1 +fi + +if [ -x /usr/bin/id ] && [ `id -u` -ne 0 ]; then + echo "${0##*/} error: Must be run as root!" 1>&2 + exit 1 +fi + +# check for /vserver/$VHOST/etc/ incase we are on pre-mounted LVM partition +# (used to just check for "/vserver/$VHOST/" existing +if [ -d "$VSERVER_ROOT/$VHOST/etc/" -o -f "/etc/vservers/$VHOST.conf" ] ; then + cat << EOF 1>&2 +${0##*/} error: Virtual Server "$VHOST" appears to already exist + check "/etc/vservers/$VHOST.conf" or "/vservers/$VHOST/etc/"; +EOF + exit 1 +fi + +# This is used to keep a cache of the downloaded .deb packges for next install +if [ -d "$VSERVER_ROOT/ARCHIVES" ]; then + mkdir -p "$VSERVER_ROOT/$VHOST/var/cache/apt/archives" + cp -a "$VSERVER_ROOT/ARCHIVES/"*.deb "$VSERVER_ROOT/$VHOST/var/cache/apt/archives" +fi + +# We only want to pass the Architecture if we need to (autodectected otherwise) +if [ -n "$ARCH" ]; then + ARCH_ARGUMENT="--arch $ARCH" +fi + +# Fire off `debootstrap' to do all the hard work +# like downloading and installing +if ! /usr/sbin/debootstrap $ARCH_ARGUMENT \ + "--include=$INSTALL_PACKAGES" "--exclude=$REMOVE_PACKAGES" \ + "$DIST" "$VSERVER_ROOT/$VHOST" "$MIRROR" ; then + echo "${0##*/}: error: debootstrap failure. Cannot continue." + exit 1 +fi + +# Make it so that apt and friends work +cat << EOF > "$VSERVER_ROOT/$VHOST/etc/apt/sources.list" +deb $MIRROR/ stable main non-free contrib +deb-src $MIRROR/ stable main non-free contrib + +deb http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free +deb-src http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free + +deb http://security.debian.org stable/updates main contrib non-free + +EOF + +# Fix up the available device nodes, for security +if cd "$VSERVER_ROOT/$VHOST/dev"; then + tar cfp /tmp/dev.tar.$$ full null ptmx random tty urandom zero + rm -rf $VSERVER_ROOT/$VHOST/dev/* + tar xfp /tmp/dev.tar.$$ + rm /tmp/dev.tar.$$ + mkdir pts + mkdir shm +fi + +# Give the new host a hostname +echo "$VHOST" > "$VSERVER_ROOT/$VHOST/etc/hostname" + +# Set up the /etc/hosts file (needed for some parts of the base-config) +cat << EOF > "$VSERVER_ROOT/$VHOST/etc/hosts" +# /etc/hosts + +127.0.0.1 localhost +$IP $VHOST.$VDOMAIN $VHOST + +# The following lines are desirable for IPv6 capable hosts +# (added automatically by netbase upgrade) + +::1 ip6-localhost ip6-loopback +fe00::0 ip6-localnet +ff00::0 ip6-mcastprefix +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters +ff02::3 ip6-allhosts + +EOF + +# grab DNS servers from the host-server for `resolv.conf' +(echo search $VDOMAIN ; grep '^nameserver' /etc/resolv.conf) \ + > "$VSERVER_ROOT/$VHOST/etc/resolv.conf" + +# If there is a proxy server statement in-use in the Host server, copy it across +if [ -f /etc/apt/apt.conf ]; then + cp /etc/apt/apt.conf $VSERVER_ROOT/$VHOST/etc/apt/apt.conf +fi + +# This old uname was putting the name of the *host* into the vserver motd +# uname -a > $VSERVER_ROOT/$VHOST/etc/motd + +# Create a shorter motd (uname -a would give name of host-server) +echo "Debian GNU/Linux ($DIST/$(uname -m)) $VHOST.$VDOMAIN" \ + > "$VSERVER_ROOT/$VHOST/etc/motd" + +# Create a dummy fstab +cat << EOF > "$VSERVER_ROOT/$VHOST/etc/fstab" +# /etc/fstab: static file system information. +# +# +proc /proc proc defaults 0 0 +EOF + +# The new vserver patch now automatically mounts /proc +# Debian needs /dev/pts mounting "gid=5,mode=620" by vserver +cat << EOF > "$VSERVER_ROOT/$VHOST/etc/mtab" +/dev/hdv1 / vfs none 0 0 +proc /proc proc rw 0 0 +devpts /dev/pts devpts rw,gid=5,mode=620 0 0 +EOF + +# Create a reduced inittab that doesn't start getty on the consoles +cat << EOF > "$VSERVER_ROOT/$VHOST/etc/inittab" +# /etc/inittab: init(8) configuration. + +# The default runlevel. +id:2:initdefault: + +# Boot-time system configuration/initialization script. +# This is run first except when booting in emergency (-b) mode. +si::sysinit:/etc/init.d/rcS + +# What to do in single-user mode. +~~:S:wait:/sbin/sulogin + +# /etc/init.d executes the S and K scripts upon change +# of runlevel. +# +# Runlevel 0 is halt. +# Runlevel 1 is single-user. +# Runlevels 2-5 are multi-user. +# Runlevel 6 is reboot. + +l0:0:wait:/etc/init.d/rc 0 +l1:1:wait:/etc/init.d/rc 1 +l2:2:wait:/etc/init.d/rc 2 +l3:3:wait:/etc/init.d/rc 3 +l4:4:wait:/etc/init.d/rc 4 +l5:5:wait:/etc/init.d/rc 5 +l6:6:wait:/etc/init.d/rc 6 + +EOF + +# By default the Debian Install script runs zillions of cron jobs at +# 0625 every morning. On a system with lots of vservers all trying to +# scan the disk at the same time this causes $MAJOR disk-thrash. So +# we randomize it a bit so that they run evenly between 1am and 7am, +# avoiding the 5minutes either side of the hour when other stuff tends +# to be scheduled. (BTW, this solution is Overkill!) + +# This looks over complicated--and it probably is...: +# +# a) We want the DAILY jobs to run between :05 and :55 minutes past +# b) We want the WEEKLY job 3-5 minutes after the DAILY. +# c) And the MONTHLY job 3-5 minutes after that. +# d) Make sure all three jobs are started by 55minutes past (five-to) +# ...if they were ever to all run on the same day! + +d1=$(($RANDOM % 3 + 3)); # between 3 and 5 +d2=$(($RANDOM % 3 + 3)); # between 3 and 5 +dt=$((50 - $d1 - $d2)); # between 0 and 44 + +DAILY=$(($RANDOM % $dt + 5)) # between 5 and 49 +WEEKLY=$(($DAILY + $d1)) # between 8 and 52 +MONTHLY=$(($WEEKLY + $d2)) # between 11 and 55 + +HOUR=$(($RANDOM % 6 + 1)) # between 1 and 7 (AM localtime) + +# Create replacement /etc/crontab with randomized times above +cat << EOF > /etc/crontab +# /etc/crontab: system-wide crontab +# Unlike any other crontab you don't have to run the \`crontab\' +# command to install the new version when you edit this file. +# This file also has a username field, that none of the other crontabs do. + +SHELL=/bin/sh +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +# m h dom mon dow user command +$DAILY $HOUR * * * root test -e /usr/sbin/anacron || run-parts --report /etc/cron.daily +$WEEKLY $HOUR * * 7 root test -e /usr/sbin/anacron || run-parts --report /etc/cron.weekly +$MONTHLY $HOUR 1 * * root test -e /usr/sbin/anacron || run-parts --report /etc/cron.monthly + +EOF + +# Create default /etc/vservers entry +cat << EOF > /etc/vservers/$VHOST.conf +S_HOSTNAME="$VHOST" +IPROOT="$IP" +IPROOTDEV="eth0" +ONBOOT="yes" +S_NICE="" +S_FLAGS="lock nproc$FAKEINIT" +ULIMIT="-H -u 256 -n 1024" +S_CAPS="CAP_NET_RAW" + +# *NOT* DNS domain name, for NIS only +S_DOMAINNAME="" + +EOF + +if [ -n "$EXTRA_PACKAGES" ]; then + EXTRA_PACKAGES_INSTALL="apt-get --assume-yes install ${EXTRA_PACKAGES//,/ }" +fi + +# ------------------------------------------------------------ +# From here on we do things live in the server +# Generate the script that runs the rest of the setup from within the +# virtual server. +cat << EOF > $VSERVER_ROOT/$VHOST/vserver-config.sh +#!/bin/sh + +dselect update + +tzsetup -y + +dpkg-reconfigure passwd + +tasksel + +rm -f /etc/exim/exim.conf +eximconfig + +# because the --exclude flag doesn\'t seem to work on debootstrap +apt-get --assume-yes --purge remove `echo $REMOVE_PACKAGES | sed -e 's/,/ /g'` + +for link in $REMOVE_LINKS +do + update-rc.d -f \$link remove +done + +$EXTRA_PACKAGES_INSTALL + +EOF + +# Run the above commands from within the server +chmod 755 $VSERVER_ROOT/$VHOST/vserver-config.sh +vserver $VHOST exec /vserver-config.sh +rm -f $VSERVER_ROOT/$VHOST/vserver-config.sh + +# If you need to install your SSH management keys into the vserver +if [ -f "$SSH_KEYS" ]; then + mkdir -p "$VSERVER_ROOT/$VHOST/root/.ssh" + chmod 700 "$VSERVER_ROOT/$VHOST/root/.ssh/" + cat "$SSH_KEYS" >> "$VSERVER_ROOT/$VHOST/root/.ssh/authorized_keys" + chmod 600 "$VSERVER_ROOT/$VHOST/root/.ssh/authorized_keys" +fi + +# Install the vreboot/rebootmgr utility--hopefully this will disappear soon +VREBOOT_LOCATION="/usr/lib/vserver/vreboot" +if [ "$COPY_VREBOOT" == "true" -a -x "$VREBOOT_LOCATION" ]; then + cp -a "$VREBOOT_LOCATION" "$VSERVER_ROOT/$VHOST/usr/local/sbin/" + chmod 750 "$VSERVER_ROOT/$VHOST/usr/local/sbin/vreboot" + # ln -s "$VSERVER_ROOT/$VHOST/usr/local/sbin/"{vshutdown,vreboot} + # ln -s "$VSERVER_ROOT/$VHOST/usr/local/sbin/"{vhalt,vreboot} +fi + +# Stop all the processes that were started inside the server +export PREVLEVEL=2 +vserver $VHOST exec /etc/init.d/rc 0 +vserver $VHOST stop + +# Populate the archive for future virtual servers +if [ ! -d $VSERVER_ROOT/ARCHIVES ]; then + mkdir $VSERVER_ROOT/ARCHIVES +fi +cp $VSERVER_ROOT/$VHOST/var/cache/apt/archives/*.deb $VSERVER_ROOT/ARCHIVES + +echo +echo "You should now adjust /etc/vservers/$VHOST.conf to suit your needs," +echo "or else just go ahead and type \`vserver $VHOST start' to start" +echo "your new virtual server. debian/rules!" +echo