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"
53 function getPhysicalDir
55 ( set -P && cd "$1" && pwd )
58 function _pkgMountBindDir()
60 test "$1" != "$2" || return 0
62 mount -n --bind "$1" "$2"
65 function _pkgSetVarsBase
69 if test -d "$vserver/vdir"; then
71 VDIR=$(getPhysicalDir "$vserver/vdir")
73 PKGDIR=$BASEDIR/apps/pkgmgmt
74 test -d "$PKGDIR" || {
75 echo "Can not find configuration-directory for package-managment tools"
78 findDir EXECDIR $PKGDIR/execdir /
80 VDIR=$(getPhysicalDir "$vserver")
85 BASEDIR=$CONFDIR/$vserver
86 test -d "$BASEDIR" || {
87 echo "Can not find configuration-directory"
92 test -d "$VDIR" || VDIR=/vservers/$vserver
93 VDIR=$(getPhysicalDir "$VDIR")
95 PKGDIR=$BASEDIR/apps/pkgmgmt
96 test -d "$PKGDIR" || {
97 echo "Can not find configuration-directory for package-managment tools"
101 findDir EXECDIR $PKGDIR/execdir /
106 if test -z "$WORKAROUND_106057"; then
109 _rpmdb_mntpoint=/.rpmdb
113 function _pkgSetVarsRPM
115 if test "$PKGDIR"; then
116 findDir RPMETCDIR $PKGDIR/rpmetc $PKGDIR/base/rpm/etc /etc/rpm
117 findDir RPMSTATEDIR $PKGDIR/rpmstate $PKGDIR/base/rpm/state
119 findDir RPMLIBDIR $PKGDIR/rpmlib /
122 findDir RPMETCDIR "$VDIR"/etc/rpm /etc/rpm
123 findDir RPMSTATEDIR "$VDIR"/var/lib/rpm
127 RPMSTATEDIR=$(getPhysicalDir "$RPMSTATEDIR")
128 RPMETCDIR=$(getPhysicalDir "$RPMETCDIR")
131 function _pkgSetVarsApt
133 if test "$PKGDIR"; then
134 findDir APTETCDIR $PKGDIR/aptetc $PKGDIR/base/apt/etc /etc/apt
135 findDir APTSTATEDIR $PKGDIR/aptstate $PKGDIR/base/apt/state
136 findDir APTCACHEDIR $PKGDIR/aptcache $PKGDIR/base/apt/cache
137 findDir APTARCHIVDIR $PKGDIR/aptarchives $PKGDIR/base/apt/archives /var/cache/apt/archives
139 findDir APTETCDIR "$VDIR"/etc/apt /etc/apt
140 findDir APTSTATEDIR "$VDIR"/var/state/apt
141 findDir APTCACHEDIR "$VDIR"/var/cache/apt
142 findDir APTARCHIVDIR "$VDIR"/var/cache/apt/archives /var/cache/apt/archives
146 function _pkgMountBase
151 function _pkgMountApt
156 function _pkgMountRPM
158 _pkgMountBindDir "$RPMETCDIR" /etc/rpm
159 test "$RPMLIBDIR" = "/" || _pkgMountBindDir "$RPMLIBDIR" /usr/lib/rpm
161 "$_SECURE_MOUNT" --chroot "$VDIR" -n --secure --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
162 test -z "$WORKAROUND_106057" || mount -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
165 function _pkgSetEnvBase
167 test "$EXECDIR" = "/" || {
169 LD_LIBRARY_PATH=$EXECDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
172 export PATH LD_LIBRARY_PATH
175 function _pkgSetEnvApt
180 function _pkgSetEnvRPM
183 RPM_FAKE_NAMESPACE_MOUNTS=$_rpmdb_mntpoint
184 RPM_BINARY=$_VRPM_PRELOAD
186 export CUR_VSERVER RPM_FAKE_NAMESPACE_MOUNTS RPM_BINARY
198 rpm) _pkgSetVarsRPM;;
199 apt) _pkgSetVarsApt;;
200 *) echo "Unknown packaging flavor"; exit 1;;
221 _PKG_VSERVER=$vserver
224 function getAllVservers
229 for i in $CONFDIR/*; do
230 test -d "$i" || continue
231 test ! -e "$i"/disabled || continue
232 test -d "$i"/vdir || continue
234 tmp=( "${tmp[@]}" "${i##$CONFDIR/}")
240 ## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
241 function getVserverStatus
243 test -r "$1"/run || return 1
244 eval read "$2" <"$1"/run
246 test "$3" || return 0
247 local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$ctx" | $_WC -l )
250 test "$4" -a $_tmp = 0 || return 0
251 _tmp=$(readlink "$1/run")
252 test "$_tmp" || return 1
257 ## Usage: isVserverRunning <vdir> [<ctx-varname>]
258 function isVserverRunning
262 getVserverStatus "$1" ctx procnum 1 || return 1
263 test $procnum != 0 || return 1
264 test -z "$2" || eval "$2"=\$ctx
268 ## Called as 'getFileValue <varname> <filename>'
269 function getFileValue
271 test -r "$2" || return 0
275 ## Called as 'getFileArray <varname> <filename>'
276 function getFileArray
278 test -r "$2" || return 0
280 local IFS=$_VS_NEWLINE
281 eval "$1"='( $(< "$2") )'