diff -r 71503088f51b -r f880f219c566 openpkg/openpkg.boot --- a/openpkg/openpkg.boot Tue Jul 31 12:12:54 2012 +0200 +++ b/openpkg/openpkg.boot Tue Jul 31 12:23:42 2012 +0200 @@ -1,15 +1,14 @@ #!/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 +## Copyright (c) 2000-2012 OpenPKG GmbH ## -## 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 property of the OpenPKG GmbH, DE MUC HRB 160208. +## All rights reserved. Licenses which grant limited permission to use, +## copy, modify and distribute this software are available from the +## OpenPKG GmbH. ## -## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED +## 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 @@ -47,6 +46,8 @@ verbose='' prefix='' tag='' +stack='' +unprivileged=no usr=''; grp='' susr=''; sgrp='' musr=''; mgrp='' @@ -71,6 +72,8 @@ -v | --verbose ) verbose=v ;; --prefix=* ) prefix=$arg ;; --tag=* ) tag=$arg ;; + --stack=* ) stack=$arg ;; + --unprivileged ) unprivileged=yes ;; --usr=* | --user=* ) usr=$arg ;; --grp=* | --group=* ) grp=$arg ;; --susr=* ) susr=$arg ;; @@ -106,6 +109,7 @@ if [ ".$help" = .1 ]; then echo "Usage: sh $me" 2>&1 echo " [--prefix=] [--tag=]" 2>&1 + echo " [--stack=] [--unprivileged]" 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 @@ -115,8 +119,33 @@ exit 1 fi +# special support for environments with only a single +# fully unprivileged user account (the current user) +if [ ".$unprivileged" = .yes ]; then + # determine current user/group + 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` + cgid=`(id -g $cusr) 2>/dev/null ||\ + ((getent passwd "${cusr}"; grep "^${cusr}:" /etc/passwd; ypmatch "${cusr}" passwd; nismatch "${cusr}" passwd; nidump passwd . | grep "^${cusr}:") 2>/dev/null |\ + sed -n -e '1p' | awk -F: '{ print $4; }')` + cgrp=`(id -gn $cusr) 2>/dev/null ||\ + ((getent group; cat /etc/group; ypcat group; niscat group; nidump group .) 2>/dev/null | grep "^[^:]*:[^:]*:${cgid}:" |\ + sed -n -e '1p' | awk -F: '{ print $1; }')` + [ ".$cgrp" = . ] && cgrp="$cusr" + + # set all other user/group variants to current user/group + for who in s m r n; do + for what in usr grp; do + eval "${who}${what}=\"\$c${what}\"" + done + done +fi + # determine missing parameters -eval `sh aux.usrgrp.sh \ +eval `sh etc.usrgrp.sh \ --usr="$usr" --grp="$grp" \ --susr="$susr" --sgrp="$sgrp" \ --musr="$musr" --mgrp="$mgrp" \ @@ -141,8 +170,8 @@ name="openpkg" spec="$name.spec" -version=`grep V_openpkg $spec | sed -e 'q' | awk '{ printf("%s", $3); }'` -release="$version" +version=`grep '^Version:' $spec | sed -e 'q' | awk '{ printf("%s", $2); }'` +release=`grep '^Release:' $spec | sed -e 'q' | awk '{ printf("%s", $2); }'` ## ## display headline @@ -158,24 +187,18 @@ if [ ".$bs" = .1 ]; then srcdir=. - if [ -d ../../dst ]; then + if [ -d ../dst ]; then + dstdir=../dst + elif [ -d ../../dst/openpkg ]; 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 + if [ -d ../pkg ]; then + pkgdir=../pkg + elif [ -d ../../pkg/openpkg ]; then + pkgdir=../../pkg/openpkg else pkgdir=.. fi @@ -196,7 +219,7 @@ 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 \ + sed <$srcdir/etc.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;" @@ -218,8 +241,10 @@ ## 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 +if [ -d ../dst ]; then + distdir="`cd ../dst; pwd`" +elif [ -d ../../dst/openpkg ]; then + distdir="`cd ../../dst/openpkg; pwd`" else distdir="`pwd`" fi @@ -229,14 +254,18 @@ ## perform prerequisite checks ## -sh ./aux.prereq.sh source || exit $? +sh ./etc.prereq.sh source || exit $? ## ## find reasonable run-time paths and tools ## # find reasonable temporary directory -tmpdir="${TMPDIR-/tmp}" +if [ -d ../tmp ]; then + tmpdir="`cd ../tmp; pwd`" +else + tmpdir="${TMPDIR-/tmp}" +fi # find reasonable safe program path test ".$PATH" = . && PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin" @@ -264,7 +293,8 @@ echo "_builddir=$tmpdir" echo "l_prefix=$prefix" echo "l_tag_fmt=\"$tag\"" - echo "l_buildroot=$tmpdir/$name-$version-root" + echo "l_stack=$stack" + echo "l_buildroot=$tmpdir/$name-$version-$release-buildroot" echo "l_susr=$susr" echo "l_sgrp=$sgrp" echo "l_musr=$musr" @@ -281,6 +311,7 @@ echo "l_rgid=$rgid" echo "l_nuid=$nuid" echo "l_ngid=$ngid" + echo "l_unprivileged=$unprivileged" echo "use_tar=$use_tar" echo "use_make=$use_make" echo "use_cc=$use_cc" @@ -341,7 +372,7 @@ ## ## adjust build environment so that the installed -## "rpm" is actually useable, although it still resides in +## "rpm" is actually usable, although it still resides in ## the temporary location instead of the real location. ## @@ -354,6 +385,7 @@ . $tmpdir/openpkg-*/.buildenv # create a custom "rpm" command +# (and direct it to an adjusted macro set) echo "++ creating custom RPM command" rm -f $tmpdir/rpm >/dev/null 2>&1 rmdir $tmpdir/rpm >/dev/null 2>&1 @@ -367,22 +399,21 @@ 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 " --macros \"$tmpdir/rpm.1:$tmpdir/rpm.2:$tmpdir/rpm.3\" \\" + echo " --rpmpopt \"$tmpdir/rpm.4:$tmpdir/rpm.5\" \\" + echo " --rpmlua \"$tmpdir/rpm.6\" \\" 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 \ +rm -f $tmpdir/rpm.1 >/dev/null 2>&1 +sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmmacros >$tmpdir/rpm.1 \ -e "s;$prefix;$RPM_BUILD_ROOT$prefix;g" # override the vendor macro set -sed <`SOURCE rpmmacros` >$tmpdir/rpm.3 \ +rm -f $tmpdir/rpm.2 >/dev/null 2>&1 +sed <`SOURCE rpmmacros` >$tmpdir/rpm.2 \ -e "s;@SUSR@;$susr;" \ -e "s;@SGRP@;$sgrp;" \ -e "s;@MUSR@;$musr;" \ @@ -392,10 +423,11 @@ -e "s;@NUSR@;$nusr;" \ -e "s;@NGRP@;$ngrp;" \ -e "s;@TAG@;$tag;" \ + -e "s;@l_unprivileged@;$unprivileged;" \ -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\\1;g" \ -e "s;%{l_prefix};%{l_prefix_INTERNAL};g" \ -e "s;^\\(%_specdir *\\).*;\\1 `pwd`;" \ -e "s;^\\(%_sourcedir *\\).*;\\1 $distdir;" \ @@ -405,17 +437,33 @@ -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;" +# provide some special overrides +rm -f $tmpdir/rpm.3 >/dev/null 2>&1 +( echo "%l_prefix $prefix" + echo "%l_rpm $tmpdir/rpm" + echo "%__spec_install_pre %{nil}" + echo "%__spec_clean_body %{nil}" + echo "%__platform $RPM_BUILD_ROOT$prefix/etc/openpkg/platform" + echo "%_integrity_spec_cfg $RPM_BUILD_ROOT$prefix/etc/openpkg/license.d/BOOT" + echo "%_integrity_proc_lua $RPM_BUILD_ROOT$prefix/lib/openpkg/license.lua" + echo "%_integrity_pkey_pgp $RPM_BUILD_ROOT$prefix/etc/openpkg/openpkg.com.pgp" +) >$tmpdir/rpm.3 -# activate the .popt file -HOME=$tmpdir -export HOME +# use an adjusted vendor POPT config +rm -f $tmpdir/rpm.4 >/dev/null 2>&1 +sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmpopt >$tmpdir/rpm.4 \ + -e "s;$prefix;$RPM_BUILD_ROOT$prefix;g" + +# override the vendor POPT config +rm -f $tmpdir/rpm.5 >/dev/null 2>&1 +sed <$RPM_BUILD_ROOT$prefix/etc/openpkg/rpmpopt >$tmpdir/rpm.5 \ + -e "s;@l_prefix@;$RPM_BUILD_ROOT$prefix;g" + +# use an adjusted vendor RPM Lua script +rm -f $tmpdir/rpm.6 >/dev/null 2>&1 +sed <$RPM_BUILD_ROOT$prefix/etc/openpkg/rpmlua >$tmpdir/rpm.6 \ + -e "s;@l_prefix@;$RPM_BUILD_ROOT$prefix;g" ## ## now initialize the RPM database under the temporary install location @@ -450,7 +498,7 @@ ## echo "++ overwriting RPM installation by installing via RPM itself" -$tmpdir/rpm --install --justdb --force --noscripts --notriggers --ignoresize \ +$tmpdir/rpm --install --justdb --replacepkgs --replacefiles --oldpackage --noscripts --notriggers --ignoresize \ $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-*.rpm ## Puhhhh!!! what a tricky bootstrapping procedure. But now we are @@ -462,28 +510,24 @@ 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 +if [ -d ../pkg ]; then + pkgdir=../pkg +elif [ -d ../../pkg/openpkg ]; then + pkgdir=../../pkg/openpkg else - dstdir=.. + pkgdir=.. 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 +$tmpdir/rpm -bs --nodeps --define "_srcrpmdir $pkgdir" $spec # create Binary-RPM file +# (notice that there might be a discrepancy in the platform +# identification, so we have to copy the source via wildcard) 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 +cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-*.rpm $pkgdir/openpkg-$v.$t.rpm +rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-*.rpm # create Binary-Bootstrap file echo "++ creating bootstrap binary shell script" @@ -492,13 +536,15 @@ 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};"` +rm -f $RPM_BUILD_ROOT$prefix/RPM/DB/__db.[0-9]* 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 + --rpm=$tmpdir/rpm \ + --list --quiet` VERSION; do db_files="$db_files RPM/DB/$db_file" done chmod 644 $RPM_BUILD_ROOT$prefix/RPM/DB/* @@ -533,7 +579,7 @@ -e 's;%{![?]l_\([^:}]*\)};${\1-""};g' \ -e 's;%{l_\([^}]*\)};${\1};g' \ >$tmpdir/rpm.post -sed <`SOURCE aux.wrapbin.sh` \ +sed <`SOURCE etc.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;" \ @@ -546,6 +592,7 @@ -e "s;@l_platform@;$l_platform;" \ -e "s;@l_release@;$l_release;" \ -e "s;@l_version@;$l_version;" \ + -e "s;@l_unprivileged@;$unprivileged;" \ -e "/^@PRE@/r $tmpdir/rpm.pre" \ -e "/^@POST@/r $tmpdir/rpm.post" |\ sed -e '/^@PRE@/d' -e '/^@POST@/d' >$tmpdir/openpkg.boot.tmp @@ -554,30 +601,30 @@ printf(" "); } }' >>$tmpdir/openpkg.boot.tmp -rm -f $dstdir/openpkg-$v.$t.sh +rm -f $pkgdir/openpkg-$v.$t.sh dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=8 \ - of=$dstdir/openpkg-$v.$t.sh 2>/dev/null + of=$pkgdir/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 +) >>$pkgdir/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 $tmpdir/rpm $tmpdir/rpm.[123456] $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) +echo "++ resulting OpenPKG Framework bootstrap package files:" +(cd $pkgdir; 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 "You have successfully built the OpenPKG Framework from scratch" echo "for prefix $prefix on target platform $l_platform. The input" - echo "was the OpenPKG Source Bootstrap Package in file:" + echo "was the OpenPKG Framework Source Bootstrap Package in file:" echo "" echo " openpkg-$v.src.sh" echo "" @@ -587,23 +634,23 @@ 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 "The first result file is the OpenPKG Framework Source RPM Package," + echo "containing just the same contents than the OpenPKG Framework Source" + echo "Bootstrap Package, but now in RPM format. Optionally use this after" + echo "the installation of the OpenPKG Framework 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 "The second result file is the OpenPKG Framework 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 "the OpenPKG Framework Binary Bootstrap Package if you want (usually" + echo "for 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 "The third result file is the OpenPKG Framework Binary Bootstrap" + echo "Package, containing the installation files as a self-extracting" + echo "shell script for the OpenPKG instance $prefix. Use this in YOUR" + echo "NEXT 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 ||\