-
Notifications
You must be signed in to change notification settings - Fork 7
/
pp.back.solaris
627 lines (564 loc) · 19 KB
/
pp.back.solaris
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#
# solaris backend
# http://docs.sun.com/app/docs/doc/802-1932
#
# the pkgmk tool input:
# prototype (required) -pkgproto(1M) or prototype(4)
# pkginfo (required) -pkginfo(4)
# compver (opt info)
# depend (opt info)
# space (opt info)
# copyright (opt info)
# request (optional script) (mode 0644 and no #!)
# checkinstall (could be used because vas dependencies broken)
# names must be [A-Za-z][-+A-Za-z0-9]{,8} and not (install|new|all)
#
# The component name is used for the class name
#
# pkginfo should have
# PKG=foobar
# NAME=the foo bad system
# CATEGORY=system
# ARCH=sparc
# VERSION=1.2[.3...][,REV=YYYY.MM.DD[.HH.MM.SS]]
# CLASSES=none
# prototype lines are
# [part] ftype class pathname[=srcpath] [mode owner group]
# directories should be 755 root sys
# binaries should be 555 root bin
# directories expected to exist should be ? ? ? (three question marks)
#
#
# Idea: create a "compressed" class that is installed using gzip?
#
#
pp_platforms="$pp_platforms solaris"
#@ pp_backend_solaris_detect(): return true if this platform uses solaris pkgs
pp_backend_solaris_detect () {
test x"$1" = x"SunOS"
}
#@ pp_backend_solaris_init(): initialise the solaris vars
pp_backend_solaris_init () {
pp_solaris_category=
pp_solaris_istates="s S 1 2 3" # run-states when install is ok
pp_solaris_rstates="s S 1 2 3" # run-states when remove is ok
pp_solaris_maxinst=
pp_solaris_vendor=
pp_solaris_pstamp=
pp_solaris_copyright=
pp_solaris_name=
pp_solaris_desc=
pp_solaris_package_arch=auto
pp_solaris_detect_os
pp_solaris_detect_arch
pp_solaris_init_svc
#-- readlink not reliably available on Solaris
pp_readlink_fn=pp_ls_readlink
}
#@ pp_solaris_detect_os(): set $pp_solaris_os to short platform ID
# Following the sunfreeware.com convention:
# SunOS 5.5 -> sol25
# SunOS 5.6 -> sol26
# SunOS 5.7 -> sol7
# SunOS 5.8 -> sol8
# SunOS 5.9 -> sol9
# SunOS 5.10 -> sol10
pp_solaris_detect_os () {
typeset osrel
osrel=`/usr/bin/uname -r`
case "$osrel" in
5.[0-6]) pp_solaris_os="sol2${osrel#5.}";;
5.*) pp_solaris_os="sol${osrel#5.}";;
esac
test -z "$pp_solaris_os" &&
pp_warn "can't determine OS suffix from uname -r"
}
#@ pp_solaris_detect_arch(): set $pp_solaris_arch to short platform arch
# NOTE: this is the architecture EXECUTION capability.
# The TARGET arch of the package is detected during pp_solaris_proto()
# i386 = 32-bit intel (i386)
# amd64 = 64-bit intel (x86_64)
# sparc = 32-bit sparc (sparc)
# sparcv9 = 64-bit sparc (sparc64)
pp_solaris_detect_arch () {
if [ -x /usr/bin/isainfo ]; then
pp_solaris_arch=`/usr/bin/isainfo -n`
else
pp_solaris_arch=`/usr/bin/optisa amd64 sparcv9 i386 sparc`
fi
[ -z "$pp_solaris_arch" ] &&
pp_error "can't determine processor architecture"
case "$pp_solaris_arch" in
amd64) pp_solaris_arch_std=x86_64;;
i386) pp_solaris_arch_std=i386;;
sparcv9) pp_solaris_arch_std=sparc64;;
sparc) pp_solaris_arch_std=sparc;;
*) pp_solaris_arch_std=unknown;;
esac
}
#@ pp_solaris_is_request_script_necessary():
# Return success if a request script should be generated; failure
# if it should not
pp_solaris_is_request_script_necessary () {
typeset has_optional_services
has_optional_services=no
for _svc in $pp_services; do
pp_load_service_vars $_svc
if test "$optional" = "yes"; then
has_optional_services=yes
fi
done
# If the package has no optional services and only one component, don't
# create a request script at all.
if test "$has_optional_services" = "no" &&
test `echo $pp_components | wc -w` -eq 1; then
return 1 # no
fi
return 0 # yes
}
#@ pp_solaris_request(output): Generate a request script for all components
pp_solaris_request () {
typeset _cmp _svc
#-- The common part of the request script contains the ask() function
# and resets the CLASSES list to empty
cat <<'.'
trap 'exit 3' 15
ask () {
ans=`ckyorn -d "$1" \
-p "Do you want to $2"` \
|| exit $?
case "$ans" in y*|Y*) return 0;; *) return 1;; esac
}
CLASSES=
.
#-- each of our components adds itself to the CLASSES list
for _cmp in $pp_components; do
case "$_cmp" in
run) :;;
doc) echo 'ask y "install the documentation files" &&';;
dev) echo 'ask y "install the development files" &&';;
dbg) echo 'ask n "install the diagnostic files" &&';;
esac
echo ' CLASSES="$CLASSES '$_cmp'"'
done
#-- the request script writes the CLASSES var to its output
cat <<'.'
echo "CLASSES=$CLASSES" > $1
.
if test -n "$pp_services"; then
echo 'SERVICES='
for _svc in $pp_services; do
pp_load_service_vars $_svc
if test "$enable" = "yes"; then
_default_prompt=y
else
_default_prompt=n
fi
if test "$optional" = "yes"; then
echo 'ask '$_default_prompt' "install '$_svc' service" &&'
fi
echo ' SERVICES="$SERVICES '$_svc'"'
done
echo 'echo "SERVICES=$SERVICES" >> $1'
fi
}
#@ pp_solaris_procedure(component, post|pre): add per-component scripts
# The code fragments are run only if the components are active
pp_solaris_procedure () {
cat <<.
#-- $2 for $1 component of $name
case " \$CLASSES " in *" $1 "*)
.
cat
cat <<.
;; esac
.
}
#@ pp_solaris_depend(): generate prerequisite depend(4) entries
pp_solaris_depend () {
typeset _name _vers
while read _name _vers; do
if test -n "$_name"; then
echo "P $_name $_name"
test -n "$_vers" && echo " $_vers"
fi
done
}
#@ pp_solaris_conflict(): generate incompatible depend(4) entries
pp_solaris_conflict () {
typeset _name _vers
while read _name _vers; do
if test -n "$_name"; then
echo "I $_name $_name"
test -n "$_vers" && echo " $_vers"
fi
done
}
#@ pp_solaris_space(dir,blocks,inodes): accumulate space reqts for a directory
pp_solaris_space() {
echo "$2:$3:$1" >> $pp_wrkdir/space.cumulative
}
#@ pp_solaris_sum_space(): sum the spaces reqts
pp_solaris_sum_space () {
if test -s $pp_wrkdir/space.cumulative; then
sort -t: +2 < $pp_wrkdir/space.cumulative |
awk -F: 'NR==1{n=$3}{if($3==n){b+=$1;i+=$2}else{print n" "b" "i;b=$1;i=$2;n=$3}}END{print n" "b" "i}' > $pp_wrkdir/space
fi
}
#@ pp_solaris_proto(class) < %files: generate prototype(4) file etc.
pp_solaris_proto () {
typeset t m o g f p st
typeset abi
while read t m o g f p st; do
# Use Solaris default mode, owner and group if all unspecified
if test x"$m$o$g" = x"---"; then
m="?"; o="?"; g="?"
fi
test x"$o" = x"-" && o="root"
case "$t" in
f) test x"$g" = x"-" && g="bin"
test x"$m" = x"-" && m=444
case "$f" in
*v*) echo "v $1 $p=$pp_destdir$p $m $o $g";;
*) echo "f $1 $p=$pp_destdir$p $m $o $g";;
esac
if test -r "$pp_destdir$p"; then
#-- Use file to record ABI types seen
case "`file "$pp_destdir$p"`" in
*"ELF 32"*80386*) abi=i386;;
*"ELF 64"*AMD*) abi=x86_64;;
*"ELF 32"*SPARC*) abi=sparc;;
*"ELF 64"*SPARC*) abi=sparc64;;
*) abi=;;
esac
if test -n "$abi"; then
pp_add_to_list pp_solaris_abis_seen $abi
fi
fi
;;
d) test x"$g" = x"-" && g="sys"
test x"$m" = x"-" && m=555
echo "d $1 $p $m $o $g"
;;
s) test x"$g" = x"-" && g="bin"
test x"$m" = x"-" && m=777
if test x"$m" != x"777" -a x"$m" != x"?"; then
pp_warn "$p: invalid mode $m for symlink, should be 777 or -"
fi
echo "s $1 $p=$st $m $o $g"
;;
esac
done
}
#-- Reads output files from the frontend and generates the single output
# package file under $pp_wrkdir/
pp_backend_solaris () {
typeset _cmp _svc _grp
prototype=$pp_wrkdir/prototype
: > $prototype
pkginfo=$pp_wrkdir/pkginfo
: > $pkginfo
echo "i pkginfo=$pkginfo" >> $prototype
case "${pp_solaris_name:-$name}" in
[0-9]*)
pp_error "Package name '${pp_solaris_name:-$name}'" \
"cannot start with a number"
;;
???????????????*)
pp_warn "Package name '${pp_solaris_name:-$name}'" \
"too long for Solaris 2.6 or 2.7 (max 9 characters)"
;;
??????????*)
pp_warn "Package name '${pp_solaris_name:-$name}'" \
"too long for 2.7 Solaris (max 9 characters)"
;;
esac
#-- generate the package info file
echo "VERSION=$version" >> $pkginfo
echo "PKG=${pp_solaris_name:-$name}" >> $pkginfo
echo "CLASSES=$pp_components" >> $pkginfo
echo "BASEDIR=/" >> $pkginfo
echo "NAME=$name $version" >> $pkginfo
echo "CATEGORY=${pp_solaris_category:-application}" >> $pkginfo
desc="${pp_solaris_desc:-$description}"
test -n "$desc" &&
echo "DESC=$desc" >> $pkginfo
test -n "$pp_solaris_rstates" &&
echo "RSTATES=$pp_solaris_rstates" >> $pkginfo
test -n "$pp_solaris_istates" &&
echo "ISTATES=$pp_solaris_istates" >> $pkginfo
test -n "$pp_solaris_maxinst" &&
echo "MAXINST=$pp_solaris_maxinst" >> $pkginfo
test -n "${pp_solaris_vendor:-$vendor}" &&
echo "VENDOR=${pp_solaris_vendor:-$vendor}" >> $pkginfo
test -n "$pp_solaris_pstamp" &&
echo "PSTAMP=$pp_solaris_pstamp" >> $pkginfo
if test -n "${pp_solaris_copyright:-$copyright}"; then
echo "${pp_solaris_copyright:-$copyright}" > $pp_wrkdir/copyright
echo "i copyright=$pp_wrkdir/copyright" >> $prototype
fi
#-- scripts to run before and after install
: > $pp_wrkdir/postinstall
: > $pp_wrkdir/preremove
: > $pp_wrkdir/postremove
for _cmp in $pp_components; do
#-- add the preinstall scripts in definition order
if test -s $pp_wrkdir/%pre.$_cmp; then
pp_solaris_procedure $_cmp preinst < $pp_wrkdir/%pre.$_cmp \
>> $pp_wrkdir/preinstall
fi
#-- add the postinstall scripts in definition order
if test -s $pp_wrkdir/%post.$_cmp; then
pp_solaris_procedure $_cmp postinst < $pp_wrkdir/%post.$_cmp \
>> $pp_wrkdir/postinstall
fi
#-- add the preremove rules in reverse definition order
if test -s $pp_wrkdir/%preun.$_cmp; then
pp_solaris_procedure $_cmp preremove < $pp_wrkdir/%preun.$_cmp |
pp_prepend $pp_wrkdir/preremove
fi
#-- add the postremove scripts in definition order
if test -s $pp_wrkdir/%postun.$_cmp; then
pp_solaris_procedure $_cmp postremove < $pp_wrkdir/%postun.$_cmp \
>> $pp_wrkdir/postremove
fi
#-- Add the check script in definition order
if test -s $pp_wrkdir/%check.$_cmp; then
pp_solaris_procedure $_cmp checkinstall \
< $pp_wrkdir/%check.$_cmp \
>> $pp_wrkdir/checkinstall
fi
#-- All dependencies and conflicts are merged together for Solaris pkgs
test -s $pp_wrkdir/%depend.$_cmp &&
pp_solaris_depend < $pp_wrkdir/%depend.$_cmp >> $pp_wrkdir/depend
test -s $pp_wrkdir/%conflict.$_cmp &&
pp_solaris_conflict < $pp_wrkdir/%conflict.$_cmp >> $pp_wrkdir/depend
done
if pp_solaris_is_request_script_necessary; then
pp_solaris_request > $pp_wrkdir/request
fi
test -n "$pp_services" &&
for _svc in $pp_services; do
pp_load_service_vars $_svc
pp_solaris_smf $_svc
pp_solaris_make_service $_svc
pp_solaris_install_service $_svc | pp_prepend $pp_wrkdir/postinstall
pp_solaris_remove_service $_svc | pp_prepend $pp_wrkdir/preremove
pp_solaris_remove_service $_svc | pp_prepend $pp_wrkdir/postremove
unset pp_svc_xml_file
done
test -n "$pp_service_groups" &&
for _grp in $pp_service_groups; do
pp_solaris_make_service_group \
$_grp "`pp_service_get_svc_group $_grp`"
done
#-- if installf was used; we need to indicate a termination
grep installf $pp_wrkdir/postinstall >/dev/null &&
echo 'installf -f $PKGINST' >> $pp_wrkdir/postinstall
pp_solaris_sum_space
# NB: pkginfo and copyright are added earlier
for f in compver depend space checkinstall \
preinstall request postinstall \
preremove postremove; do
if test -s $pp_wrkdir/$f; then
case $f in
*install|*remove|request)
# turn scripts into a proper shell scripts
mv $pp_wrkdir/$f $pp_wrkdir/$f.tmp
{ echo "#!/bin/sh";
echo "# $f script for ${pp_solaris_name:-$name}-$version"
cat $pp_wrkdir/$f.tmp
echo "exit 0"; } > $pp_wrkdir/$f
chmod +x $pp_wrkdir/$f
rm -f $pp_wrkdir/$f.tmp
;;
esac
if $pp_opt_debug; then
pp_debug "contents of $f:"
cat $pp_wrkdir/$f >&2
fi
echo "i $f=$pp_wrkdir/$f" >> $prototype
fi
done
#-- create the prototype file which lists the files to install
# do this as late as possible because files could be added
pp_solaris_abis_seen=
for _cmp in $pp_components; do
pp_solaris_proto $_cmp < $pp_wrkdir/%files.$_cmp
done >> $prototype
if test x"$pp_solaris_package_arch" = x"auto"; then
if pp_contains "$pp_solaris_abis_seen" sparc64; then
pp_solaris_package_arch_std="sparc64"
echo "ARCH=sparcv9" >> $pkginfo
elif pp_contains "$pp_solaris_abis_seen" sparc; then
pp_solaris_package_arch_std="sparc"
echo "ARCH=sparc" >> $pkginfo
elif pp_contains "$pp_solaris_abis_seen" x86_64; then
pp_solaris_package_arch_std="x86_64"
echo "ARCH=amd64" >> $pkginfo
elif pp_contains "$pp_solaris_abis_seen" i386; then
pp_solaris_package_arch_std="i386"
echo "ARCH=i386" >> $pkginfo
else
pp_warn "No ELF files found: not supplying an ARCH type"
pp_solaris_package_arch_std="noarch"
fi
else
pp_solaris_package_arch_std="$pp_solaris_package_arch"
echo "ARCH=$pp_solaris_package_arch" >> $pkginfo
fi
mkdir $pp_wrkdir/pkg
. $pp_wrkdir/%fixup
if $pp_opt_debug; then
echo "$pkginfo::"; cat $pkginfo
echo "$prototype::"; cat $prototype
fi >&2
pkgmk -d $pp_wrkdir/pkg -f $prototype \
|| { error "pkgmk failed"; return; }
pkgtrans -s $pp_wrkdir/pkg \
$pp_wrkdir/`pp_backend_solaris_names` \
${pp_solaris_name:-$name} \
|| { error "pkgtrans failed"; return; }
}
#@ pp_backend_solaris_cleanup(): cleanup
pp_backend_solaris_cleanup () {
:
}
#@ pp_backend_solaris_names(): print the name of the package files created
pp_backend_solaris_names () {
echo ${pp_solaris_name:-$name}-$version-${pp_solaris_package_arch_std:-$pp_solaris_arch}.pkg
}
#@ pp_backend_solaris_install_script(): generates a helper install script
pp_backend_solaris_install_script () {
typeset pkgname platform
platform="${pp_solaris_os:-solaris}-${pp_solaris_package_arch_std:-$pp_solaris_arch}"
echo "#! /sbin/sh"
pp_install_script_common
pkgname=`pp_backend_solaris_names`
cat <<.
tmpnocheck=/tmp/nocheck\$\$
tmpresponse=/tmp/response\$\$
trap 'rm -f \$tmpnocheck \$tmpresponse' 0
make_tmpfiles () {
cat <<-.. > \$tmpresponse
CLASSES=\$*
SERVICES=$pp_services
..
cat <<-.. > \$tmpnocheck
mail=
instance=overwrite
partial=nocheck
runlevel=nocheck
idepend=nocheck
rdepend=nocheck
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
basedir=default
..
}
test \$# -eq 0 && usage
op="\$1"; shift
case "\$op" in
list-components)
test \$# -eq 0 || usage \$op
echo "$pp_components"
;;
list-services)
test \$# -eq 0 || usage \$op
echo "$pp_services"
;;
list-files)
test \$# -ge 1 || usage \$op
echo \${PP_PKGDESTDIR:-.}/$pkgname
;;
install)
test \$# -ge 1 || usage \$op
make_tmpfiles "\$@"
verbose /usr/sbin/pkgadd -n -d \${PP_PKGDESTDIR:-.}/$pkgname \
-r \$tmpresponse \
-a \$tmpnocheck \
${pp_solaris_name:-$name}
;;
uninstall)
test \$# -ge 1 || usage \$op
make_tmpfiles "\$@"
verbose /usr/sbin/pkgrm -n \
-a \$tmpnocheck \
${pp_solaris_name:-$name}
;;
start|stop)
test \$# -ge 1 || usage \$op
ec=0
for svc
do
verbose /etc/init.d/\$svc \$op || ec=1
done
exit \$ec
;;
print-platform)
echo "$platform"
;;
*)
usage
;;
esac
.
}
#@ pp_solaris_dynlib_depend(): emits dependency from shared library info
# a list of files should be supplied on stdin. non-executable files
# are ignored. output is a set of dependency lines that should
# be added to %depend.$cpt
pp_solaris_dynlib_depend () {
xargs ldd 2>/dev/null |
sed -e '/^[^ ]*:$/d' -e 's,.*=>[ ]*,,' -e 's,^[ ]*,,' |
sort -u |
grep -v '^/usr/platform/' | (
set -- ""; shift
while read p; do
set -- "$@" -p "$p"
if [ $# -gt 32 ]; then
echo "$# is $#" >&2
pkgchk -l "$@"
set -- ""; shift
fi
done
[ $# -gt 0 ] && pkgchk -l "$@"
)|
awk '/^Current status:/{p=0} p==1 {print $1} /^Referenced by/ {p=1}' |
sort -u |
xargs -l32 pkginfo -x |
awk 'NR % 2 == 1 { name=$1; } NR%2 == 0 { print name, $2 }'
}
#@ pp_solaris_add_dynlib_depends(): creates dependencies for each component
pp_solaris_add_dynlib_depends () {
typeset tmp
tmp=$pp_wrkdir/tmp.dynlib
for _cmp in $pp_components; do
awk '{print destdir $6}' destdir="$pp_destdir" \
< $pp_wrkdir/%files.$_cmp |
pp_solaris_dynlib_depend > $tmp
if test -s $tmp; then
cat $tmp >> $pp_wrkdir/%depend.$_cmp
fi
rm -f $tmp
done
}
#@ pp_backend_solaris_probe(): probe local host type
pp_backend_solaris_probe () {
echo "${pp_solaris_os}-${pp_solaris_arch_std}"
}
#@ pp_backend_solaris_vas_platforms(): print the VAS platform identifiers
pp_backend_solaris_vas_platforms () {
case `pp_backend_solaris_probe` in
sol10-sparc* | sol9-sparc* | sol8-sparc*)
echo solaris8-sparc solaris7-sparc solaris26-sparc;;
sol7-sparc*) echo solaris7-sparc solaris26-sparc;;
sol26-sparc*) echo solaris26-sparc;;
sol8-*86) echo solaris8-x86;;
sol10-*86 | sol10-x86_64)
echo solaris10-x64 solaris8-x86;;
*) pp_die "unknown system `pp_backend_solaris_probe`";;
esac
}