4 # Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 of the License.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
20 test -e "$UTIL_VSERVER_VARS" || {
21 echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
24 . "$UTIL_VSERVER_VARS"
26 . "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
31 $"Usage: $0 --externalize|--internalize [-y] [--] <vserver-name>
33 Report bugs to <$PACKAGE_BUGREPORT>."
37 function showVersion()
40 vpkg $PACKAGE_VERSION -- shows information about packages in vservers
41 This program is part of $PACKAGE_STRING
43 Copyright (C) 2004 Enrico Scholz
44 This program is free software; you may redistribute it under the terms of
45 the GNU General Public License. This program has absolutely no warranty."
51 if test -z "$WORKAROUND_106057"; then
54 rpmdb_mntpoint=/.rpmdb
59 function _createDirs()
67 function _copySecure()
74 ( cd "$srcdir" && tar chf - '.' ) | \
75 ( cd "$chroot" && $_EXEC_CD "$dstdir" $_TAR xf - )
78 function _copySecureRev()
84 ( cd "$chroot" && $_EXEC_CD "$srcdir" $_TAR cf - '.' ) | \
85 ( cd "$dstdir" && tar xf - )
91 local dir=$(dirname "$1")
92 local file=$(basename "$1")
94 $_EXEC_CD "$dir" "$(which test)" "$file" || return 0
96 local tmp=$(mktemp /tmp/apt.conf.XXXXXX)
97 trap "rm -f $tmp" EXIT
99 $_EXEC_CD "$dir" /bin/cat "$file" | \
100 sed -e "s|^\([^$hash].*@autogenerated@\)|$hash$hash\1|" >$tmp
102 cat $tmp | $_EXEC_CD "$dir" "$(which cmp)" -s - "$file" || \
103 $_CHROOT_CAT "$1" <$tmp
108 function _unhashAuto()
110 test -e "$1" || return 0
113 local tmp=$(mktemp /tmp/apt.conf.XXXXXX)
114 trap "rm -f $tmp" EXIT
116 sed -e "s|^$hash$hash\(.*@autogenerated@\)|\1|" "$1" >$tmp
117 cmp -s "$tmp" "$1" || \
123 function processVserver_RH()
126 local is_internalize=$2
131 cfgdir=$($_VSERVER_INFO "$vserver" APPDIR pkgmgmt) || \
132 cfgdir=$($_VSERVER_INFO "$vserver" APPDIR)/pkgmgmt
134 ## Figure out the environment....
136 pkgmgmt.isAptAvailable "$cfgdir" "$vdir" "$is_internalize" || have_apt=
145 ## Create directories and assign variables where configuration
146 ## can/will be found on the host
147 if test "$is_internalize"; then
148 pushd "$vdir" >/dev/null
150 test ! -L var/lib/rpm || {
151 $_EXEC_CD /var/lib /bin/rm rpm &&
152 $_EXEC_CD /var/lib /bin/mkdir -m755 rpm &&
153 $_EXEC_CD /var/lib /bin/chown rpm:rpm rpm ||
155 } </dev/null 2>/dev/null
157 for i in var/cache/apt/{,archives/{,partial},genpkglist,gensrclist} \
158 var/state/{,apt/{,lists/{,partial}}} \
161 $_EXEC_CD /$(dirname "$i") /bin/mkdir -m755 $(basename "$i") || :
166 if test "$have_apt"; then
167 findDir APTETCDIR "$cfgdir"/aptetc "$cfgdir"/base/apt/etc /etc/apt /
170 findDir RPMETCDIR "$cfgdir"/rpmetc "$cfgdir"/base/rpm/etc /etc/rpm /
171 findDir RPMSTATEDIR "$cfgdir"/rpmstate "$cfgdir"/base/rpm/state
173 mkdir -m755 -p "$cfgdir"
176 if test "$have_apt"; then
177 findDir APTETCDIR "$cfgdir"/aptetc "$cfgdir"/base/apt/etc /
178 findDir APTSTATEDIR "$cfgdir"/aptstate "$cfgdir"/base/apt/state /
179 findDir APTCACHEDIR "$cfgdir"/aptcache "$cfgdir"/base/apt/cache /
180 findDir APTARCHIVDIR "$cfgdir"/aptarchives "$cfgdir"/base/apt/archives /
182 test "$APTETCDIR" != / || APTETCDIR=$cfgdir/base/apt/etc
183 test "$APTSTATEDIR" != / || APTSTATEDIR=$cfgdir/base/apt/state
184 test "$APTCACHEDIR" != / || APTCACHEDIR=$cfgdir/base/apt/cache
185 test "$APTARCHIVDIR" != / || APTARCHIVDIR=$cfgdir/base/apt/archive
187 test -d "$cfgdir"/aptetc -a -d "$cfgdir"/aptstate -a \
188 -d "$cfgdir"/aptcache -a -d "$cfgdir"/aptarchives || need_base=1
191 findDir RPMETCDIR "$cfgdir"/rpmetc "$cfgdir"/base/rpm/etc /
192 findDir RPMSTATEDIR "$cfgdir"/rpmstate "$cfgdir"/base/rpm/state /
194 test "$RPMETCDIR" != / || RPMETCDIR=$cfgdir/base/rpm/etc
195 test "$RPMSTATEDIR" != / || RPMSTATEDIR=$cfgdir/base/rpm/state
197 test -d "$cfgdir"/rpmetc -a -d "$cfgdir"/rpmstate || need_base=1
198 test ! -e "$cfgdir"/base || need_base=
200 test -z "$need_base" || ln -s "$PKGCFGDIR" "$cfgdir"/base
202 mkdir -m755 -p "$PKGCFGDIR"
203 _createDirs "$APTETCDIR" "$APTSTATEDIR" "$APTCACHEDIR" "$APTARCHIVDIR" \
204 "$RPMETCDIR" "$RPMSTATEDIR"
208 if test "$is_internalize"; then
209 if test "$have_apt"; then
210 _copySecure "$vdir" "$APTETCDIR" /etc/apt
211 pushd "$vdir" >/dev/null
212 _hashAuto /etc/apt/apt.conf '/'
216 _copySecure "$vdir" "$RPMETCDIR" /etc/rpm
217 _copySecure "$vdir" "$RPMSTATEDIR" /var/lib/rpm
220 if test "$have_apt"; then
221 _copySecureRev "$vdir" /etc/apt "$APTETCDIR"
222 _unhashAuto "$APTETCDIR"/apt.conf '/'
225 _copySecureRev "$vdir" /etc/rpm "$RPMETCDIR"
226 _copySecureRev "$vdir" /var/lib/rpm "$RPMSTATEDIR"
230 if test "$is_internalize"; then
233 tmpdir=$(mktemp -d /var/tmp/pgmgmt.XXXXXX)
234 trap "rm -rf $tmpdir" EXIT
235 pushd "$vdir" >/dev/null
236 $_EXEC_CD /var/lib /bin/mv rpm $tmpdir/
237 $_EXEC_CD /var/lib /bin/ln -s "$rpmdb_mntpoint" rpm
242 if test "$is_internalize"; then
243 touch "$cfgdir"/internal
245 rm -f "$cfgdir"/internal
249 function processVserver_Debian()
252 local is_internalize=$2
254 if test "$is_internalize"; then
255 echo $"Debian vservers should be internalized everytime; do not know how to handle '$vserver'" >&2
257 echo $"External packagemanagement is not supported for Debian vserver" >&2
263 function processVserver()
270 ! $_VSERVER_INFO -q "$vserver" RUNNING || {
271 echo $"Can not operate on running vservers; please stop '$vserver' and retry again..."
275 vdir=$($_VSERVER_INFO "$vserver" VDIR) && test -d "$vdir" || {
276 echo $"Vserver '$vserver' does not seem to exist; skipping it..."
280 pkgmgmt.isInternal "$vserver" || is_external=1
282 case "$is_external"X"$IS_INTERNALIZE"X"$IS_EXTERNALIZE" in
283 (*X1X1) echo $"Can not externalize and internalize at the same time";;
284 (*XX) echo $"No operation specified; try '--help' for more information";;
285 (1XX1) echo $"Vserver '$vserver' has already external packagemanagment; skipping it...";;
286 (X1X) echo $"Vserver '$vserver' has already internal packagemanagment; skipping it...";;
290 test -z "$skip" || return 1
293 pkgmgmt.guessStyle "$vserver" style || return 1
296 (redhat|mandrake) processVserver_RH "$vserver" "$IS_INTERNALIZE";;
297 (debian) processVserver_Debian "$vserver" "$IS_INTERNALIZE";;
299 echo $"Vserver style '$style' is not supported for packagemanagment" >&2
304 tmp=$(getopt -o y --long debug,externalize,internalize,help,version -n "$0" -- "$@") || exit 1
313 (--help) showHelp $0;;
314 (--version) showVersion;;
316 (--externalize) IS_EXTERNALIZE=1;;
317 (--internalize) IS_INTERNALIZE=1;;
320 (*) echo $"vserver: internal error; arg=='$1'" >&2; exit 1;;
326 echo $"No vserver specified; try '--help' for more information"
337 processVserver "$i" && passed=1 || ok=
340 test -z "$ok" || exit 0
341 test -z "$passed" || exit 1