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.
20 declare -r _VS_NEWLINE=${_VS_NEWLINE:0-1}
32 test ! $mod "$i" || { file=$i; break; }
35 test -z "$i" -o "$file" || {
36 echo "Can not find file for '$var'; aborting"
56 test ! -s "$dst" || return 0
62 test "$tmp" -a -s "$tmp" || return 0
66 function getPhysicalDir
68 ( set -P && cd "$1" && pwd )
71 function _pkgMountBindDir()
73 test "$1" != "$2" || return 0
75 mount -n --bind "$1" "$2"
78 function _pkgSetVarsBase
82 if test -d "$vserver/vdir"; then
84 VDIR=$(getPhysicalDir "$vserver/vdir")
86 PKGDIR=$BASEDIR/apps/pkgmgmt
87 test -d "$PKGDIR" || {
88 echo "Can not find configuration-directory for package-managment tools"
91 findDir EXECDIR $PKGDIR/execdir /
93 VDIR=$(getPhysicalDir "$vserver")
98 BASEDIR=$CONFDIR/$vserver
99 test -d "$BASEDIR" || {
100 echo "Can not find configuration-directory"
105 test -d "$VDIR" || VDIR=/vservers/$vserver
106 VDIR=$(getPhysicalDir "$VDIR")
108 PKGDIR=$BASEDIR/apps/pkgmgmt
109 test -d "$PKGDIR" || {
110 echo "Can not find configuration-directory for package-managment tools"
114 findDir EXECDIR $PKGDIR/execdir /
119 if test -z "$WORKAROUND_106057"; then
122 _rpmdb_mntpoint=/.rpmdb
126 function _pkgSetVarsRPM
128 if test "$PKGDIR"; then
129 findDir RPMETCDIR $PKGDIR/rpmetc $PKGDIR/base/rpm/etc /etc/rpm
130 findDir RPMSTATEDIR $PKGDIR/rpmstate $PKGDIR/base/rpm/state
132 findDir RPMLIBDIR $PKGDIR/rpmlib /
135 findDir RPMETCDIR "$VDIR"/etc/rpm /etc/rpm
136 findDir RPMSTATEDIR "$VDIR"/var/lib/rpm
140 RPMSTATEDIR=$(getPhysicalDir "$RPMSTATEDIR")
141 RPMETCDIR=$(getPhysicalDir "$RPMETCDIR")
144 function _pkgSetVarsApt
146 if test "$PKGDIR"; then
147 findDir APTETCDIR $PKGDIR/aptetc $PKGDIR/base/apt/etc /etc/apt
148 findDir APTSTATEDIR $PKGDIR/aptstate $PKGDIR/base/apt/state
149 findDir APTCACHEDIR $PKGDIR/aptcache $PKGDIR/base/apt/cache
150 findDir APTARCHIVDIR $PKGDIR/aptarchives $PKGDIR/base/apt/archives /var/cache/apt/archives
152 findDir APTETCDIR "$VDIR"/etc/apt /etc/apt
153 findDir APTSTATEDIR "$VDIR"/var/state/apt
154 findDir APTCACHEDIR "$VDIR"/var/cache/apt
155 findDir APTARCHIVDIR "$VDIR"/var/cache/apt/archives /var/cache/apt/archives
158 findFile APT_CONFIG "$APTETCDIR"/apt.conf ""
159 test -z "$APT_CONFIG" || export APT_CONFIG
162 function _pkgMountBase
167 function _pkgMountApt
172 function _pkgMountRPM
174 _pkgMountBindDir "$RPMETCDIR" /etc/rpm
175 test "$RPMLIBDIR" = "/" || _pkgMountBindDir "$RPMLIBDIR" /usr/lib/rpm
177 "$_SECURE_MOUNT" --chroot "$VDIR" -n --secure --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
178 test -z "$WORKAROUND_106057" || mount -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
180 "$_SECURE_MOUNT" --chroot "$VDIR" -n --secure -t proc none /proc
183 function _pkgSetEnvBase
185 test "$EXECDIR" = "/" || {
187 LD_LIBRARY_PATH=$EXECDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
190 export PATH LD_LIBRARY_PATH
193 function _pkgSetEnvApt
198 function _pkgSetEnvRPM
201 RPM_FAKE_NAMESPACE_MOUNTS=$_rpmdb_mntpoint
202 RPM_BINARY=$_VRPM_PRELOAD
204 export CUR_VSERVER RPM_FAKE_NAMESPACE_MOUNTS RPM_BINARY
216 rpm) _pkgSetVarsRPM;;
217 apt) _pkgSetVarsApt;;
218 *) echo "Unknown packaging flavor"; exit 1;;
239 _PKG_VSERVER=$vserver
242 function isAvoidNamespace
244 test ! -e "$1"/namespace || return 1
245 test -e "$CONFDIR"/.defaults/nonamespace -o \
249 function getAllVservers
254 for i in $CONFDIR/*; do
255 test -d "$i" || continue
256 test ! -e "$i"/disabled || continue
257 test -d "$i"/vdir || continue
262 _tmp=( "${_tmp[@]}" "${i##$CONFDIR/}")
265 eval $1='( "${_tmp[@]}" )'
268 ## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
269 function getVserverStatus
271 test -r "$1"/run || return 1
277 test "$3" || return 0
278 local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$_ctx" | $_WC -l )
281 test "$4" -a $_tmp = 0 || return 0
282 _tmp=$($_READLINK "$1/run")
283 test "$_tmp" || return 1
288 ## Usage: isCtxRunning <ctx>
289 function isCtxRunning
291 local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l )
295 ## Usage: isVserverRunning <vdir> [<ctx-varname>]
296 function isVserverRunning
300 getVserverStatus "$1" ctx procnum 1 || return 1
301 test $procnum != 0 || return 1
302 test -z "$2" || eval "$2"=\$ctx
306 ## Called as 'getFileValue <varname> <filename>'
307 function getFileValue
309 test -r "$2" || return 0
313 ## Called as 'getFileArray <varname> <filename>'
314 function getFileArray
316 test -r "$2" || return 0
318 local IFS=$_VS_NEWLINE
319 eval "$1"='( $(< "$2") )'
322 function checkComponents
333 core) test -x "$_CHBIND" || failed=1;;
334 build) test -x "$_VSERVER_BUILD" || failed=1;;
335 sysv) test -x "$INITRDDIR/vserver" || failed=1;;
336 devel) test -d "$INCLUDEDIR/vserver.h" || failed=1;;
337 *) echo "Unknown component '$i'"
342 test -z "$failed" || {