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

Contents of /trunk/pp.back.sd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 229 - (show annotations)
Tue Oct 27 20:24:32 2009 UTC (3 weeks, 4 days ago) by rcweb
File size: 14822 byte(s)
Solaris no /etc/rc?.d/*quest-sshd fix, and label the HP packages a little better. 
1 # HP-UX's Software Distributor backend
2 # [1] http://docs.hp.com/en/B2355-90979/ch10.html
3
4 pp_platforms="$pp_platforms sd"
5
6 #@ pp_backend_sd_detect(uname_s): return true if matches uname on sd
7 pp_backend_sd_detect () {
8 test x"$1" = x"HP-UX"
9 }
10
11 #@ pp_backend_sd_init(): initialises platform variables for sd
12 pp_backend_sd_init () {
13 pp_sd_sudo=sudo # FIXME: argh why is hpux so braindead
14 pp_sd_startlevels=2
15 pp_sd_stoplevels=auto
16 pp_sd_config_file=
17 pp_sd_default_start=1 # config_file default start value
18
19 pp_readlink_fn=pp_ls_readlink # HPUX has no readlink
20
21 pp_sd_detect_os
22 }
23
24 #@ pp_sd_detect_os(): detect and set operating system vars
25 pp_sd_detect_os () {
26 typeset revision
27
28 revision=`uname -r`
29 pp_sd_os="${revision#?.}"
30 test -z "$pp_sd_os" &&
31 pp_warn "cannot detect OS version"
32 pp_sd_os_std="hpux`echo $pp_sd_os | tr -d .`"
33
34 case "`uname -m`" in
35 9000/[678]??) pp_sd_arch_std=hppa;;
36 ia64) pp_sd_arch_std=ia64;;
37 *) pp_sd_arch_std=unknown;;
38 esac
39 }
40
41 #@ pp_sd_write_files() <file-list: writes PSF lines for each file
42 pp_sd_write_files () {
43 typeset t m o g f p st line dm
44 while read t m o g f p st; do
45 line=" file"
46 case "$f" in *v*) line="$line -v";; esac # FIXME for uninstall
47 case $t in
48 f) dm=644;;
49 d) line="$line -t d"; p=${p%/}; dm=755;;
50 s) line="$line -t s";;
51 esac
52
53 test x"$o" = x"-" && o=bin
54 test x"$g" = x"-" && g=bin
55 test x"$m" = x"-" && m=$dm
56
57 case $t in
58 s) echo "$line $st $p";;
59 *) echo "$line -o $o -g $g -m $m $pp_destdir$p $p";;
60 esac
61
62 done
63 }
64
65 #@ pp_sd_service_group_script (grp "svcs"): creates service group script
66 pp_sd_service_group_script () {
67 typeset grp svcs scriptpath out
68 grp="$1"
69 svcs="$2"
70 scriptpath="/sbin/init.d/$grp"
71 out="$pp_destdir$scriptpath"
72
73 pp_add_file_if_missing $scriptpath run 755 || return 0
74
75 cat <<-. > $out
76 #!/sbin/sh
77 # generated by pp $pp_version
78 svcs="$svcs"
79 .
80
81 cat <<-'.' >> $out
82 #-- starts services in order.. stops them all if any break
83 pp_start () {
84 undo=
85 for svc in $svcs; do
86 /sbin/init.d/$svc start
87 case $? in
88 0|4)
89 undo="$svc $undo"
90 ;;
91 *)
92 if test -n "$undo"; then
93 for svc in $undo; do
94 /sbin/init.d/$svc stop
95 done
96 return 1
97 fi
98 ;;
99 esac
100 done
101 return 0
102 }
103
104 #-- stops services in reverse
105 pp_stop () {
106 reverse=
107 for svc in $svcs; do
108 reverse="$svc $reverse"
109 done
110 rc=0
111 for svc in $reverse; do
112 /sbin/init.d/$svc stop || rc=$?
113 done
114 return $rc
115 }
116
117 case $1 in
118 start_msg) echo "Starting $svcs";;
119 stop_msg) echo "Stopping $svcs";;
120 start) pp_start;;
121 stop) pp_stop;;
122 *) echo "usage: $0 {start|stop|start_msg|stop_msg}"
123 exit 1;;
124 esac
125 .
126 }
127
128 #@ pp_sd_service_script(svc): creates a service script in the run component
129 # See rc(1M) for more info
130 pp_sd_service_script () {
131 typeset svc config_file config_value scriptpath out
132
133 svc="$1"
134 scriptpath="/sbin/init.d/$svc"
135
136 config_file=${pp_sd_config_file:-/etc/rc.config.d/$name}
137 sd_config_var=`echo start-$svc | tr '[a-z]-' '[A-Z]_'`
138 sd_config_value=${pp_sd_default_start:-0}
139 pp_load_service_vars "$svc"
140
141 test -n "$user" -a x"$user" != x"root" &&
142 cmd="SHELL=/usr/bin/sh /usr/bin/su $user -c \"exec `echo $cmd | sed -e 's,[$\\\`],\\&,g'`\""
143 if test -z "$pidfile"; then
144 pidfile="/var/run/$svc.pid"
145 cmd="$cmd & echo \$! > \$pidfile"
146 fi
147
148 pp_debug "config file is $config_file"
149
150 pp_add_file_if_missing $scriptpath run 755
151 pp_add_file_if_missing $config_file run 644 v
152
153 cat <<-. >> $pp_destdir$config_file
154
155 # Controls whether the $svc service is started
156 $sd_config_var=$sd_config_value
157 .
158
159 cat <<. > $pp_destdir$scriptpath
160 #!/sbin/sh
161 # generated by pp $pp_version
162
163 svc="$svc"
164 pidfile="$pidfile"
165 config_file="$config_file"
166
167 pp_start () {
168 $cmd
169 }
170
171 pp_disabled () {
172 test \${$sd_config_var:-0} -eq 0
173 }
174
175 .
176
177 cat <<'.' >>$pp_destdir$scriptpath
178
179 pp_stop () {
180 if test ! -s "$pidfile"; then
181 echo "Unable to stop $svc (no pid file)"
182 return 1
183 else
184 read pid < "$pidfile"
185 if kill -0 "$pid" 2>/dev/null; then
186 if kill -${stop_signal:-TERM} "$pid"; then
187 rm -f "$pidfile"
188 return 0
189 else
190 echo "Unable to stop $svc"
191 return 1
192 fi
193 else
194 rm -f "$pidfile"
195 return 0
196 fi
197 fi
198 }
199
200 pp_running () {
201 if test ! -s "$pidfile"; then
202 return 1
203 else
204 read pid < "$pidfile"
205 kill -0 "$pid" 2>/dev/null
206 fi
207 }
208
209 case $1 in
210 start_msg) echo "Starting the $svc service";;
211 stop_msg) echo "Stopping the $svc service";;
212 start)
213 if test -f "$config_file"; then
214 . $config_file
215 fi
216 if pp_disabled; then
217 exit 2
218 elif pp_running; then
219 echo "$svc already running";
220 exit 0
221 elif pp_start; then
222 echo "$svc started";
223 # rc(1M) says we should exit 4, but nobody expects it!
224 exit 0
225 else
226 exit 1
227 fi;;
228 stop) if pp_stop; then
229 echo "$svc stopped";
230 exit 0
231 else
232 exit 1
233 fi;;
234 *) echo "usage: $0 {start|stop|start_msg|stop_msg}"
235 exit 1;;
236 esac
237 .
238 }
239
240 #@ pp_sd_make_service($svc): create the service files and links
241 pp_sd_make_service () {
242 typeset level startpriority stoppriority startlevels stoplevels
243 typeset svc svcvar
244
245 svc="$1"
246 svcvar=`pp_makevar $svc`
247
248 # TODO: Figure out why this check is here
249 #-- don't do anything if the script exists
250 #if test -s "$pp_destdir/sbin/init.d/$svc"; then
251 # pp_error "$pp_destdir/sbin/init.d/$svc exists"
252 # return
253 #fi
254
255 # symlink the script, depending on the priorities chosen
256 eval startpriority='${pp_sd_startpriority_'$svcvar'}'
257 eval stoppriority='${pp_sd_stoppriority_'$svcvar'}'
258 test -z "$startpriority" && startpriority="${pp_sd_startpriority:-50}"
259 test -z "$stoppriority" && stoppriority="${pp_sd_stoppriority:-50}"
260
261 eval startlevels='${pp_sd_startlevels_'$svcvar'}'
262 test -z "$startlevels" && startlevels="$pp_sd_startlevels"
263
264 eval stoplevels='${pp_sd_stoplevels_'$svcvar'}'
265 test -z "$stoplevels" && stoplevels="$pp_sd_stoplevels"
266
267 # create the script and config file
268 pp_sd_service_script $svc
269
270 # fix the priority up
271 case "$startpriority" in
272 ???) :;;
273 ??) startpriority=0$startpriority;;
274 ?) startpriority=00$startpriority;;
275 esac
276 case "$stoppriority" in
277 ???) :;;
278 ??) stoppriority=0$stoppriority;;
279 ?) stoppriority=00$stoppriority;;
280 esac
281
282 if test x"$stoplevels" = x"auto"; then
283 stoplevels=
284 test -z "$startlevels" || for level in $startlevels; do
285 stoplevels="$stoplevels `expr $level - 1`"
286 done
287 fi
288
289 # create the symlinks
290 test -z "$startlevels" || for level in $startlevels; do
291 echo " file -t s" \
292 "/sbin/init.d/$svc" \
293 "/sbin/rc$level.d/S$startpriority$svc"
294 done
295 test -z "$stoplevels" || for level in $stoplevels; do
296 echo " file -t s" \
297 "/sbin/init.d/$svc" \
298 "/sbin/rc$level.d/K$stoppriority$svc"
299 done
300 }
301
302 #@ pp_sd_control (name files...) creates and emits a control script
303 # based on section "Control Script Format" in [1]
304 pp_sd_control () {
305 typeset ctrl script
306 typeset cpt
307
308 ctrl="$1"; shift
309 cpt="$1"; shift
310 script="$pp_wrkdir/control.$ctrl.$cpt"
311 cat <<. >$script
312 #! /sbin/sh
313 ########
314 # Product: $name
315 # $ctrl
316 # Generated from $pp_opt_input by pp
317 ########
318 #
319 # ${copyright:-(no copyright information)}
320 #
321 ########
322 .
323 cat "$@" >> $script
324 echo "exit 0" >> $script
325 /usr/bin/chmod +x $script
326 echo " $ctrl $script"
327 }
328
329 #@ pp_backend_sd(): processes output files to generate a package files
330 pp_backend_sd () {
331 typeset psf cpt svc outfile
332
333 psf=$pp_wrkdir/psf
334
335 echo "depot" > $psf
336 echo "layout_version 1.0" >>$psf
337
338 #-- vendor
339 cat <<. >>$psf
340 vendor
341 tag Quest
342 title Quest Software, Inc.
343
344 product
345 tag $name
346 revision $version
347 vendor_tag Quest
348 is_patch false
349 title "$summary"
350 copyright "$copyright"
351 machine_type *
352 os_name HP-UX
353 os_release ?.11.*
354 os_version ?
355 directory /
356 is_locatable false
357 .
358 test -n "$description" && cat <<. >>$psf
359 description "$description"
360 .
361
362 # make convenience service groups
363 if test -n "$pp_service_groups"; then
364 for grp in $pp_service_groups; do
365 pp_sd_service_group_script \
366 $grp "`pp_service_get_svc_group $grp`"
367 done
368 fi
369
370 for cpt in $pp_components; do
371 cat <<. >>$psf
372 fileset
373 tag $cpt
374 title $cpt
375 .
376
377 #-- make sure services are shut down during uninstall
378 if test $cpt = run -a -n "$pp_services"; then
379 for svc in $pp_services; do
380 pp_prepend $pp_wrkdir/%preun.$cpt <<-.
381 /sbin/init.d/$svc stop
382 .
383 done
384 fi
385
386 #-- we put the post/preun code into configure/unconfigure
387 # and not postinstall/preremove, because configure/unconfigure
388 # scripts are run on the hosts where the package is installed,
389 # not loaded (a subtle difference).
390 test -s $pp_wrkdir/%post.$cpt &&
391 pp_sd_control configure $cpt $pp_wrkdir/%post.$cpt >> $psf
392 test -s $pp_wrkdir/%preun.$cpt &&
393 pp_sd_control unconfigure $cpt $pp_wrkdir/%preun.$cpt >> $psf
394 test -s $pp_wrkdir/%check.$cpt &&
395 pp_sd_control checkinstall $cpt $pp_wrkdir/%check.$cpt >> $psf
396
397 if test $cpt = run -a -n "$pp_services"; then
398 for svc in $pp_services; do
399 #-- service names are 10 chars max on hpux
400 case "$svc" in ???????????*)
401 pp_warn "service name '$svc' is too long for hpux";;
402 esac
403 pp_sd_make_service $svc >> $psf
404 done
405 #pp_sd_make_service_config
406 fi
407
408 pp_sd_write_files < $pp_wrkdir/%files.$cpt >> $psf
409
410 #-- end fileset clause
411 cat <<. >>$psf
412 end
413 .
414
415 done
416
417 #-- end product clause
418 cat <<. >>$psf
419 end
420 .
421
422 $pp_opt_debug && cat $psf >&2
423
424 test -s $pp_wrkdir/%fixup && . $pp_wrkdir/%fixup
425
426 outfile=`pp_backend_sd_names`
427 if pp_verbose ${pp_sd_sudo} /usr/sbin/swpackage \
428 -s $psf \
429 -x run_as_superuser=false \
430 -x media_type=tape \
431 @ $pp_wrkdir/$outfile
432 then
433 pp_verbose ${pp_sd_sudo} /usr/sbin/swlist -l file -s $pp_wrkdir/$outfile
434 else
435 pp_error "swpackage failed"
436 fi
437 }
438
439 #@ pp_backend_sd_cleanup(): removes any files created outside $pp_wrkdir
440 pp_backend_sd_cleanup () {
441 :
442 }
443
444 #@ pp_backend_sd_names(): prints the paths to package files
445 # each path should start with $name-$version
446 # the package must be relative to the $pp_wrkdir directory
447 pp_backend_sd_names () {
448 echo "$name-$version.$pp_sd_arch_std.depot"
449 }
450
451 #@ pp_backend_sd_install_script(): generate a helper install script
452 pp_backend_sd_install_script () {
453 typeset pkgname platform
454
455 pkgname=`pp_backend_sd_names`
456 platform="`pp_backend_sd_probe`"
457
458 echo "#!/bin/sh"
459 pp_install_script_common
460 cat <<.
461
462 cpt_to_tags () {
463 test x"\$*" = x"all" && set -- $pp_components
464 for cpt
465 do
466 echo "$name.\$cpt"
467 done
468 }
469
470 test \$# -eq 0 && usage
471 op="\$1"; shift
472
473 case "\$op" in
474 list-components)
475 test \$# -eq 0 || usage \$op
476 echo "$pp_components"
477 ;;
478 list-services)
479 test \$# -eq 0 || usage \$op
480 echo "$pp_services"
481 ;;
482 list-files)
483 test \$# -ge 1 || usage \$op
484 echo \${PP_PKGDESTDIR:-.}/$pkgname
485 ;;
486 install)
487 test \$# -ge 1 || usage \$op
488 verbose /usr/sbin/swinstall -x verbose=0 \
489 -s \${PP_PKGDESTDIR:-\`pwd\`}/$pkgname \
490 \`cpt_to_tags "\$@"\`
491 ;;
492 uninstall)
493 test \$# -ge 1 || usage \$op
494 verbose /usr/sbin/swremove -x verbose=0 \
495 \`cpt_to_tags "\$@"\`
496 ;;
497 start|stop)
498 test \$# -ge 1 || usage \$op
499 ec=0
500 for svc
501 do
502 verbose /sbin/init.d/\$svc \$op
503 [ \$? -eq 4 -o \$? -eq 0 ] || ec=1
504 done
505 exit \$ec
506 ;;
507 print-platform)
508 echo "$platform"
509 ;;
510 *)
511 usage
512 ;;
513 esac
514 .
515 }
516
517 #@ pp_backend_sd_probe() : detect local platform name
518 pp_backend_sd_probe () {
519 echo "${pp_sd_os_std}-${pp_sd_arch_std}"
520 }
521
522 #@ pp_backend_sd_vas_platforms() : print the equivalent VAS platforms
523 pp_backend_sd_vas_platforms () {
524 case "`pp_backend_sd_probe`" in
525 hpux*-hppa) echo hpux-pa;;
526 hpux*-ia64) echo hpux-ia64 hpux-pa;;
527 *) pp_die "unknown system `pp_backend_sd_probe`";;
528 esac
529 }
530
531 #@ pp_backend_sd_init_svc_vars(): initialise service vars
532 pp_backend_sd_init_svc_vars () {
533 :
534 }

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