Annotation of embedaddon/sudo/pp, revision 1.1.1.2
1.1 misho 1: #!/bin/sh
1.1.1.2 ! misho 2: # Copyright 2012 Quest Software, Inc. ALL RIGHTS RESERVED
! 3: pp_revision="355"
! 4: # Copyright 2012 Quest Software, Inc. ALL RIGHTS RESERVED.
1.1 misho 5: #
6: # Redistribution and use in source and binary forms, with or without
7: # modification, are permitted provided that the following conditions
8: # are met:
9: #
10: # 1. Redistributions of source code must retain the above copyright
11: # notice, this list of conditions and the following disclaimer.
12: # 2. Redistributions in binary form must reproduce the above copyright
13: # notice, this list of conditions and the following disclaimer in the
14: # documentation and/or other materials provided with the distribution.
15: # 3. Neither the name of Quest Software, Inc. nor the names of its
16: # contributors may be used to endorse or promote products derived from
17: # this software without specific prior written permission.
18: #
19: # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20: # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21: # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22: # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23: # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24: # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25: # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26: # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27: # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28: # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29: # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30:
31: # Please see <http://rc.quest.com/topics/polypkg/> for more information
32:
33: pp_version="1.0.0.$pp_revision"
1.1.1.2 ! misho 34: pp_copyright="Copyright 2012, Quest Software, Inc. ALL RIGHTS RESERVED."
1.1 misho 35:
36: pp_opt_debug=false
37: pp_opt_destdir="$DESTDIR"
38: pp_opt_install_script=
39: pp_opt_list=false
40: pp_opt_no_clean=false
41: pp_opt_no_package=false
42: pp_opt_only_front=false
43: pp_opt_platform=
44: pp_opt_probe=false
45: pp_opt_strip=false
46: pp_opt_save_unstripped=false
47: pp_opt_vas_platforms=false
48: pp_opt_wrkdir="`pwd`/pp.work.$$"
49: pp_opt_verbose=false
50: pp_opt_version=false
51: pp_opt_input="-"
52: pp_opt_init_vars=""
53: pp_opt_eval=
54:
55: test -n "$PP_NO_CLEAN" && pp_opt_no_clean=true
56: test -n "$PP_DEBUG" && pp_opt_debug=true
57: test -n "$PP_VERBOSE" && pp_opt_verbose=true
58:
59: pp_main_cleanup () {
60: pp_debug "main_cleanup"
61: pp_remove_later_now
62: if $pp_opt_no_clean || test x"$pp_platform" = x"unknown"; then
63: : no cleanup
64: else
65: pp_backend_${pp_platform}_cleanup
66: $pp_errors && pp_die "Errors during cleanup"
67: if test -d "$pp_wrkdir"; then
68: if $pp_opt_debug; then
69: pp_debug "not removing $pp_wrkdir"
70: else
71: pp_verbose rm -rf "$pp_wrkdir"
72: fi
73: fi
74: fi
75: }
76:
77: pp_parseopts () {
78: typeset a n _var _val
79: while test $# -gt 0; do
80:
81: # convert -[dilpv] to --long-options
82: case "$1" in
83: --?*=?*) n=`echo "$1" | sed -ne 's/^--\([^=]*\)=.*/\1/p'`
84: a=`echo "$1" | sed -ne 's/^--[^=]*=\(.*\)/\1/p'`
85: shift
86: set -- "--$n" "$a" "$@";;
87: --?*) : ;;
88:
89: -d) shift; set -- "--debug" "$@";;
90: -d*) a=`echo "$1" | sed -ne 's/^-.//'`
91: shift; set -- "--debug" "$@";;
92:
93: -i) shift; set -- "--install-script" "$@";;
94: -i*) a=`echo "$1" | sed -ne 's/^-.//'`
95: shift; set -- "--install-script" "$a" "$@";;
96:
97: -l) shift; set -- "--list" "$@";;
98: -l*) a=`echo "$1" | sed -ne 's/^-.//'`
99: shift; set -- "--list" "$@";;
100:
101: -p) shift; set -- "--platform" "$@";;
102: -p*) a=`echo "$1" | sed -ne 's/^-.//'`
103: shift; set -- "--platform" "$a" "$@";;
104:
105: -v) shift; set -- "--verbose" "$@";;
106: -v*) a=`echo "$1" | sed -ne 's/^-.//'`
107: shift; set -- "--verbose" "$@";;
108:
109: -\?) shift; set -- "--help" "$@";;
110: -\?*) a=`echo "$1" | sed -ne 's/^-.//'`
111: shift; set -- "--help" "$@";;
112: esac
113:
114: case "$1" in
115: --destdir|--eval|--install-script|--platform|--wrkdir)
116: test $# -ge 2 || pp_error "missing argument to $1";;
117: esac
118:
119: case "$1" in
120: --) shift;break;;
121: --debug) pp_opt_debug=true; shift;;
122: --destdir) pp_opt_destdir="$2"; shift;shift;;
123: --eval) pp_opt_eval="$2"; shift;shift;; # undoc
124: --install-script) pp_opt_install_script="$2"; shift;shift;;
125: --list) pp_opt_list=true; shift;;
126: --no-clean) pp_opt_no_clean=true; shift;;
127: --no-package) pp_opt_no_package=true; shift;;
128: --only-front) pp_opt_only_front=true; shift;;
129: --platform) pp_opt_platform="$2"; shift;shift;;
130: --probe) pp_opt_probe=true; shift;;
131: --strip) pp_opt_strip=true; shift;;
132: --save-unstripped) pp_opt_save_unstripped=true; shift;;
133: --wrkdir) pp_opt_wrkdir="$2"; shift;shift;;
134: --vas-platforms) pp_opt_vas_platforms=true; shift;;
135: --verbose) pp_opt_verbose=true; shift;;
136: --version) pp_opt_version=true; shift;;
137: --help) pp_errors=true; shift;;
138: -) break;;
139: -*) pp_error "unknown option $1"; shift;;
140: *) break;;
141: esac
142:
143: done
144:
145: pp_opt_input=-
146: if test $# -gt 0; then
147: pp_opt_input="$1"
148: shift
149: fi
150:
151: #-- extra arguments of the form Foo=bar alter *global* vars
152: while test $# -gt 0; do
153: case "$1" in
154: -*) pp_error "unexpected option '$1'"
155: shift;;
156: *=*) _val="${1#*=}"
157: _var=${1%="$_val"}
158: _val=`echo "$_val"|sed -e 's/[$"\\]/\\&/g'`
159: pp_debug "setting $_var = \"$_val\""
160: pp_opt_init_vars="$pp_opt_init_vars$_var=\"$_val\";"
161: shift;;
162: *) pp_error "unexpected argument $1'"
163: shift;;
164: esac
165: done
166:
167: test $# -gt 0 &&
168: pp_error "unknown argument $1"
169:
170: if $pp_errors; then
171: cat <<. >&2
172: polypkg $pp_version $pp_copyright
173: usage: $0 [options] [input.pp] [var=value ...]
174: -d --debug -- write copious info to stderr
175: --destdir=path -- file root, defaults to \$DESTDIR
176: -? --help -- display this information
177: -i --install-script=path -- create an install helper script
178: -l --list -- write package filenames to stdout
179: --no-clean -- don't remove temporary files
180: --no-package -- do everything but create packages
181: --only-front -- only perform front-end actions
182: -p --platform=platform -- defaults to local platform
183: --probe -- print local system identifier, then exit
184: --strip -- strip debug symbols from binaries before
185: packaging (modifies files in destdir)
186: --save-unstripped -- save unstripped binaries to
187: \$name-\$version-unstripped.tar.gz
188: --wrkdir=path -- defaults to subdirectory of \$TMPDIR or /tmp
189: -v --verbose -- write info to stderr
190: --version -- display version and quit
191: .
192: exit 1
193: fi
194: }
195:
196: pp_drive () {
197: # initialise the front and back ends
198: pp_model_init
199: pp_frontend_init
200: $pp_opt_only_front || pp_backend_init
201:
202: # run the front-end to generate the intermediate files
203: # set $pp_input_dir to be the 'include dir' if needed
204: pp_debug "calling frontend on $pp_opt_input"
205: case "$pp_opt_input" in
206: -) pp_input_dir=.
207: test -t 1<&0 &&
208: pp_warn "reading directives from standard input"
209: pp_frontend
210: ;;
211: */*) pp_input_dir=${pp_opt_input%/*}
212: pp_frontend <"$pp_opt_input"
213: ;;
214: *) pp_input_dir=.
215: pp_frontend <"$pp_opt_input"
216: ;;
217: esac
218:
219: pp_files_ignore_others
220: pp_service_scan_groups
221:
222: # some sanity checks after front-end processing
223: if test x"$pp_platform" != x"null"; then
224: pp_debug "sanity checks"
225: test -n "$pp_components" || pp_error "No components?"
226: pp_check_var_is_defined "name"
227: pp_check_var_is_defined "version"
228: pp_files_check_duplicates
229: pp_files_check_coverage
230: pp_die_if_errors "Errors during sanity checks"
231: fi
232:
233: # stop now if we're only running the front
234: $pp_opt_only_front && return
235:
236: if test x"$pp_opt_strip" = x"true"; then
237: pp_strip_binaries
238: fi
239:
240: # run the back-end to generate the package
241: pp_debug "calling backend"
242: pp_backend
243: pp_die_if_errors "Errors during backend processing"
244:
245: # copy the resulting package files to PP_PKGDESTDIR or .
246: for f in `pp_backend_names` -; do
247: test x"$f" = x"-" && continue
248: pp_debug "copying: $f to `pwd`"
249: if pp_verbose cp -r $pp_wrkdir/$f ${PP_PKGDESTDIR:-.}; then
250: echo "${PP_PKGDESTDIR:+$PP_PKGDESTDIR/}$f"
251: else
252: pp_error "$f: missing package"
253: fi
254: done
255: pp_die_if_errors "Errors during package copying"
256: }
257:
258: pp_install_script () {
259: pp_debug "writing install script to $pp_opt_install_script"
260: rm -f $pp_opt_install_script
261: pp_backend_install_script > $pp_opt_install_script
262: pp_die_if_errors "Errors during package install script"
263: chmod +x $pp_opt_install_script
264: }
265:
266: pp_main () {
267: # If PP_DEV_PATH is set, then jump to that script.
268: # (Useful when working on polypkg source that isn't installed)
269: if test -n "$PP_DEV_PATH" -a x"$PP_DEV_PATH" != x"$0"; then
270: pp_warn "switching from $0 to $PP_DEV_PATH ..."
271: exec "$PP_DEV_PATH" "$@" || exit 1
272: fi
273:
274: pp_set_expand_converter_or_reexec "$@"
275: pp_parseopts "$@"
276:
277: if $pp_opt_version; then
278: #-- print version and exit
279: echo "polypkg $pp_version"
280: exit 0
281: fi
282:
283: pp_set_platform
284:
285: trap 'pp_main_cleanup' 0
286:
287: pp_wrkdir="$pp_opt_wrkdir"
288: pp_debug "pp_wrkdir = $pp_wrkdir"
289: rm -rf "$pp_wrkdir"
290: mkdir -p "$pp_wrkdir"
291:
292: pp_destdir="$pp_opt_destdir"
293: pp_debug "pp_destdir = $pp_destdir"
294:
295: if $pp_opt_probe; then
296: pp_backend_init
297: pp_backend_probe
298: elif $pp_opt_vas_platforms; then
299: pp_backend_init
300: pp_backend_vas_platforms
301: elif test -n "$pp_opt_eval"; then
302: #-- execute a shell command
303: eval "$pp_opt_eval" || exit
304: else
305: pp_drive
306: if test -n "$pp_opt_install_script"; then
307: pp_install_script
308: fi
309: fi
310:
311: exit 0
312: }
313:
314:
315: pp_errors=false
316:
317: if test -n "$TERM" -a -t 1 && (tput op) >/dev/null 2>/dev/null; then
318: pp_col_redfg=`tput setf 4` 2>/dev/null
319: pp_col_bluefg=`tput setf 1` 2>/dev/null
320: pp_col_reset=`tput op` 2>/dev/null
321: else
322: pp_col_redfg='['
323: pp_col_bluefg='['
324: pp_col_reset=']'
325: fi
326:
327: pp__warn () {
328: if test x"" = x"$pp_lineno"; then
329: echo "$1 $2" >&2
330: else
331: echo "$1 line $pp_lineno: $2" >&2
332: fi
333: }
334:
335: pp_warn () {
336: pp__warn "pp: ${pp_col_redfg}warning${pp_col_reset}" "$*"
337: }
338:
339: pp_error () {
340: pp__warn "pp: ${pp_col_redfg}error${pp_col_reset}" "$*"
341: pp_errors=true
342: }
343:
344: pp_die () {
345: pp_error "$@"
346: exit 1
347: }
348:
349: pp_die_if_errors () {
350: $pp_errors && pp_die "$@"
351: }
352:
353: pp_debug () {
354: $pp_opt_debug && echo "${pp_col_bluefg}debug${pp_col_reset} $*" >&2
355: }
356:
357: pp_verbose () {
358: $pp_opt_verbose && echo "pp: ${pp_col_bluefg}info${pp_col_reset} $*" >&2
359: "$@";
360: }
361:
362: pp_substitute () {
363: sed -e 's,%(\([^)]*\)),`\1`,g' \
364: -e 's,%{\([^}]*\)},${\1},g' \
365: -e 's,$,,' |
366: tr '' '\012' |
367: sed -e '/^[^]/s/["$`\\]/\\&/g' \
368: -e 's/^//' \
369: -e '1s/^/echo "/' \
370: -e '$s,$,",' \
371: -e 's,,"echo ",g' |
372: tr -d '\012' |
373: tr '' '\012'
374: echo
375: }
376:
377: pp_incr () {
378: eval "$1=\`expr \$$1 + 1\`"
379: }
380:
381: pp_decr () {
382: eval "$1=\`expr \$$1 - 1\`"
383: }
384:
385: pp_check_var_is_defined () {
386: if eval test -z "\"\$$1\""; then
387: pp_error "\$$1: not set"
388: eval "$1=undefined"
389: fi
390: }
391:
392: pp_contains () {
393: case " $1 " in
394: *" $2 "*) return 0;;
395: *) return 1;;
396: esac
397: }
398:
399: pp_contains_all () {
400: typeset _s _c
401: _l="$1"; shift
402: for _w
403: do
404: pp_contains "$_l" "$_w" || return 1
405: done
406: return 0
407: }
408:
409: pp_contains_any () {
410: typeset _s _c
411: _l="$1"; shift
412: for _w
413: do
414: pp_contains "$_l" "$_w" && return 0
415: done
416: return 1
417: }
418:
419: pp_add_to_list () {
420: if eval test -z \"\$$1\"; then
421: eval $1='"$2"'
422: elif eval pp_contains '"$'$1'"' '"$2"'; then
423: : already there
424: else
425: eval $1='"$'$1' $2"'
426: fi
427: }
428:
429: pp_unique () {
430: typeset result element
431: result=
432: for element
433: do
434: pp_add_to_list result $element
435: done
436: echo $result
437: }
438:
439: pp_mode_strip_altaccess () {
440: case "$1" in
441: ??????????[+.])
442: echo `echo "$1" | cut -b -10`;;
443: *)
444: echo "$1";;
445: esac
446: }
447:
448: pp_mode_from_ls () {
449: typeset umode gmode omode smode
450:
451: set -- `pp_mode_strip_altaccess "$1"`
452:
453: case "$1" in
454: ?--[-X]??????) umode=0;;
455: ?--[xs]??????) umode=1;;
456: ?-w[-X]??????) umode=2;;
457: ?-w[xs]??????) umode=3;;
458: ?r-[-X]??????) umode=4;;
459: ?r-[xs]??????) umode=5;;
460: ?rw[-X]??????) umode=6;;
461: ?rw[xs]??????) umode=7;;
462: *) pp_error "bad user mode $1";;
463: esac
464:
465: case "$1" in
466: ????--[-S]???) gmode=0;;
467: ????--[xs]???) gmode=1;;
468: ????-w[-S]???) gmode=2;;
469: ????-w[xs]???) gmode=3;;
470: ????r-[-X]???) gmode=4;;
471: ????r-[xs]???) gmode=5;;
472: ????rw[-X]???) gmode=6;;
473: ????rw[xs]???) gmode=7;;
474: *) pp_error "bad group mode $1";;
475: esac
476:
477: case "$1" in
478: ???????--[-T]) omode=0;;
479: ???????--[xt]) omode=1;;
480: ???????-w[-T]) omode=2;;
481: ???????-w[xt]) omode=3;;
482: ???????r-[-T]) omode=4;;
483: ???????r-[xt]) omode=5;;
484: ???????rw[-T]) omode=6;;
485: ???????rw[xt]) omode=7;;
486: *) pp_error "bad other mode $1";;
487: esac
488:
489: case "$1" in
490: ???[-x]??[-x]??[-x]) smode=;;
491: ???[-x]??[-x]??[tT]) smode=1;;
492: ???[-x]??[Ss]??[-x]) smode=2;;
493: ???[-x]??[Ss]??[tT]) smode=3;;
494: ???[Ss]??[-x]??[-x]) smode=4;;
495: ???[Ss]??[-x]??[tT]) smode=5;;
496: ???[Ss]??[Ss]??[-x]) smode=6;;
497: ???[Ss]??[Ss]??[tT]) smode=7;;
498: *) pp_error "bad set-id mode $1";;
499: esac
500:
501: echo "$smode$umode$gmode$omode"
502: }
503:
504: pp_find_recurse () {
505: pp_debug "find: ${1#$pp_destdir}/"
506: for f in "$1"/.* "$1"/*; do
507: case "$f" in */.|*/..) continue;; esac # should never happen!
508: if test -d "$f" -o -f "$f" -o -h "$f"; then
509: if test -d "$f" -a ! -h "$f"; then
510: echo "${f#$pp_destdir}/"
511: pp_find_recurse "$f"
512: else
513: echo "${f#$pp_destdir}"
514: fi
515: fi
516: done
517: }
518:
519: pp_prepend () {
520: #test -t && pp_warn "pp_prepend: stdin is a tty?"
521: if test -f $1; then
522: pp_debug "prepending to $1"
523: mv $1 $1._prepend
524: cat - $1._prepend >$1
525: rm -f $1._prepend
526: else
527: pp_debug "prepend: creating $1"
528: cat >$1
529: fi
530: }
531:
532: pp_note_file_used() {
533: echo "$1" >> $pp_wrkdir/all.files
534: }
535:
536: pp_create_dir_if_missing () {
537: case "$1" in
538: */) pp_error "pp_create_dir_if_missing: trailing / forbidden";;
539: "") return 0;;
540: *) if test ! -d "$pp_destdir$1"; then
541: pp_debug "fabricating directory $1/"
542: pp_create_dir_if_missing "${1%/*}"
543: mkdir "$pp_destdir$1" &&
544: pp_note_file_used "$1/"
545: pp_remove_later "$1" &&
546: chmod ${2:-755} "$pp_destdir$1"
547: fi;;
548: esac
549: }
550:
551: pp_add_file_if_missing () {
552: typeset dir
553: #-- check that the file isn't already declared in the component
554: if test -s $pp_wrkdir/%files.${2:-run}; then
555: awk "\$6 == \"$1\" {exit 1}" < $pp_wrkdir/%files.${2:-run} || return 1
556: fi
557:
558: pp_create_dir_if_missing "${1%/*}"
559: pp_debug "fabricating file $1"
560: echo "f ${3:-755} - - ${4:--} $1" >> $pp_wrkdir/%files.${2:-run}
561: pp_note_file_used "$1"
562: pp_remove_later "$1"
563: return 0
564: }
565:
566: pp_add_transient_file () {
567: test -f "$pp_destdir$1" && pp_die "$pp_destdir$1: exists"
568: pp_create_dir_if_missing "${1%/*}"
569: pp_debug "transient file $1"
570: pp_note_file_used "$1"
571: pp_remove_later "$1"
572: }
573:
574: pp_remove_later () {
575: {
576: echo "$1"
577: test -s $pp_wrkdir/pp_cleanup && cat $pp_wrkdir/pp_cleanup
578: } > $pp_wrkdir/pp_cleanup.new
579: mv $pp_wrkdir/pp_cleanup.new $pp_wrkdir/pp_cleanup
580: }
581:
582: pp_ls_readlink () {
583: if test -h "$1"; then
584: ls -1ld "$1" | sed -ne 's,.* -> ,,p'
585: else
586: echo "$1: not a symbolic link" >&2
587: return 1
588: fi
589: }
590:
591: pp_remove_later_now () {
592: typeset f
593: if test -s $pp_wrkdir/pp_cleanup; then
594: pp_debug "pp_remove_later_now"
595: while read f; do
596: pp_debug "removing $pp_destdir$f"
597: if test -d $pp_destdir$f; then
598: rmdir $pp_destdir$f
599: else
600: rm $pp_destdir$f
601: fi
602: done < $pp_wrkdir/pp_cleanup
603: rm $pp_wrkdir/pp_cleanup
604: fi
605: }
606:
607: pp_readlink() {
608:
609: pp_debug "&& pp_readlink_fn=$pp_readlink_fn"
610:
611: if test -n "$pp_readlink_fn"; then
612: pp_debug "&& calling $pp_readlink_fn $*"
613: "$pp_readlink_fn" "$@"
614: else
615: readlink "$@"
616: fi
617: }
618:
619:
620: pp_install_script_common () {
621: cat <<-.
622:
623: # Automatically generated for
624: # $name $version ($pp_platform)
625: # by PolyPackage $pp_version
626:
627: usage () {
628: case "$1" in
629: "list-services")
630: echo "usage: \$0 list-services" ;;
631: "list-components")
632: echo "usage: \$0 list-components" ;;
633: "list-files")
634: echo "usage: \$0 list-files {cpt...|all}" ;;
635: "install")
636: echo "usage: \$0 install {cpt...|all}" ;;
637: "uninstall")
638: echo "usage: \$0 uninstall {cpt...|all}" ;;
639: "start")
640: echo "usage: \$0 start {svc...}" ;;
641: "stop")
642: echo "usage: \$0 stop {svc...}" ;;
643: "print-platform")
644: echo "usage: \$0 print-platform" ;;
645: *)
646: echo "usage: \$0 [-q] command [args]"
647: echo " list-services"
648: echo " list-components"
649: echo " list-files {cpt...|all}"
650: echo " install {cpt...|all}"
651: echo " uninstall {cpt...|all}"
652: echo " start {svc...}"
653: echo " stop {svc...}"
654: echo " print-platform"
655: ;;
656: esac >&2
657: exit 1
658: }
659:
660: if test x"\$1" = x"-q"; then
661: shift
662: verbose () { "\$@"; }
663: verbosemsg () { : ; }
664: else
665: verbose () { echo "+ \$*"; "\$@"; }
666: verbosemsg () { echo "\$*"; }
667: fi
668: .
669: }
670:
671:
672: pp_functions () {
673: typeset func deps allfuncs
674: allfuncs=
675: while test $# -gt 0; do
676: pp_add_to_list allfuncs "$1"
677: deps=`pp_backend_function "$1:depends"`
678: shift
679: set -- `pp_unique "$@" $deps`
680: done
681:
682: for func in $allfuncs
683: do
684: pp_debug "generating function code for '$1'"
685: echo ""
686: echo "$func () {"
687: case "$func" in
688: pp_mkgroup|pp_mkuser|pp_havelib) echo <<.;;
689: if test \$# -lt 1; then
690: echo "$func: not enough arguments" >&2
691: return 1
692: fi
693: .
694: esac
695: pp_backend_function "$func" || cat <<.
696: echo "$func: not implemented" >&2
697: return 1
698: .
699: echo "}"
700: done
701: }
702:
703: pp_function () {
704: pp_functions "$1"
705: }
706:
707: pp_makevar () {
708: #-- convert all non alpha/digits to underscores
709: echo "$*" | tr -c '[a-z][A-Z][0-9]\012' '[_*]'
710: }
711:
712: pp_getpwuid () {
713: awk -F: '$3 == uid { if (!found) print $1; found=1; } END { if (!found) exit 1; }' uid="$1" \
714: < /etc/passwd || pp_error "no local username for uid $1"
715: }
716:
717: pp_getgrgid () {
718: awk -F: '$3 == gid { if (!found) print $1; found=1; } END { if (!found) exit 1; }' gid="$1" \
719: < /etc/group || pp_error "no local group for gid $1"
720: }
721:
722: pp_backend_function_getopt () {
723: cat <<'..'
724: pp_getopt () {
725: _pp_optstring="$1"; shift; eval `_pp_getopt "$_pp_optstring"`
726: }
727: _pp_getopt_meta=s,[\\\\\"\'\`\$\&\;\(\)\{\}\#\%\ \ ],\\\\\&,g
728: _pp_protect () {
729: sed "$_pp_getopt_meta" <<. | tr '\012' ' '
730: $*
731: .
732: }
733: _pp_protect2 () {
734: sed "s,^..,,$pp_getopt_meta" <<. | tr '\012' ' '
735: $*
736: .
737: }
738: _pp_nonl () {
739: tr '\012' ' ' <<.
740: $*
741: .
742: }
743: _pp_getopt () {
744: _pp_nonl '_pp_nonl set --; while test $# -gt 0; do case "$1" in "--") shift; break;;'
745: sed 's/\([^: ]:*\)/<@<\1>@>/g;
746: s/<@<\(.\):>@>/"-\1") _pp_nonl -"\1"; _pp_protect "$2"; shift; shift;; "-\1"*) _pp_nonl -"\1"; _pp_protect2 "$1"; shift;;/g;s/<@<\(.\)>@>/ "-\1") _pp_nonl -"\1"; shift;; "-\1"*) _pp_nonl -"\1"; _pp_tmp="$1"; shift; set -- -`_pp_protect2 "$_pp_tmp"` "$@";;/g' <<.
747: $1
748: .
749: _pp_nonl '-*) echo "$1: unknown option">&2; return 1;; *) break;; esac; done; _pp_nonl --; while test $# -gt 0; do _pp_nonl "$1"; shift; done; echo'
750: echo
751: }
752: ..
753: }
754:
755: pp_copy_unstripped () {
756: typeset filedir realdir
757: filedir="`dirname ${1#$pp_destdir}`"
758: realdir="$pp_wrkdir/unstripped/$filedir"
759:
760: mkdir -p "$realdir"
761: # Can't use hardlinks because `strip` modifies the original file in-place
762: cp "$1" "$realdir"
763: }
764:
765: pp_package_stripped_binaries () {
766: (cd "$pp_wrkdir/unstripped" && tar -c .) \
767: | gzip > "$name-dbg-$version.tar.gz"
768: rm -rf "$pp_wrkdir/unstripped"
769: }
770:
771: pp_strip_binaries () {
772: if test x"$pp_opt_save_unstripped" = x"true"; then
773: rm -rf "$pp_wrkdir/unstripped"
774: mkdir "$pp_wrkdir/unstripped"
775: fi
776:
777: for f in `find "$pp_destdir" -type f`; do
778: if file "$f" | awk '{print $2}' | grep ^ELF >/dev/null 2>&1; then
779: if test x"$pp_opt_save_unstripped" = x"true"; then
780: if file "$f" | LC_MESSAGES=C grep 'not stripped' >/dev/null 2>&1; then
781: pp_debug "Saving unstripped binary $f"
782: pp_copy_unstripped "$f"
783: else
784: pp_debug "$f is already stripped; not saving a copy"
785: fi
786: fi
787: pp_debug "Stripping unnecessary symbols from $f"
788: strip "$f"
789: fi
790: done
791:
792: if test x"$pp_opt_save_unstripped" = x"true"; then
793: pp_package_stripped_binaries
794: fi
795: }
796:
797: pp_if_true=0
798: pp_if_false=0
799:
800: pp_frontend_init () {
801: name=
802: version=
803: summary="no summary"
804: description="No description"
1.1.1.2 ! misho 805: copyright="Copyright 2012 Quest Software, Inc. ALL RIGHTS RESERVED."
1.1 misho 806:
807: #-- if the user supplied extra arguments on the command line
808: # then load them now.
809: pp_debug "pp_opt_init_vars=$pp_opt_init_vars"
810: test -n "$pp_opt_init_vars" && eval "$pp_opt_init_vars"
811: }
812:
813: pp_is_qualifier () {
814: typeset ret
815:
816: case "$1" in
817: "["*"]") ret=true;;
818: *) ret=false;;
819: esac
820: pp_debug "is_qualifier: $* -> $ret"
821: test $ret = true
822: }
823:
824: pp_eval_qualifier () {
825: typeset ret
826:
827: case "$1" in
828: "[!$pp_platform]"| \
829: "[!"*",$pp_platform]"| \
830: "[!$pp_platform,"*"]"| \
831: "[!"*",$pp_platform,"*"]") ret=false;;
832: "[!"*"]") ret=true;;
833: "[$pp_platform]"| \
834: "["*",$pp_platform]"| \
835: "[$pp_platform,"*"]"| \
836: "["*",$pp_platform,"*"]") ret=true;;
837: "["*"]") ret=false;;
838: *) pp_die "pp_eval_qualifier: bad qualifier '$1'"
839: esac
840: pp_debug "eval: $* -> $ret"
841: test true = $ret
842: }
843:
844: pp_frontend_if () {
845: typeset ifcmd ifret
846: ifcmd="$1";
847: shift
848: case "$ifcmd" in
849: %if) if test 0 = $pp_if_false; then
850: case "$*" in
851: true |1) pp_incr pp_if_true;;
852: false|0) pp_incr pp_if_false;;
853: *)
854: ifret=true
855: if pp_is_qualifier "$*"; then
856: pp_eval_qualifier "$*" || ifret=false
857: else
858: eval test "$@" || ifret=false
859: pp_debug "evaluating test $* -> $ifret"
860: fi
861: pp_incr pp_if_$ifret
862: ;;
863: esac
864: else
865: pp_incr pp_if_false
866: fi;;
867: %else) test $# = 0 || pp_warn "ignoring argument to %else"
868: if test $pp_if_false -gt 1; then
869: : no change
870: elif test $pp_if_false = 1; then
871: pp_incr pp_if_true
872: pp_decr pp_if_false
873: elif test $pp_if_true = 0; then
874: pp_die "unmatched %else"
875: else
876: pp_incr pp_if_false
877: pp_decr pp_if_true
878: fi;;
879: %endif) test $# = 0 || pp_warn "ignoring argument to %endif"
880: if test $pp_if_false -gt 0; then
881: pp_decr pp_if_false
882: elif test $pp_if_true -gt 0; then
883: pp_decr pp_if_true
884: else
885: pp_die "unmatched %endif"
886: fi;;
887: *) pp_die "frontend_if: unknown cmd $ifcmd";;
888: esac
889: }
890:
891:
892: pp_frontend () {
893: typeset section newsection sed_word sed_ws line cpt svc
894: typeset section_enabled newsection_enabled s sed sed_candidate
895:
896: section='%_initial'
897: newsection='%_initial'
898: section_enabled=:
899: newsection_enabled=:
900: sed_word="[a-zA-Z_][a-zA-Z_0-9]*"
901: sed_ws="[ ]"
902:
903: #-- not all seds are created equal
904: sed=
905: for sed_candidate in ${PP_SED:-sed} /usr/xpg4/bin/sed; do
906: if echo 'foo' | $sed_candidate -ne '/^\(x\)*foo/p' | grep foo > /dev/null
907: then
908: sed="$sed_candidate"
909: break
910: fi
911: done
912: test -z "$sed" &&
913: pp_die "sed is broken on this system"
914:
915: pp_lineno=0
916:
917: #-- Note: this sed script should perform similar to pp_eval_qualifier()
918: $sed -e "/^#/s/.*//" \
919: -e "/^\\[!\\($sed_word,\\)*$pp_platform\\(,$sed_word\\)*\\]/s/.*//" \
920: -e "s/^\\[\\($sed_word,\\)*$pp_platform\\(,$sed_word\\)*\\]$sed_ws*//" \
921: -e "s/^\\[!\\($sed_word,\\)*$sed_word\\]$sed_ws*//" \
922: -e "/^\\[\\($sed_word,\\)*$sed_word\\]/s/.*//" \
923: -e "s/^%$sed_ws*/%/" \
924: -e "s/^$sed_ws/%\\\\&/" \
925: > $pp_wrkdir/frontend.tmp
926:
927: #-- add an ignore section at the end to force section completion
928: echo '%ignore' >> $pp_wrkdir/frontend.tmp
929: echo >> $pp_wrkdir/frontend.tmp
930:
931: exec 0<$pp_wrkdir/frontend.tmp
932: : > $pp_wrkdir/tmp
933: : > $pp_wrkdir/%fixup
934: while read -r line; do
935: #-- Convert leading double-% to single-%, or switch sections
936: pp_incr pp_lineno
937:
938: pp_debug "line $pp_lineno: $line"
939: set -f
940: set -- $line
941: set +f
942: #pp_debug "line $pp_lineno: $*"
943:
944: case "$line" in %*)
945: case "$1" in
946: %if|%else|%endif)
947: pp_debug "processing if directive $1"
948: pp_frontend_if "$@"
949: continue;;
950: esac
951: test 0 -ne $pp_if_false && continue # ignore lines %if'd out
952:
953: case "$1" in
954: %set|%fixup|%ignore)
955: pp_debug "processing new section $1"
956: newsection="$1"; shift
957: newsection_enabled=:
958: if pp_is_qualifier "$1"; then
959: pp_eval_qualifier "$1" || newsection_enabled=false
960: shift
961: fi
962: test $# -eq 0 || pp_warn "ignoring extra arguments: $line"
963: continue;;
1.1.1.2 ! misho 964: %pre|%post|%preun|%postup|%postun|%files|%depend|%check|%conflict)
1.1 misho 965: pp_debug "processing new component section $*"
966: s="$1"; shift
967: if test $# -eq 0 || pp_is_qualifier "$1"; then
968: cpt=run
969: else
970: cpt="$1"
971: shift
972: fi
973: newsection="$s.$cpt"
974: newsection_enabled=:
975: if test $# -gt 0 && pp_is_qualifier "$1"; then
976: pp_eval_qualifier "$1" || newsection_enabled=false
977: shift
978: fi
979: test $# -eq 0 ||
980: pp_warn "ignoring extra arguments: $line"
981: case "$cpt" in
982: run|dbg|doc|dev)
983: $newsection_enabled && pp_add_component "$cpt";;
984: x-*) :;; # useful for discarding stuff
985: *) pp_error "unknown component: $1 $cpt";;
986: esac
987: continue;;
988: %pp)
989: newsection="%ignore"; shift
990: if test $# -gt 0; then
991: pp_set_api_version "$1"
992: shift
993: else
994: pp_error "%pp: missing version"
995: fi
996: test $# -gt 0 &&
997: pp_error "%pp: too many arguments"
998: continue;;
999: %service)
1000: pp_debug "processing new service section $1 $2"
1001: s="$1"; shift
1002: if test $# -eq 0 || pp_is_qualifier "$1"; then
1003: pp_error "$s: service name required"
1004: svc=unknown
1005: else
1006: svc="$1"; shift
1007: fi
1008:
1009: newsection="$s.$svc"
1010: newsection_enabled=:
1011: if test $# -gt 0 && pp_is_qualifier "$1"; then
1012: pp_eval_qualifier "$1" || newsection_enabled=false
1013: shift
1014: fi
1015: test $# -eq 0 ||
1016: pp_warn "ignoring extra arguments: $line"
1017: $newsection_enabled && pp_add_service "$svc"
1018: continue;;
1019: %\\*)
1020: pp_debug "removing leading %\\"
1021: line="${line#??}"
1022: pp_debug " result is <$line>"
1023: set -f
1024: set -- $line
1025: set +f
1026: ;;
1027: %%*)
1028: pp_debug "removing leading %"
1029: line="${line#%}"
1030: set -f
1031: set -- $line
1032: set +f
1033: ;;
1034: %*)
1035: pp_error "unknown section $1"
1036: newsection='%ignore'
1037: newsection_enabled=:
1038: continue;;
1039: esac;;
1040: esac
1041:
1042: test 0 != $pp_if_false && continue # ignore lines %if'd out
1043:
1044: pp_debug "section=$section (enabled=$section_enabled) newsection=$newsection (enabled=$newsection_enabled)"
1045:
1046: #-- finish processing a previous section
1047: if test x"$newsection" != x""; then
1048: $section_enabled && case "$section" in
1049: %ignore|%_initial)
1050: pp_debug "leaving ignored section $section"
1051: : ignore # guaranteed to be the last section
1052: ;;
1053: %set)
1054: pp_debug "leaving $section: sourcing $pp_wrkdir/tmp"
1055: $pp_opt_debug && cat $pp_wrkdir/tmp >&2
1056: . $pp_wrkdir/tmp
1057: : > $pp_wrkdir/tmp
1058: ;;
1.1.1.2 ! misho 1059: %pre.*|%preun.*|%post.*|%postup.*|%postun.*|%depend.*|%check.*|%conflict.*|%service.*|%fixup)
1.1 misho 1060: pp_debug "leaving $section: substituting $pp_wrkdir/tmp"
1061: # cat $pp_wrkdir/tmp >&2 # debugging
1062: $pp_opt_debug && pp_substitute < $pp_wrkdir/tmp >&2
1063: pp_substitute < $pp_wrkdir/tmp > $pp_wrkdir/tmp.sh
1064: . $pp_wrkdir/tmp.sh >> $pp_wrkdir/$section ||
1065: pp_error "shell error in $section"
1066: rm -f $pp_wrkdir/tmp.sh
1067: : > $pp_wrkdir/tmp
1068: ;;
1069: esac
1070: section="$newsection"
1071: section_enabled="$newsection_enabled"
1072: newsection=
1073: fi
1074:
1075: #-- ignore section content that is disabled
1076: $section_enabled || continue
1077:
1078: #-- process some lines in-place
1079: case "$section" in
1080: %_initial)
1081: case "$line" in "") continue;; esac # ignore non-section blanks
1082: pp_die "Ignoring text before % section introducer";;
1083: %set|%pre.*|%preun.*|%post.*|%postup.*|%postun.*|%check.*|%service.*|%fixup)
1084: pp_debug "appending line to \$pp_wrkdir/tmp"
1085: echo "$line" >> $pp_wrkdir/tmp
1086: ;;
1087: %files.*)
1088: test $# -eq 0 && continue;
1089: pp_files_expand "$@" >> $pp_wrkdir/$section
1090: ;;
1091: %depend.*)
1092: pp_debug "Adding explicit dependency $@ to $cpt"
1093: echo "$@" >> $pp_wrkdir/%depend.$cpt
1094: ;;
1.1.1.2 ! misho 1095: %conflict.*)
! 1096: pp_debug "Adding explicit conflict $@ to $cpt"
! 1097: echo "$@" >> $pp_wrkdir/%conflict.$cpt
! 1098: ;;
1.1 misho 1099: esac
1100: done
1101: exec <&-
1102:
1103: if test $pp_if_true != 0 -o $pp_if_false != 0; then
1104: pp_die "missing %endif at end of file"
1105: fi
1106:
1107: pp_lineno=
1108:
1109: pp_debug " name = $name"
1110: pp_debug " version = $version"
1111: pp_debug " summary = $summary"
1112: pp_debug " description = $description"
1113: pp_debug " copyright = $copyright"
1114: pp_debug ""
1115: pp_debug "\$pp_components: $pp_components"
1116: pp_debug "\$pp_services: $pp_services"
1117: }
1118:
1119: pp_set_api_version() {
1120: case "$1" in
1121: 1.0) : ;;
1122: *) pp_error "This version of polypackage is too old";;
1123: esac
1124: }
1125:
1126: pp_platform=
1127:
1128: pp_set_platform () {
1129: if test -n "$pp_opt_platform"; then
1130: pp_contains "$pp_platforms" "$pp_opt_platform" ||
1131: pp_die "$pp_opt_platform: unknown platform"
1132: pp_platform="$pp_opt_platform"
1133: else
1134: uname_s=`uname -s 2>/dev/null`
1135: pp_platform=
1136: for p in $pp_platforms; do
1137: pp_debug "probing for platform $p"
1138: if eval pp_backend_${p}_detect "$uname_s"; then
1139: pp_platform="$p"
1140: break;
1141: fi
1142: done
1143: test -z "$pp_platform" &&
1144: pp_die "cannot detect platform (supported: $pp_platforms)"
1145: fi
1146: pp_debug "pp_platform = $pp_platform"
1147: }
1148:
1149: pp_expand_path=
1150:
1151: pp_expand_test_usr_bin () {
1152: awk '$1 == "/usr" || $2 == "/usr" {usr++}
1153: $1 == "/bin" || $2 == "/bin" {bin++}
1154: END { if (usr == 1 && bin == 1) exit(0); else exit(1); }'
1155: }
1156:
1157: pp_set_expand_converter_or_reexec () {
1158: test -d /usr -a -d /bin ||
1159: pp_die "missing /usr or /bin"
1160: echo /usr /bin | pp_expand_test_usr_bin || pp_die "pp_expand_test_usr_bin?"
1161: if (eval "echo /{usr,bin}" | pp_expand_test_usr_bin) 2>/dev/null; then
1162: pp_expand_path=pp_expand_path_brace
1163: elif (eval "echo /@(usr|bin)" | pp_expand_test_usr_bin) 2>/dev/null; then
1164: pp_expand_path=pp_expand_path_at
1165: else
1166: test x"$pp_expand_rexec" != x"true" ||
1167: pp_die "problem finding shell that can do brace expansion"
1168: for shell in ksh ksh93 bash; do
1169: if ($shell -c 'echo /{usr,bin}' |
1170: pp_expand_test_usr_bin) 2>/dev/null ||
1171: ($shell -c 'echo /@(usr|bin)' |
1172: pp_expand_test_usr_bin) 2>/dev/null
1173: then
1174: pp_debug "switching to shell $shell"
1175: pp_expand_rexec=true exec $shell "$0" "$@"
1176: fi
1177: done
1178: pp_die "cannot find a shell that does brace expansion"
1179: fi
1180: }
1181:
1182: pp_expand_path_brace () {
1183: typeset f
1184: eval "for f in $1; do echo \"\$f\"; done|sort -u"
1185: }
1186:
1187: pp_expand_path_at () {
1188: typeset f
1189: eval "for f in `
1190: echo "$1" | sed -e 's/{/@(/g' -e 's/}/)/g' -e 's/,/|/g'
1191: `; do echo \"\$f\"; done|sort -u"
1192: }
1193:
1194: pp_shlib_suffix='.so*'
1195:
1196: pp_model_init () {
1197: #@ $pp_components: whitespace-delimited list of components seen in %files
1198: pp_components=
1199: #@ $pp_services: whitespace-delimited list of %service seen
1200: pp_services=
1201:
1202: rm -f $pp_wrkdir/%files.* \
1203: $pp_wrkdir/%post.* \
1204: $pp_wrkdir/%pre.* \
1205: $pp_wrkdir/%preun.* \
1206: $pp_wrkdir/%postup.* \
1207: $pp_wrkdir/%postun.* \
1208: $pp_wrkdir/%service.* \
1209: $pp_wrkdir/%set \
1210: $pp_wrkdir/%fixup
1211: }
1212:
1213:
1214: pp_have_component () {
1215: pp_contains "$pp_components" "$1"
1216: }
1217:
1218: pp_have_all_components () {
1219: pp_contains_all "$pp_components" "$@"
1220: }
1221:
1222: pp_add_component () {
1223: pp_add_to_list 'pp_components' "$1"
1224: }
1225:
1226: pp_add_service () {
1227: pp_add_to_list 'pp_services' "$1"
1228: }
1229:
1230: pp_service_init_vars () {
1231: cmd=
1232: pidfile=
1233: stop_signal=15 # SIGTERM
1234: user=root
1235: group=
1236: enable=yes # make it so the service starts on boot
1237: optional=no # Whether installing this service is optional
1238: pp_backend_init_svc_vars
1239: }
1240:
1241: pp_service_check_vars () {
1242: test -n "$cmd" ||
1243: pp_error "%service $1: cmd not defined"
1244: case "$enable" in
1245: yes|no) : ;;
1246: *) pp_error "%service $1: \$enable must be set to yes or no";;
1247: esac
1248: }
1249:
1250: pp_load_service_vars () {
1251: pp_service_init_vars
1252: . "$pp_wrkdir/%service.$1"
1253: pp_service_check_vars "$1"
1254: }
1255:
1256: pp_files_expand () {
1257: typeset _p _mode _group _owner _flags _path _optional _has_target _tree
1258: typeset _path _file _tgt _m _o _g _f _type _lm _ll _lo _lg _ls _lx
1259: typeset _ignore _a
1260:
1261: test $# -eq 0 && return
1262:
1263: pp_debug "pp_files_expand: path is: $1"
1264:
1265: case "$1" in "#"*) return;; esac
1266: _p="$1"; shift
1267:
1268: pp_debug "pp_files_expand: other arguments: $*"
1269:
1270: #-- the mode must be an octal number of at least three digits
1271: _mode="="
1272: _a=`eval echo \"$1\"`
1273: case "$_a" in
1274: *:*) :;;
1275: -|=|[01234567][01234567][01234567]*) _mode="$_a"; shift;;
1276: esac
1277:
1278: #-- the owner:group field may have optional parts
1279: _a=`eval echo \"$1\"`
1280: case "$_a" in
1281: *:*) _group=${_a#*:}; _owner=${_a%:*}; shift;;
1282: =|-) _group=$_a; _owner=$_a; shift;;
1283: *) _group=; _owner=;;
1284: esac
1285:
1286: #-- process the flags argument
1287: _flags=
1288: _optional=false
1289: _has_target=false
1290: _ignore=false
1291: if test $# -gt 0; then
1292: _a=`eval echo \"$1\"`
1293: case ",$_a," in *,volatile,*) _flags="${_flags}v";; esac
1294: case ",$_a," in *,optional,*) _optional=true;; esac
1295: case ",$_a," in *,symlink,*) _has_target=true;; esac
1296: case ",$_a," in *,ignore-others,*) _flags="${_flags}i";; esac
1297: case ",$_a," in *,ignore,*) _ignore=true;; esac
1298: shift
1299: fi
1300:
1301: #-- process the target argument
1302: if $_has_target; then
1303: test $# -ne 0 || pp_error "$_p: missing target"
1304: _a=`eval echo \"$1\"`
1305: _target="$_a"
1306: shift
1307: fi
1308:
1309: pp_debug "pp_files_expand: $_mode|$_owner:$_group|$_flags|$_target|$*"
1310:
1311: test $# -eq 0 || pp_error "$_p: too many arguments"
1312:
1313: #-- process speciall suffixes
1314: tree=
1315: case "$_p" in
1316: *"/**") _p="${_p%"/**"}"; tree="**";;
1317: *".%so") _p="${_p%".%so"}$pp_shlib_suffix";;
1318: esac
1319:
1320: #-- expand the path using the shell glob
1321: pp_debug "expanding .$_p ... with $pp_expand_path"
1322: (cd ${pp_destdir} && $pp_expand_path ".$_p") > $pp_wrkdir/tmp.files.exp
1323:
1324: #-- expand path/** by rewriting the glob output file
1325: case "$tree" in
1326: "") : ;;
1327: "**")
1328: pp_debug "expanding /** tree ..."
1329: while read _path; do
1330: _path="${_path#.}"
1331: pp_find_recurse "$pp_destdir${_path%/}"
1332: done < $pp_wrkdir/tmp.files.exp |
1333: sort -u > $pp_wrkdir/tmp.files.exp2
1334: mv $pp_wrkdir/tmp.files.exp2 $pp_wrkdir/tmp.files.exp
1335: ;;
1336: esac
1337:
1338: while read _path; do
1339: _path="${_path#.}"
1340: _file="${pp_destdir}${_path}"
1341: _tgt=
1342: _m="$_mode"
1343: _o="${_owner:--}"
1344: _g="${_group:--}"
1345: _f="$_flags"
1346:
1347: case "$_path" in
1348: /*) :;;
1349: *) pp_warn "$_path: inserting leading /"
1350: _path="/$_path";; # ensure leading /
1351: esac
1352:
1353: #-- sanity checks
1354: case "$_path" in
1355: */../*|*/..) pp_error "$_path: invalid .. in path";;
1356: */./*|*/.) pp_warn "$_path: invalid component . in path";;
1357: *//*) pp_warn "$_path: redundant / in path";;
1358: esac
1359:
1360: #-- set the type based on the real file's type
1361: if $_ignore; then
1362: _type=f _m=_ _o=_ _g=_
1363: elif test -h "$_file"; then
1364: case "$_path" in
1365: */) pp_warn "$_path (symlink $_file): removing trailing /"
1366: _path="${_path%/}"
1367: ;;
1368: esac
1369: _type=s
1370: if test x"$_target" != x"=" -a -n "$_target"; then
1371: _tgt="$_target"
1372: pp_debug "symlink target is $_tgt"
1373: else
1374: _tgt=`pp_readlink "$_file"`;
1375: test -z "$_tgt" && pp_error "can't readlink $_file"
1376: case "$_tgt" in
1377: ${pp_destdir}/*)
1378: pp_warn "stripped \$destdir from symlink ($_path)"
1379: _tgt="${_tgt#$pp_destdir}";;
1380: esac
1381: fi
1382: _m=777
1383: elif test -d "$_file"; then
1384: #-- display a warning if the user forgot the trailing /
1385: case "$_path" in
1386: */) :;;
1387: *) pp_warn "$_path (matching $_file): adding trailing /"
1388: _path="$_path/";;
1389: esac
1390: _type=d
1391: $_has_target && pp_error "$_file: not a symlink"
1392: elif test -f "$_file"; then
1393: case "$_path" in
1394: */) pp_warn "$_path (matching $_file): removing trailing /"
1395: _path="${_path%/}"
1396: ;;
1397: esac
1398: _type=f
1399: $_has_target && pp_error "$_file: not a symlink"
1400: else
1401: $_optional && continue
1402: pp_error "$_file: missing"
1403: _type=f
1404: fi
1405:
1406: #-- convert '=' shortcuts into mode/owner/group from ls
1407: case ":$_m:$_o:$_g:" in *:=:*)
1408: if LS_OPTIONS=--color=never /bin/ls -ld "$_file" \
1409: > $pp_wrkdir/ls.tmp
1410: then
1411: read _lm _ll _lo _lg _ls _lx < $pp_wrkdir/ls.tmp
1412: test x"$_m" = x"=" && _m=`pp_mode_from_ls "$_lm"`
1413: test x"$_o" = x"=" && _o="$_lo"
1414: test x"$_g" = x"=" && _g="$_lg"
1415: else
1416: pp_error "cannot read $_file"
1417: test x"$_m" = x"=" && _m=-
1418: test x"$_o" = x"=" && _o=-
1419: test x"$_g" = x"=" && _g=-
1420: fi
1421: ;;
1422: esac
1423:
1424: test -n "$_f" || _f=-
1425:
1426: #-- sanity checks
1427: test -n "$_type" || pp_die "_type empty"
1428: test -n "$_path" || pp_die "_path empty"
1429: test -n "$_m" || pp_die "_m empty"
1430: test -n "$_o" || pp_die "_o empty"
1431: test -n "$_g" || pp_die "_g empty"
1432:
1433: #-- setuid/gid files must be given an explicit owner/group (or =)
1434: case "$_o:$_g:$_m" in
1435: -:*:[4657][1357]??|-:*:[4657]?[1357]?|-:*:[4657]??[1357])
1436: pp_error "$_path: setuid file ($_m) missing explicit owner";;
1437: *:-:[2367][1357]??|*:-:[2367]?[1357]?|*:-:[2367]??[1357])
1438: pp_error "$_path: setgid file ($_m) missing explicit group";;
1439: esac
1440:
1441: # convert numeric uids into usernames; only works for /etc/passwd
1442: case "$_o" in [0-9]*) _o=`pp_getpwuid $_o`;; esac
1443: case "$_g" in [0-9]*) _g=`pp_getgrgid $_g`;; esac
1444:
1445: pp_debug "$_type $_m $_o $_g $_f $_path" $_tgt
1446: $_ignore || echo "$_type $_m $_o $_g $_f $_path" $_tgt
1447: pp_note_file_used "$_path"
1448: case "$_f" in *i*) echo "$_path" >> $pp_wrkdir/ign.files;; esac
1449: done < $pp_wrkdir/tmp.files.exp
1450: }
1451:
1452: pp_files_check_duplicates () {
1453: typeset _path
1454: if test -s $pp_wrkdir/all.files; then
1455: sort < $pp_wrkdir/all.files | uniq -d > $pp_wrkdir/duplicate.files
1456: if test -f $pp_wrkdir/ign.awk; then
1457: # Remove ignored files
1458: mv $pp_wrkdir/duplicate.files $pp_wrkdir/duplicate.files.ign
1459: sed -e 's/^/_ _ _ _ _ /' < $pp_wrkdir/duplicate.files.ign |
1460: awk -f $pp_wrkdir/ign.awk |
1461: sed -e 's/^_ _ _ _ _ //' > $pp_wrkdir/duplicate.files
1462: fi
1463: while read _path; do
1464: pp_warn "$_path: file declared more than once"
1465: done <$pp_wrkdir/duplicate.files
1466: fi
1467: }
1468:
1469: pp_files_check_coverage () {
1470: pp_find_recurse "$pp_destdir" | sort > $pp_wrkdir/coverage.avail
1471: if test -s $pp_wrkdir/all.files; then
1472: sort -u < $pp_wrkdir/all.files
1473: else
1474: :
1475: fi > $pp_wrkdir/coverage.used
1476: join -v1 $pp_wrkdir/coverage.avail $pp_wrkdir/coverage.used \
1477: > $pp_wrkdir/coverage.not-packaged
1478: if test -s $pp_wrkdir/coverage.not-packaged; then
1479: pp_warn "The following files/directories were found but not packaged:"
1480: sed -e 's,^, ,' < $pp_wrkdir/coverage.not-packaged >&2
1481: fi
1482: join -v2 $pp_wrkdir/coverage.avail $pp_wrkdir/coverage.used \
1483: > $pp_wrkdir/coverage.not-avail
1484: if test -s $pp_wrkdir/coverage.not-avail; then
1485: pp_warn "The following files/directories were named but not found:"
1486: sed -e 's,^, ,' < $pp_wrkdir/coverage.not-avail >&2
1487: fi
1488: }
1489:
1490: pp_files_ignore_others () {
1491: typeset p f
1492:
1493: test -s $pp_wrkdir/ign.files || return
1494:
1495: #-- for each file in ign.files, we remove it from all the
1496: # other %files.* lists, except where it has an i flag.
1497: # rather than scan each list multiple times, we build
1498: # an awk script
1499:
1500: pp_debug "stripping ignore files"
1501:
1502: while read p; do
1503: echo '$6 == "'"$p"'" && $5 !~ /i/ { next }'
1504: done < $pp_wrkdir/ign.files > $pp_wrkdir/ign.awk
1505: echo '{ print }' >> $pp_wrkdir/ign.awk
1506:
1507: $pp_opt_debug && cat $pp_wrkdir/ign.awk
1508:
1509: for f in $pp_wrkdir/%files.*; do
1510: mv $f $f.ign
1511: awk -f $pp_wrkdir/ign.awk < $f.ign > $f || pp_error "awk"
1512: done
1513: }
1514:
1515: pp_service_scan_groups () {
1516: typeset svc
1517:
1518: #-- scan for "group" commands, and build a list of groups
1519: pp_service_groups=
1520: if test -n "$pp_services"; then
1521: for svc in $pp_services; do
1522: group=
1523: . $pp_wrkdir/%service.$svc
1524: if test -n "$group"; then
1525: pp_contains "$pp_services" "$group" && pp_error \
1526: "%service $svc: group name $group in use by a service"
1527: pp_add_to_list 'pp_service_groups' "$group"
1528: echo "$svc" >> $pp_wrkdir/%svcgrp.$group
1529: fi
1530: done
1531: fi
1532: }
1533:
1534: pp_service_get_svc_group () {
1535: (tr '\012' ' ' < $pp_wrkdir/%svcgrp.$1 ; echo) | sed -e 's/ $//'
1536: }
1537:
1538: for _sufx in _init '' _names _cleanup _install_script \
1539: _init_svc_vars _function _probe _vas_platforms
1540: do
1541: eval "pp_backend$_sufx () { pp_debug pp_backend$_sufx; pp_backend_\${pp_platform}$_sufx \"\$@\"; }"
1542: done
1543:
1544:
1545: pp_platforms="$pp_platforms aix"
1546:
1547: pp_backend_aix_detect () {
1548: test x"$1" = x"AIX"
1549: }
1550:
1551: pp_backend_aix_init () {
1552: pp_aix_detect_arch
1553: pp_aix_detect_os
1554:
1555: pp_aix_bosboot= # components that need bosboot
1556: pp_aix_lang=en_US
1557: pp_aix_copyright=
1558: pp_aix_start_services_after_install=false
1559: pp_aix_init_services_after_install=true
1560:
1561: pp_aix_sudo=sudo # AIX package tools must run as root
1562:
1563: case "$pp_aix_os" in
1564: *) pp_readlink_fn=pp_ls_readlink;; # XXX
1565: esac
1566:
1567: pp_aix_abis_seen=
1568: }
1569:
1570: pp_aix_detect_arch () {
1571: pp_aix_arch_p=`uname -p 2>/dev/null`
1572: case "$pp_aix_arch_p" in
1573: "") pp_debug "can't get processor type from uname -p"
1574: pp_aix_arch_p=powerpc
1575: pp_aix_arch=R;; # guess (lsattr -l proc0 ??)
1576: powerpc) pp_aix_arch=R;;
1577: *) pp_aix_arch_p=intel
1578: pp_aix_arch=I;; # XXX? verify
1579: esac
1580:
1581: case "`/usr/sbin/lsattr -El proc0 -a type -F value`" in
1582: PowerPC_POWER*) pp_aix_arch_std=ppc64;;
1583: PowerPC*) pp_aix_arch_std=ppc;;
1584: *) pp_aix_arch_std=unknown;;
1585: esac
1586: }
1587:
1588: pp_aix_detect_os () {
1589: typeset r v
1590:
1591: r=`uname -r`
1592: v=`uname -v`
1593: pp_aix_os=aix$v$r
1594: }
1595:
1596: pp_aix_version_fix () {
1597: typeset v
1.1.1.2 ! misho 1598: v=`echo $1 | sed 's/[-+]/./' | tr -c -d '[0-9].\012' | awk -F"." '{ printf "%d.%d.%d.%.4s\n", $1, $2, $3, $4 }' | sed 's/[.]*$//g'`
1.1 misho 1599: if test x"$v" != x"$1"; then
1600: pp_warn "stripped version '$1' to '$v'"
1601: fi
1602: case $v in
1603: ""|*..*|.*|*.) pp_error "malformed '$1'"
1604: echo "0.0.0.0";;
1605: *.*.*.*.*)
1606: # 5 components are only valid for fileset updates, not base
1607: # filesets (full packages). We trim 5+ components down to 4.
1608: pp_warn "version '$1' has too many dots for AIX, truncating"
1609: echo "$v" | cut -d. -f1-4;;
1610: *.*.*.*) echo "$v";;
1611: *.*.*) echo "$v.0";;
1612: *.*) echo "$v.0.0";;
1613: *) echo "$v.0.0.0";;
1614: esac
1615: }
1616:
1617: pp_aix_select () {
1618: case "$1" in
1619: -user) op="";;
1620: -root) op="!";;
1621: *) pp_die "pp_aix_select: bad argument";;
1622: esac
1623: #pp_debug awk '$5 '$op' /^\/(usr|opt)(\/|$)/ { print; }'
1624: #awk '$5 '$op' /^\/(usr|opt)(\/|$)/ { print; }'
1625: awk $op'($6 ~ /^\/usr\// || $6 ~ /^\/opt\//) { print; }'
1626: }
1627:
1628: pp_aix_copy_root () {
1629: typeset t m o g f p st target
1630: while read t m o g f p st; do
1631: case "$t" in
1632: d) pp_create_dir_if_missing "$1${p%/}";;
1633: f) pp_add_transient_file "$1$p"
1634: pp_verbose ln "$pp_destdir$p" "$pp_destdir$1$p" ||
1635: pp_error "can't link $p into $1";;
1636: *) pp_warn "pp_aix_copy_root: filetype $t not handled";;
1637: esac
1638: done
1639: }
1640:
1641:
1642: pp_aix_size () {
1643: typeset prefix t m o g f p st
1644:
1645: prefix="$1"
1646: while read t m o g f p st; do
1647: case "$t" in f) du -a "$pp_destdir$p";; esac
1648: done | sed -e 's!/[^/]*$!!' | sort +1 |
1649: awk '{ if ($2 != d)
1650: { if (sz) print d,sz;
1651: d=$2; sz=0 }
1652: sz += $1; }
1653: END { if (sz) print d,sz }' |
1654: sed -n -e "s!^$pp_destdir!$prefix!p"
1655: }
1656:
1657: pp_aix_list () {
1658: awk '{ print "." pfx $6; }' pfx="$1"
1659: }
1660:
1661: pp_aix_make_liblpp () {
1662: typeset out dn fl f
1663:
1664: out="$1"; shift
1665: dn=`dirname "$2"`
1666: fl=
1667: for f
1668: do
1669: case "$f" in "$dn/"*) fl="$fl `basename $f`" ;;
1670: *) pp_die "liblpp name $f not in $dn/";; esac
1671: done
1672: (cd "$dn" && pp_verbose ar -c -g -r "$out" $fl) || pp_error "ar error"
1673: }
1674:
1675: pp_aix_make_script () {
1676: rm -f "$1"
1677: echo "#!/bin/sh" > "$1"
1678: cat >> "$1"
1679: echo "exit 0" >> "$1"
1680: chmod +x "$1"
1681: }
1682:
1683: pp_aix_inventory () {
1684: typeset fileset t m o g f p st type
1685:
1686: fileset="$1"
1687: while read t m o g f p st; do
1688: case "$p" in *:*) pp_error "path $p contains colon";; esac
1689: echo "$p:"
1690: case "$t" in
1691: f) type=FILE; defm=644 ;;
1692: s) type=SYMLINK; defm=777 ;;
1693: d) type=DIRECTORY; defm=755 ;;
1694: esac
1695: echo " type = $type"
1696: echo " class = inventory,apply,$fileset"
1697: if test x"$m" = x"-"; then m="$defm"; fi
1698: if test x"$o" = x"-"; then o="root"; fi
1699: if test x"$g" = x"-"; then g="system"; fi
1700: echo " owner = $o"
1701: echo " group = $g"
1702:
1703: case "$m" in ????)
1704: m=`echo $m|sed -e 's/^1/TCB,/' \
1705: -e 's/^[23]/TCB,SGID,/' \
1706: -e 's/^[45]/TCB,SUID,/' \
1707: -e 's/^[67]/TCB,SUID,SGID,/'`;; # vtx bit ignored
1708: esac
1709: echo " mode = $m"
1710: case "$t" in
1711: f) if test ! -f "$pp_destdir$p"; then
1712: pp_error "$p: missing file"
1713: fi
1714: case "$flags" in
1715: *v*)
1716: echo " size = VOLATILE"
1717: echo " checksum = VOLATILE"
1718: ;;
1719: *)
1720: if test -r "$pp_destdir$p"; then
1721: echo " size = $size"
1722: pp_verbose sum -r < "$pp_destdir$p" |
1723: sed -e 's/.*/ checksum = "&"/'
1724: fi
1725: ;;
1726: esac;;
1727: s)
1728: echo " target = $st"
1729: ;;
1730: esac
1731:
1732: #-- Record ABI types seen
1733: case "$t" in
1734: f) if test -r "$pp_destdir$p"; then
1735: case "`file "$pp_destdir$p"`" in
1736: *"executable (RISC System/6000)"*) abi=ppc;;
1737: *"64-bit XCOFF executable"*) abi=ppc64;;
1738: *) abi=;;
1739: esac
1740: if test -n "$abi"; then
1741: pp_add_to_list pp_aix_abis_seen $abi
1742: fi
1743: fi;;
1744: esac
1745:
1746: done
1747: }
1748:
1749: pp_aix_depend ()
1750: {
1751: if test -s "$1"; then
1752: pp_warn "aix dependencies not implemented"
1753: fi
1754: }
1755:
1756: pp_aix_add_service () {
1757: typeset svc cmd_cmd cmd_arg f
1758: svc="$1"
1759:
1760: pp_load_service_vars $svc
1761:
1762: set -- $cmd
1763: cmd_cmd="$1"; shift
1.1.1.2 ! misho 1764: cmd_arg="${pp_aix_mkssys_cmd_args:-$*}";
1.1 misho 1765:
1766: case "$stop_signal" in
1767: HUP) stop_signal=1;;
1768: INT) stop_signal=2;;
1769: QUIT) stop_signal=3;;
1770: KILL) stop_signal=9;;
1771: TERM) stop_signal=15;;
1772: USR1) stop_signal=30;;
1773: USR2) stop_signal=31;;
1774: "")
1775: pp_error "%service $svc: stop_signal not set";;
1776: [a-zA-Z]*)
1777: pp_error "%service $svc: bad stop_signal ($stop_signal)";;
1778: esac
1779:
1780: test -z "$pidfile" || pp_error "aix requires empty pidfile (non daemon)"
1781:
1782: pp_add_component run
1783: if test "$user" = "root"; then
1784: uid=0
1785: else
1786: uid="\"\`/usr/bin/id -u $user\`\""
1787: fi
1788:
1789:
1790: #-- add command text to create/remove the service
1791: cat <<-. >> $pp_wrkdir/%post.$svc
1792: svc=$svc
1793: uid=0
1.1.1.2 ! misho 1794: cmd_cmd="$cmd_cmd"
1.1 misho 1795: cmd_arg="$cmd_arg"
1796: stop_signal=$stop_signal
1797: force_signal=9
1798: srcgroup="$pp_aix_mkssys_group"
1.1.1.2 ! misho 1799: instances_allowed=${pp_aix_mkssys_instances_allowed:--Q}
1.1 misho 1800:
1801: lssrc -s \$svc > /dev/null 2>&1
1802: if [ \$? -eq 0 ]; then
1803: lssrc -s \$svc | grep "active" > /dev/null 2>&1
1804: if [ \$? -eq 0 ]; then
1805: stopsrc -s \$svc > /dev/null 2>&1
1806: fi
1807: rmsys -s \$svc > /dev/null 2>&1
1808: fi
1809:
1.1.1.2 ! misho 1810: mkssys -s \$svc -u \$uid -p "\$cmd_cmd" \${cmd_arg:+-a "\$cmd_arg"} -S -n \$stop_signal -f 9 ${pp_aix_mkssys_args} \${srcgroup:+-G \$srcgroup} \$instances_allowed
1.1 misho 1811: .
1812:
1813: #-- add code to start the service on reboot
1814: ${pp_aix_init_services_after_install} &&
1815: cat <<-. >> $pp_wrkdir/%post.$svc
1.1.1.2 ! misho 1816: id=\`echo "\$svc" | cut -c1-14\`
! 1817: mkitab "\$id:2:once:/usr/bin/startsrc -s \$svc" > /dev/null 2>&1
1.1 misho 1818: .
1819:
1820: ${pp_aix_start_services_after_install} &&
1821: cat <<-. >> $pp_wrkdir/%post.$svc
1822: startsrc -s \$svc
1823: .
1824:
1825: if [ -f "$pp_wrkdir/%post.run" ];then
1826: cat $pp_wrkdir/%post.run >> $pp_wrkdir/%post.$svc
1827: fi
1828: mv $pp_wrkdir/%post.$svc $pp_wrkdir/%post.run
1829:
1830:
1831: ${pp_aix_init_services_after_install} &&
1832: pp_prepend $pp_wrkdir/%preun.$svc <<-.
1.1.1.2 ! misho 1833: rmitab `echo "$svc" | cut -c1-14` > /dev/null 2>&1
1.1 misho 1834: .
1835: pp_prepend $pp_wrkdir/%preun.$svc <<-.
1836: stopsrc -s $svc >/dev/null 2>&1
1837: rmssys -s $svc
1838: .
1839:
1840: if [ -f "$pp_wrkdir/%preun.run" ];then
1841: cat $pp_wrkdir/%preun.run >> $pp_wrkdir/%preun.$svc
1842: fi
1843: mv $pp_wrkdir/%preun.$svc $pp_wrkdir/%preun.run
1844: }
1845:
1846: pp_backend_aix () {
1847: typeset briefex instuser instroot svc cmp outbff
1848: typeset user_wrkdir root_wrkdir
1849: typeset user_files root_files
1850:
1851: test -n "$pp_destdir" ||
1852: pp_error "AIX backend requires the '--destdir' option"
1853:
1854: instuser="/usr/lpp/$name"
1855: instroot="$instuser/inst_root"
1856: pp_aix_bff_name=${pp_aix_bff_name:-$name}
1857:
1858: # Here is the component mapping:
1859: # run -> $pp_aix_bff_name.rte ('Run time environment')
1860: # doc -> $pp_aix_bff_name.doc (non-standard)
1861: # dev -> $pp_aix_bff_name.adt ('Application developer toolkit')
1862: # dbg -> $pp_aix_bff_name.diag ('Diagnostics')
1863:
1864: test `echo "$summary" | wc -c ` -gt 40 && pp_error "\$summary too long"
1865:
1866: user_wrkdir=$pp_wrkdir/u
1867: root_wrkdir=$pp_wrkdir/r
1868: pp_verbose rm -rf $user_wrkdir $root_wrkdir
1869: pp_verbose mkdir -p $user_wrkdir $root_wrkdir
1870:
1871: for svc in $pp_services .; do
1872: test . = "$svc" && continue
1873: pp_aix_add_service $svc
1874: done
1875:
1876: {
1877: echo "4 $pp_aix_arch I $name {"
1878:
1879: for cmp in $pp_components; do
1880: case "$cmp" in
1881: run) ex=rte briefex="runtime";;
1882: doc) ex=doc briefex="documentation";;
1883: dev) ex=adt briefex="developer toolkit";;
1884: dbg) ex=diag briefex="diagnostics";;
1885: esac
1886:
1887: user_files=$pp_wrkdir/%files.$cmp.u
1888: root_files=$pp_wrkdir/%files.$cmp.r
1889:
1890: pp_aix_select -user < $pp_wrkdir/%files.$cmp > $user_files
1891: pp_aix_select -root < $pp_wrkdir/%files.$cmp > $root_files
1892:
1893: # Default to USR only unless there are root files,
1894: # or a post/pre/check script associated
1895: content=U
1896: if test -s $root_files \
1897: -o -s $pp_wrkdir/%pre.$cmp \
1898: -o -s $pp_wrkdir/%post.$cmp \
1899: -o -s $pp_wrkdir/%preun.$cmp \
1.1.1.2 ! misho 1900: -o -s $pp_wrkdir/%postun.$cmp \
1.1 misho 1901: -o -s $pp_wrkdir/%check.$cmp
1902: then
1903: content=B
1904: fi
1905:
1906: if $pp_opt_debug; then
1907: echo "$cmp USER %files:"
1908: cat $user_files
1909: echo "$cmp ROOT %files:"
1910: cat $root_files
1911: fi >&2
1912:
1913: bosboot=N; pp_contains_any "$pp_aix_bosboot" $cmp && bosboot=b
1914:
1915: echo $pp_aix_bff_name.$ex \
1.1.1.2 ! misho 1916: `[ $pp_aix_version ] && pp_aix_version_fix $pp_aix_version || pp_aix_version_fix "$version"` \
1.1 misho 1917: 1 $bosboot $content \
1918: $pp_aix_lang "$summary $briefex"
1919: echo "["
1920:
1921: pp_aix_depend $pp_wrkdir/%depend.$cmp
1922:
1923: echo "%"
1924:
1925: # generate per-directory size information
1926: pp_aix_size < $user_files
1927: pp_aix_size $instroot < $root_files
1928:
1929: pp_aix_list < $user_files > $user_wrkdir/$pp_aix_bff_name.$ex.al
1930: pp_aix_list $instroot < $root_files >> $user_wrkdir/$pp_aix_bff_name.$ex.al
1931: pp_aix_list < $root_files > $root_wrkdir/$pp_aix_bff_name.$ex.al
1932:
1933: if $pp_opt_debug; then
1934: echo "$cmp USER $pp_aix_bff_name.$ex.al:"
1935: cat $user_wrkdir/$pp_aix_bff_name.$ex.al
1936: echo "$cmp ROOT $pp_aix_bff_name.$ex.al:"
1937: cat $root_wrkdir/$pp_aix_bff_name.$ex.al
1938: fi >&2
1939:
1940: pp_aix_inventory $pp_aix_bff_name.$ex < $user_files \
1941: > $user_wrkdir/$pp_aix_bff_name.$ex.inventory
1942: pp_aix_inventory $pp_aix_bff_name.$ex < $root_files \
1943: > $root_wrkdir/$pp_aix_bff_name.$ex.inventory
1944:
1945: if $pp_opt_debug; then
1946: pp_debug "$cmp USER $pp_aix_bff_name.$ex.inventory:"
1947: cat $user_wrkdir/$pp_aix_bff_name.$ex.inventory
1948: pp_debug "$cmp ROOT $pp_aix_bff_name.$ex.inventory:"
1949: cat $root_wrkdir/$pp_aix_bff_name.$ex.inventory
1950: fi >&2
1951:
1952: if test x"" != x"${pp_aix_copyright:-$copyright}"; then
1953: echo "${pp_aix_copyright:-$copyright}" > $user_wrkdir/$pp_aix_bff_name.$ex.copyright
1954: echo "${pp_aix_copyright:-$copyright}" > $root_wrkdir/$pp_aix_bff_name.$ex.copyright
1955: fi
1956:
1957: #-- assume that post/pre uninstall scripts only make
1958: # sense when installed in a root context
1959:
1960: if test -r $pp_wrkdir/%pre.$cmp; then
1961: pp_aix_make_script $user_wrkdir/$pp_aix_bff_name.$ex.pre_i \
1962: < $pp_wrkdir/%pre.$cmp
1963: fi
1964:
1965: if test -r $pp_wrkdir/%post.$cmp; then
1966: pp_aix_make_script $root_wrkdir/$pp_aix_bff_name.$ex.post_i \
1967: < $pp_wrkdir/%post.$cmp
1968: fi
1969:
1970: if test -r $pp_wrkdir/%preun.$cmp; then
1971: pp_aix_make_script $root_wrkdir/$pp_aix_bff_name.$ex.unpost_i \
1972: < $pp_wrkdir/%preun.$cmp
1973: fi
1974:
1.1.1.2 ! misho 1975: if test -r $pp_wrkdir/%postun.$cmp; then
! 1976: pp_aix_make_script $root_wrkdir/$pp_aix_bff_name.$ex.unpre_i \
! 1977: < $pp_wrkdir/%postun.$cmp
! 1978: fi
! 1979:
1.1 misho 1980: # remove empty files
1981: for f in $user_wrkdir/$pp_aix_bff_name.$ex.* $root_wrkdir/$pp_aix_bff_name.$ex.*; do
1982: if test ! -s "$f"; then
1983: pp_debug "removing empty $f"
1984: rm -f "$f"
1985: fi
1986: done
1987:
1988: # copy/link the root files so we can do an easy backup later
1989: pp_aix_copy_root $instroot < $root_files
1990:
1991: echo "%"
1992: echo "]"
1993: done
1994: echo "}"
1995: } > $pp_wrkdir/lpp_name
1996:
1997: if $pp_opt_debug; then
1998: echo "/lpp_name :"
1999: cat $pp_wrkdir/lpp_name
2000: fi >&2
2001:
2002: #-- copy the /lpp_name file to the destdir
2003: pp_add_transient_file /lpp_name
2004: cp $pp_wrkdir/lpp_name $pp_destdir/lpp_name
2005:
2006: #-- copy the liblpp.a files under destdir for packaging
2007: (cd $user_wrkdir && pp_verbose ar -c -g -r liblpp.a $name.*) ||
2008: pp_error "ar error"
2009: if test -s $user_wrkdir/liblpp.a; then
2010: pp_add_transient_file $instuser/liblpp.a
2011: pp_verbose cp $user_wrkdir/liblpp.a $pp_destdir$instuser/liblpp.a ||
2012: pp_error "cannot create user liblpp.a"
2013: fi
2014: (cd $root_wrkdir && pp_verbose ar -c -g -r liblpp.a $name.*) ||
2015: pp_error "ar error"
2016: if test -s $root_wrkdir/liblpp.a; then
2017: pp_add_transient_file $instroot/liblpp.a
2018: pp_verbose cp $root_wrkdir/liblpp.a $pp_destdir$instroot/liblpp.a ||
2019: pp_error "cannot create root liblpp.a"
2020: fi
2021:
2022: { echo ./lpp_name
2023: test -s $user_wrkdir/liblpp.a && echo .$instuser/liblpp.a
2024: test -s $root_wrkdir/liblpp.a && echo .$instroot/liblpp.a
2025: cat $user_wrkdir/$name.*.al # includes the relocated root files!
2026: } > $pp_wrkdir/bff.list
2027:
2028: if test -n "$pp_aix_abis_seen" -a x"$pp_aix_arch_std" = x"auto"; then
2029: case "$pp_aix_abis_seen" in
2030: "ppc ppc64"|"ppc64 ppc")
2031: pp_aix_arch_std=ppc64
2032: ;;
2033: ppc|ppc64)
2034: pp_aix_arch_std=$pp_aix_abis_seen
2035: ;;
2036: *" "*)
2037: pp_warn "multiple architectures detected: $pp_aix_abis_seen"
2038: pp_aix_arch_std=unknown
2039: ;;
2040: "")
2041: pp_warn "no binary executables detected; using noarch"
2042: pp_aix_arch_std=noarch
2043: ;;
2044: *)
2045: pp_warn "unknown architecture detected $pp_aix_abis_seen"
2046: pp_aix_arch_std=$pp_aix_abis_seen
2047: ;;
2048: esac
2049: fi
2050:
2051: . $pp_wrkdir/%fixup
2052:
2053: outbff=`pp_backend_aix_names`
2054: pp_debug "creating: $pp_wrkdir/$outbff"
2055: (cd $pp_destdir && pp_verbose /usr/sbin/backup -i -q -p -f -) \
2056: < $pp_wrkdir/bff.list \
2057: > $pp_wrkdir/$outbff || pp_error "backup failed"
2058: $pp_aix_sudo /usr/sbin/installp -l -d $pp_wrkdir/$outbff
2059: }
2060:
2061: pp_backend_aix_cleanup () {
2062: :
2063: }
2064:
2065: pp_backend_aix_names () {
1.1.1.2 ! misho 2066: echo "$name.`[ $pp_aix_version ] && pp_aix_version_fix $pp_aix_version || pp_aix_version_fix "$version"`.bff"
1.1 misho 2067: }
2068:
2069: pp_backend_aix_install_script () {
2070: typeset pkgname platform
2071: #
2072: # The script should take a first argument being the
2073: # operation; further arguments refer to components or services
2074: #
2075: # list-components -- lists components in the pkg
2076: # install component... -- installs the components
2077: # uninstall component... -- uninstalles the components
2078: # list-services -- lists the services in the pkg
2079: # start service... -- starts the name service
2080: # stop service... -- stops the named services
2081: # print-platform -- prints the platform group
2082: #
2083: pkgname="`pp_backend_aix_names`"
2084: platform="`pp_backend_aix_probe`" # XXX should be derived from files
2085:
2086: fsets=
2087: for cmp in $pp_components; do
2088: case "$cmp" in
2089: run) ex=rte;;
2090: doc) ex=doc;;
2091: dev) ex=adt;;
2092: dbg) ex=diag;;
2093: esac
2094: fsets="$fsets $name.$ex"
2095: done
2096:
2097: echo '#!/bin/sh'
2098: pp_install_script_common
2099:
2100: cat <<-.
2101:
2102: cpt_to_fileset () {
2103: test x"\$*" = x"all" &&
2104: set -- $pp_components
2105: for cpt
2106: do
2107: case "\$cpt" in
2108: run) echo "$name.rte";;
2109: doc) echo "$name.doc";;
2110: dev) echo "$name.adt";;
2111: dbg) echo "$name.diag";;
2112: *) usage;;
2113: esac
2114: done
2115: }
2116:
2117: test \$# -eq 0 && usage
2118: op="\$1"; shift
2119:
2120: case "\$op" in
2121: list-components)
2122: test \$# -eq 0 || usage \$op
2123: echo "$pp_components"
2124: ;;
2125: list-services)
2126: test \$# -eq 0 || usage \$op
2127: echo "$pp_services"
2128: ;;
2129: list-files)
2130: test \$# -ge 1 || usage \$op
2131: echo \${PP_PKGDESTDIR:-.}/$pkgname
2132: ;;
2133: install)
2134: test \$# -ge 1 || usage \$op
2135: verbose /usr/sbin/installp -acX -V0 -F \
2136: -d \${PP_PKGDESTDIR:-.}/$pkgname \
2137: \`cpt_to_fileset "\$@"\`
2138: ;;
2139: uninstall)
2140: test \$# -ge 1 || usage \$op
2141: verbose /usr/sbin/installp -u -e/dev/null \
2142: -V0 \`cpt_to_fileset "\$@"\`
2143: ;;
2144: start|stop)
2145: test \$# -ge 1 || usage \$op
2146: ec=0
2147: for svc
2148: do
2149: verbose \${op}src -s \$svc || ec=1
2150: done
2151: exit \$ec
2152: ;;
2153: print-platform)
2154: echo "$platform"
2155: ;;
2156: *)
2157: usage;;
2158: esac
2159: .
2160: }
2161:
2162: pp_backend_aix_init_svc_vars () {
2163: :
2164: }
2165:
2166: pp_backend_aix_probe () {
2167: echo "${pp_aix_os}-${pp_aix_arch_std}"
2168: }
2169:
2170: pp_backend_aix_vas_platforms () {
2171: case "${pp_aix_arch_std}" in
2172: ppc*) :;;
2173: *) pp_die "unknown architecture ${pp_aix_arch_std}";;
2174: esac
2175: case "${pp_aix_os}" in
2176: aix43) echo "aix-43";;
2177: aix51) echo "aix-51 aix-43";;
2178: aix52) echo "aix-51 aix-43";;
2179: aix53) echo "aix-53 aix-51 aix-43";;
2180: aix61) echo "aix-53 aix-51 aix-43";;
2181: *) pp_die "unknown system ${pp_aix_os}";;
2182: esac
2183: }
2184: pp_backend_aix_function () {
1.1.1.2 ! misho 2185: case "$1" in
1.1 misho 2186: pp_mkgroup) cat <<'.';;
2187: /usr/sbin/lsgroup "$1" >/dev/null &&
2188: return 0
2189: echo "Creating group $1"
2190: /usr/bin/mkgroup -A "$1"
2191: .
2192: pp_mkuser:depends) echo pp_mkgroup;;
2193: pp_mkuser) cat <<'.';;
2194: /usr/sbin/lsuser "$1" >/dev/null &&
2195: return 0
2196: pp_mkgroup "${2:-$1}" || return 1
2197: echo "Creating user $1"
2198: /usr/bin/mkuser \
2199: login=false \
2200: rlogin=false \
2201: account_locked=true \
2202: home="${3:-/nohome.$1}" \
2203: pgrp="${2:-$1}" \
2204: "$1"
2205: .
2206: pp_havelib) cat <<'.';;
2207: case "$2" in
2208: "") pp_tmp_name="lib$1.so";;
2209: *.*.*) pp_tmp_name="lib$1.so.$2";;
2210: *.*) pp_tmp_name="lib$1.so.$2.0";;
2211: *) pp_tmp_name="lib$1.so.$2";;
2212: esac
2213: for pp_tmp_dir in `echo "/usr/lib:/lib${3:+:$3}" | tr : ' '`; do
2214: test -r "$pp_tmp_dir/$pp_tmp_name" -a \
2215: -r "$pp_tmp_dir/lib$1.so" && return 0
2216: done
2217: return 1
2218: .
2219: *) false;;
2220: esac
2221: }
2222:
2223: pp_platforms="$pp_platforms sd"
2224:
2225: pp_backend_sd_detect () {
2226: test x"$1" = x"HP-UX"
2227: }
2228:
2229: pp_backend_sd_init () {
2230: pp_sd_sudo=
2231: pp_sd_startlevels=2
2232: pp_sd_stoplevels=auto
2233: pp_sd_config_file=
2234: pp_sd_vendor=
2235: pp_sd_vendor_tag=Quest
2236: pp_sd_default_start=1 # config_file default start value
2237:
2238: pp_readlink_fn=pp_ls_readlink # HPUX has no readlink
2239: pp_shlib_suffix='.sl' # .so on most other platforms
2240:
2241: pp_sd_detect_os
2242: }
2243:
2244: pp_sd_detect_os () {
2245: typeset revision
2246:
2247: revision=`uname -r`
2248: pp_sd_os="${revision#?.}"
2249: test -z "$pp_sd_os" &&
2250: pp_warn "cannot detect OS version"
2251: pp_sd_os_std="hpux`echo $pp_sd_os | tr -d .`"
2252:
2253: case "`uname -m`" in
2254: 9000/[678]??) pp_sd_arch_std=hppa;;
2255: ia64) pp_sd_arch_std=ia64;;
2256: *) pp_sd_arch_std=unknown;;
2257: esac
2258: }
2259:
2260: pp_sd_write_files () {
2261: typeset t m o g f p st line dm
2262: while read t m o g f p st; do
2263: line=" file"
2264: case "$f" in *v*) line="$line -v";; esac # FIXME for uninstall
2265: case ${pp_sd_os} in
2266: 10.*)
2267: case $t in
2268: f) dm=644;;
2269: d) p=${p%/}; dm=755;;
2270: esac
2271: ;;
2272: *)
2273: case $t in
2274: f) dm=644;;
2275: d) line="$line -t d"; p=${p%/}; dm=755;;
2276: s) line="$line -t s";;
2277: esac
2278: ;;
2279: esac
2280:
2281: test x"$o" = x"-" && o=root
2282: test x"$g" = x"-" && g=sys
2283: test x"$m" = x"-" && m=$dm
2284:
2285: case $t in
1.1.1.2 ! misho 2286: s)
! 2287: # swpackage will make unqualified links relative to the
! 2288: # current working (source) directory, not the destination;
! 2289: # we need to qualify them to prevent this.
! 2290: case "$st" in
! 2291: /*) echo "$line $st $p";;
! 2292: *) echo "$line `dirname $p`/$st $p";;
! 2293: esac
! 2294: ;;
! 2295: *)
! 2296: echo "$line -o $o -g $g -m $m $pp_destdir$p $p"
! 2297: ;;
1.1 misho 2298: esac
2299:
2300: done
2301: }
2302:
2303: pp_sd_service_group_script () {
2304: typeset grp svcs scriptpath out
2305: grp="$1"
2306: svcs="$2"
2307: scriptpath="/sbin/init.d/$grp"
2308: out="$pp_destdir$scriptpath"
2309:
2310: pp_add_file_if_missing $scriptpath run 755 || return 0
2311:
2312: cat <<-. > $out
2313: #!/sbin/sh
2314: # generated by pp $pp_version
2315: svcs="$svcs"
2316: .
2317:
2318: cat <<-'.' >> $out
1.1.1.2 ! misho 2319: #-- starts services in order.. stops them all if any break
! 2320: pp_start () {
! 2321: undo=
! 2322: for svc in \$svcs; do
! 2323: /sbin/init.d/\$svc start
! 2324: case \$? in
! 2325: 0|4)
! 2326: undo="\$svc \$undo"
! 2327: ;;
! 2328: *)
! 2329: if test -n "\$undo"; then
! 2330: for svc in \$undo; do
! 2331: /sbin/init.d/\$svc stop
! 2332: done
! 2333: return 1
! 2334: fi
! 2335: ;;
! 2336: esac
! 2337: done
! 2338: return 0
! 2339: }
1.1 misho 2340:
1.1.1.2 ! misho 2341: #-- stops services in reverse
! 2342: pp_stop () {
! 2343: reverse=
! 2344: for svc in \$svcs; do
! 2345: reverse="\$svc \$reverse"
! 2346: done
! 2347: rc=0
! 2348: for svc in \$reverse; do
! 2349: /sbin/init.d/\$svc stop || rc=\$?
! 2350: done
! 2351: return \$rc
1.1 misho 2352: }
2353:
1.1.1.2 ! misho 2354: case \$1 in
! 2355: start_msg) echo "Starting \$svcs";;
! 2356: stop_msg) echo "Stopping \$svcs";;
1.1 misho 2357: start) pp_start;;
2358: stop) pp_stop;;
1.1.1.2 ! misho 2359: *) echo "usage: \$0 {start|stop|start_msg|stop_msg}"
! 2360: exit 1;;
! 2361: esac
1.1 misho 2362: .
2363: }
2364:
2365: pp_sd_service_script () {
2366: typeset svc config_file config_value scriptpath out
2367:
2368: svc="$1"
2369: scriptpath="/sbin/init.d/$svc"
2370:
2371: config_file=${pp_sd_config_file:-/etc/rc.config.d/$svc}
2372: sd_config_var=`echo run-$svc | tr '[a-z]-' '[A-Z]_'`
2373: sd_config_value=${pp_sd_default_start:-0}
2374: pp_load_service_vars "$svc"
2375:
2376: test -n "$user" -a x"$user" != x"root" &&
2377: cmd="SHELL=/usr/bin/sh /usr/bin/su $user -c \"exec `echo $cmd | sed -e 's,[$\\\`],\\&,g'`\""
2378: if test -z "$pidfile"; then
2379: pidfile="/var/run/$svc.pid"
2380: cmd="$cmd & echo \$! > \$pidfile"
2381: fi
2382:
2383: pp_debug "config file is $config_file"
2384:
2385: pp_add_file_if_missing $scriptpath run 755
2386: pp_add_file_if_missing $config_file run 644 v
2387:
2388: cat <<-. >> $pp_destdir$config_file
2389:
2390: # Controls whether the $svc service is started
2391: $sd_config_var=$sd_config_value
2392: .
2393:
2394: if test ! -f $pp_destdir$scriptpath; then
2395: cat <<-. > $pp_destdir$scriptpath
2396: #!/sbin/sh
2397: # generated by pp $pp_version
2398:
2399: svc="$svc"
2400: pidfile="$pidfile"
2401: config_file="$config_file"
2402:
2403: pp_start () {
2404: $cmd
2405: }
2406:
2407: pp_disabled () {
2408: test \${$sd_config_var:-0} -eq 0
2409: }
2410:
2411: pp_stop () {
1.1.1.2 ! misho 2412: if test ! -s "\$pidfile"; then
! 2413: echo "Unable to stop \$svc (no pid file)"
! 2414: return 1
1.1 misho 2415: else
1.1.1.2 ! misho 2416: read pid < "\$pidfile"
! 2417: if kill -0 "\$pid" 2>/dev/null; then
! 2418: if kill -${stop_signal:-TERM} "\$pid"; then
! 2419: rm -f "\$pidfile"
! 2420: return 0
! 2421: else
! 2422: echo "Unable to stop \$svc"
! 2423: return 1
! 2424: fi
! 2425: else
! 2426: rm -f "\$pidfile"
! 2427: return 0
! 2428: fi
1.1 misho 2429: fi
2430: }
2431:
2432: pp_running () {
1.1.1.2 ! misho 2433: if test ! -s "\$pidfile"; then
! 2434: return 1
1.1 misho 2435: else
1.1.1.2 ! misho 2436: read pid < "\$pidfile"
! 2437: kill -0 "\$pid" 2>/dev/null
1.1 misho 2438: fi
2439: }
2440:
1.1.1.2 ! misho 2441: case \$1 in
! 2442: start_msg) echo "Starting the \$svc service";;
! 2443: stop_msg) echo "Stopping the \$svc service";;
1.1 misho 2444: start)
1.1.1.2 ! misho 2445: if test -f "\$config_file"; then
! 2446: . \$config_file
! 2447: fi
! 2448: if pp_disabled; then
! 2449: exit 2
! 2450: elif pp_running; then
! 2451: echo "\$svc already running";
! 2452: exit 0
! 2453: elif pp_start; then
! 2454: echo "\$svc started";
! 2455: # rc(1M) says we should exit 4, but nobody expects it!
! 2456: exit 0
! 2457: else
! 2458: exit 1
! 2459: fi;;
1.1 misho 2460: stop) if pp_stop; then
1.1.1.2 ! misho 2461: echo "\$svc stopped";
! 2462: exit 0
! 2463: else
! 2464: exit 1
! 2465: fi;;
! 2466: *) echo "usage: \$0 {start|stop|start_msg|stop_msg}"
1.1 misho 2467: exit 1;;
2468: esac
2469: .
2470: fi
2471: }
2472:
2473: pp_sd_make_service () {
2474: typeset level startpriority stoppriority startlevels stoplevels
2475: typeset svc svcvar symtype
2476:
2477: svc="$1"
2478: svcvar=`pp_makevar $svc`
2479:
2480: case ${pp_sd_os} in
2481: 10.*) symtype="file";;
2482: *) symtype="file -t s";;
2483: esac
2484:
2485: # TODO: Figure out why this check is here
2486: #-- don't do anything if the script exists
2487: #if test -s "$pp_destdir/sbin/init.d/$svc"; then
2488: # pp_error "$pp_destdir/sbin/init.d/$svc exists"
2489: # return
2490: #fi
2491:
2492: # symlink the script, depending on the priorities chosen
2493: eval startpriority='${pp_sd_startpriority_'$svcvar'}'
2494: eval stoppriority='${pp_sd_stoppriority_'$svcvar'}'
2495: test -z "$startpriority" && startpriority="${pp_sd_startpriority:-50}"
2496: test -z "$stoppriority" && stoppriority="${pp_sd_stoppriority:-50}"
2497:
2498: eval startlevels='${pp_sd_startlevels_'$svcvar'}'
2499: test -z "$startlevels" && startlevels="$pp_sd_startlevels"
2500:
2501: eval stoplevels='${pp_sd_stoplevels_'$svcvar'}'
2502: test -z "$stoplevels" && stoplevels="$pp_sd_stoplevels"
2503:
2504: # create the script and config file
2505: pp_sd_service_script $svc
2506:
2507: # fix the priority up
2508: case "$startpriority" in
2509: ???) :;;
2510: ??) startpriority=0$startpriority;;
2511: ?) startpriority=00$startpriority;;
2512: esac
2513: case "$stoppriority" in
2514: ???) :;;
2515: ??) stoppriority=0$stoppriority;;
2516: ?) stoppriority=00$stoppriority;;
2517: esac
2518:
2519: if test x"$stoplevels" = x"auto"; then
2520: stoplevels=
2521: test -z "$startlevels" || for level in $startlevels; do
2522: stoplevels="$stoplevels `expr $level - 1`"
2523: done
2524: fi
2525:
2526: # create the symlinks
2527: test -z "$startlevels" || for level in $startlevels; do
2528: echo " ${symtype}" \
2529: "/sbin/init.d/$svc" \
2530: "/sbin/rc$level.d/S$startpriority$svc"
2531: done
2532: test -z "$stoplevels" || for level in $stoplevels; do
2533: echo " ${symtype}" \
2534: "/sbin/init.d/$svc" \
2535: "/sbin/rc$level.d/K$stoppriority$svc"
2536: done
2537: }
2538:
2539: pp_sd_control () {
2540: typeset ctrl script
2541: typeset cpt
2542:
2543: ctrl="$1"; shift
2544: cpt="$1"; shift
2545: script="$pp_wrkdir/control.$ctrl.$cpt"
2546: cat <<. >$script
2547: .
2548: cat "$@" >> $script
2549: echo "exit 0" >> $script
2550: /usr/bin/chmod +x $script
2551: echo " $ctrl $script"
2552: }
2553:
1.1.1.2 ! misho 2554: pp_sd_depend () {
! 2555: typeset _name _vers
! 2556: while read _name _vers; do
! 2557: case "$_name" in ""| "#"*) continue ;; esac
! 2558: echo " prerequisites $_name ${_vers:+r>= $_vers}"
! 2559: done
! 2560: }
! 2561:
! 2562: pp_sd_conflict () {
! 2563: typeset _name _vers
! 2564: while read _name _vers; do
! 2565: case "$_name" in ""| "#"*) continue ;; esac
! 2566: echo " exrequisites $_name ${_vers:+r>= $_vers}"
! 2567: done
! 2568: }
! 2569:
1.1 misho 2570: pp_backend_sd () {
2571: typeset psf cpt svc outfile release swp_flags
2572:
2573: psf=$pp_wrkdir/psf
2574: release="?.${pp_sd_os%.[0-9][0-9]}.*"
2575:
2576: echo "depot" > $psf
2577: echo "layout_version 1.0" >>$psf
2578:
2579: #-- vendor
2580: cat <<. >>$psf
2581: vendor
2582: tag $pp_sd_vendor_tag
2583: title "${pp_sd_vendor:-$vendor}"
2584: end
2585:
2586: product
2587: tag $name
2588: revision $version
2589: vendor_tag $pp_sd_vendor_tag
2590: is_patch false
2591: title "$summary"
2592: copyright "$copyright"
2593: machine_type *
2594: os_name HP-UX
2595: os_release $release
2596: os_version ?
2597: directory /
2598: is_locatable false
2599: .
2600: test -n "$description" \
2601: && echo $description > $pp_wrkdir/description \
2602: && cat <<. >> $psf
2603: description < $pp_wrkdir/description
2604: .
2605:
2606: # make convenience service groups
2607: if test -n "$pp_service_groups"; then
2608: for grp in $pp_service_groups; do
2609: pp_sd_service_group_script \
2610: $grp "`pp_service_get_svc_group $grp`"
2611: done
2612: fi
2613:
2614: for cpt in $pp_components; do
2615: cat <<. >>$psf
2616: fileset
2617: tag ${pp_sd_fileset_tag:-$cpt}
2618: title "${summary:-cpt}"
2619: revision $version
2620: .
1.1.1.2 ! misho 2621: test -s $pp_wrkdir/%depend.$cpt &&
! 2622: pp_sd_depend < $pp_wrkdir/%depend.$cpt >> $psf
! 2623: test -s $pp_wrkdir/%conflict.$cpt &&
! 2624: pp_sd_conflict < $pp_wrkdir/%conflict.$cpt >> $psf
1.1 misho 2625:
2626: #-- make sure services are shut down during uninstall
2627: if test $cpt = run -a -n "$pp_services"; then
2628: for svc in $pp_services; do
2629: pp_prepend $pp_wrkdir/%preun.$cpt <<-.
2630: /sbin/init.d/$svc stop
2631: .
2632: done
2633: fi
2634:
2635: #-- we put the post/preun code into configure/unconfigure
2636: # and not postinstall/preremove, because configure/unconfigure
2637: # scripts are run on the hosts where the package is installed,
2638: # not loaded (a subtle difference).
2639: test -s $pp_wrkdir/%pre.$cpt &&
2640: pp_sd_control checkinstall $cpt $pp_wrkdir/%pre.$cpt >> $psf
2641: test -s $pp_wrkdir/%post.$cpt &&
2642: pp_sd_control configure $cpt $pp_wrkdir/%post.$cpt >> $psf
2643: test -s $pp_wrkdir/%preun.$cpt &&
2644: pp_sd_control unconfigure $cpt $pp_wrkdir/%preun.$cpt >> $psf
2645: test -s $pp_wrkdir/%postun.$cpt &&
2646: pp_sd_control postremove $cpt $pp_wrkdir/%postun.$cpt >> $psf
2647: test -s $pp_wrkdir/%check.$cpt &&
2648: pp_sd_control checkinstall $cpt $pp_wrkdir/%check.$cpt >> $psf
2649:
2650: if test $cpt = run -a -n "$pp_services"; then
2651: for svc in $pp_services; do
2652: #-- service names are 10 chars max on hpux
2653: case "$svc" in ???????????*)
2654: pp_warn "service name '$svc' is too long for hpux";;
2655: esac
2656: pp_sd_make_service $svc >> $psf
2657: done
2658: #pp_sd_make_service_config
2659: fi
2660:
2661: pp_sd_write_files < $pp_wrkdir/%files.$cpt >> $psf
2662:
2663: #-- end fileset clause
2664: cat <<. >>$psf
2665: end
2666: .
2667:
2668: done
2669:
2670: #-- end product clause
2671: cat <<. >>$psf
2672: end
2673: .
2674:
2675: $pp_opt_debug && cat $psf >&2
2676:
2677: test -s $pp_wrkdir/%fixup && . $pp_wrkdir/%fixup
2678:
2679: outfile=`pp_backend_sd_names`
2680: case ${pp_sd_os} in
2681: 10.*)
2682: swp_flags="-x target_type=tape"
2683: ;;
2684: *)
2685: swp_flags="-x media_type=tape"
2686: ;;
2687: esac
2688: if pp_verbose ${pp_sd_sudo} /usr/sbin/swpackage -s $psf $swp_flags \
2689: @ $pp_wrkdir/$outfile
2690: then
2691: pp_verbose ${pp_sd_sudo} /usr/sbin/swlist -l file -s $pp_wrkdir/$outfile
2692: else
2693: pp_error "swpackage failed"
2694: fi
2695: }
2696:
2697: pp_backend_sd_cleanup () {
2698: :
2699: }
2700:
2701: pp_backend_sd_names () {
2702: echo "$name-$version.$pp_sd_arch_std.depot"
2703: }
2704:
2705: pp_backend_sd_install_script () {
2706: typeset pkgname platform
2707:
2708: pkgname=`pp_backend_sd_names`
2709: platform="`pp_backend_sd_probe`"
2710:
2711: echo "#!/bin/sh"
2712: pp_install_script_common
2713: cat <<.
2714:
2715: cpt_to_tags () {
2716: test x"\$*" = x"all" && set -- $pp_components
2717: for cpt
2718: do
2719: echo "$name.\$cpt"
2720: done
2721: }
2722:
2723: test \$# -eq 0 && usage
2724: op="\$1"; shift
2725:
2726: case "\$op" in
2727: list-components)
2728: test \$# -eq 0 || usage \$op
2729: echo "$pp_components"
2730: ;;
2731: list-services)
2732: test \$# -eq 0 || usage \$op
2733: echo "$pp_services"
2734: ;;
2735: list-files)
2736: test \$# -ge 1 || usage \$op
2737: echo \${PP_PKGDESTDIR:-.}/$pkgname
2738: ;;
2739: install)
2740: test \$# -ge 1 || usage \$op
2741: verbose /usr/sbin/swinstall -x verbose=0 \
2742: -s \${PP_PKGDESTDIR:-\`pwd\`}/$pkgname \
2743: \`cpt_to_tags "\$@"\`
2744: ;;
2745: uninstall)
2746: test \$# -ge 1 || usage \$op
2747: verbose /usr/sbin/swremove -x verbose=0 \
2748: \`cpt_to_tags "\$@"\`
2749: ;;
2750: start|stop)
2751: test \$# -ge 1 || usage \$op
2752: ec=0
2753: for svc
2754: do
2755: verbose /sbin/init.d/\$svc \$op
2756: [ \$? -eq 4 -o \$? -eq 0 ] || ec=1
2757: done
2758: exit \$ec
2759: ;;
2760: print-platform)
2761: echo "$platform"
2762: ;;
2763: *)
2764: usage
2765: ;;
2766: esac
2767: .
2768: }
2769:
2770: pp_backend_sd_probe () {
2771: echo "${pp_sd_os_std}-${pp_sd_arch_std}"
2772: }
2773:
2774: pp_backend_sd_vas_platforms () {
2775: case "`pp_backend_sd_probe`" in
2776: hpux*-hppa) echo hpux-pa;;
2777: hpux*-ia64) echo hpux-ia64 hpux-pa;;
2778: *) pp_die "unknown system `pp_backend_sd_probe`";;
2779: esac
2780: }
2781:
2782: pp_backend_sd_init_svc_vars () {
2783: :
2784: }
2785: pp_backend_sd_function () {
1.1.1.2 ! misho 2786: case "$1" in
1.1 misho 2787: pp_mkgroup) cat <<'.';;
2788: /usr/sbin/groupmod "$1" 2>/dev/null ||
2789: /usr/sbin/groupadd "$1"
2790: .
2791: pp_mkuser:depends) echo pp_mkgroup;;
2792: pp_mkuser) cat <<'.';;
2793: pp_mkgroup "${2:-$1}" || return 1
2794: /usr/sbin/useradd \
2795: -g "${2:-$1}" \
2796: -d "${3:-/nonexistent}" \
2797: -s "${4:-/bin/false}" \
2798: "$1"
2799: .
2800: pp_havelib) cat <<'.';;
2801: for pp_tmp_dir in `echo /usr/lib${3:+:$3} | tr : ' '`; do
2802: test -r "$pp_tmp_dir/lib$1${2:+.$2}.sl" && return 0
2803: done
2804: return 1
2805: .
2806: *) false;;
2807: esac
2808: }
2809:
2810: pp_platforms="$pp_platforms solaris"
2811:
2812: pp_backend_solaris_detect () {
2813: test x"$1" = x"SunOS"
2814: }
2815:
2816: pp_backend_solaris_init () {
2817: pp_solaris_category=
2818: pp_solaris_istates="s S 1 2 3" # run-states when install is ok
2819: pp_solaris_rstates="s S 1 2 3" # run-states when remove is ok
2820: pp_solaris_maxinst=
2821: pp_solaris_vendor=
2822: pp_solaris_pstamp=
2823: pp_solaris_copyright=
2824: pp_solaris_name=
2825: pp_solaris_desc=
2826: pp_solaris_package_arch=auto
2827:
2828: pp_solaris_detect_os
2829: pp_solaris_detect_arch
2830:
2831: pp_solaris_init_svc
2832:
2833: #-- readlink not reliably available on Solaris
2834: pp_readlink_fn=pp_ls_readlink
2835: }
2836:
2837: pp_solaris_detect_os () {
2838: typeset osrel
2839:
2840: osrel=`/usr/bin/uname -r`
2841: case "$osrel" in
2842: 5.[0-6]) pp_solaris_os="sol2${osrel#5.}";;
2843: 5.*) pp_solaris_os="sol${osrel#5.}";;
2844: esac
2845: test -z "$pp_solaris_os" &&
2846: pp_warn "can't determine OS suffix from uname -r"
2847:
2848: }
2849:
2850: pp_solaris_detect_arch () {
2851: pp_solaris_arch=`/usr/bin/optisa amd64 sparcv9 i386 sparc`
2852: [ -z "$pp_solaris_arch" ] &&
2853: pp_error "can't determine processor architecture"
2854: case "$pp_solaris_arch" in
2855: amd64) pp_solaris_arch_std=x86_64;;
2856: i386) pp_solaris_arch_std=i386;;
2857: sparcv9) pp_solaris_arch_std=sparc64;;
2858: sparc) pp_solaris_arch_std=sparc;;
2859: *) pp_solaris_arch_std=unknown;;
2860: esac
2861: }
2862:
2863: pp_solaris_is_request_script_necessary () {
2864: typeset has_optional_services
2865:
2866: has_optional_services=no
2867: for _svc in $pp_services; do
2868: pp_load_service_vars $_svc
2869: if test "$optional" = "yes"; then
2870: has_optional_services=yes
2871: fi
2872: done
2873:
2874: # If the package has no optional services and only one component, don't
2875: # create a request script at all.
2876: if test "$has_optional_services" = "no" &&
2877: test `echo $pp_components | wc -w` -eq 1; then
2878: return 1 # no
2879: fi
2880:
2881: return 0 # yes
2882: }
2883:
2884: pp_solaris_request () {
2885: typeset _cmp _svc
2886:
2887: #-- The common part of the request script contains the ask() function
2888: # and resets the CLASSES list to empty
2889: cat <<'.'
2890: trap 'exit 3' 15
2891: ask () {
2892: ans=`ckyorn -d "$1" \
2893: -p "Do you want to $2"` \
2894: || exit $?
2895: case "$ans" in y*|Y*) return 0;; *) return 1;; esac
2896: }
2897: CLASSES=
2898: .
2899: #-- each of our components adds itself to the CLASSES list
2900: for _cmp in $pp_components; do
2901: case "$_cmp" in
2902: run) :;;
2903: doc) echo 'ask y "install the documentation files" &&';;
2904: dev) echo 'ask y "install the development files" &&';;
2905: dbg) echo 'ask n "install the diagnostic files" &&';;
2906: esac
2907: echo ' CLASSES="$CLASSES '$_cmp'"'
2908: done
2909:
2910: #-- the request script writes the CLASSES var to its output
2911: cat <<'.'
2912: echo "CLASSES=$CLASSES" > $1
2913: .
2914:
2915: if test -n "$pp_services"; then
2916: echo 'SERVICES='
2917: for _svc in $pp_services; do
2918: pp_load_service_vars $_svc
2919: if test "$enable" = "yes"; then
2920: _default_prompt=y
2921: else
2922: _default_prompt=n
2923: fi
2924: if test "$optional" = "yes"; then
2925: echo 'ask '$_default_prompt' "install '$_svc' service" &&'
2926: fi
2927: echo ' SERVICES="$SERVICES '$_svc'"'
2928: done
2929: echo 'echo "SERVICES=$SERVICES" >> $1'
2930: fi
2931:
2932: }
2933:
2934: pp_solaris_procedure () {
2935: cat <<.
2936:
2937: #-- $2 for $1 component of $name
2938: case " \$CLASSES " in *" $1 "*)
2939: .
2940: cat
2941: cat <<.
2942: ;; esac
2943: .
2944: }
2945:
2946: pp_solaris_depend () {
2947: typeset _name _vers
2948: while read _name _vers; do
2949: if test -n "$_name"; then
2950: echo "P $_name $_name"
2951: test -n "$_vers" && echo " $_vers"
2952: fi
2953: done
2954: }
2955:
1.1.1.2 ! misho 2956: pp_solaris_conflict () {
! 2957: typeset _name _vers
! 2958: while read _name _vers; do
! 2959: if test -n "$_name"; then
! 2960: echo "I $_name $_name"
! 2961: test -n "$_vers" && echo " $_vers"
! 2962: fi
! 2963: done
! 2964: }
! 2965:
1.1 misho 2966: pp_solaris_space() {
2967: echo "$2:$3:$1" >> $pp_wrkdir/space.cumulative
2968: }
2969:
2970: pp_solaris_sum_space () {
2971: if test -s $pp_wrkdir/space.cumulative; then
2972: sort -t: +2 < $pp_wrkdir/space.cumulative |
2973: 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
2974: fi
2975: }
2976:
2977: pp_solaris_proto () {
2978: typeset t m o g f p st
2979: typeset abi
2980:
2981: while read t m o g f p st; do
1.1.1.2 ! misho 2982: # Use Solaris default mode, owner and group if all unspecified
! 2983: if test x"$m$o$g" = x"---"; then
! 2984: m="?"; o="?"; g="?"
! 2985: fi
! 2986: test x"$o" = x"-" && o="root"
1.1 misho 2987: case "$t" in
1.1.1.2 ! misho 2988: f) test x"$g" = x"-" && g="bin"
! 2989: test x"$m" = x"-" && m=444
1.1 misho 2990: case "$f" in
2991: *v*) echo "v $1 $p=$pp_destdir$p $m $o $g";;
2992: *) echo "f $1 $p=$pp_destdir$p $m $o $g";;
2993: esac
2994: if test -r "$pp_destdir$p"; then
2995: #-- Use file to record ABI types seen
2996: case "`file "$pp_destdir$p"`" in
2997: *"ELF 32"*80386*) abi=i386;;
2998: *"ELF 64"*AMD*) abi=x86_64;;
2999: *"ELF 32"*SPARC*) abi=sparc;;
3000: *"ELF 64"*SPARC*) abi=sparc64;;
3001: *) abi=;;
3002: esac
3003: if test -n "$abi"; then
3004: pp_add_to_list pp_solaris_abis_seen $abi
3005: fi
3006: fi
3007: ;;
1.1.1.2 ! misho 3008: d) test x"$g" = x"-" && g="sys"
! 3009: test x"$m" = x"-" && m=555
1.1 misho 3010: echo "d $1 $p $m $o $g"
3011: ;;
1.1.1.2 ! misho 3012: s) test x"$g" = x"-" && g="bin"
! 3013: test x"$m" = x"-" && m=777
! 3014: if test x"$m" != x"777" -a x"$m" != x"?"; then
1.1 misho 3015: pp_warn "$p: invalid mode $m for symlink, should be 777 or -"
1.1.1.2 ! misho 3016: fi
1.1 misho 3017: echo "s $1 $p=$st $m $o $g"
3018: ;;
3019: esac
3020: done
3021: }
3022:
3023: pp_backend_solaris () {
3024: typeset _cmp _svc _grp
3025:
3026: prototype=$pp_wrkdir/prototype
3027: : > $prototype
3028:
3029: pkginfo=$pp_wrkdir/pkginfo
3030: : > $pkginfo
3031: echo "i pkginfo=$pkginfo" >> $prototype
3032:
3033: case "${pp_solaris_name:-$name}" in
3034: [0-9]*)
3035: pp_error "Package name '${pp_solaris_name:-$name}'" \
3036: "cannot start with a number"
3037: ;;
3038: ???????????????*)
3039: pp_warn "Package name '${pp_solaris_name:-$name}'" \
3040: "too long for Solaris 2.6 or 2.7 (max 9 characters)"
3041: ;;
3042: ??????????*)
3043: pp_warn "Package name '${pp_solaris_name:-$name}'" \
3044: "too long for 2.7 Solaris (max 9 characters)"
3045: ;;
3046: esac
3047:
3048: #-- generate the package info file
3049: echo "VERSION=$version" >> $pkginfo
3050: echo "PKG=${pp_solaris_name:-$name}" >> $pkginfo
3051: echo "CLASSES=$pp_components" >> $pkginfo
3052: echo "BASEDIR=/" >> $pkginfo
3053: echo "NAME=$name $version" >> $pkginfo
3054: echo "CATEGORY=${pp_solaris_category:-application}" >> $pkginfo
3055:
3056: desc="${pp_solaris_desc:-$description}"
3057: test -n "$desc" &&
3058: echo "DESC=$desc" >> $pkginfo
3059:
3060: test -n "$pp_solaris_rstates" &&
3061: echo "RSTATES=$pp_solaris_rstates" >> $pkginfo
3062: test -n "$pp_solaris_istates" &&
3063: echo "ISTATES=$pp_solaris_istates" >> $pkginfo
3064: test -n "$pp_solaris_maxinst" &&
3065: echo "MAXINST=$pp_solaris_maxinst" >> $pkginfo
3066: test -n "${pp_solaris_vendor:-$vendor}" &&
3067: echo "VENDOR=${pp_solaris_vendor:-$vendor}" >> $pkginfo
3068: test -n "$pp_solaris_pstamp" &&
3069: echo "PSTAMP=$pp_solaris_pstamp" >> $pkginfo
3070:
3071: if test -n "${pp_solaris_copyright:-$copyright}"; then
3072: echo "${pp_solaris_copyright:-$copyright}" > $pp_wrkdir/copyright
3073: echo "i copyright=$pp_wrkdir/copyright" >> $prototype
3074: fi
3075:
3076: #-- scripts to run before and after install
3077: : > $pp_wrkdir/postinstall
3078: : > $pp_wrkdir/preremove
1.1.1.2 ! misho 3079: : > $pp_wrkdir/postremove
1.1 misho 3080: for _cmp in $pp_components; do
3081: #-- add the preinstall scripts in definition order
3082: if test -s $pp_wrkdir/%pre.$_cmp; then
3083: pp_solaris_procedure $_cmp preinst < $pp_wrkdir/%pre.$_cmp \
3084: >> $pp_wrkdir/preinstall
3085: fi
3086: #-- add the postinstall scripts in definition order
3087: if test -s $pp_wrkdir/%post.$_cmp; then
3088: pp_solaris_procedure $_cmp postinst < $pp_wrkdir/%post.$_cmp \
3089: >> $pp_wrkdir/postinstall
3090: fi
3091: #-- add the preremove rules in reverse definition order
3092: if test -s $pp_wrkdir/%preun.$_cmp; then
3093: pp_solaris_procedure $_cmp preremove < $pp_wrkdir/%preun.$_cmp |
3094: pp_prepend $pp_wrkdir/preremove
3095: fi
1.1.1.2 ! misho 3096: #-- add the postremove scripts in definition order
! 3097: if test -s $pp_wrkdir/%postun.$_cmp; then
! 3098: pp_solaris_procedure $_cmp postremove < $pp_wrkdir/%postun.$_cmp \
! 3099: >> $pp_wrkdir/postremove
! 3100: fi
1.1 misho 3101: #-- Add the check script in definition order
3102: if test -s $pp_wrkdir/%check.$_cmp; then
3103: pp_solaris_procedure $_cmp checkinstall \
3104: < $pp_wrkdir/%check.$_cmp \
3105: >> $pp_wrkdir/checkinstall
3106: fi
1.1.1.2 ! misho 3107: #-- All dependencies and conflicts are merged together for Solaris pkgs
1.1 misho 3108: test -s $pp_wrkdir/%depend.$_cmp &&
1.1.1.2 ! misho 3109: pp_solaris_depend < $pp_wrkdir/%depend.$_cmp >> $pp_wrkdir/depend
! 3110: test -s $pp_wrkdir/%conflict.$_cmp &&
! 3111: pp_solaris_conflict < $pp_wrkdir/%conflict.$_cmp >> $pp_wrkdir/depend
1.1 misho 3112: done
3113:
3114:
3115: if pp_solaris_is_request_script_necessary; then
3116: pp_solaris_request > $pp_wrkdir/request
3117: fi
3118:
3119: test -n "$pp_services" &&
3120: for _svc in $pp_services; do
3121: pp_load_service_vars $_svc
3122: pp_solaris_smf $_svc
3123: pp_solaris_make_service $_svc
3124: pp_solaris_install_service $_svc | pp_prepend $pp_wrkdir/postinstall
3125: pp_solaris_remove_service $_svc | pp_prepend $pp_wrkdir/preremove
1.1.1.2 ! misho 3126: pp_solaris_remove_service $_svc | pp_prepend $pp_wrkdir/postremove
1.1 misho 3127: unset pp_svc_xml_file
3128: done
3129:
3130: test -n "$pp_service_groups" &&
3131: for _grp in $pp_service_groups; do
3132: pp_solaris_make_service_group \
3133: $_grp "`pp_service_get_svc_group $_grp`"
3134: done
3135:
3136: #-- if installf was used; we need to indicate a termination
3137: grep installf $pp_wrkdir/postinstall >/dev/null &&
3138: echo 'installf -f $PKGINST' >> $pp_wrkdir/postinstall
3139:
3140: pp_solaris_sum_space
3141:
3142: # NB: pkginfo and copyright are added earlier
3143: for f in compver depend space checkinstall \
3144: preinstall request postinstall \
3145: preremove postremove; do
3146: if test -s $pp_wrkdir/$f; then
3147: case $f in
3148: *install|*remove|request)
3149: # turn scripts into a proper shell scripts
3150: mv $pp_wrkdir/$f $pp_wrkdir/$f.tmp
3151: { echo "#!/bin/sh";
3152: echo "# $f script for ${pp_solaris_name:-$name}-$version"
3153: cat $pp_wrkdir/$f.tmp
3154: echo "exit 0"; } > $pp_wrkdir/$f
3155: chmod +x $pp_wrkdir/$f
3156: rm -f $pp_wrkdir/$f.tmp
3157: ;;
3158: esac
3159: if $pp_opt_debug; then
3160: pp_debug "contents of $f:"
3161: cat $pp_wrkdir/$f >&2
3162: fi
3163: echo "i $f=$pp_wrkdir/$f" >> $prototype
3164: fi
3165: done
3166:
3167: #-- create the prototype file which lists the files to install
3168: # do this as late as possible because files could be added
3169: pp_solaris_abis_seen=
3170: for _cmp in $pp_components; do
3171: pp_solaris_proto $_cmp < $pp_wrkdir/%files.$_cmp
3172: done >> $prototype
3173:
3174: if test x"$pp_solaris_package_arch" = x"auto"; then
3175: if pp_contains "$pp_solaris_abis_seen" sparc64; then
3176: pp_solaris_package_arch_std="sparc64"
3177: echo "ARCH=sparcv9" >> $pkginfo
3178: elif pp_contains "$pp_solaris_abis_seen" sparc; then
3179: pp_solaris_package_arch_std="sparc"
3180: echo "ARCH=sparc" >> $pkginfo
3181: elif pp_contains "$pp_solaris_abis_seen" x86_64; then
3182: pp_solaris_package_arch_std="x86_64"
3183: echo "ARCH=amd64" >> $pkginfo
3184: elif pp_contains "$pp_solaris_abis_seen" i386; then
3185: pp_solaris_package_arch_std="i386"
3186: echo "ARCH=i386" >> $pkginfo
3187: else
3188: pp_warn "No ELF files found: not supplying an ARCH type"
3189: pp_solaris_package_arch_std="noarch"
3190: fi
3191: else
3192: pp_solaris_package_arch_std="$pp_solaris_package_arch"
3193: echo "ARCH=$pp_solaris_package_arch" >> $pkginfo
3194: fi
3195:
3196: mkdir $pp_wrkdir/pkg
3197:
3198: . $pp_wrkdir/%fixup
3199:
3200: if $pp_opt_debug; then
3201: echo "$pkginfo::"; cat $pkginfo
3202: echo "$prototype::"; cat $prototype
3203: fi >&2
3204:
3205: pkgmk -d $pp_wrkdir/pkg -f $prototype \
3206: || { error "pkgmk failed"; return; }
1.1.1.2 ! misho 3207: pkgtrans -s $pp_wrkdir/pkg \
1.1 misho 3208: $pp_wrkdir/`pp_backend_solaris_names` \
3209: ${pp_solaris_name:-$name} \
3210: || { error "pkgtrans failed"; return; }
3211: }
3212:
3213: pp_backend_solaris_cleanup () {
3214: :
3215: }
3216:
3217: pp_backend_solaris_names () {
3218: echo ${pp_solaris_name:-$name}-$version-${pp_solaris_package_arch_std:-$pp_solaris_arch}.pkg
3219: }
3220:
3221: pp_backend_solaris_install_script () {
3222: typeset pkgname platform
3223:
3224: platform="${pp_solaris_os:-solaris}-${pp_solaris_package_arch_std:-$pp_solaris_arch}"
3225:
3226: echo "#! /sbin/sh"
3227: pp_install_script_common
3228: pkgname=`pp_backend_solaris_names`
3229:
3230: cat <<.
3231: tmpnocheck=/tmp/nocheck\$\$
3232: tmpresponse=/tmp/response\$\$
3233: trap 'rm -f \$tmpnocheck \$tmpresponse' 0
3234:
3235: make_tmpfiles () {
3236: cat <<-.. > \$tmpresponse
3237: CLASSES=\$*
3238: SERVICES=$pp_services
3239: ..
3240: cat <<-.. > \$tmpnocheck
3241: mail=
3242: instance=overwrite
3243: partial=nocheck
3244: runlevel=nocheck
3245: idepend=nocheck
3246: rdepend=nocheck
3247: space=nocheck
3248: setuid=nocheck
3249: conflict=nocheck
3250: action=nocheck
3251: basedir=default
3252: ..
3253: }
3254:
3255: test \$# -eq 0 && usage
3256: op="\$1"; shift
3257:
3258: case "\$op" in
3259: list-components)
3260: test \$# -eq 0 || usage \$op
3261: echo "$pp_components"
3262: ;;
3263: list-services)
3264: test \$# -eq 0 || usage \$op
3265: echo "$pp_services"
3266: ;;
3267: list-files)
3268: test \$# -ge 1 || usage \$op
3269: echo \${PP_PKGDESTDIR:-.}/$pkgname
3270: ;;
3271: install)
3272: test \$# -ge 1 || usage \$op
3273: make_tmpfiles "\$@"
3274: verbose /usr/sbin/pkgadd -n -d \${PP_PKGDESTDIR:-.}/$pkgname \
3275: -r \$tmpresponse \
3276: -a \$tmpnocheck \
3277: ${pp_solaris_name:-$name}
3278: ;;
3279: uninstall)
3280: test \$# -ge 1 || usage \$op
3281: make_tmpfiles "\$@"
3282: verbose /usr/sbin/pkgrm -n \
3283: -a \$tmpnocheck \
3284: ${pp_solaris_name:-$name}
3285: ;;
3286: start|stop)
3287: test \$# -ge 1 || usage \$op
3288: ec=0
3289: for svc
3290: do
3291: verbose /etc/init.d/\$svc \$op || ec=1
3292: done
3293: exit \$ec
3294: ;;
3295: print-platform)
3296: echo "$platform"
3297: ;;
3298: *)
3299: usage
3300: ;;
3301: esac
3302: .
3303: }
3304:
3305: pp_solaris_dynlib_depend () {
3306: xargs ldd 2>/dev/null |
3307: sed -e '/^[^ ]*:$/d' -e 's,.*=>[ ]*,,' -e 's,^[ ]*,,' |
3308: sort -u |
3309: grep -v '^/usr/platform/' | (
3310: set -- ""; shift
3311: while read p; do
3312: set -- "$@" -p "$p"
3313: if [ $# -gt 32 ]; then
3314: echo "$# is $#" >&2
3315: pkgchk -l "$@"
3316: set -- ""; shift
3317: fi
3318: done
3319: [ $# -gt 0 ] && pkgchk -l "$@"
3320: )|
3321: awk '/^Current status:/{p=0} p==1 {print $1} /^Referenced by/ {p=1}' |
3322: sort -u |
3323: xargs -l32 pkginfo -x |
3324: awk 'NR % 2 == 1 { name=$1; } NR%2 == 0 { print name, $2 }'
3325: }
3326:
3327: pp_solaris_add_dynlib_depends () {
3328: typeset tmp
3329: tmp=$pp_wrkdir/tmp.dynlib
3330:
3331: for _cmp in $pp_components; do
3332: awk '{print destdir $6}' destdir="$pp_destdir" \
3333: < $pp_wrkdir/%files.$_cmp |
3334: pp_solaris_dynlib_depend > $tmp
3335: if test -s $tmp; then
3336: cat $tmp >> $pp_wrkdir/%depend.$_cmp
3337: fi
3338: rm -f $tmp
3339: done
3340: }
3341:
3342: pp_backend_solaris_probe () {
3343: echo "${pp_solaris_os}-${pp_solaris_arch_std}"
3344: }
3345:
3346: pp_backend_solaris_vas_platforms () {
3347: case `pp_backend_solaris_probe` in
3348: sol10-sparc* | sol9-sparc* | sol8-sparc*)
3349: echo solaris8-sparc solaris7-sparc solaris26-sparc;;
3350: sol7-sparc*) echo solaris7-sparc solaris26-sparc;;
3351: sol26-sparc*) echo solaris26-sparc;;
3352: sol8-*86) echo solaris8-x86;;
3353: sol10-*86 | sol10-x86_64)
3354: echo solaris10-x64 solaris8-x86;;
3355: *) pp_die "unknown system `pp_backend_solaris_probe`";;
3356: esac
3357: }
3358: pp_backend_solaris_function() {
1.1.1.2 ! misho 3359: case "$1" in
1.1 misho 3360: pp_mkgroup) cat<<'.';;
3361: /usr/sbin/groupmod "$1" 2>/dev/null && return 0
3362: /usr/sbin/groupadd "$1"
3363: .
3364: pp_mkuser:depends) echo pp_mkgroup;;
3365: pp_mkuser) cat<<'.';;
3366: id "$1" >/dev/null 2>/dev/null && return 0
3367: pp_mkgroup "${2:-$1}" || return 1
3368: /usr/sbin/useradd \
3369: -g "${2:-$1}" \
3370: -d "${3:-/nonexistent}" \
3371: -s "${4:-/bin/false}" \
3372: "$1"
3373: .
3374: *) false;;
3375: esac
3376: }
3377:
3378: pp_backend_solaris_init_svc_vars () {
3379: _smf_category=${pp_solaris_smf_category:-application}
3380: _smf_method_envvar_name=${smf_method_envvar_name:-"PP_SMF_SERVICE"}
3381: pp_solaris_service_shell=/sbin/sh
3382: }
3383:
3384: pp_solaris_init_svc () {
3385: smf_version=1
3386: smf_type=service
3387: solaris_user=
3388: solaris_stop_signal=
3389: solaris_sysv_init_start=S70 # invocation order for start scripts
3390: solaris_sysv_init_kill=K30 # invocation order for kill scripts
3391: solaris_sysv_init_start_states="2" # states to install start link
3392: solaris_sysv_init_kill_states="S 0 1" # states to install kill link
3393:
3394: #
3395: # To have the service be installed to start automatically,
3396: # %service foo
3397: # solaris_sysv_init_start_states="S 0 1 2"
3398: #
3399: }
3400:
3401: pp_solaris_smf () {
3402: typeset f _pp_solaris_service_script svc _pp_solaris_manpage
3403:
3404: pp_solaris_name=${pp_solaris_name:-$name}
3405: pp_solaris_manpath=${pp_solaris_manpath:-"/usr/share/man"}
1.1.1.2 ! misho 3406: pp_solaris_mansect=${pp_solaris_mansect:-1}
1.1 misho 3407: smf_start_timeout=${smf_start_timeout:-60}
3408: smf_stop_timeout=${smf_stop_timeout:-60}
3409: smf_restart_timeout=${smf_restart_timeout:-60}
3410:
3411: svc=${pp_solaris_smf_service_name:-$1}
3412: _pp_solaris_service_script=${pp_solaris_service_script:-"/etc/init.d/${pp_solaris_service_script_name:-$svc}"}
1.1.1.2 ! misho 3413: _pp_solaris_manpage=${pp_solaris_manpage:-$svc}
1.1 misho 3414:
3415: if [ -z $pp_svc_xml_file ]; then
3416: pp_svc_xml_file="/var/svc/manifest/$_smf_category/$svc.xml"
3417: echo "## Generating the smf service manifest file for $pp_svc_xml_file"
3418: else
3419: echo "## SMF service manifest file already defined at $pp_svc_xml_file"
3420: if [ -z $pp_solaris_smf_service_name ] || [ -z $pp_solaris_smf_category ] || [ -z $pp_solaris_service_script ] || [ -z $smf_method_envvar_name ]; then
3421: pp_error "All required variables are not set.\n"\
3422: "When using a custom manifest file all of the following variables must be set:\n"\
3423: "pp_solaris_smf_service_name, pp_solaris_smf_category, pp_solaris_service_script and smf_method_envvar_name.\n\n"\
3424: "Example:\n"\
3425: " \$pp_solaris_smf_category=application\n"\
3426: " \$pp_solaris_smf_service_name=pp\n\n"\
3427: " <service name='application/pp' type='service' version='1'>\n\n"\
3428: "Example:\n"\
3429: " \$pp_solaris_service_script=/etc/init.d/pp\n\n"\
3430: " <exec_method type='method' name='start' exec='/etc/init.d/pp' />\n\n"\
3431: "Example:\n"\
3432: " \$smf_method_envvar_name=PP_SMF_SERVICE\n\n"\
3433: " <method_environment>\n"\
3434: " <envvar name='PP_SMF_SERVICE' value='1'/>\n"\
3435: " </method_environment>\n"
3436:
3437: return 1
3438: fi
3439: return 0
3440: fi
3441:
3442: f=$pp_svc_xml_file
3443: pp_add_file_if_missing $f ||
3444: return 0
1.1.1.2 ! misho 3445: pp_solaris_add_parent_dirs "$f"
1.1 misho 3446:
3447: _pp_solaris_smf_dependencies="
3448: <dependency name='pp_local_filesystems'
3449: grouping='require_all'
3450: restart_on='none'
3451: type='service'>
3452: <service_fmri value='svc:/system/filesystem/local'/>
3453: </dependency>
3454:
3455: <dependency name='pp_single-user'
3456: grouping='require_all'
3457: restart_on='none'
3458: type='service'>
3459: <service_fmri value='svc:/milestone/single-user' />
3460: </dependency>
3461: "
3462: _pp_solaris_smf_dependencies=${pp_solaris_smf_dependencies:-$_pp_solaris_smf_dependencies}
3463:
3464: cat <<-. >$pp_destdir$f
3465: <?xml version="1.0"?>
3466: <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
3467: <!--
3468: $copyright
3469: Generated by PolyPackage $pp_version
3470: -->
3471:
3472: <service_bundle type='manifest' name='${pp_solaris_name}:${svc}' >
3473: <service name='$_smf_category/$svc'
3474: type='$smf_type'
3475: version='$smf_version'>
3476:
3477: <create_default_instance enabled='false'/>
3478:
3479: <single_instance />
3480:
3481: $_pp_solaris_smf_dependencies
3482:
3483: $pp_solaris_smf_additional_dependencies
3484:
3485: <method_context>
3486: <method_credential user='${solaris_user:-$user}' />
3487: <method_environment>
3488: <envvar name='$_smf_method_envvar_name' value='1'/>
3489: </method_environment>
3490: </method_context>
3491:
3492: <exec_method type='method' name='start'
3493: exec='$_pp_solaris_service_script start'
3494: timeout_seconds='$smf_start_timeout' />
3495:
3496: <exec_method type='method' name='stop'
3497: exec='$_pp_solaris_service_script stop'
3498: timeout_seconds='$smf_stop_timeout' />
3499:
3500: <exec_method type='method' name='restart'
3501: exec='$_pp_solaris_service_script restart'
3502: timeout_seconds='$smf_restart_timeout' />
3503:
3504: <template>
3505: <common_name>
3506: <loctext xml:lang='C'>$description</loctext>
3507: </common_name>
3508: <documentation>
1.1.1.2 ! misho 3509: <manpage title='$pp_solaris_manpage' section='$pp_solaris_mansect' manpath='$pp_solaris_manpath'/>
1.1 misho 3510: </documentation>
3511: </template>
3512: </service>
3513: </service_bundle>
3514: .
3515: }
3516:
3517: pp_solaris_make_service_group () {
3518: typeset group out file svcs svc
3519:
3520: group="$1"
3521: svcs="$2"
3522: file="/etc/init.d/$group"
3523: out="$pp_destdir$file"
3524:
1.1.1.2 ! misho 3525: #-- return if the script is supplied already
1.1 misho 3526: pp_add_file_if_missing "$file" run 755 || return 0
1.1.1.2 ! misho 3527: pp_solaris_add_parent_dirs "$file"
1.1 misho 3528:
3529: echo "#! /sbin/sh" > $out
3530: echo "# polypkg service group script for these services:" >> $out
3531: echo "svcs=\"$svcs\"" >> $out
3532:
3533: cat <<'.' >>$out
3534:
3535: #-- starts services in order.. stops them all if any break
3536: pp_start () {
3537: undo=
3538: for svc in $svcs; do
3539: if /etc/init.d/$svc start; then
3540: undo="$svc $undo"
3541: else
3542: if test -n "$undo"; then
3543: for svc in $undo; do
3544: /etc/init.d/$svc stop
3545: done
3546: return 1
3547: fi
3548: fi
3549: done
3550: return 0
3551: }
3552:
3553: #-- stops services in reverse
3554: pp_stop () {
3555: reverse=
3556: for svc in $svcs; do
3557: reverse="$svc $reverse"
3558: done
3559: rc=0
3560: for svc in $reverse; do
3561: /etc/init.d/$svc stop || rc=$?
3562: done
3563: return $rc
3564: }
3565:
3566: #-- returns true only if all services return true status
3567: pp_status () {
3568: rc=0
3569: for svc in $svcs; do
3570: /etc/init.d/$svc status || rc=$?
3571: done
3572: return $rc
3573: }
3574:
3575: case "$1" in
3576: start) pp_start;;
3577: stop) pp_stop;;
3578: status) pp_status;;
3579: restart) pp_stop && pp_start;;
3580: *) echo "usage: $0 {start|stop|restart|status}" >&2; exit 1;;
3581: esac
3582: .
3583: }
3584:
3585: pp_solaris_make_service () {
3586: typeset file out _cmd svc
3587:
3588: svc="${pp_solaris_smf_service_name:-$1}"
3589: file=${pp_solaris_service_script:-"/etc/init.d/${pp_solaris_service_script_name:-$svc}"}
3590: out="$pp_destdir$file"
3591:
3592: #-- return if we don't need to create the init script
3593: pp_add_file_if_missing "$file" run 755 ||
3594: return 0
1.1.1.2 ! misho 3595: pp_solaris_add_parent_dirs "$file"
1.1 misho 3596:
3597: echo "#! /sbin/sh" >$out
3598: echo "#-- This service init file generated by polypkg" >>$out
3599:
3600: #-- Start SMF integration.
3601: if [ -n "$pp_svc_xml_file" ] ; then
3602: cat <<_EOF >>$out
3603: if [ -x /usr/sbin/svcadm ] && [ "x\$1" != "xstatus" ] && [ "t\$$_smf_method_envvar_name" = "t" ] ; then
3604: case "\$1" in
3605: start)
3606: echo "starting $svc"
3607: /usr/sbin/svcadm clear svc:/$_smf_category/$svc:default >/dev/null 2>&1
3608: /usr/sbin/svcadm enable -s $_smf_category/$svc
3609: RESULT=\$?
3610: if [ "\$RESULT" -ne 0 ] ; then
1.1.1.2 ! misho 3611: echo "Error \$RESULT starting $svc" >&2
! 3612: fi
1.1 misho 3613: ;;
3614: stop)
3615: echo "stopping $svc"
3616: /usr/sbin/svcadm disable -ts $_smf_category/$svc
1.1.1.2 ! misho 3617: RESULT=0
1.1 misho 3618: ;;
3619: restart)
3620: echo "restarting $svc"
3621: /usr/sbin/svcadm disable -ts $_smf_category/$svc
3622: /usr/sbin/svcadm clear svc:/$_smf_category/$svc:default >/dev/null 2>&1
3623: /usr/sbin/svcadm enable -s $_smf_category/$svc
3624: RESULT=\$?
3625: if [ "\$RESULT" -ne 0 ] ; then
1.1.1.2 ! misho 3626: echo "Error \$RESULT starting $svc" >&2
! 3627: fi
! 3628: ;;
1.1 misho 3629: *)
1.1.1.2 ! misho 3630: echo "Usage: $file {start|stop|restart|status}" >&2
! 3631: RESULT=1
1.1 misho 3632: esac
1.1.1.2 ! misho 3633: exit $RESULT
1.1 misho 3634: fi
3635: _EOF
3636: fi
3637:
3638: #-- construct a start command that builds a pid file as needed
3639: # and forks the daemon
3640: _cmd="$cmd";
3641: if test -z "$pidfile"; then
3642: # The service does not define a pidfile, so we have to make
3643: # our own up. On Solaris systems where there is no /var/run
3644: # we must use /tmp to guarantee the pid files are removed after
3645: # a system crash.
3646: cat <<. >>$out
3647: pp_piddir="/var/run"
3648: test -d "\$pp_piddir/." || pp_piddir="/tmp"
3649: pidfile="\$pp_piddir/$svc.pid"
3650: .
3651: _cmd="$cmd & echo \$! > \$pidfile"
3652: else
3653: # The service is able to write its own PID file
3654: cat <<. >>$out
3655: pidfile="$pidfile"
3656: .
3657: fi
3658:
3659: if test "${user:-root}" != "root"; then
3660: _cmd="su $user -c exec $_cmd";
3661: fi
3662:
3663: cat <<. >>$out
3664: stop_signal="${stop_signal:-TERM}"
3665: svc="${svc}"
3666:
3667: # generated command to run $svc as a daemon process
3668: pp_exec () { $_cmd; }
3669: .
3670:
3671: #-- write the invariant section of the init script
3672: cat <<'.' >>$out
3673:
3674: # returns true if $svc is running
3675: pp_running () {
1.1.1.2 ! misho 3676: test -s "$pidfile" || return 1
! 3677: read pid junk < "$pidfile" 2>/dev/null
1.1 misho 3678: test ${pid:-0} -gt 1 &&
3679: kill -0 "$pid" 2>/dev/null
3680: }
3681:
3682: # prints a message describing $svc's running state
3683: pp_status () {
3684: if pp_running; then
3685: echo "service $svc is running (pid $pid)"
3686: return 0
3687: elif test -f "$pidfile"; then
3688: echo "service $svc is not running, but pid file exists"
3689: return 2
3690: else
3691: echo "service $svc is not running"
3692: return 1
3693: fi
3694: }
3695:
3696: # starts $svc
3697: pp_start () {
3698: if pp_running; then
3699: echo "service $svc already running" >&2
3700: return 0
3701: fi
3702: echo "starting $svc... \c"
3703: if pp_exec; then
3704: echo "done."
3705: else
3706: echo "ERROR."
3707: exit 1
3708: fi
3709: }
3710:
3711: # stops $svc
3712: pp_stop () {
3713: if pp_running; then
3714: echo "stopping $svc... \c"
3715: if kill -$stop_signal $pid; then
3716: rm -f "$pidfile"
3717: echo "done."
3718: else
3719: echo "ERROR."
3720: return 1
3721: fi
3722: else
3723: echo "service $svc already stopped" >&2
3724: return 0
3725: fi
3726: }
3727:
3728: umask 022
3729: case "$1" in
3730: start) pp_start;;
3731: stop) pp_stop;;
3732: status) pp_status;;
3733: restart) pp_stop && pp_start;;
3734: *) echo "usage: $0 {start|stop|restart|status}" >&2; exit 1;;
3735: esac
3736: .
3737: }
3738:
3739: pp_solaris_remove_service () {
3740: typeset file svc
3741:
3742: svc="${pp_solaris_smf_service_name:-$1}"
3743: file=${pp_solaris_service_script:-"/etc/init.d/${pp_solaris_service_script_name:-$svc}"}
3744:
3745: echo '
3746: '$file' stop >/dev/null 2>/dev/null
3747: if [ "x${PKG_INSTALL_ROOT}" = 'x' ]; then
3748: if [ -x /usr/sbin/svcadm ] ; then
3749: # Likely un-needed, but just in case.
3750: /usr/sbin/svcadm disable -s '$svc' 2>/dev/null
3751: /usr/sbin/svccfg delete '$svc' 2>/dev/null
3752: fi
3753: fi
3754: '
3755: }
3756:
3757: pp_solaris_install_service () {
3758: typeset s k l file svc
3759:
3760: svc="${pp_solaris_smf_service_name:-$1}"
3761: file=${pp_solaris_service_script:-"/etc/init.d/${pp_solaris_service_script_name:-$svc}"}
3762:
3763: s="${solaris_sysv_init_start}$svc"
3764: k="${solaris_sysv_init_kill}$svc"
3765:
3766: echo '
3767: if [ "x${PKG_INSTALL_ROOT}" != "x" ]; then
3768: if [ -x ${PKG_INSTALL_ROOT}/usr/sbin/svcadm ]; then
3769: echo "/usr/sbin/svccfg import '$pp_svc_xml_file' 2>/dev/null" >> ${PKG_INSTALL_ROOT}/var/svc/profile/upgrade
3770: else'
3771: test -n "${solaris_sysv_init_start_states}" &&
3772: for state in ${solaris_sysv_init_start_states}; do
3773: l="/etc/rc$state.d/$s"
3774: echo "echo '$l'"
3775: echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=$file s"
3776: pp_solaris_space /etc/rc$state.d 0 1
3777: done
3778: test -n "${solaris_sysv_init_kill_states}" &&
3779: for state in ${solaris_sysv_init_kill_states}; do
3780: l="/etc/rc$state.d/$k"
3781: echo "echo '$l'"
3782: echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=$file s"
3783: pp_solaris_space /etc/rc$state.d 0 1
3784: done
3785: echo '
3786: fi
3787: else
3788: if [ -x /usr/sbin/svcadm ]; then
3789: echo "Registering '$svc' with SMF"
3790: /usr/sbin/svcadm disable -s '$svc' 2>/dev/null
3791: /usr/sbin/svccfg delete '$svc' 2>/dev/null
3792: /usr/sbin/svccfg import '$pp_svc_xml_file'
3793: else'
3794: test -n "${solaris_sysv_init_start_states}" &&
3795: for state in ${solaris_sysv_init_start_states}; do
3796: l="/etc/rc$state.d/$s"
3797: echo "echo '$l'"
3798: echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=$file s"
3799: pp_solaris_space /etc/rc$state.d 0 1
3800: done
3801: test -n "${solaris_sysv_init_kill_states}" &&
3802: for state in ${solaris_sysv_init_kill_states}; do
3803: l="/etc/rc$state.d/$k"
3804: echo "echo '$l'"
3805: echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=$file s"
3806: pp_solaris_space /etc/rc$state.d 0 1
3807: done
3808: echo '
3809: fi
3810: fi'
3811: }
3812:
1.1.1.2 ! misho 3813: pp_solaris_add_parent_dirs () {
! 3814: typeset dir
! 3815:
! 3816: dir=${1%/*}
! 3817: while test -n "$dir"; do
! 3818: if awk "\$6 == \"$dir/\" {exit 1}" < $pp_wrkdir/%files.run; then
! 3819: echo "d - - - - $dir/" >> $pp_wrkdir/%files.run
! 3820: fi
! 3821: dir=${dir%/*}
! 3822: done
! 3823: }
! 3824:
1.1 misho 3825: pp_platforms="$pp_platforms deb"
3826:
3827: pp_backend_deb_detect () {
3828: test -f /etc/debian_version
3829: }
3830:
3831: pp_deb_cmp_full_name () {
3832: local prefix
3833: prefix="${pp_deb_name:-$name}"
3834: case "$1" in
3835: run) echo "${prefix}" ;;
3836: dbg) echo "${prefix}-${pp_deb_dbg_pkgname}";;
3837: dev) echo "${prefix}-${pp_deb_dev_pkgname}";;
3838: doc) echo "${prefix}-${pp_deb_doc_pkgname}";;
3839: *) pp_error "unknown component '$1'";
3840: esac
3841: }
3842:
3843: pp_backend_deb_init () {
3844: pp_deb_dpkg_version="2.0"
3845: pp_deb_name=
3846: pp_deb_version=
3847: pp_deb_release=
3848: pp_deb_arch=
3849: pp_deb_arch_std=
3850: pp_deb_maintainer=support@quest.com
3851: pp_deb_copyright=
3852: pp_deb_distro=
3853: pp_deb_control_description=
3854: pp_deb_summary=
3855: pp_deb_description=
3856: pp_deb_dbg_pkgname="dbg"
3857: pp_deb_dev_pkgname="dev"
3858: pp_deb_doc_pkgname="doc"
3859: pp_deb_section=contrib # Free software that depends on non-free software
3860:
3861: # Detect the host architecture
3862: pp_deb_detect_arch
3863:
3864: # Make sure any programs we require are installed
3865: pp_deb_check_required_programs
3866:
3867: # Set generated/interrogated platforms variables
3868: pp_deb_munge_description
3869: }
3870:
3871: pp_deb_check_required_programs () {
3872: local p needed notfound ok
3873: needed= notfound=
3874: for prog in dpkg dpkg-deb install md5sum fakeroot
3875: do
3876: if which $prog 2>/dev/null >/dev/null; then
3877: pp_debug "$prog: found"
3878: else
3879: pp_debug "$prog: not found"
3880: case "$prog" in
3881: dpkg|dpkg-deb) p=dpkg;;
3882: install|md5sum) p=coreutils;;
3883: fakeroot) p=fakeroot;;
3884: *) pp_die "unexpected dpkg tool $prog";;
3885: esac
3886: notfound="$notfound $prog"
3887: pp_contains "$needed" "$p" || needed="$needed $p"
3888: fi
3889: done
3890: if [ -n "$notfound" ]; then
3891: pp_error "cannot find these programs: $notfound"
3892: pp_error "please install these packages: $needed"
3893: fi
3894: }
3895:
3896: pp_deb_munge_description () {
3897: # Insert a leading space on each line, replace blank lines with a
3898: #space followed by a full-stop.
3899: pp_deb_control_description=`echo ${pp_deb_description:-$description} | \
3900: sed "s,^\(.*\)$, \1, " \
3901: | sed "s,^[ \t]*$, .,g"`
3902:
3903: }
3904:
3905: pp_deb_detect_arch () {
3906: pp_deb_arch=`dpkg --print-architecture`
3907: pp_deb_arch_std=`uname -m`
3908: }
3909:
3910: pp_deb_sanitize_version() {
3911: echo "$@" | tr -d -c '[:alnum:].+-:~'
3912: }
3913:
3914: pp_deb_version_final() {
3915: if test -n "$pp_deb_version"; then
3916: # Don't sanitize; assume the user is sane (hah!)
3917: echo "$pp_deb_version"
3918: else
3919: pp_deb_sanitize_version "$version"
3920: fi
3921: }
3922:
1.1.1.2 ! misho 3923: pp_deb_conflict () {
! 3924: local _name _vers _conflicts
! 3925:
! 3926: _conflicts="Conflicts:"
! 3927: while read _name _vers; do
! 3928: case "$_name" in ""| "#"*) continue ;; esac
! 3929: _conflicts="$_conflicts $_name"
! 3930: test -n "$_vers" && _conflicts="$_conflicts $_name (>= $vers)"
! 3931: _conflicts="${_conflicts},"
! 3932: done
! 3933: echo "${_conflicts%,}"
! 3934: }
! 3935:
1.1 misho 3936: pp_deb_make_control() {
3937: package_name=`pp_deb_cmp_full_name "$1"`
3938: cat <<-.
3939: Package: ${package_name}
3940: Version: `pp_deb_version_final`-${pp_deb_release:-1}
3941: Section: ${pp_deb_section:-contrib}
3942: Priority: optional
3943: Architecture: ${pp_deb_arch}
3944: Maintainer: ${pp_deb_maintainer:-$maintainer}
3945: Description: ${pp_deb_summary:-$summary}
3946: ${pp_deb_control_description}
3947: .
3948: if test -s $pp_wrkdir/%depend."$1"; then
3949: sed -ne '/^[ ]*$/!s/^[ ]*/Depends: /p' \
3950: < $pp_wrkdir/%depend."$1"
3951: fi
1.1.1.2 ! misho 3952: if test -s $pp_wrkdir/%conflict."$1"; then
! 3953: pp_deb_conflict < $pp_wrkdir/%conflict."$1"
! 3954: fi
1.1 misho 3955: }
3956:
3957: pp_deb_make_md5sums() {
3958: local cmp="$1"; shift
3959: local pkg_dir
3960:
3961: pkg_dir=$pp_wrkdir/`pp_deb_cmp_full_name $cmp`
3962: (cd $pkg_dir && md5sum "$@") > $pkg_dir/DEBIAN/md5sums ||
3963: pp_error "cannot make md5sums"
3964: }
3965:
3966: pp_deb_make_package_maintainer_script() {
3967: local output="$1"
3968: local source="$2"
3969: local desc="$3"
3970:
3971: # See if we need to create this script at all
3972: if [ -s "$source" ]
3973: then
3974:
3975: # Create header
3976: cat <<-. >$output || pp_error "Cannot create $output"
3977: #!/bin/sh
3978: # $desc
3979: # Generated by PolyPackage $pp_version
3980:
3981: .
3982:
3983: cat $source >> "$output" || pp_error "Cannot append to $output"
3984:
3985: # Set perms
3986: chmod 755 "$output" || pp_error "Cannot chmod $output"
3987: fi
3988: }
3989:
3990: pp_deb_handle_services() {
3991: local svc
3992:
3993: #-- add service start/stop code
3994: if test -n "$pp_services"; then
3995: #-- record the uninstall commands in reverse order
3996: for svc in $pp_services; do
3997: pp_load_service_vars $svc
3998:
3999: # Create init script (unless one exists)
4000: pp_deb_service_make_init_script $svc
4001:
4002: #-- append %post code to install the svc
4003: test x"yes" = x"$enable" &&
4004: cat<<-. >> $pp_wrkdir/%post.run
4005: # Install the service links
4006: /usr/sbin/update-rc.d $svc defaults
4007: .
4008:
4009: #-- prepend %preun code to stop svc
4010: cat<<-. | pp_prepend $pp_wrkdir/%preun.run
4011: # Stop the $svc service
4012: if test -x /usr/sbin/invoke-rc.d; then
4013: /usr/sbin/invoke-rc.d $svc stop
4014: else
4015: /etc/init.d/$svc stop
4016: fi
4017: # Remove the service links
4018: /usr/sbin/update-rc.d -f $svc remove
4019: .
4020: done
4021: #pp_deb_service_remove_common | pp_prepend $pp_wrkdir/%preun.run
4022: fi
4023:
4024: }
4025: pp_deb_fakeroot () {
4026: if test -s $pp_wrkdir/fakeroot.save; then
4027: fakeroot -i $pp_wrkdir/fakeroot.save -s $pp_wrkdir/fakeroot.save "$@"
4028: else
4029: fakeroot -s $pp_wrkdir/fakeroot.save "$@"
4030: fi
4031: }
4032:
4033: pp_deb_make_DEBIAN() {
4034: local cmp="${1:-run}"
4035: local data cmp_full_name
4036: local old_umask
4037:
4038: old_umask=`umask`
4039: umask 0022
4040: cmp_full_name=`pp_deb_cmp_full_name $cmp`
4041: data=$pp_wrkdir/$cmp_full_name
4042:
4043: # Create DEBIAN dir $data/DEBIAN
4044: mkdir -p $data/DEBIAN
4045:
4046: # Create control file
4047: pp_deb_make_control $cmp > $data/DEBIAN/control
4048:
4049: # Copy in conffiles
4050: if test -f $pp_wrkdir/%conffiles.$cmp; then
4051: cp $pp_wrkdir/%conffiles.$cmp $data/DEBIAN/conffiles
4052: fi
4053:
4054: # Create postinst
4055: pp_deb_make_package_maintainer_script "$data/DEBIAN/postinst" \
4056: "$pp_wrkdir/%post.$cmp" "Post install script for $cmp_full_name"\
4057: || exit $?
4058:
4059: # Create prerm
4060: pp_deb_make_package_maintainer_script "$data/DEBIAN/prerm" \
4061: "$pp_wrkdir/%preun.$cmp" "Pre-uninstall script for $cmp_full_name"\
4062: || exit $?
4063:
1.1.1.2 ! misho 4064: # Create postrm
! 4065: pp_deb_make_package_maintainer_script "$data/DEBIAN/postrm" \
! 4066: "$pp_wrkdir/%postun.$cmp" "Post-uninstall script for $cmp_full_name"\
! 4067: || exit $?
! 4068:
1.1 misho 4069: umask $old_umask
4070: }
4071:
4072: pp_deb_make_data() {
4073: local _l t m o g f p st data
4074: local data share_doc owner group
4075: cmp=$1
4076: data=$pp_wrkdir/`pp_deb_cmp_full_name $cmp`
4077: cat $pp_wrkdir/%files.${cmp} | while read t m o g f p st; do
1.1.1.2 ! misho 4078: if test x"$m" = x"-"; then
! 4079: case "$t" in
! 4080: d) m=755;;
! 4081: f) m=644;;
! 4082: esac
! 4083: fi
1.1 misho 4084: test x"$o" = x"-" && o=root
4085: test x"$g" = x"-" && g=root
4086: case "$t" in
4087: f) # Files
4088: pp_deb_fakeroot install -D -o $o -g $g -m ${m} $pp_destdir/$p $data/$p;
4089: if [ x"$f" = x"v" ]
4090: then
4091: # File marked as "volatile". Assume this means it's a conffile
4092: # TODO: check this as admins like modified conffiles to be left
4093: # behind
4094: echo "$p" >> $pp_wrkdir/%conffiles.$cmp
4095: fi;;
4096:
4097: d) # Directories
4098: pp_deb_fakeroot install -m ${m} -o $o -g $g -d $data/$p;;
4099:
4100: s) # Symlinks
4101: # Remove leading / from vars
4102: rel_p=`echo $p | sed s,^/,,`
4103: rel_st=`echo $st | sed s,^/,,`
4104: # TODO: we are always doing absolute links here. We should follow
4105: # the debian policy of relative links when in the same top-level
4106: # directory
4107: (cd $data; ln -sf $st $rel_p);;
4108: *) pp_error "Unsupported data file type: $t";;
4109: esac
4110: done
4111:
4112: # If no copyright file is present add one. This is a debian requirement.
4113: share_doc="/usr/share/doc/`pp_deb_cmp_full_name $cmp`"
4114: if [ ! -f "$data/$share_doc/copyright" ]
4115: then
4116: echo "${pp_deb_copyright:-$copyright}" > "$pp_wrkdir/copyright"
4117: install -D -m 644 "$pp_wrkdir/copyright" "$data/$share_doc/copyright"
4118: fi
4119:
4120: }
4121:
4122: pp_deb_makedeb () {
4123: local cmp
4124: local package_build_dir
4125:
4126: cmp="$1"
4127:
4128: package_build_dir=$pp_wrkdir/`pp_deb_cmp_full_name $cmp`
4129:
4130: # Create package dir
4131: mkdir -p $package_build_dir
4132:
4133: # Copy in data
4134: pp_deb_make_data $cmp ||
4135: pp_die "Could not make DEBIAN data files for $cmp"
4136:
4137: # Make control files
4138: # must be done after copying data so conffiles are found
4139: pp_deb_make_DEBIAN $cmp ||
4140: pp_die "Could not make DEBIAN control files for $cmp"
4141:
4142: # Create md5sums
4143: pp_deb_make_md5sums $cmp `(cd $package_build_dir;
4144: find . -type f -a -not -name DEBIAN | sed "s,^\./,,")` ||
4145: pp_die "Could not make DEBIAN md5sums for $cmp"
4146: }
4147:
4148: pp_backend_deb () {
4149: local debname
4150:
4151: # Handle services
4152: pp_deb_handle_services $cmp
4153:
4154: for cmp in $pp_components
4155: do
4156: debname=`pp_deb_name $cmp`
4157: pp_deb_makedeb $cmp
4158: done
4159:
4160: . $pp_wrkdir/%fixup
4161:
4162: for cmp in $pp_components
4163: do
4164: debname=`pp_deb_name $cmp`
4165: # Create debian package
4166: pp_debug "Building `pp_deb_cmp_full_name $cmp` -> $output"
4167: pp_deb_fakeroot dpkg-deb \
4168: --build $pp_wrkdir/`pp_deb_cmp_full_name $cmp` \
4169: $pp_wrkdir/$debname ||
4170: pp_error "failed to create $cmp package"
4171: done
4172: }
4173:
4174: pp_backend_deb_cleanup () {
4175: # rm -rf $pp_wrkdir
4176: :
4177: }
4178:
4179: pp_deb_name () {
4180: local cmp="${1:-run}"
4181: echo `pp_deb_cmp_full_name $cmp`"_"`pp_deb_version_final`"-${pp_deb_release:-1}_${pp_deb_arch}.deb"
4182: }
4183: pp_backend_deb_names () {
4184: for cmp in $pp_components
4185: do
4186: pp_deb_name $cmp
4187: done
4188: }
4189:
4190: pp_backend_deb_install_script () {
4191: local cmp _cmp_full_name
4192:
4193: echo "#!/bin/sh"
4194: pp_install_script_common
4195:
4196: cat <<.
4197:
4198: cmp_to_pkgname () {
4199: test x"\$*" = x"all" &&
4200: set -- $pp_components
4201: for cmp
4202: do
4203: case \$cmp in
4204: .
4205: for cmp in $pp_components; do
4206: echo "$cmp) echo '`pp_deb_cmp_full_name $cmp`';;"
4207: done
4208: cat <<.
4209: *) usage;;
4210: esac
4211: done
4212: }
4213:
4214:
4215: cmp_to_pathname () {
4216: test x"\$*" = x"all" &&
4217: set -- $pp_components
4218: for cmp
4219: do
4220: case \$cmp in
4221: .
4222: for cmp in $pp_components; do
4223: echo "$cmp) echo \${PP_PKGDESTDIR:-.}/'`pp_deb_name $cmp`';;"
4224: done
4225: cat <<.
4226: *) usage;;
4227: esac
4228: done
4229: }
4230:
4231: test \$# -eq 0 && usage
4232: op="\$1"; shift
4233: case "\$op" in
4234: list-components)
4235: test \$# -eq 0 || usage \$op
4236: echo $pp_components
4237: ;;
4238: list-services)
4239: test \$# -eq 0 || usage \$op
4240: echo $pp_services
4241: ;;
4242: list-files)
4243: test \$# -ge 1 || usage \$op
4244: cmp_to_pathname "\$@"
4245: ;;
4246: install)
4247: test \$# -ge 1 || usage \$op
4248: dpkg --install \`cmp_to_pathname "\$@"\`
4249: ;;
4250: uninstall)
4251: test \$# -ge 1 || usage \$op
4252: dpkg --remove \`cmp_to_pkgname "\$@"\`; :
4253: ;;
4254: start|stop)
4255: test \$# -ge 1 || usage \$op
4256: ec=0
4257: for svc
4258: do
4259: /etc/init.d/\$svc \$op || ec=1
4260: done
4261: exit \$ec
4262: ;;
4263: print-platform)
4264: test \$# -eq 0 || usage \$op
4265: echo "linux-${pp_deb_arch}"
4266: ;;
4267: *)
4268: usage
4269: ;;
4270: esac
4271: .
4272: }
4273:
4274: pp_backend_deb_probe() {
4275: local arch distro release
4276:
4277: pp_deb_detect_arch
4278:
4279: # /etc/debian_version exists on Debian & Ubuntu, so it's no use
4280: # to us. Use lsb_release instead.
4281:
4282: case `(lsb_release -is || echo no-lsb) 2>/dev/null` in
4283: Debian)
4284: distro=deb
4285: ;;
4286: Ubuntu)
4287: distro=ubu
4288: ;;
4289: no-lsb)
4290: echo unknown-$pp_deb_arch_std
4291: return 0
4292: ;;
4293: *)
4294: distro=unknown
4295: ;;
4296: esac
4297:
4298: release=`lsb_release -rs`
4299:
4300: # If release is not numeric, use the codename
4301: case $release in
4302: *[!.0-9r]*)
4303: release=`lsb_release -cs`
4304: case $release in
4305: buzz)
4306: release="11"
4307: ;;
4308: rex)
4309: release="12"
4310: ;;
4311: bo)
4312: release="13"
4313: ;;
4314: hamm)
4315: release="20"
4316: ;;
4317: slink)
4318: release="21"
4319: ;;
4320: potato)
4321: release="22"
4322: ;;
4323: woody)
4324: release="30"
4325: ;;
4326: sarge)
4327: release="31"
4328: ;;
4329: etch)
4330: release="40"
4331: ;;
4332: lenny)
4333: release="50"
4334: ;;
4335: squeeze)
4336: release="60"
4337: ;;
4338: esac
4339: ;;
4340: *)
4341: # Remove trailing revision number and any dots
4342: release=`echo $release | cut -dr -f1 | tr -d .`
4343: ;;
4344: esac
4345:
4346: echo $distro$release-$pp_deb_arch_std
4347: }
4348:
4349: pp_backend_deb_vas_platforms () {
4350: case "$pp_deb_arch_std" in
4351: x86_64) echo "linux-x86_64.deb";; # DO NOT add linux-x86.deb here!!
4352: *86) echo "linux-x86.deb";;
4353: *) pp_die "unknown architecture ${pp_deb_arch_std}";;
4354: esac
4355: }
4356: pp_backend_deb_init_svc_vars () {
4357:
4358: reload_signal=
1.1.1.2 ! misho 4359: start_runlevels=${pp_deb_default_start_runlevels-"2 3 4 5"} # == lsb default-start
! 4360: stop_runlevels=${pp_deb_default_stop_runlevels-"0 1 6"} # == lsb default-stop
1.1 misho 4361: svc_description="${pp_deb_default_svc_description}" # == lsb short descr
4362: svc_process=
4363:
4364: lsb_required_start='$local_fs $network'
4365: lsb_should_start=
4366: lsb_required_stop=
4367: lsb_description=
4368:
4369: start_priority=50
4370: stop_priority=50 #-- stop_priority = 100 - start_priority
4371: }
4372:
4373: pp_deb_service_make_init_script () {
4374: local svc=$1
4375: local script=/etc/init.d/$svc
4376: local out=$pp_destdir$script
4377: local _process _cmd
4378:
4379: pp_add_file_if_missing $script run 755 || return 0
4380:
4381: #-- start out as an empty shell script
4382: cat <<-'.' >$out
4383: #!/bin/sh
4384: .
4385:
4386: #-- determine the process name from $cmd unless $svc_process is given
4387: set -- $cmd
4388: #_process=${svc_process:-"$1"} --? WTF
4389:
4390: #-- construct a start command that builds a pid file if needed
1.1.1.2 ! misho 4391: #-- the command name in /proc/[pid]/stat is limited to 15 characters
1.1 misho 4392: _cmd="$cmd";
4393: _cmd_path=`echo $cmd | cut -d" " -f1`
1.1.1.2 ! misho 4394: _cmd_name=`basename $_cmd_path | cut -c1-15`
1.1 misho 4395: _cmd_args=`echo $cmd | cut -d" " -f2-`
4396: test x"$_cmd_path" != x"$_cmd_args" || _cmd_args=
4397:
4398: #-- generate the LSB init info
4399: cat <<-. >>$out
4400: ### BEGIN INIT INFO
4401: # Provides: ${svc}
4402: # Required-Start: ${lsb_required_start}
4403: # Should-Start: ${lsb_should_start}
4404: # Required-Stop: ${lsb_required_stop}
4405: # Default-Start: ${start_runlevels}
4406: # Default-Stop: ${stop_runlevels}
1.1.1.2 ! misho 4407: # Short-Description: ${svc_description:-no description}
1.1 misho 4408: ### END INIT INFO
4409: # Generated by PolyPackage ${pp_version}
4410: # ${copyright}
4411:
4412: .
4413:
4414: if test x"${svc_description}" = x"${pp_deb_default_svc_description}"; then
4415: svc_description=
4416: fi
4417:
4418: #-- write service-specific definitions
4419: cat <<. >>$out
4420: NAME="${_cmd_name}"
4421: DESC="${svc_description:-$svc service}"
4422: USER="${user}"
4423: GROUP="${group}"
4424: PIDFILE="${pidfile}"
4425: STOP_SIGNAL="${stop_signal}"
4426: RELOAD_SIGNAL="${reload_signal}"
4427: CMD="${_cmd}"
4428: DAEMON="${_cmd_path}"
4429: DAEMON_ARGS="${_cmd_args}"
4430: SCRIPTNAME=${script}
4431: .
4432:
4433: #-- write the generic part of the init script
4434: cat <<'.' >>$out
4435:
4436: [ -x "$DAEMON" ] || exit 0
4437:
4438: [ -r /etc/default/$NAME ] && . /etc/default/$NAME
4439:
4440: [ -f /etc/default/rcS ] && . /etc/default/rcS
4441:
4442: . /lib/lsb/init-functions
4443:
4444: do_start()
4445: {
4446: # Return
4447: # 0 if daemon has been started
4448: # 1 if daemon was already running
4449: # 2 if daemon could not be started
4450: if [ -n "$PIDFILE" ]
4451: then
4452: pidfile_opt="--pidfile $PIDFILE"
4453: else
4454: pidfile_opt="--make-pidfile --background --pidfile /var/run/$NAME.pid"
4455: fi
4456: if [ -n "$USER" ]
4457: then
4458: user_opt="--user $USER"
4459: fi
4460: if [ -n "$GROUP" ]
4461: then
4462: group_opt="--group $GROUP"
4463: fi
4464: if [ "$VERBOSE" = no ]
4465: then
4466: quiet_opt="--quiet"
4467: else
4468: quiet_opt="--verbose"
4469: fi
4470:
4471: start-stop-daemon --start $quiet_opt $pidfile_opt $user_opt --exec $DAEMON --test > /dev/null \
4472: || return 1
4473:
4474: # Note: there seems to be no way to tell whether the daemon will fork itself or not, so pass
4475: # --background for now
4476: start-stop-daemon --start $quiet_opt $pidfile_opt $user_opt --exec $DAEMON -- \
4477: $DAEMON_ARGS \
4478: || return 2
4479: }
4480:
4481: do_stop()
4482: {
4483: # Return
4484: # 0 if daemon has been stopped
4485: # 1 if daemon was already stopped
4486: # 2 if daemon could not be stopped
4487: # other if a failure occurred
4488: if [ -n "$PIDFILE" ]
4489: then
4490: pidfile_opt="--pidfile $PIDFILE"
4491: else
4492: pidfile_opt="--pidfile /var/run/$NAME.pid"
4493: fi
4494: if [ -n "$USER" ]
4495: then
4496: user_opt="--user $USER"
4497: fi
4498: if [ -n $STOP_SIGNAL ]
4499: then
4500: signal_opt="--signal $STOP_SIGNAL"
4501: fi
4502: if [ "$VERBOSE" = "no" ]
4503: then
4504: quiet_opt="--quiet"
4505: else
4506: quiet_opt="--verbose"
4507: fi
4508: start-stop-daemon --stop $quiet_opt $signal_opt --retry=TERM/30/KILL/5 $pidfile_opt --name $NAME
4509: RETVAL="$?"
4510: [ "$RETVAL" = 2 ] && return 2
4511: # Wait for children to finish too if this is a daemon that forks
4512: # and if the daemon is only ever run from this initscript.
4513: # If the above conditions are not satisfied then add some other code
4514: # that waits for the process to drop all resources that could be
4515: # needed by services started subsequently. A last resort is to
4516: # sleep for some time.
4517: start-stop-daemon --stop $quiet_opt --oknodo --retry=0/30/KILL/5 --exec $DAEMON
4518: [ "$?" = 2 ] && return 2
4519: # Many daemons don't delete their pidfiles when they exit.
4520: test -z $PIDFILE || rm -f $PIDFILE
4521: return "$RETVAL"
4522: }
4523:
4524: do_reload() {
4525: #
4526: # If the daemon can reload its configuration without
4527: # restarting (for example, when it is sent a SIGHUP),
4528: # then implement that here.
4529: #
4530: if [ -n "$PIDFILE" ]
4531: then
4532: pidfile_opt="--pidfile $PIDFILE"
4533: else
4534: pidfile_opt="--pidfile /var/run/$NAME.pid"
4535: fi
4536: if [ -n "$RELOAD_SIGNAL" ]
4537: then
4538: start-stop-daemon --stop --signal $RELOAD_SIGNAL $quiet_opt $pidfile_opt --name $NAME
4539: fi
4540: return 0
4541: }
4542:
4543: case "$1" in
4544: start)
4545: [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
4546: do_start
4547: case "$?" in
4548: 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
4549: 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
4550: esac
4551: ;;
4552: stop)
4553: [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
4554: do_stop
4555: case "$?" in
4556: 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
4557: 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
4558: esac
4559: ;;
4560: reload|force-reload)
4561: if [ -n "$RELOAD_SIGNAL" ]
4562: then
4563: log_daemon_msg "Reloading $DESC" "$NAME"
4564: do_reload
4565: log_end_msg $?
4566: else
4567: # Do a restart instead
4568: "$0" restart
4569: fi
4570: ;;
4571: restart)
4572: #
4573: # If the "reload" option is implemented then remove the
4574: # 'force-reload' alias
4575: #
4576: log_daemon_msg "Restarting $DESC" "$NAME"
4577: do_stop
4578: case "$?" in
4579: 0|1)
4580: do_start
4581: case "$?" in
4582: 0) log_end_msg 0 ;;
4583: 1) log_end_msg 1 ;; # Old process is still running
4584: *) log_end_msg 1 ;; # Failed to start
4585: esac
4586: ;;
4587: *)
4588: # Failed to stop
4589: log_end_msg 1
4590: ;;
4591: esac
4592: ;;
4593: *)
4594: #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
4595: echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
4596: exit 3
4597: ;;
4598: esac
4599:
4600: :
4601: .
4602: chmod 755 $out
4603: }
4604: pp_backend_deb_function() {
1.1.1.2 ! misho 4605: case "$1" in
1.1 misho 4606: pp_mkgroup) cat<<'.';;
4607: /usr/sbin/groupmod "$1" 2>/dev/null && return 0
4608: /usr/sbin/groupadd "$1"
4609: .
4610: pp_mkuser:depends) echo pp_mkgroup;;
4611: pp_mkuser) cat<<'.';;
4612: pp_tmp_system=
4613: id -u "$1" >/dev/null 2>/dev/null && return 0
4614: # deb 3.1's useradd changed API in 4.0. Gah!
4615: /usr/sbin/useradd --help 2>&1 | /bin/grep -q .--system &&
4616: pp_tmp_system=--system
4617: pp_mkgroup "${2:-$1}" || return 1
4618: /usr/sbin/useradd \
4619: -g "${2:-$1}" \
4620: -d "${3:-/nonexistent}" \
4621: -s "${4:-/bin/false}" \
4622: $pp_tmp_system \
4623: "$1"
4624: .
4625: pp_havelib) cat<<'.';;
4626: for pp_tmp_dir in `echo "/usr/lib:/lib${3:+:$3}" | tr : ' '`; do
4627: test -r "$pp_tmp_dir/lib$1.so{$2:+.$2}" && return 0
4628: done
4629: return 1
4630: .
4631: *) false;;
4632: esac
4633: }
4634:
4635: pp_platforms="$pp_platforms kit"
4636:
4637: pp_backend_kit_detect () {
4638: test x"$1" = x"OSF1"
4639: }
4640:
4641: pp_backend_kit_init () {
4642: pp_kit_name=
4643: pp_kit_package=
4644: pp_kit_desc=
4645: pp_kit_version=
4646: pp_kit_subset=
4647: pp_readlink_fn=pp_ls_readlink
4648: pp_kit_startlevels="2 3"
4649: pp_kit_stoplevels="0 2 3"
4650: }
4651:
4652: pp_backend_kit () {
4653: typeset mi_file k_file svc outfile
4654: typeset desc
4655:
4656: pp_backend_kit_names > /dev/null
4657:
4658: if test -z "$pp_kit_desc"; then
4659: pp_kit_desc="$description"
4660: fi
4661:
4662: mi_file="$pp_wrkdir/$pp_kit_subset.mi"
4663: k_file="$pp_wrkdir/$pp_kit_subset.k"
4664: scp_file="$pp_wrkdir/$pp_kit_subset.scp"
4665:
4666: desc="${pp_kit_desc:-$description}"
4667:
4668: cat <<-. >> $k_file
4669: NAME='$name'
4670: CODE=$pp_kit_name
4671: VERS=$pp_kit_version
4672: MI=$mi_file
4673: COMPRESS=0
4674: %%
4675: $pp_kit_subset . 0 '$desc'
4676: .
4677:
4678: if test -n "$pp_services"; then
4679: for svc in $pp_services; do
4680: pp_kit_make_service $svc
4681: pp_prepend $pp_wrkdir/%preun.run <<-.
4682: /sbin/init.d/$svc stop
4683: .
4684: done
4685: fi
4686:
4687: pp_backend_kit_make_mi "$mi_file"
4688: pp_backend_kit_make_scp
4689: #rm -rf $pp_wrkdir/kit_dest
4690: mkdir -p $pp_wrkdir/kit_dest
4691: pp_backend_kit_kits $k_file $pp_opt_destdir $pp_wrkdir/kit_dest
4692: tar cvf $pp_wrkdir/$pp_kit_subset.tar -C $pp_wrkdir/kit_dest .
4693: gzip -c $pp_wrkdir/$pp_kit_subset.tar > $pp_wrkdir/$pp_kit_subset.tar.gz
4694: #rm -rf $pp_wrkdir/$pp_kit_subset.tar $pp_wrkdir/scps
4695: }
4696:
4697: pp_backend_kit_make_mi () {
4698: # XXX this information should go into the .inv files
4699: typeset t m o g f p st line dm
4700: while read t m o g f p st; do
4701: case $t in
4702: f|d)
4703: echo "0 .$p $pp_kit_subset"
4704: echo " chmod $m $p" >> $pp_wrkdir/%post.run
4705: if [ x"$o" = x"-" ] ; then
4706: echo " chown root $p" >> $pp_wrkdir/%post.run
4707: else
4708: echo " chown $o $p" >> $pp_wrkdir/%post.run
4709: fi
4710: if [ x"$g" = x"-" ] ; then
4711: echo " chgrp 0 $p" >> $pp_wrkdir/%post.run
4712: else
4713: echo " chgrp $g $p" >> $pp_wrkdir/%post.run
4714: fi
4715: ;;
4716: s)
4717: echo " ln -s $st $p" >> $pp_wrkdir/%post.run
4718: echo " rm -f $p" >> $pp_wrkdir/%preun.run
4719: ;;
4720: esac
4721: done < $pp_wrkdir/%files.run | sort -k3 |uniq > $1
4722: }
4723:
4724:
4725: pp_backend_kit_make_scp () {
4726: scpdir="$pp_wrkdir/scps"
4727: mkdir "$scpdir" && touch "$scpdir"/$pp_kit_subset.scp
4728: cat <<EOF >"$scpdir"/$pp_kit_subset.scp
4729:
4730: . /usr/share/lib/shell/libscp
4731:
4732: case "\$ACT" in
4733: PRE_L)
4734: STL_ScpInit
4735:
4736:
4737:
4738: ;;
4739: POST_L)
4740: STL_ScpInit
4741: STL_LinkCreate
4742: EOF
4743:
4744: cat $pp_wrkdir/%post.run >>"$scpdir"/$pp_kit_subset.scp
4745: cat >>"$scpdir"/$pp_kit_subset.scp <<EOF
4746: ;;
4747: PRE_D)
4748: STL_ScpInit
4749: STL_LinkRemove
4750: EOF
4751: cat $pp_wrkdir/%preun.run >>"$scpdir"/$pp_kit_subset.scp
4752: cat >>"$scpdir"/$pp_kit_subset.scp <<EOF
4753: ;;
4754: POST_D)
4755:
4756: ;;
4757: C)
4758: STL_ScpInit
4759:
4760: case "\$1" in
4761: INSTALL)
4762: echo "Installation of the \$_DESC (\$_SUB) subset is complete."
4763: ;;
4764: DELETE)
4765: ;;
4766: esac
4767:
4768: ;;
4769: V)
4770:
4771: ;;
4772: esac
4773:
4774: exit 0
4775: EOF
4776: chmod 744 "$scpdir"/$pp_kit_subset.scp
4777: }
4778:
4779:
4780: pp_backend_kit_cleanup () {
4781: :
4782: }
4783:
4784: pp_backend_kit_names () {
4785: if test -z "$pp_kit_name"; then
4786: pp_warn "pp_kit_name not specified, using XXX"
4787: pp_kit_name=XXX
4788: fi
4789: case "$pp_kit_name" in
4790: ???) : ok;;
4791: *) pp_error "\$pp_kit_name $pp_kit_name must be three characters";;
4792: esac
4793: if test -z "$pp_kit_package"; then
4794: pp_warn "pp_kit_package not specified, using YYYY"
4795: pp_kit_package=YYYY
4796: fi
4797: if test -z "$pp_kit_version"; then
4798: pp_kit_version=`echo $version|tr -d '.a-zA-Z'`
4799: fi
4800: case "$pp_kit_version" in
4801: [0-9]) pp_kit_version="${pp_kit_version}00";;
4802: [0-9][0-9]) pp_kit_version="${pp_kit_version}0";;
4803: [0-9][0-9][0-9]) : ok;;
4804: *) pp_error "\$pp_kit_version $pp_kit_version must be three digits, ";;
4805: esac
4806: if test -z "$pp_kit_subset"; then
4807: pp_kit_subset="$pp_kit_name$pp_kit_package$pp_kit_version"
4808: fi
4809: echo "$pp_kit_subset.tar.gz"
4810: }
4811:
4812: pp_backend_kit_install_script () {
4813: typeset pkgname platform
4814:
4815: pkgname=`pp_backend_kit_names`
4816: platform="`pp_backend_kit_probe`"
4817:
4818: echo "#!/bin/sh"
4819: pp_install_script_common
4820: cat <<.
4821:
4822: cpt_to_tags () {
4823: test x"\$*" = x"all" && set -- $pp_components
4824: for cpt
4825: do
4826: echo "$name.\$cpt"
4827: done
4828: }
4829:
4830: test \$# -eq 0 && usage
4831: op="\$1"; shift
4832:
4833: case "\$op" in
4834: list-components)
4835: test \$# -eq 0 || usage \$op
4836: echo "$pp_components"
4837: ;;
4838: list-services)
4839: test \$# -eq 0 || usage \$op
4840: echo "$pp_services"
4841: ;;
4842: list-files)
4843: test \$# -ge 1 || usage \$op
4844: echo \${PP_PKGDESTDIR:-.}/$pkgname
4845: ;;
4846: install)
4847: test \$# -ge 1 || usage \$op
4848: verbose echo \${PP_PKGDESTDIR:-\`pwd\`}/$pkgname \`cpt_to_tags "\$@"\`
4849: #verbose swinstall -x verbose=0 -s \${PP_PKGDESTDIR:-\`pwd\`}/$pkgname \`cpt_to_tags "\$@"\`
4850: ;;
4851: uninstall)
4852: test \$# -ge 1 || usage \$op
4853: verbose echo \`cpt_to_tags "\$@"\`
4854: #verbose swremove -x verbose=0 \`cpt_to_tags "\$@"\`
4855: ;;
4856: start|stop)
4857: test \$# -ge 1 || usage \$op
4858: ec=0
4859: for svc
4860: do
4861: verbose /sbin/init.d/\$svc \$op
4862: [ \$? -eq 4 -o \$? -eq 0 ] || ec=1
4863: done
4864: exit \$ec
4865: ;;
4866: print-platform)
4867: echo "$platform"
4868: ;;
4869: *)
4870: usage
4871: ;;
4872: esac
4873: .
4874: }
4875:
4876: pp_backend_kit_function () {
4877: case "$1" in
4878: pp_mkgroup) cat <<'.';;
4879: grep "^$1:" /etc/group >/dev/null ||
4880: /usr/sbin/groupadd $1
4881: .
4882: pp_mkuser) cat <<'.';;
4883: eval user=\$$#
4884: grep "^$user:" /etc/passwd >/dev/null ||
4885: /usr/sbin/useradd -s /usr/bin/false "$@"
4886: .
4887: pp_havelib) cat <<'.';;
4888: for dir in `echo /usr/lib${3+:$3} | tr : ' '`; do
4889: test -r "$dir/lib$1.${2-sl}" && return 0
4890: done
4891: return 1
4892: .
4893: *) pp_error "unknown function request: $1";;
4894: esac
4895: }
4896:
4897: pp_backend_kit_init_svc_vars () {
4898: :
4899: }
4900:
4901: pp_backend_kit_probe () {
4902: echo tru64-`uname -r | sed 's/V\([0-9]*\)\.\([0-9]*\)/\1\2/'`
4903: }
4904:
4905: pp_kit_service_group_script () {
4906: typeset grp svcs scriptpath out
4907: grp="$1"
4908: svcs="$2"
4909: scriptpath="/sbin/init.d/$grp"
4910: out="$pp_destdir$scriptpath"
4911:
4912: pp_add_file_if_missing $scriptpath run 755 || return 0
4913:
4914: cat <<-. > $out
4915: #!/sbin/sh
4916: # generated by pp $pp_version
4917: svcs="$svcs"
4918: .
4919:
4920: cat <<-'.' >> $out
4921: #-- starts services in order.. stops them all if any break
4922: pp_start () {
4923: undo=
4924: for svc in $svcs; do
4925: /sbin/init.d/$svc start
4926: case $? in
4927: 0|4)
4928: undo="$svc $undo"
4929: ;;
4930: *)
4931: if test -n "$undo"; then
4932: for svc in $undo; do
4933: /sbin/init.d/$svc stop
4934: done
4935: return 1
4936: fi
4937: ;;
4938: esac
4939: done
4940: return 0
4941: }
4942:
4943: #-- stops services in reverse
4944: pp_stop () {
4945: reverse=
4946: for svc in $svcs; do
4947: reverse="$svc $reverse"
4948: done
4949: rc=0
4950: for svc in $reverse; do
4951: /sbin/init.d/$svc stop || rc=$?
4952: done
4953: return $rc
4954: }
4955:
1.1.1.2 ! misho 4956: case "$1" in
1.1 misho 4957: start_msg) echo "Starting $svcs";;
4958: stop_msg) echo "Stopping $svcs";;
4959: start) pp_start;;
4960: stop) pp_stop;;
4961: *) echo "usage: $0 {start|stop|start_msg|stop_msg}"
4962: exit 1;;
4963: esac
4964: .
4965: }
4966:
4967: pp_kit_service_script () {
4968: typeset svc scriptpath out
4969:
4970: svc="$1"
4971: scriptpath="/sbin/init.d/$svc"
4972:
4973: pp_load_service_vars "$svc"
4974:
4975: test -n "$user" -a x"$user" != x"root" &&
4976: cmd="SHELL=/usr/bin/sh /usr/bin/su $user -c \"exec `echo $cmd | sed -e 's,[$\\\`],\\&,g'`\""
4977: if test -z "$pidfile"; then
4978: pidfile="/var/run/$svc.pid"
4979: cmd="$cmd & echo \$! > \$pidfile"
4980: fi
4981:
4982: pp_add_file_if_missing $scriptpath run 755
4983:
4984: cat <<-. > $pp_destdir$scriptpath
4985: svc="$svc"
4986: pidfile="$pidfile"
4987:
4988: pp_start () {
4989: $cmd
4990: }
4991: .
4992: cat <<-'.' >>$pp_destdir$scriptpath
4993: pp_stop () {
4994: if test ! -s "$pidfile"; then
4995: echo "Unable to stop $svc (no pid file)"
4996: return 1
4997: else
4998: read pid < "$pidfile"
4999: if kill -0 "$pid" 2>/dev/null; then
5000: if kill -${stop_signal:-TERM} "$pid"; then
5001: rm -f "$pidfile"
5002: return 0
5003: else
5004: echo "Unable to stop $svc"
5005: return 1
5006: fi
5007: else
5008: rm -f "$pidfile"
5009: return 0
5010: fi
5011: fi
5012: }
5013:
5014: pp_running () {
5015: if test ! -s "$pidfile"; then
5016: return 1
5017: else
5018: read pid < "$pidfile"
5019: kill -0 "$pid" 2>/dev/null
5020: fi
5021: }
1.1.1.2 ! misho 5022: case "$1" in
1.1 misho 5023: start_msg) echo "Starting the $svc service";;
5024: stop_msg) echo "Stopping the $svc service";;
5025: start)
5026: if pp_running; then
5027: echo "$svc already running";
5028: exit 0
5029: elif pp_start; then
5030: echo "$svc started";
5031: # rc(1M) says we should exit 4, but nobody expects it!
5032: exit 0
5033: else
5034: exit 1
5035: fi
5036: ;;
5037: stop)
5038: if pp_stop; then
5039: echo "$svc stopped";
5040: exit 0
5041: else
5042: exit 1
5043: fi
5044: ;;
5045: *) echo "usage: $0 {start|stop|start_msg|stop_msg}"
5046: exit 1
5047: ;;
5048: esac
5049: .
5050: }
5051:
5052: pp_kit_make_service () {
5053: typeset level priority startlevels stoplevels
5054: typeset svc svcvar
5055:
5056: svc="$1"
5057: svcvar=`pp_makevar $svc`
5058:
5059: #-- don't do anything if the script exists
5060: if test -s "$pp_destdir/sbin/init.d/$svc"; then
5061: pp_error "$pp_destdir/sbin/init.d/$svc exists"
5062: return
5063: fi
5064:
5065: # symlink the script, depending on the priorities chosen
5066: eval priority='${pp_kit_priority_'$svcvar'}'
5067: test -z "$priority" && priority="${pp_kit_priority:-50}"
5068:
5069: eval startlevels='${pp_kit_startlevels_'$svcvar'}'
5070: test -z "$startlevels" && startlevels="$pp_kit_startlevels"
5071:
5072: eval stoplevels='${pp_kit_stoplevels_'$svcvar'}'
5073: test -z "$stoplevels" && stoplevels="$pp_kit_stoplevels"
5074:
5075: # create the script and config file
5076: pp_kit_service_script $svc
5077:
5078: # fix the priority up
5079: case "$priority" in
5080: ???) :;;
5081: ??) priority=0$priority;;
5082: ?) priority=00$priority;;
5083: esac
5084:
5085: if test x"$stoplevels" = x"auto"; then
5086: stoplevels=
5087: test -z "$startlevels" || for level in $startlevels; do
5088: stoplevels="$stoplevels `expr $level - 1`"
5089: done
5090: fi
5091:
5092: # create the symlinks
5093: test -z "$startlevels" || for level in $startlevels; do
5094: echo " ln -s /sbin/init.d/$svc /sbin/rc$level.d/S$priority$svc" >>$pp_wrkdir/%post.run
5095: echo " rm /sbin/rc$level.d/S$priority$svc" >>$pp_wrkdir/%preun.run
5096: done
5097: test -z "$stoplevels" || for level in $stoplevels; do
5098: echo " ln -s /sbin/init.d/$svc /sbin/rc$level.d/K$priority$svc" >>$pp_wrkdir/%post.run
5099: echo " rm -f /sbin/rc$level.d/K$priority$svc" >>$pp_wrkdir/%preun.run
5100: done
5101: }
5102:
5103:
5104:
5105:
5106: pp_backend_kit_sizes () {
5107: awk '
5108: BEGIN { root = usr = var = 0; }
5109: {
5110: if (substr($9, 1, 1) != "l")
5111: if (substr($10, 1, 6) == "./var/")
5112: var += $2;
5113: else if (substr($10, 1, 10) == "./usr/var/")
5114: var += $2
5115: else if (substr($10, 1, 6) == "./usr/")
5116: usr += $2
5117: else
5118: root += $2
5119: }
5120: END { printf "%d\t%d\t%d", root, usr, var }
5121: ' "$@"
5122: }
5123:
5124: pp_kit_kits_global () {
5125: line=`sed -n '/^%%/q;/^'$2'=/{s/^'$2'=//p;q;}' <"$1"`
5126: test -z "$line" && return 1
5127: eval "echo $line"
5128: :
5129: }
5130:
5131: pp_backend_kit_kits () {
5132: typeset KITFILE FROMDIR TODIR
5133: typeset SCPDIR
5134:
5135: SCPDIR="$pp_wrkdir/scps"
5136:
5137: PATH="/usr/lbin:/usr/bin:/etc:/usr/ucb:$PATH"; export PATH # XXX
5138: #umask 2 # XXX
5139:
5140: test $# -ge 3 || pp_die "pp_backend_kit_kits: too few arguments"
5141: KITFILE="$1"; shift
5142: FROMDIR="$1"; shift
5143: TODIR="$1"; shift
5144:
5145: test -f "$KITFILE" || pp_die "$KITFILE not found"
5146: test -d "$FROMDIR" || pp_die "$FROMDIR not found"
5147: test -d "$TODIR" || pp_die "$TODIR not found"
5148:
5149: INSTCTRL="$TODIR/instctrl"
5150: mkdir -p "$INSTCTRL" || pp_die "cannot create instctrl directory"
5151: chmod 775 "$INSTCTRL"
5152:
5153: grep "%%" $KITFILE > /dev/null || pp_die "no %% in $KITFILE"
5154:
5155: typeset NAME CODE VERS MI ROOT COMPRESS
5156: typeset S_LIST ALLSUBS
5157:
5158: NAME=`pp_kit_kits_global "$KITFILE" NAME` || pp_die "no NAME in $KITFILE"
5159: CODE=`pp_kit_kits_global "$KITFILE" CODE` || pp_die "no CODE in $KITFILE"
5160: VERS=`pp_kit_kits_global "$KITFILE" VERS` || pp_die "no VERS in $KITFILE"
5161: MI=`pp_kit_kits_global "$KITFILE" MI` || pp_die "no MI in $KITFILE"
5162: ROOT=`pp_kit_kits_global "$KITFILE" ROOT`
5163: COMPRESS=`pp_kit_kits_global "$KITFILE" COMPRESS`
5164:
5165: test -f "$MI" || pp_die "Inventory file $MI not found"
5166:
5167: case "$ROOT" in
5168: *ROOT)
5169: test -f "$TODIR/$ROOT" ||
5170: pp_die "Root image $ROOT not found in $TODIR" ;;
5171: esac
5172:
5173: ALLSUBS=`awk 'insub==1 {print $1} /^%%/ {insub=1}' <"$KITFILE"`
5174: test $# -eq 0 && set -- $ALLSUBS
5175:
5176: pp_debug "Creating $# $NAME subsets."
5177: pp_debug "ALLSUBS=<$ALLSUBS>"
5178:
5179: if test x"$COMPRESS" = x"1"; then
5180: COMPRESS=:
5181: else
5182: COMPRESS=false
5183: fi
5184:
5185: #rm -f *.ctrl Volume*
5186:
5187: for SUB
5188: do
5189: test -z "$SUB" && pp_die "SUB is empty"
5190:
5191: typeset INV CTRL ROOTSIZE USRSIZE VARSIZE TSSUB
5192: #rm -f Volume*
5193: case $SUB in
5194: .*) :;;
5195: *) pp_verbose rm -f "$TODIR/$SUB"* "$INSTCTRL/$SUB"*;;
5196: esac
5197:
5198: TSSUB="$pp_wrkdir/ts.$SUB"
5199:
5200: pp_debug "kits: Subset $SUB"
5201:
5202: INV="$SUB.inv"
5203: CTRL="$SUB.ctrl"
5204: pp_debug "kits: Generating media creation information..."
5205:
5206: # Invcutter takes as input
5207: # SUB dir/path
5208: # and generates stl_inv(4) files, like this
5209: # f 0 00000 0 0 100644 2/11/09 010 f dir/path none SUB
5210: grep " $SUB\$" "$MI" |
5211: pp_verbose /usr/lbin/invcutter \
5212: -v "$VERS" -f "$FROMDIR" > "$INSTCTRL/$INV" ||
5213: pp_die "failed to create $INSTCTRL/$INV"
5214: chmod 664 "$INSTCTRL/$INV"
5215:
5216: pp_backend_kit_sizes "$INSTCTRL/$INV" > "$pp_wrkdir/kit.sizes"
5217: read ROOTSIZE USRSIZE VARSIZE < "$pp_wrkdir/kit.sizes"
5218:
5219: # Prefix each line with $FROMDIR. This will be stripped
5220: awk '$1 != "d" {print from $10}' from="$FROMDIR/" \
5221: > "$TSSUB" < "$INSTCTRL/$INV" ||
5222: pp_die "failed"
5223:
5224: NVOLS=0
5225:
5226: pp_debug "kits: Creating $SUB control file..."
5227:
5228: sed '1,/^%%/d;/^'"$SUB"'/{p;q;}' < "$KITFILE" > "$pp_wrkdir/kit.line"
5229: read _SUB _IGNOR DEPS FLAGS DESC < "$pp_wrkdir/kit.line"
5230: if test -z "$_SUB"; then
5231: pp_warn "No such subset $SUB in $KITFILE"
5232: continue
5233: fi
5234: DEPS=`echo $DEPS | tr '|' ' '`
5235: case $FLAGS in
5236: FLGEXP*) pp_verbose FLAGS='"${'"$FLAGS"'}"' ;;
5237: esac
5238: case $DESC in
5239: *%*) DESC=`echo $DESC|awk -F% '{printf "%-36s%%%s\n", $1, $2}'`;;
5240: esac
5241:
5242: cat > "$INSTCTRL/$CTRL" <<-.
5243: NAME='$NAME $SUB'
5244: DESC=$DESC
5245: ROOTSIZE=$ROOTSIZE
5246: USRSIZE=$USRSIZE
5247: VARSIZE=$VARSIZE
5248: NVOLS=1:$NVOLS
5249: MTLOC=1:$TLOC
5250: DEPS="$DEPS"
5251: FLAGS=$FLAGS
5252: .
5253: chmod 664 "$INSTCTRL/$CTRL"
5254:
5255: pp_debug "kits: Making tar image"
5256:
5257: pp_verbose tar cfPR "$TODIR/$SUB" "$FROMDIR/" "$TSSUB" ||
5258: pp_error "problem creating kit file"
5259:
5260: if $COMPRESS; then
5261: pp_debug "kits: Compressing"
5262: (cd "$TODIR" && compress -f -v "$SUB") ||
5263: pp_die "problem compressing $TODIR/$SUB"
5264: SPC=`expr $SUB : '\(...\).*'` # first three characters
5265: SVC=`expr $SUB : '.*\(...\)'` # last three characters
5266: : > "$INSTCTRL/$SPC$SVC.comp"
5267: chmod 664 "$INSTCTRL/$SPC$SVC.comp"
5268: pp_debug "kits: Padding compressed file to 10kB" # wtf?
5269: rm -f "$TODIR/$SUB"
5270: pp_verbose \
5271: dd if="$TODIR/$SUB.Z" of="$TODIR/$SUB" bs=10k conv=sync ||
5272: pp_die "problem moving compressed file"
5273: rm -f "$TODIR/$SUB.Z"
5274: fi
5275: chmod 664 "$TODIR/$SUB"
5276:
5277: if test -f "$SCPDIR/$SUB.scp"; then
5278: cp "$SCPDIR/$SUB.scp" "$INSTCTRL/$SUB.scp"
5279: chmod 755 "$INSTCTRL/$SUB.scp"
5280: else
5281: pp_debug "kits: null subset control program for $SUB"
5282: : > "$INSTCTRL/$SUB.scp"
5283: chmod 744 "$INSTCTRL/$SUB.scp"
5284: fi
5285:
5286: pp_debug "kits: Finished creating media image for $SUB"
5287: done
5288:
5289: pp_debug "kits: Creating $CODE.image"
5290:
5291: case "$ROOT" in
5292: *ROOT) ALLSUBS="$ROOT $ALLSUBS"
5293: ;;
5294: esac
5295:
5296: (cd "$TODIR" && sum $ALLSUBS) > "$INSTCTRL/$CODE.image"
5297: chmod 664 "$INSTTRL/$CODE.image"
5298: pp_debug "kits: Creating INSTCTRL"
5299: (cd "$INSTCTRL" && tar cpvf - *) > "$TODIR/INSTCTRL"
5300: chmod 664 "$TODIR/INSTCTRL"
5301: cp "$INSTCTRL/$CODE.image" "$TODIR/$CODE.image"
5302: chmod 664 "$TODIR/$CODE.image"
5303:
5304: pp_debug "kits: Media image production complete"
5305: }
5306:
5307: pp_platforms="$pp_platforms rpm"
5308:
5309: pp_backend_rpm_detect () {
5310: test x"$1" = x"Linux" -a ! -f /etc/debian_version
5311: }
5312:
5313: pp_backend_rpm_init () {
5314:
5315: pp_rpm_version=
5316: pp_rpm_summary=
5317: pp_rpm_description=
5318: pp_rpm_group="Applications/Internet"
5319: pp_rpm_license="Unspecified"
5320: pp_rpm_vendor=
5321: pp_rpm_url=
5322: pp_rpm_packager=
5323: pp_rpm_provides=
5324: pp_rpm_requires=
5325: pp_rpm_release=
5326: pp_rpm_epoch=
5327: pp_rpm_dev_group="Development/Libraries"
5328: pp_rpm_dbg_group="Development/Tools"
5329: pp_rpm_doc_group="Documentation"
5330: pp_rpm_dev_description=
5331: pp_rpm_dbg_description=
5332: pp_rpm_doc_description=
5333: pp_rpm_dev_requires=
5334: pp_rpm_dbg_requires=
5335: pp_rpm_doc_requires=
5336: pp_rpm_dev_provides=
5337: pp_rpm_dbg_provides=
5338: pp_rpm_doc_provides=
5339:
5340: pp_rpm_dbg_pkgname=debug
5341: pp_rpm_dev_pkgname=devel
5342: pp_rpm_doc_pkgname=doc
5343:
5344: pp_rpm_defattr_uid=root
5345: pp_rpm_defattr_gid=root
5346:
5347: pp_rpm_detect_arch
5348: pp_rpm_detect_distro
5349: pp_rpm_rpmbuild=`pp_rpm_detect_rpmbuild`
5350:
5351: # SLES8 doesn't always come with readlink
5352: test -x /usr/bin/readlink -o -x /bin/readlink ||
5353: pp_readlink_fn=pp_ls_readlink
5354: }
5355:
5356: pp_rpm_detect_arch () {
5357: pp_rpm_arch=auto
5358:
5359: #-- Find the default native architecture that RPM is configured to use
5360: cat <<-. >$pp_wrkdir/dummy.spec
5361: Name: dummy
5362: Version: 1
5363: Release: 1
5364: Summary: dummy
5365: Group: ${pp_rpm_group}
5366: License: ${pp_rpm_license}
5367: %description
5368: dummy
5369: .
5370: $pp_opt_debug && cat $pp_wrkdir/dummy.spec
5371: pp_rpm_arch_local=`rpm -q --qf '%{arch}\n' --specfile $pp_wrkdir/dummy.spec`
5372: rm $pp_wrkdir/dummy.spec
5373:
5374: #-- Ask the kernel what machine architecture is in use
5375: local arch
5376: for arch in "`uname -m`" "`uname -p`"; do
5377: case "$arch" in
5378: i?86)
5379: pp_rpm_arch_std=i386
5380: break
5381: ;;
5382: x86_64|ppc|ppc64|ia64|s390|s390x)
5383: pp_rpm_arch_std="$arch"
5384: break
5385: ;;
5386: powerpc)
5387: # Probably AIX
5388: case "`/usr/sbin/lsattr -El proc0 -a type -F value`" in
5389: PowerPC_POWER*) pp_rpm_arch_std=ppc64;;
5390: *) pp_rpm_arch_std=ppc;;
5391: esac
5392: break
5393: ;;
5394: *) pp_rpm_arch_std=unknown
5395: ;;
5396: esac
5397: done
5398:
5399: #-- Later on, when files are processed, we use 'file' to determine
5400: # what platform ABIs are used. This is used when pp_rpm_arch == auto
5401: pp_rpm_arch_seen=
5402: }
5403:
5404: pp_rpm_detect_distro () {
5405: pp_rpm_distro=
5406: if test -f /etc/whitebox-release; then
5407: pp_rpm_distro=`awk '
5408: /^White Box Enterprise Linux release/ { print "wbel" $6; exit; }
5409: ' /etc/whitebox-release`
5410: elif test -f /etc/mandrakelinux-release; then
5411: pp_rpm_distro=`awk '
5412: /^Mandrakelinux release/ { print "mand" $3; exit; }
5413: ' /etc/mandrake-release`
5414: elif test -f /etc/mandrake-release; then
5415: pp_rpm_distro=`awk '
5416: /^Linux Mandrake release/ { print "mand" $4; exit; }
5417: /^Mandrake Linux release/ { print "mand" $4; exit; }
5418: ' /etc/mandrake-release`
5419: elif test -f /etc/fedora-release; then
5420: pp_rpm_distro=`awk '
5421: /^Fedora Core release/ { print "fc" $4; exit; }
5422: /^Fedora release/ { print "f" $3; exit; }
5423: ' /etc/fedora-release`
5424: elif test -f /etc/redhat-release; then
5425: pp_rpm_distro=`awk '
5426: /^Red Hat Enterprise Linux/ { print "rhel" $7; exit; }
5427: /^CentOS release/ { print "centos" $3; exit; }
1.1.1.2 ! misho 5428: /^CentOS Linux release/ { print "centos" $4; exit; }
1.1 misho 5429: /^Red Hat Linux release/ { print "rh" $5; exit; }
5430: ' /etc/redhat-release`
5431: elif test -f /etc/SuSE-release; then
5432: pp_rpm_distro=`awk '
5433: /^SuSE Linux [0-9]/ { print "suse" $3; exit; }
5434: /^SUSE LINUX [0-9]/ { print "suse" $3; exit; }
5435: /^openSUSE [0-9]/ { print "suse" $2; exit; }
5436: /^S[uU]SE Linux Enterprise Server [0-9]/ { print "sles" $5; exit; }
5437: /^S[uU]SE LINUX Enterprise Server [0-9]/ { print "sles" $5; exit; }
5438: /^SuSE SLES-[0-9]/ { print "sles" substr($2,6); exit; }
5439: ' /etc/SuSE-release`
5440: elif test -f /etc/pld-release; then
5441: pp_rpm_distro=`awk '
5442: /^[^ ]* PLD Linux/ { print "pld" $1; exit; }
5443: ' /etc/pld-release`
5444: elif test X"`uname -s 2>/dev/null`" = X"AIX"; then
5445: local r v
5446: r=`uname -r`
5447: v=`uname -v`
5448: pp_rpm_distro="aix$v$r"
5449: fi
5450: pp_rpm_distro=`echo $pp_rpm_distro | tr -d .`
5451: test -z "$pp_rpm_distro" &&
5452: pp_warn "unknown distro"
5453: }
5454:
5455: pp_rpm_detect_rpmbuild () {
5456: local cmd
5457: for cmd in rpmbuild rpm; do
5458: if `which $cmd > /dev/null 2>&1`; then
5459: echo $cmd
5460: return 0
5461: fi
5462: done
5463:
5464: pp_error "Could not find rpmbuild"
5465: # Default to `rpmbuild` in case it magically appears
5466: echo rpmbuild
5467: return 1
5468: }
5469:
5470: pp_rpm_label () {
5471: local label arg
5472: label="$1"; shift
5473: for arg
5474: do
5475: test -z "$arg" || echo "$label: $arg"
5476: done
5477: }
5478:
5479: pp_rpm_writefiles () {
5480: local _l t m o g f p st fo farch
5481: while read t m o g f p st; do
5482: _l="$p"
5483: test $t = d && _l="%dir ${_l%/}/"
5484: if test x"$m" = x"-"; then
5485: case "$t" in
5486: d) m=755;;
5487: f) m=644;;
5488: esac
5489: fi
5490: test x"$o" = x"-" && o="${pp_rpm_defattr_uid:-root}"
5491: test x"$g" = x"-" && g="${pp_rpm_defattr_gid:-root}"
5492: _l="%attr($m,$o,$g) $_l"
5493:
5494: if test "$t" = "f" -a x"$pp_rpm_arch" = x"auto"; then
5495: fo=`file "${pp_destdir}$p" 2>/dev/null`
5496: #NB: The following should match executables and shared objects,
5497: #relocatable objects. It will not match .a files however.
5498: case "$fo" in
5499: *": ELF 32-bit LSB "*", Intel 80386"*)
5500: farch=i386;;
5501: *": ELF 64-bit LSB "*", AMD x86-64"*|\
5502: *": ELF 64-bit LSB "*", x86-64"*)
5503: farch=x86_64;;
5504: *": ELF 32-bit MSB "*", PowerPC"*)
5505: farch=ppc;;
1.1.1.2 ! misho 5506: *": ELF 64-bit MSB "*", 64-bit PowerPC"*)
! 5507: farch=ppc64;;
1.1 misho 5508: *": ELF 64-bit LSB "*", IA-64"*)
5509: farch=ia64;;
5510: *": ELF 32-bit MSB "*", IBM S/390"*)
5511: farch=s390;;
5512: *": ELF 64-bit MSB "*", IBM S/390"*)
5513: farch=s390x;;
5514: *"executable (RISC System/6000)"*)
5515: farch=ppc;;
5516: *"64-bit XCOFF executable"*)
5517: farch=ppc64;;
5518: *" ELF "*)
5519: farch=ELF;;
5520: *)
5521: farch=noarch;;
5522: esac
5523: # If file(1) doesn't provide enough info, try readelf(1)
5524: if test "$farch" = "ELF"; then
5525: fo=`readelf -h "${pp_destdir}$p" | awk '{if ($1 == "Class:") {class=$2} else if ($1 == "Machine:") {machine=$0; sub(/^ *Machine: */, "", machine)}} END {print class " " machine}' 2>/dev/null`
5526: case "$fo" in
5527: "ELF32 Intel 80386")
5528: farch=i386;;
5529: "ELF64 "*[xX]"86-64")
5530: farch=x86_64;;
5531: "ELF32 PowerPC")
5532: farch=ppc;;
1.1.1.2 ! misho 5533: "ELF64 PowerPC"*)
1.1 misho 5534: farch=ppc64;;
5535: "ELF64 IA-64")
5536: farch=ia64;;
5537: "ELF32 IBM S/390")
5538: farch=s390;;
5539: "ELF64 IBM S/390")
5540: farch=s390x;;
5541: *)
5542: farch=noarch;;
5543: esac
5544: fi
5545: pp_debug "file: $fo -> $farch"
5546: test x"$farch" = x"noarch" || pp_add_to_list pp_rpm_arch_seen $farch
5547: fi
5548:
5549: case $f in *v*) _l="%config(noreplace) $_l";; esac
5550: echo "$_l"
5551: done
5552: echo
5553: }
5554:
5555: pp_rpm_subname () {
5556: case "$1" in
5557: run) : ;;
5558: dbg) echo "${2}${pp_rpm_dbg_pkgname}";;
5559: dev) echo "${2}${pp_rpm_dev_pkgname}";;
5560: doc) echo "${2}${pp_rpm_doc_pkgname}";;
5561: *) pp_error "unknown component '$1'";
5562: esac
5563: }
5564:
5565: pp_rpm_depend () {
1.1.1.2 ! misho 5566: local _name _vers
1.1 misho 5567: while read _name _vers; do
5568: case "$_name" in ""| "#"*) continue ;; esac
5569: echo "Requires: $_name ${_vers:+>= $_vers}"
5570: done
5571: }
5572:
1.1.1.2 ! misho 5573: pp_rpm_conflict () {
! 5574: local _name _vers
! 5575: while read _name _vers; do
! 5576: case "$_name" in ""| "#"*) continue ;; esac
! 5577: echo "Conflicts: $_name ${_vers:+>= $_vers}"
! 5578: done
! 5579: }
! 5580:
1.1 misho 5581: pp_rpm_override_requires () {
5582: local orig_find_requires
5583:
5584: if test -z "$pp_rpm_depend_filter_cmd"; then
5585: return 0
5586: fi
5587:
5588: orig_find_requires=`rpm --eval '%{__find_requires}'`
5589: cat << EOF > "$pp_wrkdir/filtered-find-requires"
5590: $orig_find_requires \$@ | $pp_rpm_depend_filter_cmd
5591: EOF
5592: chmod +x "$pp_wrkdir/filtered-find-requires"
5593: echo "%define __find_requires $pp_wrkdir/filtered-find-requires"
5594: # Might be necessary for old versions of RPM? Not for 4.4.2.
5595: #echo "%define _use_internal_dependency_generator 0"
5596: }
5597:
5598: pp_backend_rpm () {
5599: local cmp specfile _summary _group _desc _pkg _subname svc
5600:
5601: specfile=$pp_wrkdir/$name.spec
5602: : > $specfile
5603:
5604: #-- force existence of a 'run' component
5605: pp_add_component run
5606: : >> $pp_wrkdir/%files.run
5607:
5608: if test -z "$pp_rpm_arch"; then
5609: pp_error "Unknown RPM architecture"
5610: return 1
5611: fi
5612:
5613: #-- Write the header components of the RPM spec file
5614: cat <<-. >>$specfile
5615: Name: ${pp_rpm_name:-$name}
5616: Version: ${pp_rpm_version:-$version}
5617: Release: ${pp_rpm_release:-1}
5618: Summary: ${pp_rpm_summary:-$summary}
5619: Group: ${pp_rpm_group}
5620: License: ${pp_rpm_license}
5621: .
5622: if test -n "$pp_rpm_url"; then
5623: pp_rpm_label "URL" "$pp_rpm_url" >>$specfile
5624: fi
5625: pp_rpm_label "Vendor" "${pp_rpm_vendor:-$vendor}" >>$specfile
5626: pp_rpm_label "Packager" "$pp_rpm_packager" >>$specfile
5627: pp_rpm_label "Provides" "$pp_rpm_provides" >>$specfile
5628: pp_rpm_label "Requires" "$pp_rpm_requires" >>$specfile
5629:
5630: test -n "$pp_rpm_serial" && pp_warn "pp_rpm_serial deprecated"
5631: if test -n "$pp_rpm_epoch"; then
5632: #-- Epoch was introduced in RPM 2.5.6
5633: case `$pp_rpm_rpmbuild --version 2>/dev/null` in
5634: 1.*|2.[0-5].*|2.5.[0-5])
5635: pp_rpm_label "Serial" $pp_rpm_epoch >>$specfile;;
5636: *)
5637: pp_rpm_label "Epoch" $pp_rpm_epoch >>$specfile;;
5638: esac
5639: fi
5640:
5641: if test -n "$pp_rpm_requires"; then
5642: pp_rpm_label "Requires" "$pp_rpm_requires" >>$specfile
5643: elif test -s $pp_wrkdir/%depend.run; then
5644: pp_rpm_depend < $pp_wrkdir/%depend.run >> $specfile
5645: fi
1.1.1.2 ! misho 5646: if test -s $pp_wrkdir/%conflict.run; then
! 5647: pp_rpm_conflict < $pp_wrkdir/%conflict.run >> $specfile
! 5648: fi
1.1 misho 5649:
5650: pp_rpm_override_requires >> $specfile
5651:
5652: cat <<-. >>$specfile
5653:
5654: %description
5655: ${pp_rpm_description:-$description}
5656: .
5657:
5658: for cmp in $pp_components; do
5659: case $cmp in
5660: run) continue;;
5661: dev) _summary="development tools for $pp_rpm_summary"
5662: _group="$pp_rpm_dev_group"
5663: _desc="${pp_rpm_dev_description:-Development libraries for $name. $pp_rpm_description.}"
5664: ;;
5665: doc) _summary="documentation for $pp_rpm_summary"
5666: _group="$pp_rpm_doc_group"
5667: _desc="${pp_rpm_doc_description:-Documentation for $name. $pp_rpm_description.}"
5668: ;;
5669: dbg) _summary="diagnostic tools for $pp_rpm_summary"
5670: _group="$pp_rpm_dbg_group"
5671: _desc="${pp_rpm_dbg_description:-Diagnostic tools for $name.}"
5672: ;;
5673: esac
5674:
5675: _subname=`pp_rpm_subname $cmp`
5676: cat <<-.
5677:
5678: %package $_subname
5679: Summary: $name $_summary
5680: Group: $_group
5681: .
5682: eval '_pkg="$pp_rpm_'$cmp'_requires"'
5683: if test -n "$_pkg"; then
5684: eval pp_rpm_label Requires ${pp_rpm_name:-$name} $_pkg
5685: elif test -s $pp_wrkdir/%depend.$cmp; then
5686: pp_rpm_depend < $pp_wrkdir/%depend.$cmp >> $specfile
5687: fi
1.1.1.2 ! misho 5688: if test -s $pp_wrkdir/%conflict.$cmp; then
! 5689: pp_rpm_conflict < $pp_wrkdir/%conflict.$cmp >> $specfile
! 5690: fi
1.1 misho 5691:
5692: eval '_pkg="$pp_rpm_'$cmp'_provides"'
5693: eval pp_rpm_label Provides $_pkg
5694:
5695: cat <<-.
5696:
5697: %description $_subname
5698: $_desc
5699: .
5700: done >>$specfile
5701:
5702: #-- NB: we don't put any %prep, %build or %install RPM sections
5703: # into the spec file.
5704:
5705: #-- add service start/stop code
5706: if test -n "$pp_services"; then
5707: pp_rpm_service_install_common >> $pp_wrkdir/%post.run
5708:
5709: #-- record the uninstall commands in reverse order
5710: for svc in $pp_services; do
5711: pp_load_service_vars $svc
5712:
5713: pp_rpm_service_make_init_script $svc
5714:
5715: #-- append %post code to install the svc
5716: pp_rpm_service_install $svc >> $pp_wrkdir/%post.run
5717:
5718: #-- prepend %preun code to uninstall svc
5719: # (use files in case vars are modified)
5720: pp_rpm_service_remove $svc | pp_prepend $pp_wrkdir/%preun.run
5721: done
5722: pp_rpm_service_remove_common | pp_prepend $pp_wrkdir/%preun.run
5723: fi
5724:
5725: # make convenience service groups
5726: if test -n "$pp_service_groups"; then
5727: for grp in $pp_service_groups; do
5728: pp_rpm_service_group_make_init_script \
5729: $grp "`pp_service_get_svc_group $grp`"
5730: done
5731: fi
5732:
5733: #-- Write the RPM %file sections
5734: # (do this after services, since services adds to %files.run)
5735: for cmp in $pp_components; do
5736: _subname=`pp_rpm_subname $cmp`
5737:
5738: if test -s $pp_wrkdir/%check.$cmp; then
5739: echo ""
5740: echo "%pre $_subname"
5741: cat $pp_wrkdir/%check.$cmp
5742: echo : # causes script to exit true by default
5743: fi
5744:
5745: if test -s $pp_wrkdir/%files.$cmp; then
5746: echo ""
5747: echo "%files $_subname"
5748: pp_rpm_writefiles < $pp_wrkdir/%files.$cmp
5749: fi
5750:
5751: if test -n "$pp_rpm_ghost"; then
5752: for ghost in $pp_rpm_ghost; do
5753: echo "%ghost $ghost"
5754: done
5755: fi
5756:
5757: if test -s $pp_wrkdir/%pre.$cmp; then
5758: echo ""
5759: echo "%pre $_subname"
5760: cat $pp_wrkdir/%pre.$cmp
5761: echo : # causes script to exit true
5762: fi
5763:
5764: if test -s $pp_wrkdir/%post.$cmp; then
5765: echo ""
5766: echo "%post $_subname"
5767: cat $pp_wrkdir/%post.$cmp
5768: echo : # causes script to exit true
5769: fi
5770:
5771: if test -s $pp_wrkdir/%preun.$cmp; then
5772: echo ""
5773: echo "%preun $_subname"
5774: cat $pp_wrkdir/%preun.$cmp
5775: echo : # causes script to exit true
5776: fi
1.1.1.2 ! misho 5777:
! 5778: if test -s $pp_wrkdir/%postun.$cmp; then
! 5779: echo ""
! 5780: echo "%postun $_subname"
! 5781: cat $pp_wrkdir/%postun.$cmp
! 5782: echo : # causes script to exit true
! 5783: fi
1.1 misho 5784: done >>$specfile
5785:
5786: #-- create a suitable work area for rpmbuild
5787: cat <<-. >$pp_wrkdir/.rpmmacros
5788: %_topdir $pp_wrkdir
5789: # XXX Note escaped %% for use in headerSprintf
5790: %_rpmfilename %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm
5791: .
5792: mkdir $pp_wrkdir/RPMS
5793: mkdir $pp_wrkdir/BUILD
5794:
5795: if test x"$pp_rpm_arch" = x"auto"; then
5796: #-- Reduce the arch_seen list to exactly one item
5797: case "$pp_rpm_arch_seen" in
5798: "i386 x86_64"|"x86_64 i386")
5799: pp_rpm_arch_seen=x86_64;;
5800: *"s390 s390x"* | *"s390x s390"* )
5801: pp_rpm_arch_seen=s390x;;
5802: *" "*)
5803: pp_error "detected multiple targets: $pp_rpm_arch_seen"
5804: pp_rpm_arch_seen=unknown;; # not detected
5805: "")
5806: pp_warn "detected no binaries: using target noarch"
5807: pp_rpm_arch_seen=noarch;;
5808: *)
5809: pp_debug "detected architecture $pp_rpm_arch_seen"
5810: esac
5811: pp_rpm_arch="$pp_rpm_arch_seen"
5812: fi
5813:
5814: . $pp_wrkdir/%fixup
5815:
5816: $pp_opt_debug && cat $specfile
5817:
5818: pp_debug "creating: `pp_backend_rpm_names`"
5819:
5820: pp_debug "pp_rpm_arch_seen = <${pp_rpm_arch_seen}>"
5821: pp_debug "pp_rpm_arch = <${pp_rpm_arch}>"
5822:
5823: HOME=$pp_wrkdir \
5824: pp_verbose \
5825: $pp_rpm_rpmbuild -bb \
5826: --buildroot="$pp_destdir/" \
5827: --target="${pp_rpm_arch}" \
5828: --define='_unpackaged_files_terminate_build 0' \
5829: --define='_use_internal_dependency_generator 0' \
5830: `$pp_opt_debug && echo --verbose || echo --quiet` \
5831: $pp_rpm_rpmbuild_extra_flags \
5832: $specfile ||
5833: pp_error "Problem creating RPM packages"
5834:
5835: for f in `pp_backend_rpm_names`; do
5836: # The package might be in an arch-specific subdir
5837: pkgfile=not-found
5838: for dir in $pp_wrkdir/RPMS/${pp_rpm_arch} $pp_wrkdir/RPMS; do
5839: if test -f $dir/$f; then
5840: pkgfile=$dir/$f
5841: fi
5842: done
5843: if test x"$pkgfile" = x"not-found"; then
5844: pp_error "Problem predicting RPM filename: $f"
5845: else
5846: ln $pkgfile $pp_wrkdir/$f
5847: fi
5848: done
5849: }
5850:
5851: pp_rpm_output_name () {
5852: echo "${pp_rpm_name:-$name}`pp_rpm_subname "$1" -`-${pp_rpm_version:-$version}-${pp_rpm_release:-1}.${pp_rpm_arch}.rpm"
5853: }
5854:
5855: pp_backend_rpm_names () {
5856: local cmp _subname
5857: for cmp in $pp_components; do
5858: pp_rpm_output_name $cmp
5859: done
5860: }
5861:
5862: pp_backend_rpm_cleanup () {
5863: :
5864: }
5865:
5866: pp_rpm_print_requires () {
5867: local _subname _name
5868:
5869: echo "CPU:$pp_rpm_arch"
5870: ## XXX should be lines of the form (from file/ldd/objdump)
5871: # EXEC:/bin/sh
5872: # RTLD:libc.so.4:open
5873: rpm -q --requires -p $pp_wrkdir/`pp_rpm_output_name $1` |sed -e '/^rpmlib(/d;s/ //g;s/^/RPM:/' | sort -u
5874: }
5875:
5876: pp_backend_rpm_install_script () {
5877: local cmp _subname
5878:
5879: echo "#!/bin/sh"
5880: pp_install_script_common
5881:
5882: cat <<.
5883:
5884: cmp_to_pkgname () {
5885: local oi name
5886: if test x"\$1" = x"--only-installed"; then
5887: #-- only print if installation detected
5888: oi=false
5889: shift
5890: else
5891: oi=true
5892: fi
5893: test x"\$*" = x"all" &&
5894: set -- $pp_components
5895: for cmp
5896: do
5897: case \$cmp in
5898: .
5899: for cmp in $pp_components; do
5900: _subname=`pp_rpm_subname $cmp -`
5901: echo "$cmp) name=${pp_rpm_name:-$name}${_subname};;"
5902: done
5903: cat <<.
5904: *) usage;;
5905: esac
5906: if \$oi || rpm -q "\$name" >/dev/null 2>/dev/null; then
5907: echo "\$name"
5908: fi
5909: done
5910: }
5911:
5912:
5913: cmp_to_pathname () {
5914: test x"\$*" = x"all" &&
5915: set -- $pp_components
5916: for cmp
5917: do
5918: case \$cmp in
5919: .
5920: for cmp in $pp_components; do
5921: echo "$cmp) echo \${PP_PKGDESTDIR:-.}/`pp_rpm_output_name $cmp` ;;"
5922: done
5923: cat <<.
5924: *) usage;;
5925: esac
5926: done
5927: }
5928:
5929: print_requires () {
5930: test x"\$*" = x"all" &&
5931: set -- $pp_components
5932: for cmp
5933: do
5934: case \$cmp in
5935: .
5936: for cmp in $pp_components; do
5937: echo "$cmp) cat <<'._end'"
5938: pp_rpm_print_requires $cmp
5939: echo "._end"; echo ';;'
5940: done
5941: cat <<.
5942: *) usage;;
5943: esac
5944: done
5945: }
5946:
5947: test \$# -eq 0 && usage
5948: op="\$1"; shift
5949: case "\$op" in
5950: list-components)
5951: test \$# -eq 0 || usage \$op
5952: echo $pp_components
5953: ;;
5954: list-services)
5955: test \$# -eq 0 || usage \$op
5956: echo $pp_services
5957: ;;
5958: list-files)
5959: test \$# -ge 1 || usage \$op
5960: cmp_to_pathname "\$@"
5961: ;;
5962: install)
5963: test \$# -ge 1 || usage \$op
5964: verbose rpm -U --replacepkgs --oldpackage \
5965: \`cmp_to_pathname "\$@"\`
5966: ;;
5967: uninstall)
5968: test \$# -ge 1 || usage \$op
5969: pkgs=\`cmp_to_pkgname --only-installed "\$@"\`
5970: if test -z "\$pkgs"; then
5971: verbosemsg "nothing to uninstall"
5972: else
5973: verbose rpm -e \$pkgs
5974: fi
5975: ;;
5976: start|stop)
5977: test \$# -ge 1 || usage \$op
5978: ec=0
5979: for svc
5980: do
5981: verbose /etc/init.d/\$svc \$op || ec=1
5982: done
5983: exit \$ec
5984: ;;
5985: print-platform)
5986: test \$# -eq 0 || usage \$op
5987: echo "linux-${pp_rpm_arch}"
5988: ;;
5989: print-requires)
5990: test \$# -ge 1 || usage \$op
5991: print_requires "\$@"
5992: ;;
5993: *)
5994: usage
5995: ;;
5996: esac
5997: .
5998:
5999: }
6000:
6001: pp_backend_rpm_probe () {
6002: echo "${pp_rpm_distro}-${pp_rpm_arch_std}"
6003: }
6004:
6005: pp_backend_rpm_vas_platforms () {
6006: case "$pp_rpm_arch_std" in
6007: x86_64) echo "linux-x86_64.rpm linux-x86.rpm";;
6008: *86) echo "linux-x86.rpm";;
6009: s390) echo "linux-s390";;
6010: s390x) echo "linux-s390x";;
6011: ppc*) echo "linux-glibc23-ppc64 linux-glibc22-ppc64";;
6012: ia64) echo "linux-ia64";;
6013: *) pp_die "unknown architecture $pp_rpm_arch_std";;
6014: esac
6015: }
6016:
6017: pp_rpm_service_install_common () {
6018: cat <<-'.'
6019:
6020: _pp_install_service () {
6021: local svc level
6022: svc="$1"
6023: if [ -x /usr/lib/lsb/install_initd -a ! -r /etc/redhat-release ]
6024: then
6025: # LSB-style install
6026: /usr/lib/lsb/install_initd /etc/init.d/$svc &> /dev/null
6027: elif [ -x /sbin/chkconfig ]; then
6028: # Red Hat/chkconfig-style install
6029: /sbin/chkconfig --add $svc &> /dev/null
6030: /sbin/chkconfig $svc off &> /dev/null
6031: else
6032: : # manual links under /etc/init.d
6033: fi
6034: }
6035:
6036: _pp_enable_service () {
6037: local svc level
6038: svc="$1"
6039: if [ -x /usr/lib/lsb/install_initd -a ! -r /etc/redhat-release ]
6040: then
6041: # LSB-style install
6042: : # not sure how to enable
6043: elif [ -x /sbin/chkconfig ]; then
6044: # Red Hat/chkconfig-style install
6045: /sbin/chkconfig $svc on &> /dev/null
6046: else
6047: # manual install
6048: set -- `sed -n -e 's/^# Default-Start://p' /etc/init.d/$svc`
6049: start_priority=`sed -n -e 's/^# X-Quest-Start-Priority:[[:space:]]*//p' /etc/init.d/$svc`
6050: stop_priority=`sed -n -e 's/^# X-Quest-Stop-Priority:[[:space:]]*//p' /etc/init.d/$svc`
6051:
6052: # Provide default start & stop priorities of 20 & 80 in
6053: # accordance with Debian update-rc.d defaults
6054: if [ -z "$start_priority" ]; then
6055: start_priority=20
6056: fi
6057: if [ -z "$stop_priority" ]; then
6058: stop_priority=80
6059: fi
6060:
6061: if [ -d "/etc/rc.d" ];then
6062: rcdir=/etc/rc.d
6063: else
6064: rcdir=/etc
6065: fi
6066:
6067: for level
6068: do ln -sf /etc/init.d/$svc $rcdir/rc$level.d/S$start_priority$svc; done
6069: set -- `sed -n -e 's/^# Default-Stop://p' /etc/init.d/$svc`
6070: for level
6071: do ln -sf /etc/init.d/$svc $rcdir/rc$level.d/K$stop_priority$svc; done
6072: fi
6073: }
6074: .
6075: }
6076:
6077: pp_rpm_service_remove_common () {
6078: cat <<-'.'
6079:
6080: _pp_remove_service () {
6081: local svc
6082: svc="$1"
6083: /etc/init.d/$svc stop >/dev/null 2>&1
6084: if [ -x /usr/lib/lsb/remove_initd -a ! -r /etc/redhat-release ]
6085: then
6086: /usr/lib/lsb/remove_initd /etc/init.d/$svc &> /dev/null
6087: elif [ -x /sbin/chkconfig ]; then
6088: /sbin/chkconfig --del $svc &> /dev/null
6089: else
6090: if [ -d "/etc/rc.d" ];then
6091: rcdir=/etc/rc.d
6092: else
6093: rcdir=/etc
6094: fi
6095:
6096: rm -f $rcdir/rc?.d/[SK]??$svc
6097: fi
6098: }
6099: .
6100: }
6101:
6102:
6103: pp_rpm_service_install () {
6104: pp_rpm_service_make_init_script $1 >/dev/null ||
6105: pp_error "could not create init script for service $1"
6106: echo "_pp_install_service $1"
6107: test $enable = yes && echo "_pp_enable_service $1"
6108: }
6109:
6110: pp_rpm_service_remove () {
6111: cat <<-.
6112: if [ "\$1" = "remove" -o "\$1" = "0" ]; then
6113: # only remove the service if not upgrade
6114: _pp_remove_service $1
6115: fi
6116: .
6117: }
6118:
6119:
6120: pp_backend_rpm_init_svc_vars () {
6121:
6122: reload_signal=
1.1.1.2 ! misho 6123: start_runlevels=${pp_rpm_default_start_runlevels-"2 3 4 5"} # == lsb default-start
! 6124: stop_runlevels=${pp_rpm_default_stop_runlevels-"0 1 6"} # == lsb default-stop
1.1 misho 6125: svc_description="${pp_rpm_default_svc_description}" # == lsb short descr
6126: svc_process=
6127:
6128: lsb_required_start='$local_fs $network'
6129: lsb_should_start=
6130: lsb_required_stop=
6131: lsb_description=
6132:
6133: start_priority=50
6134: stop_priority=50 #-- stop_priority = 100 - start_priority
6135: }
6136:
6137: pp_rpm_service_group_make_init_script () {
6138: local grp=$1
6139: local svcs="$2"
6140: local script=/etc/init.d/$grp
6141: local out=$pp_destdir$script
6142:
6143: pp_add_file_if_missing $script run 755 || return 0
6144:
6145: cat <<-. >>$out
6146: #!/bin/sh
6147: svcs="$svcs"
6148: .
6149:
6150: cat <<-'.' >>$out
6151:
6152: #-- prints usage message
6153: pp_usage () {
6154: echo "usage: $0 {start|stop|status|restart|reload|condrestart|try-restart|force-reload}" >&2
6155: return 2
6156: }
6157:
6158: #-- starts services in order.. stops them all if any break
6159: pp_start () {
6160: undo=
6161: for svc in $svcs; do
6162: if /etc/init.d/$svc start; then
6163: undo="$svc $undo"
6164: else
6165: if test -n "$undo"; then
6166: for svc in $undo; do
6167: /etc/init.d/$svc stop
6168: done
6169: return 1
6170: fi
6171: fi
6172: done
6173: return 0
6174: }
6175:
6176: #-- stops services in reverse
6177: pp_stop () {
6178: reverse=
6179: for svc in $svcs; do
6180: reverse="$svc $reverse"
6181: done
6182: rc=0
6183: for svc in $reverse; do
6184: /etc/init.d/$svc stop || rc=$?
6185: done
6186: return $rc
6187: }
6188:
6189: #-- returns true only if all services return true status
6190: pp_status () {
6191: rc=0
6192: for svc in $svcs; do
6193: /etc/init.d/$svc status || rc=$?
6194: done
6195: return $rc
6196: }
6197:
6198: pp_reload () {
6199: rc=0
6200: for svc in $svcs; do
6201: /etc/init.d/$svc reload || rc=$?
6202: done
6203: return $rc
6204: }
6205:
6206: case "$1" in
6207: start) pp_start;;
6208: stop) pp_stop;;
6209: restart) pp_stop; pp_start;;
6210: status) pp_status;;
6211: try-restart|condrestart)
6212: if pp_status >/dev/null; then
6213: pp_restart
6214: fi;;
6215: reload) pp_reload;;
6216: force-reload) if pp_status >/dev/null; then
6217: pp_reload
6218: else
6219: pp_restart
6220: fi;;
6221: *) pp_usage;;
6222: esac
6223: .
6224: chmod 755 $out
6225: }
6226:
6227: pp_rpm_service_make_init_script () {
6228: local svc=$1
6229: local script=/etc/init.d/$svc
6230: local out=$pp_destdir$script
6231: local _process _cmd _rpmlevels
6232:
6233: pp_add_file_if_missing $script run 755 || return 0
6234:
6235: #-- start out as an empty shell script
6236: cat <<-'.' >$out
6237: #!/bin/sh
6238: .
6239:
6240: #-- determine the process name from $cmd unless $svc_process is given
6241: set -- $cmd
6242: _process=${svc_process:-"$1"}
6243:
6244: #-- construct a start command that builds a pid file if needed
6245: _cmd="$cmd";
6246: if test -z "$pidfile"; then
6247: pidfile=/var/run/$svc.pid
6248: _cmd="$cmd & echo \$! > \$pidfile"
6249: fi
6250: if test "$user" != "root"; then
6251: _cmd="su $user -c exec $_cmd";
6252: fi
6253:
6254: #-- generate the Red Hat chkconfig headers
6255: _rpmlevels=`echo $start_runlevels | tr -d ' '`
6256: cat <<-. >>$out
6257: # chkconfig: ${_rpmlevels:--} ${start_priority:-50} ${stop_priority:-50}
6258: # description: ${svc_description:-no description}
6259: # processname: ${_process}
6260: # pidfile: ${pidfile}
6261: .
6262:
6263: #-- generate the LSB init info
6264: cat <<-. >>$out
6265: ### BEGIN INIT INFO
6266: # Provides: ${svc}
6267: # Required-Start: ${lsb_required_start}
6268: # Should-Start: ${lsb_should_start}
6269: # Required-Stop: ${lsb_required_stop}
6270: # Default-Start: ${start_runlevels}
6271: # Default-Stop: ${stop_runlevels}
6272: # Short-Description: ${svc_description}
6273: ### END INIT INFO
6274: # Generated by PolyPackage ${pp_version}
6275: # ${copyright}
6276:
6277: .
6278:
6279: if test x"${svc_description}" = x"${pp_rpm_default_svc_description}"; then
6280: svc_description=
6281: fi
6282:
6283: #-- write service-specific definitions
6284: cat <<. >>$out
6285: #-- definitions specific to service ${svc}
6286: svc_name="${svc_description:-$svc service}"
6287: user="${user}"
6288: pidfile="${pidfile}"
6289: stop_signal="${stop_signal}"
6290: reload_signal="${reload_signal}"
6291: pp_exec_cmd () { $_cmd; }
6292: .
6293:
6294: #-- write the generic part of the init script
6295: cat <<'.' >>$out
6296:
6297: #-- use system message logging, if available
6298: if [ -f /lib/lsb/init-functions -a ! -r /etc/redhat-release ]; then
6299: . /lib/lsb/init-functions
6300: pp_success_msg () { log_success_msg "$@"; }
6301: pp_failure_msg () { log_failure_msg "$@"; }
6302: pp_warning_msg () { log_warning_msg "$@"; }
6303: elif [ -f /etc/init.d/functions ]; then
6304: . /etc/init.d/functions
6305: pp_success_msg () { echo -n "$*"; success "$@"; echo; }
6306: pp_failure_msg () { echo -n "$*"; failure "$@"; echo; }
6307: pp_warning_msg () { echo -n "$*"; warning "$@"; echo; }
6308: else
6309: pp_success_msg () { echo ${1:+"$*:"} OK; }
6310: pp_failure_msg () { echo ${1:+"$*:"} FAIL; }
6311: pp_warning_msg () { echo ${1:+"$*:"} WARNING; }
6312: fi
6313:
6314: #-- prints a status message
6315: pp_msg () { echo -n "$*: "; }
6316:
6317: #-- prints usage message
6318: pp_usage () {
6319: echo "usage: $0 {start|stop|status|restart|reload|condrestart|try-restart|force-reload}" >&2
6320: return 2
6321: }
6322:
6323: #-- reloads the service, if possible
6324: # returns 0=success 1=failure 3=unimplemented
6325: pp_reload () {
6326: test -n "$reload_signal" || return 3 # unimplemented
6327: pp_msg "Reloading ${svc_name}"
6328: if pp_signal -${reload_signal}; then
6329: pp_success_msg
6330: return 0
6331: else
6332: pp_failure_msg "not running"
6333: return 1
6334: fi
6335: }
6336:
6337: #-- delivers signal $1 to the pidfile
6338: # returns 0=success 1=failure
6339: pp_signal () {
6340: if test -r "$pidfile"; then
6341: read pid < $pidfile
6342: kill "$@" "$pid" 2>/dev/null
6343: else
6344: return 1
6345: fi
6346: }
6347:
6348: #-- prints information about the service status
6349: # returns 0=running 1=crashed 3=stopped
6350: pp_status () {
6351: pp_msg "Checking for ${svc_name}"
6352: if pp_signal -0; then
6353: pp_success_msg "running"
6354: return 0
6355: elif test -r "$pidfile"; then
6356: pp_failure_msg "not running (crashed)"
6357: return 1
6358: else
6359: pp_failure_msg "not running"
6360: return 3
6361: fi
6362: }
6363:
6364: #-- starts the service
6365: # returns 0=success 1=failure
6366: pp_start () {
6367: pp_msg "Starting ${svc_name}"
6368: if pp_status >/dev/null; then
6369: pp_warning_msg "already started"
6370: return 0
6371: elif pp_exec_cmd; then
6372: pp_success_msg
6373: return 0
6374: else
6375: pp_failure_msg "cannot start"
6376: return 1
6377: fi
6378: }
6379:
6380: #-- stops the service
6381: # returns 0=success (always)
6382: pp_stop () {
6383: pp_msg "Stopping ${svc_name}"
6384: if pp_signal -${stop_signal}; then
6385: pp_success_msg
6386: else
6387: pp_success_msg "already stopped"
6388: fi
6389: rm -f "$pidfile"
6390: return 0
6391: }
6392:
6393: #-- stops and starts the service
6394: pp_restart () {
6395: pp_stop
6396: pp_start
6397: }
6398:
6399: case "$1" in
6400: start) pp_start;;
6401: stop) pp_stop;;
6402: restart) pp_restart;;
6403: status) pp_status;;
6404: try-restart|condrestart)
6405: if pp_status >/dev/null; then
6406: pp_restart
6407: fi;;
6408: reload) pp_reload;;
6409: force-reload) if pp_status >/dev/null; then
6410: pp_reload
6411: else
6412: pp_restart
6413: fi;;
6414: *) pp_usage;;
6415: esac
6416:
6417: .
6418: chmod 755 $out
6419: }
6420: pp_backend_rpm_function () {
1.1.1.2 ! misho 6421: case "$1" in
1.1 misho 6422: pp_mkgroup) cat<<'.';;
6423: /usr/sbin/groupadd -f -r "$1"
6424: .
6425: pp_mkuser:depends) echo pp_mkgroup;;
6426: pp_mkuser) cat<<'.';;
6427: pp_mkgroup "${2:-$1}" || return 1
6428: /usr/sbin/useradd \
6429: -g "${2:-$1}" \
6430: -M -d "${3:-/nonexistent}" \
6431: -s "${4:-/bin/false}" \
6432: -r "$1"
6433: .
6434: pp_havelib) cat<<'.';;
6435: for pp_tmp_dir in `echo "/usr/lib:/lib${3:+:$3}" | tr : ' '`; do
6436: test -r "$pp_tmp_dir/lib$1.so{$2:+.$2}" && return 0
6437: done
6438: return 1
6439: .
6440: *) false;;
6441: esac
6442: }
6443:
6444: : NOTES <<.
6445:
6446: # creating a dmg file for publishing on the web
6447: hdiutil create -srcfolder /path/foo foo.dmg
6448: hdiutil internet-enable -yes /path/foo.dmg
6449: # Layout for packages
6450: <name>-<cpy>/component/<file>
6451: <name>-<cpt>/extras/postinstall
6452: <name>-<cpt>/extras/postupgrade
6453: # /Developer/usr/bin/packagemaker (man packagemaker)
6454:
6455: Make a bunch of packages, and then build a 'distribution'
6456: which is only understood by macos>10.4
6457:
6458: # Message files in the resource path used are
6459: Welcome.{rtf,html,rtfd,txt} - limited text shown in Intro
6460: ReadMe.{rtf,html,rtfd,txt} - scrollable/printable, after Intro
6461: License.{rtf,html,rtfd,txt} - ditto, user must click 'Accept'
6462: background.{jpg,tif,gif,pict,eps,pdf} 620x418 background image
6463:
6464: # These scripts looked for in the resource path
6465: InstallationCheck $pkgpath $defaultloc $targetvol
6466: 0:ok 32:warn 32+x:warn[1] 64:stop 96+x:stop[2]
6467: VolumeCheck $volpath
6468: 0:ok 32:failure 32+x:failure[3]
6469: preflight $pkgpath $targetloc $targetvol [priv]
6470: preinstall $pkgpath $targetloc $targetvol [priv]
6471: preupgrade $pkgpath $targetloc $targetvol [priv]
6472: postinstall $pkgpath $targetloc $targetvol [priv]
6473: postupgrade $pkgpath $targetloc $targetvol [priv]
6474: postflight $pkgpath $targetloc $targetvol [priv]
6475: 0:ok else fail (for all scripts)
6476:
6477: A detailed reason is deduced by finding an index x (16..31)
6478: in the file InstallationCheck.strings or VolumeCheck.strings.
6479:
6480: Scripts marked [priv] are executed with root privileges.
6481: None of the [priv] scripts are used by metapackages.
6482:
6483: # Default permissions
6484: Permissions of existing directories should match those
6485: of a clean install of the OS; typically root:admin 0775
6486: New directories or files should be 0775 or 0664 with the
6487: appropriate user:group.
6488: Exceptions:
6489: /etc root:admin 0755
6490: /var root:admin 0755
6491:
6492: <http://developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution4/Concepts/sd_pkg_flags.html>
6493: Info.plist = {
6494: CFBundleGetInfoString: "1.2.3, Quest Software, Inc.",
6495: CFBundleIdentifier: "com.quest.rc.openssh",
6496: CFBundleShortVersionString: "1.2.3",
6497: IFMajorVersion: 1,
6498: IFMinorVersion: 2,
6499: IFPkgFlagAllowBackRev: false,
6500: IFPkgFlagAuthorizationAction: "AdminAuthorization",
6501: IFPkgFlagDefaultLocation: "/",
6502: IFPkgFlagFollowLinks: true,
6503: IFPkgFlagInstallFat: false,
6504: IFPkgFlagInstalledSize: <integer>, # this is added by packagemaker
6505: IFPkgFlagIsRequired: false,
6506: IFPkgFlagOverwritePermissions: false,
6507: IFPkgFlagRelocatable: false,
6508: IFPkgFlagRestartAction: "NoRestart",
6509: IFPkgFlagRootVolumeOnly: false,
6510: IFPkgFlagUpdateInstalledLanguages: false,
6511: IFPkgFormatVersion= 0.10000000149011612,
6512: IFRequirementDicts: [ {
6513: Level = "requires",
6514: SpecArgument = "/opt/quest/lib/libvas.4.2.0.dylib",
6515: SpecType = "file",
6516: TestObject = true,
6517: TestOperator = "eq", } ]
6518: }
6519:
6520: Description.plist = {
6521: IFPkgDescriptionDescription = "this is the description text",
6522: IFPkgDescriptionTitle = "quest-openssh"
6523: }
6524:
6525: # Startup scripts
6526: 'launchd' is a kind of combined inetd and rc/init.d system.
6527: <http://developer.apple.com/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/DesigningDaemons.html>
6528: Create a /Library/LaunchDaemons/$daemonname.plist file
6529: Examples found in /System/Library/LaunchDaemons/
6530: See manual page launchd.plist(5) for details:
6531:
1.1.1.2 ! misho 6532: { Label: "com.quest.rc.foo", # required
1.1 misho 6533: Program: "/sbin/program",
6534: ProgramArguments: [ "/sbin/program", "arg1", "arg2" ], # required
6535: RunAtLoad: true,
6536: WatchPaths: [ "/etc/crontab" ],
6537: QueueDirectories: [ "/var/cron/tabs" ],
6538: inetdCompatibility: { Wait: false }, # inetd-only
6539: OnDemand: false, # recommended
6540: SessionCreate: true,
6541: UserName: "nobody",
6542: InitGroups: true,
6543: Sockets: { # inetd only
6544: Listeners: {
6545: SockServiceName: "ssh",
6546: Bonjour: ["ssh", "sftp-ssh"], } },
6547: Disabled: false,
6548: StandardErrorPath: "/dev/null",
6549: }
6550:
6551:
6552: How to add a new user
6553: dscl . -create /Users/$user
6554: dscl . -create /Users/$user UserShell /bin/bash
6555: dscl . -create /Users/$user RealName "$user"
6556: dscl . -create /Users/$user UniqueID $uid
6557: dscl . -create /Users/$user PrimaryGroupID $gid
6558: dscl . -create /Users/$user NFSHomeDirectory /Users/$user
6559: dscl . -passwd /Users/$user "$passwd"
6560: mkdir /Users/$user
6561: chown $uid.$gid /Users/$user
6562:
6563: .
6564:
6565:
6566: pp_platforms="$pp_platforms macos"
6567:
6568: pp_backend_macos_detect () {
6569: [ x"$1" = x"Darwin" ]
6570: }
6571:
6572: pp_backend_macos_init () {
6573: pp_macos_default_bundle_id_prefix="com.quest.rc."
6574: pp_macos_bundle_id=
6575: pp_macos_bundle_vendor=
6576: pp_macos_bundle_version=
6577: pp_macos_bundle_info_string=
1.1.1.2 ! misho 6578: pp_macos_pkg_type=bundle
! 6579: pp_macos_pkg_license=
! 6580: pp_macos_pkg_readme=
! 6581: pp_macos_pkg_welcome=
! 6582: pp_macos_sudo=sudo
1.1 misho 6583: # OS X puts the library version *before* the .dylib extension
6584: pp_shlib_suffix='*.dylib'
6585: }
6586:
6587: pp_macos_plist () {
6588: typeset in
6589: in=""
6590: while test $# -gt 0; do
6591: case "$1" in
6592:
6593: start-plist) cat <<-.; in=" "; shift ;;
6594: <?xml version="1.0" encoding="UTF-8"?>
6595: <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
6596: <plist version="1.0">
6597: .
6598: end-plist) echo "</plist>"; in=; shift;;
6599:
6600: '[') echo "$in<array>"; in="$in "; shift;;
6601: ']') echo "$in</array>"; in="${in# }"; shift;;
6602: '{') echo "<dict>"; in="$in "; shift;;
6603: '}') echo "</dict>"; in="${in# }"; shift;;
6604: key) shift; echo "$in<key>$1</key>"; shift;;
6605: string) shift;
6606: echo "$1" | sed -e 's/&/&/g;s/</\</g;s/>/\>/g;' \
6607: -e 's/^/'"$in"'<string>/;s/$/<\/string>/';
6608: shift;;
6609: true) echo "$in<true/>"; shift;;
6610: false) echo "$in<false/>"; shift;;
6611: real) shift; echo "$in<real>$1</real>"; shift;;
6612: integer) shift; echo "$in<integer>$1</integer>"; shift;;
6613: date) shift; echo "$in<date>$1</date>"; shift;; # ISO 8601 format
6614: data) shift; echo "$in<data>$1</data>"; shift;; # base64 encoded
6615: *) pp_error "pp_macos_plist: bad argument '$1'"; shift;;
6616: esac
6617: done
6618: }
6619:
6620: pp_macos_rewrite_cpio () {
6621: typeset script
6622: script=$pp_wrkdir/cpio-rewrite.pl
6623: cat <<-'.' >$script
1.1.1.2 ! misho 6624: #!/usr/bin/perl
! 6625: #
! 6626: # Filter a cpio file, applying the user/group/mode specified in %files
! 6627: #
! 6628: # A CPIO header block has octal fields at the following offset/lengths:
! 6629: # 0 6 magic
! 6630: # 6 6 dev
! 6631: # 12 6 ino
! 6632: # 18 6 mode
! 6633: # 24 6 uid
! 6634: # 30 6 gid
! 6635: # 36 6 nlink
! 6636: # 42 6 rdev
! 6637: # 48 11 mtime
! 6638: # 59 6 namesize (including NUL terminator)
! 6639: # 65 11 filesize
! 6640: # 76 --
! 6641: #
! 6642: use strict;
! 6643: use warnings;
! 6644: no strict 'subs';
! 6645:
! 6646: # set %uid, %gid, %mode based on %files
! 6647: my (%uid, %gid, %mode, %users, %groups);
! 6648: my %type_map = ( d => 0040000, f => 0100000, s => 0120000 );
1.1 misho 6649: while (<DATA>) {
1.1.1.2 ! misho 6650: my ($type,$mode,$uid,$gid,$flags,$name) =
! 6651: m/^(.) (\S+) (\S+) (\S+) (\S+) (\S+)/;
! 6652: $mode = $type eq "f" ? "0644" : "0755" if $mode eq "-";
! 6653: $uid = 0 if $uid eq "-";
! 6654: $gid = 0 if $gid eq "-";
! 6655: if ($uid ne "=" and $uid =~ m/\D/) {
! 6656: unless (exists $users{$uid}) {
! 6657: my @pw = getpwnam($uid) or die "bad username '$uid'";
! 6658: $users{$uid} = $pw[2];
! 6659: }
! 6660: $uid = $users{$uid};
! 6661: }
! 6662: if ($gid ne "=" and $gid =~ m/\D/) {
! 6663: unless (exists $groups{$gid}) {
! 6664: my @gr = getgrnam($gid) or die "bad group'$gid'";
! 6665: $groups{$gid} = $gr[2];
! 6666: }
! 6667: $gid = $groups{$gid};
! 6668: }
! 6669: $name =~ s:/$:: if $type eq "d";
! 6670: $name = ".".$name."\0";
! 6671: $uid{$name} = sprintf("%06o",int($uid)) unless $uid eq "=";
! 6672: $gid{$name} = sprintf("%06o",int($gid)) unless $gid eq "=";
! 6673: $mode{$name} = sprintf("%06o",oct($mode)|$type_map{$type}) unless $mode eq "=";
1.1 misho 6674: }
1.1.1.2 ! misho 6675: undef %users;
! 6676: undef %groups;
! 6677: # parse the cpio file
! 6678: my $hdrlen = 76;
! 6679: while (read(STDIN, my $header, $hdrlen)) {
! 6680: my ($name, $namesize, $filesize);
! 6681: my $filepad = 0;
! 6682: if ($header =~ m/^07070[12]/) {
! 6683: # SVR4 ASCII format, convert to ODC
! 6684: if ($hdrlen == 76) {
! 6685: # Read in rest of header and update header len for SVR4
! 6686: read(STDIN, $header, 110 - 76, 76);
! 6687: $hdrlen = 110;
! 6688: }
! 6689: my $ino = hex(substr($header, 6, 8)) & 0x3ffff;
! 6690: my $mode = hex(substr($header, 14, 8)) & 0x3ffff;
! 6691: my $uid = hex(substr($header, 22, 8)) & 0x3ffff;
! 6692: my $gid = hex(substr($header, 30, 8)) & 0x3ffff;
! 6693: my $nlink = hex(substr($header, 38, 8)) & 0x3ffff;
! 6694: my $mtime = hex(substr($header, 46, 8)) & 0xffffffff;
! 6695: $filesize = hex(substr($header, 54, 8)) & 0xffffffff;
! 6696: my $dev_maj = hex(substr($header, 62, 8));
! 6697: my $dev_min = hex(substr($header, 70, 8));
! 6698: my $dev = &makedev($dev_maj, $dev_min) & 0x3ffff;
! 6699: my $rdev_maj = hex(substr($header, 78, 8));
! 6700: my $rdev_min = hex(substr($header, 86, 8));
! 6701: my $rdev = &makedev($rdev_maj, $rdev_min) & 0x3ffff;
! 6702: $namesize = hex(substr($header, 94, 8)) & 0x3ffff;
! 6703: read(STDIN, $name, $namesize);
! 6704: # Header + name is padded to a multiple of 4 bytes
! 6705: my $namepad = (($hdrlen + $namesize + 3) & 0xfffffffc) - ($hdrlen + $namesize);
! 6706: read(STDIN, my $padding, $namepad) if ($namepad);
! 6707: # File data is padded to be a multiple of 4 bytes
! 6708: $filepad = (($filesize + 3) & 0xfffffffc) - $filesize;
! 6709:
! 6710: my $new_header = sprintf("070707%06o%06o%06o%06o%06o%06o%06o%011o%06o%011o", $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime, $namesize, $filesize);
! 6711: $header = $new_header;
! 6712: } elsif ($header =~ m/^070707/) {
! 6713: # POSIX Portable ASCII Format
! 6714: $namesize = oct(substr($header, 59, 6));
! 6715: $filesize = oct(substr($header, 65, 11));
! 6716: read(STDIN, $name, $namesize);
! 6717: } else {
! 6718: die "bad magic";
! 6719: }
! 6720: # update uid, gid and mode (already in octal)
! 6721: substr($header, 24, 6) = $uid{$name} if exists $uid{$name};
! 6722: substr($header, 30, 6) = $gid{$name} if exists $gid{$name};
! 6723: substr($header, 18, 6) = $mode{$name} if exists $mode{$name};
! 6724: print($header, $name);
! 6725: # check for trailer at EOF
! 6726: last if $filesize == 0 && $name =~ /^TRAILER!!!\0/;
! 6727: # copy-through the file data
! 6728: while ($filesize > 0) {
! 6729: my $seg = 8192;
! 6730: $seg = $filesize if $filesize < $seg;
! 6731: read(STDIN, my $data, $seg);
! 6732: print $data;
! 6733: $filesize -= $seg;
! 6734: }
! 6735: # If file data is padded, skip it
! 6736: read(STDIN, my $padding, $filepad) if ($filepad);
! 6737: }
! 6738: # pass through any padding at the end (blocksize-dependent)
! 6739: for (;;) {
! 6740: my $numread = read(STDIN, my $data, 8192);
! 6741: last unless $numread;
! 6742: print $data;
1.1 misho 6743: }
6744: exit(0);
1.1.1.2 ! misho 6745:
! 6746: sub makedev {
! 6747: (((($_[0] & 0xff)) << 24) | ($_[1] & 0xffffff));
! 6748: }
1.1 misho 6749: __DATA__
6750: .
6751: # Append to the script the %files data
6752: cat "$@" </dev/null >> $script
6753: /usr/bin/perl $script || pp_error "pp_macos_rewrite_cpio error";
6754: }
6755:
6756: pp_macos_files_bom () {
6757: typeset _l t m o g f p st owner
6758: while read t m o g f p st; do
6759: # make sure that $m is padded up to 4 digits long
6760: case "$m" in
6761: ?) m="000$m";;
6762: ??) m="00$m";;
6763: ???) m="0$m";;
1.1.1.2 ! misho 6764: ?????*) pp_error "pp_macos_writebom: mode '$m' too long";;
1.1 misho 6765: esac
6766:
6767: # convert owner,group into owner/group in octal
6768: case $o in -) o=0;; esac
6769: case $g in -) g=0;; esac
6770: owner=`pp_d2o $o`/`pp_d2o $g`
6771:
6772: case $t in
6773: f)
1.1.1.2 ! misho 6774: test x"$m" = x"000-" && m=0644
1.1 misho 6775: echo ".$p 10$m $owner `
6776: /usr/bin/cksum < "${pp_destdir}$p" |
1.1.1.2 ! misho 6777: awk '{print $2 " " $1}'`"
! 6778: ;;
1.1 misho 6779: d)
1.1.1.2 ! misho 6780: test x"$m" = x"000-" && m=0755
! 6781: echo ".${p%/} 4$m $owner"
! 6782: ;;
1.1 misho 6783: s)
1.1.1.2 ! misho 6784: test x"$m" = x"000-" && m=0755
1.1 misho 6785: rl=`/usr/bin/readlink "${pp_destdir}$p"`
6786: #test x"$rl" = x"$st" ||
6787: # pp_error "symlink mismatch $rl != $st"
6788: echo ".$p 12$m $owner `
6789: /usr/bin/readlink -n "${pp_destdir}$p" |
6790: /usr/bin/cksum |
1.1.1.2 ! misho 6791: awk '{print $2 " " $1}'` $st"
! 6792: ;;
1.1 misho 6793: esac
6794: done
6795: }
6796:
6797: pp_macos_bom_fix_parents () {
6798: perl -pe '
6799: sub dirname { my $d=shift; $d=~s,/[^/]*$,,; $d; }
6800: sub chk { my $d=shift;
6801: &chk(&dirname($d)) if $d =~ m,/,;
6802: unless ($seen{$d}++) {
6803: print "$d\t40755\t0/0\n";
6804: }
6805: }
1.1.1.2 ! misho 6806: m/^(\S+)\s+(\d+)/;
! 6807: if (oct($2) & 040000) {
! 6808: $seen{$1}++; # directory
! 6809: }
! 6810: &chk(&dirname($1));'
1.1 misho 6811: }
6812:
6813: pp_macos_files_size () {
6814: typeset _l t m o g f p st owner
6815: while read t m o g f p st; do
6816: case $t in
6817: f) wc -c < "${pp_destdir}$p";;
6818: s) echo 4095;;
6819: d) ;; # always seems to be zero
6820: esac
6821: done | awk '{n+=1+int($1/4096)} END {print n*4}'
6822: }
6823:
6824: pp_o2d () {
6825: awk 'BEGIN { x=0; '`echo "$1" |
6826: sed -e 's/./x=x*8+&;/g'`'print x;}' </dev/null
6827: }
6828: pp_d2o () {
6829: case "$1" in
6830: [0-7]) echo $1;;
6831: *) awk 'BEGIN { printf("%o\n", 0+('"$1"'));}' < /dev/null;;
6832: esac
6833: }
6834:
6835: pp_macos_mkbom () {
6836: #/usr/bin/mkbom -i $1 $2
6837: typeset path mode ugid size cksum linkpath
6838: typeset bomstage
6839:
6840: # Use mkbom if it understands -i (avoids a copy)
6841: if /usr/bin/mkbom -i /dev/null "$2" 2>/dev/null; then
6842: rm -f "$2"
6843: /usr/bin/mkbom -i "$1" "$2"
6844: return
6845: fi
6846:
6847: # On 10.4 we have this nonsense.
6848: pp_warn "mkbom workaround: copying source files to staging area"
6849:
6850: bomstage=$pp_wrkdir/bom_stage
1.1.1.2 ! misho 6851: $pp_macos_sudo /bin/mkdir "$bomstage"
1.1 misho 6852: while IFS=' ' read path mode ugid size cksumi linkpath; do
6853: if test -h "$pp_destdir/$path"; then
6854: $pp_macos_sudo /bin/ln -s "$linkpath" "$bomstage/$path"
6855: else
6856: if test -d "$pp_destdir/$path"; then
6857: $pp_macos_sudo /bin/mkdir -p "$bomstage/$path"
6858: else
6859: $pp_macos_sudo /bin/cp "$pp_destdir/$path" "$bomstage/$path"
6860: fi
6861: $pp_macos_sudo /bin/chmod $mode "$bomstage/$path"
6862: $pp_macos_sudo /usr/sbin/chown `echo $ugid| tr / :` "$bomstage/$path"
6863: fi
6864: done <"$1"
6865: (cd $bomstage && $pp_macos_sudo mkbom . $pp_wrkdir/bom_stage.bom) ||
6866: pp_error "mkbom failed"
6867: $pp_macos_sudo mv $pp_wrkdir/bom_stage.bom "$2"
6868: }
6869:
6870: pp_backend_macos () {
1.1.1.2 ! misho 6871: : ${pp_macos_bundle_id:=$pp_macos_default_bundle_id_prefix$name}
! 6872: case "$pp_macos_pkg_type" in
! 6873: bundle) pp_backend_macos_bundle;;
! 6874: flat) pp_backend_macos_flat;;
! 6875: *) pp_error "unsupported package type $pp_macos_pkg_type";;
! 6876: esac
! 6877: }
! 6878:
! 6879: pp_backend_macos_bundle () {
! 6880: typeset pkgdir Contents Resources lprojdir svc
1.1 misho 6881: typeset Info_plist Description_plist
1.1.1.2 ! misho 6882: typeset bundle_vendor bundle_version size cmp filelists
1.1 misho 6883:
6884: mac_version=`sw_vers -productVersion`
6885: bundle_vendor=${pp_macos_bundle_vendor:-$vendor}
6886:
6887: if test -z "$pp_macos_bundle_version"; then
6888: bundle_version=`echo "$version.0.0.0" | sed -n -e 's/[^0-9.]//g' \
6889: -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p'`
6890: else
6891: bundle_version="$pp_macos_bundle_version"
6892: fi
6893: source_version=`echo $version | sed 's/.*\.//'`
6894:
6895: # build the package layout
6896: pkgdir=$pp_wrkdir/$name.pkg
6897: Contents=$pkgdir/Contents
6898: Resources=$Contents/Resources
6899: lprojdir=$Resources/en.lproj
6900: mkdir $pkgdir $Contents $Resources $lprojdir ||
1.1.1.2 ! misho 6901: pp_error "Can't make package temporary directories"
1.1 misho 6902:
6903: echo "major: 1" > $Resources/package_version
6904: echo "minor: 0" >> $Resources/package_version
6905: echo "pmkrpkg1" > $Contents/PkgInfo
6906: case $mac_version in
6907: "10.6"*)
6908: xattr -w "com.apple.TextEncoding" "macintosh;0" "$Resources/package_version"
1.1.1.2 ! misho 6909: xattr -w "com.apple.TextEncoding" "macintosh;0" "$Contents/PkgInfo"
1.1 misho 6910: ;;
6911: esac
6912:
1.1.1.2 ! misho 6913: # Copy welcome file/dir for display at package install time.
! 6914: if test -n "$pp_macos_pkg_welcome"; then
! 6915: typeset sfx
! 6916: sfx=`echo "$pp_macos_pkg_welcome"|sed 's/^.*\.\([^\.]*\)$/\1/'`
! 6917: case "$sfx" in
! 6918: rtf|html|rtfd|txt) ;;
! 6919: *) sfx=txt;;
! 6920: esac
! 6921: cp -R ${pp_macos_pkg_welcome} $Resources/Welcome.$sfx
! 6922: fi
! 6923:
! 6924: # Copy readme file/dir for display at package install time.
! 6925: if test -n "$pp_macos_pkg_readme"; then
! 6926: typeset sfx
! 6927: sfx=`echo "$pp_macos_pkg_readme"|sed 's/^.*\.\([^\.]*\)$/\1/'`
! 6928: case "$sfx" in
! 6929: rtf|html|rtfd|txt) ;;
! 6930: *) sfx=txt;;
! 6931: esac
! 6932: cp -R ${pp_macos_pkg_readme} $Resources/ReadMe.$sfx
! 6933: fi
! 6934:
! 6935: # Copy license file/dir for display at package install time.
! 6936: if test -n "$pp_macos_pkg_license"; then
! 6937: typeset sfx
! 6938: sfx=`echo "$pp_macos_pkg_license"|sed 's/^.*\.\([^\.]*\)$/\1/'`
! 6939: case "$sfx" in
! 6940: rtf|html|rtfd|txt) ;;
! 6941: *) sfx=txt;;
! 6942: esac
! 6943: cp -R ${pp_macos_pkg_license} $Resources/License.$sfx
! 6944: fi
! 6945:
! 6946: # Add services (may modify %files)
! 6947: for svc in $pp_services .; do
! 6948: test . = "$svc" && continue
! 6949: pp_macos_add_service $svc
! 6950: done
! 6951:
! 6952: # Find file lists (%files.* includes ignore files)
! 6953: for cmp in $pp_components; do
! 6954: test -f $pp_wrkdir/%files.$cmp && filelists="$filelists${filelists:+ }$pp_wrkdir/%files.$cmp"
! 6955: done
! 6956:
1.1 misho 6957: # compute the installed size
1.1.1.2 ! misho 6958: size=`cat $filelists | pp_macos_files_size`
1.1 misho 6959:
6960: #-- Create Info.plist
6961: Info_plist=$Contents/Info.plist
6962: pp_macos_plist \
6963: start-plist \{ \
6964: key CFBundleGetInfoString string \
6965: "${pp_macos_bundle_info_string:-$version $bundle_vendor}" \
6966: key CFBundleIdentifier string \
1.1.1.2 ! misho 6967: "${pp_macos_bundle_id}" \
1.1 misho 6968: key CFBundleName string "$name" \
6969: key CFBundleShortVersionString string "$bundle_version" \
6970: key IFMajorVersion integer 1 \
6971: key IFMinorVersion integer 0 \
6972: key IFPkgFlagAllowBackRev false \
6973: key IFPkgFlagAuthorizationAction string "RootAuthorization" \
6974: key IFPkgFlagDefaultLocation string "/" \
6975: key IFPkgFlagFollowLinks true \
6976: key IFPkgFlagInstallFat true \
6977: key IFPkgFlagInstalledSize integer $size \
6978: key IFPkgFlagIsRequired false \
6979: key IFPkgFlagOverwritePermissions true \
6980: key IFPkgFlagRelocatable false \
6981: key IFPkgFlagRestartAction string "NoRestart" \
6982: key IFPkgFlagRootVolumeOnly true \
6983: key IFPkgFlagUpdateInstalledLanguages false \
6984: key IFPkgFlagUseUserMask false \
6985: key IFPkgFormatVersion real 0.10000000149011612 \
6986: key SourceVersion string $source_version \
6987: \} end-plist> $Info_plist
6988:
6989: # write en.lproj/Description.plist
6990: Description_plist=$lprojdir/Description.plist
6991: pp_macos_plist \
6992: start-plist \{ \
6993: key IFPkgDescriptionDeleteWarning string "" \
6994: key IFPkgDescriptionDescription string "$pp_macos_bundle_info_string" \
6995: key IFPkgDescriptionTitle string "$name" \
6996: key IFPkgDescriptionVersion string "$version" \
6997: \} end-plist > $Description_plist
6998:
1.1.1.2 ! misho 6999: # write Resources/files
! 7000: awk '{print $6}' $filelists > $Resources/files
1.1 misho 7001:
7002: # write package size file
7003: printf \
7004: "NumFiles 0
7005: InstalledSize $size
7006: CompressedSize 0
7007: " > $Resources/$name.sizes
7008:
1.1.1.2 ! misho 7009: # write Resources/preinstall
1.1 misho 7010: for cmp in $pp_components; do
7011: if test -s $pp_wrkdir/%pre.$cmp; then
7012: if test ! -s $Resources/preinstall; then
7013: echo "#!/bin/sh" > $Resources/preinstall
7014: chmod +x $Resources/preinstall
7015: fi
7016: cat $pp_wrkdir/%pre.$cmp >> $Resources/preinstall
7017: echo : >> $Resources/preinstall
7018: fi
7019: done
7020:
7021: # write Resources/postinstall
7022: for cmp in $pp_components; do
7023: if test -s $pp_wrkdir/%post.$cmp; then
7024: if test ! -s $Resources/postinstall; then
7025: echo "#!/bin/sh" > $Resources/postinstall
7026: chmod +x $Resources/postinstall
7027: fi
7028: cat $pp_wrkdir/%post.$cmp >> $Resources/postinstall
7029: echo : >> $Resources/postinstall
7030: fi
7031: done
7032:
1.1.1.2 ! misho 7033: # write Resources/postupgrade
1.1 misho 7034: for cmp in $pp_components; do
7035: if test -s $pp_wrkdir/%postup.$cmp; then
7036: if test ! -s $Resources/postupgrade; then
7037: echo "#!/bin/sh" > $Resources/postupgrade
7038: chmod +x $Resources/postupgrade
7039: fi
7040: cat $pp_wrkdir/%postup.$cmp >> $Resources/postupgrade
7041: echo : >> $Resources/postupgrade
7042: fi
7043: done
7044:
1.1.1.2 ! misho 7045: # write Resources/preremove
1.1 misho 7046: for cmp in $pp_components; do
7047: if test -s $pp_wrkdir/%preun.$cmp; then
7048: if test ! -s $Resources/preremove; then
7049: echo "#!/bin/sh" > $Resources/preremove
7050: chmod +x $Resources/preremove
7051: fi
7052: cat $pp_wrkdir/%preun.$cmp >> $Resources/preremove
7053: echo : >> $Resources/preremove
7054: fi
7055: done
7056:
1.1.1.2 ! misho 7057: # write Resources/postremove
1.1 misho 7058: for cmp in $pp_components; do
7059: if test -s $pp_wrkdir/%postun.$cmp; then
7060: if test ! -s $Resources/postremove; then
7061: echo "#!/bin/sh" > $Resources/postremove
7062: chmod +x $Resources/postremove
7063: fi
7064: cat $pp_wrkdir/%postun.$cmp >> $Resources/postremove
7065: echo : >> $Resources/postremove
7066: fi
7067: done
7068:
7069: # write uninstall info
7070: echo "version=$version" > $Resources/uninstall
7071: if [ -n "$pp_macos_requires" ];then
7072: echo "requires=$pp_macos_requires" >> $Resources/uninstall
7073: fi
7074:
1.1.1.2 ! misho 7075: . $pp_wrkdir/%fixup
! 7076:
1.1 misho 7077: # Create the bill-of-materials (Archive.bom)
1.1.1.2 ! misho 7078: cat $filelists | pp_macos_files_bom | sort |
1.1 misho 7079: pp_macos_bom_fix_parents > $pp_wrkdir/tmp.bomls
7080:
7081: pp_macos_mkbom $pp_wrkdir/tmp.bomls $Contents/Archive.bom
7082:
7083: # Create the cpio archive (Archive.pax.gz)
7084: (
7085: cd $pp_destdir &&
1.1.1.2 ! misho 7086: awk '{ print "." $6 }' $filelists | sed 's:/$::' | sort | /usr/bin/cpio -o | pp_macos_rewrite_cpio $filelists | gzip -9f -c > $Contents/Archive.pax.gz
1.1 misho 7087: )
7088:
1.1.1.2 ! misho 7089: test -d $pp_wrkdir/bom_stage && $pp_macos_sudo rm -rf $pp_wrkdir/bom_stage
1.1 misho 7090:
1.1.1.2 ! misho 7091: rm -f ${name}-${version}.dmg
1.1 misho 7092: hdiutil create -fs HFS+ -srcfolder $pkgdir -volname $name ${name}-${version}.dmg
7093: }
7094:
1.1.1.2 ! misho 7095: pp_backend_macos_flat () {
! 7096: typeset pkgdir bundledir Resources lprojdir svc
! 7097: typeset Info_plist Description_plist
! 7098: typeset bundle_vendor bundle_version size numfiles cmp filelists
! 7099:
! 7100: mac_version=`sw_vers -productVersion`
! 7101: bundle_vendor=${pp_macos_bundle_vendor:-$vendor}
! 7102:
! 7103: if test -z "$pp_macos_bundle_version"; then
! 7104: bundle_version=`echo "$version.0.0.0" | sed -n -e 's/[^0-9.]//g' \
! 7105: -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p'`
! 7106: else
! 7107: bundle_version="$pp_macos_bundle_version"
! 7108: fi
! 7109: source_version=`echo $version | sed 's/.*\.//'`
! 7110:
! 7111: # build the flat package layout
! 7112: pkgdir=$pp_wrkdir/pkg
! 7113: bundledir=$pp_wrkdir/pkg/$name.pkg
! 7114: Resources=$pkgdir/Resources
! 7115: lprojdir=$Resources/en.lproj
! 7116: mkdir $pkgdir $bundledir $Resources $lprojdir ||
! 7117: pp_error "Can't make package temporary directories"
! 7118:
! 7119: # Add services (may modify %files)
! 7120: for svc in $pp_services .; do
! 7121: test . = "$svc" && continue
! 7122: pp_macos_add_service $svc
! 7123: done
! 7124:
! 7125: # Find file lists (%files.* includes ignore files)
! 7126: for cmp in $pp_components; do
! 7127: test -f $pp_wrkdir/%files.$cmp && filelists="$filelists${filelists:+ }$pp_wrkdir/%files.$cmp"
! 7128: done
! 7129:
! 7130: # compute the installed size and number of files/dirs
! 7131: size=`cat $filelists | pp_macos_files_size`
! 7132: numfiles=`cat $filelists | wc -l`
! 7133: numfiles="${numfiles##* }"
! 7134:
! 7135: # Write Distribution file
! 7136: cat <<-. >$pkgdir/Distribution
! 7137: <?xml version="1.0" encoding="UTF-8"?>
! 7138: <installer-script minSpecVersion="1.000000" authoringTool="com.quest.rc.PolyPkg" authoringToolVersion="$pp_version" authoringToolBuild="$pp_revision">
! 7139: <title>$name $version</title>
! 7140: <options customize="never" allow-external-scripts="no"/>
! 7141: <domains enable_localSystem="true"/>
! 7142: .
! 7143: if test -n "$pp_macos_pkg_welcome"; then
! 7144: cp -R "${pp_macos_pkg_welcome}" $Resources
! 7145: echo " <welcome file=\"${pp_macos_pkg_welcome##*/}\"/>" >>$pkgdir/Distribution
! 7146: fi
! 7147: if test -n "$pp_macos_pkg_readme"; then
! 7148: cp -R "${pp_macos_pkg_readme}" $Resources
! 7149: echo " <readme file=\"${pp_macos_pkg_readme##*/}\"/>" >>$pkgdir/Distribution
! 7150: fi
! 7151: if test -n "$pp_macos_pkg_license"; then
! 7152: cp -R "${pp_macos_pkg_license}" $Resources
! 7153: echo " <license file=\"${pp_macos_pkg_license##*/}\"/>" >>$pkgdir/Distribution
! 7154: fi
! 7155: cat <<-. >>$pkgdir/Distribution
! 7156: <choices-outline>
! 7157: <line choice="choice0"/>
! 7158: </choices-outline>
! 7159: <choice id="choice0" title="$name $version">
! 7160: <pkg-ref id="${pp_macos_bundle_id}"/>
! 7161: </choice>
! 7162: <pkg-ref id="${pp_macos_bundle_id}" installKBytes="$size" version="$version" auth="Root">#$name.pkg</pkg-ref>
! 7163: </installer-script>
! 7164: .
! 7165:
! 7166: # write scripts archive
! 7167: # XXX - missing preupgrade, preflight, postflight
! 7168: mkdir $pp_wrkdir/scripts
! 7169: for cmp in $pp_components; do
! 7170: if test -s $pp_wrkdir/%pre.$cmp; then
! 7171: if test ! -s $pp_wrkdir/scripts/preinstall; then
! 7172: echo "#!/bin/sh" > $pp_wrkdir/scripts/preinstall
! 7173: chmod +x $pp_wrkdir/scripts/preinstall
! 7174: fi
! 7175: cat $pp_wrkdir/%pre.$cmp >> $pp_wrkdir/scripts/preinstall
! 7176: echo : >> $pp_wrkdir/scripts/preinstall
! 7177: fi
! 7178: if test -s $pp_wrkdir/%post.$cmp; then
! 7179: if test ! -s $pp_wrkdir/scripts/postinstall; then
! 7180: echo "#!/bin/sh" > $pp_wrkdir/scripts/postinstall
! 7181: chmod +x $pp_wrkdir/scripts/postinstall
! 7182: fi
! 7183: cat $pp_wrkdir/%post.$cmp >> $pp_wrkdir/scripts/postinstall
! 7184: echo : >> $pp_wrkdir/scripts/postinstall
! 7185: fi
! 7186: if test -s $pp_wrkdir/%postup.$cmp; then
! 7187: if test ! -s $pp_wrkdir/scripts/postupgrade; then
! 7188: echo "#!/bin/sh" > $pp_wrkdir/scripts/postupgrade
! 7189: chmod +x $pp_wrkdir/scripts/postupgrade
! 7190: fi
! 7191: cat $pp_wrkdir/%postup.$cmp >> $pp_wrkdir/scripts/postupgrade
! 7192: echo : >> $pp_wrkdir/scripts/postupgrade
! 7193: fi
! 7194: # XXX - not supported
! 7195: if test -s $pp_wrkdir/%preun.$cmp; then
! 7196: if test ! -s $pp_wrkdir/scripts/preremove; then
! 7197: echo "#!/bin/sh" > $pp_wrkdir/scripts/preremove
! 7198: chmod +x $pp_wrkdir/scripts/preremove
! 7199: fi
! 7200: cat $pp_wrkdir/%preun.$cmp >> $pp_wrkdir/scripts/preremove
! 7201: echo : >> $pp_wrkdir/scripts/preremove
! 7202: fi
! 7203: # XXX - not supported
! 7204: if test -s $pp_wrkdir/%postun.$cmp; then
! 7205: if test ! -s $pp_wrkdir/scripts/postremove; then
! 7206: echo "#!/bin/sh" > $pp_wrkdir/scripts/postremove
! 7207: chmod +x $pp_wrkdir/scripts/postremove
! 7208: fi
! 7209: cat $pp_wrkdir/%postun.$cmp >> $pp_wrkdir/scripts/postremove
! 7210: echo : >> $pp_wrkdir/scripts/postremove
! 7211: fi
! 7212: done
! 7213: if test "`echo $pp_wrkdir/scripts/*`" != "$pp_wrkdir/scripts/*"; then
! 7214: # write scripts archive, scripts are mode 0755 uid/gid 0/0
! 7215: # resetting the owner and mode is not strictly required
! 7216: (
! 7217: cd $pp_wrkdir/scripts || pp_error "Can't cd to $pp_wrkdir/scripts"
! 7218: rm -f $pp_wrkdir/tmp.files.scripts
! 7219: for s in *; do
! 7220: echo "f 0755 0 0 - ./$s" >>$pp_wrkdir/tmp.files.scripts
! 7221: done
! 7222: find . -type f | /usr/bin/cpio -o | pp_macos_rewrite_cpio $pp_wrkdir/tmp.files.scripts | gzip -9f -c > $bundledir/Scripts
! 7223: )
! 7224: fi
! 7225:
! 7226: # Write PackageInfo file
! 7227: cat <<-. >$bundledir/PackageInfo
! 7228: <?xml version="1.0" encoding="UTF-8"?>
! 7229: <pkg-info format-version="2" identifier="${pp_macos_bundle_id}" version="$version" install-location="/" relocatable="false" overwrite-permissions="true" followSymLinks="true" auth="root">
! 7230: <payload installKBytes="$size" numberOfFiles="$numfiles"/>
! 7231: .
! 7232: if test -s $bundledir/Scripts; then
! 7233: echo " <scripts>" >>$bundledir/PackageInfo
! 7234: for s in preflight postflight preinstall postinstall preupgrade postupgrade; do
! 7235: if test -s "$pp_wrkdir/scripts/$s"; then
! 7236: echo " <$s file=\"$s\"/>" >>$bundledir/PackageInfo
! 7237: fi
! 7238: done
! 7239: echo " </scripts>" >>$bundledir/PackageInfo
! 7240: fi
! 7241: cat <<-. >>$bundledir/PackageInfo
! 7242: </pkg-info>
! 7243: .
! 7244:
! 7245: . $pp_wrkdir/%fixup
! 7246:
! 7247: # Create the bill-of-materials (Bom)
! 7248: cat $filelists | pp_macos_files_bom | sort |
! 7249: pp_macos_bom_fix_parents > $pp_wrkdir/tmp.bomls
! 7250: pp_macos_mkbom $pp_wrkdir/tmp.bomls $bundledir/Bom
! 7251:
! 7252: # Create the cpio payload
! 7253: (
! 7254: cd $pp_destdir || pp_error "Can't cd to $pp_destdir"
! 7255: awk '{ print "." $6 }' $filelists | sed 's:/$::' | sort | /usr/bin/cpio -o | pp_macos_rewrite_cpio $filelists | gzip -9f -c > $bundledir/Payload
! 7256: )
! 7257:
! 7258: test -d $pp_wrkdir/bom_stage && $pp_macos_sudo rm -rf $pp_wrkdir/bom_stage
! 7259:
! 7260: # Create the flat package with xar (like pkgutil --flatten does)
! 7261: # Note that --distribution is only supported by Mac OS X 10.6 and above
! 7262: xar_flags="--compression=bzip2 --no-compress Scripts --no-compress Payload"
! 7263: case $mac_version in
! 7264: "10.5"*) ;;
! 7265: *) xar_flags="$xar_flags --distribution";;
! 7266: esac
! 7267: (cd $pkgdir && /usr/bin/xar $xar_flags -cf "../$name-$version.pkg" *)
! 7268: }
! 7269:
1.1 misho 7270: pp_backend_macos_cleanup () {
7271: :
7272: }
7273:
7274: pp_backend_macos_names () {
1.1.1.2 ! misho 7275: case "$pp_macos_pkg_type" in
! 7276: bundle) echo ${name}.pkg;;
! 7277: flat) echo ${name}-${version}.pkg;;
! 7278: *) pp_error "unsupported package type $pp_macos_pkg_type";;
! 7279: esac
1.1 misho 7280: }
7281:
7282: pp_backend_macos_install_script () {
7283: echo '#!/bin/sh'
7284: typeset pkgname platform
7285:
7286: pkgname="`pp_backend_macos_names`"
7287: platform="`pp_backend_macos_probe`"
7288: pp_install_script_common
7289:
7290: cat <<.
7291: test \$# -eq 0 && usage
7292: op="\$1"; shift
7293:
7294: case "\$op" in
7295: list-components)
7296: test \$# -eq 0 || usage \$op
7297: echo "$pp_components"
7298: ;;
7299: list-services)
7300: test \$# -eq 0 || usage \$op
7301: echo "$pp_services"
7302: ;;
7303: list-files)
7304: test \$# -ge 1 || usage \$op
7305: echo \${PP_PKGDESTDIR:-.}/"$pkgname"
7306: ;;
7307: install)
7308: test \$# -ge 1 || usage \$op
7309: vol=/Volumes/pp\$\$
7310: pkg=\$vol/${name}-${version}.pkg
7311: hdiutil attach -readonly -mountpoint \$vol \
7312: \${PP_PKGDESTDIR:-.}/"$pkgname"
7313: trap "hdiutil detach \$vol" 0
7314: installer -pkginfo -pkg \$pkg
7315: installer -verbose -pkg \$pkg -target /
7316: ;;
7317: uninstall)
7318: test \$# -ge 1 || usage \$op
7319: # XXX
7320: echo "Uninstall not implemented" >&2
7321: exit 1;;
7322: start|stop)
7323: test \$# -ge 1 || usage \$op
7324: ec=0
7325: for svc
7326: do
7327: # XXX
7328: echo "\${op} not implemented" >&2
7329: ec=1
7330: done
7331: exit \$ec
7332: ;;
7333: print-platform)
7334: echo "$platform"
7335: ;;
7336: *)
7337: usage;;
7338: esac
7339: .
7340: }
7341:
7342: pp_backend_macos_init_svc_vars () {
1.1.1.2 ! misho 7343: pp_macos_start_services_after_install=false
! 7344: pp_macos_service_name=
! 7345: pp_macos_default_service_id_prefix="com.quest.rc."
! 7346: pp_macos_service_id=
! 7347: pp_macos_service_user=
! 7348: pp_macos_service_group=
! 7349: pp_macos_service_initgroups=
! 7350: pp_macos_service_umask=
! 7351: pp_macos_service_cwd=
! 7352: pp_macos_service_nice=
! 7353: pp_macos_svc_plist_file=
! 7354: }
! 7355:
! 7356: pp_macos_launchd_plist () {
! 7357: typeset svc svc_id
! 7358:
! 7359: svc="$1"
! 7360: svc_id="$2"
! 7361:
! 7362: set -- $cmd
! 7363:
! 7364: if [ -n "$pp_macos_svc_plist_file" ]; then
! 7365: echo "## Launchd plist file already defined at $pp_macos_svc_plist_file"
! 7366: return
! 7367: fi
! 7368:
! 7369: echo "## Generating the launchd plist file for $svc"
! 7370: pp_macos_svc_plist_file="$pp_wrkdir/$svc.plist"
! 7371: cat <<-. > $pp_macos_svc_plist_file
! 7372: <?xml version="1.0" encoding="UTF-8"?>
! 7373: <!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
! 7374: http://www.apple.com/DTDs/PropertyList-1.0.dtd >
! 7375: <plist version="1.0">
! 7376: <dict>
! 7377: <key>Label</key>
! 7378: <string>$svc_id</string>
! 7379: <key>ProgramArguments</key>
! 7380: <array>
! 7381: .
! 7382: while test $# != 0; do
! 7383: printf " <string>$1</string>\n" >> $pp_macos_svc_plist_file
! 7384: shift
! 7385: done
! 7386: cat <<-. >> $pp_macos_svc_plist_file
! 7387: </array>
! 7388: <key>KeepAlive</key>
! 7389: <true/>
! 7390: .
! 7391: if test -n "$pp_macos_service_user"; then
! 7392: printf " <key>UserName</key>\n" >> $pp_macos_svc_plist_file
! 7393: printf " <string>$pp_macos_service_user</string>\n" >> $pp_macos_svc_plist_file
! 7394: fi
! 7395: if test -n "$pp_macos_service_group"; then
! 7396: printf " <key>GroupName</key>\n" >> $pp_macos_svc_plist_file
! 7397: printf " <string>$pp_macos_service_group</string>\n" >> $pp_macos_svc_plist_file
! 7398: fi
! 7399: if test -n "$pp_macos_service_initgroups"; then
! 7400: printf " <key>InitGroups</key>\n" >> $pp_macos_svc_plist_file
! 7401: printf " <string>$pp_macos_service_initgroups</string>\n" >> $pp_macos_svc_plist_file
! 7402: fi
! 7403: if test -n "$pp_macos_service_umask"; then
! 7404: printf " <key>Umask</key>\n" >> $pp_macos_svc_plist_file
! 7405: printf " <string>$pp_macos_service_umask</string>\n" >> $pp_macos_svc_plist_file
! 7406: fi
! 7407: if test -n "$pp_macos_service_cwd"; then
! 7408: printf " <key>WorkingDirectory</key>\n" >> $pp_macos_svc_plist_file
! 7409: printf " <string>$pp_macos_service_cwd</string>\n" >> $pp_macos_svc_plist_file
! 7410: fi
! 7411: if test -n "$pp_macos_service_nice"; then
! 7412: printf " <key>Nice</key>\n" >> $pp_macos_svc_plist_file
! 7413: printf " <string>$pp_macos_service_nice</string>\n" >> $pp_macos_svc_plist_file
! 7414: fi
! 7415: cat <<-. >> $pp_macos_svc_plist_file
! 7416: </dict>
! 7417: </plist>
! 7418: .
! 7419: }
! 7420:
! 7421: pp_macos_add_service () {
! 7422: typeset svc svc_id plist_file plist_dir
! 7423:
! 7424: pp_load_service_vars "$1"
! 7425: svc=${pp_macos_service_name:-$1}
! 7426: svc_id=${pp_macos_service_id:-$pp_macos_default_service_id_prefix$svc}
! 7427:
! 7428: #-- create a plist file for svc
! 7429: pp_macos_launchd_plist "$svc" "$svc_id"
! 7430:
! 7431: #-- copy the plist file into place and add to %files
! 7432: plist_dir="/Library/LaunchDaemons"
! 7433: plist_file="$plist_dir/$svc_id.plist"
! 7434: mkdir -p "$pp_destdir/$plist_dir"
! 7435: cp "$pp_macos_svc_plist_file" "$pp_destdir/$plist_file"
! 7436: pp_add_file_if_missing "$plist_file"
! 7437:
! 7438: #-- add code to start the service on install
! 7439: ${pp_macos_start_services_after_install} && <<-. >> $pp_wrkdir/%post.$svc
! 7440: # start service '$svc' automatically after install
! 7441: launchctl load "$plist_file"
! 7442: .
1.1 misho 7443: }
7444:
7445: pp_backend_macos_probe () {
7446: typeset name vers arch
7447: case `sw_vers -productName` in
7448: "Mac OS X") name="macos";;
7449: *) name="unknown";;
7450: esac
7451: vers=`sw_vers -productVersion | sed -e 's/^\([^.]*\)\.\([^.]*\).*/\1\2/'`
7452: arch=`arch`
7453: echo "$name$vers-$arch"
7454: }
7455:
7456: pp_backend_macos_vas_platforms () {
7457: echo "osx" # XXX non-really sure what they do.. it should be "macos"
7458: }
7459: pp_backend_macos_function () {
1.1.1.2 ! misho 7460: case "$1" in
1.1 misho 7461: _pp_macos_search_unused) cat<<'.';;
7462: # Find an unused value in the given path
7463: # args: path attribute minid [maxid]
7464: pp_tmp_val=$3
7465: while :; do
7466: test $pp_tmp_val -ge ${4:-999999} && return 1
7467: /usr/bin/dscl . -search "$1" "$2" $pp_tmp_val |
7468: grep . > /dev/null || break
7469: pp_tmp_val=`expr $pp_tmp_val + 1`
7470: done
7471: echo $pp_tmp_val
7472: .
7473: pp_mkgroup:depends) echo _pp_macos_search_unused;;
7474: pp_mkgroup) cat<<'.';;
7475: set -e
7476: /usr/bin/dscl . -read /Groups/"$1" >/dev/null 2>&1 && return
7477: pp_tmp_gid=`_pp_macos_search_unused /Groups PrimaryGroupID 100`
7478: /usr/bin/dscl . -create /Groups/"$1"
7479: /usr/bin/dscl . -create /Groups/"$1" PrimaryGroupID $pp_tmp_gid
7480: /usr/bin/dscl . -create /Groups/"$1" RealName "Group $1"
7481: /usr/bin/dscl . -create /Groups/"$1" GroupMembership ""
7482: /usr/bin/dscl . -create /Groups/"$1" Password '*'
7483: .
7484: pp_mkuser:depends) echo pp_mkgroup _pp_macos_search_unused;;
7485: pp_mkuser) cat<<'.';;
7486: set -e
7487: /usr/bin/dscl . -read /Users/"$1" >/dev/null 2>&1 && return
7488: pp_tmp_uid=`_pp_macos_search_unused /Users UniqueID 100`
7489: pp_mkgroup "${2:-$1}"
7490: pp_tmp_gid=`/usr/bin/dscl . -read /Groups/"${2:-$1}" \
7491: PrimaryGroupID | awk '{print $2}'`
7492: /usr/bin/dscl . -create /Users/"$1"
7493: /usr/bin/dscl . -create /Users/"$1" PrimaryGroupID $pp_tmp_gid
7494: /usr/bin/dscl . -create /Users/"$1" NFSHomeDirectory \
7495: "${3:-/var/empty}"
7496: /usr/bin/dscl . -create /Users/"$1" UserShell \
7497: "${4:-/usr/bin/false}"
7498: /usr/bin/dscl . -create /Users/"$1" RealName "$1"
7499: /usr/bin/dscl . -create /Users/"$1" UniqueID $pp_tmp_uid
7500: /usr/bin/dscl . -create /Users/"$1" Password '*'
7501: .
7502: pp_havelib) cat<<'.';;
7503: # (use otool -L to find dependent libraries)
7504: for pp_tmp_dir in `echo "${3:+$3:}/usr/local/lib:/lib:/usr/lib" |
7505: tr : ' '`; do
7506: test -r "$pp_tmp_dir/lib$1{$2:+.$2}.dylib" && return 0
7507: done
7508: return 1
7509: .
7510: *) false;;
7511: esac
7512: }
7513:
7514: pp_platforms="$pp_platforms inst"
7515:
7516: pp_backend_inst_detect () {
7517: case "$1" in
7518: IRIX*) return 0;;
7519: *) return 1;;
7520: esac
7521: }
7522:
7523: pp_backend_inst_init () {
7524: pp_readlink_fn=pp_ls_readlink
7525: }
7526:
7527: pp_backend_inst_create_idb()
7528: {
7529: typeset t m o g f p st
7530:
7531: while read t m o g f p st; do
7532: if test x"$o" = x"-"; then
7533: o="root"
7534: fi
7535: if test x"$g" = x"-"; then
7536: g="sys"
7537: fi
7538: case "$t" in
7539: f) test x"$m" = x"-" && m=444
7540: echo "f 0$m $o $g $p $p $name.sw.base"
7541: ;;
7542: d) test x"$m" = x"-" && m=555
7543: echo "d 0$m $o $g $p $p $name.sw.base"
7544: ;;
7545: s) test x"$m" = x"-" && m=777
7546: test x"$m" = x"777" ||
7547: pp_warn "$p: invalid mode $m for symlink, should be 777 or -"
7548: echo "l 0$m $o $g $p $p $name.sw.base symval($st)"
7549: ;;
7550: esac
7551: done
7552: }
7553:
7554: pp_backend_inst_create_spec()
7555: {
7556: echo "product $name"
7557: echo " id \"${summary}. Version: ${version}\""
7558: echo " image sw"
7559: echo " id \"Software\""
7560: echo " version $version"
7561: echo " order 9999"
7562: echo " subsys base"
7563: echo " id \"Base Software\""
7564: echo " replaces self"
7565: echo " exp $name.sw.base"
7566: echo " endsubsys"
7567: echo " endimage"
7568: echo "endproduct"
7569: }
7570:
7571: pp_backend_inst () {
7572: curdir=`pwd`
7573:
7574: cd "$pp_opt_wrkdir"
7575:
7576: # initialize
7577: pp_inst_tardist=tardist
7578: pp_inst_spec=${name}.spec
7579: pp_inst_idb=${name}.idb
7580:
7581: rm -rf $pp_inst_tardist $pp_inst_spec $pp_inst_idb
7582: mkdir -p $pp_inst_tardist
7583:
7584: # Create idb file
7585: (for _cmp in $pp_components; do
7586: cat %files.$_cmp | sort +4u -6 | pp_backend_inst_create_idb
7587: done) >> $pp_inst_idb
7588:
7589: pp_backend_inst_create_spec >> $pp_inst_spec
7590:
7591: # Generate tardist
7592: gendist -verbose -all -root / -source $pp_opt_destdir -idb $pp_inst_idb -spec $pp_inst_spec -dist $pp_inst_tardist $name
7593: tar -cvf `pp_backend_inst_names` $pp_inst_tardist
7594:
7595: cd "$curdir"
7596: }
7597:
7598: pp_backend_inst_cleanup () {
7599: :
7600: }
7601:
7602: pp_backend_inst_names () {
7603: echo ${name}-${version}.tardist
7604: }
7605:
7606: pp_backend_inst_install_script () {
7607: :
7608: }
7609:
7610: pp_backend_inst_function () {
7611: echo false
7612: }
7613:
7614: pp_backend_inst_init_svc_vars () {
7615: :
7616: }
7617:
7618: pp_backend_inst_probe () {
7619: cpu=`hinv|sed -n '/^CPU/{s/000 /k /;s/^CPU: //;s/ Process.*//;s/^MIPS //;p;q;}'|tr A-Z a-z`
7620: echo irix`uname -r`-$cpu
7621: }
7622:
7623: pp_backend_inst_vas_platforms () {
7624: echo "irix-65"
7625: }
7626:
7627: pp_platforms="$pp_platforms null"
7628:
7629: pp_backend_null_detect () {
7630: ! :
7631: }
7632:
7633: pp_backend_null_init () {
7634: :
7635: }
7636:
7637:
7638: pp_backend_null () {
7639: :
7640: }
7641:
7642: pp_backend_null_cleanup () {
7643: :
7644: }
7645:
7646: pp_backend_null_names () {
7647: :
7648: }
7649:
7650: pp_backend_null_install_script () {
7651: :
7652: }
7653:
7654: pp_backend_null_function () {
7655: echo false
7656: }
7657:
7658: pp_backend_null_init_svc_vars () {
7659: :
7660: }
7661:
7662: pp_backend_null_probe () {
7663: echo unknown-unknown
7664: }
7665:
7666: pp_backend_null_vas_platforms () {
7667: :
7668: }
7669:
7670:
7671: quest_require_vas () {
7672: typeset v d
7673:
7674: if test $# -ne 1; then
7675: return
7676: fi
7677: set -- `echo "$1" | tr . ' '` 0 0 0
7678:
7679: for d
7680: do
7681: echo $d | grep '^[0-9][0-9]*$' > /dev/null ||
7682: pp_error "quest_require_vas: Bad version component $d"
7683: done
7684:
7685: test $# -lt 4 &&
7686: pp_error "quest_require_vas: missing version number"
7687:
7688: case "$1.$2.$3.$4" in
7689: *.0.0.0) v=$1;;
7690: *.*.0.0) v=$1.$2;;
7691: *.*.*.0) v=$1.$2.$3;;
7692: *) v=$1.$2.$3.$4;;
7693: esac
7694:
7695: cat <<.
7696: if test -x /opt/quest/bin/vastool &&
7697: /opt/quest/bin/vastool -v |
7698: awk 'NR == 1 {print \$4}' |
7699: awk -F. '{ if (\$1<$1 || \$1==$1 && ( \
7700: \$2<$2 || \$2==$2 && ( \
7701: \$3<$3 || \$2==$3 && ( \
7702: \$4<$4 )))) exit(1); }'
7703: then
7704: exit 0
7705: else
7706: echo "Requires VAS $v or later"
7707: exit 1
7708: fi
7709: .
7710: }
7711: pp_main ${1+"$@"}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>