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:,lockfile:,help,version \
30 -n "$0" -- "$@") || exit 1
48 c|b) mknod -m$6 "$dst" $3 $4 $5;;
49 d) mkdir -p -m$4 "$dst";;
53 *) echo "Unknown dev-entry mode '$3'" >&2
59 function installBasePackages
64 test "$dir" != / || return
65 for filelist in "$dir"/*; do
66 test -f "$filelist" || continue
72 while test "$#" -gt 0; do
74 --reinstall) flags='--reinstall';;
75 --can-fail) can_fail=true;;
80 "$_VAPT_GET" "$name" -- install -y $flags $* || $can_fail
84 function populateDirectory
93 for file in "$i"/*; do
94 test -e "$file" || continue
100 function prepareRPMDb
103 test -z "$WORKAROUND_106057" || {
105 mkdir -p "$rpmdb_path"
107 mkdir -p "$vdir$rpmdb_path"
110 function importGPGPubKeys
120 for file in "$i"/*; do
121 test -f "$file" || continue
122 pkgs[${#pkgs[*]}]=$file
126 test "$pkgs" || return 0
127 "$_VRPM" "$dst" -- --import "${pkgs[@]}"
132 -d) distrib="$2"; shift 2;;
133 -r) root="$2"; shift 2;;
134 --pkgcfg) pkgcfg="$2"; shift 2;;
135 --force) force=1; shift;;
136 --dir) dir="$2"; shift 2;;
137 --lockfile) lockfile="$2"; shift 2;;
138 --help) showHelp; exit 0;;
139 --version) showVersion; exit 0;;
141 *) echo "Internal error!"; exit 1;;
146 echo "No vserver name given" >&2
151 echo "Too much parameters" >&2
158 for item in "$CONFDIR/.defaults/vdirbase 1" "/vservers"; do
162 test ! -d "$root" || break
167 echo "Root-directory '$root' does not exists or is invalid"
171 test "$lockfile" || lockfile=/var/run/vservers/$name
175 for item in "$CONFDIR/.defaults/apps/pkgmgmt/base 1" "$root/.pkg"; do
179 test ! -d "$pkgcfgbase" || break
182 test -d "$pkgcfgbase" || {
183 echo "pkgcfgbase-dir '$pkgcfgbase' does not exists or is invalid"
187 pkgcfg="$pkgcfgbase/$name"
190 test "$dir" || dir=$name
193 test ! -d "$vdir" || {
194 test "$force" && mv "$vdir" "$vdir".bak
197 confdir="$CONFDIR/$name"
198 test ! -d "$confdir" || {
199 test "$force" && mv "$confdir" "$confdir".bak
202 test ! -d "$vdir" -a ! -d "$confdir" || {
203 echo "vserver-topdirectory and/or configuration exist already; "
204 echo "please try to use '--force', or remove them manually"
209 if test -e /etc/redhat-release; then
210 set -- $(cat /etc/redhat-release)
213 echo "Can not determine distribution; please specify it manually"
214 echo "with the '-d' option"
219 findFile INITPRE $CONFDIR/.distributions/$distrib/initpre $DISTRIBDIR/$distrib/initpre ""
220 findFile INITPOST $CONFDIR/.distributions/$distrib/initpost $DISTRIBDIR/$distrib/initpost ""
221 findFile DEVDESCR $CONFDIR/.distributions/$distrib/devs $DISTRIBDIR/$distrib/devs $DISTRIBDIR/defaults/devs
222 findDir EXECDIR $CONFDIR/.distributions/$distrib/execdir $DISTRIBDIR/$distrib/execdir /
223 findDir RPMLIB $CONFDIR/.distributions/$distrib/rpmlib $DISTRIBDIR/$distrib/rpmlib /
224 findDir PKGDIR $CONFDIR/.distributions/$distrib/pkgs $DISTRIBDIR/$distrib/pkgs /
226 mkdir -p "$confdir"/apps/pkgmgmt "$vdir"/{dev/pts,etc} \
227 "$pkgcfg"/{rpm/{etc,state},apt/{etc,archives/partial,cache,state/lists/partial}}
229 ln -s "$lockfile" "$confdir"/run
230 ln -s "$lockfile/rev" "$confdir"/run.rev
234 ## HACK AND SECURITY ALERT!
235 ## /var/lib/rpm is hardcoded into apt-get which does not honor the
236 ## %_dbpath variable therefore
238 mkdir -p "$vdir"/var/lib
239 ln -s "$rpmdb_path" "$vdir"/var/lib/rpm
243 makeDevEntry "$vdir"/dev $spec
246 ln -s "$vdir" "$confdir"/vdir
247 for i in hostname; do
250 test -z "$v" || echo $v >"$confdir/$i"
253 ln -s "$pkgcfg" "$confdir/apps/pkgmgmt/base"
254 test "$EXECDIR" = / || ln -s "$EXECDIR" "$confdir/apps/pkgmgmt/execdir"
255 test "$RPMLIB" = / || ln -s "$RPMLIB" "$confdir/apps/pkgmgmt/rpmlib"
257 populateDirectory "$pkgcfg/apt/etc" "$DISTRIBDIR/$distrib/apt" "$CONFDIR/.distributions/$distrib/apt"
258 populateDirectory "$pkgcfg/rpm/etc" "$DISTRIBDIR/defaults/rpm" "$DISTRIBDIR/$distrib/rpm" \
259 "$CONFDIR/.distributions/$distrib/rpm"
261 echo "%_dbpath $rpmdb_path" >>"$pkgcfg/rpm/etc/macros"
263 test -z "$INITPRE" || "$INITPRE" "$name"
264 importGPGPubKeys "$name" "$CONFDIR/.distributions/$distrib/pubkeys" "$DISTRIBDIR/$distrib/pubkeys"
265 "$_VAPT_GET" "$name" -- update
266 installBasePackages "$name" "$PKGDIR"
267 "$_VAPT_GET" "$name" -- dist-upgrade -y
268 test -z "$INITPOST" || "$INITPOST" "$name"