openpkg/openpkg.boot

changeset 13
cb59d6afeb61
child 428
f880f219c566
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/openpkg/openpkg.boot	Tue Jan 06 23:40:39 2009 +0100
     1.3 @@ -0,0 +1,621 @@
     1.4 +#!/bin/sh
     1.5 +##
     1.6 +##  openpkg.boot -- OpenPKG bootstrap procedure (look Ma, without hands ;)
     1.7 +##  Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
     1.8 +##  Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
     1.9 +##
    1.10 +##  Permission to use, copy, modify, and distribute this software for
    1.11 +##  any purpose with or without fee is hereby granted, provided that
    1.12 +##  the above copyright notice and this permission notice appear in all
    1.13 +##  copies.
    1.14 +##
    1.15 +##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    1.16 +##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    1.17 +##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    1.18 +##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
    1.19 +##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.20 +##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.21 +##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    1.22 +##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    1.23 +##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.24 +##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    1.25 +##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.26 +##  SUCH DAMAGE.
    1.27 +##
    1.28 +
    1.29 +#   This is a very tricky procedure for building the OpenPKG bootstrap
    1.30 +#   package via the RPM specification openpkg.spec, but without
    1.31 +#   requiring that OpenPKG's RPM already exists. For this the
    1.32 +#   openpkg.spec file is manually executed here in order to build
    1.33 +#   OpenPKG RPM the first time (that is, we emulate a sufficient
    1.34 +#   subset of the RPM functionality), followed by a second round over
    1.35 +#   openpkg.spec with the real (and then existing) OpenPKG RPM tool.
    1.36 +#   Also keep in mind that lots of tricks are played here in order to
    1.37 +#   perform all the steps without having to touch the real installation
    1.38 +#   location. That is the whole procedure can (and should) be performed
    1.39 +#   by a non-privileged user and no access to the real installation
    1.40 +#   location filesystem location.
    1.41 +
    1.42 +me="openpkg.boot"
    1.43 +
    1.44 +##
    1.45 +##  command line handling
    1.46 +##
    1.47 +
    1.48 +#   command line parameters (defaults)
    1.49 +help=0
    1.50 +verbose=''
    1.51 +prefix=''
    1.52 +tag=''
    1.53 +usr='';  grp=''
    1.54 +susr=''; sgrp=''
    1.55 +musr=''; mgrp=''
    1.56 +rusr=''; rgrp=''
    1.57 +nusr=''; ngrp=''
    1.58 +suid=''; sgid=''
    1.59 +muid=''; mgid=''
    1.60 +ruid=''; rgid=''
    1.61 +nuid=''; ngid=''
    1.62 +use_tar=''; use_make=''; use_cc=''; use_ar=''; use_ld=''; use_as=''; use_strip=''
    1.63 +bs=0
    1.64 +
    1.65 +#   parse command line options
    1.66 +for opt
    1.67 +do
    1.68 +    case $opt in
    1.69 +        -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
    1.70 +           *) arg='' ;;
    1.71 +    esac
    1.72 +    case $opt in
    1.73 +        -h | --help          ) help=1      ;;
    1.74 +        -v | --verbose       ) verbose=v   ;;
    1.75 +        --prefix=*           ) prefix=$arg ;;
    1.76 +        --tag=*              ) tag=$arg    ;;
    1.77 +        --usr=* | --user=*   ) usr=$arg    ;;
    1.78 +        --grp=* | --group=*  ) grp=$arg    ;;
    1.79 +        --susr=*             ) susr=$arg   ;;
    1.80 +        --sgrp=*             ) sgrp=$arg   ;;
    1.81 +        --musr=*             ) musr=$arg   ;;
    1.82 +        --mgrp=*             ) mgrp=$arg   ;;
    1.83 +        --rusr=*             ) rusr=$arg   ;;
    1.84 +        --rgrp=*             ) rgrp=$arg   ;;
    1.85 +        --nusr=*             ) nusr=$arg   ;;
    1.86 +        --ngrp=*             ) ngrp=$arg   ;;
    1.87 +        --suid=*             ) suid=$arg   ;;
    1.88 +        --sgid=*             ) sgid=$arg   ;;
    1.89 +        --muid=*             ) muid=$arg   ;;
    1.90 +        --mgid=*             ) mgid=$arg   ;;
    1.91 +        --ruid=*             ) ruid=$arg   ;;
    1.92 +        --rgid=*             ) rgid=$arg   ;;
    1.93 +        --nuid=*             ) nuid=$arg   ;;
    1.94 +        --ngid=*             ) ngid=$arg   ;;
    1.95 +        --use_tar=*          ) use_tar=$arg   ;;
    1.96 +        --use_make=*         ) use_make=$arg  ;;
    1.97 +        --use_cc=*           ) use_cc=$arg    ;;
    1.98 +        --use_ar=*           ) use_ar=$arg    ;;
    1.99 +        --use_ld=*           ) use_ld=$arg    ;;
   1.100 +        --use_as=*           ) use_as=$arg    ;;
   1.101 +        --use_strip=*        ) use_strip=$arg ;;
   1.102 +        -bs | -s             ) bs=1        ;;
   1.103 +        *                    ) help=1      ;;
   1.104 +    esac
   1.105 +done
   1.106 +if [ ".$bs" = .0 -a ".$prefix" = . ]; then
   1.107 +    help=1
   1.108 +fi
   1.109 +if [ ".$help" = .1 ]; then
   1.110 +    echo "Usage: sh $me" 2>&1
   1.111 +    echo "       [--prefix=<prefix>] [--tag=<str>]" 2>&1
   1.112 +    echo "       [--user=<usr>] [--group=<grp>]" 2>&1
   1.113 +    echo "       [--{s,m,r,n}usr=<usr>] [--{s,m,r,n}grp=<grp>]" 2>&1
   1.114 +    echo "       [--{s,m,r,n}uid=<uid>] [--{s,m,r,n}gid=<gid>]" 2>&1
   1.115 +    echo "       [--use_tar=<tar>] [--use_make=<make>] [--use_cc=<cc>]" 2>&1
   1.116 +    echo "       [--use_ar=<ar>] [--use_ld=<ld>] [--use_as=<as>] [--use_strip=<strip>]" 2>&1
   1.117 +    echo "       [-t|--tar] [-h|--help] [-v|--version]" 2>&1
   1.118 +    exit 1
   1.119 +fi
   1.120 +
   1.121 +#   determine missing parameters
   1.122 +eval `sh aux.usrgrp.sh \
   1.123 +      --usr="$usr" --grp="$grp" \
   1.124 +      --susr="$susr" --sgrp="$sgrp" \
   1.125 +      --musr="$musr" --mgrp="$mgrp" \
   1.126 +      --rusr="$rusr" --rgrp="$rgrp" \
   1.127 +      --nusr="$nusr" --ngrp="$ngrp" \
   1.128 +      --suid="$suid" --sgid="$sgid" \
   1.129 +      --muid="$muid" --mgid="$mgid" \
   1.130 +      --ruid="$ruid" --rgid="$rgid" \
   1.131 +      --nuid="$nuid" --ngid="$ngid"`
   1.132 +
   1.133 +#   canonicalize prefix
   1.134 +prefix=`echo "$prefix" | sed -e 's;//*;/;g' -e 's;/$;;'`
   1.135 +
   1.136 +#   provide default package tag
   1.137 +if [ ".$tag" = . ]; then
   1.138 +    tag="<loc>"
   1.139 +fi
   1.140 +
   1.141 +##
   1.142 +##  determine package information
   1.143 +##
   1.144 +
   1.145 +name="openpkg"
   1.146 +spec="$name.spec"
   1.147 +version=`grep V_openpkg $spec | sed -e 'q' | awk '{ printf("%s", $3); }'`
   1.148 +release="$version"
   1.149 +
   1.150 +##
   1.151 +##  display headline
   1.152 +##
   1.153 +
   1.154 +sh ./shtool echo -e "%BOpenPKG Bootstrap Procedure%b"
   1.155 +echo "++ bootstrap version: $version-$release"
   1.156 +echo "++ user/group pairs: $susr/$sgrp $musr/$mgrp $rusr/$rgrp $nusr/$ngrp"
   1.157 +
   1.158 +##
   1.159 +##   optionally roll just a bootstrap source package
   1.160 +##
   1.161 +
   1.162 +if [ ".$bs" = .1 ]; then
   1.163 +    srcdir=.
   1.164 +    if [ -d ../../dst ]; then
   1.165 +       dstdir=../../dst/openpkg
   1.166 +    else
   1.167 +       dstdir=.
   1.168 +    fi
   1.169 +    tmpdir="/tmp/$me.$$.d"
   1.170 +    if [ -d ../PKG/SRC ]; then
   1.171 +       pkgdir=../PKG/SRC
   1.172 +    elif [ -d ../PKG ]; then
   1.173 +       pkgdir=../PKG
   1.174 +    elif [ -d ../../PKG/SRC ]; then
   1.175 +       pkgdir=../../PKG/SRC
   1.176 +    elif [ -d ../../PKG ]; then
   1.177 +       pkgdir=../../PKG
   1.178 +    elif [ -d ../../pkg/src ]; then
   1.179 +       pkgdir=../../pkg/src
   1.180 +    elif [ -d ../../pkg ]; then
   1.181 +       pkgdir=../../pkg
   1.182 +    else
   1.183 +       pkgdir=..
   1.184 +    fi
   1.185 +    echo "** rolling source bootstrap package:"
   1.186 +    echo "   $pkgdir/$name-$version-$release.src.sh"
   1.187 +    rm -rf $tmpdir
   1.188 +    mkdir $tmpdir
   1.189 +    ( echo "dstdir=$dstdir"
   1.190 +      echo "srcdir=$srcdir"
   1.191 +      echo "tmpdir=$tmpdir"
   1.192 +      grep '^%define' $spec | sed -e 's:^%define *\([^ ]*\) *\(.*\):\1="\2":'
   1.193 +      grep '^Source' $spec  | sed -e 's;^Source[0-9]*: *;;' -e 's;^.*/;$dstdir/;' \
   1.194 +                                  -e 's;^\([^/]*\)$;$srcdir/\1;' -e 's;%;$;g' \
   1.195 +                                  -e 's;^\(.*\)$;cp \1 $tmpdir/;'
   1.196 +      echo "cp -p $spec $tmpdir/"
   1.197 +    ) >$tmpdir/.sh
   1.198 +    sh $tmpdir/.sh
   1.199 +    rm -f $tmpdir/.sh
   1.200 +    l_version="$release"
   1.201 +    l_release=`sh ./release.sh -r "${l_version}" -F "%t"`
   1.202 +    sed <$srcdir/aux.wrapsrc.sh >$tmpdir/openpkg.boot.tmp \
   1.203 +        -e "s;@l_dir@;$name-$version-$release.src;" \
   1.204 +        -e "s;@l_release@;$l_release;" \
   1.205 +        -e "s;@l_version@;$l_version;"
   1.206 +    echo . | awk '{
   1.207 +        for (i = 0; i < 8192; i++) {
   1.208 +            printf("        ");
   1.209 +        }
   1.210 +    }' >>$tmpdir/openpkg.boot.tmp
   1.211 +    dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=8 \
   1.212 +        of=$pkgdir/$name-$version-$release.src.sh 2>/dev/null
   1.213 +    rm -f $tmpdir/openpkg.boot.tmp
   1.214 +    (cd $tmpdir && tar cf - *) >>$pkgdir/$name-$version-$release.src.sh
   1.215 +    rm -rf $tmpdir
   1.216 +    exit 0
   1.217 +fi
   1.218 +
   1.219 +##
   1.220 +##  determine distribution directory
   1.221 +##
   1.222 +
   1.223 +V_rpm=`grep V_rpm $spec | sed -e 'q' | awk '{ printf("%s", $3); }'`
   1.224 +if [ -f "../../dst/openpkg/rpm-${V_rpm}.tar.gz" ]; then
   1.225 +    distdir="`cd ../../dst/openpkg; pwd`" # developer only
   1.226 +else
   1.227 +    distdir="`pwd`"
   1.228 +fi
   1.229 +echo "++ distribution directory: $distdir"
   1.230 +
   1.231 +##
   1.232 +##  perform prerequisite checks
   1.233 +##
   1.234 +
   1.235 +sh ./aux.prereq.sh source || exit $?
   1.236 +
   1.237 +##
   1.238 +##  find reasonable run-time paths and tools
   1.239 +##
   1.240 +
   1.241 +#   find reasonable temporary directory
   1.242 +tmpdir="${TMPDIR-/tmp}"
   1.243 +
   1.244 +#   find reasonable safe program path
   1.245 +test ".$PATH" = . && PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin"
   1.246 +for dir in /usr/ccs/bin /usr/xpg4/bin; do
   1.247 +    test -d $dir && PATH="$PATH:$dir"
   1.248 +done
   1.249 +export PATH
   1.250 +
   1.251 +#   make environment at least partly sane
   1.252 +umask 022
   1.253 +unset ls rm mv cp sed grep awk >/dev/null 2>&1 || true
   1.254 +
   1.255 +##
   1.256 +##  execute the spec file manually by emulating
   1.257 +##  the behaviour of the OpenPKG RPM tool.
   1.258 +##
   1.259 +
   1.260 +#   create script prolog
   1.261 +prolog="$tmpdir/openpkg.boot.prolog.sh"
   1.262 +cp /dev/null $prolog
   1.263 +(
   1.264 +  echo "_specdir=`pwd`"
   1.265 +  echo "_sourcedir=$distdir"
   1.266 +  echo "_tmppath=$tmpdir"
   1.267 +  echo "_builddir=$tmpdir"
   1.268 +  echo "l_prefix=$prefix"
   1.269 +  echo "l_tag_fmt=\"$tag\""
   1.270 +  echo "l_buildroot=$tmpdir/$name-$version-root"
   1.271 +  echo "l_susr=$susr"
   1.272 +  echo "l_sgrp=$sgrp"
   1.273 +  echo "l_musr=$musr"
   1.274 +  echo "l_mgrp=$mgrp"
   1.275 +  echo "l_rusr=$rusr"
   1.276 +  echo "l_rgrp=$rgrp"
   1.277 +  echo "l_nusr=$nusr"
   1.278 +  echo "l_ngrp=$ngrp"
   1.279 +  echo "l_suid=$suid"
   1.280 +  echo "l_sgid=$sgid"
   1.281 +  echo "l_muid=$muid"
   1.282 +  echo "l_mgid=$mgid"
   1.283 +  echo "l_ruid=$ruid"
   1.284 +  echo "l_rgid=$rgid"
   1.285 +  echo "l_nuid=$nuid"
   1.286 +  echo "l_ngid=$ngid"
   1.287 +  echo "use_tar=$use_tar"
   1.288 +  echo "use_make=$use_make"
   1.289 +  echo "use_cc=$use_cc"
   1.290 +  echo "use_ar=$use_ar"
   1.291 +  echo "use_ld=$use_ld"
   1.292 +  echo "use_as=$use_as"
   1.293 +  echo "use_strip=$use_strip"
   1.294 +  grep '%define' $spec | \
   1.295 +  sed \
   1.296 +    -e 's:^%define *\([^ ]*\) *\(.*\):\1="\2":'
   1.297 +  grep "^[A-Za-z0-9]*: *" $spec | \
   1.298 +  sed \
   1.299 +    -e 's;^\([A-Za-z0-9]*\): *\(.*\)$;\1="\2";' \
   1.300 +    -e 's;^A;a;' -e 's;^B;b;' -e 's;^C;c;' -e 's;^D;d;' -e 's;^E;e;' \
   1.301 +    -e 's;^F;f;' -e 's;^G;g;' -e 's;^H;h;' -e 's;^I;i;' -e 's;^J;j;' \
   1.302 +    -e 's;^K;k;' -e 's;^L;l;' -e 's;^M;m;' -e 's;^N;n;' -e 's;^O;o;' \
   1.303 +    -e 's;^P;p;' -e 's;^Q;q;' -e 's;^R;r;' -e 's;^S;s;' -e 's;^T;t;' \
   1.304 +    -e 's;^U;u;' -e 's;^V;v;' -e 's;^W;w;' -e 's;^X;x;' -e 's;^Y;y;' \
   1.305 +    -e 's;^Z;z;' -e 's;^buildRoot;buildroot;'
   1.306 +  echo "RPM_BUILD_ROOT=\"%{buildroot}\""
   1.307 +  echo "RPM_BUILD_DIR=\"%{_builddir}\""
   1.308 +  echo "RPM_SOURCE_DIR=\"$distdir\""
   1.309 +  echo "export RPM_BUILD_ROOT"
   1.310 +  echo "export RPM_BUILD_DIR"
   1.311 +  echo "export RPM_SOURCE_DIR"
   1.312 +  echo "set -x"
   1.313 +  echo "umask 022"
   1.314 +  echo "cd \$RPM_BUILD_DIR"
   1.315 +) | sed -e 's;%{\([^}]*\)};${\1};g' >$prolog
   1.316 +
   1.317 +#   install package via RPM spec file by faking a
   1.318 +#   sufficiently enough RPM run-time environment
   1.319 +runscript () {
   1.320 +    step=$1
   1.321 +    script="$tmpdir/openpkg.boot.$step.sh"
   1.322 +    echo ". $prolog" >$script
   1.323 +    sed -e "/^%$step/,/^%/ p" -e 'd' <$spec | \
   1.324 +    sed -e '/^%/d' | \
   1.325 +    sed -e 's;%{SOURCE \([^ ]*\.tar[^ ]*\)};${RPM_DIST_DIR}/\1;g' \
   1.326 +        -e 's;%{SOURCE \([^ ]*\)};${RPM_SOURCE_DIR}/\1;g' | \
   1.327 +    sed -e 's;%{[?]\([^:}]*\):\([^}]*\)};${\1+\2};g' \
   1.328 +        -e 's;%{![?]\([^:}]*\):\([^}]*\)};${\1-\2};g' \
   1.329 +        -e 's;%{[?]\([^:}]*\)};${\1+""};g' \
   1.330 +        -e 's;%{![?]\([^:}]*\)};${\1-""};g' \
   1.331 +        -e 's;%{\([^}]*\)};${\1};g' >>$script
   1.332 +    echo "++ executing(%$step): sh $script"
   1.333 +    sh $script
   1.334 +    if [ $? -ne 0 ]; then
   1.335 +        rm -f $script
   1.336 +        echo "$0:ERROR: script returned non-null value"
   1.337 +        exit 1
   1.338 +    fi
   1.339 +    rm -f $script
   1.340 +}
   1.341 +runscript prep
   1.342 +runscript build
   1.343 +runscript install
   1.344 +
   1.345 +##
   1.346 +##  adjust build environment so that the installed
   1.347 +##  "rpm" is actually useable, although it still resides in
   1.348 +##  the temporary location instead of the real location.
   1.349 +##
   1.350 +
   1.351 +#   suck in prolog in order to get variables from the spec file
   1.352 +cwd=`pwd`
   1.353 +. $prolog
   1.354 +cd $cwd
   1.355 +
   1.356 +#   suck in buildenv script in order to get musr/mgrp
   1.357 +. $tmpdir/openpkg-*/.buildenv
   1.358 +
   1.359 +#   create a custom "rpm" command
   1.360 +echo "++ creating custom RPM command"
   1.361 +rm -f $tmpdir/rpm >/dev/null 2>&1
   1.362 +rmdir $tmpdir/rpm >/dev/null 2>&1
   1.363 +if [ -d "$tmpdir/rpm" ]; then
   1.364 +    echo "$0:ERROR: directory $tmpdir/rpm exists, cannot create file with same name"
   1.365 +    exit 1
   1.366 +fi
   1.367 +if [ -f "$tmpdir/rpm" ]; then
   1.368 +    echo "$0:ERROR: file $tmpdir/rpm exists, cannot override"
   1.369 +    exit 1
   1.370 +fi
   1.371 +( echo "#!/bin/sh"
   1.372 +  echo "exec $RPM_BUILD_ROOT$prefix/lib/openpkg/rpm \\"
   1.373 +  echo "    --rcfile \"$tmpdir/rpm.1\" \\"
   1.374 +  echo "    --define \"__platform $RPM_BUILD_ROOT$prefix/etc/openpkg/platform\" \\"
   1.375 +  echo "    \"\$@\""
   1.376 +) >$tmpdir/rpm
   1.377 +chmod a+x $tmpdir/rpm
   1.378 +
   1.379 +#   direct our own "rpm" tool to adjusted macro sets
   1.380 +sed <`SOURCE rpmrc` >$tmpdir/rpm.1 \
   1.381 +    -e "s;^\\(macrofiles:\\) .*;\\1 $tmpdir/rpm.2:$tmpdir/rpm.3;"
   1.382 +
   1.383 +#   use an adjusted vendor macro set
   1.384 +sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/macros >$tmpdir/rpm.2 \
   1.385 +    -e "s;$prefix;$RPM_BUILD_ROOT$prefix;g"
   1.386 +
   1.387 +#   override the vendor macro set
   1.388 +sed <`SOURCE rpmmacros` >$tmpdir/rpm.3 \
   1.389 +    -e "s;@SUSR@;$susr;" \
   1.390 +    -e "s;@SGRP@;$sgrp;" \
   1.391 +    -e "s;@MUSR@;$musr;" \
   1.392 +    -e "s;@MGRP@;$mgrp;" \
   1.393 +    -e "s;@RUSR@;$rusr;" \
   1.394 +    -e "s;@RGRP@;$rgrp;" \
   1.395 +    -e "s;@NUSR@;$nusr;" \
   1.396 +    -e "s;@NGRP@;$ngrp;" \
   1.397 +    -e "s;@TAG@;$tag;" \
   1.398 +    -e "s;\\(%{l_prefix}/lib/openpkg/rpmtool\\);%{l_bash} \\1;g" \
   1.399 +    -e "s;@l_prefix_static@;$prefix;g" \
   1.400 +    -e "s;@l_prefix@;$RPM_BUILD_ROOT$prefix;g" \
   1.401 +    -e "s;%l_prefix\\([^_]\\);%l_prefix_INTERNAL\\1;g" \
   1.402 +    -e "s;%{l_prefix};%{l_prefix_INTERNAL};g" \
   1.403 +    -e "s;^\\(%_specdir *\\).*;\\1 `pwd`;" \
   1.404 +    -e "s;^\\(%_sourcedir *\\).*;\\1 $distdir;" \
   1.405 +    -e "s;^\\(%_builddir *\\).*;\\1 $tmpdir;" \
   1.406 +    -e "s;^\\(%_tmppath *\\).*;\\1 $tmpdir;" \
   1.407 +    -e "s;^\\(%_buildshell *\\).*;\\1 env -i OPENPKG_BOOT=1 %{l_build_shell_cmd} %{l_build_shell_opt};" \
   1.408 +    -e "s;@l_build_path@;/bin:/sbin:/usr/bin:/usr/sbin;g" \
   1.409 +    -e "s;@l_build_ldlp@;/usr/lib;g" \
   1.410 +    -e "s;@l_build_ulim@;:;g"
   1.411 +echo "%l_prefix $prefix" >>$tmpdir/rpm.3
   1.412 +
   1.413 +#   use an own $HOME/.popt in order to make sure the "rpm"
   1.414 +#   tool is able to execute its sub-tools "rpm<x>".
   1.415 +V_rpm=`grep V_rpm $spec | sed -e 'q' | awk '{ printf("%s", $3); }'`
   1.416 +sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmpopt >$tmpdir/.popt \
   1.417 +    -e "s;^\\(rpm.*exec.*\\)\\(rpm[bdieukvq]*\\);\\1$RPM_BUILD_ROOT$prefix/lib/openpkg/\\2;"
   1.418 +
   1.419 +#   activate the .popt file
   1.420 +HOME=$tmpdir
   1.421 +export HOME
   1.422 +
   1.423 +##
   1.424 +##   now initialize the RPM database under the temporary install location
   1.425 +##
   1.426 +
   1.427 +echo "++ initializing RPM database"
   1.428 +$RPM_BUILD_ROOT$prefix/lib/openpkg/bash \
   1.429 +$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmdb \
   1.430 +    --prefix=$RPM_BUILD_ROOT$prefix \
   1.431 +    --dbpath=$RPM_BUILD_ROOT$prefix/RPM/DB \
   1.432 +    --rpm=$tmpdir/rpm \
   1.433 +    --build --quiet
   1.434 +
   1.435 +##
   1.436 +##   now turn over and re-iterate over the RPM spec, but this time
   1.437 +##   with the real RPM tool.
   1.438 +##
   1.439 +
   1.440 +echo "++ re-iterating over RPM specification procedures"
   1.441 +$tmpdir/rpm -bb $spec
   1.442 +
   1.443 +##
   1.444 +##   and finally overwrite the installation again, but this time by
   1.445 +##   installing officially through the "rpm" tool. This way we achieve
   1.446 +##   that RPM is remembered as an RPM package in its own database. We
   1.447 +##   just have to make sure the package is relocated while installing.
   1.448 +##   For this we could use --prefix=$RPM_BUILD_ROOT$prefix, but this
   1.449 +##   would create an incorrect filelist for "rpm" in the database.
   1.450 +##   Instead we use the --justdb option which means "rpm" behaves as it
   1.451 +##   would install into the real location, but does not actually install
   1.452 +##   anything. But as a side-effect, the database is now correct.
   1.453 +##
   1.454 +
   1.455 +echo "++ overwriting RPM installation by installing via RPM itself"
   1.456 +$tmpdir/rpm --install --justdb --force --noscripts --notriggers --ignoresize \
   1.457 +    $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-*.rpm
   1.458 +
   1.459 +##  Puhhhh!!! what a tricky bootstrapping procedure. But now we are
   1.460 +##  mostly finished. All we finally have to do is to roll a bootstrap
   1.461 +##  tarball in addition to the binary RPM and save the stuff in a
   1.462 +##  permanent location.
   1.463 +
   1.464 +v="$version-$release"
   1.465 +t="`$tmpdir/rpm --eval '%{l_platform -p}-%{l_tag}'`"
   1.466 +
   1.467 +#   find a reasonable destination directory for packages
   1.468 +if [ -d ../PKG/BIN ]; then
   1.469 +   dstdir=../PKG/BIN
   1.470 +elif [ -d ../PKG ]; then
   1.471 +   dstdir=../PKG
   1.472 +elif [ -d ../../PKG/BIN ]; then
   1.473 +   dstdir=../../PKG/BIN
   1.474 +elif [ -d ../../PKG ]; then
   1.475 +   dstdir=../../PKG
   1.476 +else
   1.477 +   dstdir=..
   1.478 +fi
   1.479 +
   1.480 +#   create Source-RPM file
   1.481 +echo "++ creating bootstrap source RPM file"
   1.482 +$tmpdir/rpm -bs --nodeps $spec
   1.483 +cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.src.rpm $dstdir/
   1.484 +rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.src.rpm
   1.485 +
   1.486 +#   create Binary-RPM file
   1.487 +echo "++ creating bootstrap binary RPM file"
   1.488 +cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.$t.rpm $dstdir/
   1.489 +rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.$t.rpm
   1.490 +
   1.491 +#   create Binary-Bootstrap file
   1.492 +echo "++ creating bootstrap binary shell script"
   1.493 +files=`cat $spec |\
   1.494 +       sed -e '1,/%files/d' -e '/%clean/,$d' |\
   1.495 +       grep -v '^ *$' | grep -v '%defattr' |\
   1.496 +       sed -e 's;%config(noreplace) *;;' -e 's;%config *;;' -e 's;%ghost *;;' -e 's;%attr([^)]*) *;;' \
   1.497 +           -e 's;%dir *;;' -e 's;%{l_prefix}/;;' -e 's;^ *;;' -e "s;%{V_rpm};${V_rpm};"`
   1.498 +db_files=""
   1.499 +for db_file in \
   1.500 +    `$RPM_BUILD_ROOT$prefix/lib/openpkg/bash \
   1.501 +     $RPM_BUILD_ROOT$prefix/lib/openpkg/rpmdb \
   1.502 +         --prefix=$RPM_BUILD_ROOT$prefix \
   1.503 +         --dbpath=$RPM_BUILD_ROOT$prefix/RPM/DB \
   1.504 +         --list --quiet`; do
   1.505 +    db_files="$db_files RPM/DB/$db_file"
   1.506 +done
   1.507 +chmod 644 $RPM_BUILD_ROOT$prefix/RPM/DB/*
   1.508 +files="$files $db_files"
   1.509 +( cd $RPM_BUILD_ROOT$prefix
   1.510 +  $RPM_BUILD_ROOT$prefix/lib/openpkg/tar --no-recursion -cf - $files
   1.511 +) | $RPM_BUILD_ROOT$prefix/lib/openpkg/bzip2 -9 \
   1.512 +    >$RPM_BUILD_ROOT$prefix/openpkg.tar.bz2
   1.513 +cp -p $RPM_BUILD_ROOT$prefix/lib/openpkg/tar \
   1.514 +    $RPM_BUILD_ROOT$prefix/openpkg.tar
   1.515 +cp -p $RPM_BUILD_ROOT$prefix/lib/openpkg/bzip2 \
   1.516 +    $RPM_BUILD_ROOT$prefix/openpkg.bzip2
   1.517 +l_platform=`$tmpdir/rpm --eval '%{l_platform -p}'`
   1.518 +l_version=`$tmpdir/rpm -q --qf '%{version}' openpkg`
   1.519 +release_sh=`SOURCE release.sh`
   1.520 +l_release=`sh $release_sh -r "$l_version" -F "%t"`
   1.521 +cat $spec |\
   1.522 +    sed -e "/^%pre$/,/^%/ p" -e 'd' |\
   1.523 +    sed -e '/^%/d' -e 's/^ 	//' |\
   1.524 +    sed -e 's;%{[?]l_\([^:}]*\):\([^}]*\)};${\1+\2};g' \
   1.525 +        -e 's;%{![?]l_\([^:}]*\):\([^}]*\)};${\1-\2};g' \
   1.526 +        -e 's;%{[?]l_\([^:}]*\)};${\1+""};g' \
   1.527 +        -e 's;%{![?]l_\([^:}]*\)};${\1-""};g' \
   1.528 +        -e 's;%{l_\([^}]*\)};${\1};g' \
   1.529 +    >$tmpdir/rpm.pre
   1.530 +cat $spec |\
   1.531 +    sed -e "/^%post$/,/^%/ p" -e 'd' |\
   1.532 +    sed -e '/^%/d' -e 's/^ 	//' |\
   1.533 +    sed -e 's;%{[?]l_\([^:}]*\):\([^}]*\)};${\1+\2};g' \
   1.534 +        -e 's;%{![?]l_\([^:}]*\):\([^}]*\)};${\1-\2};g' \
   1.535 +        -e 's;%{[?]l_\([^:}]*\)};${\1+""};g' \
   1.536 +        -e 's;%{![?]l_\([^:}]*\)};${\1-""};g' \
   1.537 +        -e 's;%{l_\([^}]*\)};${\1};g' \
   1.538 +    >$tmpdir/rpm.post
   1.539 +sed <`SOURCE aux.wrapbin.sh` \
   1.540 +    -e "s;@SUSR@;$susr;" -e "s;@SGRP@;$sgrp;" \
   1.541 +    -e "s;@MUSR@;$musr;" -e "s;@MGRP@;$mgrp;" \
   1.542 +    -e "s;@RUSR@;$rusr;" -e "s;@RGRP@;$rgrp;" \
   1.543 +    -e "s;@NUSR@;$nusr;" -e "s;@NGRP@;$ngrp;" \
   1.544 +    -e "s;@SUID@;$suid;" -e "s;@SGID@;$sgid;" \
   1.545 +    -e "s;@MUID@;$muid;" -e "s;@MGID@;$mgid;" \
   1.546 +    -e "s;@RUID@;$ruid;" -e "s;@RGID@;$rgid;" \
   1.547 +    -e "s;@NUID@;$nuid;" -e "s;@NGID@;$ngid;" \
   1.548 +    -e "s;@l_prefix@;$prefix;" \
   1.549 +    -e "s;@l_platform@;$l_platform;" \
   1.550 +    -e "s;@l_release@;$l_release;" \
   1.551 +    -e "s;@l_version@;$l_version;" \
   1.552 +    -e "/^@PRE@/r $tmpdir/rpm.pre" \
   1.553 +    -e "/^@POST@/r $tmpdir/rpm.post" |\
   1.554 +    sed -e '/^@PRE@/d' -e '/^@POST@/d' >$tmpdir/openpkg.boot.tmp
   1.555 +echo . | awk '{
   1.556 +    for (i = 0; i < 8192; i++) {
   1.557 +        printf("        ");
   1.558 +    }
   1.559 +}' >>$tmpdir/openpkg.boot.tmp
   1.560 +rm -f $dstdir/openpkg-$v.$t.sh
   1.561 +dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=8 \
   1.562 +   of=$dstdir/openpkg-$v.$t.sh 2>/dev/null
   1.563 +rm -f $tmpdir/openpkg.boot.tmp
   1.564 +( cd $RPM_BUILD_ROOT$prefix
   1.565 +  $RPM_BUILD_ROOT$prefix/lib/openpkg/tar --no-recursion -cf - \
   1.566 +      openpkg.tar openpkg.bzip2 openpkg.tar.bz2
   1.567 +) >>$dstdir/openpkg-$v.$t.sh
   1.568 +
   1.569 +#   cleanup
   1.570 +echo "++ cleaning up"
   1.571 +cp `SOURCE rpmtool` $tmpdir/rpmtool
   1.572 +rm -rf $RPM_BUILD_ROOT
   1.573 +rm -rf $tmpdir/$name-$version
   1.574 +rm -f $tmpdir/rpm $tmpdir/rpm.[123] $tmpdir/.popt $tmpdir/rpm.pre $tmpdir/rpm.post
   1.575 +rm -f $prolog
   1.576 +
   1.577 +#   final hint about results
   1.578 +echo "++ resulting OpenPKG bootstrap package files:"
   1.579 +(cd $dstdir; ls -l openpkg-$v.$t.sh openpkg-$v.$t.rpm openpkg-$v.src.rpm)
   1.580 +set +x
   1.581 +( echo "You have successfully built the OpenPKG Package from scratch"
   1.582 +  echo "for prefix $prefix on target platform $l_platform. The input"
   1.583 +  echo "was the OpenPKG Source Bootstrap Package in file:"
   1.584 +  echo ""
   1.585 +  echo "    openpkg-$v.src.sh"
   1.586 +  echo ""
   1.587 +  echo "The results are the following three files:"
   1.588 +  echo ""
   1.589 +  echo "    openpkg-$v.src.rpm"
   1.590 +  echo "    openpkg-$v.$t.rpm"
   1.591 +  echo "    openpkg-$v.$t.sh"
   1.592 +  echo ""
   1.593 +  echo "The first result file is the OpenPKG Source RPM Package,"
   1.594 +  echo "containing just the same contents than the OpenPKG Source"
   1.595 +  echo "Bootstrap Package, but now in RPM format. Optionally use this"
   1.596 +  echo "after the installation of the OpenPKG Binary Bootstrap Package"
   1.597 +  echo "if you want to rebuild from source again (but then with RPM"
   1.598 +  echo "available)."
   1.599 +  echo ""
   1.600 +  echo "The second result file is the OpenPKG Binary RPM Package,"
   1.601 +  echo "containing the installation files in RPM format for the OpenPKG"
   1.602 +  echo "instance $prefix. Optionally use this after the installation of"
   1.603 +  echo "the OpenPKG Binary Bootstrap Package if you want (usually for"
   1.604 +  echo "fixing something) to reinstall (but then with RPM available)."
   1.605 +  echo ""
   1.606 +  echo "The third result file is the OpenPKG Binary Bootstrap Package,"
   1.607 +  echo "containing the installation files as a self-extracting shell"
   1.608 +  echo "script for the OpenPKG instance $prefix. Use this in YOUR NEXT"
   1.609 +  echo "STEP to initially create the OpenPKG instance from scratch."
   1.610 +  echo "Hence, proceed now by running the following command:"
   1.611 +  echo ""
   1.612 +  cusr=`(id -un) 2>/dev/null ||\
   1.613 +        (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
   1.614 +        (whoami) 2>/dev/null ||\
   1.615 +        (who am i | cut "-d " -f1) 2>/dev/null ||\
   1.616 +        echo $LOGNAME`
   1.617 +  if [ ".$musr.$rusr.$nusr" = ".$cusr.$cusr.$cusr" -o ".$cusr" = ".root" ]; then
   1.618 +      echo "    \$ sh openpkg-$v.$t.sh"
   1.619 +  else
   1.620 +      echo "    \$ su root -c \"sh openpkg-$v.$t.sh\""
   1.621 +  fi
   1.622 +) | sh $tmpdir/rpmtool msg -b -t info
   1.623 +rm -f $tmpdir/rpmtool
   1.624 +

mercurial