3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 test ! $mod "$i" || { file=$i; break; }
31 test -z "$i" -o "$file" || {
32 echo "Can not find file for '$var'; aborting"
49 function getPhysicalDir
51 ( set -P && cd "$1" && pwd )
54 function _pkgMountBindDir()
56 test "$1" != "$2" || return 0
58 mount -n --bind "$1" "$2"
61 function _pkgSetVarsBase
65 echo "not supported yet"
69 BASEDIR=$CONFDIR/$vserver
70 test -d "$BASEDIR" || {
71 echo "Can not find configuration-directory"
76 test -d "$VDIR" || VDIR=/vservers/$vserver
77 VDIR=$(getPhysicalDir "$VDIR")
79 PKGDIR=$BASEDIR/apps/pkgmgmt
80 test -d "$PKGDIR" || {
81 echo "Can not find configuration-directory for package-managment tools"
85 findDir EXECDIR $PKGDIR/execdir /
90 if test -z "$WORKAROUND_106057"; then
93 _rpmdb_mntpoint=/.rpmdb
97 function _pkgSetVarsRPM
101 echo "not supported yet"
106 findDir RPMETCDIR $PKGDIR/rpmetc $PKGDIR/base/rpm/etc /etc/rpm
107 findDir RPMSTATEDIR $PKGDIR/rpmstate $PKGDIR/base/rpm/state
109 findDir RPMLIBDIR $PKGDIR/rpmlib /
111 RPMSTATEDIR=$(getPhysicalDir "$RPMSTATEDIR")
112 RPMETCDIR=$(getPhysicalDir "$RPMETCDIR")
117 function _pkgSetVarsApt
121 echo "not supported yet"
126 findDir APTETCDIR $PKGDIR/aptetc $PKGDIR/base/apt/etc /etc/apt
127 findDir APTSTATEDIR $PKGDIR/aptstate $PKGDIR/base/apt/state
128 findDir APTCACHEDIR $PKGDIR/aptcache $PKGDIR/base/apt/cache
129 findDir APTARCHIVDIR $PKGDIR/aptarchives $PKGDIR/base/apt/archives /var/cache/apt/archives
134 function _pkgMountBase
139 function _pkgMountApt
144 function _pkgMountRPM
146 _pkgMountBindDir "$RPMETCDIR" /etc/rpm
147 test "$RPMLIBDIR" = "/" || _pkgMountBindDir "$RPMLIBDIR" /usr/lib/rpm
149 "$_SECURE_MOUNT" --chroot "$VDIR" -n --secure --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
150 test -z "$WORKAROUND_106057" || mount -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
153 function _pkgSetEnvBase
155 test "$EXECDIR" = "/" || {
157 LD_LIBRARY_PATH=$EXECDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
160 export PATH LD_LIBRARY_PATH
163 function _pkgSetEnvApt
168 function _pkgSetEnvRPM
171 RPM_FAKE_NAMESPACE_MOUNTS=$_rpmdb_mntpoint
172 RPM_BINARY=$_VRPM_PRELOAD
174 export CUR_VSERVER RPM_FAKE_NAMESPACE_MOUNTS RPM_BINARY
186 rpm) _pkgSetVarsRPM;;
187 apt) _pkgSetVarsApt;;
188 *) echo "Unknown packaging flavor"; exit 1;;
209 _PKG_VSERVER=$vserver
212 function getAllVservers
217 for i in $CONFDIR/*; do
218 test -d "$i" || continue
219 test ! -e "$i"/disabled || continue
220 test -d "$i"/vdir || continue
222 eval "$var=\"$var ${i##$CONFDIR/}\""
226 ## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
227 function getVserverStatus
229 test -r "$1"/run || return 1
230 eval read "$2" <"$1"/run
232 test "$3" || return 0
233 local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$ctx" | $_WC -l )
236 test "$4" -a $_tmp = 0 || return 0
237 _tmp=$(readlink "$1/run")
238 test "$_tmp" || return 1
243 ## Usage: isVserverRunning <vdir> [<ctx-varname>]
244 function isVserverRunning
248 getVserverStatus "$1" ctx procnum 1 || return 1
249 test $procnum != 0 || return 1
250 test -z "$2" || eval "$2"=\$ctx