diff -r 333964c621f1 -r cb59d6afeb61 openpkg/openpkg.boot
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/openpkg/openpkg.boot Tue Jan 06 23:40:39 2009 +0100
@@ -0,0 +1,621 @@
+#!/bin/sh
+##
+## openpkg.boot -- OpenPKG bootstrap procedure (look Ma, without hands ;)
+## Copyright (c) 2000-2007 OpenPKG Foundation e.V.
+## Copyright (c) 2000-2007 Ralf S. Engelschall
+##
+## Permission to use, copy, modify, and distribute this software for
+## any purpose with or without fee is hereby granted, provided that
+## the above copyright notice and this permission notice appear in all
+## copies.
+##
+## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+## SUCH DAMAGE.
+##
+
+# This is a very tricky procedure for building the OpenPKG bootstrap
+# package via the RPM specification openpkg.spec, but without
+# requiring that OpenPKG's RPM already exists. For this the
+# openpkg.spec file is manually executed here in order to build
+# OpenPKG RPM the first time (that is, we emulate a sufficient
+# subset of the RPM functionality), followed by a second round over
+# openpkg.spec with the real (and then existing) OpenPKG RPM tool.
+# Also keep in mind that lots of tricks are played here in order to
+# perform all the steps without having to touch the real installation
+# location. That is the whole procedure can (and should) be performed
+# by a non-privileged user and no access to the real installation
+# location filesystem location.
+
+me="openpkg.boot"
+
+##
+## command line handling
+##
+
+# command line parameters (defaults)
+help=0
+verbose=''
+prefix=''
+tag=''
+usr=''; grp=''
+susr=''; sgrp=''
+musr=''; mgrp=''
+rusr=''; rgrp=''
+nusr=''; ngrp=''
+suid=''; sgid=''
+muid=''; mgid=''
+ruid=''; rgid=''
+nuid=''; ngid=''
+use_tar=''; use_make=''; use_cc=''; use_ar=''; use_ld=''; use_as=''; use_strip=''
+bs=0
+
+# parse command line options
+for opt
+do
+ case $opt in
+ -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
+ *) arg='' ;;
+ esac
+ case $opt in
+ -h | --help ) help=1 ;;
+ -v | --verbose ) verbose=v ;;
+ --prefix=* ) prefix=$arg ;;
+ --tag=* ) tag=$arg ;;
+ --usr=* | --user=* ) usr=$arg ;;
+ --grp=* | --group=* ) grp=$arg ;;
+ --susr=* ) susr=$arg ;;
+ --sgrp=* ) sgrp=$arg ;;
+ --musr=* ) musr=$arg ;;
+ --mgrp=* ) mgrp=$arg ;;
+ --rusr=* ) rusr=$arg ;;
+ --rgrp=* ) rgrp=$arg ;;
+ --nusr=* ) nusr=$arg ;;
+ --ngrp=* ) ngrp=$arg ;;
+ --suid=* ) suid=$arg ;;
+ --sgid=* ) sgid=$arg ;;
+ --muid=* ) muid=$arg ;;
+ --mgid=* ) mgid=$arg ;;
+ --ruid=* ) ruid=$arg ;;
+ --rgid=* ) rgid=$arg ;;
+ --nuid=* ) nuid=$arg ;;
+ --ngid=* ) ngid=$arg ;;
+ --use_tar=* ) use_tar=$arg ;;
+ --use_make=* ) use_make=$arg ;;
+ --use_cc=* ) use_cc=$arg ;;
+ --use_ar=* ) use_ar=$arg ;;
+ --use_ld=* ) use_ld=$arg ;;
+ --use_as=* ) use_as=$arg ;;
+ --use_strip=* ) use_strip=$arg ;;
+ -bs | -s ) bs=1 ;;
+ * ) help=1 ;;
+ esac
+done
+if [ ".$bs" = .0 -a ".$prefix" = . ]; then
+ help=1
+fi
+if [ ".$help" = .1 ]; then
+ echo "Usage: sh $me" 2>&1
+ echo " [--prefix=] [--tag=]" 2>&1
+ echo " [--user=] [--group=]" 2>&1
+ echo " [--{s,m,r,n}usr=] [--{s,m,r,n}grp=]" 2>&1
+ echo " [--{s,m,r,n}uid=] [--{s,m,r,n}gid=]" 2>&1
+ echo " [--use_tar=] [--use_make=] [--use_cc=]" 2>&1
+ echo " [--use_ar=] [--use_ld=] [--use_as=] [--use_strip=]" 2>&1
+ echo " [-t|--tar] [-h|--help] [-v|--version]" 2>&1
+ exit 1
+fi
+
+# determine missing parameters
+eval `sh aux.usrgrp.sh \
+ --usr="$usr" --grp="$grp" \
+ --susr="$susr" --sgrp="$sgrp" \
+ --musr="$musr" --mgrp="$mgrp" \
+ --rusr="$rusr" --rgrp="$rgrp" \
+ --nusr="$nusr" --ngrp="$ngrp" \
+ --suid="$suid" --sgid="$sgid" \
+ --muid="$muid" --mgid="$mgid" \
+ --ruid="$ruid" --rgid="$rgid" \
+ --nuid="$nuid" --ngid="$ngid"`
+
+# canonicalize prefix
+prefix=`echo "$prefix" | sed -e 's;//*;/;g' -e 's;/$;;'`
+
+# provide default package tag
+if [ ".$tag" = . ]; then
+ tag=""
+fi
+
+##
+## determine package information
+##
+
+name="openpkg"
+spec="$name.spec"
+version=`grep V_openpkg $spec | sed -e 'q' | awk '{ printf("%s", $3); }'`
+release="$version"
+
+##
+## display headline
+##
+
+sh ./shtool echo -e "%BOpenPKG Bootstrap Procedure%b"
+echo "++ bootstrap version: $version-$release"
+echo "++ user/group pairs: $susr/$sgrp $musr/$mgrp $rusr/$rgrp $nusr/$ngrp"
+
+##
+## optionally roll just a bootstrap source package
+##
+
+if [ ".$bs" = .1 ]; then
+ srcdir=.
+ if [ -d ../../dst ]; then
+ dstdir=../../dst/openpkg
+ else
+ dstdir=.
+ fi
+ tmpdir="/tmp/$me.$$.d"
+ if [ -d ../PKG/SRC ]; then
+ pkgdir=../PKG/SRC
+ elif [ -d ../PKG ]; then
+ pkgdir=../PKG
+ elif [ -d ../../PKG/SRC ]; then
+ pkgdir=../../PKG/SRC
+ elif [ -d ../../PKG ]; then
+ pkgdir=../../PKG
+ elif [ -d ../../pkg/src ]; then
+ pkgdir=../../pkg/src
+ elif [ -d ../../pkg ]; then
+ pkgdir=../../pkg
+ else
+ pkgdir=..
+ fi
+ echo "** rolling source bootstrap package:"
+ echo " $pkgdir/$name-$version-$release.src.sh"
+ rm -rf $tmpdir
+ mkdir $tmpdir
+ ( echo "dstdir=$dstdir"
+ echo "srcdir=$srcdir"
+ echo "tmpdir=$tmpdir"
+ grep '^%define' $spec | sed -e 's:^%define *\([^ ]*\) *\(.*\):\1="\2":'
+ grep '^Source' $spec | sed -e 's;^Source[0-9]*: *;;' -e 's;^.*/;$dstdir/;' \
+ -e 's;^\([^/]*\)$;$srcdir/\1;' -e 's;%;$;g' \
+ -e 's;^\(.*\)$;cp \1 $tmpdir/;'
+ echo "cp -p $spec $tmpdir/"
+ ) >$tmpdir/.sh
+ sh $tmpdir/.sh
+ rm -f $tmpdir/.sh
+ l_version="$release"
+ l_release=`sh ./release.sh -r "${l_version}" -F "%t"`
+ sed <$srcdir/aux.wrapsrc.sh >$tmpdir/openpkg.boot.tmp \
+ -e "s;@l_dir@;$name-$version-$release.src;" \
+ -e "s;@l_release@;$l_release;" \
+ -e "s;@l_version@;$l_version;"
+ echo . | awk '{
+ for (i = 0; i < 8192; i++) {
+ printf(" ");
+ }
+ }' >>$tmpdir/openpkg.boot.tmp
+ dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=8 \
+ of=$pkgdir/$name-$version-$release.src.sh 2>/dev/null
+ rm -f $tmpdir/openpkg.boot.tmp
+ (cd $tmpdir && tar cf - *) >>$pkgdir/$name-$version-$release.src.sh
+ rm -rf $tmpdir
+ exit 0
+fi
+
+##
+## determine distribution directory
+##
+
+V_rpm=`grep V_rpm $spec | sed -e 'q' | awk '{ printf("%s", $3); }'`
+if [ -f "../../dst/openpkg/rpm-${V_rpm}.tar.gz" ]; then
+ distdir="`cd ../../dst/openpkg; pwd`" # developer only
+else
+ distdir="`pwd`"
+fi
+echo "++ distribution directory: $distdir"
+
+##
+## perform prerequisite checks
+##
+
+sh ./aux.prereq.sh source || exit $?
+
+##
+## find reasonable run-time paths and tools
+##
+
+# find reasonable temporary directory
+tmpdir="${TMPDIR-/tmp}"
+
+# find reasonable safe program path
+test ".$PATH" = . && PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin"
+for dir in /usr/ccs/bin /usr/xpg4/bin; do
+ test -d $dir && PATH="$PATH:$dir"
+done
+export PATH
+
+# make environment at least partly sane
+umask 022
+unset ls rm mv cp sed grep awk >/dev/null 2>&1 || true
+
+##
+## execute the spec file manually by emulating
+## the behaviour of the OpenPKG RPM tool.
+##
+
+# create script prolog
+prolog="$tmpdir/openpkg.boot.prolog.sh"
+cp /dev/null $prolog
+(
+ echo "_specdir=`pwd`"
+ echo "_sourcedir=$distdir"
+ echo "_tmppath=$tmpdir"
+ echo "_builddir=$tmpdir"
+ echo "l_prefix=$prefix"
+ echo "l_tag_fmt=\"$tag\""
+ echo "l_buildroot=$tmpdir/$name-$version-root"
+ echo "l_susr=$susr"
+ echo "l_sgrp=$sgrp"
+ echo "l_musr=$musr"
+ echo "l_mgrp=$mgrp"
+ echo "l_rusr=$rusr"
+ echo "l_rgrp=$rgrp"
+ echo "l_nusr=$nusr"
+ echo "l_ngrp=$ngrp"
+ echo "l_suid=$suid"
+ echo "l_sgid=$sgid"
+ echo "l_muid=$muid"
+ echo "l_mgid=$mgid"
+ echo "l_ruid=$ruid"
+ echo "l_rgid=$rgid"
+ echo "l_nuid=$nuid"
+ echo "l_ngid=$ngid"
+ echo "use_tar=$use_tar"
+ echo "use_make=$use_make"
+ echo "use_cc=$use_cc"
+ echo "use_ar=$use_ar"
+ echo "use_ld=$use_ld"
+ echo "use_as=$use_as"
+ echo "use_strip=$use_strip"
+ grep '%define' $spec | \
+ sed \
+ -e 's:^%define *\([^ ]*\) *\(.*\):\1="\2":'
+ grep "^[A-Za-z0-9]*: *" $spec | \
+ sed \
+ -e 's;^\([A-Za-z0-9]*\): *\(.*\)$;\1="\2";' \
+ -e 's;^A;a;' -e 's;^B;b;' -e 's;^C;c;' -e 's;^D;d;' -e 's;^E;e;' \
+ -e 's;^F;f;' -e 's;^G;g;' -e 's;^H;h;' -e 's;^I;i;' -e 's;^J;j;' \
+ -e 's;^K;k;' -e 's;^L;l;' -e 's;^M;m;' -e 's;^N;n;' -e 's;^O;o;' \
+ -e 's;^P;p;' -e 's;^Q;q;' -e 's;^R;r;' -e 's;^S;s;' -e 's;^T;t;' \
+ -e 's;^U;u;' -e 's;^V;v;' -e 's;^W;w;' -e 's;^X;x;' -e 's;^Y;y;' \
+ -e 's;^Z;z;' -e 's;^buildRoot;buildroot;'
+ echo "RPM_BUILD_ROOT=\"%{buildroot}\""
+ echo "RPM_BUILD_DIR=\"%{_builddir}\""
+ echo "RPM_SOURCE_DIR=\"$distdir\""
+ echo "export RPM_BUILD_ROOT"
+ echo "export RPM_BUILD_DIR"
+ echo "export RPM_SOURCE_DIR"
+ echo "set -x"
+ echo "umask 022"
+ echo "cd \$RPM_BUILD_DIR"
+) | sed -e 's;%{\([^}]*\)};${\1};g' >$prolog
+
+# install package via RPM spec file by faking a
+# sufficiently enough RPM run-time environment
+runscript () {
+ step=$1
+ script="$tmpdir/openpkg.boot.$step.sh"
+ echo ". $prolog" >$script
+ sed -e "/^%$step/,/^%/ p" -e 'd' <$spec | \
+ sed -e '/^%/d' | \
+ sed -e 's;%{SOURCE \([^ ]*\.tar[^ ]*\)};${RPM_DIST_DIR}/\1;g' \
+ -e 's;%{SOURCE \([^ ]*\)};${RPM_SOURCE_DIR}/\1;g' | \
+ sed -e 's;%{[?]\([^:}]*\):\([^}]*\)};${\1+\2};g' \
+ -e 's;%{![?]\([^:}]*\):\([^}]*\)};${\1-\2};g' \
+ -e 's;%{[?]\([^:}]*\)};${\1+""};g' \
+ -e 's;%{![?]\([^:}]*\)};${\1-""};g' \
+ -e 's;%{\([^}]*\)};${\1};g' >>$script
+ echo "++ executing(%$step): sh $script"
+ sh $script
+ if [ $? -ne 0 ]; then
+ rm -f $script
+ echo "$0:ERROR: script returned non-null value"
+ exit 1
+ fi
+ rm -f $script
+}
+runscript prep
+runscript build
+runscript install
+
+##
+## adjust build environment so that the installed
+## "rpm" is actually useable, although it still resides in
+## the temporary location instead of the real location.
+##
+
+# suck in prolog in order to get variables from the spec file
+cwd=`pwd`
+. $prolog
+cd $cwd
+
+# suck in buildenv script in order to get musr/mgrp
+. $tmpdir/openpkg-*/.buildenv
+
+# create a custom "rpm" command
+echo "++ creating custom RPM command"
+rm -f $tmpdir/rpm >/dev/null 2>&1
+rmdir $tmpdir/rpm >/dev/null 2>&1
+if [ -d "$tmpdir/rpm" ]; then
+ echo "$0:ERROR: directory $tmpdir/rpm exists, cannot create file with same name"
+ exit 1
+fi
+if [ -f "$tmpdir/rpm" ]; then
+ echo "$0:ERROR: file $tmpdir/rpm exists, cannot override"
+ exit 1
+fi
+( echo "#!/bin/sh"
+ echo "exec $RPM_BUILD_ROOT$prefix/lib/openpkg/rpm \\"
+ echo " --rcfile \"$tmpdir/rpm.1\" \\"
+ echo " --define \"__platform $RPM_BUILD_ROOT$prefix/etc/openpkg/platform\" \\"
+ echo " \"\$@\""
+) >$tmpdir/rpm
+chmod a+x $tmpdir/rpm
+
+# direct our own "rpm" tool to adjusted macro sets
+sed <`SOURCE rpmrc` >$tmpdir/rpm.1 \
+ -e "s;^\\(macrofiles:\\) .*;\\1 $tmpdir/rpm.2:$tmpdir/rpm.3;"
+
+# use an adjusted vendor macro set
+sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/macros >$tmpdir/rpm.2 \
+ -e "s;$prefix;$RPM_BUILD_ROOT$prefix;g"
+
+# override the vendor macro set
+sed <`SOURCE rpmmacros` >$tmpdir/rpm.3 \
+ -e "s;@SUSR@;$susr;" \
+ -e "s;@SGRP@;$sgrp;" \
+ -e "s;@MUSR@;$musr;" \
+ -e "s;@MGRP@;$mgrp;" \
+ -e "s;@RUSR@;$rusr;" \
+ -e "s;@RGRP@;$rgrp;" \
+ -e "s;@NUSR@;$nusr;" \
+ -e "s;@NGRP@;$ngrp;" \
+ -e "s;@TAG@;$tag;" \
+ -e "s;\\(%{l_prefix}/lib/openpkg/rpmtool\\);%{l_bash} \\1;g" \
+ -e "s;@l_prefix_static@;$prefix;g" \
+ -e "s;@l_prefix@;$RPM_BUILD_ROOT$prefix;g" \
+ -e "s;%l_prefix\\([^_]\\);%l_prefix_INTERNAL\\1;g" \
+ -e "s;%{l_prefix};%{l_prefix_INTERNAL};g" \
+ -e "s;^\\(%_specdir *\\).*;\\1 `pwd`;" \
+ -e "s;^\\(%_sourcedir *\\).*;\\1 $distdir;" \
+ -e "s;^\\(%_builddir *\\).*;\\1 $tmpdir;" \
+ -e "s;^\\(%_tmppath *\\).*;\\1 $tmpdir;" \
+ -e "s;^\\(%_buildshell *\\).*;\\1 env -i OPENPKG_BOOT=1 %{l_build_shell_cmd} %{l_build_shell_opt};" \
+ -e "s;@l_build_path@;/bin:/sbin:/usr/bin:/usr/sbin;g" \
+ -e "s;@l_build_ldlp@;/usr/lib;g" \
+ -e "s;@l_build_ulim@;:;g"
+echo "%l_prefix $prefix" >>$tmpdir/rpm.3
+
+# use an own $HOME/.popt in order to make sure the "rpm"
+# tool is able to execute its sub-tools "rpm".
+V_rpm=`grep V_rpm $spec | sed -e 'q' | awk '{ printf("%s", $3); }'`
+sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmpopt >$tmpdir/.popt \
+ -e "s;^\\(rpm.*exec.*\\)\\(rpm[bdieukvq]*\\);\\1$RPM_BUILD_ROOT$prefix/lib/openpkg/\\2;"
+
+# activate the .popt file
+HOME=$tmpdir
+export HOME
+
+##
+## now initialize the RPM database under the temporary install location
+##
+
+echo "++ initializing RPM database"
+$RPM_BUILD_ROOT$prefix/lib/openpkg/bash \
+$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmdb \
+ --prefix=$RPM_BUILD_ROOT$prefix \
+ --dbpath=$RPM_BUILD_ROOT$prefix/RPM/DB \
+ --rpm=$tmpdir/rpm \
+ --build --quiet
+
+##
+## now turn over and re-iterate over the RPM spec, but this time
+## with the real RPM tool.
+##
+
+echo "++ re-iterating over RPM specification procedures"
+$tmpdir/rpm -bb $spec
+
+##
+## and finally overwrite the installation again, but this time by
+## installing officially through the "rpm" tool. This way we achieve
+## that RPM is remembered as an RPM package in its own database. We
+## just have to make sure the package is relocated while installing.
+## For this we could use --prefix=$RPM_BUILD_ROOT$prefix, but this
+## would create an incorrect filelist for "rpm" in the database.
+## Instead we use the --justdb option which means "rpm" behaves as it
+## would install into the real location, but does not actually install
+## anything. But as a side-effect, the database is now correct.
+##
+
+echo "++ overwriting RPM installation by installing via RPM itself"
+$tmpdir/rpm --install --justdb --force --noscripts --notriggers --ignoresize \
+ $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-*.rpm
+
+## Puhhhh!!! what a tricky bootstrapping procedure. But now we are
+## mostly finished. All we finally have to do is to roll a bootstrap
+## tarball in addition to the binary RPM and save the stuff in a
+## permanent location.
+
+v="$version-$release"
+t="`$tmpdir/rpm --eval '%{l_platform -p}-%{l_tag}'`"
+
+# find a reasonable destination directory for packages
+if [ -d ../PKG/BIN ]; then
+ dstdir=../PKG/BIN
+elif [ -d ../PKG ]; then
+ dstdir=../PKG
+elif [ -d ../../PKG/BIN ]; then
+ dstdir=../../PKG/BIN
+elif [ -d ../../PKG ]; then
+ dstdir=../../PKG
+else
+ dstdir=..
+fi
+
+# create Source-RPM file
+echo "++ creating bootstrap source RPM file"
+$tmpdir/rpm -bs --nodeps $spec
+cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.src.rpm $dstdir/
+rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.src.rpm
+
+# create Binary-RPM file
+echo "++ creating bootstrap binary RPM file"
+cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.$t.rpm $dstdir/
+rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.$t.rpm
+
+# create Binary-Bootstrap file
+echo "++ creating bootstrap binary shell script"
+files=`cat $spec |\
+ sed -e '1,/%files/d' -e '/%clean/,$d' |\
+ grep -v '^ *$' | grep -v '%defattr' |\
+ sed -e 's;%config(noreplace) *;;' -e 's;%config *;;' -e 's;%ghost *;;' -e 's;%attr([^)]*) *;;' \
+ -e 's;%dir *;;' -e 's;%{l_prefix}/;;' -e 's;^ *;;' -e "s;%{V_rpm};${V_rpm};"`
+db_files=""
+for db_file in \
+ `$RPM_BUILD_ROOT$prefix/lib/openpkg/bash \
+ $RPM_BUILD_ROOT$prefix/lib/openpkg/rpmdb \
+ --prefix=$RPM_BUILD_ROOT$prefix \
+ --dbpath=$RPM_BUILD_ROOT$prefix/RPM/DB \
+ --list --quiet`; do
+ db_files="$db_files RPM/DB/$db_file"
+done
+chmod 644 $RPM_BUILD_ROOT$prefix/RPM/DB/*
+files="$files $db_files"
+( cd $RPM_BUILD_ROOT$prefix
+ $RPM_BUILD_ROOT$prefix/lib/openpkg/tar --no-recursion -cf - $files
+) | $RPM_BUILD_ROOT$prefix/lib/openpkg/bzip2 -9 \
+ >$RPM_BUILD_ROOT$prefix/openpkg.tar.bz2
+cp -p $RPM_BUILD_ROOT$prefix/lib/openpkg/tar \
+ $RPM_BUILD_ROOT$prefix/openpkg.tar
+cp -p $RPM_BUILD_ROOT$prefix/lib/openpkg/bzip2 \
+ $RPM_BUILD_ROOT$prefix/openpkg.bzip2
+l_platform=`$tmpdir/rpm --eval '%{l_platform -p}'`
+l_version=`$tmpdir/rpm -q --qf '%{version}' openpkg`
+release_sh=`SOURCE release.sh`
+l_release=`sh $release_sh -r "$l_version" -F "%t"`
+cat $spec |\
+ sed -e "/^%pre$/,/^%/ p" -e 'd' |\
+ sed -e '/^%/d' -e 's/^ //' |\
+ sed -e 's;%{[?]l_\([^:}]*\):\([^}]*\)};${\1+\2};g' \
+ -e 's;%{![?]l_\([^:}]*\):\([^}]*\)};${\1-\2};g' \
+ -e 's;%{[?]l_\([^:}]*\)};${\1+""};g' \
+ -e 's;%{![?]l_\([^:}]*\)};${\1-""};g' \
+ -e 's;%{l_\([^}]*\)};${\1};g' \
+ >$tmpdir/rpm.pre
+cat $spec |\
+ sed -e "/^%post$/,/^%/ p" -e 'd' |\
+ sed -e '/^%/d' -e 's/^ //' |\
+ sed -e 's;%{[?]l_\([^:}]*\):\([^}]*\)};${\1+\2};g' \
+ -e 's;%{![?]l_\([^:}]*\):\([^}]*\)};${\1-\2};g' \
+ -e 's;%{[?]l_\([^:}]*\)};${\1+""};g' \
+ -e 's;%{![?]l_\([^:}]*\)};${\1-""};g' \
+ -e 's;%{l_\([^}]*\)};${\1};g' \
+ >$tmpdir/rpm.post
+sed <`SOURCE aux.wrapbin.sh` \
+ -e "s;@SUSR@;$susr;" -e "s;@SGRP@;$sgrp;" \
+ -e "s;@MUSR@;$musr;" -e "s;@MGRP@;$mgrp;" \
+ -e "s;@RUSR@;$rusr;" -e "s;@RGRP@;$rgrp;" \
+ -e "s;@NUSR@;$nusr;" -e "s;@NGRP@;$ngrp;" \
+ -e "s;@SUID@;$suid;" -e "s;@SGID@;$sgid;" \
+ -e "s;@MUID@;$muid;" -e "s;@MGID@;$mgid;" \
+ -e "s;@RUID@;$ruid;" -e "s;@RGID@;$rgid;" \
+ -e "s;@NUID@;$nuid;" -e "s;@NGID@;$ngid;" \
+ -e "s;@l_prefix@;$prefix;" \
+ -e "s;@l_platform@;$l_platform;" \
+ -e "s;@l_release@;$l_release;" \
+ -e "s;@l_version@;$l_version;" \
+ -e "/^@PRE@/r $tmpdir/rpm.pre" \
+ -e "/^@POST@/r $tmpdir/rpm.post" |\
+ sed -e '/^@PRE@/d' -e '/^@POST@/d' >$tmpdir/openpkg.boot.tmp
+echo . | awk '{
+ for (i = 0; i < 8192; i++) {
+ printf(" ");
+ }
+}' >>$tmpdir/openpkg.boot.tmp
+rm -f $dstdir/openpkg-$v.$t.sh
+dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=8 \
+ of=$dstdir/openpkg-$v.$t.sh 2>/dev/null
+rm -f $tmpdir/openpkg.boot.tmp
+( cd $RPM_BUILD_ROOT$prefix
+ $RPM_BUILD_ROOT$prefix/lib/openpkg/tar --no-recursion -cf - \
+ openpkg.tar openpkg.bzip2 openpkg.tar.bz2
+) >>$dstdir/openpkg-$v.$t.sh
+
+# cleanup
+echo "++ cleaning up"
+cp `SOURCE rpmtool` $tmpdir/rpmtool
+rm -rf $RPM_BUILD_ROOT
+rm -rf $tmpdir/$name-$version
+rm -f $tmpdir/rpm $tmpdir/rpm.[123] $tmpdir/.popt $tmpdir/rpm.pre $tmpdir/rpm.post
+rm -f $prolog
+
+# final hint about results
+echo "++ resulting OpenPKG bootstrap package files:"
+(cd $dstdir; ls -l openpkg-$v.$t.sh openpkg-$v.$t.rpm openpkg-$v.src.rpm)
+set +x
+( echo "You have successfully built the OpenPKG Package from scratch"
+ echo "for prefix $prefix on target platform $l_platform. The input"
+ echo "was the OpenPKG Source Bootstrap Package in file:"
+ echo ""
+ echo " openpkg-$v.src.sh"
+ echo ""
+ echo "The results are the following three files:"
+ echo ""
+ echo " openpkg-$v.src.rpm"
+ echo " openpkg-$v.$t.rpm"
+ echo " openpkg-$v.$t.sh"
+ echo ""
+ echo "The first result file is the OpenPKG Source RPM Package,"
+ echo "containing just the same contents than the OpenPKG Source"
+ echo "Bootstrap Package, but now in RPM format. Optionally use this"
+ echo "after the installation of the OpenPKG Binary Bootstrap Package"
+ echo "if you want to rebuild from source again (but then with RPM"
+ echo "available)."
+ echo ""
+ echo "The second result file is the OpenPKG Binary RPM Package,"
+ echo "containing the installation files in RPM format for the OpenPKG"
+ echo "instance $prefix. Optionally use this after the installation of"
+ echo "the OpenPKG Binary Bootstrap Package if you want (usually for"
+ echo "fixing something) to reinstall (but then with RPM available)."
+ echo ""
+ echo "The third result file is the OpenPKG Binary Bootstrap Package,"
+ echo "containing the installation files as a self-extracting shell"
+ echo "script for the OpenPKG instance $prefix. Use this in YOUR NEXT"
+ echo "STEP to initially create the OpenPKG instance from scratch."
+ echo "Hence, proceed now by running the following command:"
+ echo ""
+ cusr=`(id -un) 2>/dev/null ||\
+ (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
+ (whoami) 2>/dev/null ||\
+ (who am i | cut "-d " -f1) 2>/dev/null ||\
+ echo $LOGNAME`
+ if [ ".$musr.$rusr.$nusr" = ".$cusr.$cusr.$cusr" -o ".$cusr" = ".root" ]; then
+ echo " \$ sh openpkg-$v.$t.sh"
+ else
+ echo " \$ su root -c \"sh openpkg-$v.$t.sh\""
+ fi
+) | sh $tmpdir/rpmtool msg -b -t info
+rm -f $tmpdir/rpmtool
+