-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpp.back.sd
602 lines (526 loc) · 16.2 KB
/
pp.back.sd
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
# HP-UX's Software Distributor backend
# [1] http://docs.hp.com/en/B2355-90979/ch10.html
pp_platforms="$pp_platforms sd"
#@ pp_backend_sd_detect(uname_s): return true if matches uname on sd
pp_backend_sd_detect () {
test x"$1" = x"HP-UX"
}
#@ pp_backend_sd_init(): initialises platform variables for sd
pp_backend_sd_init () {
pp_sd_sudo=sudo
pp_sd_startlevels=2
pp_sd_stoplevels=auto
pp_sd_config_file=
pp_sd_vendor=
pp_sd_vendor_tag=OneIdentity
pp_sd_default_start=1 # config_file default start value
pp_readlink_fn=pp_ls_readlink # HPUX has no readlink
pp_shlib_suffix='.sl' # .so on most other platforms
pp_sd_detect_os
}
#@ pp_sd_detect_os(): detect and set operating system vars
pp_sd_detect_os () {
typeset revision
revision=`uname -r`
pp_sd_os="${revision#?.}"
test -z "$pp_sd_os" &&
pp_warn "cannot detect OS version"
pp_sd_os_std="hpux`echo $pp_sd_os | tr -d .`"
case "`uname -m`" in
9000/[678]??) pp_sd_arch_std=hppa;;
ia64) pp_sd_arch_std=ia64;;
*) pp_sd_arch_std=unknown;;
esac
}
#@ pp_sd_write_files() <file-list: writes PSF lines for each file
pp_sd_write_files () {
typeset t m o g f p st line dm
while read t m o g f p st; do
line=" file"
case "$f" in *v*) line="$line -v";; esac # FIXME for uninstall
case ${pp_sd_os} in
10.*)
case $t in
f) dm=644;;
d) p=${p%/}; dm=755;;
esac
;;
*)
case $t in
f) dm=644;;
d) line="$line -t d"; p=${p%/}; dm=755;;
s) line="$line -t s";;
esac
;;
esac
test x"$o" = x"-" && o=root
test x"$g" = x"-" && g=sys
test x"$m" = x"-" && m=$dm
case $t in
s)
# swpackage will make unqualified links relative to the
# current working (source) directory, not the destination;
# we need to qualify them to prevent this.
case "$st" in
[!/]*) st="`dirname \"$p\"`/$st";;
esac
echo "$line -o $o -g $g -m $m $st $p"
;;
*)
echo "$line -o $o -g $g -m $m $pp_destdir$p $p"
;;
esac
done
}
#@ pp_sd_service_group_script (grp "svcs"): creates service group script
pp_sd_service_group_script () {
typeset grp svcs scriptpath out
grp="$1"
svcs="$2"
scriptpath="/sbin/init.d/$grp"
out="$pp_destdir$scriptpath"
pp_add_file_if_missing $scriptpath run 755 || return 0
cat <<-. > $out
#!/sbin/sh
# generated by pp $pp_version
svcs="$svcs"
.
cat <<-'.' >> $out
#-- starts services in order.. stops them all if any break
pp_start () {
undo=
for svc in \$svcs; do
/sbin/init.d/\$svc start
case \$? in
0|4)
undo="\$svc \$undo"
;;
*)
if test -n "\$undo"; then
for svc in \$undo; do
/sbin/init.d/\$svc stop
done
return 1
fi
;;
esac
done
return 0
}
#-- stops services in reverse
pp_stop () {
reverse=
for svc in \$svcs; do
reverse="\$svc \$reverse"
done
rc=0
for svc in \$reverse; do
/sbin/init.d/\$svc stop || rc=\$?
done
return \$rc
}
case \$1 in
start_msg) echo "Starting \$svcs";;
stop_msg) echo "Stopping \$svcs";;
start) pp_start;;
stop) pp_stop;;
*) echo "usage: \$0 {start|stop|start_msg|stop_msg}"
exit 1;;
esac
.
}
#@ pp_sd_service_script(svc): creates a service script in the run component
# See rc(1M) for more info
pp_sd_service_script () {
typeset svc config_file config_value scriptpath out
svc="$1"
scriptpath="/sbin/init.d/$svc"
config_file=${pp_sd_config_file:-/etc/rc.config.d/$svc}
sd_config_var=`echo run-$svc | tr '[a-z]-' '[A-Z]_'`
sd_config_value=${pp_sd_default_start:-0}
pp_load_service_vars "$svc"
test -n "$user" -a x"$user" != x"root" &&
cmd="SHELL=/usr/bin/sh /usr/bin/su $user -c \"exec `echo $cmd | sed -e 's,[$\\\`],\\&,g'`\""
if test -z "$pidfile"; then
pidfile="/var/run/$svc.pid"
cmd="$cmd & echo \$! > \$pidfile"
fi
pp_debug "config file is $config_file"
pp_add_file_if_missing $scriptpath run 755
pp_add_file_if_missing $config_file run 644 v
cat <<-. >> $pp_destdir$config_file
# Controls whether the $svc service is started
$sd_config_var=$sd_config_value
.
if test ! -f $pp_destdir$scriptpath; then
cat <<-. > $pp_destdir$scriptpath
#!/sbin/sh
# generated by pp $pp_version
svc="$svc"
pidfile="$pidfile"
config_file="$config_file"
pp_start () {
$cmd
}
pp_disabled () {
test \${$sd_config_var:-0} -eq 0
}
pp_stop () {
if test ! -s "\$pidfile"; then
echo "Unable to stop \$svc (no pid file)"
return 1
else
read pid < "\$pidfile"
if kill -0 "\$pid" 2>/dev/null; then
if kill -${stop_signal:-TERM} "\$pid"; then
rm -f "\$pidfile"
return 0
else
echo "Unable to stop \$svc"
return 1
fi
else
rm -f "\$pidfile"
return 0
fi
fi
}
pp_running () {
if test -s "\$pidfile"; then
read pid < "\$pidfile" 2>/dev/null
if test \${pid:-0} -gt 1 && kill -0 "\$pid" 2>/dev/null; then
# make sure command name matches
c="\`echo $cmd | sed -e 's: .*::' -e 's:^.*/::'\`"
pid="\`ps -p \$pid 2>/dev/null | sed -n \"s/^ *\(\$pid\) .*\$c *\$/\1/p\"\`"
if test -n "\$pid"; then
return 0
fi
fi
fi
return 1
}
case \$1 in
start_msg) echo "Starting the \$svc service";;
stop_msg) echo "Stopping the \$svc service";;
start)
if test -f "\$config_file"; then
. \$config_file
fi
if pp_disabled; then
exit 2
elif pp_running; then
echo "\$svc already running";
exit 0
elif pp_start; then
echo "\$svc started";
# rc(1M) says we should exit 4, but nobody expects it!
exit 0
else
exit 1
fi;;
stop) if pp_stop; then
echo "\$svc stopped";
exit 0
else
exit 1
fi;;
*) echo "usage: \$0 {start|stop|start_msg|stop_msg}"
exit 1;;
esac
.
fi
}
#@ pp_sd_make_service($svc): create the service files and links
pp_sd_make_service () {
typeset level startpriority stoppriority startlevels stoplevels
typeset svc svcvar symtype
svc="$1"
svcvar=`pp_makevar $svc`
case ${pp_sd_os} in
10.*) symtype="file";;
*) symtype="file -t s";;
esac
# TODO: Figure out why this check is here
#-- don't do anything if the script exists
#if test -s "$pp_destdir/sbin/init.d/$svc"; then
# pp_error "$pp_destdir/sbin/init.d/$svc exists"
# return
#fi
# symlink the script, depending on the priorities chosen
eval startpriority='${pp_sd_startpriority_'$svcvar'}'
eval stoppriority='${pp_sd_stoppriority_'$svcvar'}'
test -z "$startpriority" && startpriority="${pp_sd_startpriority:-50}"
test -z "$stoppriority" && stoppriority="${pp_sd_stoppriority:-50}"
eval startlevels='${pp_sd_startlevels_'$svcvar'}'
test -z "$startlevels" && startlevels="$pp_sd_startlevels"
eval stoplevels='${pp_sd_stoplevels_'$svcvar'}'
test -z "$stoplevels" && stoplevels="$pp_sd_stoplevels"
# create the script and config file
pp_sd_service_script $svc
# fix the priority up
case "$startpriority" in
???) :;;
??) startpriority=0$startpriority;;
?) startpriority=00$startpriority;;
esac
case "$stoppriority" in
???) :;;
??) stoppriority=0$stoppriority;;
?) stoppriority=00$stoppriority;;
esac
if test x"$stoplevels" = x"auto"; then
stoplevels=
test -z "$startlevels" || for level in $startlevels; do
stoplevels="$stoplevels `expr $level - 1`"
done
fi
# create the symlinks
test -z "$startlevels" || for level in $startlevels; do
echo " ${symtype}" \
"/sbin/init.d/$svc" \
"/sbin/rc$level.d/S$startpriority$svc"
done
test -z "$stoplevels" || for level in $stoplevels; do
echo " ${symtype}" \
"/sbin/init.d/$svc" \
"/sbin/rc$level.d/K$stoppriority$svc"
done
}
#@ pp_sd_control (name files...) creates and emits a control script
# based on section "Control Script Format" in [1]
pp_sd_control () {
typeset ctrl script
typeset cpt
ctrl="$1"; shift
cpt="$1"; shift
script="$pp_wrkdir/control.$ctrl.$cpt"
cat <<. >$script
#! /sbin/sh
########
# Product: $name
# $ctrl
# Generated from $pp_opt_input by pp
########
#
# ${copyright:-(no copyright information)}
#
########
.
cat "$@" >> $script
echo "exit 0" >> $script
/usr/bin/chmod +x $script
echo " $ctrl $script"
}
#@ pp_sd_depend(): generate prerequisite fileset entries
pp_sd_depend () {
typeset _name _vers
while read _name _vers; do
case "$_name" in ""| "#"*) continue ;; esac
echo " prerequisites $_name ${_vers:+r>= $_vers}"
done
}
#@ pp_sd_conflict(): generate exrequisite fileset entries
pp_sd_conflict () {
typeset _name _vers
while read _name _vers; do
case "$_name" in ""| "#"*) continue ;; esac
echo " exrequisites $_name ${_vers:+r>= $_vers}"
done
}
#@ pp_backend_sd(): processes output files to generate a package files
pp_backend_sd () {
typeset psf cpt svc outfile release swp_flags
psf=$pp_wrkdir/psf
release="?.${pp_sd_os%.[0-9][0-9]}.*"
echo "depot" > $psf
echo "layout_version 1.0" >>$psf
#-- vendor
cat <<. >>$psf
vendor
tag $pp_sd_vendor_tag
title "${pp_sd_vendor:-$vendor}"
end
product
tag $name
revision $version
vendor_tag $pp_sd_vendor_tag
is_patch false
title "$summary"
copyright "$copyright"
machine_type *
os_name HP-UX
os_release $release
os_version ?
directory /
is_locatable false
.
test -n "$description" \
&& echo $description > $pp_wrkdir/description \
&& cat <<. >> $psf
description < $pp_wrkdir/description
.
# make convenience service groups
if test -n "$pp_service_groups"; then
for grp in $pp_service_groups; do
pp_sd_service_group_script \
$grp "`pp_service_get_svc_group $grp`"
done
fi
for cpt in $pp_components; do
cat <<. >>$psf
fileset
tag ${pp_sd_fileset_tag:-$cpt}
title "${summary:-cpt}"
revision $version
.
test -s $pp_wrkdir/%depend.$cpt &&
pp_sd_depend < $pp_wrkdir/%depend.$cpt >> $psf
test -s $pp_wrkdir/%conflict.$cpt &&
pp_sd_conflict < $pp_wrkdir/%conflict.$cpt >> $psf
#-- make sure services are shut down during uninstall
if test $cpt = run -a -n "$pp_services"; then
for svc in $pp_services; do
pp_prepend $pp_wrkdir/%preun.$cpt <<-.
/sbin/init.d/$svc stop
.
done
fi
#-- we put the post/preun code into configure/unconfigure
# and not postinstall/preremove, because configure/unconfigure
# scripts are run on the hosts where the package is installed,
# not loaded (a subtle difference).
test -s $pp_wrkdir/%pre.$cpt &&
pp_sd_control checkinstall $cpt $pp_wrkdir/%pre.$cpt >> $psf
test -s $pp_wrkdir/%post.$cpt &&
pp_sd_control configure $cpt $pp_wrkdir/%post.$cpt >> $psf
test -s $pp_wrkdir/%preun.$cpt &&
pp_sd_control unconfigure $cpt $pp_wrkdir/%preun.$cpt >> $psf
test -s $pp_wrkdir/%postun.$cpt &&
pp_sd_control postremove $cpt $pp_wrkdir/%postun.$cpt >> $psf
test -s $pp_wrkdir/%check.$cpt &&
pp_sd_control checkinstall $cpt $pp_wrkdir/%check.$cpt >> $psf
if test $cpt = run -a -n "$pp_services"; then
for svc in $pp_services; do
#-- service names are 10 chars max on hpux
case "$svc" in ???????????*)
pp_warn "service name '$svc' is too long for hpux";;
esac
pp_sd_make_service $svc >> $psf
done
#pp_sd_make_service_config
fi
pp_sd_write_files < $pp_wrkdir/%files.$cpt >> $psf
#-- end fileset clause
cat <<. >>$psf
end
.
done
#-- end product clause
cat <<. >>$psf
end
.
$pp_opt_debug && cat $psf >&2
test -s $pp_wrkdir/%fixup && . $pp_wrkdir/%fixup
outfile=`pp_backend_sd_names`
case ${pp_sd_os} in
10.*)
swp_flags="-x target_type=tape"
;;
*)
swp_flags="-x media_type=tape"
;;
esac
if pp_verbose ${pp_sd_sudo} /usr/sbin/swpackage -s $psf $swp_flags \
@ $pp_wrkdir/$outfile
then
pp_verbose ${pp_sd_sudo} /usr/sbin/swlist -l file -s $pp_wrkdir/$outfile
else
pp_error "swpackage failed"
fi
}
#@ pp_backend_sd_cleanup(): removes any files created outside $pp_wrkdir
pp_backend_sd_cleanup () {
:
}
#@ pp_backend_sd_names(): prints the paths to package files
# each path should start with $name-$version
# the package must be relative to the $pp_wrkdir directory
pp_backend_sd_names () {
echo "$name-$version.$pp_sd_arch_std.depot"
}
#@ pp_backend_sd_install_script(): generate a helper install script
pp_backend_sd_install_script () {
typeset pkgname platform
pkgname=`pp_backend_sd_names`
platform="`pp_backend_sd_probe`"
echo "#!/bin/sh"
pp_install_script_common
cat <<.
cpt_to_tags () {
test x"\$*" = x"all" && set -- $pp_components
for cpt
do
echo "$name.\$cpt"
done
}
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
verbose /usr/sbin/swinstall -x verbose=0 \
-s \${PP_PKGDESTDIR:-\`pwd\`}/$pkgname \
\`cpt_to_tags "\$@"\`
;;
uninstall)
test \$# -ge 1 || usage \$op
verbose /usr/sbin/swremove -x verbose=0 \
\`cpt_to_tags "\$@"\`
;;
start|stop)
test \$# -ge 1 || usage \$op
ec=0
for svc
do
verbose /sbin/init.d/\$svc \$op
[ \$? -eq 4 -o \$? -eq 0 ] || ec=1
done
exit \$ec
;;
print-platform)
echo "$platform"
;;
*)
usage
;;
esac
.
}
#@ pp_backend_sd_probe() : detect local platform name
pp_backend_sd_probe () {
echo "${pp_sd_os_std}-${pp_sd_arch_std}"
}
#@ pp_backend_sd_vas_platforms() : print the equivalent VAS platforms
pp_backend_sd_vas_platforms () {
case "`pp_backend_sd_probe`" in
hpux*-hppa) echo hpux-pa;;
hpux*-ia64) echo hpux-ia64 hpux-pa;;
*) pp_die "unknown system `pp_backend_sd_probe`";;
esac
}
#@ pp_backend_sd_init_svc_vars(): initialise service vars
pp_backend_sd_init_svc_vars () {
:
}