openpkg/openpkg.boot

changeset 271
f45355418dfd
child 428
f880f219c566
equal deleted inserted replaced
-1:000000000000 0:bdddab3fb43c
1 #!/bin/sh
2 ##
3 ## openpkg.boot -- OpenPKG bootstrap procedure (look Ma, without hands ;)
4 ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
5 ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
6 ##
7 ## Permission to use, copy, modify, and distribute this software for
8 ## any purpose with or without fee is hereby granted, provided that
9 ## the above copyright notice and this permission notice appear in all
10 ## copies.
11 ##
12 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
13 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
16 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
22 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 ## SUCH DAMAGE.
24 ##
25
26 # This is a very tricky procedure for building the OpenPKG bootstrap
27 # package via the RPM specification openpkg.spec, but without
28 # requiring that OpenPKG's RPM already exists. For this the
29 # openpkg.spec file is manually executed here in order to build
30 # OpenPKG RPM the first time (that is, we emulate a sufficient
31 # subset of the RPM functionality), followed by a second round over
32 # openpkg.spec with the real (and then existing) OpenPKG RPM tool.
33 # Also keep in mind that lots of tricks are played here in order to
34 # perform all the steps without having to touch the real installation
35 # location. That is the whole procedure can (and should) be performed
36 # by a non-privileged user and no access to the real installation
37 # location filesystem location.
38
39 me="openpkg.boot"
40
41 ##
42 ## command line handling
43 ##
44
45 # command line parameters (defaults)
46 help=0
47 verbose=''
48 prefix=''
49 tag=''
50 usr=''; grp=''
51 susr=''; sgrp=''
52 musr=''; mgrp=''
53 rusr=''; rgrp=''
54 nusr=''; ngrp=''
55 suid=''; sgid=''
56 muid=''; mgid=''
57 ruid=''; rgid=''
58 nuid=''; ngid=''
59 use_tar=''; use_make=''; use_cc=''; use_ar=''; use_ld=''; use_as=''; use_strip=''
60 bs=0
61
62 # parse command line options
63 for opt
64 do
65 case $opt in
66 -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
67 *) arg='' ;;
68 esac
69 case $opt in
70 -h | --help ) help=1 ;;
71 -v | --verbose ) verbose=v ;;
72 --prefix=* ) prefix=$arg ;;
73 --tag=* ) tag=$arg ;;
74 --usr=* | --user=* ) usr=$arg ;;
75 --grp=* | --group=* ) grp=$arg ;;
76 --susr=* ) susr=$arg ;;
77 --sgrp=* ) sgrp=$arg ;;
78 --musr=* ) musr=$arg ;;
79 --mgrp=* ) mgrp=$arg ;;
80 --rusr=* ) rusr=$arg ;;
81 --rgrp=* ) rgrp=$arg ;;
82 --nusr=* ) nusr=$arg ;;
83 --ngrp=* ) ngrp=$arg ;;
84 --suid=* ) suid=$arg ;;
85 --sgid=* ) sgid=$arg ;;
86 --muid=* ) muid=$arg ;;
87 --mgid=* ) mgid=$arg ;;
88 --ruid=* ) ruid=$arg ;;
89 --rgid=* ) rgid=$arg ;;
90 --nuid=* ) nuid=$arg ;;
91 --ngid=* ) ngid=$arg ;;
92 --use_tar=* ) use_tar=$arg ;;
93 --use_make=* ) use_make=$arg ;;
94 --use_cc=* ) use_cc=$arg ;;
95 --use_ar=* ) use_ar=$arg ;;
96 --use_ld=* ) use_ld=$arg ;;
97 --use_as=* ) use_as=$arg ;;
98 --use_strip=* ) use_strip=$arg ;;
99 -bs | -s ) bs=1 ;;
100 * ) help=1 ;;
101 esac
102 done
103 if [ ".$bs" = .0 -a ".$prefix" = . ]; then
104 help=1
105 fi
106 if [ ".$help" = .1 ]; then
107 echo "Usage: sh $me" 2>&1
108 echo " [--prefix=<prefix>] [--tag=<str>]" 2>&1
109 echo " [--user=<usr>] [--group=<grp>]" 2>&1
110 echo " [--{s,m,r,n}usr=<usr>] [--{s,m,r,n}grp=<grp>]" 2>&1
111 echo " [--{s,m,r,n}uid=<uid>] [--{s,m,r,n}gid=<gid>]" 2>&1
112 echo " [--use_tar=<tar>] [--use_make=<make>] [--use_cc=<cc>]" 2>&1
113 echo " [--use_ar=<ar>] [--use_ld=<ld>] [--use_as=<as>] [--use_strip=<strip>]" 2>&1
114 echo " [-t|--tar] [-h|--help] [-v|--version]" 2>&1
115 exit 1
116 fi
117
118 # determine missing parameters
119 eval `sh aux.usrgrp.sh \
120 --usr="$usr" --grp="$grp" \
121 --susr="$susr" --sgrp="$sgrp" \
122 --musr="$musr" --mgrp="$mgrp" \
123 --rusr="$rusr" --rgrp="$rgrp" \
124 --nusr="$nusr" --ngrp="$ngrp" \
125 --suid="$suid" --sgid="$sgid" \
126 --muid="$muid" --mgid="$mgid" \
127 --ruid="$ruid" --rgid="$rgid" \
128 --nuid="$nuid" --ngid="$ngid"`
129
130 # canonicalize prefix
131 prefix=`echo "$prefix" | sed -e 's;//*;/;g' -e 's;/$;;'`
132
133 # provide default package tag
134 if [ ".$tag" = . ]; then
135 tag="<loc>"
136 fi
137
138 ##
139 ## determine package information
140 ##
141
142 name="openpkg"
143 spec="$name.spec"
144 version=`grep V_openpkg $spec | sed -e 'q' | awk '{ printf("%s", $3); }'`
145 release="$version"
146
147 ##
148 ## display headline
149 ##
150
151 sh ./shtool echo -e "%BOpenPKG Bootstrap Procedure%b"
152 echo "++ bootstrap version: $version-$release"
153 echo "++ user/group pairs: $susr/$sgrp $musr/$mgrp $rusr/$rgrp $nusr/$ngrp"
154
155 ##
156 ## optionally roll just a bootstrap source package
157 ##
158
159 if [ ".$bs" = .1 ]; then
160 srcdir=.
161 if [ -d ../../dst ]; then
162 dstdir=../../dst/openpkg
163 else
164 dstdir=.
165 fi
166 tmpdir="/tmp/$me.$$.d"
167 if [ -d ../PKG/SRC ]; then
168 pkgdir=../PKG/SRC
169 elif [ -d ../PKG ]; then
170 pkgdir=../PKG
171 elif [ -d ../../PKG/SRC ]; then
172 pkgdir=../../PKG/SRC
173 elif [ -d ../../PKG ]; then
174 pkgdir=../../PKG
175 elif [ -d ../../pkg/src ]; then
176 pkgdir=../../pkg/src
177 elif [ -d ../../pkg ]; then
178 pkgdir=../../pkg
179 else
180 pkgdir=..
181 fi
182 echo "** rolling source bootstrap package:"
183 echo " $pkgdir/$name-$version-$release.src.sh"
184 rm -rf $tmpdir
185 mkdir $tmpdir
186 ( echo "dstdir=$dstdir"
187 echo "srcdir=$srcdir"
188 echo "tmpdir=$tmpdir"
189 grep '^%define' $spec | sed -e 's:^%define *\([^ ]*\) *\(.*\):\1="\2":'
190 grep '^Source' $spec | sed -e 's;^Source[0-9]*: *;;' -e 's;^.*/;$dstdir/;' \
191 -e 's;^\([^/]*\)$;$srcdir/\1;' -e 's;%;$;g' \
192 -e 's;^\(.*\)$;cp \1 $tmpdir/;'
193 echo "cp -p $spec $tmpdir/"
194 ) >$tmpdir/.sh
195 sh $tmpdir/.sh
196 rm -f $tmpdir/.sh
197 l_version="$release"
198 l_release=`sh ./release.sh -r "${l_version}" -F "%t"`
199 sed <$srcdir/aux.wrapsrc.sh >$tmpdir/openpkg.boot.tmp \
200 -e "s;@l_dir@;$name-$version-$release.src;" \
201 -e "s;@l_release@;$l_release;" \
202 -e "s;@l_version@;$l_version;"
203 echo . | awk '{
204 for (i = 0; i < 8192; i++) {
205 printf(" ");
206 }
207 }' >>$tmpdir/openpkg.boot.tmp
208 dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=8 \
209 of=$pkgdir/$name-$version-$release.src.sh 2>/dev/null
210 rm -f $tmpdir/openpkg.boot.tmp
211 (cd $tmpdir && tar cf - *) >>$pkgdir/$name-$version-$release.src.sh
212 rm -rf $tmpdir
213 exit 0
214 fi
215
216 ##
217 ## determine distribution directory
218 ##
219
220 V_rpm=`grep V_rpm $spec | sed -e 'q' | awk '{ printf("%s", $3); }'`
221 if [ -f "../../dst/openpkg/rpm-${V_rpm}.tar.gz" ]; then
222 distdir="`cd ../../dst/openpkg; pwd`" # developer only
223 else
224 distdir="`pwd`"
225 fi
226 echo "++ distribution directory: $distdir"
227
228 ##
229 ## perform prerequisite checks
230 ##
231
232 sh ./aux.prereq.sh source || exit $?
233
234 ##
235 ## find reasonable run-time paths and tools
236 ##
237
238 # find reasonable temporary directory
239 tmpdir="${TMPDIR-/tmp}"
240
241 # find reasonable safe program path
242 test ".$PATH" = . && PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin"
243 for dir in /usr/ccs/bin /usr/xpg4/bin; do
244 test -d $dir && PATH="$PATH:$dir"
245 done
246 export PATH
247
248 # make environment at least partly sane
249 umask 022
250 unset ls rm mv cp sed grep awk >/dev/null 2>&1 || true
251
252 ##
253 ## execute the spec file manually by emulating
254 ## the behaviour of the OpenPKG RPM tool.
255 ##
256
257 # create script prolog
258 prolog="$tmpdir/openpkg.boot.prolog.sh"
259 cp /dev/null $prolog
260 (
261 echo "_specdir=`pwd`"
262 echo "_sourcedir=$distdir"
263 echo "_tmppath=$tmpdir"
264 echo "_builddir=$tmpdir"
265 echo "l_prefix=$prefix"
266 echo "l_tag_fmt=\"$tag\""
267 echo "l_buildroot=$tmpdir/$name-$version-root"
268 echo "l_susr=$susr"
269 echo "l_sgrp=$sgrp"
270 echo "l_musr=$musr"
271 echo "l_mgrp=$mgrp"
272 echo "l_rusr=$rusr"
273 echo "l_rgrp=$rgrp"
274 echo "l_nusr=$nusr"
275 echo "l_ngrp=$ngrp"
276 echo "l_suid=$suid"
277 echo "l_sgid=$sgid"
278 echo "l_muid=$muid"
279 echo "l_mgid=$mgid"
280 echo "l_ruid=$ruid"
281 echo "l_rgid=$rgid"
282 echo "l_nuid=$nuid"
283 echo "l_ngid=$ngid"
284 echo "use_tar=$use_tar"
285 echo "use_make=$use_make"
286 echo "use_cc=$use_cc"
287 echo "use_ar=$use_ar"
288 echo "use_ld=$use_ld"
289 echo "use_as=$use_as"
290 echo "use_strip=$use_strip"
291 grep '%define' $spec | \
292 sed \
293 -e 's:^%define *\([^ ]*\) *\(.*\):\1="\2":'
294 grep "^[A-Za-z0-9]*: *" $spec | \
295 sed \
296 -e 's;^\([A-Za-z0-9]*\): *\(.*\)$;\1="\2";' \
297 -e 's;^A;a;' -e 's;^B;b;' -e 's;^C;c;' -e 's;^D;d;' -e 's;^E;e;' \
298 -e 's;^F;f;' -e 's;^G;g;' -e 's;^H;h;' -e 's;^I;i;' -e 's;^J;j;' \
299 -e 's;^K;k;' -e 's;^L;l;' -e 's;^M;m;' -e 's;^N;n;' -e 's;^O;o;' \
300 -e 's;^P;p;' -e 's;^Q;q;' -e 's;^R;r;' -e 's;^S;s;' -e 's;^T;t;' \
301 -e 's;^U;u;' -e 's;^V;v;' -e 's;^W;w;' -e 's;^X;x;' -e 's;^Y;y;' \
302 -e 's;^Z;z;' -e 's;^buildRoot;buildroot;'
303 echo "RPM_BUILD_ROOT=\"%{buildroot}\""
304 echo "RPM_BUILD_DIR=\"%{_builddir}\""
305 echo "RPM_SOURCE_DIR=\"$distdir\""
306 echo "export RPM_BUILD_ROOT"
307 echo "export RPM_BUILD_DIR"
308 echo "export RPM_SOURCE_DIR"
309 echo "set -x"
310 echo "umask 022"
311 echo "cd \$RPM_BUILD_DIR"
312 ) | sed -e 's;%{\([^}]*\)};${\1};g' >$prolog
313
314 # install package via RPM spec file by faking a
315 # sufficiently enough RPM run-time environment
316 runscript () {
317 step=$1
318 script="$tmpdir/openpkg.boot.$step.sh"
319 echo ". $prolog" >$script
320 sed -e "/^%$step/,/^%/ p" -e 'd' <$spec | \
321 sed -e '/^%/d' | \
322 sed -e 's;%{SOURCE \([^ ]*\.tar[^ ]*\)};${RPM_DIST_DIR}/\1;g' \
323 -e 's;%{SOURCE \([^ ]*\)};${RPM_SOURCE_DIR}/\1;g' | \
324 sed -e 's;%{[?]\([^:}]*\):\([^}]*\)};${\1+\2};g' \
325 -e 's;%{![?]\([^:}]*\):\([^}]*\)};${\1-\2};g' \
326 -e 's;%{[?]\([^:}]*\)};${\1+""};g' \
327 -e 's;%{![?]\([^:}]*\)};${\1-""};g' \
328 -e 's;%{\([^}]*\)};${\1};g' >>$script
329 echo "++ executing(%$step): sh $script"
330 sh $script
331 if [ $? -ne 0 ]; then
332 rm -f $script
333 echo "$0:ERROR: script returned non-null value"
334 exit 1
335 fi
336 rm -f $script
337 }
338 runscript prep
339 runscript build
340 runscript install
341
342 ##
343 ## adjust build environment so that the installed
344 ## "rpm" is actually useable, although it still resides in
345 ## the temporary location instead of the real location.
346 ##
347
348 # suck in prolog in order to get variables from the spec file
349 cwd=`pwd`
350 . $prolog
351 cd $cwd
352
353 # suck in buildenv script in order to get musr/mgrp
354 . $tmpdir/openpkg-*/.buildenv
355
356 # create a custom "rpm" command
357 echo "++ creating custom RPM command"
358 rm -f $tmpdir/rpm >/dev/null 2>&1
359 rmdir $tmpdir/rpm >/dev/null 2>&1
360 if [ -d "$tmpdir/rpm" ]; then
361 echo "$0:ERROR: directory $tmpdir/rpm exists, cannot create file with same name"
362 exit 1
363 fi
364 if [ -f "$tmpdir/rpm" ]; then
365 echo "$0:ERROR: file $tmpdir/rpm exists, cannot override"
366 exit 1
367 fi
368 ( echo "#!/bin/sh"
369 echo "exec $RPM_BUILD_ROOT$prefix/lib/openpkg/rpm \\"
370 echo " --rcfile \"$tmpdir/rpm.1\" \\"
371 echo " --define \"__platform $RPM_BUILD_ROOT$prefix/etc/openpkg/platform\" \\"
372 echo " \"\$@\""
373 ) >$tmpdir/rpm
374 chmod a+x $tmpdir/rpm
375
376 # direct our own "rpm" tool to adjusted macro sets
377 sed <`SOURCE rpmrc` >$tmpdir/rpm.1 \
378 -e "s;^\\(macrofiles:\\) .*;\\1 $tmpdir/rpm.2:$tmpdir/rpm.3;"
379
380 # use an adjusted vendor macro set
381 sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/macros >$tmpdir/rpm.2 \
382 -e "s;$prefix;$RPM_BUILD_ROOT$prefix;g"
383
384 # override the vendor macro set
385 sed <`SOURCE rpmmacros` >$tmpdir/rpm.3 \
386 -e "s;@SUSR@;$susr;" \
387 -e "s;@SGRP@;$sgrp;" \
388 -e "s;@MUSR@;$musr;" \
389 -e "s;@MGRP@;$mgrp;" \
390 -e "s;@RUSR@;$rusr;" \
391 -e "s;@RGRP@;$rgrp;" \
392 -e "s;@NUSR@;$nusr;" \
393 -e "s;@NGRP@;$ngrp;" \
394 -e "s;@TAG@;$tag;" \
395 -e "s;\\(%{l_prefix}/lib/openpkg/rpmtool\\);%{l_bash} \\1;g" \
396 -e "s;@l_prefix_static@;$prefix;g" \
397 -e "s;@l_prefix@;$RPM_BUILD_ROOT$prefix;g" \
398 -e "s;%l_prefix\\([^_]\\);%l_prefix_INTERNAL\\1;g" \
399 -e "s;%{l_prefix};%{l_prefix_INTERNAL};g" \
400 -e "s;^\\(%_specdir *\\).*;\\1 `pwd`;" \
401 -e "s;^\\(%_sourcedir *\\).*;\\1 $distdir;" \
402 -e "s;^\\(%_builddir *\\).*;\\1 $tmpdir;" \
403 -e "s;^\\(%_tmppath *\\).*;\\1 $tmpdir;" \
404 -e "s;^\\(%_buildshell *\\).*;\\1 env -i OPENPKG_BOOT=1 %{l_build_shell_cmd} %{l_build_shell_opt};" \
405 -e "s;@l_build_path@;/bin:/sbin:/usr/bin:/usr/sbin;g" \
406 -e "s;@l_build_ldlp@;/usr/lib;g" \
407 -e "s;@l_build_ulim@;:;g"
408 echo "%l_prefix $prefix" >>$tmpdir/rpm.3
409
410 # use an own $HOME/.popt in order to make sure the "rpm"
411 # tool is able to execute its sub-tools "rpm<x>".
412 V_rpm=`grep V_rpm $spec | sed -e 'q' | awk '{ printf("%s", $3); }'`
413 sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmpopt >$tmpdir/.popt \
414 -e "s;^\\(rpm.*exec.*\\)\\(rpm[bdieukvq]*\\);\\1$RPM_BUILD_ROOT$prefix/lib/openpkg/\\2;"
415
416 # activate the .popt file
417 HOME=$tmpdir
418 export HOME
419
420 ##
421 ## now initialize the RPM database under the temporary install location
422 ##
423
424 echo "++ initializing RPM database"
425 $RPM_BUILD_ROOT$prefix/lib/openpkg/bash \
426 $RPM_BUILD_ROOT$prefix/lib/openpkg/rpmdb \
427 --prefix=$RPM_BUILD_ROOT$prefix \
428 --dbpath=$RPM_BUILD_ROOT$prefix/RPM/DB \
429 --rpm=$tmpdir/rpm \
430 --build --quiet
431
432 ##
433 ## now turn over and re-iterate over the RPM spec, but this time
434 ## with the real RPM tool.
435 ##
436
437 echo "++ re-iterating over RPM specification procedures"
438 $tmpdir/rpm -bb $spec
439
440 ##
441 ## and finally overwrite the installation again, but this time by
442 ## installing officially through the "rpm" tool. This way we achieve
443 ## that RPM is remembered as an RPM package in its own database. We
444 ## just have to make sure the package is relocated while installing.
445 ## For this we could use --prefix=$RPM_BUILD_ROOT$prefix, but this
446 ## would create an incorrect filelist for "rpm" in the database.
447 ## Instead we use the --justdb option which means "rpm" behaves as it
448 ## would install into the real location, but does not actually install
449 ## anything. But as a side-effect, the database is now correct.
450 ##
451
452 echo "++ overwriting RPM installation by installing via RPM itself"
453 $tmpdir/rpm --install --justdb --force --noscripts --notriggers --ignoresize \
454 $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-*.rpm
455
456 ## Puhhhh!!! what a tricky bootstrapping procedure. But now we are
457 ## mostly finished. All we finally have to do is to roll a bootstrap
458 ## tarball in addition to the binary RPM and save the stuff in a
459 ## permanent location.
460
461 v="$version-$release"
462 t="`$tmpdir/rpm --eval '%{l_platform -p}-%{l_tag}'`"
463
464 # find a reasonable destination directory for packages
465 if [ -d ../PKG/BIN ]; then
466 dstdir=../PKG/BIN
467 elif [ -d ../PKG ]; then
468 dstdir=../PKG
469 elif [ -d ../../PKG/BIN ]; then
470 dstdir=../../PKG/BIN
471 elif [ -d ../../PKG ]; then
472 dstdir=../../PKG
473 else
474 dstdir=..
475 fi
476
477 # create Source-RPM file
478 echo "++ creating bootstrap source RPM file"
479 $tmpdir/rpm -bs --nodeps $spec
480 cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.src.rpm $dstdir/
481 rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.src.rpm
482
483 # create Binary-RPM file
484 echo "++ creating bootstrap binary RPM file"
485 cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.$t.rpm $dstdir/
486 rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.$t.rpm
487
488 # create Binary-Bootstrap file
489 echo "++ creating bootstrap binary shell script"
490 files=`cat $spec |\
491 sed -e '1,/%files/d' -e '/%clean/,$d' |\
492 grep -v '^ *$' | grep -v '%defattr' |\
493 sed -e 's;%config(noreplace) *;;' -e 's;%config *;;' -e 's;%ghost *;;' -e 's;%attr([^)]*) *;;' \
494 -e 's;%dir *;;' -e 's;%{l_prefix}/;;' -e 's;^ *;;' -e "s;%{V_rpm};${V_rpm};"`
495 db_files=""
496 for db_file in \
497 `$RPM_BUILD_ROOT$prefix/lib/openpkg/bash \
498 $RPM_BUILD_ROOT$prefix/lib/openpkg/rpmdb \
499 --prefix=$RPM_BUILD_ROOT$prefix \
500 --dbpath=$RPM_BUILD_ROOT$prefix/RPM/DB \
501 --list --quiet`; do
502 db_files="$db_files RPM/DB/$db_file"
503 done
504 chmod 644 $RPM_BUILD_ROOT$prefix/RPM/DB/*
505 files="$files $db_files"
506 ( cd $RPM_BUILD_ROOT$prefix
507 $RPM_BUILD_ROOT$prefix/lib/openpkg/tar --no-recursion -cf - $files
508 ) | $RPM_BUILD_ROOT$prefix/lib/openpkg/bzip2 -9 \
509 >$RPM_BUILD_ROOT$prefix/openpkg.tar.bz2
510 cp -p $RPM_BUILD_ROOT$prefix/lib/openpkg/tar \
511 $RPM_BUILD_ROOT$prefix/openpkg.tar
512 cp -p $RPM_BUILD_ROOT$prefix/lib/openpkg/bzip2 \
513 $RPM_BUILD_ROOT$prefix/openpkg.bzip2
514 l_platform=`$tmpdir/rpm --eval '%{l_platform -p}'`
515 l_version=`$tmpdir/rpm -q --qf '%{version}' openpkg`
516 release_sh=`SOURCE release.sh`
517 l_release=`sh $release_sh -r "$l_version" -F "%t"`
518 cat $spec |\
519 sed -e "/^%pre$/,/^%/ p" -e 'd' |\
520 sed -e '/^%/d' -e 's/^ //' |\
521 sed -e 's;%{[?]l_\([^:}]*\):\([^}]*\)};${\1+\2};g' \
522 -e 's;%{![?]l_\([^:}]*\):\([^}]*\)};${\1-\2};g' \
523 -e 's;%{[?]l_\([^:}]*\)};${\1+""};g' \
524 -e 's;%{![?]l_\([^:}]*\)};${\1-""};g' \
525 -e 's;%{l_\([^}]*\)};${\1};g' \
526 >$tmpdir/rpm.pre
527 cat $spec |\
528 sed -e "/^%post$/,/^%/ p" -e 'd' |\
529 sed -e '/^%/d' -e 's/^ //' |\
530 sed -e 's;%{[?]l_\([^:}]*\):\([^}]*\)};${\1+\2};g' \
531 -e 's;%{![?]l_\([^:}]*\):\([^}]*\)};${\1-\2};g' \
532 -e 's;%{[?]l_\([^:}]*\)};${\1+""};g' \
533 -e 's;%{![?]l_\([^:}]*\)};${\1-""};g' \
534 -e 's;%{l_\([^}]*\)};${\1};g' \
535 >$tmpdir/rpm.post
536 sed <`SOURCE aux.wrapbin.sh` \
537 -e "s;@SUSR@;$susr;" -e "s;@SGRP@;$sgrp;" \
538 -e "s;@MUSR@;$musr;" -e "s;@MGRP@;$mgrp;" \
539 -e "s;@RUSR@;$rusr;" -e "s;@RGRP@;$rgrp;" \
540 -e "s;@NUSR@;$nusr;" -e "s;@NGRP@;$ngrp;" \
541 -e "s;@SUID@;$suid;" -e "s;@SGID@;$sgid;" \
542 -e "s;@MUID@;$muid;" -e "s;@MGID@;$mgid;" \
543 -e "s;@RUID@;$ruid;" -e "s;@RGID@;$rgid;" \
544 -e "s;@NUID@;$nuid;" -e "s;@NGID@;$ngid;" \
545 -e "s;@l_prefix@;$prefix;" \
546 -e "s;@l_platform@;$l_platform;" \
547 -e "s;@l_release@;$l_release;" \
548 -e "s;@l_version@;$l_version;" \
549 -e "/^@PRE@/r $tmpdir/rpm.pre" \
550 -e "/^@POST@/r $tmpdir/rpm.post" |\
551 sed -e '/^@PRE@/d' -e '/^@POST@/d' >$tmpdir/openpkg.boot.tmp
552 echo . | awk '{
553 for (i = 0; i < 8192; i++) {
554 printf(" ");
555 }
556 }' >>$tmpdir/openpkg.boot.tmp
557 rm -f $dstdir/openpkg-$v.$t.sh
558 dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=8 \
559 of=$dstdir/openpkg-$v.$t.sh 2>/dev/null
560 rm -f $tmpdir/openpkg.boot.tmp
561 ( cd $RPM_BUILD_ROOT$prefix
562 $RPM_BUILD_ROOT$prefix/lib/openpkg/tar --no-recursion -cf - \
563 openpkg.tar openpkg.bzip2 openpkg.tar.bz2
564 ) >>$dstdir/openpkg-$v.$t.sh
565
566 # cleanup
567 echo "++ cleaning up"
568 cp `SOURCE rpmtool` $tmpdir/rpmtool
569 rm -rf $RPM_BUILD_ROOT
570 rm -rf $tmpdir/$name-$version
571 rm -f $tmpdir/rpm $tmpdir/rpm.[123] $tmpdir/.popt $tmpdir/rpm.pre $tmpdir/rpm.post
572 rm -f $prolog
573
574 # final hint about results
575 echo "++ resulting OpenPKG bootstrap package files:"
576 (cd $dstdir; ls -l openpkg-$v.$t.sh openpkg-$v.$t.rpm openpkg-$v.src.rpm)
577 set +x
578 ( echo "You have successfully built the OpenPKG Package from scratch"
579 echo "for prefix $prefix on target platform $l_platform. The input"
580 echo "was the OpenPKG Source Bootstrap Package in file:"
581 echo ""
582 echo " openpkg-$v.src.sh"
583 echo ""
584 echo "The results are the following three files:"
585 echo ""
586 echo " openpkg-$v.src.rpm"
587 echo " openpkg-$v.$t.rpm"
588 echo " openpkg-$v.$t.sh"
589 echo ""
590 echo "The first result file is the OpenPKG Source RPM Package,"
591 echo "containing just the same contents than the OpenPKG Source"
592 echo "Bootstrap Package, but now in RPM format. Optionally use this"
593 echo "after the installation of the OpenPKG Binary Bootstrap Package"
594 echo "if you want to rebuild from source again (but then with RPM"
595 echo "available)."
596 echo ""
597 echo "The second result file is the OpenPKG Binary RPM Package,"
598 echo "containing the installation files in RPM format for the OpenPKG"
599 echo "instance $prefix. Optionally use this after the installation of"
600 echo "the OpenPKG Binary Bootstrap Package if you want (usually for"
601 echo "fixing something) to reinstall (but then with RPM available)."
602 echo ""
603 echo "The third result file is the OpenPKG Binary Bootstrap Package,"
604 echo "containing the installation files as a self-extracting shell"
605 echo "script for the OpenPKG instance $prefix. Use this in YOUR NEXT"
606 echo "STEP to initially create the OpenPKG instance from scratch."
607 echo "Hence, proceed now by running the following command:"
608 echo ""
609 cusr=`(id -un) 2>/dev/null ||\
610 (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
611 (whoami) 2>/dev/null ||\
612 (who am i | cut "-d " -f1) 2>/dev/null ||\
613 echo $LOGNAME`
614 if [ ".$musr.$rusr.$nusr" = ".$cusr.$cusr.$cusr" -o ".$cusr" = ".root" ]; then
615 echo " \$ sh openpkg-$v.$t.sh"
616 else
617 echo " \$ su root -c \"sh openpkg-$v.$t.sh\""
618 fi
619 ) | sh $tmpdir/rpmtool msg -b -t info
620 rm -f $tmpdir/rpmtool
621

mercurial