/[polypkg]/trunk/pp.back.rpm
ViewVC logotype

Contents of /trunk/pp.back.rpm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 216 - (show annotations)
Tue Jun 2 20:00:22 2009 UTC (5 months, 2 weeks ago) by tperciva
File size: 18023 byte(s)
Build using `rpm` not `rpmbuild` on older systems

eg. SUSE 8.1.
1 # rpm backend
2 # The packages generated by this backend are suitable for
3 # both redhat and linux.
4 # http://www.novell.com/coolsolutions/feature/11256.html
5
6 pp_platforms="$pp_platforms rpm"
7
8 #@ pp_backend_rpm_detect(uname_s): return true if this platform uses RPM
9 # -- specific test for debian
10 pp_backend_rpm_detect () {
11 test x"$1" = x"Linux" -a ! -f /etc/debian_version
12 }
13
14 #@ pp_backend_rpm_init(): initialises rpm backend variables
15 pp_backend_rpm_init () {
16
17 pp_rpm_version=
18 pp_rpm_summary=
19 pp_rpm_description=
20 pp_rpm_group="Applications/Internet"
21 pp_rpm_license=Unspecified
22 pp_rpm_vendor="Quest Software, Inc."
23 pp_rpm_packager=
24 pp_rpm_provides=
25 pp_rpm_requires=
26 pp_rpm_release=
27 pp_rpm_epoch=
28 pp_rpm_dev_group="Development/Libraries"
29 pp_rpm_dbg_group="Development/Tools"
30 pp_rpm_doc_group="Documentation"
31 pp_rpm_dev_description=
32 pp_rpm_dbg_description=
33 pp_rpm_doc_description=
34 pp_rpm_dev_requires=
35 pp_rpm_dbg_requires=
36 pp_rpm_doc_requires=
37 pp_rpm_dev_provides=
38 pp_rpm_dbg_provides=
39 pp_rpm_doc_provides=
40
41 pp_rpm_dbg_pkgname=debug
42 pp_rpm_dev_pkgname=devel
43 pp_rpm_doc_pkgname=doc
44
45 pp_rpm_defattr_uid=root
46 pp_rpm_defattr_gid=root
47
48 pp_rpm_detect_arch
49 pp_rpm_detect_distro
50 pp_rpm_rpmbuild=`pp_rpm_detect_rpmbuild`
51
52 # SLES8 doesn't always come with readlink
53 test -x /usr/bin/readlink -o -x /bin/readlink ||
54 pp_readlink_fn=pp_ls_readlink
55 }
56
57 #@ pp_rpm_detect_arch(): sets $pp_rpm_arch to current RPM architecture
58 pp_rpm_detect_arch () {
59 pp_rpm_arch=auto
60
61 #-- Find the default native architecture that RPM is configured to use
62 cat <<-. >$pp_wrkdir/dummy.spec
63 Name: dummy
64 Version: 1
65 Release: 1
66 Summary: dummy
67 Group: ${pp_rpm_group}
68 License: ${pp_rpm_license}
69 %description
70 dummy
71 .
72 $pp_opt_debug && cat $pp_wrkdir/dummy.spec
73 pp_rpm_arch_local=`rpm -q --qf '%{arch}\n' --specfile $pp_wrkdir/dummy.spec`
74 rm $pp_wrkdir/dummy.spec
75
76 #-- Ask the kernel what machine architecture is in use
77 case "`uname -m`" in
78 i?86) pp_rpm_arch_std=i386;;
79 x86_64) pp_rpm_arch_std=x86_64;;
80 ppc) pp_rpm_arch_std=ppc;;
81 ppc64) pp_rpm_arch_std=ppc64;;
82 ia64) pp_rpm_arch_std=ia64;;
83 s390) pp_rpm_arch_std=s390;;
84 s390x) pp_rpm_arch_std=s390x;;
85 *) pp_rpm_arch_std=unknown;;
86 esac
87
88 #-- Later on, when files are processed, we use 'file' to determine
89 # what platform ABIs are used. This is used when pp_rpm_arch == auto
90 pp_rpm_arch_seen=
91 }
92
93 #@ pp_rpm_detect_distro(): sets $pp_rpm_distro to a short distro name or ''
94 pp_rpm_detect_distro () {
95 pp_rpm_distro=
96 if test -f /etc/whitebox-release; then
97 pp_rpm_distro=`awk '
98 /^White Box Enterprise Linux release/ { print "wbel" $6; exit; }
99 ' /etc/whitebox-release`
100 elif test -f /etc/fedora-release; then
101 pp_rpm_distro=`awk '
102 /^Fedora Core release/ { print "fc" $4; exit; }
103 /^Fedora release/ { print "f" $3; exit; }
104 ' /etc/fedora-release`
105 elif test -f /etc/redhat-release; then
106 pp_rpm_distro=`awk '
107 /^Red Hat Enterprise Linux/ { print "rhel" $7; exit; }
108 /^CentOS release/ { print "centos" $3; exit; }
109 /^Red Hat Linux release/ { print "rh" $5; exit; }
110 ' /etc/redhat-release`
111 elif test -f /etc/SuSE-release; then
112 pp_rpm_distro=`awk '
113 /^SuSE Linux [0-9]/ { print "suse" $3; exit; }
114 /^SUSE LINUX [0-9]/ { print "suse" $3; exit; }
115 /^openSUSE [0-9]/ { print "suse" $2; exit; }
116 /^SuSE Linux Enterprise Server [0-9]/ { print "sles" $5; exit; }
117 /^SUSE LINUX Enterprise Server [0-9]/ { print "sles" $5; exit; }
118 /^SuSE SLES-[0-9]/ { print "sles" substr($2,6); exit; }
119 ' /etc/SuSE-release`
120 fi
121 pp_rpm_distro=`echo $pp_rpm_distro | tr -d .`
122 test -z "$pp_rpm_distro" &&
123 pp_warn "unknown distro"
124 }
125
126 # Detect the rpmbuild program. On old systems, it is actually the `rpm`
127 # command. More recently it is called rpmbuild.
128 # Both are invoked the same way.
129 pp_rpm_detect_rpmbuild () {
130 typeset cmd
131 for cmd in rpmbuild rpm; do
132 if `which $cmd > /dev/null 2>&1`; then
133 echo $cmd
134 return 0
135 fi
136 done
137
138 pp_error "Could not find rpmbuild"
139 # Default to `rpmbuild` in case it magically appears
140 echo rpmbuild
141 return 1
142 }
143
144 #@ pp_rpm_label(label [arg...]): writes "$label: $arg" for each non-empty arg
145 pp_rpm_label () {
146 typeset label arg
147 label="$1"; shift
148 for arg
149 do
150 test -z "$arg" || echo "$label: $arg"
151 done
152 }
153
154 #@ pp_rpm_writefiles() < %files: Write body of a %files section in RPM form
155 pp_rpm_writefiles () {
156 typeset _l t m o g f p st fo farch
157 while read t m o g f p st; do
158 _l="$p"
159 test $t = d && _l="%dir ${_l%/}/"
160 if test x"$m" = x"-"; then
161 case "$t" in
162 d) m=755;;
163 f) m=644;;
164 esac
165 fi
166 test x"$o" = x"-" && o="${pp_rpm_defattr_uid:-root}"
167 test x"$g" = x"-" && g="${pp_rpm_defattr_gid:-root}"
168 _l="%attr($m,$o,$g) $_l"
169
170 if test "$t" = "f" -a x"$pp_rpm_arch" = x"auto"; then
171 fo=`file "${pp_destdir}$p" 2>/dev/null`
172 #NB: The following should match executables and shared objects,
173 #relocatable objects. It will not match .a files however.
174 case "$fo" in
175 *": ELF 32-bit LSB "*", Intel 80386"*)
176 farch=i386;;
177 *": ELF 64-bit LSB "*", AMD x86-64"*|\
178 *": ELF 64-bit LSB "*", x86-64"*)
179 farch=x86_64;;
180 *": ELF 32-bit MSB "*", PowerPC"*)
181 farch=ppc;;
182 *": ELF 64-bit LSB "*", IA-64"*)
183 farch=ia64;;
184 *": ELF 32-bit MSB "*", IBM S/390"*)
185 farch=s390;;
186 *": ELF 64-bit MSB "*", IBM S/390"*)
187 farch=s390x;;
188 *)
189 farch=noarch;;
190 esac
191 pp_debug "file: $fo -> $farch"
192 test x"$farch" = x"noarch" || pp_add_to_list pp_rpm_arch_seen $farch
193 fi
194
195 case $f in *v*) _l="%config $_l";; esac
196 echo "$_l"
197 done
198 echo
199 }
200
201 #@ pp_rpm_subname(component hyphen): translate cpt into a linux subpackage name
202 pp_rpm_subname () {
203 case "$1" in
204 run) : ;;
205 dbg) echo "${2}${pp_rpm_dbg_pkgname}";;
206 dev) echo "${2}${pp_rpm_dev_pkgname}";;
207 doc) echo "${2}${pp_rpm_doc_pkgname}";;
208 *) pp_error "unknown component '$1'";
209 esac
210 }
211
212 #@ pp_rpm_depend() < %depend: generate Requires rules
213 pp_rpm_depend () {
214 while read _name _vers; do
215 case "$_name" in ""| "#"*) continue ;; esac
216 echo "Requires: $_name ${_vers:+>= $_vers}"
217 done
218 }
219
220 #@ pp_backend_rpm(): generate RPMs for the package
221 #-- Reads output files from the frontend and generates multiple output
222 # package files under $pp_wrkdir/
223 pp_backend_rpm () {
224 typeset cmp specfile _summary _group _desc _pkg _subname svc
225
226 specfile=$pp_wrkdir/$name.spec
227 : > $specfile
228
229 #-- force existence of a 'run' component
230 pp_add_component run
231 : >> $pp_wrkdir/%files.run
232
233 if test -z "$pp_rpm_arch"; then
234 pp_error "Unknown RPM architecture"
235 return 1
236 fi
237
238 #-- Write the header components of the RPM spec file
239 cat <<-. >>$specfile
240 Name: ${pp_rpm_name:-$name}
241 Version: ${pp_rpm_version:-$version}
242 Release: ${pp_rpm_release:-1}
243 Summary: ${pp_rpm_summary:-$summary}
244 Group: ${pp_rpm_group}
245 License: ${pp_rpm_license}
246 .
247 pp_rpm_label "Vendor" "$pp_rpm_vendor" >>$specfile
248 pp_rpm_label "Packager" "$pp_rpm_packager" >>$specfile
249 pp_rpm_label "Provides" "$pp_rpm_provides" >>$specfile
250
251 test -n "$pp_rpm_serial" && pp_warn "pp_rpm_serial deprecated"
252 if test -n "$pp_rpm_epoch"; then
253 #-- Epoch was introduced in RPM 2.5.6
254 case `$pp_rpm_rpmbuild --version 2>/dev/null` in
255 1.*|2.[0-5].*|2.5.[0-5])
256 pp_rpm_label "Serial" $pp_rpm_epoch >>$specfile;;
257 *)
258 pp_rpm_label "Epoch" $pp_rpm_epoch >>$specfile;;
259 esac
260 fi
261
262 if test -n "$pp_rpm_requires"; then
263 pp_rpm_label "Requires" "$pp_rpm_requires" >>$specfile
264 elif test -s $pp_wrkdir/%depend.run; then
265 pp_rpm_depend < $pp_wrkdir/%depend.run >> $specfile
266 fi
267
268 cat <<-. >>$specfile
269
270 %description
271 ${pp_rpm_description:-$description}
272 .
273
274 for cmp in $pp_components; do
275 case $cmp in
276 run) continue;;
277 dev) _summary="development tools for $pp_rpm_summary"
278 _group="$pp_rpm_dev_group"
279 _desc="${pp_rpm_dev_description:-Development libraries for $name. $pp_rpm_description.}"
280 ;;
281 doc) _summary="documentation for $pp_rpm_summary"
282 _group="$pp_rpm_doc_group"
283 _desc="${pp_rpm_doc_description:-Documentation for $name. $pp_rpm_description.}"
284 ;;
285 dbg) _summary="diagnostic tools for $pp_rpm_summary"
286 _group="$pp_rpm_dbg_group"
287 _desc="${pp_rpm_dbg_description:-Diagnostic tools for $name.}"
288 ;;
289 esac
290
291 _subname=`pp_rpm_subname $cmp`
292 cat <<-.
293
294 %package $_subname
295 Summary: $name $_summary
296 Group: $_group
297 .
298 eval '_pkg="$pp_rpm_'$cmp'_requires"'
299 if test -n "$_pkg"; then
300 eval pp_rpm_label Requires ${pp_rpm_name:-$name} $_pkg
301 elif test -s $pp_wrkdir/%depend.$cmp; then
302 pp_rpm_depend < $pp_wrkdir/%depend.$cmp >> $specfile
303 fi
304
305 eval '_pkg="$pp_rpm_'$cmp'_provides"'
306 eval pp_rpm_label Provides $_pkg
307
308 cat <<-.
309
310 %description $_subname
311 $_desc
312 .
313 done >>$specfile
314
315 #-- NB: we don't put any %prep, %build or %install RPM sections
316 # into the spec file.
317
318 #-- add service start/stop code
319 if test -n "$pp_services"; then
320 pp_rpm_service_install_common >> $pp_wrkdir/%post.run
321
322 #-- record the uninstall commands in reverse order
323 for svc in $pp_services; do
324 pp_load_service_vars $svc
325
326 pp_rpm_service_make_init_script $svc
327
328 #-- append %post code to install the svc
329 pp_rpm_service_install $svc >> $pp_wrkdir/%post.run
330
331 #-- prepend %preun code to uninstall svc
332 # (use files in case vars are modified)
333 pp_rpm_service_remove $svc | pp_prepend $pp_wrkdir/%preun.run
334 done
335 pp_rpm_service_remove_common | pp_prepend $pp_wrkdir/%preun.run
336 fi
337
338 # make convenience service groups
339 if test -n "$pp_service_groups"; then
340 for grp in $pp_service_groups; do
341 pp_rpm_service_group_make_init_script \
342 $grp "`pp_service_get_svc_group $grp`"
343 done
344 fi
345
346 #-- Write the RPM %file sections
347 # (do this after services, since services adds to %files.run)
348 for cmp in $pp_components; do
349 _subname=`pp_rpm_subname $cmp`
350
351 if test -s $pp_wrkdir/%check.$cmp; then
352 echo ""
353 echo "%pre $_subname"
354 cat $pp_wrkdir/%check.$cmp
355 echo : # causes script to exit true by default
356 fi
357
358 if test -s $pp_wrkdir/%files.$cmp; then
359 echo ""
360 echo "%files $_subname"
361 pp_rpm_writefiles < $pp_wrkdir/%files.$cmp
362 fi
363
364 if test -s $pp_wrkdir/%post.$cmp; then
365 echo ""
366 echo "%post $_subname"
367 # echo 'if test "$1" -eq 1; then # first install'
368 cat $pp_wrkdir/%post.$cmp
369 echo : # causes script to exit true
370 # echo 'fi'
371 fi
372
373 if test -s $pp_wrkdir/%preun.$cmp; then
374 echo ""
375 echo "%preun $_subname"
376 # echo 'if test "$1" -eq 0; then # uninstall'
377 cat $pp_wrkdir/%preun.$cmp
378 echo : # causes script to exit true
379 # echo 'fi'
380 fi
381 done >>$specfile
382
383 #-- create a suitable work area for rpmbuild
384 echo "%_topdir $pp_wrkdir" >$pp_wrkdir/.rpmmacros
385 mkdir $pp_wrkdir/RPMS
386 mkdir $pp_wrkdir/BUILD
387
388 if test x"$pp_rpm_arch" = x"auto"; then
389 #-- Reduce the arch_seen list to exactly one item
390 case "$pp_rpm_arch_seen" in
391 "i386 x86_64"|"x86_64 i386")
392 pp_rpm_arch_seen=x86_64;;
393 *" "*)
394 pp_warn "detected multiple targets: $pp_rpm_arch_seen"
395 pp_rpm_arch_seen=unknown;; # not detected
396 "")
397 pp_warn "detected no binaries: using target noarch"
398 pp_rpm_arch_seen=noarch;;
399 *)
400 pp_debug "detected architecture $pp_rpm_arch_seen"
401 esac
402 pp_rpm_arch="$pp_rpm_arch_seen"
403 fi
404
405 . $pp_wrkdir/%fixup
406
407 $pp_opt_debug && cat $specfile
408
409 pp_debug "creating: `pp_backend_rpm_names`"
410
411 pp_debug "pp_rpm_arch_seen = <${pp_rpm_arch_seen}>"
412 pp_debug "pp_rpm_arch = <${pp_rpm_arch}>"
413
414 HOME=$pp_wrkdir \
415 pp_verbose \
416 $pp_rpm_rpmbuild -bb \
417 --buildroot="$pp_destdir/" \
418 --target="${pp_rpm_arch}" \
419 --define='_unpackaged_files_terminate_build 0' \
420 `$pp_opt_debug && echo --verbose || echo --quiet` \
421 $pp_rpm_rpmbuild_extra_flags \
422 $specfile ||
423 pp_error "Problem creating RPM packages"
424
425 for f in `pp_backend_rpm_names`; do
426 # The package might be in an arch-specific subdir
427 pkgfile=not-found
428 for dir in $pp_wrkdir/RPMS/${pp_rpm_arch} $pp_wrkdir/RPMS; do
429 if test -f $dir/$f; then
430 pkgfile=$dir/$f
431 fi
432 done
433 if test x"$pkgfile" = x"not-found"; then
434 pp_error "Problem predicting RPM filename: $f"
435 else
436 ln $pkgfile $pp_wrkdir/$f
437 fi
438 done
439 }
440
441 #@ pp_rpm_output_name($cpt): print the package names for the subpackage
442 pp_rpm_output_name () {
443 echo "${pp_rpm_name:-$name}`pp_rpm_subname "$1" -`-${pp_rpm_version:-$version}-${pp_rpm_release:-1}.${pp_rpm_arch}.rpm"
444 }
445
446 #@ pp_backend_rpm_names(): print the package names generated
447 # the names always start with $name-$version
448 pp_backend_rpm_names () {
449 typeset cmp _subname
450 for cmp in $pp_components; do
451 pp_rpm_output_name $cmp
452 done
453 }
454
455 pp_backend_rpm_cleanup () {
456 :
457 }
458
459 #@ pp_rpm_print_requires(): prints the required features of the package
460 pp_rpm_print_requires () {
461 typeset _subname _name
462
463 echo "CPU:$pp_rpm_arch"
464 ## XXX should be lines of the form (from file/ldd/objdump)
465 # EXEC:/bin/sh
466 # RTLD:libc.so.4:open
467 rpm -q --requires -p $pp_wrkdir/`pp_rpm_output_name $1` |sed -e '/^rpmlib(/d;s/ //g;s/^/RPM:/' | sort -u
468 }
469
470 #@ pp_backend_rpm_install_script(): generate the install script
471 pp_backend_rpm_install_script () {
472 typeset cmp _subname
473
474 echo "#!/bin/sh"
475 pp_install_script_common
476
477 cat <<.
478
479 cmp_to_pkgname () {
480 typeset oi name
481 if test x"\$1" = x"--only-installed"; then
482 #-- only print if installation detected
483 oi=false
484 shift
485 else
486 oi=true
487 fi
488 test x"\$*" = x"all" &&
489 set -- $pp_components
490 for cmp
491 do
492 case \$cmp in
493 .
494 for cmp in $pp_components; do
495 _subname=`pp_rpm_subname $cmp -`
496 echo "$cmp) name=${pp_rpm_name:-$name}${_subname};;"
497 done
498 cat <<.
499 *) usage;;
500 esac
501 if \$oi || rpm -q "\$name" >/dev/null 2>/dev/null; then
502 echo "\$name"
503 fi
504 done
505 }
506
507
508 cmp_to_pathname () {
509 test x"\$*" = x"all" &&
510 set -- $pp_components
511 for cmp
512 do
513 case \$cmp in
514 .
515 for cmp in $pp_components; do
516 echo "$cmp) echo \${PP_PKGDESTDIR:-.}/`pp_rpm_output_name $cmp` ;;"
517 done
518 cat <<.
519 *) usage;;
520 esac
521 done
522 }
523
524 print_requires () {
525 test x"\$*" = x"all" &&
526 set -- $pp_components
527 for cmp
528 do
529 case \$cmp in
530 .
531 for cmp in $pp_components; do
532 echo "$cmp) cat <<'._end'"
533 pp_rpm_print_requires $cmp
534 echo "._end"; echo ';;'
535 done
536 cat <<.
537 *) usage;;
538 esac
539 done
540 }
541
542 test \$# -eq 0 && usage
543 op="\$1"; shift
544 case "\$op" in
545 list-components)
546 test \$# -eq 0 || usage \$op
547 echo $pp_components
548 ;;
549 list-services)
550 test \$# -eq 0 || usage \$op
551 echo $pp_services
552 ;;
553 list-files)
554 test \$# -ge 1 || usage \$op
555 cmp_to_pathname "\$@"
556 ;;
557 install)
558 test \$# -ge 1 || usage \$op
559 verbose rpm -U --replacepkgs --oldpackage \
560 \`cmp_to_pathname "\$@"\`
561 ;;
562 uninstall)
563 test \$# -ge 1 || usage \$op
564 pkgs=\`cmp_to_pkgname --only-installed "\$@"\`
565 if test -z "\$pkgs"; then
566 verbosemsg "nothing to uninstall"
567 else
568 verbose rpm -e \$pkgs
569 fi
570 ;;
571 start|stop)
572 test \$# -ge 1 || usage \$op
573 ec=0
574 for svc
575 do
576 verbose /etc/init.d/\$svc \$op || ec=1
577 done
578 exit \$ec
579 ;;
580 print-platform)
581 test \$# -eq 0 || usage \$op
582 echo "linux-${pp_rpm_arch}"
583 ;;
584 print-requires)
585 test \$# -ge 1 || usage \$op
586 print_requires "\$@"
587 ;;
588 *)
589 usage
590 ;;
591 esac
592 .
593
594 }
595
596 #@ pp_backend_rpm_probe(): print the local platform's short name
597 pp_backend_rpm_probe () {
598 echo "${pp_rpm_distro}-${pp_rpm_arch_std}"
599 }
600
601 #@ pp_backend_rpm_vas_platforms(): print the VAS platform identifiers
602 pp_backend_rpm_vas_platforms () {
603 case "$pp_rpm_arch_std" in
604 x86_64) echo "linux-x86_64.rpm linux-x86.rpm";;
605 *86) echo "linux-x86.rpm";;
606 s390) echo "linux-s390";;
607 s390x) echo "linux-s390x";;
608 ppc*) echo "linux-glibc23-ppc64 linux-glibc22-ppc64";;
609 ia64) echo "linux-ia64";;
610 *) pp_die "unknown architecture $pp_rpm_arch_std";;
611 esac
612 }

Ted.Percival@quest.com
ViewVC Help
Powered by ViewVC 1.1.2