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