#! /bin/bash # $Id$ # 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. set -e : ${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:,lockfile:,help,version \ -n "$0" -- "$@") || exit 1 eval set -- "$tmp" distrib= root= root_rel=1 dir= name= force= pkgcfg= pkgcfgbase_rel= lockfile= function makeDevEntry { local dst=$1/$2 case "$3" in c|b) mknod -m$6 "$dst" $3 $4 $5;; d) mkdir -p -m$4 "$dst";; f) touch "$dst" chmod $4 "$dst" ;; *) echo "Unknown dev-entry mode '$3'" >&2 false ;; esac } function installBasePackages { local name="$1" local dir="$2" test "$dir" != / || return for filelist in "$dir"/*; do test -f "$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 -y $flags $* || $can_fail done } function populateDirectory { local dst=$1 local i shift for i; do local file= for file in "$i"/*; do test -e "$file" || continue cp -a "$file" "$dst/" done done } function prepareRPMDb { rpmdb_path=/dev test -z "$WORKAROUND_106057" || { rpmdb_path=/.rpmdb mkdir -p "$rpmdb_path" } mkdir -p "$vdir$rpmdb_path" } function importGPGPubKeys { local dst=$1 local pkgs declare -a pkgs local i shift for i; do local file= for file in "$i"/*; do test -f "$file" || continue pkgs[${#pkgs[*]}]=$file done done test "$pkgs" || return 0 "$_VRPM" "$dst" -- --import "${pkgs[@]}" } 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;; --lockfile) lockfile="$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 "$root" || { for item in "$CONFDIR/.defaults/vdirbase 1" "/vservers"; do set -- $item root=$1 root_rel=$2 test ! -d "$root" || break done } test -d "$root" || { echo "Root-directory '$root' does not exists or is invalid" exit 1 } test "$lockfile" || lockfile=/var/run/vservers/$name test "$pkgcfg" || { pkgcfgbase= for item in "$CONFDIR/.defaults/apps/pkgmgmt/base 1" "$root/.pkg"; do set -- $item pkgcfgbase=$1 pkgcfgbase_rel=$2 test ! -d "$pkgcfgbase" || break done test -d "$pkgcfgbase" || { echo "pkgcfgbase-dir '$pkgcfgbase' does not exists or is invalid" exit 1 } pkgcfg="$pkgcfgbase/$name" } test "$dir" || dir=$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 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/pts,etc} \ "$pkgcfg"/{rpm/{etc,state},apt/{etc,archives/partial,cache,state/lists/partial}} ln -s "$lockfile" "$confdir"/run prepareRPMDb ## HACK AND SECURITY ALERT! ## /var/lib/rpm is hardcoded into apt-get which does not honor the ## %_dbpath variable therefore ## see ??? mkdir -p "$vdir"/var/lib ln -s "$rpmdb_path" "$vdir"/var/lib/rpm while read spec; do makeDevEntry "$vdir"/dev $spec done <$DEVDESCR ln -s "$vdir" "$confdir"/vdir for i in hostname; 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" populateDirectory "$pkgcfg/apt/etc" "$DISTRIBDIR/$distrib/apt" "$CONFDIR/.distributions/$distrib/apt" populateDirectory "$pkgcfg/rpm/etc" "$DISTRIBDIR/defaults/rpm" "$DISTRIBDIR/$distrib/rpm" \ "$CONFDIR/.distributions/$distrib/rpm" echo "%_dbpath $rpmdb_path" >>"$pkgcfg/rpm/etc/macros" test -z "$INITPRE" || "$INITPRE" "$name" importGPGPubKeys "$name" "$CONFDIR/.distributions/$distrib/pubkeys" "$DISTRIBDIR/$distrib/pubkeys" "$_VAPT_GET" "$name" -- update installBasePackages "$name" "$PKGDIR" "$_VAPT_GET" "$name" -- dist-upgrade -y test -z "$INITPOST" || "$INITPOST" "$name"