michael@13: #!/bin/sh michael@13: ## michael@13: ## openpkg.boot -- OpenPKG bootstrap procedure (look Ma, without hands ;) michael@428: ## Copyright (c) 2000-2012 OpenPKG GmbH michael@13: ## michael@428: ## This software is property of the OpenPKG GmbH, DE MUC HRB 160208. michael@428: ## All rights reserved. Licenses which grant limited permission to use, michael@428: ## copy, modify and distribute this software are available from the michael@428: ## OpenPKG GmbH. michael@13: ## michael@428: ## 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@447: # by a nonprivileged 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@428: stack='' michael@428: unprivileged=no 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@428: --stack=* ) stack=$arg ;; michael@428: --unprivileged ) unprivileged=yes ;; 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@428: echo " [--stack=] [--unprivileged]" 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@428: # special support for environments with only a single michael@428: # fully unprivileged user account (the current user) michael@428: if [ ".$unprivileged" = .yes ]; then michael@428: # determine current user/group michael@428: cusr=`(id -un) 2>/dev/null ||\ michael@428: (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\ michael@428: (whoami) 2>/dev/null ||\ michael@428: (who am i | cut "-d " -f1) 2>/dev/null ||\ michael@428: echo $LOGNAME` michael@428: cgid=`(id -g $cusr) 2>/dev/null ||\ michael@428: ((getent passwd "${cusr}"; grep "^${cusr}:" /etc/passwd; ypmatch "${cusr}" passwd; nismatch "${cusr}" passwd; nidump passwd . | grep "^${cusr}:") 2>/dev/null |\ michael@428: sed -n -e '1p' | awk -F: '{ print $4; }')` michael@428: cgrp=`(id -gn $cusr) 2>/dev/null ||\ michael@428: ((getent group; cat /etc/group; ypcat group; niscat group; nidump group .) 2>/dev/null | grep "^[^:]*:[^:]*:${cgid}:" |\ michael@428: sed -n -e '1p' | awk -F: '{ print $1; }')` michael@428: [ ".$cgrp" = . ] && cgrp="$cusr" michael@428: michael@428: # set all other user/group variants to current user/group michael@428: for who in s m r n; do michael@428: for what in usr grp; do michael@428: eval "${who}${what}=\"\$c${what}\"" michael@428: done michael@428: done michael@428: fi michael@428: michael@13: # determine missing parameters michael@428: eval `sh etc.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@428: version=`grep '^Version:' $spec | sed -e 'q' | awk '{ printf("%s", $2); }'` michael@428: release=`grep '^Release:' $spec | sed -e 'q' | awk '{ printf("%s", $2); }'` 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@428: if [ -d ../dst ]; then michael@428: dstdir=../dst michael@428: elif [ -d ../../dst/openpkg ]; then michael@13: dstdir=../../dst/openpkg michael@13: else michael@13: dstdir=. michael@13: fi michael@13: tmpdir="/tmp/$me.$$.d" michael@428: if [ -d ../pkg ]; then michael@428: pkgdir=../pkg michael@428: elif [ -d ../../pkg/openpkg ]; then michael@428: pkgdir=../../pkg/openpkg 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@428: sed <$srcdir/etc.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@450: for (i = 0; i < 8192*2; i++) { michael@13: printf(" "); michael@13: } michael@13: }' >>$tmpdir/openpkg.boot.tmp michael@450: dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=10 \ 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@428: if [ -d ../dst ]; then michael@428: distdir="`cd ../dst; pwd`" michael@428: elif [ -d ../../dst/openpkg ]; then michael@428: distdir="`cd ../../dst/openpkg; pwd`" 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@428: sh ./etc.prereq.sh source || exit $? michael@13: michael@13: ## michael@447: ## find reasonable runtime paths and tools michael@13: ## michael@13: michael@13: # find reasonable temporary directory michael@428: if [ -d ../tmp ]; then michael@428: tmpdir="`cd ../tmp; pwd`" michael@428: else michael@428: tmpdir="${TMPDIR-/tmp}" michael@428: fi 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@428: echo "l_stack=$stack" michael@428: echo "l_buildroot=$tmpdir/$name-$version-$release-buildroot" 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@428: echo "l_unprivileged=$unprivileged" 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@447: # sufficiently enough RPM runtime 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@447: echo "$0:ERROR: script returned nonnull 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@428: ## "rpm" is actually usable, 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@428: # (and direct it to an adjusted macro set) 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@428: echo " --macros \"$tmpdir/rpm.1:$tmpdir/rpm.2:$tmpdir/rpm.3\" \\" michael@428: echo " --rpmpopt \"$tmpdir/rpm.4:$tmpdir/rpm.5\" \\" michael@428: echo " --rpmlua \"$tmpdir/rpm.6\" \\" michael@13: echo " \"\$@\"" michael@13: ) >$tmpdir/rpm michael@13: chmod a+x $tmpdir/rpm michael@13: michael@13: # use an adjusted vendor macro set michael@428: rm -f $tmpdir/rpm.1 >/dev/null 2>&1 michael@428: sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmmacros >$tmpdir/rpm.1 \ michael@13: -e "s;$prefix;$RPM_BUILD_ROOT$prefix;g" michael@13: michael@13: # override the vendor macro set michael@428: rm -f $tmpdir/rpm.2 >/dev/null 2>&1 michael@428: sed <`SOURCE rpmmacros` >$tmpdir/rpm.2 \ 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@428: -e "s;@l_unprivileged@;$unprivileged;" \ 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@428: -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: michael@428: # provide some special overrides michael@428: rm -f $tmpdir/rpm.3 >/dev/null 2>&1 michael@428: ( echo "%l_prefix $prefix" michael@428: echo "%l_rpm $tmpdir/rpm" michael@428: echo "%__spec_install_pre %{nil}" michael@428: echo "%__spec_clean_body %{nil}" michael@428: echo "%__platform $RPM_BUILD_ROOT$prefix/etc/openpkg/platform" michael@428: echo "%_integrity_spec_cfg $RPM_BUILD_ROOT$prefix/etc/openpkg/license.d/BOOT" michael@428: echo "%_integrity_proc_lua $RPM_BUILD_ROOT$prefix/lib/openpkg/license.lua" michael@428: echo "%_integrity_pkey_pgp $RPM_BUILD_ROOT$prefix/etc/openpkg/openpkg.com.pgp" michael@428: ) >$tmpdir/rpm.3 michael@13: michael@428: # use an adjusted vendor POPT config michael@428: rm -f $tmpdir/rpm.4 >/dev/null 2>&1 michael@428: sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmpopt >$tmpdir/rpm.4 \ michael@428: -e "s;$prefix;$RPM_BUILD_ROOT$prefix;g" michael@428: michael@428: # override the vendor POPT config michael@428: rm -f $tmpdir/rpm.5 >/dev/null 2>&1 michael@428: sed <$RPM_BUILD_ROOT$prefix/etc/openpkg/rpmpopt >$tmpdir/rpm.5 \ michael@428: -e "s;@l_prefix@;$RPM_BUILD_ROOT$prefix;g" michael@428: michael@428: # use an adjusted vendor RPM Lua script michael@428: rm -f $tmpdir/rpm.6 >/dev/null 2>&1 michael@428: sed <$RPM_BUILD_ROOT$prefix/etc/openpkg/rpmlua >$tmpdir/rpm.6 \ michael@428: -e "s;@l_prefix@;$RPM_BUILD_ROOT$prefix;g" 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@447: ## now turn over and reiterate over the RPM spec, but this time michael@13: ## with the real RPM tool. michael@13: ## michael@13: michael@447: echo "++ reiterating 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@447: ## 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@428: $tmpdir/rpm --install --justdb --replacepkgs --replacefiles --oldpackage --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@428: if [ -d ../pkg ]; then michael@428: pkgdir=../pkg michael@428: elif [ -d ../../pkg/openpkg ]; then michael@428: pkgdir=../../pkg/openpkg michael@13: else michael@428: pkgdir=.. michael@13: fi michael@13: michael@447: # create Source RPM file michael@13: echo "++ creating bootstrap source RPM file" michael@428: $tmpdir/rpm -bs --nodeps --define "_srcrpmdir $pkgdir" $spec michael@13: michael@447: # create Binary RPM file michael@428: # (notice that there might be a discrepancy in the platform michael@428: # identification, so we have to copy the source via wildcard) michael@13: echo "++ creating bootstrap binary RPM file" michael@428: cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-*.rpm $pkgdir/openpkg-$v.$t.rpm michael@428: rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-*.rpm michael@13: michael@447: # 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@428: rm -f $RPM_BUILD_ROOT$prefix/RPM/DB/__db.[0-9]* 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@428: --rpm=$tmpdir/rpm \ michael@428: --list --quiet` VERSION; 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@428: sed <`SOURCE etc.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@428: -e "s;@l_unprivileged@;$unprivileged;" \ 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@450: for (i = 0; i < 8192*2; i++) { michael@13: printf(" "); michael@13: } michael@13: }' >>$tmpdir/openpkg.boot.tmp michael@428: rm -f $pkgdir/openpkg-$v.$t.sh michael@450: dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=10 \ michael@428: of=$pkgdir/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@428: ) >>$pkgdir/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@428: rm -f $tmpdir/rpm $tmpdir/rpm.[123456] $tmpdir/rpm.pre $tmpdir/rpm.post michael@13: rm -f $prolog michael@13: michael@13: # final hint about results michael@428: echo "++ resulting OpenPKG Framework bootstrap package files:" michael@428: (cd $pkgdir; ls -l openpkg-$v.$t.sh openpkg-$v.$t.rpm openpkg-$v.src.rpm) michael@13: set +x michael@428: ( echo "You have successfully built the OpenPKG Framework from scratch" michael@13: echo "for prefix $prefix on target platform $l_platform. The input" michael@428: echo "was the OpenPKG Framework 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@428: echo "The first result file is the OpenPKG Framework Source RPM Package," michael@428: echo "containing just the same contents than the OpenPKG Framework Source" michael@428: echo "Bootstrap Package, but now in RPM format. Optionally use this after" michael@428: echo "the installation of the OpenPKG Framework 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@428: echo "The second result file is the OpenPKG Framework 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@428: echo "the OpenPKG Framework Binary Bootstrap Package if you want (usually" michael@428: echo "for fixing something) to reinstall (but then with RPM available)." michael@13: echo "" michael@428: echo "The third result file is the OpenPKG Framework Binary Bootstrap" michael@428: echo "Package, containing the installation files as a self-extracting" michael@428: echo "shell script for the OpenPKG instance $prefix. Use this in YOUR" michael@428: echo "NEXT 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: