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