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"
181 function _pkgSetEnvBase
183 test "$EXECDIR" = "/" || {
185 LD_LIBRARY_PATH=$EXECDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
188 export PATH LD_LIBRARY_PATH
191 function _pkgSetEnvApt
196 function _pkgSetEnvRPM
199 RPM_FAKE_NAMESPACE_MOUNTS=$_rpmdb_mntpoint
200 RPM_BINARY=$_VRPM_PRELOAD
202 export CUR_VSERVER RPM_FAKE_NAMESPACE_MOUNTS RPM_BINARY
214 rpm) _pkgSetVarsRPM;;
215 apt) _pkgSetVarsApt;;
216 *) echo "Unknown packaging flavor"; exit 1;;
237 _PKG_VSERVER=$vserver
240 function getAllVservers
245 for i in $CONFDIR/*; do
246 test -d "$i" || continue
247 test ! -e "$i"/disabled || continue
248 test -d "$i"/vdir || continue
250 _tmp=( "${_tmp[@]}" "${i##$CONFDIR/}")
253 eval $1='( "${_tmp[@]}" )'
256 ## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
257 function getVserverStatus
259 test -r "$1"/run || return 1
260 eval read "$2" <"$1"/run
262 test "$3" || return 0
263 local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$ctx" | $_WC -l )
266 test "$4" -a $_tmp = 0 || return 0
267 _tmp=$(readlink "$1/run")
268 test "$_tmp" || return 1
273 ## Usage: isVserverRunning <vdir> [<ctx-varname>]
274 function isVserverRunning
278 getVserverStatus "$1" ctx procnum 1 || return 1
279 test $procnum != 0 || return 1
280 test -z "$2" || eval "$2"=\$ctx
284 ## Called as 'getFileValue <varname> <filename>'
285 function getFileValue
287 test -r "$2" || return 0
291 ## Called as 'getFileArray <varname> <filename>'
292 function getFileArray
294 test -r "$2" || return 0
296 local IFS=$_VS_NEWLINE
297 eval "$1"='( $(< "$2") )'
300 function checkComponents
311 core) test -x "$_CHBIND" || failed=1;;
312 build) test -x "$_VSERVER_BUILD" || failed=1;;
313 sysv) test -x "$INITRDDIR/vserver" || failed=1;;
314 devel) test -d "$INCLUDEDIR/vserver.h" || failed=1;;
315 *) echo "Unknown component '$i'"
320 test -z "$failed" || {