4 # Copyright (C) 2003 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.
21 : ${UTIL_VSERVER_VARS:=$(dirname $0)/util-vserver-vars}
22 test -e "$UTIL_VSERVER_VARS" || {
23 echo "Can not find util-vserver installation; aborting..."
26 . "$UTIL_VSERVER_VARS"
27 . "$PKGLIBDIR/functions"
29 tmp=$(getopt -o d:r: --long force,dir:,pkgcfg:,hostname:,iproot:,iprootmask:,iprootbcast:,iprootdev:,help,version \
30 -n "$0" -- "$@") || exit 1
52 c|b) mknod -m$6 "$dst" $3 $4 $5;;
53 d) mkdir -p -m$4 "$dst";;
57 *) echo "Unknown dev-entry mode '$3'" >&2
63 function installBasePackages
68 test "$dir" != / || return
69 for filelist in "$dir"/*; do
70 test -f "$filelist" || continue
76 while test "$#" -gt 0; do
78 --reinstall) flags='--reinstall';;
79 --can-fail) can_fail=true;;
84 "$_VAPT_GET" "$name" -- install -y $flags $* || $can_fail
88 function populateDirectory
97 for file in "$i"/*; do
98 test -e "$file" || continue
104 function prepareRPMDb
107 test -z "$WORKAROUND_106057" || {
109 mkdir -p "$rpmdb_path"
111 mkdir -p "$vdir$rpmdb_path"
114 function importGPGPubKeys
124 for file in "$i"/*; do
125 test -f "$file" || continue
126 pkgs[${#pkgs[*]}]=$file
130 test "$pkgs" || return 0
131 "$_VRPM" "$dst" -- --import "${pkgs[@]}"
136 -d) distrib="$2"; shift 2;;
137 -r) root="$2"; shift 2;;
138 --pkgcfg) pkgcfg="$2"; shift 2;;
139 --force) force=1; shift;;
140 --dir) dir="$2"; shift 2;;
141 --hostname) hostname="$2"; shift 2;;
142 --iproot) iproot="$2"; shift 2;;
143 --iprootmask) iprootmask="$2"; shift 2;;
144 --iprootbcast) iprootbcast="$2"; shift 2;;
145 --iprootdev) iprootdev="$2"; shift 2;;
146 --help) showHelp; exit 0;;
147 --version) showVersion; exit 0;;
149 *) echo "Internal error!"; exit 1;;
154 echo "No vserver name given" >&2
159 echo "Too much parameters" >&2
166 for item in "$CONFDIR/.defaults/vdirbase 1" "/vservers"; do
170 test ! -d "$root" || break
175 echo "Root-directory '$root' does not exists or is invalid"
181 for item in "$CONFDIR/.defaults/apps/pkgmgmt/base 1" "$root/.pkg"; do
185 test ! -d "$pkgcfgbase" || break
188 test -d "$pkgcfgbase" || {
189 echo "pkgcfgbase-dir '$pkgcfgbase' does not exists or is invalid"
193 pkgcfg="$pkgcfgbase/$name"
196 test "$dir" || dir=$name
199 test ! -d "$vdir" || {
200 test "$force" && mv "$vdir" "$vdir".bak
203 confdir="$CONFDIR/$name"
204 test ! -d "$confdir" || {
205 test "$force" && mv "$confdir" "$confdir".bak
208 test ! -d "$vdir" -a ! -d "$confdir" || {
209 echo "vserver-topdirectory and/or configuration exist already; "
210 echo "please try to use '--force', or remove them manually"
215 if test -e /etc/redhat-release; then
216 set -- $(cat /etc/redhat-release)
219 echo "Can not determine distribution; please specify it manually"
220 echo "with the '-d' option"
225 findFile INITPRE $CONFDIR/.distributions/$distrib/initpre $DISTRIBDIR/$distrib/initpre ""
226 findFile INITPOST $CONFDIR/.distributions/$distrib/initpost $DISTRIBDIR/$distrib/initpost ""
227 findFile DEVDESCR $CONFDIR/.distributions/$distrib/devs $DISTRIBDIR/$distrib/devs $DISTRIBDIR/defaults/devs
228 findDir EXECDIR $CONFDIR/.distributions/$distrib/execdir $DISTRIBDIR/$distrib/execdir /
229 findDir RPMLIB $CONFDIR/.distributions/$distrib/rpmlib $DISTRIBDIR/$distrib/rpmlib /
230 findDir PKGDIR $CONFDIR/.distributions/$distrib/pkgs $DISTRIBDIR/$distrib/pkgs /
232 mkdir -p "$confdir"/apps/pkgmgmt "$vdir"/{dev/pts,etc} \
233 "$pkgcfg"/{rpm/{etc,state},apt/{etc,archives/partial,cache,state/lists/partial}}
237 ## HACK AND SECURITY ALERT!
238 ## /var/lib/rpm is hardcoded into apt-get which does not honor the
239 ## %_dbpath variable therefore
240 #mkdir -p "$vdir"/var/lib
241 #ln -s ../../dev "$vdir"/var/lib/rpm
245 makeDevEntry "$vdir"/dev $spec
248 ln -s "$vdir" "$confdir"/vdir
249 for i in hostname iproot iprootmask iprootbcast iprootdev; do
252 test -z "$v" || echo $v >"$confdir/$i"
255 ln -s "$pkgcfg" "$confdir/apps/pkgmgmt/base"
256 test "$EXECDIR" = / || ln -s "$EXECDIR" "$confdir/apps/pkgmgmt/execdir"
257 test "$RPMLIB" = / || ln -s "$RPMLIB" "$confdir/apps/pkgmgmt/rpmlib"
259 populateDirectory "$pkgcfg/apt/etc" "$DISTRIBDIR/$distrib/apt" "$CONFDIR/.distributions/$distrib/apt"
260 populateDirectory "$pkgcfg/rpm/etc" "$DISTRIBDIR/defaults/rpm" "$DISTRIBDIR/$distrib/rpm" \
261 "$CONFDIR/.distributions/$distrib/rpm"
263 echo "%_dbpath $rpmdb_path" >>"$pkgcfg/rpm/etc/macros"
265 test -z "$INITPRE" || "$INITPRE" "$name"
266 importGPGPubKeys "$name" "$CONFDIR/.distributions/$distrib/pubkeys" "$DISTRIBDIR/$distrib/pubkeys"
267 "$_VAPT_GET" "$name" -- update
268 installBasePackages "$name" "$PKGDIR"
269 "$_VAPT_GET" "$name" -- dist-upgrade -y
270 test -z "$INITPOST" || "$INITPOST" "$name"