Wed, 25 Feb 2009 19:23:10 +0100
Import new package specs for introduction into repository.
The purpose of these packages are for flash video manipulation,
something seemingly missing from the current mtasc, haxe, sswf,
swftools, and adobeflex packages.
michael@13 | 1 | #!/bin/sh |
michael@13 | 2 | ## |
michael@13 | 3 | ## openpkg.boot -- OpenPKG bootstrap procedure (look Ma, without hands ;) |
michael@13 | 4 | ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/> |
michael@13 | 5 | ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/> |
michael@13 | 6 | ## |
michael@13 | 7 | ## Permission to use, copy, modify, and distribute this software for |
michael@13 | 8 | ## any purpose with or without fee is hereby granted, provided that |
michael@13 | 9 | ## the above copyright notice and this permission notice appear in all |
michael@13 | 10 | ## copies. |
michael@13 | 11 | ## |
michael@13 | 12 | ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
michael@13 | 13 | ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
michael@13 | 14 | ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
michael@13 | 15 | ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR |
michael@13 | 16 | ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@13 | 17 | ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@13 | 18 | ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
michael@13 | 19 | ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
michael@13 | 20 | ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
michael@13 | 21 | ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
michael@13 | 22 | ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
michael@13 | 23 | ## SUCH DAMAGE. |
michael@13 | 24 | ## |
michael@13 | 25 | |
michael@13 | 26 | # This is a very tricky procedure for building the OpenPKG bootstrap |
michael@13 | 27 | # package via the RPM specification openpkg.spec, but without |
michael@13 | 28 | # requiring that OpenPKG's RPM already exists. For this the |
michael@13 | 29 | # openpkg.spec file is manually executed here in order to build |
michael@13 | 30 | # OpenPKG RPM the first time (that is, we emulate a sufficient |
michael@13 | 31 | # subset of the RPM functionality), followed by a second round over |
michael@13 | 32 | # openpkg.spec with the real (and then existing) OpenPKG RPM tool. |
michael@13 | 33 | # Also keep in mind that lots of tricks are played here in order to |
michael@13 | 34 | # perform all the steps without having to touch the real installation |
michael@13 | 35 | # location. That is the whole procedure can (and should) be performed |
michael@13 | 36 | # by a non-privileged user and no access to the real installation |
michael@13 | 37 | # location filesystem location. |
michael@13 | 38 | |
michael@13 | 39 | me="openpkg.boot" |
michael@13 | 40 | |
michael@13 | 41 | ## |
michael@13 | 42 | ## command line handling |
michael@13 | 43 | ## |
michael@13 | 44 | |
michael@13 | 45 | # command line parameters (defaults) |
michael@13 | 46 | help=0 |
michael@13 | 47 | verbose='' |
michael@13 | 48 | prefix='' |
michael@13 | 49 | tag='' |
michael@13 | 50 | usr=''; grp='' |
michael@13 | 51 | susr=''; sgrp='' |
michael@13 | 52 | musr=''; mgrp='' |
michael@13 | 53 | rusr=''; rgrp='' |
michael@13 | 54 | nusr=''; ngrp='' |
michael@13 | 55 | suid=''; sgid='' |
michael@13 | 56 | muid=''; mgid='' |
michael@13 | 57 | ruid=''; rgid='' |
michael@13 | 58 | nuid=''; ngid='' |
michael@13 | 59 | use_tar=''; use_make=''; use_cc=''; use_ar=''; use_ld=''; use_as=''; use_strip='' |
michael@13 | 60 | bs=0 |
michael@13 | 61 | |
michael@13 | 62 | # parse command line options |
michael@13 | 63 | for opt |
michael@13 | 64 | do |
michael@13 | 65 | case $opt in |
michael@13 | 66 | -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;; |
michael@13 | 67 | *) arg='' ;; |
michael@13 | 68 | esac |
michael@13 | 69 | case $opt in |
michael@13 | 70 | -h | --help ) help=1 ;; |
michael@13 | 71 | -v | --verbose ) verbose=v ;; |
michael@13 | 72 | --prefix=* ) prefix=$arg ;; |
michael@13 | 73 | --tag=* ) tag=$arg ;; |
michael@13 | 74 | --usr=* | --user=* ) usr=$arg ;; |
michael@13 | 75 | --grp=* | --group=* ) grp=$arg ;; |
michael@13 | 76 | --susr=* ) susr=$arg ;; |
michael@13 | 77 | --sgrp=* ) sgrp=$arg ;; |
michael@13 | 78 | --musr=* ) musr=$arg ;; |
michael@13 | 79 | --mgrp=* ) mgrp=$arg ;; |
michael@13 | 80 | --rusr=* ) rusr=$arg ;; |
michael@13 | 81 | --rgrp=* ) rgrp=$arg ;; |
michael@13 | 82 | --nusr=* ) nusr=$arg ;; |
michael@13 | 83 | --ngrp=* ) ngrp=$arg ;; |
michael@13 | 84 | --suid=* ) suid=$arg ;; |
michael@13 | 85 | --sgid=* ) sgid=$arg ;; |
michael@13 | 86 | --muid=* ) muid=$arg ;; |
michael@13 | 87 | --mgid=* ) mgid=$arg ;; |
michael@13 | 88 | --ruid=* ) ruid=$arg ;; |
michael@13 | 89 | --rgid=* ) rgid=$arg ;; |
michael@13 | 90 | --nuid=* ) nuid=$arg ;; |
michael@13 | 91 | --ngid=* ) ngid=$arg ;; |
michael@13 | 92 | --use_tar=* ) use_tar=$arg ;; |
michael@13 | 93 | --use_make=* ) use_make=$arg ;; |
michael@13 | 94 | --use_cc=* ) use_cc=$arg ;; |
michael@13 | 95 | --use_ar=* ) use_ar=$arg ;; |
michael@13 | 96 | --use_ld=* ) use_ld=$arg ;; |
michael@13 | 97 | --use_as=* ) use_as=$arg ;; |
michael@13 | 98 | --use_strip=* ) use_strip=$arg ;; |
michael@13 | 99 | -bs | -s ) bs=1 ;; |
michael@13 | 100 | * ) help=1 ;; |
michael@13 | 101 | esac |
michael@13 | 102 | done |
michael@13 | 103 | if [ ".$bs" = .0 -a ".$prefix" = . ]; then |
michael@13 | 104 | help=1 |
michael@13 | 105 | fi |
michael@13 | 106 | if [ ".$help" = .1 ]; then |
michael@13 | 107 | echo "Usage: sh $me" 2>&1 |
michael@13 | 108 | echo " [--prefix=<prefix>] [--tag=<str>]" 2>&1 |
michael@13 | 109 | echo " [--user=<usr>] [--group=<grp>]" 2>&1 |
michael@13 | 110 | echo " [--{s,m,r,n}usr=<usr>] [--{s,m,r,n}grp=<grp>]" 2>&1 |
michael@13 | 111 | echo " [--{s,m,r,n}uid=<uid>] [--{s,m,r,n}gid=<gid>]" 2>&1 |
michael@13 | 112 | echo " [--use_tar=<tar>] [--use_make=<make>] [--use_cc=<cc>]" 2>&1 |
michael@13 | 113 | echo " [--use_ar=<ar>] [--use_ld=<ld>] [--use_as=<as>] [--use_strip=<strip>]" 2>&1 |
michael@13 | 114 | echo " [-t|--tar] [-h|--help] [-v|--version]" 2>&1 |
michael@13 | 115 | exit 1 |
michael@13 | 116 | fi |
michael@13 | 117 | |
michael@13 | 118 | # determine missing parameters |
michael@13 | 119 | eval `sh aux.usrgrp.sh \ |
michael@13 | 120 | --usr="$usr" --grp="$grp" \ |
michael@13 | 121 | --susr="$susr" --sgrp="$sgrp" \ |
michael@13 | 122 | --musr="$musr" --mgrp="$mgrp" \ |
michael@13 | 123 | --rusr="$rusr" --rgrp="$rgrp" \ |
michael@13 | 124 | --nusr="$nusr" --ngrp="$ngrp" \ |
michael@13 | 125 | --suid="$suid" --sgid="$sgid" \ |
michael@13 | 126 | --muid="$muid" --mgid="$mgid" \ |
michael@13 | 127 | --ruid="$ruid" --rgid="$rgid" \ |
michael@13 | 128 | --nuid="$nuid" --ngid="$ngid"` |
michael@13 | 129 | |
michael@13 | 130 | # canonicalize prefix |
michael@13 | 131 | prefix=`echo "$prefix" | sed -e 's;//*;/;g' -e 's;/$;;'` |
michael@13 | 132 | |
michael@13 | 133 | # provide default package tag |
michael@13 | 134 | if [ ".$tag" = . ]; then |
michael@13 | 135 | tag="<loc>" |
michael@13 | 136 | fi |
michael@13 | 137 | |
michael@13 | 138 | ## |
michael@13 | 139 | ## determine package information |
michael@13 | 140 | ## |
michael@13 | 141 | |
michael@13 | 142 | name="openpkg" |
michael@13 | 143 | spec="$name.spec" |
michael@13 | 144 | version=`grep V_openpkg $spec | sed -e 'q' | awk '{ printf("%s", $3); }'` |
michael@13 | 145 | release="$version" |
michael@13 | 146 | |
michael@13 | 147 | ## |
michael@13 | 148 | ## display headline |
michael@13 | 149 | ## |
michael@13 | 150 | |
michael@13 | 151 | sh ./shtool echo -e "%BOpenPKG Bootstrap Procedure%b" |
michael@13 | 152 | echo "++ bootstrap version: $version-$release" |
michael@13 | 153 | echo "++ user/group pairs: $susr/$sgrp $musr/$mgrp $rusr/$rgrp $nusr/$ngrp" |
michael@13 | 154 | |
michael@13 | 155 | ## |
michael@13 | 156 | ## optionally roll just a bootstrap source package |
michael@13 | 157 | ## |
michael@13 | 158 | |
michael@13 | 159 | if [ ".$bs" = .1 ]; then |
michael@13 | 160 | srcdir=. |
michael@13 | 161 | if [ -d ../../dst ]; then |
michael@13 | 162 | dstdir=../../dst/openpkg |
michael@13 | 163 | else |
michael@13 | 164 | dstdir=. |
michael@13 | 165 | fi |
michael@13 | 166 | tmpdir="/tmp/$me.$$.d" |
michael@13 | 167 | if [ -d ../PKG/SRC ]; then |
michael@13 | 168 | pkgdir=../PKG/SRC |
michael@13 | 169 | elif [ -d ../PKG ]; then |
michael@13 | 170 | pkgdir=../PKG |
michael@13 | 171 | elif [ -d ../../PKG/SRC ]; then |
michael@13 | 172 | pkgdir=../../PKG/SRC |
michael@13 | 173 | elif [ -d ../../PKG ]; then |
michael@13 | 174 | pkgdir=../../PKG |
michael@13 | 175 | elif [ -d ../../pkg/src ]; then |
michael@13 | 176 | pkgdir=../../pkg/src |
michael@13 | 177 | elif [ -d ../../pkg ]; then |
michael@13 | 178 | pkgdir=../../pkg |
michael@13 | 179 | else |
michael@13 | 180 | pkgdir=.. |
michael@13 | 181 | fi |
michael@13 | 182 | echo "** rolling source bootstrap package:" |
michael@13 | 183 | echo " $pkgdir/$name-$version-$release.src.sh" |
michael@13 | 184 | rm -rf $tmpdir |
michael@13 | 185 | mkdir $tmpdir |
michael@13 | 186 | ( echo "dstdir=$dstdir" |
michael@13 | 187 | echo "srcdir=$srcdir" |
michael@13 | 188 | echo "tmpdir=$tmpdir" |
michael@13 | 189 | grep '^%define' $spec | sed -e 's:^%define *\([^ ]*\) *\(.*\):\1="\2":' |
michael@13 | 190 | grep '^Source' $spec | sed -e 's;^Source[0-9]*: *;;' -e 's;^.*/;$dstdir/;' \ |
michael@13 | 191 | -e 's;^\([^/]*\)$;$srcdir/\1;' -e 's;%;$;g' \ |
michael@13 | 192 | -e 's;^\(.*\)$;cp \1 $tmpdir/;' |
michael@13 | 193 | echo "cp -p $spec $tmpdir/" |
michael@13 | 194 | ) >$tmpdir/.sh |
michael@13 | 195 | sh $tmpdir/.sh |
michael@13 | 196 | rm -f $tmpdir/.sh |
michael@13 | 197 | l_version="$release" |
michael@13 | 198 | l_release=`sh ./release.sh -r "${l_version}" -F "%t"` |
michael@13 | 199 | sed <$srcdir/aux.wrapsrc.sh >$tmpdir/openpkg.boot.tmp \ |
michael@13 | 200 | -e "s;@l_dir@;$name-$version-$release.src;" \ |
michael@13 | 201 | -e "s;@l_release@;$l_release;" \ |
michael@13 | 202 | -e "s;@l_version@;$l_version;" |
michael@13 | 203 | echo . | awk '{ |
michael@13 | 204 | for (i = 0; i < 8192; i++) { |
michael@13 | 205 | printf(" "); |
michael@13 | 206 | } |
michael@13 | 207 | }' >>$tmpdir/openpkg.boot.tmp |
michael@13 | 208 | dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=8 \ |
michael@13 | 209 | of=$pkgdir/$name-$version-$release.src.sh 2>/dev/null |
michael@13 | 210 | rm -f $tmpdir/openpkg.boot.tmp |
michael@13 | 211 | (cd $tmpdir && tar cf - *) >>$pkgdir/$name-$version-$release.src.sh |
michael@13 | 212 | rm -rf $tmpdir |
michael@13 | 213 | exit 0 |
michael@13 | 214 | fi |
michael@13 | 215 | |
michael@13 | 216 | ## |
michael@13 | 217 | ## determine distribution directory |
michael@13 | 218 | ## |
michael@13 | 219 | |
michael@13 | 220 | V_rpm=`grep V_rpm $spec | sed -e 'q' | awk '{ printf("%s", $3); }'` |
michael@13 | 221 | if [ -f "../../dst/openpkg/rpm-${V_rpm}.tar.gz" ]; then |
michael@13 | 222 | distdir="`cd ../../dst/openpkg; pwd`" # developer only |
michael@13 | 223 | else |
michael@13 | 224 | distdir="`pwd`" |
michael@13 | 225 | fi |
michael@13 | 226 | echo "++ distribution directory: $distdir" |
michael@13 | 227 | |
michael@13 | 228 | ## |
michael@13 | 229 | ## perform prerequisite checks |
michael@13 | 230 | ## |
michael@13 | 231 | |
michael@13 | 232 | sh ./aux.prereq.sh source || exit $? |
michael@13 | 233 | |
michael@13 | 234 | ## |
michael@13 | 235 | ## find reasonable run-time paths and tools |
michael@13 | 236 | ## |
michael@13 | 237 | |
michael@13 | 238 | # find reasonable temporary directory |
michael@13 | 239 | tmpdir="${TMPDIR-/tmp}" |
michael@13 | 240 | |
michael@13 | 241 | # find reasonable safe program path |
michael@13 | 242 | test ".$PATH" = . && PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin" |
michael@13 | 243 | for dir in /usr/ccs/bin /usr/xpg4/bin; do |
michael@13 | 244 | test -d $dir && PATH="$PATH:$dir" |
michael@13 | 245 | done |
michael@13 | 246 | export PATH |
michael@13 | 247 | |
michael@13 | 248 | # make environment at least partly sane |
michael@13 | 249 | umask 022 |
michael@13 | 250 | unset ls rm mv cp sed grep awk >/dev/null 2>&1 || true |
michael@13 | 251 | |
michael@13 | 252 | ## |
michael@13 | 253 | ## execute the spec file manually by emulating |
michael@13 | 254 | ## the behaviour of the OpenPKG RPM tool. |
michael@13 | 255 | ## |
michael@13 | 256 | |
michael@13 | 257 | # create script prolog |
michael@13 | 258 | prolog="$tmpdir/openpkg.boot.prolog.sh" |
michael@13 | 259 | cp /dev/null $prolog |
michael@13 | 260 | ( |
michael@13 | 261 | echo "_specdir=`pwd`" |
michael@13 | 262 | echo "_sourcedir=$distdir" |
michael@13 | 263 | echo "_tmppath=$tmpdir" |
michael@13 | 264 | echo "_builddir=$tmpdir" |
michael@13 | 265 | echo "l_prefix=$prefix" |
michael@13 | 266 | echo "l_tag_fmt=\"$tag\"" |
michael@13 | 267 | echo "l_buildroot=$tmpdir/$name-$version-root" |
michael@13 | 268 | echo "l_susr=$susr" |
michael@13 | 269 | echo "l_sgrp=$sgrp" |
michael@13 | 270 | echo "l_musr=$musr" |
michael@13 | 271 | echo "l_mgrp=$mgrp" |
michael@13 | 272 | echo "l_rusr=$rusr" |
michael@13 | 273 | echo "l_rgrp=$rgrp" |
michael@13 | 274 | echo "l_nusr=$nusr" |
michael@13 | 275 | echo "l_ngrp=$ngrp" |
michael@13 | 276 | echo "l_suid=$suid" |
michael@13 | 277 | echo "l_sgid=$sgid" |
michael@13 | 278 | echo "l_muid=$muid" |
michael@13 | 279 | echo "l_mgid=$mgid" |
michael@13 | 280 | echo "l_ruid=$ruid" |
michael@13 | 281 | echo "l_rgid=$rgid" |
michael@13 | 282 | echo "l_nuid=$nuid" |
michael@13 | 283 | echo "l_ngid=$ngid" |
michael@13 | 284 | echo "use_tar=$use_tar" |
michael@13 | 285 | echo "use_make=$use_make" |
michael@13 | 286 | echo "use_cc=$use_cc" |
michael@13 | 287 | echo "use_ar=$use_ar" |
michael@13 | 288 | echo "use_ld=$use_ld" |
michael@13 | 289 | echo "use_as=$use_as" |
michael@13 | 290 | echo "use_strip=$use_strip" |
michael@13 | 291 | grep '%define' $spec | \ |
michael@13 | 292 | sed \ |
michael@13 | 293 | -e 's:^%define *\([^ ]*\) *\(.*\):\1="\2":' |
michael@13 | 294 | grep "^[A-Za-z0-9]*: *" $spec | \ |
michael@13 | 295 | sed \ |
michael@13 | 296 | -e 's;^\([A-Za-z0-9]*\): *\(.*\)$;\1="\2";' \ |
michael@13 | 297 | -e 's;^A;a;' -e 's;^B;b;' -e 's;^C;c;' -e 's;^D;d;' -e 's;^E;e;' \ |
michael@13 | 298 | -e 's;^F;f;' -e 's;^G;g;' -e 's;^H;h;' -e 's;^I;i;' -e 's;^J;j;' \ |
michael@13 | 299 | -e 's;^K;k;' -e 's;^L;l;' -e 's;^M;m;' -e 's;^N;n;' -e 's;^O;o;' \ |
michael@13 | 300 | -e 's;^P;p;' -e 's;^Q;q;' -e 's;^R;r;' -e 's;^S;s;' -e 's;^T;t;' \ |
michael@13 | 301 | -e 's;^U;u;' -e 's;^V;v;' -e 's;^W;w;' -e 's;^X;x;' -e 's;^Y;y;' \ |
michael@13 | 302 | -e 's;^Z;z;' -e 's;^buildRoot;buildroot;' |
michael@13 | 303 | echo "RPM_BUILD_ROOT=\"%{buildroot}\"" |
michael@13 | 304 | echo "RPM_BUILD_DIR=\"%{_builddir}\"" |
michael@13 | 305 | echo "RPM_SOURCE_DIR=\"$distdir\"" |
michael@13 | 306 | echo "export RPM_BUILD_ROOT" |
michael@13 | 307 | echo "export RPM_BUILD_DIR" |
michael@13 | 308 | echo "export RPM_SOURCE_DIR" |
michael@13 | 309 | echo "set -x" |
michael@13 | 310 | echo "umask 022" |
michael@13 | 311 | echo "cd \$RPM_BUILD_DIR" |
michael@13 | 312 | ) | sed -e 's;%{\([^}]*\)};${\1};g' >$prolog |
michael@13 | 313 | |
michael@13 | 314 | # install package via RPM spec file by faking a |
michael@13 | 315 | # sufficiently enough RPM run-time environment |
michael@13 | 316 | runscript () { |
michael@13 | 317 | step=$1 |
michael@13 | 318 | script="$tmpdir/openpkg.boot.$step.sh" |
michael@13 | 319 | echo ". $prolog" >$script |
michael@13 | 320 | sed -e "/^%$step/,/^%/ p" -e 'd' <$spec | \ |
michael@13 | 321 | sed -e '/^%/d' | \ |
michael@13 | 322 | sed -e 's;%{SOURCE \([^ ]*\.tar[^ ]*\)};${RPM_DIST_DIR}/\1;g' \ |
michael@13 | 323 | -e 's;%{SOURCE \([^ ]*\)};${RPM_SOURCE_DIR}/\1;g' | \ |
michael@13 | 324 | sed -e 's;%{[?]\([^:}]*\):\([^}]*\)};${\1+\2};g' \ |
michael@13 | 325 | -e 's;%{![?]\([^:}]*\):\([^}]*\)};${\1-\2};g' \ |
michael@13 | 326 | -e 's;%{[?]\([^:}]*\)};${\1+""};g' \ |
michael@13 | 327 | -e 's;%{![?]\([^:}]*\)};${\1-""};g' \ |
michael@13 | 328 | -e 's;%{\([^}]*\)};${\1};g' >>$script |
michael@13 | 329 | echo "++ executing(%$step): sh $script" |
michael@13 | 330 | sh $script |
michael@13 | 331 | if [ $? -ne 0 ]; then |
michael@13 | 332 | rm -f $script |
michael@13 | 333 | echo "$0:ERROR: script returned non-null value" |
michael@13 | 334 | exit 1 |
michael@13 | 335 | fi |
michael@13 | 336 | rm -f $script |
michael@13 | 337 | } |
michael@13 | 338 | runscript prep |
michael@13 | 339 | runscript build |
michael@13 | 340 | runscript install |
michael@13 | 341 | |
michael@13 | 342 | ## |
michael@13 | 343 | ## adjust build environment so that the installed |
michael@13 | 344 | ## "rpm" is actually useable, although it still resides in |
michael@13 | 345 | ## the temporary location instead of the real location. |
michael@13 | 346 | ## |
michael@13 | 347 | |
michael@13 | 348 | # suck in prolog in order to get variables from the spec file |
michael@13 | 349 | cwd=`pwd` |
michael@13 | 350 | . $prolog |
michael@13 | 351 | cd $cwd |
michael@13 | 352 | |
michael@13 | 353 | # suck in buildenv script in order to get musr/mgrp |
michael@13 | 354 | . $tmpdir/openpkg-*/.buildenv |
michael@13 | 355 | |
michael@13 | 356 | # create a custom "rpm" command |
michael@13 | 357 | echo "++ creating custom RPM command" |
michael@13 | 358 | rm -f $tmpdir/rpm >/dev/null 2>&1 |
michael@13 | 359 | rmdir $tmpdir/rpm >/dev/null 2>&1 |
michael@13 | 360 | if [ -d "$tmpdir/rpm" ]; then |
michael@13 | 361 | echo "$0:ERROR: directory $tmpdir/rpm exists, cannot create file with same name" |
michael@13 | 362 | exit 1 |
michael@13 | 363 | fi |
michael@13 | 364 | if [ -f "$tmpdir/rpm" ]; then |
michael@13 | 365 | echo "$0:ERROR: file $tmpdir/rpm exists, cannot override" |
michael@13 | 366 | exit 1 |
michael@13 | 367 | fi |
michael@13 | 368 | ( echo "#!/bin/sh" |
michael@13 | 369 | echo "exec $RPM_BUILD_ROOT$prefix/lib/openpkg/rpm \\" |
michael@13 | 370 | echo " --rcfile \"$tmpdir/rpm.1\" \\" |
michael@13 | 371 | echo " --define \"__platform $RPM_BUILD_ROOT$prefix/etc/openpkg/platform\" \\" |
michael@13 | 372 | echo " \"\$@\"" |
michael@13 | 373 | ) >$tmpdir/rpm |
michael@13 | 374 | chmod a+x $tmpdir/rpm |
michael@13 | 375 | |
michael@13 | 376 | # direct our own "rpm" tool to adjusted macro sets |
michael@13 | 377 | sed <`SOURCE rpmrc` >$tmpdir/rpm.1 \ |
michael@13 | 378 | -e "s;^\\(macrofiles:\\) .*;\\1 $tmpdir/rpm.2:$tmpdir/rpm.3;" |
michael@13 | 379 | |
michael@13 | 380 | # use an adjusted vendor macro set |
michael@13 | 381 | sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/macros >$tmpdir/rpm.2 \ |
michael@13 | 382 | -e "s;$prefix;$RPM_BUILD_ROOT$prefix;g" |
michael@13 | 383 | |
michael@13 | 384 | # override the vendor macro set |
michael@13 | 385 | sed <`SOURCE rpmmacros` >$tmpdir/rpm.3 \ |
michael@13 | 386 | -e "s;@SUSR@;$susr;" \ |
michael@13 | 387 | -e "s;@SGRP@;$sgrp;" \ |
michael@13 | 388 | -e "s;@MUSR@;$musr;" \ |
michael@13 | 389 | -e "s;@MGRP@;$mgrp;" \ |
michael@13 | 390 | -e "s;@RUSR@;$rusr;" \ |
michael@13 | 391 | -e "s;@RGRP@;$rgrp;" \ |
michael@13 | 392 | -e "s;@NUSR@;$nusr;" \ |
michael@13 | 393 | -e "s;@NGRP@;$ngrp;" \ |
michael@13 | 394 | -e "s;@TAG@;$tag;" \ |
michael@13 | 395 | -e "s;\\(%{l_prefix}/lib/openpkg/rpmtool\\);%{l_bash} \\1;g" \ |
michael@13 | 396 | -e "s;@l_prefix_static@;$prefix;g" \ |
michael@13 | 397 | -e "s;@l_prefix@;$RPM_BUILD_ROOT$prefix;g" \ |
michael@13 | 398 | -e "s;%l_prefix\\([^_]\\);%l_prefix_INTERNAL\\1;g" \ |
michael@13 | 399 | -e "s;%{l_prefix};%{l_prefix_INTERNAL};g" \ |
michael@13 | 400 | -e "s;^\\(%_specdir *\\).*;\\1 `pwd`;" \ |
michael@13 | 401 | -e "s;^\\(%_sourcedir *\\).*;\\1 $distdir;" \ |
michael@13 | 402 | -e "s;^\\(%_builddir *\\).*;\\1 $tmpdir;" \ |
michael@13 | 403 | -e "s;^\\(%_tmppath *\\).*;\\1 $tmpdir;" \ |
michael@13 | 404 | -e "s;^\\(%_buildshell *\\).*;\\1 env -i OPENPKG_BOOT=1 %{l_build_shell_cmd} %{l_build_shell_opt};" \ |
michael@13 | 405 | -e "s;@l_build_path@;/bin:/sbin:/usr/bin:/usr/sbin;g" \ |
michael@13 | 406 | -e "s;@l_build_ldlp@;/usr/lib;g" \ |
michael@13 | 407 | -e "s;@l_build_ulim@;:;g" |
michael@13 | 408 | echo "%l_prefix $prefix" >>$tmpdir/rpm.3 |
michael@13 | 409 | |
michael@13 | 410 | # use an own $HOME/.popt in order to make sure the "rpm" |
michael@13 | 411 | # tool is able to execute its sub-tools "rpm<x>". |
michael@13 | 412 | V_rpm=`grep V_rpm $spec | sed -e 'q' | awk '{ printf("%s", $3); }'` |
michael@13 | 413 | sed <$RPM_BUILD_ROOT$prefix/lib/openpkg/rpmpopt >$tmpdir/.popt \ |
michael@13 | 414 | -e "s;^\\(rpm.*exec.*\\)\\(rpm[bdieukvq]*\\);\\1$RPM_BUILD_ROOT$prefix/lib/openpkg/\\2;" |
michael@13 | 415 | |
michael@13 | 416 | # activate the .popt file |
michael@13 | 417 | HOME=$tmpdir |
michael@13 | 418 | export HOME |
michael@13 | 419 | |
michael@13 | 420 | ## |
michael@13 | 421 | ## now initialize the RPM database under the temporary install location |
michael@13 | 422 | ## |
michael@13 | 423 | |
michael@13 | 424 | echo "++ initializing RPM database" |
michael@13 | 425 | $RPM_BUILD_ROOT$prefix/lib/openpkg/bash \ |
michael@13 | 426 | $RPM_BUILD_ROOT$prefix/lib/openpkg/rpmdb \ |
michael@13 | 427 | --prefix=$RPM_BUILD_ROOT$prefix \ |
michael@13 | 428 | --dbpath=$RPM_BUILD_ROOT$prefix/RPM/DB \ |
michael@13 | 429 | --rpm=$tmpdir/rpm \ |
michael@13 | 430 | --build --quiet |
michael@13 | 431 | |
michael@13 | 432 | ## |
michael@13 | 433 | ## now turn over and re-iterate over the RPM spec, but this time |
michael@13 | 434 | ## with the real RPM tool. |
michael@13 | 435 | ## |
michael@13 | 436 | |
michael@13 | 437 | echo "++ re-iterating over RPM specification procedures" |
michael@13 | 438 | $tmpdir/rpm -bb $spec |
michael@13 | 439 | |
michael@13 | 440 | ## |
michael@13 | 441 | ## and finally overwrite the installation again, but this time by |
michael@13 | 442 | ## installing officially through the "rpm" tool. This way we achieve |
michael@13 | 443 | ## that RPM is remembered as an RPM package in its own database. We |
michael@13 | 444 | ## just have to make sure the package is relocated while installing. |
michael@13 | 445 | ## For this we could use --prefix=$RPM_BUILD_ROOT$prefix, but this |
michael@13 | 446 | ## would create an incorrect filelist for "rpm" in the database. |
michael@13 | 447 | ## Instead we use the --justdb option which means "rpm" behaves as it |
michael@13 | 448 | ## would install into the real location, but does not actually install |
michael@13 | 449 | ## anything. But as a side-effect, the database is now correct. |
michael@13 | 450 | ## |
michael@13 | 451 | |
michael@13 | 452 | echo "++ overwriting RPM installation by installing via RPM itself" |
michael@13 | 453 | $tmpdir/rpm --install --justdb --force --noscripts --notriggers --ignoresize \ |
michael@13 | 454 | $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-*.rpm |
michael@13 | 455 | |
michael@13 | 456 | ## Puhhhh!!! what a tricky bootstrapping procedure. But now we are |
michael@13 | 457 | ## mostly finished. All we finally have to do is to roll a bootstrap |
michael@13 | 458 | ## tarball in addition to the binary RPM and save the stuff in a |
michael@13 | 459 | ## permanent location. |
michael@13 | 460 | |
michael@13 | 461 | v="$version-$release" |
michael@13 | 462 | t="`$tmpdir/rpm --eval '%{l_platform -p}-%{l_tag}'`" |
michael@13 | 463 | |
michael@13 | 464 | # find a reasonable destination directory for packages |
michael@13 | 465 | if [ -d ../PKG/BIN ]; then |
michael@13 | 466 | dstdir=../PKG/BIN |
michael@13 | 467 | elif [ -d ../PKG ]; then |
michael@13 | 468 | dstdir=../PKG |
michael@13 | 469 | elif [ -d ../../PKG/BIN ]; then |
michael@13 | 470 | dstdir=../../PKG/BIN |
michael@13 | 471 | elif [ -d ../../PKG ]; then |
michael@13 | 472 | dstdir=../../PKG |
michael@13 | 473 | else |
michael@13 | 474 | dstdir=.. |
michael@13 | 475 | fi |
michael@13 | 476 | |
michael@13 | 477 | # create Source-RPM file |
michael@13 | 478 | echo "++ creating bootstrap source RPM file" |
michael@13 | 479 | $tmpdir/rpm -bs --nodeps $spec |
michael@13 | 480 | cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.src.rpm $dstdir/ |
michael@13 | 481 | rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.src.rpm |
michael@13 | 482 | |
michael@13 | 483 | # create Binary-RPM file |
michael@13 | 484 | echo "++ creating bootstrap binary RPM file" |
michael@13 | 485 | cp $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.$t.rpm $dstdir/ |
michael@13 | 486 | rm -f $RPM_BUILD_ROOT$prefix/RPM/PKG/openpkg-$v.$t.rpm |
michael@13 | 487 | |
michael@13 | 488 | # create Binary-Bootstrap file |
michael@13 | 489 | echo "++ creating bootstrap binary shell script" |
michael@13 | 490 | files=`cat $spec |\ |
michael@13 | 491 | sed -e '1,/%files/d' -e '/%clean/,$d' |\ |
michael@13 | 492 | grep -v '^ *$' | grep -v '%defattr' |\ |
michael@13 | 493 | sed -e 's;%config(noreplace) *;;' -e 's;%config *;;' -e 's;%ghost *;;' -e 's;%attr([^)]*) *;;' \ |
michael@13 | 494 | -e 's;%dir *;;' -e 's;%{l_prefix}/;;' -e 's;^ *;;' -e "s;%{V_rpm};${V_rpm};"` |
michael@13 | 495 | db_files="" |
michael@13 | 496 | for db_file in \ |
michael@13 | 497 | `$RPM_BUILD_ROOT$prefix/lib/openpkg/bash \ |
michael@13 | 498 | $RPM_BUILD_ROOT$prefix/lib/openpkg/rpmdb \ |
michael@13 | 499 | --prefix=$RPM_BUILD_ROOT$prefix \ |
michael@13 | 500 | --dbpath=$RPM_BUILD_ROOT$prefix/RPM/DB \ |
michael@13 | 501 | --list --quiet`; do |
michael@13 | 502 | db_files="$db_files RPM/DB/$db_file" |
michael@13 | 503 | done |
michael@13 | 504 | chmod 644 $RPM_BUILD_ROOT$prefix/RPM/DB/* |
michael@13 | 505 | files="$files $db_files" |
michael@13 | 506 | ( cd $RPM_BUILD_ROOT$prefix |
michael@13 | 507 | $RPM_BUILD_ROOT$prefix/lib/openpkg/tar --no-recursion -cf - $files |
michael@13 | 508 | ) | $RPM_BUILD_ROOT$prefix/lib/openpkg/bzip2 -9 \ |
michael@13 | 509 | >$RPM_BUILD_ROOT$prefix/openpkg.tar.bz2 |
michael@13 | 510 | cp -p $RPM_BUILD_ROOT$prefix/lib/openpkg/tar \ |
michael@13 | 511 | $RPM_BUILD_ROOT$prefix/openpkg.tar |
michael@13 | 512 | cp -p $RPM_BUILD_ROOT$prefix/lib/openpkg/bzip2 \ |
michael@13 | 513 | $RPM_BUILD_ROOT$prefix/openpkg.bzip2 |
michael@13 | 514 | l_platform=`$tmpdir/rpm --eval '%{l_platform -p}'` |
michael@13 | 515 | l_version=`$tmpdir/rpm -q --qf '%{version}' openpkg` |
michael@13 | 516 | release_sh=`SOURCE release.sh` |
michael@13 | 517 | l_release=`sh $release_sh -r "$l_version" -F "%t"` |
michael@13 | 518 | cat $spec |\ |
michael@13 | 519 | sed -e "/^%pre$/,/^%/ p" -e 'd' |\ |
michael@13 | 520 | sed -e '/^%/d' -e 's/^ //' |\ |
michael@13 | 521 | sed -e 's;%{[?]l_\([^:}]*\):\([^}]*\)};${\1+\2};g' \ |
michael@13 | 522 | -e 's;%{![?]l_\([^:}]*\):\([^}]*\)};${\1-\2};g' \ |
michael@13 | 523 | -e 's;%{[?]l_\([^:}]*\)};${\1+""};g' \ |
michael@13 | 524 | -e 's;%{![?]l_\([^:}]*\)};${\1-""};g' \ |
michael@13 | 525 | -e 's;%{l_\([^}]*\)};${\1};g' \ |
michael@13 | 526 | >$tmpdir/rpm.pre |
michael@13 | 527 | cat $spec |\ |
michael@13 | 528 | sed -e "/^%post$/,/^%/ p" -e 'd' |\ |
michael@13 | 529 | sed -e '/^%/d' -e 's/^ //' |\ |
michael@13 | 530 | sed -e 's;%{[?]l_\([^:}]*\):\([^}]*\)};${\1+\2};g' \ |
michael@13 | 531 | -e 's;%{![?]l_\([^:}]*\):\([^}]*\)};${\1-\2};g' \ |
michael@13 | 532 | -e 's;%{[?]l_\([^:}]*\)};${\1+""};g' \ |
michael@13 | 533 | -e 's;%{![?]l_\([^:}]*\)};${\1-""};g' \ |
michael@13 | 534 | -e 's;%{l_\([^}]*\)};${\1};g' \ |
michael@13 | 535 | >$tmpdir/rpm.post |
michael@13 | 536 | sed <`SOURCE aux.wrapbin.sh` \ |
michael@13 | 537 | -e "s;@SUSR@;$susr;" -e "s;@SGRP@;$sgrp;" \ |
michael@13 | 538 | -e "s;@MUSR@;$musr;" -e "s;@MGRP@;$mgrp;" \ |
michael@13 | 539 | -e "s;@RUSR@;$rusr;" -e "s;@RGRP@;$rgrp;" \ |
michael@13 | 540 | -e "s;@NUSR@;$nusr;" -e "s;@NGRP@;$ngrp;" \ |
michael@13 | 541 | -e "s;@SUID@;$suid;" -e "s;@SGID@;$sgid;" \ |
michael@13 | 542 | -e "s;@MUID@;$muid;" -e "s;@MGID@;$mgid;" \ |
michael@13 | 543 | -e "s;@RUID@;$ruid;" -e "s;@RGID@;$rgid;" \ |
michael@13 | 544 | -e "s;@NUID@;$nuid;" -e "s;@NGID@;$ngid;" \ |
michael@13 | 545 | -e "s;@l_prefix@;$prefix;" \ |
michael@13 | 546 | -e "s;@l_platform@;$l_platform;" \ |
michael@13 | 547 | -e "s;@l_release@;$l_release;" \ |
michael@13 | 548 | -e "s;@l_version@;$l_version;" \ |
michael@13 | 549 | -e "/^@PRE@/r $tmpdir/rpm.pre" \ |
michael@13 | 550 | -e "/^@POST@/r $tmpdir/rpm.post" |\ |
michael@13 | 551 | sed -e '/^@PRE@/d' -e '/^@POST@/d' >$tmpdir/openpkg.boot.tmp |
michael@13 | 552 | echo . | awk '{ |
michael@13 | 553 | for (i = 0; i < 8192; i++) { |
michael@13 | 554 | printf(" "); |
michael@13 | 555 | } |
michael@13 | 556 | }' >>$tmpdir/openpkg.boot.tmp |
michael@13 | 557 | rm -f $dstdir/openpkg-$v.$t.sh |
michael@13 | 558 | dd if=$tmpdir/openpkg.boot.tmp bs=8192 count=8 \ |
michael@13 | 559 | of=$dstdir/openpkg-$v.$t.sh 2>/dev/null |
michael@13 | 560 | rm -f $tmpdir/openpkg.boot.tmp |
michael@13 | 561 | ( cd $RPM_BUILD_ROOT$prefix |
michael@13 | 562 | $RPM_BUILD_ROOT$prefix/lib/openpkg/tar --no-recursion -cf - \ |
michael@13 | 563 | openpkg.tar openpkg.bzip2 openpkg.tar.bz2 |
michael@13 | 564 | ) >>$dstdir/openpkg-$v.$t.sh |
michael@13 | 565 | |
michael@13 | 566 | # cleanup |
michael@13 | 567 | echo "++ cleaning up" |
michael@13 | 568 | cp `SOURCE rpmtool` $tmpdir/rpmtool |
michael@13 | 569 | rm -rf $RPM_BUILD_ROOT |
michael@13 | 570 | rm -rf $tmpdir/$name-$version |
michael@13 | 571 | rm -f $tmpdir/rpm $tmpdir/rpm.[123] $tmpdir/.popt $tmpdir/rpm.pre $tmpdir/rpm.post |
michael@13 | 572 | rm -f $prolog |
michael@13 | 573 | |
michael@13 | 574 | # final hint about results |
michael@13 | 575 | echo "++ resulting OpenPKG bootstrap package files:" |
michael@13 | 576 | (cd $dstdir; ls -l openpkg-$v.$t.sh openpkg-$v.$t.rpm openpkg-$v.src.rpm) |
michael@13 | 577 | set +x |
michael@13 | 578 | ( echo "You have successfully built the OpenPKG Package from scratch" |
michael@13 | 579 | echo "for prefix $prefix on target platform $l_platform. The input" |
michael@13 | 580 | echo "was the OpenPKG Source Bootstrap Package in file:" |
michael@13 | 581 | echo "" |
michael@13 | 582 | echo " openpkg-$v.src.sh" |
michael@13 | 583 | echo "" |
michael@13 | 584 | echo "The results are the following three files:" |
michael@13 | 585 | echo "" |
michael@13 | 586 | echo " openpkg-$v.src.rpm" |
michael@13 | 587 | echo " openpkg-$v.$t.rpm" |
michael@13 | 588 | echo " openpkg-$v.$t.sh" |
michael@13 | 589 | echo "" |
michael@13 | 590 | echo "The first result file is the OpenPKG Source RPM Package," |
michael@13 | 591 | echo "containing just the same contents than the OpenPKG Source" |
michael@13 | 592 | echo "Bootstrap Package, but now in RPM format. Optionally use this" |
michael@13 | 593 | echo "after the installation of the OpenPKG Binary Bootstrap Package" |
michael@13 | 594 | echo "if you want to rebuild from source again (but then with RPM" |
michael@13 | 595 | echo "available)." |
michael@13 | 596 | echo "" |
michael@13 | 597 | echo "The second result file is the OpenPKG Binary RPM Package," |
michael@13 | 598 | echo "containing the installation files in RPM format for the OpenPKG" |
michael@13 | 599 | echo "instance $prefix. Optionally use this after the installation of" |
michael@13 | 600 | echo "the OpenPKG Binary Bootstrap Package if you want (usually for" |
michael@13 | 601 | echo "fixing something) to reinstall (but then with RPM available)." |
michael@13 | 602 | echo "" |
michael@13 | 603 | echo "The third result file is the OpenPKG Binary Bootstrap Package," |
michael@13 | 604 | echo "containing the installation files as a self-extracting shell" |
michael@13 | 605 | echo "script for the OpenPKG instance $prefix. Use this in YOUR NEXT" |
michael@13 | 606 | echo "STEP to initially create the OpenPKG instance from scratch." |
michael@13 | 607 | echo "Hence, proceed now by running the following command:" |
michael@13 | 608 | echo "" |
michael@13 | 609 | cusr=`(id -un) 2>/dev/null ||\ |
michael@13 | 610 | (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\ |
michael@13 | 611 | (whoami) 2>/dev/null ||\ |
michael@13 | 612 | (who am i | cut "-d " -f1) 2>/dev/null ||\ |
michael@13 | 613 | echo $LOGNAME` |
michael@13 | 614 | if [ ".$musr.$rusr.$nusr" = ".$cusr.$cusr.$cusr" -o ".$cusr" = ".root" ]; then |
michael@13 | 615 | echo " \$ sh openpkg-$v.$t.sh" |
michael@13 | 616 | else |
michael@13 | 617 | echo " \$ su root -c \"sh openpkg-$v.$t.sh\"" |
michael@13 | 618 | fi |
michael@13 | 619 | ) | sh $tmpdir/rpmtool msg -b -t info |
michael@13 | 620 | rm -f $tmpdir/rpmtool |
michael@13 | 621 |