#! /bin/bash -e # Copyright (C) 2003 Enrico Scholz # # 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; version 2 of the License. # # This program 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 program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. : ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars} test -e "$UTIL_VSERVER_VARS" || { echo "Can not find util-vserver installation; aborting..." exit 1 } . "$UTIL_VSERVER_VARS" . "$PKGLIBDIR/functions" tmp=$(getopt -o d:r: --long force,dir:,pkgcfg:,hostname:,iproot:,iprootmask:,iprootbcast:,iprootdev:,help,version \ -n "$0" -- "$@") || exit 1 eval set -- "$tmp" distrib= root=/vservers dir= name= hostname= iproot= iprootmask= iprootbcast= iprootdev= force= pkgcfg= function makeInode { mknod -m$6 $1/$2 $3 $4 $5 } function installBasePackages { local name="$1" local dir="$2" test "$dir" != / || return for filelist in "$dir"/*; do test -e "$filelist" || continue local idx=0 local can_fail=false local flags= set -- $(<$filelist) while test "$#" -gt 0; do case "$1" in --reinstall) flags='--reinstall';; --can-fail) can_fail=true;; *) break;; esac shift done "$_VAPT_GET" "$name" -- install $flags "$@" || $can_fail done } while true; do case "$1" in -d) distrib="$2"; shift 2;; -r) root="$2"; shift 2;; --pkgcfg) pkgcfg="$2"; shift 2;; --force) force=1; shift;; --dir) dir="$2"; shift 2;; --hostname) hostname="$2"; shift 2;; --iproot) iproot="$2"; shift 2;; --iprootmask) iprootmask="$2"; shift 2;; --iprootbcast) iprootbcast="$2"; shift 2;; --iprootdev) iprootdev="$2"; shift 2;; --help) showHelp; exit 0;; --version) showVersion; exit 0;; --) shift; break;; *) echo "Internal error!"; exit 1;; esac done test "$#" != 0 || { echo "No vserver name given" >&2 exit 1 } test "$#" = 1 || { echo "Too much parameters" >&2 exit 1 } name=$1 test "$dir" || dir=$name test "$pkgcfg" || pkgcfg=$root/.pkg/$name vdir=$root/$dir test ! -d "$vdir" || { test "$force" && mv "$vdir" "$vdir".bak } confdir="$CONFDIR/$name" test ! -d "$confdir" || { test "$force" && mv "$confdir" "$confdir".bak } test ! -d "$vdir" -a ! -d "$confdir" || { echo "vserver-topdirectory and/or configuration exist already; " echo "please try to use '--force', or remove them manually" exit 1 } >&2 test "$distrib" || { if test -e /etc/redhat-release; then set -- $(cat /etc/redhat-release) distrib=rh$5 else echo "Can not determine distribution; please specify it manually" echo "with the '-d' option" exit 1 fi >&2 } findFile INITPRE $CONFDIR/.distributions/$distrib/initpre $DISTRIBDIR/$distrib/initpre "" findFile INITPOST $CONFDIR/.distributions/$distrib/initpost $DISTRIBDIR/$distrib/initpost "" findFile DEVDESCR $CONFDIR/.distributions/$distrib/devs $DISTRIBDIR/$distrib/devs $DISTRIBDIR/defaults/devs findDir APTTMPL $CONFDIR/.distributions/$distrib/apt $DISTRIBDIR/$distrib/apt findDir RPMTMPL $CONFDIR/.distributions/$distrib/rpm $DISTRIBDIR/$distrib/rpm $DISTRIBDIR/defaults/rpm findDir EXECDIR $CONFDIR/.distributions/$distrib/execdir $DISTRIBDIR/$distrib/execdir / findDir RPMLIB $CONFDIR/.distributions/$distrib/rpmlib $DISTRIBDIR/$distrib/rpmlib / findDir PKGDIR $CONFDIR/.distributions/$distrib/pkgs $DISTRIBDIR/$distrib/pkgs / mkdir -p "$confdir"/apps/pkgmgmt "$vdir"/{dev,/var/lib/rpm,/etc} \ "$pkgcfg"/{rpm/{etc,state},apt/{etc,archives/partial,cache,state/lists/partial}} while read spec; do makeInode "$vdir"/dev $spec done <$DEVDESCR ln -s "$vdir" "$confdir"/vdir for i in hostname iproot iprootmask iprootbcast iprootdev; do i_=\$$i eval "v=$i_" test -z "$v" || echo $v >"$confdir/$i" done ln -s "$pkgcfg" "$confdir/apps/pkgmgmt/base" test "$EXECDIR" = / || ln -s "$EXECDIR" "$confdir/apps/pkgmgmt/execdir" test "$RPMLIB" = / || ln -s "$RPMLIB" "$confdir/apps/pkgmgmt/rpmlib" cp -a "$RPMTMPL/"* "$pkgcfg/rpm/etc/" cp -a "$APTTMPL/"* "$pkgcfg/apt/etc/" test -z "$INITPRE" || "$INITPRE" "$name" "$_VAPT_GET" "$name" -- update installBasePackages "$name" "$PKGDIR" "$_VAPT_GET" "$name" -- dist-upgrade test -z "$INITPOST" || "$INITPOST" "$name"