| 1 |
#!/bin/sh |
| 2 |
# Copyright 2024 One Identity LLC. ALL RIGHTS RESERVED |
| 3 |
pp_revision="20240518" |
| 4 |
# Copyright 2018 One Identity LLC. ALL RIGHTS RESERVED. |
| 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 One Identity LLC. 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" |
| 34 |
pp_copyright="Copyright 2018, One Identity LLC. ALL RIGHTS RESERVED." |
| 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_is_version_greater () { |
| 798 |
smaller_version="$(echo -e "$1\n$2" | sort -V | head -1)" |
| 799 |
test x"$smaller_version" = x"$1" |
| 800 |
} |
| 801 |
|
| 802 |
pp_if_true=0 |
| 803 |
pp_if_false=0 |
| 804 |
|
| 805 |
pp_frontend_init () { |
| 806 |
name= |
| 807 |
version= |
| 808 |
build_number= |
| 809 |
summary="no summary" |
| 810 |
description="No description" |
| 811 |
copyright="Copyright 2018 One Identity LLC. ALL RIGHTS RESERVED." |
| 812 |
|
| 813 |
#-- if the user supplied extra arguments on the command line |
| 814 |
# then load them now. |
| 815 |
pp_debug "pp_opt_init_vars=$pp_opt_init_vars" |
| 816 |
test -n "$pp_opt_init_vars" && eval "$pp_opt_init_vars" |
| 817 |
} |
| 818 |
|
| 819 |
pp_is_qualifier () { |
| 820 |
typeset ret |
| 821 |
|
| 822 |
case "$1" in |
| 823 |
"["*"]") ret=true;; |
| 824 |
*) ret=false;; |
| 825 |
esac |
| 826 |
pp_debug "is_qualifier: $* -> $ret" |
| 827 |
test $ret = true |
| 828 |
} |
| 829 |
|
| 830 |
pp_eval_qualifier () { |
| 831 |
typeset ret |
| 832 |
|
| 833 |
case "$1" in |
| 834 |
"[!$pp_platform]"| \ |
| 835 |
"[!"*",$pp_platform]"| \ |
| 836 |
"[!$pp_platform,"*"]"| \ |
| 837 |
"[!"*",$pp_platform,"*"]") ret=false;; |
| 838 |
"[!"*"]") ret=true;; |
| 839 |
"[$pp_platform]"| \ |
| 840 |
"["*",$pp_platform]"| \ |
| 841 |
"[$pp_platform,"*"]"| \ |
| 842 |
"["*",$pp_platform,"*"]") ret=true;; |
| 843 |
"["*"]") ret=false;; |
| 844 |
*) pp_die "pp_eval_qualifier: bad qualifier '$1'" |
| 845 |
esac |
| 846 |
pp_debug "eval: $* -> $ret" |
| 847 |
test true = $ret |
| 848 |
} |
| 849 |
|
| 850 |
pp_frontend_if () { |
| 851 |
typeset ifcmd ifret |
| 852 |
ifcmd="$1"; |
| 853 |
shift |
| 854 |
case "$ifcmd" in |
| 855 |
%if) if test 0 = $pp_if_false; then |
| 856 |
case "$*" in |
| 857 |
true |1) pp_incr pp_if_true;; |
| 858 |
false|0) pp_incr pp_if_false;; |
| 859 |
*) |
| 860 |
ifret=true |
| 861 |
if pp_is_qualifier "$*"; then |
| 862 |
pp_eval_qualifier "$*" || ifret=false |
| 863 |
else |
| 864 |
eval test "$@" || ifret=false |
| 865 |
pp_debug "evaluating test $* -> $ifret" |
| 866 |
fi |
| 867 |
pp_incr pp_if_$ifret |
| 868 |
;; |
| 869 |
esac |
| 870 |
else |
| 871 |
pp_incr pp_if_false |
| 872 |
fi;; |
| 873 |
%else) test $# = 0 || pp_warn "ignoring argument to %else" |
| 874 |
if test $pp_if_false -gt 1; then |
| 875 |
: no change |
| 876 |
elif test $pp_if_false = 1; then |
| 877 |
pp_incr pp_if_true |
| 878 |
pp_decr pp_if_false |
| 879 |
elif test $pp_if_true = 0; then |
| 880 |
pp_die "unmatched %else" |
| 881 |
else |
| 882 |
pp_incr pp_if_false |
| 883 |
pp_decr pp_if_true |
| 884 |
fi;; |
| 885 |
%endif) test $# = 0 || pp_warn "ignoring argument to %endif" |
| 886 |
if test $pp_if_false -gt 0; then |
| 887 |
pp_decr pp_if_false |
| 888 |
elif test $pp_if_true -gt 0; then |
| 889 |
pp_decr pp_if_true |
| 890 |
else |
| 891 |
pp_die "unmatched %endif" |
| 892 |
fi;; |
| 893 |
*) pp_die "frontend_if: unknown cmd $ifcmd";; |
| 894 |
esac |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
pp_frontend () { |
| 899 |
typeset section newsection sed_word sed_ws line cpt svc |
| 900 |
typeset section_enabled newsection_enabled s sed sed_candidate |
| 901 |
|
| 902 |
section='%_initial' |
| 903 |
newsection='%_initial' |
| 904 |
section_enabled=: |
| 905 |
newsection_enabled=: |
| 906 |
sed_word="[a-zA-Z_][a-zA-Z_0-9]*" |
| 907 |
sed_ws="[ ]" |
| 908 |
|
| 909 |
#-- not all seds are created equal |
| 910 |
sed= |
| 911 |
for sed_candidate in ${PP_SED:-sed} /usr/xpg4/bin/sed; do |
| 912 |
if echo 'foo' | $sed_candidate -ne '/^\(x\)*foo/p' | grep foo > /dev/null |
| 913 |
then |
| 914 |
sed="$sed_candidate" |
| 915 |
break |
| 916 |
fi |
| 917 |
done |
| 918 |
test -z "$sed" && |
| 919 |
pp_die "sed is broken on this system" |
| 920 |
|
| 921 |
pp_lineno=0 |
| 922 |
|
| 923 |
#-- Note: this sed script should perform similar to pp_eval_qualifier() |
| 924 |
$sed -e "/^#/s/.*//" \ |
| 925 |
-e "/^\\[!\\($sed_word,\\)*$pp_platform\\(,$sed_word\\)*\\]/s/.*//" \ |
| 926 |
-e "s/^\\[\\($sed_word,\\)*$pp_platform\\(,$sed_word\\)*\\]$sed_ws*//" \ |
| 927 |
-e "s/^\\[!\\($sed_word,\\)*$sed_word\\]$sed_ws*//" \ |
| 928 |
-e "/^\\[\\($sed_word,\\)*$sed_word\\]/s/.*//" \ |
| 929 |
-e "s/^%$sed_ws*/%/" \ |
| 930 |
-e "s/^$sed_ws/%\\\\&/" \ |
| 931 |
> $pp_wrkdir/frontend.tmp |
| 932 |
|
| 933 |
#-- add an ignore section at the end to force section completion |
| 934 |
echo '%ignore' >> $pp_wrkdir/frontend.tmp |
| 935 |
echo >> $pp_wrkdir/frontend.tmp |
| 936 |
|
| 937 |
exec 0<$pp_wrkdir/frontend.tmp |
| 938 |
: > $pp_wrkdir/tmp |
| 939 |
: > $pp_wrkdir/%fixup |
| 940 |
while read -r line; do |
| 941 |
#-- Convert leading double-% to single-%, or switch sections |
| 942 |
pp_incr pp_lineno |
| 943 |
|
| 944 |
pp_debug "line $pp_lineno: $line" |
| 945 |
set -f |
| 946 |
set -- $line |
| 947 |
set +f |
| 948 |
#pp_debug "line $pp_lineno: $*" |
| 949 |
|
| 950 |
case "$line" in %*) |
| 951 |
case "$1" in |
| 952 |
%if|%else|%endif) |
| 953 |
pp_debug "processing if directive $1" |
| 954 |
pp_frontend_if "$@" |
| 955 |
continue;; |
| 956 |
esac |
| 957 |
test 0 -ne $pp_if_false && continue # ignore lines %if'd out |
| 958 |
|
| 959 |
case "$1" in |
| 960 |
%set|%fixup|%ignore) |
| 961 |
pp_debug "processing new section $1" |
| 962 |
newsection="$1"; shift |
| 963 |
newsection_enabled=: |
| 964 |
if pp_is_qualifier "$1"; then |
| 965 |
pp_eval_qualifier "$1" || newsection_enabled=false |
| 966 |
shift |
| 967 |
fi |
| 968 |
test $# -eq 0 || pp_warn "ignoring extra arguments: $line" |
| 969 |
continue;; |
| 970 |
%pre|%post|%preun|%postup|%preup|%postun|%files|%depend|%check|%conflict) |
| 971 |
pp_debug "processing new component section $*" |
| 972 |
s="$1"; shift |
| 973 |
if test $# -eq 0 || pp_is_qualifier "$1"; then |
| 974 |
cpt=run |
| 975 |
else |
| 976 |
cpt="$1" |
| 977 |
shift |
| 978 |
fi |
| 979 |
newsection="$s.$cpt" |
| 980 |
newsection_enabled=: |
| 981 |
if test $# -gt 0 && pp_is_qualifier "$1"; then |
| 982 |
pp_eval_qualifier "$1" || newsection_enabled=false |
| 983 |
shift |
| 984 |
fi |
| 985 |
test $# -eq 0 || |
| 986 |
pp_warn "ignoring extra arguments: $line" |
| 987 |
case "$cpt" in |
| 988 |
run|dbg|doc|dev) |
| 989 |
$newsection_enabled && pp_add_component "$cpt";; |
| 990 |
x-*) :;; # useful for discarding stuff |
| 991 |
*) pp_error "unknown component: $1 $cpt";; |
| 992 |
esac |
| 993 |
continue;; |
| 994 |
%pp) |
| 995 |
newsection="%ignore"; shift |
| 996 |
if test $# -gt 0; then |
| 997 |
pp_set_api_version "$1" |
| 998 |
shift |
| 999 |
else |
| 1000 |
pp_error "%pp: missing version" |
| 1001 |
fi |
| 1002 |
test $# -gt 0 && |
| 1003 |
pp_error "%pp: too many arguments" |
| 1004 |
continue;; |
| 1005 |
%service) |
| 1006 |
pp_debug "processing new service section $1 $2" |
| 1007 |
s="$1"; shift |
| 1008 |
if test $# -eq 0 || pp_is_qualifier "$1"; then |
| 1009 |
pp_error "$s: service name required" |
| 1010 |
svc=unknown |
| 1011 |
else |
| 1012 |
svc="$1"; shift |
| 1013 |
fi |
| 1014 |
|
| 1015 |
newsection="$s.$svc" |
| 1016 |
newsection_enabled=: |
| 1017 |
if test $# -gt 0 && pp_is_qualifier "$1"; then |
| 1018 |
pp_eval_qualifier "$1" || newsection_enabled=false |
| 1019 |
shift |
| 1020 |
fi |
| 1021 |
test $# -eq 0 || |
| 1022 |
pp_warn "ignoring extra arguments: $line" |
| 1023 |
$newsection_enabled && pp_add_service "$svc" |
| 1024 |
continue;; |
| 1025 |
%\\*) |
| 1026 |
pp_debug "removing leading %\\" |
| 1027 |
line="${line#??}" |
| 1028 |
pp_debug " result is <$line>" |
| 1029 |
set -f |
| 1030 |
set -- $line |
| 1031 |
set +f |
| 1032 |
;; |
| 1033 |
%%*) |
| 1034 |
pp_debug "removing leading %" |
| 1035 |
line="${line#%}" |
| 1036 |
set -f |
| 1037 |
set -- $line |
| 1038 |
set +f |
| 1039 |
;; |
| 1040 |
%*) |
| 1041 |
pp_error "unknown section $1" |
| 1042 |
newsection='%ignore' |
| 1043 |
newsection_enabled=: |
| 1044 |
continue;; |
| 1045 |
esac;; |
| 1046 |
esac |
| 1047 |
|
| 1048 |
test 0 != $pp_if_false && continue # ignore lines %if'd out |
| 1049 |
|
| 1050 |
pp_debug "section=$section (enabled=$section_enabled) newsection=$newsection (enabled=$newsection_enabled)" |
| 1051 |
|
| 1052 |
#-- finish processing a previous section |
| 1053 |
if test x"$newsection" != x""; then |
| 1054 |
$section_enabled && case "$section" in |
| 1055 |
%ignore|%_initial) |
| 1056 |
pp_debug "leaving ignored section $section" |
| 1057 |
: ignore # guaranteed to be the last section |
| 1058 |
;; |
| 1059 |
%set) |
| 1060 |
pp_debug "leaving $section: sourcing $pp_wrkdir/tmp" |
| 1061 |
$pp_opt_debug && cat $pp_wrkdir/tmp >&2 |
| 1062 |
. $pp_wrkdir/tmp |
| 1063 |
: > $pp_wrkdir/tmp |
| 1064 |
;; |
| 1065 |
%pre.*|%preun.*|%post.*|%postup.*|%preup.*|%postun.*|%depend.*|%check.*|%conflict.*|%service.*|%fixup) |
| 1066 |
pp_debug "leaving $section: substituting $pp_wrkdir/tmp" |
| 1067 |
# cat $pp_wrkdir/tmp >&2 # debugging |
| 1068 |
$pp_opt_debug && pp_substitute < $pp_wrkdir/tmp >&2 |
| 1069 |
pp_substitute < $pp_wrkdir/tmp > $pp_wrkdir/tmp.sh |
| 1070 |
. $pp_wrkdir/tmp.sh >> $pp_wrkdir/$section || |
| 1071 |
pp_error "shell error in $section" |
| 1072 |
rm -f $pp_wrkdir/tmp.sh |
| 1073 |
: > $pp_wrkdir/tmp |
| 1074 |
;; |
| 1075 |
esac |
| 1076 |
section="$newsection" |
| 1077 |
section_enabled="$newsection_enabled" |
| 1078 |
newsection= |
| 1079 |
fi |
| 1080 |
|
| 1081 |
#-- ignore section content that is disabled |
| 1082 |
$section_enabled || continue |
| 1083 |
|
| 1084 |
#-- process some lines in-place |
| 1085 |
case "$section" in |
| 1086 |
%_initial) |
| 1087 |
case "$line" in "") continue;; esac # ignore non-section blanks |
| 1088 |
pp_die "Ignoring text before % section introducer";; |
| 1089 |
%set|%pre.*|%preun.*|%post.*|%postup.*|%preup.*|%postun.*|%check.*|%service.*|%fixup) |
| 1090 |
pp_debug "appending line to \$pp_wrkdir/tmp" |
| 1091 |
echo "$line" >> $pp_wrkdir/tmp |
| 1092 |
;; |
| 1093 |
%files.*) |
| 1094 |
test $# -eq 0 && continue; |
| 1095 |
pp_files_expand "$@" >> $pp_wrkdir/$section |
| 1096 |
;; |
| 1097 |
%depend.*) |
| 1098 |
pp_debug "Adding explicit dependency $@ to $cpt" |
| 1099 |
echo "$@" >> $pp_wrkdir/%depend.$cpt |
| 1100 |
;; |
| 1101 |
%conflict.*) |
| 1102 |
pp_debug "Adding explicit conflict $@ to $cpt" |
| 1103 |
echo "$@" >> $pp_wrkdir/%conflict.$cpt |
| 1104 |
;; |
| 1105 |
esac |
| 1106 |
done |
| 1107 |
exec <&- |
| 1108 |
|
| 1109 |
if test $pp_if_true != 0 -o $pp_if_false != 0; then |
| 1110 |
pp_die "missing %endif at end of file" |
| 1111 |
fi |
| 1112 |
|
| 1113 |
pp_lineno= |
| 1114 |
|
| 1115 |
pp_debug " name = $name" |
| 1116 |
pp_debug " version = $version" |
| 1117 |
pp_debug " summary = $summary" |
| 1118 |
pp_debug " description = $description" |
| 1119 |
pp_debug " copyright = $copyright" |
| 1120 |
pp_debug "" |
| 1121 |
pp_debug "\$pp_components: $pp_components" |
| 1122 |
pp_debug "\$pp_services: $pp_services" |
| 1123 |
} |
| 1124 |
|
| 1125 |
pp_set_api_version() { |
| 1126 |
case "$1" in |
| 1127 |
1.0) : ;; |
| 1128 |
*) pp_error "This version of polypackage is too old";; |
| 1129 |
esac |
| 1130 |
} |
| 1131 |
|
| 1132 |
pp_platform= |
| 1133 |
|
| 1134 |
pp_set_platform () { |
| 1135 |
if test -n "$pp_opt_platform"; then |
| 1136 |
pp_contains "$pp_platforms" "$pp_opt_platform" || |
| 1137 |
pp_die "$pp_opt_platform: unknown platform" |
| 1138 |
pp_platform="$pp_opt_platform" |
| 1139 |
else |
| 1140 |
uname_s=`uname -s 2>/dev/null` |
| 1141 |
pp_platform= |
| 1142 |
for p in $pp_platforms; do |
| 1143 |
pp_debug "probing for platform $p" |
| 1144 |
if eval pp_backend_${p}_detect "$uname_s"; then |
| 1145 |
pp_platform="$p" |
| 1146 |
break; |
| 1147 |
fi |
| 1148 |
done |
| 1149 |
test -z "$pp_platform" && |
| 1150 |
pp_die "cannot detect platform (supported: $pp_platforms)" |
| 1151 |
fi |
| 1152 |
pp_debug "pp_platform = $pp_platform" |
| 1153 |
} |
| 1154 |
|
| 1155 |
pp_expand_path= |
| 1156 |
|
| 1157 |
pp_expand_test_usr_bin () { |
| 1158 |
awk '$1 == "/usr" || $2 == "/usr" {usr++} |
| 1159 |
$1 == "/bin" || $2 == "/bin" {bin++} |
| 1160 |
END { if (usr == 1 && bin == 1) exit(0); else exit(1); }' |
| 1161 |
} |
| 1162 |
|
| 1163 |
pp_set_expand_converter_or_reexec () { |
| 1164 |
test -d /usr -a -d /bin || |
| 1165 |
pp_die "missing /usr or /bin" |
| 1166 |
echo /usr /bin | pp_expand_test_usr_bin || pp_die "pp_expand_test_usr_bin?" |
| 1167 |
if (eval "echo /{usr,bin}" | pp_expand_test_usr_bin) 2>/dev/null; then |
| 1168 |
pp_expand_path=pp_expand_path_brace |
| 1169 |
elif (eval "echo /@(usr|bin)" | pp_expand_test_usr_bin) 2>/dev/null; then |
| 1170 |
pp_expand_path=pp_expand_path_at |
| 1171 |
else |
| 1172 |
test x"$pp_expand_rexec" != x"true" || |
| 1173 |
pp_die "problem finding shell that can do brace expansion" |
| 1174 |
for shell in bash ksh ksh93; do |
| 1175 |
if ($shell -c 'echo /{usr,bin}' | |
| 1176 |
pp_expand_test_usr_bin) 2>/dev/null || |
| 1177 |
($shell -c 'echo /@(usr|bin)' | |
| 1178 |
pp_expand_test_usr_bin) 2>/dev/null |
| 1179 |
then |
| 1180 |
pp_debug "switching to shell $shell" |
| 1181 |
pp_expand_rexec=true exec $shell "$0" "$@" |
| 1182 |
fi |
| 1183 |
done |
| 1184 |
pp_die "cannot find a shell that does brace expansion" |
| 1185 |
fi |
| 1186 |
} |
| 1187 |
|
| 1188 |
pp_expand_path_brace () { |
| 1189 |
typeset f |
| 1190 |
eval "for f in $1; do echo \"\$f\"; done|sort -u" |
| 1191 |
} |
| 1192 |
|
| 1193 |
pp_expand_path_at () { |
| 1194 |
typeset f |
| 1195 |
eval "for f in ` |
| 1196 |
echo "$1" | sed -e 's/{/@(/g' -e 's/}/)/g' -e 's/,/|/g' |
| 1197 |
`; do echo \"\$f\"; done|sort -u" |
| 1198 |
} |
| 1199 |
|
| 1200 |
pp_shlib_suffix='.so*' |
| 1201 |
|
| 1202 |
pp_model_init () { |
| 1203 |
#@ $pp_components: whitespace-delimited list of components seen in %files |
| 1204 |
pp_components= |
| 1205 |
#@ $pp_services: whitespace-delimited list of %service seen |
| 1206 |
pp_services= |
| 1207 |
|
| 1208 |
rm -f $pp_wrkdir/%files.* \ |
| 1209 |
$pp_wrkdir/%post.* \ |
| 1210 |
$pp_wrkdir/%pre.* \ |
| 1211 |
$pp_wrkdir/%preun.* \ |
| 1212 |
$pp_wrkdir/%postup.* \ |
| 1213 |
$pp_wrkdir/%postun.* \ |
| 1214 |
$pp_wrkdir/%service.* \ |
| 1215 |
$pp_wrkdir/%set \ |
| 1216 |
$pp_wrkdir/%fixup |
| 1217 |
} |
| 1218 |
|
| 1219 |
|
| 1220 |
pp_have_component () { |
| 1221 |
pp_contains "$pp_components" "$1" |
| 1222 |
} |
| 1223 |
|
| 1224 |
pp_have_all_components () { |
| 1225 |
pp_contains_all "$pp_components" "$@" |
| 1226 |
} |
| 1227 |
|
| 1228 |
pp_add_component () { |
| 1229 |
pp_add_to_list 'pp_components' "$1" |
| 1230 |
} |
| 1231 |
|
| 1232 |
pp_add_service () { |
| 1233 |
pp_add_to_list 'pp_services' "$1" |
| 1234 |
} |
| 1235 |
|
| 1236 |
pp_service_init_vars () { |
| 1237 |
cmd= |
| 1238 |
pidfile= |
| 1239 |
stop_signal=15 # SIGTERM |
| 1240 |
user=root |
| 1241 |
group= |
| 1242 |
enable=yes # make it so the service starts on boot |
| 1243 |
optional=no # Whether installing this service is optional |
| 1244 |
pp_backend_init_svc_vars |
| 1245 |
} |
| 1246 |
|
| 1247 |
pp_service_check_vars () { |
| 1248 |
test -n "$cmd" || |
| 1249 |
pp_error "%service $1: cmd not defined" |
| 1250 |
case "$enable" in |
| 1251 |
yes|no) : ;; |
| 1252 |
*) pp_error "%service $1: \$enable must be set to yes or no";; |
| 1253 |
esac |
| 1254 |
} |
| 1255 |
|
| 1256 |
pp_load_service_vars () { |
| 1257 |
pp_service_init_vars |
| 1258 |
. "$pp_wrkdir/%service.$1" |
| 1259 |
pp_service_check_vars "$1" |
| 1260 |
} |
| 1261 |
|
| 1262 |
pp_files_expand () { |
| 1263 |
typeset _p _mode _group _owner _flags _path _optional _has_target _tree |
| 1264 |
typeset _target _file _tgt _m _o _g _f _type _lm _ll _lo _lg _ls _lx |
| 1265 |
typeset _ignore _a |
| 1266 |
|
| 1267 |
test $# -eq 0 && return |
| 1268 |
|
| 1269 |
pp_debug "pp_files_expand: path is: $1" |
| 1270 |
|
| 1271 |
case "$1" in "#"*) return;; esac |
| 1272 |
_p="$1"; shift |
| 1273 |
|
| 1274 |
pp_debug "pp_files_expand: other arguments: $*" |
| 1275 |
|
| 1276 |
#-- the mode must be an octal number of at least three digits |
| 1277 |
_mode="=" |
| 1278 |
_a=`eval echo \"$1\"` |
| 1279 |
case "$_a" in |
| 1280 |
*:*) :;; |
| 1281 |
-|=|[01234567][01234567][01234567]*) _mode="$_a"; shift;; |
| 1282 |
esac |
| 1283 |
|
| 1284 |
#-- the owner:group field may have optional parts |
| 1285 |
_a=`eval echo \"$1\"` |
| 1286 |
case "$_a" in |
| 1287 |
*:*) _group=${_a#*:}; _owner=${_a%:*}; shift;; |
| 1288 |
=|-) _group=$_a; _owner=$_a; shift;; |
| 1289 |
*) _group=; _owner=;; |
| 1290 |
esac |
| 1291 |
|
| 1292 |
#-- process the flags argument |
| 1293 |
_flags= |
| 1294 |
_target= |
| 1295 |
_optional=false |
| 1296 |
_has_target=false |
| 1297 |
_ignore=false |
| 1298 |
if test $# -gt 0; then |
| 1299 |
_a=`eval echo \"$1\"` |
| 1300 |
case ",$_a," in *,volatile,*) _flags="${_flags}v";; esac |
| 1301 |
case ",$_a," in *,missingok,*) _flags="${_flags}m";; esac |
| 1302 |
case ",$_a," in *,optional,*) _optional=true;; esac |
| 1303 |
case ",$_a," in *,symlink,*) _has_target=true;; esac |
| 1304 |
case ",$_a," in *,ignore-others,*) _flags="${_flags}i";; esac |
| 1305 |
case ",$_a," in *,ignore,*) _ignore=true;; esac |
| 1306 |
shift |
| 1307 |
fi |
| 1308 |
|
| 1309 |
#-- process the target argument |
| 1310 |
if $_has_target; then |
| 1311 |
test $# -ne 0 || pp_error "$_p: missing target" |
| 1312 |
_a=`eval echo \"$1\"` |
| 1313 |
_target="$_a" |
| 1314 |
shift |
| 1315 |
fi |
| 1316 |
|
| 1317 |
pp_debug "pp_files_expand: $_mode|$_owner:$_group|$_flags|$_target|$*" |
| 1318 |
|
| 1319 |
test $# -eq 0 || pp_error "$_p: too many arguments" |
| 1320 |
|
| 1321 |
#-- process speciall suffixes |
| 1322 |
tree= |
| 1323 |
case "$_p" in |
| 1324 |
*"/**") _p="${_p%"/**"}"; tree="**";; |
| 1325 |
*".%so") _p="${_p%".%so"}$pp_shlib_suffix";; |
| 1326 |
esac |
| 1327 |
|
| 1328 |
#-- expand the path using the shell glob |
| 1329 |
pp_debug "expanding .$_p ... with $pp_expand_path" |
| 1330 |
(cd ${pp_destdir} && $pp_expand_path ".$_p") > $pp_wrkdir/tmp.files.exp |
| 1331 |
|
| 1332 |
#-- expand path/** by rewriting the glob output file |
| 1333 |
case "$tree" in |
| 1334 |
"") : ;; |
| 1335 |
"**") |
| 1336 |
pp_debug "expanding /** tree ..." |
| 1337 |
while read _path; do |
| 1338 |
_path="${_path#.}" |
| 1339 |
pp_find_recurse "$pp_destdir${_path%/}" |
| 1340 |
done < $pp_wrkdir/tmp.files.exp | |
| 1341 |
sort -u > $pp_wrkdir/tmp.files.exp2 |
| 1342 |
mv $pp_wrkdir/tmp.files.exp2 $pp_wrkdir/tmp.files.exp |
| 1343 |
;; |
| 1344 |
esac |
| 1345 |
|
| 1346 |
while read _path; do |
| 1347 |
_path="${_path#.}" |
| 1348 |
_file="${pp_destdir}${_path}" |
| 1349 |
_tgt= |
| 1350 |
_m="$_mode" |
| 1351 |
_o="${_owner:--}" |
| 1352 |
_g="${_group:--}" |
| 1353 |
_f="$_flags" |
| 1354 |
|
| 1355 |
case "$_path" in |
| 1356 |
/*) :;; |
| 1357 |
*) pp_warn "$_path: inserting leading /" |
| 1358 |
_path="/$_path";; # ensure leading / |
| 1359 |
esac |
| 1360 |
|
| 1361 |
#-- sanity checks |
| 1362 |
case "$_path" in |
| 1363 |
*/../*|*/..) pp_error "$_path: invalid .. in path";; |
| 1364 |
*/./*|*/.) pp_warn "$_path: invalid component . in path";; |
| 1365 |
*//*) pp_warn "$_path: redundant / in path";; |
| 1366 |
esac |
| 1367 |
|
| 1368 |
#-- set the type based on the real file's type |
| 1369 |
if $_ignore; then |
| 1370 |
_type=f _m=_ _o=_ _g=_ |
| 1371 |
elif test -h "$_file"; then |
| 1372 |
case "$_path" in |
| 1373 |
*/) pp_warn "$_path (symlink $_file): removing trailing /" |
| 1374 |
_path="${_path%/}" |
| 1375 |
;; |
| 1376 |
esac |
| 1377 |
_type=s |
| 1378 |
if test x"$_target" != x"=" -a -n "$_target"; then |
| 1379 |
_tgt="$_target" |
| 1380 |
pp_debug "symlink target is $_tgt" |
| 1381 |
else |
| 1382 |
_tgt=`pp_readlink "$_file"`; |
| 1383 |
test -z "$_tgt" && pp_error "can't readlink $_file" |
| 1384 |
case "$_tgt" in |
| 1385 |
${pp_destdir}/*) |
| 1386 |
pp_warn "stripped \$destdir from symlink ($_path)" |
| 1387 |
_tgt="${_tgt#$pp_destdir}";; |
| 1388 |
esac |
| 1389 |
fi |
| 1390 |
_m=777 |
| 1391 |
elif test -d "$_file"; then |
| 1392 |
#-- display a warning if the user forgot the trailing / |
| 1393 |
case "$_path" in |
| 1394 |
*/) :;; |
| 1395 |
*) pp_warn "$_path (matching $_file): adding trailing /" |
| 1396 |
_path="$_path/";; |
| 1397 |
esac |
| 1398 |
_type=d |
| 1399 |
$_has_target && pp_error "$_file: not a symlink" |
| 1400 |
elif test -f "$_file"; then |
| 1401 |
case "$_path" in |
| 1402 |
*/) pp_warn "$_path (matching $_file): removing trailing /" |
| 1403 |
_path="${_path%/}" |
| 1404 |
;; |
| 1405 |
esac |
| 1406 |
_type=f |
| 1407 |
$_has_target && pp_error "$_file: not a symlink" |
| 1408 |
else |
| 1409 |
$_optional && continue |
| 1410 |
pp_error "$_file: missing" |
| 1411 |
_type=f |
| 1412 |
fi |
| 1413 |
|
| 1414 |
#-- convert '=' shortcuts into mode/owner/group from ls |
| 1415 |
case ":$_m:$_o:$_g:" in *:=:*) |
| 1416 |
if LS_OPTIONS=--color=never /bin/ls -ld "$_file" \ |
| 1417 |
> $pp_wrkdir/ls.tmp |
| 1418 |
then |
| 1419 |
read _lm _ll _lo _lg _ls _lx < $pp_wrkdir/ls.tmp |
| 1420 |
test x"$_m" = x"=" && _m=`pp_mode_from_ls "$_lm"` |
| 1421 |
test x"$_o" = x"=" && _o="$_lo" |
| 1422 |
test x"$_g" = x"=" && _g="$_lg" |
| 1423 |
else |
| 1424 |
pp_error "cannot read $_file" |
| 1425 |
test x"$_m" = x"=" && _m=- |
| 1426 |
test x"$_o" = x"=" && _o=- |
| 1427 |
test x"$_g" = x"=" && _g=- |
| 1428 |
fi |
| 1429 |
;; |
| 1430 |
esac |
| 1431 |
|
| 1432 |
test -n "$_f" || _f=- |
| 1433 |
|
| 1434 |
#-- sanity checks |
| 1435 |
test -n "$_type" || pp_die "_type empty" |
| 1436 |
test -n "$_path" || pp_die "_path empty" |
| 1437 |
test -n "$_m" || pp_die "_m empty" |
| 1438 |
test -n "$_o" || pp_die "_o empty" |
| 1439 |
test -n "$_g" || pp_die "_g empty" |
| 1440 |
|
| 1441 |
#-- setuid/gid files must be given an explicit owner/group (or =) |
| 1442 |
case "$_o:$_g:$_m" in |
| 1443 |
-:*:[4657][1357]??|-:*:[4657]?[1357]?|-:*:[4657]??[1357]) |
| 1444 |
pp_error "$_path: setuid file ($_m) missing explicit owner";; |
| 1445 |
*:-:[2367][1357]??|*:-:[2367]?[1357]?|*:-:[2367]??[1357]) |
| 1446 |
pp_error "$_path: setgid file ($_m) missing explicit group";; |
| 1447 |
esac |
| 1448 |
|
| 1449 |
# convert numeric uids into usernames; only works for /etc/passwd |
| 1450 |
case "$_o" in [0-9]*) _o=`pp_getpwuid $_o`;; esac |
| 1451 |
case "$_g" in [0-9]*) _g=`pp_getgrgid $_g`;; esac |
| 1452 |
|
| 1453 |
pp_debug "$_type $_m $_o $_g $_f $_path" $_tgt |
| 1454 |
$_ignore || echo "$_type $_m $_o $_g $_f $_path" $_tgt |
| 1455 |
pp_note_file_used "$_path" |
| 1456 |
case "$_f" in *i*) echo "$_path" >> $pp_wrkdir/ign.files;; esac |
| 1457 |
done < $pp_wrkdir/tmp.files.exp |
| 1458 |
} |
| 1459 |
|
| 1460 |
pp_files_check_duplicates () { |
| 1461 |
typeset _path |
| 1462 |
if test -s $pp_wrkdir/all.files; then |
| 1463 |
sort < $pp_wrkdir/all.files | uniq -d > $pp_wrkdir/duplicate.files |
| 1464 |
if test -f $pp_wrkdir/ign.awk; then |
| 1465 |
# Remove ignored files |
| 1466 |
mv $pp_wrkdir/duplicate.files $pp_wrkdir/duplicate.files.ign |
| 1467 |
sed -e 's/^/_ _ _ _ _ /' < $pp_wrkdir/duplicate.files.ign | |
| 1468 |
awk -f $pp_wrkdir/ign.awk | |
| 1469 |
sed -e 's/^_ _ _ _ _ //' > $pp_wrkdir/duplicate.files |
| 1470 |
fi |
| 1471 |
while read _path; do |
| 1472 |
pp_warn "$_path: file declared more than once" |
| 1473 |
done <$pp_wrkdir/duplicate.files |
| 1474 |
fi |
| 1475 |
} |
| 1476 |
|
| 1477 |
pp_files_check_coverage () { |
| 1478 |
pp_find_recurse "$pp_destdir" | sort > $pp_wrkdir/coverage.avail |
| 1479 |
if test -s $pp_wrkdir/all.files; then |
| 1480 |
sort -u < $pp_wrkdir/all.files |
| 1481 |
else |
| 1482 |
: |
| 1483 |
fi > $pp_wrkdir/coverage.used |
| 1484 |
join -v1 $pp_wrkdir/coverage.avail $pp_wrkdir/coverage.used \ |
| 1485 |
> $pp_wrkdir/coverage.not-packaged |
| 1486 |
if test -s $pp_wrkdir/coverage.not-packaged; then |
| 1487 |
pp_warn "The following files/directories were found but not packaged:" |
| 1488 |
sed -e 's,^, ,' < $pp_wrkdir/coverage.not-packaged >&2 |
| 1489 |
fi |
| 1490 |
join -v2 $pp_wrkdir/coverage.avail $pp_wrkdir/coverage.used \ |
| 1491 |
> $pp_wrkdir/coverage.not-avail |
| 1492 |
if test -s $pp_wrkdir/coverage.not-avail; then |
| 1493 |
pp_warn "The following files/directories were named but not found:" |
| 1494 |
sed -e 's,^, ,' < $pp_wrkdir/coverage.not-avail >&2 |
| 1495 |
fi |
| 1496 |
} |
| 1497 |
|
| 1498 |
pp_files_ignore_others () { |
| 1499 |
typeset p f |
| 1500 |
|
| 1501 |
test -s $pp_wrkdir/ign.files || return |
| 1502 |
|
| 1503 |
#-- for each file in ign.files, we remove it from all the |
| 1504 |
# other %files.* lists, except where it has an i flag. |
| 1505 |
# rather than scan each list multiple times, we build |
| 1506 |
# an awk script |
| 1507 |
|
| 1508 |
pp_debug "stripping ignore files" |
| 1509 |
|
| 1510 |
while read p; do |
| 1511 |
echo '$6 == "'"$p"'" && $5 !~ /i/ { next }' |
| 1512 |
done < $pp_wrkdir/ign.files > $pp_wrkdir/ign.awk |
| 1513 |
echo '{ print }' >> $pp_wrkdir/ign.awk |
| 1514 |
|
| 1515 |
$pp_opt_debug && cat $pp_wrkdir/ign.awk |
| 1516 |
|
| 1517 |
for f in $pp_wrkdir/%files.*; do |
| 1518 |
mv $f $f.ign |
| 1519 |
awk -f $pp_wrkdir/ign.awk < $f.ign > $f || pp_error "awk" |
| 1520 |
done |
| 1521 |
} |
| 1522 |
|
| 1523 |
pp_service_scan_groups () { |
| 1524 |
typeset svc |
| 1525 |
|
| 1526 |
#-- scan for "group" commands, and build a list of groups |
| 1527 |
pp_service_groups= |
| 1528 |
if test -n "$pp_services"; then |
| 1529 |
for svc in $pp_services; do |
| 1530 |
group= |
| 1531 |
. $pp_wrkdir/%service.$svc |
| 1532 |
if test -n "$group"; then |
| 1533 |
pp_contains "$pp_services" "$group" && pp_error \ |
| 1534 |
"%service $svc: group name $group in use by a service" |
| 1535 |
pp_add_to_list 'pp_service_groups' "$group" |
| 1536 |
echo "$svc" >> $pp_wrkdir/%svcgrp.$group |
| 1537 |
fi |
| 1538 |
done |
| 1539 |
fi |
| 1540 |
} |
| 1541 |
|
| 1542 |
pp_service_get_svc_group () { |
| 1543 |
(tr '\012' ' ' < $pp_wrkdir/%svcgrp.$1 ; echo) | sed -e 's/ $//' |
| 1544 |
} |
| 1545 |
|
| 1546 |
for _sufx in _init '' _names _cleanup _install_script \ |
| 1547 |
_init_svc_vars _function _probe _vas_platforms |
| 1548 |
do |
| 1549 |
eval "pp_backend$_sufx () { pp_debug pp_backend$_sufx; pp_backend_\${pp_platform}$_sufx \"\$@\"; }" |
| 1550 |
done |
| 1551 |
|
| 1552 |
|
| 1553 |
pp_platforms="$pp_platforms aix" |
| 1554 |
|
| 1555 |
pp_backend_aix_detect () { |
| 1556 |
test x"$1" = x"AIX" |
| 1557 |
} |
| 1558 |
|
| 1559 |
pp_backend_aix_init () { |
| 1560 |
pp_aix_detect_arch |
| 1561 |
pp_aix_detect_os |
| 1562 |
|
| 1563 |
pp_aix_bosboot= # components that need bosboot |
| 1564 |
pp_aix_lang=en_US |
| 1565 |
pp_aix_copyright= |
| 1566 |
pp_aix_start_services_after_install=false |
| 1567 |
pp_aix_init_services_after_install=true |
| 1568 |
|
| 1569 |
pp_aix_sudo=sudo # AIX package tools must run as root |
| 1570 |
|
| 1571 |
case "$pp_aix_os" in |
| 1572 |
*) pp_readlink_fn=pp_ls_readlink;; # XXX |
| 1573 |
esac |
| 1574 |
|
| 1575 |
pp_aix_abis_seen= |
| 1576 |
} |
| 1577 |
|
| 1578 |
pp_aix_detect_arch () { |
| 1579 |
pp_aix_arch_p=`uname -p 2>/dev/null` |
| 1580 |
case "$pp_aix_arch_p" in |
| 1581 |
"") pp_debug "can't get processor type from uname -p" |
| 1582 |
pp_aix_arch_p=powerpc |
| 1583 |
pp_aix_arch=R;; # guess (lsattr -l proc0 ??) |
| 1584 |
powerpc) pp_aix_arch=R;; |
| 1585 |
*) pp_aix_arch_p=intel |
| 1586 |
pp_aix_arch=I;; # XXX? verify |
| 1587 |
esac |
| 1588 |
|
| 1589 |
case "`/usr/sbin/lsattr -El proc0 -a type -F value`" in |
| 1590 |
PowerPC_POWER*) pp_aix_arch_std=ppc64;; |
| 1591 |
PowerPC*) pp_aix_arch_std=ppc;; |
| 1592 |
*) pp_aix_arch_std=unknown;; |
| 1593 |
esac |
| 1594 |
} |
| 1595 |
|
| 1596 |
pp_aix_detect_os () { |
| 1597 |
typeset r v |
| 1598 |
|
| 1599 |
r=`uname -r` |
| 1600 |
v=`uname -v` |
| 1601 |
pp_aix_os=aix$v$r |
| 1602 |
} |
| 1603 |
|
| 1604 |
pp_aix_version_fix () { |
| 1605 |
typeset v |
| 1606 |
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'` |
| 1607 |
if test x"$v" != x"$1"; then |
| 1608 |
pp_warn "stripped version '$1' to '$v'" |
| 1609 |
fi |
| 1610 |
case $v in |
| 1611 |
""|*..*|.*|*.) pp_error "malformed '$1'" |
| 1612 |
echo "0.0.0.0";; |
| 1613 |
*.*.*.*.*) |
| 1614 |
# 5 components are only valid for fileset updates, not base |
| 1615 |
# filesets (full packages). We trim 5+ components down to 4. |
| 1616 |
pp_warn "version '$1' has too many dots for AIX, truncating" |
| 1617 |
echo "$v" | cut -d. -f1-4;; |
| 1618 |
*.*.*.*) echo "$v";; |
| 1619 |
*.*.*) echo "$v.0";; |
| 1620 |
*.*) echo "$v.0.0";; |
| 1621 |
*) echo "$v.0.0.0";; |
| 1622 |
esac |
| 1623 |
} |
| 1624 |
|
| 1625 |
pp_aix_select () { |
| 1626 |
case "$1" in |
| 1627 |
-user) op="!";; |
| 1628 |
-root) op="";; |
| 1629 |
*) pp_die "pp_aix_select: bad argument";; |
| 1630 |
esac |
| 1631 |
awk $op'($6 ~ /^\/(dev|etc|sbin|var)\//) { print }' |
| 1632 |
} |
| 1633 |
|
| 1634 |
pp_aix_copy_root () { |
| 1635 |
typeset t m o g f p st target |
| 1636 |
while read t m o g f p st; do |
| 1637 |
case "$t" in |
| 1638 |
d) pp_create_dir_if_missing "$1${p%/}";; |
| 1639 |
f) pp_add_transient_file "$1$p" |
| 1640 |
pp_verbose ln "$pp_destdir$p" "$pp_destdir$1$p" || |
| 1641 |
pp_error "can't link $p into $1";; |
| 1642 |
*) pp_warn "pp_aix_copy_root: filetype $t not handled";; |
| 1643 |
esac |
| 1644 |
done |
| 1645 |
} |
| 1646 |
|
| 1647 |
pp_aix_size () { |
| 1648 |
typeset prefix t m o g f p st |
| 1649 |
|
| 1650 |
prefix="$1" |
| 1651 |
while read t m o g f p st; do |
| 1652 |
case "$t" in f) du -a "$pp_destdir$p";; esac |
| 1653 |
done | sed -e 's!/[^/]*$!!' | sort +1 | |
| 1654 |
awk '{ if ($2 != d) |
| 1655 |
{ if (sz) print d,sz; |
| 1656 |
d=$2; sz=0 } |
| 1657 |
sz += $1; } |
| 1658 |
END { if (sz) print d,sz }' | |
| 1659 |
sed -n -e "s!^$pp_destdir!$prefix!p" |
| 1660 |
} |
| 1661 |
|
| 1662 |
pp_aix_list () { |
| 1663 |
awk '{ print "." pfx $6; }' pfx="$1" |
| 1664 |
} |
| 1665 |
|
| 1666 |
pp_aix_make_liblpp () { |
| 1667 |
typeset out dn fl f |
| 1668 |
|
| 1669 |
out="$1"; shift |
| 1670 |
dn=`dirname "$2"` |
| 1671 |
fl= |
| 1672 |
for f |
| 1673 |
do |
| 1674 |
case "$f" in "$dn/"*) fl="$fl `basename $f`" ;; |
| 1675 |
*) pp_die "liblpp name $f not in $dn/";; esac |
| 1676 |
done |
| 1677 |
(cd "$dn" && pp_verbose ar -c -g -r "$out" $fl) || pp_error "ar error" |
| 1678 |
} |
| 1679 |
|
| 1680 |
pp_aix_make_script () { |
| 1681 |
rm -f "$1" |
| 1682 |
echo "#!/bin/sh" > "$1" |
| 1683 |
cat >> "$1" |
| 1684 |
echo "exit 0" >> "$1" |
| 1685 |
chmod +x "$1" |
| 1686 |
} |
| 1687 |
|
| 1688 |
pp_aix_inventory () { |
| 1689 |
typeset fileset t m o g f p st type |
| 1690 |
|
| 1691 |
fileset="$1" |
| 1692 |
while read t m o g f p st; do |
| 1693 |
case "$p" in *:*) pp_error "path $p contains colon";; esac |
| 1694 |
echo "$p:" |
| 1695 |
case "$t" in |
| 1696 |
f) type=FILE; defm=644 ;; |
| 1697 |
s) type=SYMLINK; defm=777 ;; |
| 1698 |
d) type=DIRECTORY; defm=755 ;; |
| 1699 |
esac |
| 1700 |
echo " type = $type" |
| 1701 |
echo " class = inventory,apply,$fileset" |
| 1702 |
if test x"$m" = x"-"; then m="$defm"; fi |
| 1703 |
if test x"$o" = x"-"; then o="root"; fi |
| 1704 |
if test x"$g" = x"-"; then g="system"; fi |
| 1705 |
echo " owner = $o" |
| 1706 |
echo " group = $g" |
| 1707 |
|
| 1708 |
case "$m" in ????) |
| 1709 |
m=`echo $m|sed -e 's/^1/TCB,/' \ |
| 1710 |
-e 's/^[23]/TCB,SGID,/' \ |
| 1711 |
-e 's/^[45]/TCB,SUID,/' \ |
| 1712 |
-e 's/^[67]/TCB,SUID,SGID,/'`;; # vtx bit ignored |
| 1713 |
esac |
| 1714 |
echo " mode = $m" |
| 1715 |
case "$t" in |
| 1716 |
f) if test ! -f "$pp_destdir$p"; then |
| 1717 |
pp_error "$p: missing file" |
| 1718 |
fi |
| 1719 |
case "$flags" in |
| 1720 |
*v*) |
| 1721 |
echo " size = VOLATILE" |
| 1722 |
echo " checksum = VOLATILE" |
| 1723 |
;; |
| 1724 |
*) |
| 1725 |
if test -r "$pp_destdir$p"; then |
| 1726 |
echo " size = $size" |
| 1727 |
pp_verbose sum -r < "$pp_destdir$p" | |
| 1728 |
sed -e 's/.*/ checksum = "&"/' |
| 1729 |
fi |
| 1730 |
;; |
| 1731 |
esac;; |
| 1732 |
s) |
| 1733 |
echo " target = $st" |
| 1734 |
;; |
| 1735 |
esac |
| 1736 |
|
| 1737 |
#-- Record ABI types seen |
| 1738 |
case "$t" in |
| 1739 |
f) if test -r "$pp_destdir$p"; then |
| 1740 |
case "`file "$pp_destdir$p"`" in |
| 1741 |
*"executable (RISC System/6000)"*) abi=ppc;; |
| 1742 |
*"64-bit XCOFF executable"*) abi=ppc64;; |
| 1743 |
*) abi=;; |
| 1744 |
esac |
| 1745 |
if test -n "$abi"; then |
| 1746 |
pp_add_to_list pp_aix_abis_seen $abi |
| 1747 |
fi |
| 1748 |
fi;; |
| 1749 |
esac |
| 1750 |
|
| 1751 |
done |
| 1752 |
} |
| 1753 |
|
| 1754 |
pp_aix_depend () |
| 1755 |
{ |
| 1756 |
if test -s "$1"; then |
| 1757 |
pp_warn "aix dependencies not implemented" |
| 1758 |
fi |
| 1759 |
} |
| 1760 |
|
| 1761 |
pp_aix_add_service () { |
| 1762 |
typeset svc cmd_cmd cmd_arg f |
| 1763 |
svc="$1" |
| 1764 |
|
| 1765 |
pp_load_service_vars $svc |
| 1766 |
|
| 1767 |
set -- $cmd |
| 1768 |
cmd_cmd="$1"; shift |
| 1769 |
cmd_arg="${pp_aix_mkssys_cmd_args:-$*}"; |
| 1770 |
|
| 1771 |
case "$stop_signal" in |
| 1772 |
HUP) stop_signal=1;; |
| 1773 |
INT) stop_signal=2;; |
| 1774 |
QUIT) stop_signal=3;; |
| 1775 |
KILL) stop_signal=9;; |
| 1776 |
TERM) stop_signal=15;; |
| 1777 |
USR1) stop_signal=30;; |
| 1778 |
USR2) stop_signal=31;; |
| 1779 |
"") |
| 1780 |
pp_error "%service $svc: stop_signal not set";; |
| 1781 |
[a-zA-Z]*) |
| 1782 |
pp_error "%service $svc: bad stop_signal ($stop_signal)";; |
| 1783 |
esac |
| 1784 |
|
| 1785 |
test -z "$pidfile" || pp_error "aix requires empty pidfile (non daemon)" |
| 1786 |
|
| 1787 |
pp_add_component run |
| 1788 |
if test "$user" = "root"; then |
| 1789 |
uid=0 |
| 1790 |
else |
| 1791 |
uid="\"\`/usr/bin/id -u $user\`\"" |
| 1792 |
fi |
| 1793 |
|
| 1794 |
|
| 1795 |
#-- add command text to create/remove the service |
| 1796 |
cat <<-. >> $pp_wrkdir/%post.$svc |
| 1797 |
svc=$svc |
| 1798 |
uid=0 |
| 1799 |
cmd_cmd="$cmd_cmd" |
| 1800 |
cmd_arg="$cmd_arg" |
| 1801 |
stop_signal=$stop_signal |
| 1802 |
force_signal=9 |
| 1803 |
srcgroup="$pp_aix_mkssys_group" |
| 1804 |
instances_allowed=${pp_aix_mkssys_instances_allowed:--Q} |
| 1805 |
|
| 1806 |
lssrc -s \$svc > /dev/null 2>&1 |
| 1807 |
if [ \$? -eq 0 ]; then |
| 1808 |
lssrc -s \$svc | grep "active" > /dev/null 2>&1 |
| 1809 |
if [ \$? -eq 0 ]; then |
| 1810 |
stopsrc -s \$svc > /dev/null 2>&1 |
| 1811 |
fi |
| 1812 |
rmsys -s \$svc > /dev/null 2>&1 |
| 1813 |
fi |
| 1814 |
|
| 1815 |
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 |
| 1816 |
. |
| 1817 |
|
| 1818 |
#-- add code to start the service on reboot |
| 1819 |
${pp_aix_init_services_after_install} && |
| 1820 |
cat <<-. >> $pp_wrkdir/%post.$svc |
| 1821 |
id=\`echo "\$svc" | cut -c1-14\` |
| 1822 |
mkitab "\$id:2:once:/usr/bin/startsrc -s \$svc" > /dev/null 2>&1 |
| 1823 |
. |
| 1824 |
|
| 1825 |
${pp_aix_start_services_after_install} && |
| 1826 |
cat <<-. >> $pp_wrkdir/%post.$svc |
| 1827 |
startsrc -s \$svc |
| 1828 |
. |
| 1829 |
|
| 1830 |
if [ -f "$pp_wrkdir/%post.run" ];then |
| 1831 |
cat $pp_wrkdir/%post.run >> $pp_wrkdir/%post.$svc |
| 1832 |
fi |
| 1833 |
mv $pp_wrkdir/%post.$svc $pp_wrkdir/%post.run |
| 1834 |
|
| 1835 |
|
| 1836 |
${pp_aix_init_services_after_install} && |
| 1837 |
pp_prepend $pp_wrkdir/%preun.$svc <<-. |
| 1838 |
rmitab `echo "$svc" | cut -c1-14` > /dev/null 2>&1 |
| 1839 |
. |
| 1840 |
pp_prepend $pp_wrkdir/%preun.$svc <<-. |
| 1841 |
stopsrc -s $svc >/dev/null 2>&1 |
| 1842 |
rmssys -s $svc |
| 1843 |
. |
| 1844 |
|
| 1845 |
if [ -f "$pp_wrkdir/%preun.run" ];then |
| 1846 |
cat $pp_wrkdir/%preun.run >> $pp_wrkdir/%preun.$svc |
| 1847 |
fi |
| 1848 |
mv $pp_wrkdir/%preun.$svc $pp_wrkdir/%preun.run |
| 1849 |
} |
| 1850 |
|
| 1851 |
pp_backend_aix () { |
| 1852 |
typeset briefex instuser instroot svc cmp outbff |
| 1853 |
typeset user_wrkdir root_wrkdir |
| 1854 |
typeset user_files root_files |
| 1855 |
|
| 1856 |
test -n "$pp_destdir" || |
| 1857 |
pp_error "AIX backend requires the '--destdir' option" |
| 1858 |
|
| 1859 |
instuser="/usr/lpp/$name" |
| 1860 |
instroot="$instuser/inst_root" |
| 1861 |
pp_aix_bff_name=${pp_aix_bff_name:-$name} |
| 1862 |
|
| 1863 |
# Here is the component mapping: |
| 1864 |
# run -> $pp_aix_bff_name.rte ('Run time environment') |
| 1865 |
# doc -> $pp_aix_bff_name.doc (non-standard) |
| 1866 |
# dev -> $pp_aix_bff_name.adt ('Application developer toolkit') |
| 1867 |
# dbg -> $pp_aix_bff_name.diag ('Diagnostics') |
| 1868 |
|
| 1869 |
test `echo "$summary" | wc -c ` -gt 40 && pp_error "\$summary too long" |
| 1870 |
|
| 1871 |
user_wrkdir=$pp_wrkdir/u |
| 1872 |
root_wrkdir=$pp_wrkdir/r |
| 1873 |
pp_verbose rm -rf $user_wrkdir $root_wrkdir |
| 1874 |
pp_verbose mkdir -p $user_wrkdir $root_wrkdir |
| 1875 |
|
| 1876 |
for svc in $pp_services .; do |
| 1877 |
test . = "$svc" && continue |
| 1878 |
pp_aix_add_service $svc |
| 1879 |
done |
| 1880 |
|
| 1881 |
{ |
| 1882 |
echo "4 $pp_aix_arch I $name {" |
| 1883 |
|
| 1884 |
for cmp in $pp_components; do |
| 1885 |
case "$cmp" in |
| 1886 |
run) ex=rte briefex="runtime";; |
| 1887 |
doc) ex=doc briefex="documentation";; |
| 1888 |
dev) ex=adt briefex="developer toolkit";; |
| 1889 |
dbg) ex=diag briefex="diagnostics";; |
| 1890 |
esac |
| 1891 |
|
| 1892 |
user_files=$pp_wrkdir/%files.$cmp.u |
| 1893 |
root_files=$pp_wrkdir/%files.$cmp.r |
| 1894 |
|
| 1895 |
pp_aix_select -user < $pp_wrkdir/%files.$cmp > $user_files |
| 1896 |
pp_aix_select -root < $pp_wrkdir/%files.$cmp > $root_files |
| 1897 |
|
| 1898 |
# Default to USR only unless there are root files, |
| 1899 |
# or a post/pre/check script associated |
| 1900 |
content=U |
| 1901 |
if test -s $root_files \ |
| 1902 |
-o -s $pp_wrkdir/%pre.$cmp \ |
| 1903 |
-o -s $pp_wrkdir/%post.$cmp \ |
| 1904 |
-o -s $pp_wrkdir/%preun.$cmp \ |
| 1905 |
-o -s $pp_wrkdir/%postun.$cmp \ |
| 1906 |
-o -s $pp_wrkdir/%check.$cmp |
| 1907 |
then |
| 1908 |
content=B |
| 1909 |
fi |
| 1910 |
|
| 1911 |
if $pp_opt_debug; then |
| 1912 |
echo "$cmp USER %files:" |
| 1913 |
cat $user_files |
| 1914 |
echo "$cmp ROOT %files:" |
| 1915 |
cat $root_files |
| 1916 |
fi >&2 |
| 1917 |
|
| 1918 |
bosboot=N; pp_contains_any "$pp_aix_bosboot" $cmp && bosboot=b |
| 1919 |
|
| 1920 |
echo $pp_aix_bff_name.$ex \ |
| 1921 |
`[ $pp_aix_version ] && pp_aix_version_fix $pp_aix_version || pp_aix_version_fix "$version"` \ |
| 1922 |
1 $bosboot $content \ |
| 1923 |
$pp_aix_lang "$summary $briefex" |
| 1924 |
echo "[" |
| 1925 |
|
| 1926 |
pp_aix_depend $pp_wrkdir/%depend.$cmp |
| 1927 |
|
| 1928 |
echo "%" |
| 1929 |
|
| 1930 |
# generate per-directory size information |
| 1931 |
pp_aix_size < $user_files |
| 1932 |
pp_aix_size $instroot < $root_files |
| 1933 |
|
| 1934 |
pp_aix_list < $user_files > $user_wrkdir/$pp_aix_bff_name.$ex.al |
| 1935 |
pp_aix_list $instroot < $root_files >> $user_wrkdir/$pp_aix_bff_name.$ex.al |
| 1936 |
pp_aix_list < $root_files > $root_wrkdir/$pp_aix_bff_name.$ex.al |
| 1937 |
|
| 1938 |
if $pp_opt_debug; then |
| 1939 |
echo "$cmp USER $pp_aix_bff_name.$ex.al:" |
| 1940 |
cat $user_wrkdir/$pp_aix_bff_name.$ex.al |
| 1941 |
echo "$cmp ROOT $pp_aix_bff_name.$ex.al:" |
| 1942 |
cat $root_wrkdir/$pp_aix_bff_name.$ex.al |
| 1943 |
fi >&2 |
| 1944 |
|
| 1945 |
pp_aix_inventory $pp_aix_bff_name.$ex < $user_files \ |
| 1946 |
> $user_wrkdir/$pp_aix_bff_name.$ex.inventory |
| 1947 |
pp_aix_inventory $pp_aix_bff_name.$ex < $root_files \ |
| 1948 |
> $root_wrkdir/$pp_aix_bff_name.$ex.inventory |
| 1949 |
|
| 1950 |
if $pp_opt_debug; then |
| 1951 |
pp_debug "$cmp USER $pp_aix_bff_name.$ex.inventory:" |
| 1952 |
cat $user_wrkdir/$pp_aix_bff_name.$ex.inventory |
| 1953 |
pp_debug "$cmp ROOT $pp_aix_bff_name.$ex.inventory:" |
| 1954 |
cat $root_wrkdir/$pp_aix_bff_name.$ex.inventory |
| 1955 |
fi >&2 |
| 1956 |
|
| 1957 |
for fileset in ${pp_aix_deprecated_filesets}; do |
| 1958 |
echo "$fileset" |
| 1959 |
done >$user_wrkdir/$pp_aix_bff_name.$ex.namelist |
| 1960 |
|
| 1961 |
if test x"" != x"${pp_aix_copyright:-$copyright}"; then |
| 1962 |
echo "${pp_aix_copyright:-$copyright}" > $user_wrkdir/$pp_aix_bff_name.$ex.copyright |
| 1963 |
echo "${pp_aix_copyright:-$copyright}" > $root_wrkdir/$pp_aix_bff_name.$ex.copyright |
| 1964 |
fi |
| 1965 |
|
| 1966 |
#-- assume that post/pre uninstall scripts only make |
| 1967 |
# sense when installed in a root context |
| 1968 |
|
| 1969 |
if test -r $pp_wrkdir/%pre.$cmp; then |
| 1970 |
pp_aix_make_script $user_wrkdir/$pp_aix_bff_name.$ex.pre_i \ |
| 1971 |
< $pp_wrkdir/%pre.$cmp |
| 1972 |
fi |
| 1973 |
|
| 1974 |
if test -r $pp_wrkdir/%post.$cmp; then |
| 1975 |
pp_aix_make_script $root_wrkdir/$pp_aix_bff_name.$ex.post_i \ |
| 1976 |
< $pp_wrkdir/%post.$cmp |
| 1977 |
fi |
| 1978 |
|
| 1979 |
if test -r $pp_wrkdir/%preun.$cmp; then |
| 1980 |
pp_aix_make_script $root_wrkdir/$pp_aix_bff_name.$ex.unpost_i \ |
| 1981 |
< $pp_wrkdir/%preun.$cmp |
| 1982 |
fi |
| 1983 |
|
| 1984 |
if test -r $pp_wrkdir/%postun.$cmp; then |
| 1985 |
pp_aix_make_script $root_wrkdir/$pp_aix_bff_name.$ex.unpre_i \ |
| 1986 |
< $pp_wrkdir/%postun.$cmp |
| 1987 |
fi |
| 1988 |
|
| 1989 |
# remove empty files |
| 1990 |
for f in $user_wrkdir/$pp_aix_bff_name.$ex.* $root_wrkdir/$pp_aix_bff_name.$ex.*; do |
| 1991 |
if test ! -s "$f"; then |
| 1992 |
pp_debug "removing empty $f" |
| 1993 |
rm -f "$f" |
| 1994 |
fi |
| 1995 |
done |
| 1996 |
|
| 1997 |
# copy/link the root files so we can do an easy backup later |
| 1998 |
pp_aix_copy_root $instroot < $root_files |
| 1999 |
|
| 2000 |
echo "%" |
| 2001 |
echo "]" |
| 2002 |
done |
| 2003 |
echo "}" |
| 2004 |
} > $pp_wrkdir/lpp_name |
| 2005 |
|
| 2006 |
if $pp_opt_debug; then |
| 2007 |
echo "/lpp_name :" |
| 2008 |
cat $pp_wrkdir/lpp_name |
| 2009 |
fi >&2 |
| 2010 |
|
| 2011 |
#-- copy the /lpp_name file to the destdir |
| 2012 |
pp_add_transient_file /lpp_name |
| 2013 |
cp $pp_wrkdir/lpp_name $pp_destdir/lpp_name |
| 2014 |
|
| 2015 |
#-- copy the liblpp.a files under destdir for packaging |
| 2016 |
(cd $user_wrkdir && pp_verbose ar -c -g -r liblpp.a $name.*) || |
| 2017 |
pp_error "ar error" |
| 2018 |
if test -s $user_wrkdir/liblpp.a; then |
| 2019 |
pp_add_transient_file $instuser/liblpp.a |
| 2020 |
pp_verbose cp $user_wrkdir/liblpp.a $pp_destdir$instuser/liblpp.a || |
| 2021 |
pp_error "cannot create user liblpp.a" |
| 2022 |
fi |
| 2023 |
(cd $root_wrkdir && pp_verbose ar -c -g -r liblpp.a $name.*) || |
| 2024 |
pp_error "ar error" |
| 2025 |
if test -s $root_wrkdir/liblpp.a; then |
| 2026 |
pp_add_transient_file $instroot/liblpp.a |
| 2027 |
pp_verbose cp $root_wrkdir/liblpp.a $pp_destdir$instroot/liblpp.a || |
| 2028 |
pp_error "cannot create root liblpp.a" |
| 2029 |
fi |
| 2030 |
|
| 2031 |
{ echo ./lpp_name |
| 2032 |
test -s $user_wrkdir/liblpp.a && echo .$instuser/liblpp.a |
| 2033 |
test -s $root_wrkdir/liblpp.a && echo .$instroot/liblpp.a |
| 2034 |
cat $user_wrkdir/$name.*.al # includes the relocated root files! |
| 2035 |
} > $pp_wrkdir/bff.list |
| 2036 |
|
| 2037 |
if test -n "$pp_aix_abis_seen" -a x"$pp_aix_arch_std" = x"auto"; then |
| 2038 |
case "$pp_aix_abis_seen" in |
| 2039 |
"ppc ppc64"|"ppc64 ppc") |
| 2040 |
pp_aix_arch_std=ppc64 |
| 2041 |
;; |
| 2042 |
ppc|ppc64) |
| 2043 |
pp_aix_arch_std=$pp_aix_abis_seen |
| 2044 |
;; |
| 2045 |
*" "*) |
| 2046 |
pp_warn "multiple architectures detected: $pp_aix_abis_seen" |
| 2047 |
pp_aix_arch_std=unknown |
| 2048 |
;; |
| 2049 |
"") |
| 2050 |
pp_warn "no binary executables detected; using noarch" |
| 2051 |
pp_aix_arch_std=noarch |
| 2052 |
;; |
| 2053 |
*) |
| 2054 |
pp_warn "unknown architecture detected $pp_aix_abis_seen" |
| 2055 |
pp_aix_arch_std=$pp_aix_abis_seen |
| 2056 |
;; |
| 2057 |
esac |
| 2058 |
fi |
| 2059 |
|
| 2060 |
. $pp_wrkdir/%fixup |
| 2061 |
|
| 2062 |
outbff=`pp_backend_aix_names` |
| 2063 |
pp_debug "creating: $pp_wrkdir/$outbff" |
| 2064 |
(cd $pp_destdir && pp_verbose /usr/sbin/backup -i -q -p -f -) \ |
| 2065 |
< $pp_wrkdir/bff.list \ |
| 2066 |
> $pp_wrkdir/$outbff || pp_error "backup failed" |
| 2067 |
if test -n "$pp_aix_sudo" -o -x /usr/sbin/installp; then |
| 2068 |
$pp_aix_sudo /usr/sbin/installp -l -d $pp_wrkdir/$outbff |
| 2069 |
fi |
| 2070 |
} |
| 2071 |
|
| 2072 |
pp_backend_aix_cleanup () { |
| 2073 |
: |
| 2074 |
} |
| 2075 |
|
| 2076 |
pp_backend_aix_names () { |
| 2077 |
echo "$name.`[ $pp_aix_version ] && pp_aix_version_fix $pp_aix_version || pp_aix_version_fix "$version"`.bff" |
| 2078 |
} |
| 2079 |
|
| 2080 |
pp_backend_aix_install_script () { |
| 2081 |
typeset pkgname platform |
| 2082 |
# |
| 2083 |
# The script should take a first argument being the |
| 2084 |
# operation; further arguments refer to components or services |
| 2085 |
# |
| 2086 |
# list-components -- lists components in the pkg |
| 2087 |
# install component... -- installs the components |
| 2088 |
# uninstall component... -- uninstalles the components |
| 2089 |
# list-services -- lists the services in the pkg |
| 2090 |
# start service... -- starts the name service |
| 2091 |
# stop service... -- stops the named services |
| 2092 |
# print-platform -- prints the platform group |
| 2093 |
# |
| 2094 |
pkgname="`pp_backend_aix_names`" |
| 2095 |
platform="`pp_backend_aix_probe`" # XXX should be derived from files |
| 2096 |
|
| 2097 |
fsets= |
| 2098 |
for cmp in $pp_components; do |
| 2099 |
case "$cmp" in |
| 2100 |
run) ex=rte;; |
| 2101 |
doc) ex=doc;; |
| 2102 |
dev) ex=adt;; |
| 2103 |
dbg) ex=diag;; |
| 2104 |
esac |
| 2105 |
fsets="$fsets $name.$ex" |
| 2106 |
done |
| 2107 |
|
| 2108 |
echo '#!/bin/sh' |
| 2109 |
pp_install_script_common |
| 2110 |
|
| 2111 |
cat <<-. |
| 2112 |
|
| 2113 |
cpt_to_fileset () { |
| 2114 |
test x"\$*" = x"all" && |
| 2115 |
set -- $pp_components |
| 2116 |
for cpt |
| 2117 |
do |
| 2118 |
case "\$cpt" in |
| 2119 |
run) echo "$name.rte";; |
| 2120 |
doc) echo "$name.doc";; |
| 2121 |
dev) echo "$name.adt";; |
| 2122 |
dbg) echo "$name.diag";; |
| 2123 |
*) usage;; |
| 2124 |
esac |
| 2125 |
done |
| 2126 |
} |
| 2127 |
|
| 2128 |
test \$# -eq 0 && usage |
| 2129 |
op="\$1"; shift |
| 2130 |
|
| 2131 |
case "\$op" in |
| 2132 |
list-components) |
| 2133 |
test \$# -eq 0 || usage \$op |
| 2134 |
echo "$pp_components" |
| 2135 |
;; |
| 2136 |
list-services) |
| 2137 |
test \$# -eq 0 || usage \$op |
| 2138 |
echo "$pp_services" |
| 2139 |
;; |
| 2140 |
list-files) |
| 2141 |
test \$# -ge 1 || usage \$op |
| 2142 |
echo \${PP_PKGDESTDIR:-.}/$pkgname |
| 2143 |
;; |
| 2144 |
install) |
| 2145 |
test \$# -ge 1 || usage \$op |
| 2146 |
verbose /usr/sbin/installp -acX -V0 -F \ |
| 2147 |
-d \${PP_PKGDESTDIR:-.}/$pkgname \ |
| 2148 |
\`cpt_to_fileset "\$@"\` |
| 2149 |
;; |
| 2150 |
uninstall) |
| 2151 |
test \$# -ge 1 || usage \$op |
| 2152 |
verbose /usr/sbin/installp -u -e/dev/null \ |
| 2153 |
-V0 \`cpt_to_fileset "\$@"\` |
| 2154 |
;; |
| 2155 |
start|stop) |
| 2156 |
test \$# -ge 1 || usage \$op |
| 2157 |
ec=0 |
| 2158 |
for svc |
| 2159 |
do |
| 2160 |
verbose \${op}src -s \$svc || ec=1 |
| 2161 |
done |
| 2162 |
exit \$ec |
| 2163 |
;; |
| 2164 |
print-platform) |
| 2165 |
echo "$platform" |
| 2166 |
;; |
| 2167 |
*) |
| 2168 |
usage;; |
| 2169 |
esac |
| 2170 |
. |
| 2171 |
} |
| 2172 |
|
| 2173 |
pp_backend_aix_init_svc_vars () { |
| 2174 |
: |
| 2175 |
} |
| 2176 |
|
| 2177 |
pp_backend_aix_probe () { |
| 2178 |
echo "${pp_aix_os}-${pp_aix_arch_std}" |
| 2179 |
} |
| 2180 |
|
| 2181 |
pp_backend_aix_vas_platforms () { |
| 2182 |
case "${pp_aix_arch_std}" in |
| 2183 |
ppc*) :;; |
| 2184 |
*) pp_die "unknown architecture ${pp_aix_arch_std}";; |
| 2185 |
esac |
| 2186 |
case "${pp_aix_os}" in |
| 2187 |
aix43) echo "aix-43";; |
| 2188 |
aix51) echo "aix-51 aix-43";; |
| 2189 |
aix52) echo "aix-51 aix-43";; |
| 2190 |
aix53) echo "aix-53 aix-51 aix-43";; |
| 2191 |
aix61) echo "aix-53 aix-51 aix-43";; |
| 2192 |
*) pp_die "unknown system ${pp_aix_os}";; |
| 2193 |
esac |
| 2194 |
} |
| 2195 |
pp_backend_aix_function () { |
| 2196 |
case "$1" in |
| 2197 |
pp_mkgroup) cat <<'.';; |
| 2198 |
/usr/sbin/lsgroup "$1" >/dev/null && |
| 2199 |
return 0 |
| 2200 |
echo "Creating group $1" |
| 2201 |
/usr/bin/mkgroup -A "$1" |
| 2202 |
. |
| 2203 |
pp_mkuser:depends) echo pp_mkgroup;; |
| 2204 |
pp_mkuser) cat <<'.';; |
| 2205 |
/usr/sbin/lsuser "$1" >/dev/null && |
| 2206 |
return 0 |
| 2207 |
pp_mkgroup "${2:-$1}" || return 1 |
| 2208 |
echo "Creating user $1" |
| 2209 |
/usr/bin/mkuser \ |
| 2210 |
login=false \ |
| 2211 |
rlogin=false \ |
| 2212 |
account_locked=true \ |
| 2213 |
home="${3:-/nohome.$1}" \ |
| 2214 |
pgrp="${2:-$1}" \ |
| 2215 |
"$1" |
| 2216 |
. |
| 2217 |
pp_havelib) cat <<'.';; |
| 2218 |
case "$2" in |
| 2219 |
"") pp_tmp_name="lib$1.so";; |
| 2220 |
*.*.*) pp_tmp_name="lib$1.so.$2";; |
| 2221 |
*.*) pp_tmp_name="lib$1.so.$2.0";; |
| 2222 |
*) pp_tmp_name="lib$1.so.$2";; |
| 2223 |
esac |
| 2224 |
for pp_tmp_dir in `echo "/usr/lib:/lib${3:+:$3}" | tr : ' '`; do |
| 2225 |
test -r "$pp_tmp_dir/$pp_tmp_name" -a \ |
| 2226 |
-r "$pp_tmp_dir/lib$1.so" && return 0 |
| 2227 |
done |
| 2228 |
return 1 |
| 2229 |
. |
| 2230 |
*) false;; |
| 2231 |
esac |
| 2232 |
} |
| 2233 |
|
| 2234 |
pp_platforms="$pp_platforms sd" |
| 2235 |
|
| 2236 |
pp_backend_sd_detect () { |
| 2237 |
test x"$1" = x"HP-UX" |
| 2238 |
} |
| 2239 |
|
| 2240 |
pp_backend_sd_init () { |
| 2241 |
pp_sd_sudo=sudo |
| 2242 |
pp_sd_startlevels=2 |
| 2243 |
pp_sd_stoplevels=auto |
| 2244 |
pp_sd_config_file= |
| 2245 |
pp_sd_vendor= |
| 2246 |
pp_sd_vendor_tag=OneIdentity |
| 2247 |
pp_sd_default_start=1 # config_file default start value |
| 2248 |
|
| 2249 |
pp_readlink_fn=pp_ls_readlink # HPUX has no readlink |
| 2250 |
pp_shlib_suffix='.sl' # .so on most other platforms |
| 2251 |
|
| 2252 |
pp_sd_detect_os |
| 2253 |
} |
| 2254 |
|
| 2255 |
pp_sd_detect_os () { |
| 2256 |
typeset revision |
| 2257 |
|
| 2258 |
revision=`uname -r` |
| 2259 |
pp_sd_os="${revision#?.}" |
| 2260 |
test -z "$pp_sd_os" && |
| 2261 |
pp_warn "cannot detect OS version" |
| 2262 |
pp_sd_os_std="hpux`echo $pp_sd_os | tr -d .`" |
| 2263 |
|
| 2264 |
case "`uname -m`" in |
| 2265 |
9000/[678]??) pp_sd_arch_std=hppa;; |
| 2266 |
ia64) pp_sd_arch_std=ia64;; |
| 2267 |
*) pp_sd_arch_std=unknown;; |
| 2268 |
esac |
| 2269 |
} |
| 2270 |
|
| 2271 |
pp_sd_write_files () { |
| 2272 |
typeset t m o g f p st line dm |
| 2273 |
while read t m o g f p st; do |
| 2274 |
line=" file" |
| 2275 |
case "$f" in *v*) line="$line -v";; esac # FIXME for uninstall |
| 2276 |
case ${pp_sd_os} in |
| 2277 |
10.*) |
| 2278 |
case $t in |
| 2279 |
f) dm=644;; |
| 2280 |
d) p=${p%/}; dm=755;; |
| 2281 |
esac |
| 2282 |
;; |
| 2283 |
*) |
| 2284 |
case $t in |
| 2285 |
f) dm=644;; |
| 2286 |
d) line="$line -t d"; p=${p%/}; dm=755;; |
| 2287 |
s) line="$line -t s";; |
| 2288 |
esac |
| 2289 |
;; |
| 2290 |
esac |
| 2291 |
|
| 2292 |
test x"$o" = x"-" && o=root |
| 2293 |
test x"$g" = x"-" && g=sys |
| 2294 |
test x"$m" = x"-" && m=$dm |
| 2295 |
|
| 2296 |
case $t in |
| 2297 |
s) |
| 2298 |
# swpackage will make unqualified links relative to the |
| 2299 |
# current working (source) directory, not the destination; |
| 2300 |
# we need to qualify them to prevent this. |
| 2301 |
case "$st" in |
| 2302 |
[!/]*) st="`dirname \"$p\"`/$st";; |
| 2303 |
esac |
| 2304 |
echo "$line -o $o -g $g -m $m $st $p" |
| 2305 |
;; |
| 2306 |
*) |
| 2307 |
echo "$line -o $o -g $g -m $m $pp_destdir$p $p" |
| 2308 |
;; |
| 2309 |
esac |
| 2310 |
|
| 2311 |
done |
| 2312 |
} |
| 2313 |
|
| 2314 |
pp_sd_service_group_script () { |
| 2315 |
typeset grp svcs scriptpath out |
| 2316 |
grp="$1" |
| 2317 |
svcs="$2" |
| 2318 |
scriptpath="/sbin/init.d/$grp" |
| 2319 |
out="$pp_destdir$scriptpath" |
| 2320 |
|
| 2321 |
pp_add_file_if_missing $scriptpath run 755 || return 0 |
| 2322 |
|
| 2323 |
cat <<-. > $out |
| 2324 |
#!/sbin/sh |
| 2325 |
# generated by pp $pp_version |
| 2326 |
svcs="$svcs" |
| 2327 |
. |
| 2328 |
|
| 2329 |
cat <<-'.' >> $out |
| 2330 |
#-- starts services in order.. stops them all if any break |
| 2331 |
pp_start () { |
| 2332 |
undo= |
| 2333 |
for svc in \$svcs; do |
| 2334 |
/sbin/init.d/\$svc start |
| 2335 |
case \$? in |
| 2336 |
0|4) |
| 2337 |
undo="\$svc \$undo" |
| 2338 |
;; |
| 2339 |
*) |
| 2340 |
if test -n "\$undo"; then |
| 2341 |
for svc in \$undo; do |
| 2342 |
/sbin/init.d/\$svc stop |
| 2343 |
done |
| 2344 |
return 1 |
| 2345 |
fi |
| 2346 |
;; |
| 2347 |
esac |
| 2348 |
done |
| 2349 |
return 0 |
| 2350 |
} |
| 2351 |
|
| 2352 |
#-- stops services in reverse |
| 2353 |
pp_stop () { |
| 2354 |
reverse= |
| 2355 |
for svc in \$svcs; do |
| 2356 |
reverse="\$svc \$reverse" |
| 2357 |
done |
| 2358 |
rc=0 |
| 2359 |
for svc in \$reverse; do |
| 2360 |
/sbin/init.d/\$svc stop || rc=\$? |
| 2361 |
done |
| 2362 |
return \$rc |
| 2363 |
} |
| 2364 |
|
| 2365 |
case \$1 in |
| 2366 |
start_msg) echo "Starting \$svcs";; |
| 2367 |
stop_msg) echo "Stopping \$svcs";; |
| 2368 |
start) pp_start;; |
| 2369 |
stop) pp_stop;; |
| 2370 |
*) echo "usage: \$0 {start|stop|start_msg|stop_msg}" |
| 2371 |
exit 1;; |
| 2372 |
esac |
| 2373 |
. |
| 2374 |
} |
| 2375 |
|
| 2376 |
pp_sd_service_script () { |
| 2377 |
typeset svc config_file config_value scriptpath out |
| 2378 |
|
| 2379 |
svc="$1" |
| 2380 |
scriptpath="/sbin/init.d/$svc" |
| 2381 |
|
| 2382 |
config_file=${pp_sd_config_file:-/etc/rc.config.d/$svc} |
| 2383 |
sd_config_var=`echo run-$svc | tr '[a-z]-' '[A-Z]_'` |
| 2384 |
sd_config_value=${pp_sd_default_start:-0} |
| 2385 |
pp_load_service_vars "$svc" |
| 2386 |
|
| 2387 |
test -n "$user" -a x"$user" != x"root" && |
| 2388 |
cmd="SHELL=/usr/bin/sh /usr/bin/su $user -c \"exec `echo $cmd | sed -e 's,[$\\\`],\\&,g'`\"" |
| 2389 |
if test -z "$pidfile"; then |
| 2390 |
pidfile="/var/run/$svc.pid" |
| 2391 |
cmd="$cmd & echo \$! > \$pidfile" |
| 2392 |
fi |
| 2393 |
|
| 2394 |
pp_debug "config file is $config_file" |
| 2395 |
|
| 2396 |
pp_add_file_if_missing $scriptpath run 755 |
| 2397 |
pp_add_file_if_missing $config_file run 644 v |
| 2398 |
|
| 2399 |
cat <<-. >> $pp_destdir$config_file |
| 2400 |
|
| 2401 |
# Controls whether the $svc service is started |
| 2402 |
$sd_config_var=$sd_config_value |
| 2403 |
. |
| 2404 |
|
| 2405 |
if test ! -f $pp_destdir$scriptpath; then |
| 2406 |
cat <<-. > $pp_destdir$scriptpath |
| 2407 |
#!/sbin/sh |
| 2408 |
# generated by pp $pp_version |
| 2409 |
|
| 2410 |
svc="$svc" |
| 2411 |
pidfile="$pidfile" |
| 2412 |
config_file="$config_file" |
| 2413 |
|
| 2414 |
pp_start () { |
| 2415 |
$cmd |
| 2416 |
} |
| 2417 |
|
| 2418 |
pp_disabled () { |
| 2419 |
test \${$sd_config_var:-0} -eq 0 |
| 2420 |
} |
| 2421 |
|
| 2422 |
pp_stop () { |
| 2423 |
if test ! -s "\$pidfile"; then |
| 2424 |
echo "Unable to stop \$svc (no pid file)" |
| 2425 |
return 1 |
| 2426 |
else |
| 2427 |
read pid < "\$pidfile" |
| 2428 |
if kill -0 "\$pid" 2>/dev/null; then |
| 2429 |
if kill -${stop_signal:-TERM} "\$pid"; then |
| 2430 |
rm -f "\$pidfile" |
| 2431 |
return 0 |
| 2432 |
else |
| 2433 |
echo "Unable to stop \$svc" |
| 2434 |
return 1 |
| 2435 |
fi |
| 2436 |
else |
| 2437 |
rm -f "\$pidfile" |
| 2438 |
return 0 |
| 2439 |
fi |
| 2440 |
fi |
| 2441 |
} |
| 2442 |
|
| 2443 |
pp_running () { |
| 2444 |
if test -s "\$pidfile"; then |
| 2445 |
read pid < "\$pidfile" 2>/dev/null |
| 2446 |
if test \${pid:-0} -gt 1 && kill -0 "\$pid" 2>/dev/null; then |
| 2447 |
# make sure command name matches |
| 2448 |
c="\`echo $cmd | sed -e 's: .*::' -e 's:^.*/::'\`" |
| 2449 |
pid="\`ps -p \$pid 2>/dev/null | sed -n \"s/^ *\(\$pid\) .*\$c *\$/\1/p\"\`" |
| 2450 |
if test -n "\$pid"; then |
| 2451 |
return 0 |
| 2452 |
fi |
| 2453 |
fi |
| 2454 |
fi |
| 2455 |
return 1 |
| 2456 |
} |
| 2457 |
|
| 2458 |
case \$1 in |
| 2459 |
start_msg) echo "Starting the \$svc service";; |
| 2460 |
stop_msg) echo "Stopping the \$svc service";; |
| 2461 |
start) |
| 2462 |
if test -f "\$config_file"; then |
| 2463 |
. \$config_file |
| 2464 |
fi |
| 2465 |
if pp_disabled; then |
| 2466 |
exit 2 |
| 2467 |
elif pp_running; then |
| 2468 |
echo "\$svc already running"; |
| 2469 |
exit 0 |
| 2470 |
elif pp_start; then |
| 2471 |
echo "\$svc started"; |
| 2472 |
# rc(1M) says we should exit 4, but nobody expects it! |
| 2473 |
exit 0 |
| 2474 |
else |
| 2475 |
exit 1 |
| 2476 |
fi;; |
| 2477 |
stop) if pp_stop; then |
| 2478 |
echo "\$svc stopped"; |
| 2479 |
exit 0 |
| 2480 |
else |
| 2481 |
exit 1 |
| 2482 |
fi;; |
| 2483 |
*) echo "usage: \$0 {start|stop|start_msg|stop_msg}" |
| 2484 |
exit 1;; |
| 2485 |
esac |
| 2486 |
. |
| 2487 |
fi |
| 2488 |
} |
| 2489 |
|
| 2490 |
pp_sd_make_service () { |
| 2491 |
typeset level startpriority stoppriority startlevels stoplevels |
| 2492 |
typeset svc svcvar symtype |
| 2493 |
|
| 2494 |
svc="$1" |
| 2495 |
svcvar=`pp_makevar $svc` |
| 2496 |
|
| 2497 |
case ${pp_sd_os} in |
| 2498 |
10.*) symtype="file";; |
| 2499 |
*) symtype="file -t s";; |
| 2500 |
esac |
| 2501 |
|
| 2502 |
# TODO: Figure out why this check is here |
| 2503 |
#-- don't do anything if the script exists |
| 2504 |
#if test -s "$pp_destdir/sbin/init.d/$svc"; then |
| 2505 |
# pp_error "$pp_destdir/sbin/init.d/$svc exists" |
| 2506 |
# return |
| 2507 |
#fi |
| 2508 |
|
| 2509 |
# symlink the script, depending on the priorities chosen |
| 2510 |
eval startpriority='${pp_sd_startpriority_'$svcvar'}' |
| 2511 |
eval stoppriority='${pp_sd_stoppriority_'$svcvar'}' |
| 2512 |
test -z "$startpriority" && startpriority="${pp_sd_startpriority:-50}" |
| 2513 |
test -z "$stoppriority" && stoppriority="${pp_sd_stoppriority:-50}" |
| 2514 |
|
| 2515 |
eval startlevels='${pp_sd_startlevels_'$svcvar'}' |
| 2516 |
test -z "$startlevels" && startlevels="$pp_sd_startlevels" |
| 2517 |
|
| 2518 |
eval stoplevels='${pp_sd_stoplevels_'$svcvar'}' |
| 2519 |
test -z "$stoplevels" && stoplevels="$pp_sd_stoplevels" |
| 2520 |
|
| 2521 |
# create the script and config file |
| 2522 |
pp_sd_service_script $svc |
| 2523 |
|
| 2524 |
# fix the priority up |
| 2525 |
case "$startpriority" in |
| 2526 |
???) :;; |
| 2527 |
??) startpriority=0$startpriority;; |
| 2528 |
?) startpriority=00$startpriority;; |
| 2529 |
esac |
| 2530 |
case "$stoppriority" in |
| 2531 |
???) :;; |
| 2532 |
??) stoppriority=0$stoppriority;; |
| 2533 |
?) stoppriority=00$stoppriority;; |
| 2534 |
esac |
| 2535 |
|
| 2536 |
if test x"$stoplevels" = x"auto"; then |
| 2537 |
stoplevels= |
| 2538 |
test -z "$startlevels" || for level in $startlevels; do |
| 2539 |
stoplevels="$stoplevels `expr $level - 1`" |
| 2540 |
done |
| 2541 |
fi |
| 2542 |
|
| 2543 |
# create the symlinks |
| 2544 |
test -z "$startlevels" || for level in $startlevels; do |
| 2545 |
echo " ${symtype}" \ |
| 2546 |
"/sbin/init.d/$svc" \ |
| 2547 |
"/sbin/rc$level.d/S$startpriority$svc" |
| 2548 |
done |
| 2549 |
test -z "$stoplevels" || for level in $stoplevels; do |
| 2550 |
echo " ${symtype}" \ |
| 2551 |
"/sbin/init.d/$svc" \ |
| 2552 |
"/sbin/rc$level.d/K$stoppriority$svc" |
| 2553 |
done |
| 2554 |
} |
| 2555 |
|
| 2556 |
pp_sd_control () { |
| 2557 |
typeset ctrl script |
| 2558 |
typeset cpt |
| 2559 |
|
| 2560 |
ctrl="$1"; shift |
| 2561 |
cpt="$1"; shift |
| 2562 |
script="$pp_wrkdir/control.$ctrl.$cpt" |
| 2563 |
cat <<. >$script |
| 2564 |
. |
| 2565 |
cat "$@" >> $script |
| 2566 |
echo "exit 0" >> $script |
| 2567 |
/usr/bin/chmod +x $script |
| 2568 |
echo " $ctrl $script" |
| 2569 |
} |
| 2570 |
|
| 2571 |
pp_sd_depend () { |
| 2572 |
typeset _name _vers |
| 2573 |
while read _name _vers; do |
| 2574 |
case "$_name" in ""| "#"*) continue ;; esac |
| 2575 |
echo " prerequisites $_name ${_vers:+r>= $_vers}" |
| 2576 |
done |
| 2577 |
} |
| 2578 |
|
| 2579 |
pp_sd_conflict () { |
| 2580 |
typeset _name _vers |
| 2581 |
while read _name _vers; do |
| 2582 |
case "$_name" in ""| "#"*) continue ;; esac |
| 2583 |
echo " exrequisites $_name ${_vers:+r>= $_vers}" |
| 2584 |
done |
| 2585 |
} |
| 2586 |
|
| 2587 |
pp_backend_sd () { |
| 2588 |
typeset psf cpt svc outfile release swp_flags |
| 2589 |
|
| 2590 |
psf=$pp_wrkdir/psf |
| 2591 |
release="?.${pp_sd_os%.[0-9][0-9]}.*" |
| 2592 |
|
| 2593 |
echo "depot" > $psf |
| 2594 |
echo "layout_version 1.0" >>$psf |
| 2595 |
|
| 2596 |
#-- vendor |
| 2597 |
cat <<. >>$psf |
| 2598 |
vendor |
| 2599 |
tag $pp_sd_vendor_tag |
| 2600 |
title "${pp_sd_vendor:-$vendor}" |
| 2601 |
end |
| 2602 |
|
| 2603 |
product |
| 2604 |
tag $name |
| 2605 |
revision $version |
| 2606 |
vendor_tag $pp_sd_vendor_tag |
| 2607 |
is_patch false |
| 2608 |
title "$summary" |
| 2609 |
copyright "$copyright" |
| 2610 |
machine_type * |
| 2611 |
os_name HP-UX |
| 2612 |
os_release $release |
| 2613 |
os_version ? |
| 2614 |
directory / |
| 2615 |
is_locatable false |
| 2616 |
. |
| 2617 |
test -n "$description" \ |
| 2618 |
&& echo $description > $pp_wrkdir/description \ |
| 2619 |
&& cat <<. >> $psf |
| 2620 |
description < $pp_wrkdir/description |
| 2621 |
. |
| 2622 |
|
| 2623 |
# make convenience service groups |
| 2624 |
if test -n "$pp_service_groups"; then |
| 2625 |
for grp in $pp_service_groups; do |
| 2626 |
pp_sd_service_group_script \ |
| 2627 |
$grp "`pp_service_get_svc_group $grp`" |
| 2628 |
done |
| 2629 |
fi |
| 2630 |
|
| 2631 |
for cpt in $pp_components; do |
| 2632 |
cat <<. >>$psf |
| 2633 |
fileset |
| 2634 |
tag ${pp_sd_fileset_tag:-$cpt} |
| 2635 |
title "${summary:-cpt}" |
| 2636 |
revision $version |
| 2637 |
. |
| 2638 |
test -s $pp_wrkdir/%depend.$cpt && |
| 2639 |
pp_sd_depend < $pp_wrkdir/%depend.$cpt >> $psf |
| 2640 |
test -s $pp_wrkdir/%conflict.$cpt && |
| 2641 |
pp_sd_conflict < $pp_wrkdir/%conflict.$cpt >> $psf |
| 2642 |
|
| 2643 |
#-- make sure services are shut down during uninstall |
| 2644 |
if test $cpt = run -a -n "$pp_services"; then |
| 2645 |
for svc in $pp_services; do |
| 2646 |
pp_prepend $pp_wrkdir/%preun.$cpt <<-. |
| 2647 |
/sbin/init.d/$svc stop |
| 2648 |
. |
| 2649 |
done |
| 2650 |
fi |
| 2651 |
|
| 2652 |
#-- we put the post/preun code into configure/unconfigure |
| 2653 |
# and not postinstall/preremove, because configure/unconfigure |
| 2654 |
# scripts are run on the hosts where the package is installed, |
| 2655 |
# not loaded (a subtle difference). |
| 2656 |
test -s $pp_wrkdir/%pre.$cpt && |
| 2657 |
pp_sd_control checkinstall $cpt $pp_wrkdir/%pre.$cpt >> $psf |
| 2658 |
test -s $pp_wrkdir/%post.$cpt && |
| 2659 |
pp_sd_control configure $cpt $pp_wrkdir/%post.$cpt >> $psf |
| 2660 |
test -s $pp_wrkdir/%preun.$cpt && |
| 2661 |
pp_sd_control unconfigure $cpt $pp_wrkdir/%preun.$cpt >> $psf |
| 2662 |
test -s $pp_wrkdir/%postun.$cpt && |
| 2663 |
pp_sd_control postremove $cpt $pp_wrkdir/%postun.$cpt >> $psf |
| 2664 |
test -s $pp_wrkdir/%check.$cpt && |
| 2665 |
pp_sd_control checkinstall $cpt $pp_wrkdir/%check.$cpt >> $psf |
| 2666 |
|
| 2667 |
if test $cpt = run -a -n "$pp_services"; then |
| 2668 |
for svc in $pp_services; do |
| 2669 |
#-- service names are 10 chars max on hpux |
| 2670 |
case "$svc" in ???????????*) |
| 2671 |
pp_warn "service name '$svc' is too long for hpux";; |
| 2672 |
esac |
| 2673 |
pp_sd_make_service $svc >> $psf |
| 2674 |
done |
| 2675 |
#pp_sd_make_service_config |
| 2676 |
fi |
| 2677 |
|
| 2678 |
pp_sd_write_files < $pp_wrkdir/%files.$cpt >> $psf |
| 2679 |
|
| 2680 |
#-- end fileset clause |
| 2681 |
cat <<. >>$psf |
| 2682 |
end |
| 2683 |
. |
| 2684 |
|
| 2685 |
done |
| 2686 |
|
| 2687 |
#-- end product clause |
| 2688 |
cat <<. >>$psf |
| 2689 |
end |
| 2690 |
. |
| 2691 |
|
| 2692 |
$pp_opt_debug && cat $psf >&2 |
| 2693 |
|
| 2694 |
test -s $pp_wrkdir/%fixup && . $pp_wrkdir/%fixup |
| 2695 |
|
| 2696 |
outfile=`pp_backend_sd_names` |
| 2697 |
case ${pp_sd_os} in |
| 2698 |
10.*) |
| 2699 |
swp_flags="-x target_type=tape" |
| 2700 |
;; |
| 2701 |
*) |
| 2702 |
swp_flags="-x media_type=tape" |
| 2703 |
;; |
| 2704 |
esac |
| 2705 |
if pp_verbose ${pp_sd_sudo} /usr/sbin/swpackage -s $psf $swp_flags \ |
| 2706 |
@ $pp_wrkdir/$outfile |
| 2707 |
then |
| 2708 |
pp_verbose ${pp_sd_sudo} /usr/sbin/swlist -l file -s $pp_wrkdir/$outfile |
| 2709 |
else |
| 2710 |
pp_error "swpackage failed" |
| 2711 |
fi |
| 2712 |
} |
| 2713 |
|
| 2714 |
pp_backend_sd_cleanup () { |
| 2715 |
: |
| 2716 |
} |
| 2717 |
|
| 2718 |
pp_backend_sd_names () { |
| 2719 |
echo "$name-$version.$pp_sd_arch_std.depot" |
| 2720 |
} |
| 2721 |
|
| 2722 |
pp_backend_sd_install_script () { |
| 2723 |
typeset pkgname platform |
| 2724 |
|
| 2725 |
pkgname=`pp_backend_sd_names` |
| 2726 |
platform="`pp_backend_sd_probe`" |
| 2727 |
|
| 2728 |
echo "#!/bin/sh" |
| 2729 |
pp_install_script_common |
| 2730 |
cat <<. |
| 2731 |
|
| 2732 |
cpt_to_tags () { |
| 2733 |
test x"\$*" = x"all" && set -- $pp_components |
| 2734 |
for cpt |
| 2735 |
do |
| 2736 |
echo "$name.\$cpt" |
| 2737 |
done |
| 2738 |
} |
| 2739 |
|
| 2740 |
test \$# -eq 0 && usage |
| 2741 |
op="\$1"; shift |
| 2742 |
|
| 2743 |
case "\$op" in |
| 2744 |
list-components) |
| 2745 |
test \$# -eq 0 || usage \$op |
| 2746 |
echo "$pp_components" |
| 2747 |
;; |
| 2748 |
list-services) |
| 2749 |
test \$# -eq 0 || usage \$op |
| 2750 |
echo "$pp_services" |
| 2751 |
;; |
| 2752 |
list-files) |
| 2753 |
test \$# -ge 1 || usage \$op |
| 2754 |
echo \${PP_PKGDESTDIR:-.}/$pkgname |
| 2755 |
;; |
| 2756 |
install) |
| 2757 |
test \$# -ge 1 || usage \$op |
| 2758 |
verbose /usr/sbin/swinstall -x verbose=0 \ |
| 2759 |
-s \${PP_PKGDESTDIR:-\`pwd\`}/$pkgname \ |
| 2760 |
\`cpt_to_tags "\$@"\` |
| 2761 |
;; |
| 2762 |
uninstall) |
| 2763 |
test \$# -ge 1 || usage \$op |
| 2764 |
verbose /usr/sbin/swremove -x verbose=0 \ |
| 2765 |
\`cpt_to_tags "\$@"\` |
| 2766 |
;; |
| 2767 |
start|stop) |
| 2768 |
test \$# -ge 1 || usage \$op |
| 2769 |
ec=0 |
| 2770 |
for svc |
| 2771 |
do |
| 2772 |
verbose /sbin/init.d/\$svc \$op |
| 2773 |
[ \$? -eq 4 -o \$? -eq 0 ] || ec=1 |
| 2774 |
done |
| 2775 |
exit \$ec |
| 2776 |
;; |
| 2777 |
print-platform) |
| 2778 |
echo "$platform" |
| 2779 |
;; |
| 2780 |
*) |
| 2781 |
usage |
| 2782 |
;; |
| 2783 |
esac |
| 2784 |
. |
| 2785 |
} |
| 2786 |
|
| 2787 |
pp_backend_sd_probe () { |
| 2788 |
echo "${pp_sd_os_std}-${pp_sd_arch_std}" |
| 2789 |
} |
| 2790 |
|
| 2791 |
pp_backend_sd_vas_platforms () { |
| 2792 |
case "`pp_backend_sd_probe`" in |
| 2793 |
hpux*-hppa) echo hpux-pa;; |
| 2794 |
hpux*-ia64) echo hpux-ia64 hpux-pa;; |
| 2795 |
*) pp_die "unknown system `pp_backend_sd_probe`";; |
| 2796 |
esac |
| 2797 |
} |
| 2798 |
|
| 2799 |
pp_backend_sd_init_svc_vars () { |
| 2800 |
: |
| 2801 |
} |
| 2802 |
pp_backend_sd_function () { |
| 2803 |
case "$1" in |
| 2804 |
pp_mkgroup) cat <<'.';; |
| 2805 |
/usr/sbin/groupmod "$1" 2>/dev/null || |
| 2806 |
/usr/sbin/groupadd "$1" |
| 2807 |
. |
| 2808 |
pp_mkuser:depends) echo pp_mkgroup;; |
| 2809 |
pp_mkuser) cat <<'.';; |
| 2810 |
pp_mkgroup "${2:-$1}" || return 1 |
| 2811 |
/usr/sbin/useradd \ |
| 2812 |
-g "${2:-$1}" \ |
| 2813 |
-d "${3:-/nonexistent}" \ |
| 2814 |
-s "${4:-/bin/false}" \ |
| 2815 |
"$1" |
| 2816 |
. |
| 2817 |
pp_havelib) cat <<'.';; |
| 2818 |
for pp_tmp_dir in `echo /usr/lib${3:+:$3} | tr : ' '`; do |
| 2819 |
test -r "$pp_tmp_dir/lib$1${2:+.$2}.sl" && return 0 |
| 2820 |
done |
| 2821 |
return 1 |
| 2822 |
. |
| 2823 |
*) false;; |
| 2824 |
esac |
| 2825 |
} |
| 2826 |
|
| 2827 |
pp_platforms="$pp_platforms solaris" |
| 2828 |
|
| 2829 |
pp_backend_solaris_detect () { |
| 2830 |
test x"$1" = x"SunOS" |
| 2831 |
} |
| 2832 |
|
| 2833 |
pp_backend_solaris_init () { |
| 2834 |
pp_solaris_category= |
| 2835 |
pp_solaris_istates="s S 1 2 3" # run-states when install is ok |
| 2836 |
pp_solaris_rstates="s S 1 2 3" # run-states when remove is ok |
| 2837 |
pp_solaris_maxinst= |
| 2838 |
pp_solaris_vendor= |
| 2839 |
pp_solaris_pstamp= |
| 2840 |
pp_solaris_copyright= |
| 2841 |
pp_solaris_name= |
| 2842 |
pp_solaris_desc= |
| 2843 |
pp_solaris_package_arch=auto |
| 2844 |
|
| 2845 |
pp_solaris_detect_os |
| 2846 |
pp_solaris_detect_arch |
| 2847 |
|
| 2848 |
pp_solaris_init_svc |
| 2849 |
|
| 2850 |
#-- readlink not reliably available on Solaris |
| 2851 |
pp_readlink_fn=pp_ls_readlink |
| 2852 |
} |
| 2853 |
|
| 2854 |
pp_solaris_detect_os () { |
| 2855 |
typeset osrel |
| 2856 |
|
| 2857 |
osrel=`/usr/bin/uname -r` |
| 2858 |
case "$osrel" in |
| 2859 |
5.[0-6]) pp_solaris_os="sol2${osrel#5.}";; |
| 2860 |
5.*) pp_solaris_os="sol${osrel#5.}";; |
| 2861 |
esac |
| 2862 |
test -z "$pp_solaris_os" && |
| 2863 |
pp_warn "can't determine OS suffix from uname -r" |
| 2864 |
|
| 2865 |
} |
| 2866 |
|
| 2867 |
pp_solaris_detect_arch () { |
| 2868 |
if [ -x /usr/bin/isainfo ]; then |
| 2869 |
pp_solaris_arch=`/usr/bin/isainfo -n` |
| 2870 |
else |
| 2871 |
pp_solaris_arch=`/usr/bin/optisa amd64 sparcv9 i386 sparc` |
| 2872 |
fi |
| 2873 |
[ -z "$pp_solaris_arch" ] && |
| 2874 |
pp_error "can't determine processor architecture" |
| 2875 |
case "$pp_solaris_arch" in |
| 2876 |
amd64) pp_solaris_arch_std=x86_64;; |
| 2877 |
i386) pp_solaris_arch_std=i386;; |
| 2878 |
sparcv9) pp_solaris_arch_std=sparc64;; |
| 2879 |
sparc) pp_solaris_arch_std=sparc;; |
| 2880 |
*) pp_solaris_arch_std=unknown;; |
| 2881 |
esac |
| 2882 |
} |
| 2883 |
|
| 2884 |
pp_solaris_is_request_script_necessary () { |
| 2885 |
typeset has_optional_services |
| 2886 |
|
| 2887 |
has_optional_services=no |
| 2888 |
for _svc in $pp_services; do |
| 2889 |
pp_load_service_vars $_svc |
| 2890 |
if test "$optional" = "yes"; then |
| 2891 |
has_optional_services=yes |
| 2892 |
fi |
| 2893 |
done |
| 2894 |
|
| 2895 |
# If the package has no optional services and only one component, don't |
| 2896 |
# create a request script at all. |
| 2897 |
if test "$has_optional_services" = "no" && |
| 2898 |
test `echo $pp_components | wc -w` -eq 1; then |
| 2899 |
return 1 # no |
| 2900 |
fi |
| 2901 |
|
| 2902 |
return 0 # yes |
| 2903 |
} |
| 2904 |
|
| 2905 |
pp_solaris_request () { |
| 2906 |
typeset _cmp _svc |
| 2907 |
|
| 2908 |
#-- The common part of the request script contains the ask() function |
| 2909 |
# and resets the CLASSES list to empty |
| 2910 |
cat <<'.' |
| 2911 |
trap 'exit 3' 15 |
| 2912 |
ask () { |
| 2913 |
ans=`ckyorn -d "$1" \ |
| 2914 |
-p "Do you want to $2"` \ |
| 2915 |
|| exit $? |
| 2916 |
case "$ans" in y*|Y*) return 0;; *) return 1;; esac |
| 2917 |
} |
| 2918 |
CLASSES= |
| 2919 |
. |
| 2920 |
#-- each of our components adds itself to the CLASSES list |
| 2921 |
for _cmp in $pp_components; do |
| 2922 |
case "$_cmp" in |
| 2923 |
run) :;; |
| 2924 |
doc) echo 'ask y "install the documentation files" &&';; |
| 2925 |
dev) echo 'ask y "install the development files" &&';; |
| 2926 |
dbg) echo 'ask n "install the diagnostic files" &&';; |
| 2927 |
esac |
| 2928 |
echo ' CLASSES="$CLASSES '$_cmp'"' |
| 2929 |
done |
| 2930 |
|
| 2931 |
#-- the request script writes the CLASSES var to its output |
| 2932 |
cat <<'.' |
| 2933 |
echo "CLASSES=$CLASSES" > $1 |
| 2934 |
. |
| 2935 |
|
| 2936 |
if test -n "$pp_services"; then |
| 2937 |
echo 'SERVICES=' |
| 2938 |
for _svc in $pp_services; do |
| 2939 |
pp_load_service_vars $_svc |
| 2940 |
if test "$enable" = "yes"; then |
| 2941 |
_default_prompt=y |
| 2942 |
else |
| 2943 |
_default_prompt=n |
| 2944 |
fi |
| 2945 |
if test "$optional" = "yes"; then |
| 2946 |
echo 'ask '$_default_prompt' "install '$_svc' service" &&' |
| 2947 |
fi |
| 2948 |
echo ' SERVICES="$SERVICES '$_svc'"' |
| 2949 |
done |
| 2950 |
echo 'echo "SERVICES=$SERVICES" >> $1' |
| 2951 |
fi |
| 2952 |
|
| 2953 |
} |
| 2954 |
|
| 2955 |
pp_solaris_procedure () { |
| 2956 |
cat <<. |
| 2957 |
|
| 2958 |
#-- $2 for $1 component of $name |
| 2959 |
case " \$CLASSES " in *" $1 "*) |
| 2960 |
. |
| 2961 |
cat |
| 2962 |
cat <<. |
| 2963 |
;; esac |
| 2964 |
. |
| 2965 |
} |
| 2966 |
|
| 2967 |
pp_solaris_depend () { |
| 2968 |
typeset _name _vers |
| 2969 |
while read _name _vers; do |
| 2970 |
if test -n "$_name"; then |
| 2971 |
echo "P $_name $_name" |
| 2972 |
test -n "$_vers" && echo " $_vers" |
| 2973 |
fi |
| 2974 |
done |
| 2975 |
} |
| 2976 |
|
| 2977 |
pp_solaris_conflict () { |
| 2978 |
typeset _name _vers |
| 2979 |
while read _name _vers; do |
| 2980 |
if test -n "$_name"; then |
| 2981 |
echo "I $_name $_name" |
| 2982 |
test -n "$_vers" && echo " $_vers" |
| 2983 |
fi |
| 2984 |
done |
| 2985 |
} |
| 2986 |
|
| 2987 |
pp_solaris_space() { |
| 2988 |
echo "$2:$3:$1" >> $pp_wrkdir/space.cumulative |
| 2989 |
} |
| 2990 |
|
| 2991 |
pp_solaris_sum_space () { |
| 2992 |
if test -s $pp_wrkdir/space.cumulative; then |
| 2993 |
sort -t: +2 < $pp_wrkdir/space.cumulative | |
| 2994 |
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 |
| 2995 |
fi |
| 2996 |
} |
| 2997 |
|
| 2998 |
pp_solaris_proto () { |
| 2999 |
typeset t m o g f p st |
| 3000 |
typeset abi |
| 3001 |
|
| 3002 |
while read t m o g f p st; do |
| 3003 |
# Use Solaris default mode, owner and group if all unspecified |
| 3004 |
if test x"$m$o$g" = x"---"; then |
| 3005 |
m="?"; o="?"; g="?" |
| 3006 |
fi |
| 3007 |
test x"$o" = x"-" && o="root" |
| 3008 |
case "$t" in |
| 3009 |
f) test x"$g" = x"-" && g="bin" |
| 3010 |
test x"$m" = x"-" && m=444 |
| 3011 |
case "$f" in |
| 3012 |
*v*) echo "v $1 $p=$pp_destdir$p $m $o $g";; |
| 3013 |
*) echo "f $1 $p=$pp_destdir$p $m $o $g";; |
| 3014 |
esac |
| 3015 |
if test -r "$pp_destdir$p"; then |
| 3016 |
#-- Use file to record ABI types seen |
| 3017 |
case "`file "$pp_destdir$p"`" in |
| 3018 |
*"ELF 32"*80386*) abi=i386;; |
| 3019 |
*"ELF 64"*AMD*) abi=x86_64;; |
| 3020 |
*"ELF 32"*SPARC*) abi=sparc;; |
| 3021 |
*"ELF 64"*SPARC*) abi=sparc64;; |
| 3022 |
*) abi=;; |
| 3023 |
esac |
| 3024 |
if test -n "$abi"; then |
| 3025 |
pp_add_to_list pp_solaris_abis_seen $abi |
| 3026 |
fi |
| 3027 |
fi |
| 3028 |
;; |
| 3029 |
d) test x"$g" = x"-" && g="sys" |
| 3030 |
test x"$m" = x"-" && m=555 |
| 3031 |
echo "d $1 $p $m $o $g" |
| 3032 |
;; |
| 3033 |
s) test x"$g" = x"-" && g="bin" |
| 3034 |
test x"$m" = x"-" && m=777 |
| 3035 |
if test x"$m" != x"777" -a x"$m" != x"?"; then |
| 3036 |
pp_warn "$p: invalid mode $m for symlink, should be 777 or -" |
| 3037 |
fi |
| 3038 |
echo "s $1 $p=$st $m $o $g" |
| 3039 |
;; |
| 3040 |
esac |
| 3041 |
done |
| 3042 |
} |
| 3043 |
|
| 3044 |
pp_backend_solaris () { |
| 3045 |
typeset _cmp _svc _grp |
| 3046 |
|
| 3047 |
prototype=$pp_wrkdir/prototype |
| 3048 |
: > $prototype |
| 3049 |
|
| 3050 |
pkginfo=$pp_wrkdir/pkginfo |
| 3051 |
: > $pkginfo |
| 3052 |
echo "i pkginfo=$pkginfo" >> $prototype |
| 3053 |
|
| 3054 |
case "${pp_solaris_name:-$name}" in |
| 3055 |
[0-9]*) |
| 3056 |
pp_error "Package name '${pp_solaris_name:-$name}'" \ |
| 3057 |
"cannot start with a number" |
| 3058 |
;; |
| 3059 |
???????????????*) |
| 3060 |
pp_warn "Package name '${pp_solaris_name:-$name}'" \ |
| 3061 |
"too long for Solaris 2.6 or 2.7 (max 9 characters)" |
| 3062 |
;; |
| 3063 |
??????????*) |
| 3064 |
pp_warn "Package name '${pp_solaris_name:-$name}'" \ |
| 3065 |
"too long for 2.7 Solaris (max 9 characters)" |
| 3066 |
;; |
| 3067 |
esac |
| 3068 |
|
| 3069 |
#-- generate the package info file |
| 3070 |
echo "VERSION=$version" >> $pkginfo |
| 3071 |
echo "PKG=${pp_solaris_name:-$name}" >> $pkginfo |
| 3072 |
echo "CLASSES=$pp_components" >> $pkginfo |
| 3073 |
echo "BASEDIR=/" >> $pkginfo |
| 3074 |
echo "NAME=$name $version" >> $pkginfo |
| 3075 |
echo "CATEGORY=${pp_solaris_category:-application}" >> $pkginfo |
| 3076 |
|
| 3077 |
desc="${pp_solaris_desc:-$description}" |
| 3078 |
test -n "$desc" && |
| 3079 |
echo "DESC=$desc" >> $pkginfo |
| 3080 |
|
| 3081 |
test -n "$pp_solaris_rstates" && |
| 3082 |
echo "RSTATES=$pp_solaris_rstates" >> $pkginfo |
| 3083 |
test -n "$pp_solaris_istates" && |
| 3084 |
echo "ISTATES=$pp_solaris_istates" >> $pkginfo |
| 3085 |
test -n "$pp_solaris_maxinst" && |
| 3086 |
echo "MAXINST=$pp_solaris_maxinst" >> $pkginfo |
| 3087 |
test -n "${pp_solaris_vendor:-$vendor}" && |
| 3088 |
echo "VENDOR=${pp_solaris_vendor:-$vendor}" >> $pkginfo |
| 3089 |
test -n "$pp_solaris_pstamp" && |
| 3090 |
echo "PSTAMP=$pp_solaris_pstamp" >> $pkginfo |
| 3091 |
|
| 3092 |
if test -n "${pp_solaris_copyright:-$copyright}"; then |
| 3093 |
echo "${pp_solaris_copyright:-$copyright}" > $pp_wrkdir/copyright |
| 3094 |
echo "i copyright=$pp_wrkdir/copyright" >> $prototype |
| 3095 |
fi |
| 3096 |
|
| 3097 |
#-- scripts to run before and after install |
| 3098 |
: > $pp_wrkdir/postinstall |
| 3099 |
: > $pp_wrkdir/preremove |
| 3100 |
: > $pp_wrkdir/postremove |
| 3101 |
for _cmp in $pp_components; do |
| 3102 |
#-- add the preinstall scripts in definition order |
| 3103 |
if test -s $pp_wrkdir/%pre.$_cmp; then |
| 3104 |
pp_solaris_procedure $_cmp preinst < $pp_wrkdir/%pre.$_cmp \ |
| 3105 |
>> $pp_wrkdir/preinstall |
| 3106 |
fi |
| 3107 |
#-- add the postinstall scripts in definition order |
| 3108 |
if test -s $pp_wrkdir/%post.$_cmp; then |
| 3109 |
pp_solaris_procedure $_cmp postinst < $pp_wrkdir/%post.$_cmp \ |
| 3110 |
>> $pp_wrkdir/postinstall |
| 3111 |
fi |
| 3112 |
#-- add the preremove rules in reverse definition order |
| 3113 |
if test -s $pp_wrkdir/%preun.$_cmp; then |
| 3114 |
pp_solaris_procedure $_cmp preremove < $pp_wrkdir/%preun.$_cmp | |
| 3115 |
pp_prepend $pp_wrkdir/preremove |
| 3116 |
fi |
| 3117 |
#-- add the postremove scripts in definition order |
| 3118 |
if test -s $pp_wrkdir/%postun.$_cmp; then |
| 3119 |
pp_solaris_procedure $_cmp postremove < $pp_wrkdir/%postun.$_cmp \ |
| 3120 |
>> $pp_wrkdir/postremove |
| 3121 |
fi |
| 3122 |
#-- Add the check script in definition order |
| 3123 |
if test -s $pp_wrkdir/%check.$_cmp; then |
| 3124 |
pp_solaris_procedure $_cmp checkinstall \ |
| 3125 |
< $pp_wrkdir/%check.$_cmp \ |
| 3126 |
>> $pp_wrkdir/checkinstall |
| 3127 |
fi |
| 3128 |
#-- All dependencies and conflicts are merged together for Solaris pkgs |
| 3129 |
test -s $pp_wrkdir/%depend.$_cmp && |
| 3130 |
pp_solaris_depend < $pp_wrkdir/%depend.$_cmp >> $pp_wrkdir/depend |
| 3131 |
test -s $pp_wrkdir/%conflict.$_cmp && |
| 3132 |
pp_solaris_conflict < $pp_wrkdir/%conflict.$_cmp >> $pp_wrkdir/depend |
| 3133 |
done |
| 3134 |
|
| 3135 |
|
| 3136 |
if pp_solaris_is_request_script_necessary; then |
| 3137 |
pp_solaris_request > $pp_wrkdir/request |
| 3138 |
fi |
| 3139 |
|
| 3140 |
test -n "$pp_services" && |
| 3141 |
for _svc in $pp_services; do |
| 3142 |
pp_load_service_vars $_svc |
| 3143 |
pp_solaris_smf $_svc |
| 3144 |
pp_solaris_make_service $_svc |
| 3145 |
pp_solaris_install_service $_svc | pp_prepend $pp_wrkdir/postinstall |
| 3146 |
pp_solaris_remove_service $_svc | pp_prepend $pp_wrkdir/preremove |
| 3147 |
pp_solaris_remove_service $_svc | pp_prepend $pp_wrkdir/postremove |
| 3148 |
unset pp_svc_xml_file |
| 3149 |
done |
| 3150 |
|
| 3151 |
test -n "$pp_service_groups" && |
| 3152 |
for _grp in $pp_service_groups; do |
| 3153 |
pp_solaris_make_service_group \ |
| 3154 |
$_grp "`pp_service_get_svc_group $_grp`" |
| 3155 |
done |
| 3156 |
|
| 3157 |
#-- if installf was used; we need to indicate a termination |
| 3158 |
grep installf $pp_wrkdir/postinstall >/dev/null && |
| 3159 |
echo 'installf -f $PKGINST' >> $pp_wrkdir/postinstall |
| 3160 |
|
| 3161 |
pp_solaris_sum_space |
| 3162 |
|
| 3163 |
# NB: pkginfo and copyright are added earlier |
| 3164 |
for f in compver depend space checkinstall \ |
| 3165 |
preinstall request postinstall \ |
| 3166 |
preremove postremove; do |
| 3167 |
if test -s $pp_wrkdir/$f; then |
| 3168 |
case $f in |
| 3169 |
*install|*remove|request) |
| 3170 |
# turn scripts into a proper shell scripts |
| 3171 |
mv $pp_wrkdir/$f $pp_wrkdir/$f.tmp |
| 3172 |
{ echo "#!/bin/sh"; |
| 3173 |
echo "# $f script for ${pp_solaris_name:-$name}-$version" |
| 3174 |
cat $pp_wrkdir/$f.tmp |
| 3175 |
echo "exit 0"; } > $pp_wrkdir/$f |
| 3176 |
chmod +x $pp_wrkdir/$f |
| 3177 |
rm -f $pp_wrkdir/$f.tmp |
| 3178 |
;; |
| 3179 |
esac |
| 3180 |
if $pp_opt_debug; then |
| 3181 |
pp_debug "contents of $f:" |
| 3182 |
cat $pp_wrkdir/$f >&2 |
| 3183 |
fi |
| 3184 |
echo "i $f=$pp_wrkdir/$f" >> $prototype |
| 3185 |
fi |
| 3186 |
done |
| 3187 |
|
| 3188 |
#-- create the prototype file which lists the files to install |
| 3189 |
# do this as late as possible because files could be added |
| 3190 |
pp_solaris_abis_seen= |
| 3191 |
for _cmp in $pp_components; do |
| 3192 |
pp_solaris_proto $_cmp < $pp_wrkdir/%files.$_cmp |
| 3193 |
done >> $prototype |
| 3194 |
|
| 3195 |
if test x"$pp_solaris_package_arch" = x"auto"; then |
| 3196 |
if pp_contains "$pp_solaris_abis_seen" sparc64; then |
| 3197 |
pp_solaris_package_arch_std="sparc64" |
| 3198 |
echo "ARCH=sparcv9" >> $pkginfo |
| 3199 |
elif pp_contains "$pp_solaris_abis_seen" sparc; then |
| 3200 |
pp_solaris_package_arch_std="sparc" |
| 3201 |
echo "ARCH=sparc" >> $pkginfo |
| 3202 |
elif pp_contains "$pp_solaris_abis_seen" x86_64; then |
| 3203 |
pp_solaris_package_arch_std="x86_64" |
| 3204 |
echo "ARCH=amd64" >> $pkginfo |
| 3205 |
elif pp_contains "$pp_solaris_abis_seen" i386; then |
| 3206 |
pp_solaris_package_arch_std="i386" |
| 3207 |
echo "ARCH=i386" >> $pkginfo |
| 3208 |
else |
| 3209 |
pp_warn "No ELF files found: not supplying an ARCH type" |
| 3210 |
pp_solaris_package_arch_std="noarch" |
| 3211 |
fi |
| 3212 |
else |
| 3213 |
pp_solaris_package_arch_std="$pp_solaris_package_arch" |
| 3214 |
echo "ARCH=$pp_solaris_package_arch" >> $pkginfo |
| 3215 |
fi |
| 3216 |
|
| 3217 |
mkdir $pp_wrkdir/pkg |
| 3218 |
|
| 3219 |
. $pp_wrkdir/%fixup |
| 3220 |
|
| 3221 |
if $pp_opt_debug; then |
| 3222 |
echo "$pkginfo::"; cat $pkginfo |
| 3223 |
echo "$prototype::"; cat $prototype |
| 3224 |
fi >&2 |
| 3225 |
|
| 3226 |
pkgmk -d $pp_wrkdir/pkg -f $prototype \ |
| 3227 |
|| { error "pkgmk failed"; return; } |
| 3228 |
pkgtrans -s $pp_wrkdir/pkg \ |
| 3229 |
$pp_wrkdir/`pp_backend_solaris_names` \ |
| 3230 |
${pp_solaris_name:-$name} \ |
| 3231 |
|| { error "pkgtrans failed"; return; } |
| 3232 |
} |
| 3233 |
|
| 3234 |
pp_backend_solaris_cleanup () { |
| 3235 |
: |
| 3236 |
} |
| 3237 |
|
| 3238 |
pp_backend_solaris_names () { |
| 3239 |
echo ${pp_solaris_name:-$name}-$version-${pp_solaris_package_arch_std:-$pp_solaris_arch}.pkg |
| 3240 |
} |
| 3241 |
|
| 3242 |
pp_backend_solaris_install_script () { |
| 3243 |
typeset pkgname platform |
| 3244 |
|
| 3245 |
platform="${pp_solaris_os:-solaris}-${pp_solaris_package_arch_std:-$pp_solaris_arch}" |
| 3246 |
|
| 3247 |
echo "#! /sbin/sh" |
| 3248 |
pp_install_script_common |
| 3249 |
pkgname=`pp_backend_solaris_names` |
| 3250 |
|
| 3251 |
cat <<. |
| 3252 |
tmpnocheck=/tmp/nocheck\$\$ |
| 3253 |
tmpresponse=/tmp/response\$\$ |
| 3254 |
trap 'rm -f \$tmpnocheck \$tmpresponse' 0 |
| 3255 |
|
| 3256 |
make_tmpfiles () { |
| 3257 |
cat <<-.. > \$tmpresponse |
| 3258 |
CLASSES=\$* |
| 3259 |
SERVICES=$pp_services |
| 3260 |
.. |
| 3261 |
cat <<-.. > \$tmpnocheck |
| 3262 |
mail= |
| 3263 |
instance=overwrite |
| 3264 |
partial=nocheck |
| 3265 |
runlevel=nocheck |
| 3266 |
idepend=nocheck |
| 3267 |
rdepend=nocheck |
| 3268 |
space=nocheck |
| 3269 |
setuid=nocheck |
| 3270 |
conflict=nocheck |
| 3271 |
action=nocheck |
| 3272 |
basedir=default |
| 3273 |
.. |
| 3274 |
} |
| 3275 |
|
| 3276 |
test \$# -eq 0 && usage |
| 3277 |
op="\$1"; shift |
| 3278 |
|
| 3279 |
case "\$op" in |
| 3280 |
list-components) |
| 3281 |
test \$# -eq 0 || usage \$op |
| 3282 |
echo "$pp_components" |
| 3283 |
;; |
| 3284 |
list-services) |
| 3285 |
test \$# -eq 0 || usage \$op |
| 3286 |
echo "$pp_services" |
| 3287 |
;; |
| 3288 |
list-files) |
| 3289 |
test \$# -ge 1 || usage \$op |
| 3290 |
echo \${PP_PKGDESTDIR:-.}/$pkgname |
| 3291 |
;; |
| 3292 |
install) |
| 3293 |
test \$# -ge 1 || usage \$op |
| 3294 |
make_tmpfiles "\$@" |
| 3295 |
verbose /usr/sbin/pkgadd -n -d \${PP_PKGDESTDIR:-.}/$pkgname \ |
| 3296 |
-r \$tmpresponse \ |
| 3297 |
-a \$tmpnocheck \ |
| 3298 |
${pp_solaris_name:-$name} |
| 3299 |
;; |
| 3300 |
uninstall) |
| 3301 |
test \$# -ge 1 || usage \$op |
| 3302 |
make_tmpfiles "\$@" |
| 3303 |
verbose /usr/sbin/pkgrm -n \ |
| 3304 |
-a \$tmpnocheck \ |
| 3305 |
${pp_solaris_name:-$name} |
| 3306 |
;; |
| 3307 |
start|stop) |
| 3308 |
test \$# -ge 1 || usage \$op |
| 3309 |
ec=0 |
| 3310 |
for svc |
| 3311 |
do |
| 3312 |
verbose /etc/init.d/\$svc \$op || ec=1 |
| 3313 |
done |
| 3314 |
exit \$ec |
| 3315 |
;; |
| 3316 |
print-platform) |
| 3317 |
echo "$platform" |
| 3318 |
;; |
| 3319 |
*) |
| 3320 |
usage |
| 3321 |
;; |
| 3322 |
esac |
| 3323 |
. |
| 3324 |
} |
| 3325 |
|
| 3326 |
pp_solaris_dynlib_depend () { |
| 3327 |
xargs ldd 2>/dev/null | |
| 3328 |
sed -e '/^[^ ]*:$/d' -e 's,.*=>[ ]*,,' -e 's,^[ ]*,,' | |
| 3329 |
sort -u | |
| 3330 |
grep -v '^/usr/platform/' | ( |
| 3331 |
set -- ""; shift |
| 3332 |
while read p; do |
| 3333 |
set -- "$@" -p "$p" |
| 3334 |
if [ $# -gt 32 ]; then |
| 3335 |
echo "$# is $#" >&2 |
| 3336 |
pkgchk -l "$@" |
| 3337 |
set -- ""; shift |
| 3338 |
fi |
| 3339 |
done |
| 3340 |
[ $# -gt 0 ] && pkgchk -l "$@" |
| 3341 |
)| |
| 3342 |
awk '/^Current status:/{p=0} p==1 {print $1} /^Referenced by/ {p=1}' | |
| 3343 |
sort -u | |
| 3344 |
xargs -l32 pkginfo -x | |
| 3345 |
awk 'NR % 2 == 1 { name=$1; } NR%2 == 0 { print name, $2 }' |
| 3346 |
} |
| 3347 |
|
| 3348 |
pp_solaris_add_dynlib_depends () { |
| 3349 |
typeset tmp |
| 3350 |
tmp=$pp_wrkdir/tmp.dynlib |
| 3351 |
|
| 3352 |
for _cmp in $pp_components; do |
| 3353 |
awk '{print destdir $6}' destdir="$pp_destdir" \ |
| 3354 |
< $pp_wrkdir/%files.$_cmp | |
| 3355 |
pp_solaris_dynlib_depend > $tmp |
| 3356 |
if test -s $tmp; then |
| 3357 |
cat $tmp >> $pp_wrkdir/%depend.$_cmp |
| 3358 |
fi |
| 3359 |
rm -f $tmp |
| 3360 |
done |
| 3361 |
} |
| 3362 |
|
| 3363 |
pp_backend_solaris_probe () { |
| 3364 |
echo "${pp_solaris_os}-${pp_solaris_arch_std}" |
| 3365 |
} |
| 3366 |
|
| 3367 |
pp_backend_solaris_vas_platforms () { |
| 3368 |
case `pp_backend_solaris_probe` in |
| 3369 |
sol10-sparc* | sol9-sparc* | sol8-sparc*) |
| 3370 |
echo solaris8-sparc solaris7-sparc solaris26-sparc;; |
| 3371 |
sol7-sparc*) echo solaris7-sparc solaris26-sparc;; |
| 3372 |
sol26-sparc*) echo solaris26-sparc;; |
| 3373 |
sol8-*86) echo solaris8-x86;; |
| 3374 |
sol10-*86 | sol10-x86_64) |
| 3375 |
echo solaris10-x64 solaris8-x86;; |
| 3376 |
*) pp_die "unknown system `pp_backend_solaris_probe`";; |
| 3377 |
esac |
| 3378 |
} |
| 3379 |
pp_backend_solaris_function() { |
| 3380 |
case "$1" in |
| 3381 |
pp_mkgroup) cat<<'.';; |
| 3382 |
/usr/sbin/groupmod "$1" 2>/dev/null && return 0 |
| 3383 |
/usr/sbin/groupadd "$1" |
| 3384 |
. |
| 3385 |
pp_mkuser:depends) echo pp_mkgroup;; |
| 3386 |
pp_mkuser) cat<<'.';; |
| 3387 |
id "$1" >/dev/null 2>/dev/null && return 0 |
| 3388 |
pp_mkgroup "${2:-$1}" || return 1 |
| 3389 |
/usr/sbin/useradd \ |
| 3390 |
-g "${2:-$1}" \ |
| 3391 |
-d "${3:-/nonexistent}" \ |
| 3392 |
-s "${4:-/bin/false}" \ |
| 3393 |
"$1" |
| 3394 |
. |
| 3395 |
*) false;; |
| 3396 |
esac |
| 3397 |
} |
| 3398 |
|
| 3399 |
pp_backend_solaris_init_svc_vars () { |
| 3400 |
_smf_category=${pp_solaris_smf_category:-application} |
| 3401 |
_smf_method_envvar_name=${smf_method_envvar_name:-"PP_SMF_SERVICE"} |
| 3402 |
pp_solaris_service_shell=/sbin/sh |
| 3403 |
} |
| 3404 |
|
| 3405 |
pp_solaris_init_svc () { |
| 3406 |
smf_version=1 |
| 3407 |
smf_type=service |
| 3408 |
solaris_user= |
| 3409 |
solaris_stop_signal= |
| 3410 |
solaris_sysv_init_start=S70 # invocation order for start scripts |
| 3411 |
solaris_sysv_init_kill=K30 # invocation order for kill scripts |
| 3412 |
solaris_sysv_init_start_states="2" # states to install start link |
| 3413 |
solaris_sysv_init_kill_states="S 0 1" # states to install kill link |
| 3414 |
|
| 3415 |
# |
| 3416 |
# To have the service be installed to start automatically, |
| 3417 |
# %service foo |
| 3418 |
# solaris_sysv_init_start_states="S 0 1 2" |
| 3419 |
# |
| 3420 |
} |
| 3421 |
|
| 3422 |
pp_solaris_smf () { |
| 3423 |
typeset f _pp_solaris_service_script svc _pp_solaris_manpage |
| 3424 |
|
| 3425 |
pp_solaris_name=${pp_solaris_name:-$name} |
| 3426 |
pp_solaris_manpath=${pp_solaris_manpath:-"/usr/share/man"} |
| 3427 |
pp_solaris_mansect=${pp_solaris_mansect:-1} |
| 3428 |
smf_start_timeout=${smf_start_timeout:-60} |
| 3429 |
smf_stop_timeout=${smf_stop_timeout:-60} |
| 3430 |
smf_restart_timeout=${smf_restart_timeout:-60} |
| 3431 |
|
| 3432 |
svc=${pp_solaris_smf_service_name:-$1} |
| 3433 |
_pp_solaris_service_script=${pp_solaris_service_script:-"/etc/init.d/${pp_solaris_service_script_name:-$svc}"} |
| 3434 |
_pp_solaris_manpage=${pp_solaris_manpage:-$svc} |
| 3435 |
|
| 3436 |
if [ -z $pp_svc_xml_file ]; then |
| 3437 |
pp_svc_xml_file="/var/svc/manifest/$_smf_category/$svc.xml" |
| 3438 |
echo "## Generating the smf service manifest file for $pp_svc_xml_file" |
| 3439 |
else |
| 3440 |
echo "## SMF service manifest file already defined at $pp_svc_xml_file" |
| 3441 |
if [ -z $pp_solaris_smf_service_name ] || [ -z $pp_solaris_smf_category ] || [ -z $pp_solaris_service_script ] || [ -z $smf_method_envvar_name ]; then |
| 3442 |
pp_error "All required variables are not set.\n"\ |
| 3443 |
"When using a custom manifest file all of the following variables must be set:\n"\ |
| 3444 |
"pp_solaris_smf_service_name, pp_solaris_smf_category, pp_solaris_service_script and smf_method_envvar_name.\n\n"\ |
| 3445 |
"Example:\n"\ |
| 3446 |
" \$pp_solaris_smf_category=application\n"\ |
| 3447 |
" \$pp_solaris_smf_service_name=pp\n\n"\ |
| 3448 |
" <service name='application/pp' type='service' version='1'>\n\n"\ |
| 3449 |
"Example:\n"\ |
| 3450 |
" \$pp_solaris_service_script=/etc/init.d/pp\n\n"\ |
| 3451 |
" <exec_method type='method' name='start' exec='/etc/init.d/pp' />\n\n"\ |
| 3452 |
"Example:\n"\ |
| 3453 |
" \$smf_method_envvar_name=PP_SMF_SERVICE\n\n"\ |
| 3454 |
" <method_environment>\n"\ |
| 3455 |
" <envvar name='PP_SMF_SERVICE' value='1'/>\n"\ |
| 3456 |
" </method_environment>\n" |
| 3457 |
|
| 3458 |
return 1 |
| 3459 |
fi |
| 3460 |
return 0 |
| 3461 |
fi |
| 3462 |
|
| 3463 |
f=$pp_svc_xml_file |
| 3464 |
pp_add_file_if_missing $f || |
| 3465 |
return 0 |
| 3466 |
pp_solaris_add_parent_dirs "$f" |
| 3467 |
|
| 3468 |
_pp_solaris_smf_dependencies=" |
| 3469 |
<dependency name='pp_local_filesystems' |
| 3470 |
grouping='require_all' |
| 3471 |
restart_on='none' |
| 3472 |
type='service'> |
| 3473 |
<service_fmri value='svc:/system/filesystem/local'/> |
| 3474 |
</dependency> |
| 3475 |
|
| 3476 |
<dependency name='pp_single-user' |
| 3477 |
grouping='require_all' |
| 3478 |
restart_on='none' |
| 3479 |
type='service'> |
| 3480 |
<service_fmri value='svc:/milestone/single-user' /> |
| 3481 |
</dependency> |
| 3482 |
" |
| 3483 |
_pp_solaris_smf_dependencies=${pp_solaris_smf_dependencies:-$_pp_solaris_smf_dependencies} |
| 3484 |
|
| 3485 |
cat <<-. >$pp_destdir$f |
| 3486 |
<?xml version="1.0"?> |
| 3487 |
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'> |
| 3488 |
<!-- |
| 3489 |
$copyright |
| 3490 |
Generated by PolyPackage $pp_version |
| 3491 |
--> |
| 3492 |
|
| 3493 |
<service_bundle type='manifest' name='${pp_solaris_name}:${svc}' > |
| 3494 |
<service name='$_smf_category/$svc' |
| 3495 |
type='$smf_type' |
| 3496 |
version='$smf_version'> |
| 3497 |
|
| 3498 |
<create_default_instance enabled='false'/> |
| 3499 |
|
| 3500 |
<single_instance /> |
| 3501 |
|
| 3502 |
$_pp_solaris_smf_dependencies |
| 3503 |
|
| 3504 |
$pp_solaris_smf_additional_dependencies |
| 3505 |
|
| 3506 |
<method_context> |
| 3507 |
<method_credential user='${solaris_user:-$user}' /> |
| 3508 |
<method_environment> |
| 3509 |
<envvar name='$_smf_method_envvar_name' value='1'/> |
| 3510 |
</method_environment> |
| 3511 |
</method_context> |
| 3512 |
|
| 3513 |
<exec_method type='method' name='start' |
| 3514 |
exec='$_pp_solaris_service_script start' |
| 3515 |
timeout_seconds='$smf_start_timeout' /> |
| 3516 |
|
| 3517 |
<exec_method type='method' name='stop' |
| 3518 |
exec='$_pp_solaris_service_script stop' |
| 3519 |
timeout_seconds='$smf_stop_timeout' /> |
| 3520 |
|
| 3521 |
<exec_method type='method' name='restart' |
| 3522 |
exec='$_pp_solaris_service_script restart' |
| 3523 |
timeout_seconds='$smf_restart_timeout' /> |
| 3524 |
|
| 3525 |
$pp_solaris_smf_property_groups |
| 3526 |
|
| 3527 |
<template> |
| 3528 |
<common_name> |
| 3529 |
<loctext xml:lang='C'>$description</loctext> |
| 3530 |
</common_name> |
| 3531 |
<documentation> |
| 3532 |
<manpage title='$pp_solaris_manpage' section='$pp_solaris_mansect' manpath='$pp_solaris_manpath'/> |
| 3533 |
</documentation> |
| 3534 |
</template> |
| 3535 |
</service> |
| 3536 |
</service_bundle> |
| 3537 |
. |
| 3538 |
} |
| 3539 |
|
| 3540 |
pp_solaris_make_service_group () { |
| 3541 |
typeset group out file svcs svc |
| 3542 |
|
| 3543 |
group="$1" |
| 3544 |
svcs="$2" |
| 3545 |
file="/etc/init.d/$group" |
| 3546 |
out="$pp_destdir$file" |
| 3547 |
|
| 3548 |
#-- return if the script is supplied already |
| 3549 |
pp_add_file_if_missing "$file" run 755 || return 0 |
| 3550 |
pp_solaris_add_parent_dirs "$file" |
| 3551 |
|
| 3552 |
echo "#! /sbin/sh" > $out |
| 3553 |
echo "# polypkg service group script for these services:" >> $out |
| 3554 |
echo "svcs=\"$svcs\"" >> $out |
| 3555 |
|
| 3556 |
cat <<'.' >>$out |
| 3557 |
|
| 3558 |
#-- starts services in order.. stops them all if any break |
| 3559 |
pp_start () { |
| 3560 |
undo= |
| 3561 |
for svc in $svcs; do |
| 3562 |
if /etc/init.d/$svc start; then |
| 3563 |
undo="$svc $undo" |
| 3564 |
else |
| 3565 |
if test -n "$undo"; then |
| 3566 |
for svc in $undo; do |
| 3567 |
/etc/init.d/$svc stop |
| 3568 |
done |
| 3569 |
return 1 |
| 3570 |
fi |
| 3571 |
fi |
| 3572 |
done |
| 3573 |
return 0 |
| 3574 |
} |
| 3575 |
|
| 3576 |
#-- stops services in reverse |
| 3577 |
pp_stop () { |
| 3578 |
reverse= |
| 3579 |
for svc in $svcs; do |
| 3580 |
reverse="$svc $reverse" |
| 3581 |
done |
| 3582 |
rc=0 |
| 3583 |
for svc in $reverse; do |
| 3584 |
/etc/init.d/$svc stop || rc=$? |
| 3585 |
done |
| 3586 |
return $rc |
| 3587 |
} |
| 3588 |
|
| 3589 |
#-- returns true only if all services return true status |
| 3590 |
pp_status () { |
| 3591 |
rc=0 |
| 3592 |
for svc in $svcs; do |
| 3593 |
/etc/init.d/$svc status || rc=$? |
| 3594 |
done |
| 3595 |
return $rc |
| 3596 |
} |
| 3597 |
|
| 3598 |
case "$1" in |
| 3599 |
start) pp_start;; |
| 3600 |
stop) pp_stop;; |
| 3601 |
status) pp_status;; |
| 3602 |
restart) pp_stop && pp_start;; |
| 3603 |
*) echo "usage: $0 {start|stop|restart|status}" >&2; exit 1;; |
| 3604 |
esac |
| 3605 |
. |
| 3606 |
} |
| 3607 |
|
| 3608 |
pp_solaris_make_service () { |
| 3609 |
typeset file out svc |
| 3610 |
|
| 3611 |
svc="${pp_solaris_smf_service_name:-$1}" |
| 3612 |
file=${pp_solaris_service_script:-"/etc/init.d/${pp_solaris_service_script_name:-$svc}"} |
| 3613 |
out="$pp_destdir$file" |
| 3614 |
|
| 3615 |
#-- return if we don't need to create the init script |
| 3616 |
pp_add_file_if_missing "$file" run 755 || |
| 3617 |
return 0 |
| 3618 |
pp_solaris_add_parent_dirs "$file" |
| 3619 |
|
| 3620 |
echo "#! /sbin/sh" >$out |
| 3621 |
echo "#-- This service init file generated by polypkg" >>$out |
| 3622 |
|
| 3623 |
#-- Start SMF integration. |
| 3624 |
if [ -n "$pp_svc_xml_file" ] ; then |
| 3625 |
cat <<_EOF >>$out |
| 3626 |
if [ -x /usr/sbin/svcadm ] && [ "x\$1" != "xstatus" ] && [ "t\$$_smf_method_envvar_name" = "t" ] ; then |
| 3627 |
case "\$1" in |
| 3628 |
start) |
| 3629 |
echo "starting $svc" |
| 3630 |
/usr/sbin/svcadm clear svc:/$_smf_category/$svc:default >/dev/null 2>&1 |
| 3631 |
/usr/sbin/svcadm enable -s $_smf_category/$svc |
| 3632 |
RESULT=\$? |
| 3633 |
if [ "\$RESULT" -ne 0 ] ; then |
| 3634 |
echo "Error \$RESULT starting $svc" >&2 |
| 3635 |
fi |
| 3636 |
;; |
| 3637 |
stop) |
| 3638 |
echo "stopping $svc" |
| 3639 |
/usr/sbin/svcadm disable -ts $_smf_category/$svc |
| 3640 |
RESULT=0 |
| 3641 |
;; |
| 3642 |
restart) |
| 3643 |
echo "restarting $svc" |
| 3644 |
/usr/sbin/svcadm disable -ts $_smf_category/$svc |
| 3645 |
/usr/sbin/svcadm clear svc:/$_smf_category/$svc:default >/dev/null 2>&1 |
| 3646 |
/usr/sbin/svcadm enable -s $_smf_category/$svc |
| 3647 |
RESULT=\$? |
| 3648 |
if [ "\$RESULT" -ne 0 ] ; then |
| 3649 |
echo "Error \$RESULT starting $svc" >&2 |
| 3650 |
fi |
| 3651 |
;; |
| 3652 |
*) |
| 3653 |
echo "Usage: $file {start|stop|restart|status}" >&2 |
| 3654 |
RESULT=1 |
| 3655 |
esac |
| 3656 |
exit $RESULT |
| 3657 |
fi |
| 3658 |
_EOF |
| 3659 |
fi |
| 3660 |
|
| 3661 |
#-- Construct a start command that builds a pid file as needed |
| 3662 |
# and forks the daemon. Services started by smf may not fork. |
| 3663 |
if test -z "$pidfile"; then |
| 3664 |
# The service does not define a pidfile, so we have to make |
| 3665 |
# our own up. On Solaris systems where there is no /var/run |
| 3666 |
# we must use /tmp to guarantee the pid files are removed after |
| 3667 |
# a system crash. |
| 3668 |
if test -z "$pp_piddir"; then |
| 3669 |
pp_piddir="/var/run" |
| 3670 |
fi |
| 3671 |
cat <<. >>$out |
| 3672 |
pp_isdaemon=0 |
| 3673 |
pp_piddirs="${pp_piddir}${pp_piddir+ }/var/run /tmp" |
| 3674 |
for pp_piddir in \$pp_piddirs; do |
| 3675 |
test -d "\$pp_piddir/." && break |
| 3676 |
done |
| 3677 |
pidfile="\$pp_piddir/$svc.pid" |
| 3678 |
. |
| 3679 |
else |
| 3680 |
# The service is able to write its own PID file |
| 3681 |
cat <<. >>$out |
| 3682 |
pp_isdaemon=1 |
| 3683 |
pidfile="$pidfile" |
| 3684 |
. |
| 3685 |
fi |
| 3686 |
|
| 3687 |
pp_su= |
| 3688 |
if test "${user:-root}" != "root"; then |
| 3689 |
pp_su="su $user -c exec " |
| 3690 |
fi |
| 3691 |
|
| 3692 |
cat <<. >>$out |
| 3693 |
stop_signal="${stop_signal:-TERM}" |
| 3694 |
svc="${svc}" |
| 3695 |
|
| 3696 |
# generated command to run $svc as a service |
| 3697 |
pp_exec () { |
| 3698 |
if [ \$pp_isdaemon -ne 1 ]; then |
| 3699 |
if [ "t\$PP_SMF_SERVICE" = "t" ]; then |
| 3700 |
${pp_su}$cmd & |
| 3701 |
echo \$! > \$pidfile |
| 3702 |
else |
| 3703 |
echo "via exec." |
| 3704 |
echo \$$ > \$pidfile |
| 3705 |
exec ${pp_su}$cmd |
| 3706 |
return 1 |
| 3707 |
fi |
| 3708 |
else |
| 3709 |
${pp_su}$cmd |
| 3710 |
fi |
| 3711 |
} |
| 3712 |
. |
| 3713 |
|
| 3714 |
#-- write the invariant section of the init script |
| 3715 |
cat <<'.' >>$out |
| 3716 |
|
| 3717 |
# returns true if $svc is running |
| 3718 |
pp_running () { |
| 3719 |
if test -s "$pidfile"; then |
| 3720 |
read pid < "$pidfile" 2>/dev/null |
| 3721 |
if test ${pid:-0} -gt 1 && kill -0 "$pid" 2>/dev/null; then |
| 3722 |
# make sure command name matches up to the first 8 chars |
| 3723 |
c="`echo $cmd | sed -e 's: .*::' -e 's:^.*/::' -e 's/^\(........\).*$/\1/'`" |
| 3724 |
pid="`ps -p $pid 2>/dev/null | sed -n \"s/^ *\($pid\) .*$c *$/\1/p\"`" |
| 3725 |
if test -n "$pid"; then |
| 3726 |
return 0 |
| 3727 |
fi |
| 3728 |
fi |
| 3729 |
fi |
| 3730 |
return 1 |
| 3731 |
} |
| 3732 |
|
| 3733 |
# prints a message describing $svc's running state |
| 3734 |
pp_status () { |
| 3735 |
if pp_running; then |
| 3736 |
echo "service $svc is running (pid $pid)" |
| 3737 |
return 0 |
| 3738 |
elif test -f "$pidfile"; then |
| 3739 |
echo "service $svc is not running, but pid file exists" |
| 3740 |
return 2 |
| 3741 |
else |
| 3742 |
echo "service $svc is not running" |
| 3743 |
return 1 |
| 3744 |
fi |
| 3745 |
} |
| 3746 |
|
| 3747 |
# starts $svc |
| 3748 |
pp_start () { |
| 3749 |
if pp_running; then |
| 3750 |
echo "service $svc already running" >&2 |
| 3751 |
return 0 |
| 3752 |
fi |
| 3753 |
echo "starting $svc... \c" |
| 3754 |
if pp_exec; then |
| 3755 |
echo "done." |
| 3756 |
else |
| 3757 |
echo "ERROR." |
| 3758 |
exit 1 |
| 3759 |
fi |
| 3760 |
} |
| 3761 |
|
| 3762 |
# stops $svc |
| 3763 |
pp_stop () { |
| 3764 |
if pp_running; then |
| 3765 |
echo "stopping $svc... \c" |
| 3766 |
if kill -$stop_signal $pid; then |
| 3767 |
rm -f "$pidfile" |
| 3768 |
echo "done." |
| 3769 |
else |
| 3770 |
echo "ERROR." |
| 3771 |
return 1 |
| 3772 |
fi |
| 3773 |
else |
| 3774 |
echo "service $svc already stopped" >&2 |
| 3775 |
return 0 |
| 3776 |
fi |
| 3777 |
} |
| 3778 |
|
| 3779 |
umask 022 |
| 3780 |
case "$1" in |
| 3781 |
start) pp_start;; |
| 3782 |
stop) pp_stop;; |
| 3783 |
status) pp_status;; |
| 3784 |
restart) pp_stop && pp_start;; |
| 3785 |
*) echo "usage: $0 {start|stop|restart|status}" >&2; exit 1;; |
| 3786 |
esac |
| 3787 |
. |
| 3788 |
} |
| 3789 |
|
| 3790 |
pp_solaris_remove_service () { |
| 3791 |
typeset file svc |
| 3792 |
|
| 3793 |
svc="${pp_solaris_smf_service_name:-$1}" |
| 3794 |
file=${pp_solaris_service_script:-"/etc/init.d/${pp_solaris_service_script_name:-$svc}"} |
| 3795 |
|
| 3796 |
echo ' |
| 3797 |
if [ "x${PKG_INSTALL_ROOT}" = 'x' ]; then |
| 3798 |
if [ -x /usr/sbin/svcadm ] ; then |
| 3799 |
/usr/sbin/svcadm disable -s '$svc' 2>/dev/null |
| 3800 |
if [ `uname -r` = 5.10 ] || [ "'${pp_svc_xml_file%/*/*}'" != "/var/svc/manifest" ]; then |
| 3801 |
/usr/sbin/svccfg delete '$svc' 2>/dev/null |
| 3802 |
else |
| 3803 |
/usr/sbin/svcadm restart manifest-import 2>/dev/null |
| 3804 |
fi |
| 3805 |
else |
| 3806 |
'$file' stop >/dev/null 2>/dev/null |
| 3807 |
fi |
| 3808 |
fi |
| 3809 |
' |
| 3810 |
} |
| 3811 |
|
| 3812 |
pp_solaris_install_service () { |
| 3813 |
typeset s k l file svc |
| 3814 |
|
| 3815 |
svc="${pp_solaris_smf_service_name:-$1}" |
| 3816 |
file=${pp_solaris_service_script:-"/etc/init.d/${pp_solaris_service_script_name:-$svc}"} |
| 3817 |
|
| 3818 |
s="${solaris_sysv_init_start}$svc" |
| 3819 |
k="${solaris_sysv_init_kill}$svc" |
| 3820 |
|
| 3821 |
echo ' |
| 3822 |
if [ "x${PKG_INSTALL_ROOT}" != "x" ]; then |
| 3823 |
if [ -x ${PKG_INSTALL_ROOT}/usr/sbin/svcadm ]; then |
| 3824 |
if [ `uname -r` = 5.10 ] || [ "'${pp_svc_xml_file%/*/*}'" != "/var/svc/manifest" ]; then |
| 3825 |
echo "/usr/sbin/svccfg import '$pp_svc_xml_file' 2>/dev/null" >> ${PKG_INSTALL_ROOT}/var/svc/profile/upgrade |
| 3826 |
else |
| 3827 |
echo "/usr/sbin/svcadm restart manifest-import 2>/dev/null" >> ${PKG_INSTALL_ROOT}/var/svc/profile/upgrade |
| 3828 |
fi |
| 3829 |
else' |
| 3830 |
test -n "${solaris_sysv_init_start_states}" && |
| 3831 |
for state in ${solaris_sysv_init_start_states}; do |
| 3832 |
l="/etc/rc$state.d/$s" |
| 3833 |
echo "echo '$l'" |
| 3834 |
echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=$file s" |
| 3835 |
pp_solaris_space /etc/rc$state.d 0 1 |
| 3836 |
done |
| 3837 |
test -n "${solaris_sysv_init_kill_states}" && |
| 3838 |
for state in ${solaris_sysv_init_kill_states}; do |
| 3839 |
l="/etc/rc$state.d/$k" |
| 3840 |
echo "echo '$l'" |
| 3841 |
echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=$file s" |
| 3842 |
pp_solaris_space /etc/rc$state.d 0 1 |
| 3843 |
done |
| 3844 |
echo ' |
| 3845 |
fi |
| 3846 |
else |
| 3847 |
if [ -x /usr/sbin/svcadm ]; then |
| 3848 |
echo "Registering '$svc' with SMF" |
| 3849 |
/usr/sbin/svcadm disable -s '$svc' 2>/dev/null |
| 3850 |
if [ `uname -r` = 5.10 ] || [ "'${pp_svc_xml_file%/*/*}'" != "/var/svc/manifest" ]; then |
| 3851 |
/usr/sbin/svccfg delete '$svc' 2>/dev/null |
| 3852 |
/usr/sbin/svccfg import '$pp_svc_xml_file' |
| 3853 |
else |
| 3854 |
/usr/sbin/svcadm restart manifest-import |
| 3855 |
# Wait for import to complete, otherwise it will not know |
| 3856 |
# about our service until after we try to start it |
| 3857 |
echo Waiting for manifest-import... |
| 3858 |
typeset waited |
| 3859 |
waited=0 |
| 3860 |
while [ $waited -lt 15 ] && ! /usr/bin/svcs -l '$svc' >/dev/null 2>&1; do |
| 3861 |
sleep 1 |
| 3862 |
waited=`expr $waited + 1` |
| 3863 |
done |
| 3864 |
if /usr/bin/svcs -l '$svc' >/dev/null 2>&1; then |
| 3865 |
echo OK |
| 3866 |
else |
| 3867 |
echo manifest-import took to long, you might have to control '$svc' manually. |
| 3868 |
fi |
| 3869 |
fi |
| 3870 |
else' |
| 3871 |
test -n "${solaris_sysv_init_start_states}" && |
| 3872 |
for state in ${solaris_sysv_init_start_states}; do |
| 3873 |
l="/etc/rc$state.d/$s" |
| 3874 |
echo "echo '$l'" |
| 3875 |
echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=$file s" |
| 3876 |
pp_solaris_space /etc/rc$state.d 0 1 |
| 3877 |
done |
| 3878 |
test -n "${solaris_sysv_init_kill_states}" && |
| 3879 |
for state in ${solaris_sysv_init_kill_states}; do |
| 3880 |
l="/etc/rc$state.d/$k" |
| 3881 |
echo "echo '$l'" |
| 3882 |
echo "installf -c run \$PKGINST \$PKG_INSTALL_ROOT$l=$file s" |
| 3883 |
pp_solaris_space /etc/rc$state.d 0 1 |
| 3884 |
done |
| 3885 |
echo ' |
| 3886 |
fi |
| 3887 |
fi' |
| 3888 |
} |
| 3889 |
|
| 3890 |
pp_solaris_add_parent_dirs () { |
| 3891 |
typeset dir |
| 3892 |
|
| 3893 |
dir=${1%/*} |
| 3894 |
while test -n "$dir"; do |
| 3895 |
if awk "\$6 == \"$dir/\" {exit 1}" < $pp_wrkdir/%files.run; then |
| 3896 |
echo "d - - - - $dir/" >> $pp_wrkdir/%files.run |
| 3897 |
fi |
| 3898 |
dir=${dir%/*} |
| 3899 |
done |
| 3900 |
} |
| 3901 |
|
| 3902 |
pp_platforms="$pp_platforms deb" |
| 3903 |
|
| 3904 |
pp_backend_deb_detect () { |
| 3905 |
test -f /etc/debian_version |
| 3906 |
} |
| 3907 |
|
| 3908 |
pp_deb_cmp_full_name () { |
| 3909 |
local prefix |
| 3910 |
prefix="${pp_deb_name:-$name}" |
| 3911 |
case "$1" in |
| 3912 |
run) echo "${prefix}" ;; |
| 3913 |
dbg) echo "${prefix}-${pp_deb_dbg_pkgname}";; |
| 3914 |
dev) echo "${prefix}-${pp_deb_dev_pkgname}";; |
| 3915 |
doc) echo "${prefix}-${pp_deb_doc_pkgname}";; |
| 3916 |
*) pp_error "unknown component '$1'"; |
| 3917 |
esac |
| 3918 |
} |
| 3919 |
|
| 3920 |
pp_backend_deb_init () { |
| 3921 |
pp_deb_dpkg_version="2.0" |
| 3922 |
pp_deb_name= |
| 3923 |
pp_deb_version= |
| 3924 |
pp_deb_release= |
| 3925 |
pp_deb_arch= |
| 3926 |
pp_deb_arch_std= |
| 3927 |
pp_deb_maintainer="One Identity LLC <[email protected]>" |
| 3928 |
pp_deb_copyright= |
| 3929 |
pp_deb_distro= |
| 3930 |
pp_deb_control_description= |
| 3931 |
pp_deb_summary= |
| 3932 |
pp_deb_description= |
| 3933 |
pp_deb_dbg_pkgname="dbg" |
| 3934 |
pp_deb_dev_pkgname="dev" |
| 3935 |
pp_deb_doc_pkgname="doc" |
| 3936 |
pp_deb_section=contrib # Free software that depends on non-free software |
| 3937 |
|
| 3938 |
# Detect the host architecture |
| 3939 |
pp_deb_detect_arch |
| 3940 |
|
| 3941 |
# Make sure any programs we require are installed |
| 3942 |
pp_deb_check_required_programs |
| 3943 |
} |
| 3944 |
|
| 3945 |
pp_deb_check_required_programs () { |
| 3946 |
local p needed notfound ok |
| 3947 |
needed= notfound= |
| 3948 |
for prog in dpkg dpkg-deb install md5sum fakeroot |
| 3949 |
do |
| 3950 |
if command -v $prog 2>/dev/null >/dev/null; then |
| 3951 |
pp_debug "$prog: found" |
| 3952 |
else |
| 3953 |
pp_debug "$prog: not found" |
| 3954 |
case "$prog" in |
| 3955 |
dpkg|dpkg-deb) p=dpkg;; |
| 3956 |
install|md5sum) p=coreutils;; |
| 3957 |
fakeroot) p=fakeroot;; |
| 3958 |
*) pp_die "unexpected dpkg tool $prog";; |
| 3959 |
esac |
| 3960 |
notfound="$notfound $prog" |
| 3961 |
pp_contains "$needed" "$p" || needed="$needed $p" |
| 3962 |
fi |
| 3963 |
done |
| 3964 |
if [ -n "$notfound" ]; then |
| 3965 |
pp_error "cannot find these programs: $notfound" |
| 3966 |
pp_error "please install these packages: $needed" |
| 3967 |
fi |
| 3968 |
} |
| 3969 |
|
| 3970 |
pp_deb_munge_description () { |
| 3971 |
# Insert a leading space on each line, replace blank lines with a |
| 3972 |
#space followed by a full-stop. |
| 3973 |
pp_deb_control_description="`echo ${pp_deb_description:-$description} | \ |
| 3974 |
sed 's,^\(.*\)$, \1, ' | sed 's,^[ \t]*$, .,g' | fmt -w 80`" |
| 3975 |
} |
| 3976 |
|
| 3977 |
pp_deb_detect_arch () { |
| 3978 |
pp_deb_arch=`dpkg-architecture -qDEB_HOST_ARCH` |
| 3979 |
pp_deb_arch_std=`uname -m` |
| 3980 |
} |
| 3981 |
|
| 3982 |
pp_deb_sanitize_version() { |
| 3983 |
echo "$@" | tr -d -c '[:alnum:].+-:~' |
| 3984 |
} |
| 3985 |
|
| 3986 |
pp_deb_version_final() { |
| 3987 |
if test -n "$pp_deb_version"; then |
| 3988 |
# Don't sanitize; assume the user is sane (hah!) |
| 3989 |
echo "$pp_deb_version" |
| 3990 |
else |
| 3991 |
pp_deb_sanitize_version "$version" |
| 3992 |
fi |
| 3993 |
} |
| 3994 |
|
| 3995 |
pp_deb_conflict () { |
| 3996 |
local _name _vers _conflicts |
| 3997 |
|
| 3998 |
_conflicts="Conflicts:" |
| 3999 |
while read _name _vers; do |
| 4000 |
case "$_name" in ""| "#"*) continue ;; esac |
| 4001 |
_conflicts="$_conflicts $_name" |
| 4002 |
test -n "$_vers" && _conflicts="$_conflicts $_name (>= $vers)" |
| 4003 |
_conflicts="${_conflicts}," |
| 4004 |
done |
| 4005 |
echo "${_conflicts%,}" |
| 4006 |
} |
| 4007 |
|
| 4008 |
pp_deb_make_control() { |
| 4009 |
local cmp="$1" |
| 4010 |
local installed_size |
| 4011 |
|
| 4012 |
# compute the installed size |
| 4013 |
installed_size=`pp_deb_files_size < $pp_wrkdir/%files.$cmp` |
| 4014 |
|
| 4015 |
package_name=`pp_deb_cmp_full_name "$cmp"` |
| 4016 |
cat <<-. |
| 4017 |
Package: ${package_name} |
| 4018 |
Version: `pp_deb_version_final`-${pp_deb_release:-1} |
| 4019 |
Section: ${pp_deb_section:-contrib} |
| 4020 |
Priority: optional |
| 4021 |
Architecture: ${pp_deb_arch} |
| 4022 |
Maintainer: ${pp_deb_maintainer:-$maintainer} |
| 4023 |
Description: ${pp_deb_summary:-$summary} |
| 4024 |
${pp_deb_control_description} |
| 4025 |
Installed-Size: ${installed_size} |
| 4026 |
. |
| 4027 |
if test -s $pp_wrkdir/%depend."$cmp"; then |
| 4028 |
sed -ne '/^[ ]*$/!s/^[ ]*/Depends: /p' \ |
| 4029 |
< $pp_wrkdir/%depend."$cmp" |
| 4030 |
fi |
| 4031 |
if test -s $pp_wrkdir/%conflict."$cmp"; then |
| 4032 |
pp_deb_conflict < $pp_wrkdir/%conflict."$cmp" |
| 4033 |
fi |
| 4034 |
} |
| 4035 |
|
| 4036 |
pp_deb_make_md5sums() { |
| 4037 |
local cmp="$1"; shift |
| 4038 |
local pkg_dir |
| 4039 |
|
| 4040 |
pkg_dir=$pp_wrkdir/`pp_deb_cmp_full_name $cmp` |
| 4041 |
(cd $pkg_dir && md5sum "$@") > $pkg_dir/DEBIAN/md5sums || |
| 4042 |
pp_error "cannot make md5sums" |
| 4043 |
} |
| 4044 |
|
| 4045 |
pp_deb_make_package_maintainer_script() { |
| 4046 |
local output="$1" |
| 4047 |
local source="$2" |
| 4048 |
local desc="$3" |
| 4049 |
|
| 4050 |
# See if we need to create this script at all |
| 4051 |
if [ -s "$source" ] |
| 4052 |
then |
| 4053 |
|
| 4054 |
# Create header |
| 4055 |
cat <<-. >$output || pp_error "Cannot create $output" |
| 4056 |
#!/bin/sh |
| 4057 |
# $desc |
| 4058 |
# Generated by PolyPackage $pp_version |
| 4059 |
|
| 4060 |
. |
| 4061 |
|
| 4062 |
cat $source >> "$output" || pp_error "Cannot append to $output" |
| 4063 |
|
| 4064 |
# Set perms |
| 4065 |
chmod 755 "$output" || pp_error "Cannot chmod $output" |
| 4066 |
fi |
| 4067 |
} |
| 4068 |
|
| 4069 |
pp_deb_handle_services() { |
| 4070 |
local svc |
| 4071 |
|
| 4072 |
#-- add service start/stop code |
| 4073 |
if test -n "$pp_services"; then |
| 4074 |
#-- append common %post install code |
| 4075 |
pp_systemd_service_install_common >> $pp_wrkdir/%post.run |
| 4076 |
|
| 4077 |
#-- record the uninstall commands in reverse order |
| 4078 |
for svc in $pp_services; do |
| 4079 |
pp_load_service_vars $svc |
| 4080 |
|
| 4081 |
# Create init script and systemd service file (unless they exists) |
| 4082 |
pp_deb_service_make_service_files $svc || |
| 4083 |
pp_error "could not create service files for $svc" |
| 4084 |
|
| 4085 |
#-- append %post code to install the svc |
| 4086 |
test x"yes" = x"$enable" && |
| 4087 |
cat<<-. >> $pp_wrkdir/%post.run |
| 4088 |
|
| 4089 |
case "\$1" in |
| 4090 |
configure) |
| 4091 |
# Install the service links |
| 4092 |
_pp_systemd_init |
| 4093 |
if test -n "\$systemctl_cmd"; then |
| 4094 |
_pp_systemd_install $svc |
| 4095 |
_pp_systemd_enable $svc |
| 4096 |
else |
| 4097 |
update-rc.d $svc defaults |
| 4098 |
fi |
| 4099 |
;; |
| 4100 |
esac |
| 4101 |
. |
| 4102 |
|
| 4103 |
#-- prepend %preun code to stop svc |
| 4104 |
cat<<-. | pp_prepend $pp_wrkdir/%preun.run |
| 4105 |
|
| 4106 |
case "\$1" in |
| 4107 |
remove|deconfigure|upgrade) |
| 4108 |
# Stop the $svc service |
| 4109 |
invoke-rc.d $svc stop |
| 4110 |
_pp_systemd_disable $svc |
| 4111 |
;; |
| 4112 |
esac |
| 4113 |
. |
| 4114 |
|
| 4115 |
#-- prepend %postun code to remove service |
| 4116 |
cat<<-. | pp_prepend $pp_wrkdir/%postun.run |
| 4117 |
|
| 4118 |
case "\$1" in |
| 4119 |
purge) |
| 4120 |
# Remove the service links |
| 4121 |
update-rc.d $svc remove |
| 4122 |
_pp_systemd_remove $svc |
| 4123 |
;; |
| 4124 |
esac |
| 4125 |
. |
| 4126 |
done |
| 4127 |
|
| 4128 |
pp_systemd_service_remove_common | pp_prepend $pp_wrkdir/%preun.run |
| 4129 |
#pp_deb_service_remove_common | pp_prepend $pp_wrkdir/%preun.run |
| 4130 |
|
| 4131 |
# Actual systemd service removal is done in %postun. |
| 4132 |
# Otherwise, systemd may pick up the init.d script if it exists. |
| 4133 |
pp_systemd_service_remove_common | pp_prepend $pp_wrkdir/%postun.run |
| 4134 |
fi |
| 4135 |
|
| 4136 |
} |
| 4137 |
pp_deb_fakeroot () { |
| 4138 |
if test -s $pp_wrkdir/fakeroot.save; then |
| 4139 |
fakeroot -i $pp_wrkdir/fakeroot.save -s $pp_wrkdir/fakeroot.save "$@" |
| 4140 |
else |
| 4141 |
fakeroot -s $pp_wrkdir/fakeroot.save "$@" |
| 4142 |
fi |
| 4143 |
} |
| 4144 |
|
| 4145 |
pp_deb_files_size () { |
| 4146 |
local t m o g f p st |
| 4147 |
while read t m o g f p st; do |
| 4148 |
case $t in |
| 4149 |
f|s) du -k "${pp_destdir}$p";; |
| 4150 |
d) echo 4;; |
| 4151 |
esac |
| 4152 |
done | awk '{n+=$1} END {print n}' |
| 4153 |
} |
| 4154 |
|
| 4155 |
pp_deb_make_DEBIAN() { |
| 4156 |
local cmp="${1:-run}" |
| 4157 |
local data cmp_full_name |
| 4158 |
local old_umask |
| 4159 |
|
| 4160 |
old_umask=`umask` |
| 4161 |
umask 0022 |
| 4162 |
cmp_full_name=`pp_deb_cmp_full_name $cmp` |
| 4163 |
data=$pp_wrkdir/$cmp_full_name |
| 4164 |
|
| 4165 |
# Create DEBIAN dir $data/DEBIAN |
| 4166 |
mkdir -p $data/DEBIAN |
| 4167 |
|
| 4168 |
# Create control file |
| 4169 |
pp_deb_make_control $cmp > $data/DEBIAN/control |
| 4170 |
|
| 4171 |
# Copy in conffiles |
| 4172 |
if test -f $pp_wrkdir/%conffiles.$cmp; then |
| 4173 |
cp $pp_wrkdir/%conffiles.$cmp $data/DEBIAN/conffiles |
| 4174 |
fi |
| 4175 |
|
| 4176 |
# Create preinst |
| 4177 |
pp_deb_make_package_maintainer_script "$data/DEBIAN/preinst" \ |
| 4178 |
"$pp_wrkdir/%pre.$cmp" "Pre-install script for $cmp_full_name"\ |
| 4179 |
|| exit $? |
| 4180 |
|
| 4181 |
# Create postinst |
| 4182 |
pp_deb_make_package_maintainer_script "$data/DEBIAN/postinst" \ |
| 4183 |
"$pp_wrkdir/%post.$cmp" "Post-install script for $cmp_full_name"\ |
| 4184 |
|| exit $? |
| 4185 |
|
| 4186 |
# Create prerm |
| 4187 |
pp_deb_make_package_maintainer_script "$data/DEBIAN/prerm" \ |
| 4188 |
"$pp_wrkdir/%preun.$cmp" "Pre-uninstall script for $cmp_full_name"\ |
| 4189 |
|| exit $? |
| 4190 |
|
| 4191 |
# Create postrm |
| 4192 |
pp_deb_make_package_maintainer_script "$data/DEBIAN/postrm" \ |
| 4193 |
"$pp_wrkdir/%postun.$cmp" "Post-uninstall script for $cmp_full_name"\ |
| 4194 |
|| exit $? |
| 4195 |
|
| 4196 |
umask $old_umask |
| 4197 |
} |
| 4198 |
|
| 4199 |
pp_deb_make_data() { |
| 4200 |
local _l t m o g f p st data |
| 4201 |
local data share_doc owner group |
| 4202 |
cmp=$1 |
| 4203 |
data=$pp_wrkdir/`pp_deb_cmp_full_name $cmp` |
| 4204 |
cat $pp_wrkdir/%files.${cmp} | while read t m o g f p st; do |
| 4205 |
if test x"$m" = x"-"; then |
| 4206 |
case "$t" in |
| 4207 |
d) m=755;; |
| 4208 |
f) m=644;; |
| 4209 |
esac |
| 4210 |
fi |
| 4211 |
test x"$o" = x"-" && o=root |
| 4212 |
test x"$g" = x"-" && g=root |
| 4213 |
case "$t" in |
| 4214 |
f) # Files |
| 4215 |
pp_deb_fakeroot install -D -o $o -g $g -m ${m} $pp_destdir/$p $data/$p; |
| 4216 |
case "$f" in |
| 4217 |
*v*) |
| 4218 |
# File marked as "volatile". Assume this means it's a conffile |
| 4219 |
# TODO: check this as admins like modified conffiles to be left |
| 4220 |
# behind |
| 4221 |
echo "$p" >> $pp_wrkdir/%conffiles.$cmp |
| 4222 |
;; |
| 4223 |
esac |
| 4224 |
;; |
| 4225 |
|
| 4226 |
d) # Directories |
| 4227 |
pp_deb_fakeroot install -m ${m} -o $o -g $g -d $data/$p;; |
| 4228 |
|
| 4229 |
s) # Symlinks |
| 4230 |
# Remove leading / from vars |
| 4231 |
rel_p=`echo $p | sed s,^/,,` |
| 4232 |
rel_st=`echo $st | sed s,^/,,` |
| 4233 |
# TODO: we are always doing absolute links here. We should follow |
| 4234 |
# the debian policy of relative links when in the same top-level |
| 4235 |
# directory |
| 4236 |
(cd $data; ln -sf $st $rel_p);; |
| 4237 |
*) pp_error "Unsupported data file type: $t";; |
| 4238 |
esac |
| 4239 |
done |
| 4240 |
|
| 4241 |
# If no copyright file is present add one. This is a debian requirement. |
| 4242 |
share_doc="/usr/share/doc/`pp_deb_cmp_full_name $cmp`" |
| 4243 |
if [ ! -f "$data/$share_doc/copyright" ] |
| 4244 |
then |
| 4245 |
echo "${pp_deb_copyright:-$copyright}" > "$pp_wrkdir/copyright" |
| 4246 |
install -D -m 644 "$pp_wrkdir/copyright" "$data/$share_doc/copyright" |
| 4247 |
fi |
| 4248 |
|
| 4249 |
} |
| 4250 |
|
| 4251 |
pp_deb_makedeb () { |
| 4252 |
local cmp |
| 4253 |
local package_build_dir |
| 4254 |
|
| 4255 |
cmp="$1" |
| 4256 |
|
| 4257 |
package_build_dir=$pp_wrkdir/`pp_deb_cmp_full_name $cmp` |
| 4258 |
|
| 4259 |
# Create package dir |
| 4260 |
mkdir -p $package_build_dir |
| 4261 |
|
| 4262 |
# Copy in data |
| 4263 |
pp_deb_make_data $cmp || |
| 4264 |
pp_die "Could not make DEBIAN data files for $cmp" |
| 4265 |
|
| 4266 |
# Make control files |
| 4267 |
# must be done after copying data so conffiles are found |
| 4268 |
pp_deb_make_DEBIAN $cmp || |
| 4269 |
pp_die "Could not make DEBIAN control files for $cmp" |
| 4270 |
|
| 4271 |
# Create md5sums |
| 4272 |
pp_deb_make_md5sums $cmp `(cd $package_build_dir; |
| 4273 |
find . -name DEBIAN -prune -o -type f -print | sed "s,^\./,,")` || |
| 4274 |
pp_die "Could not make DEBIAN md5sums for $cmp" |
| 4275 |
} |
| 4276 |
|
| 4277 |
pp_backend_deb () { |
| 4278 |
local debname |
| 4279 |
|
| 4280 |
# Munge description for control file inclusion |
| 4281 |
pp_deb_munge_description |
| 4282 |
|
| 4283 |
# Handle services |
| 4284 |
pp_deb_handle_services $cmp |
| 4285 |
|
| 4286 |
for cmp in $pp_components |
| 4287 |
do |
| 4288 |
debname=`pp_deb_name $cmp` |
| 4289 |
pp_deb_makedeb $cmp |
| 4290 |
done |
| 4291 |
|
| 4292 |
. $pp_wrkdir/%fixup |
| 4293 |
|
| 4294 |
for cmp in $pp_components |
| 4295 |
do |
| 4296 |
debname=`pp_deb_name $cmp` |
| 4297 |
# Create debian package |
| 4298 |
pp_debug "Building `pp_deb_cmp_full_name $cmp` -> $output" |
| 4299 |
pp_deb_fakeroot dpkg-deb \ |
| 4300 |
--build $pp_wrkdir/`pp_deb_cmp_full_name $cmp` \ |
| 4301 |
$pp_wrkdir/$debname || |
| 4302 |
pp_error "failed to create $cmp package" |
| 4303 |
done |
| 4304 |
} |
| 4305 |
|
| 4306 |
pp_backend_deb_cleanup () { |
| 4307 |
# rm -rf $pp_wrkdir |
| 4308 |
: |
| 4309 |
} |
| 4310 |
|
| 4311 |
pp_deb_name () { |
| 4312 |
local cmp="${1:-run}" |
| 4313 |
echo `pp_deb_cmp_full_name $cmp`"_"`pp_deb_version_final`"-${pp_deb_release:-1}_${pp_deb_arch}.deb" |
| 4314 |
} |
| 4315 |
pp_backend_deb_names () { |
| 4316 |
for cmp in $pp_components |
| 4317 |
do |
| 4318 |
pp_deb_name $cmp |
| 4319 |
done |
| 4320 |
} |
| 4321 |
|
| 4322 |
pp_backend_deb_install_script () { |
| 4323 |
local cmp _cmp_full_name |
| 4324 |
|
| 4325 |
echo "#!/bin/sh" |
| 4326 |
pp_install_script_common |
| 4327 |
|
| 4328 |
cat <<. |
| 4329 |
|
| 4330 |
cmp_to_pkgname () { |
| 4331 |
test x"\$*" = x"all" && |
| 4332 |
set -- $pp_components |
| 4333 |
for cmp |
| 4334 |
do |
| 4335 |
case \$cmp in |
| 4336 |
. |
| 4337 |
for cmp in $pp_components; do |
| 4338 |
echo "$cmp) echo '`pp_deb_cmp_full_name $cmp`';;" |
| 4339 |
done |
| 4340 |
cat <<. |
| 4341 |
*) usage;; |
| 4342 |
esac |
| 4343 |
done |
| 4344 |
} |
| 4345 |
|
| 4346 |
|
| 4347 |
cmp_to_pathname () { |
| 4348 |
test x"\$*" = x"all" && |
| 4349 |
set -- $pp_components |
| 4350 |
for cmp |
| 4351 |
do |
| 4352 |
case \$cmp in |
| 4353 |
. |
| 4354 |
for cmp in $pp_components; do |
| 4355 |
echo "$cmp) echo \${PP_PKGDESTDIR:-.}/'`pp_deb_name $cmp`';;" |
| 4356 |
done |
| 4357 |
cat <<. |
| 4358 |
*) usage;; |
| 4359 |
esac |
| 4360 |
done |
| 4361 |
} |
| 4362 |
|
| 4363 |
test \$# -eq 0 && usage |
| 4364 |
op="\$1"; shift |
| 4365 |
case "\$op" in |
| 4366 |
list-components) |
| 4367 |
test \$# -eq 0 || usage \$op |
| 4368 |
echo $pp_components |
| 4369 |
;; |
| 4370 |
list-services) |
| 4371 |
test \$# -eq 0 || usage \$op |
| 4372 |
echo $pp_services |
| 4373 |
;; |
| 4374 |
list-files) |
| 4375 |
test \$# -ge 1 || usage \$op |
| 4376 |
cmp_to_pathname "\$@" |
| 4377 |
;; |
| 4378 |
install) |
| 4379 |
test \$# -ge 1 || usage \$op |
| 4380 |
dpkg --install \`cmp_to_pathname "\$@"\` |
| 4381 |
;; |
| 4382 |
uninstall) |
| 4383 |
test \$# -ge 1 || usage \$op |
| 4384 |
dpkg --remove \`cmp_to_pkgname "\$@"\`; : |
| 4385 |
;; |
| 4386 |
start|stop) |
| 4387 |
test \$# -ge 1 || usage \$op |
| 4388 |
ec=0 |
| 4389 |
for svc |
| 4390 |
do |
| 4391 |
/etc/init.d/\$svc \$op || ec=1 |
| 4392 |
done |
| 4393 |
exit \$ec |
| 4394 |
;; |
| 4395 |
print-platform) |
| 4396 |
test \$# -eq 0 || usage \$op |
| 4397 |
echo "linux-${pp_deb_arch}" |
| 4398 |
;; |
| 4399 |
*) |
| 4400 |
usage |
| 4401 |
;; |
| 4402 |
esac |
| 4403 |
. |
| 4404 |
} |
| 4405 |
|
| 4406 |
pp_backend_deb_probe() { |
| 4407 |
local arch distro release |
| 4408 |
|
| 4409 |
pp_deb_detect_arch |
| 4410 |
|
| 4411 |
# /etc/debian_version exists on Debian & Ubuntu, so it's no use |
| 4412 |
# to us. Use lsb_release instead. |
| 4413 |
|
| 4414 |
case `(lsb_release -is || echo no-lsb) 2>/dev/null` in |
| 4415 |
Debian) |
| 4416 |
distro=deb |
| 4417 |
;; |
| 4418 |
Ubuntu) |
| 4419 |
distro=ubu |
| 4420 |
;; |
| 4421 |
no-lsb) |
| 4422 |
echo unknown-$pp_deb_arch_std |
| 4423 |
return 0 |
| 4424 |
;; |
| 4425 |
*) |
| 4426 |
distro=unknown |
| 4427 |
;; |
| 4428 |
esac |
| 4429 |
|
| 4430 |
release=`lsb_release -rs` |
| 4431 |
|
| 4432 |
# If release is not numeric, use the codename |
| 4433 |
case $release in |
| 4434 |
*[!.0-9r]*) |
| 4435 |
release=`lsb_release -cs` |
| 4436 |
case $release in |
| 4437 |
buzz) |
| 4438 |
release="11" |
| 4439 |
;; |
| 4440 |
rex) |
| 4441 |
release="12" |
| 4442 |
;; |
| 4443 |
bo) |
| 4444 |
release="13" |
| 4445 |
;; |
| 4446 |
hamm) |
| 4447 |
release="20" |
| 4448 |
;; |
| 4449 |
slink) |
| 4450 |
release="21" |
| 4451 |
;; |
| 4452 |
potato) |
| 4453 |
release="22" |
| 4454 |
;; |
| 4455 |
woody) |
| 4456 |
release="30" |
| 4457 |
;; |
| 4458 |
sarge) |
| 4459 |
release="31" |
| 4460 |
;; |
| 4461 |
etch) |
| 4462 |
release="40" |
| 4463 |
;; |
| 4464 |
lenny) |
| 4465 |
release="50" |
| 4466 |
;; |
| 4467 |
squeeze) |
| 4468 |
release="60" |
| 4469 |
;; |
| 4470 |
wheezy) |
| 4471 |
release="70" |
| 4472 |
;; |
| 4473 |
jessie) |
| 4474 |
release="80" |
| 4475 |
;; |
| 4476 |
stretch) |
| 4477 |
release="90" |
| 4478 |
;; |
| 4479 |
esac |
| 4480 |
;; |
| 4481 |
*) |
| 4482 |
# Remove trailing revision number and any dots |
| 4483 |
release=`echo $release | cut -dr -f1 | tr -d .` |
| 4484 |
;; |
| 4485 |
esac |
| 4486 |
|
| 4487 |
echo $distro$release-$pp_deb_arch_std |
| 4488 |
} |
| 4489 |
|
| 4490 |
pp_backend_deb_vas_platforms () { |
| 4491 |
case "$pp_deb_arch_std" in |
| 4492 |
x86_64) echo "linux-x86_64.deb";; # DO NOT add linux-x86.deb here!! |
| 4493 |
*86) echo "linux-x86.deb";; |
| 4494 |
*) pp_die "unknown architecture ${pp_deb_arch_std}";; |
| 4495 |
esac |
| 4496 |
} |
| 4497 |
pp_backend_deb_init_svc_vars () { |
| 4498 |
|
| 4499 |
reload_signal= |
| 4500 |
start_runlevels=${pp_deb_default_start_runlevels-"2 3 4 5"} # == lsb default-start |
| 4501 |
stop_runlevels=${pp_deb_default_stop_runlevels-"0 1 6"} # == lsb default-stop |
| 4502 |
svc_description="${pp_deb_default_svc_description}" # == lsb short descr |
| 4503 |
svc_process= |
| 4504 |
svc_init_filename="${pp_deb_svc_init_filename}" # == $svc.init |
| 4505 |
svc_init_filepath="${pp_deb_svc_init_filepath}" # == /etc/init.d/ by default |
| 4506 |
|
| 4507 |
lsb_required_start='$local_fs $network' |
| 4508 |
lsb_should_start= |
| 4509 |
lsb_required_stop='$local_fs' |
| 4510 |
lsb_description= |
| 4511 |
|
| 4512 |
start_priority=50 |
| 4513 |
stop_priority=50 #-- stop_priority = 100 - start_priority |
| 4514 |
} |
| 4515 |
|
| 4516 |
pp_deb_service_make_service_files () { |
| 4517 |
local svc=${svc_init_filename:-$1} |
| 4518 |
local script="${svc_init_filepath:-"/etc/init.d"}/$svc" |
| 4519 |
local out=$pp_destdir$script |
| 4520 |
local _process _cmd |
| 4521 |
|
| 4522 |
pp_add_file_if_missing $script run 755 v || return 0 |
| 4523 |
|
| 4524 |
#-- start out as an empty shell script |
| 4525 |
cat <<-'.' >$out |
| 4526 |
#!/bin/sh |
| 4527 |
. |
| 4528 |
|
| 4529 |
#-- determine the process name from $cmd unless $svc_process is given |
| 4530 |
set -- $cmd |
| 4531 |
#_process=${svc_process:-"$1"} --? WTF |
| 4532 |
|
| 4533 |
#-- construct a start command that builds a pid file if needed |
| 4534 |
#-- the command name in /proc/[pid]/stat is limited to 15 characters |
| 4535 |
_cmd="$cmd"; |
| 4536 |
_cmd_path=`echo $cmd | cut -d" " -f1` |
| 4537 |
_cmd_name=`basename $_cmd_path | cut -c1-15` |
| 4538 |
_cmd_args=`echo $cmd | cut -d" " -f2-` |
| 4539 |
test x"$_cmd_path" != x"$_cmd_args" || _cmd_args= |
| 4540 |
|
| 4541 |
#-- generate the LSB init info |
| 4542 |
cat <<-. >>$out |
| 4543 |
### BEGIN INIT INFO |
| 4544 |
# Provides: ${svc} |
| 4545 |
# Required-Start: ${lsb_required_start} |
| 4546 |
# Should-Start: ${lsb_should_start} |
| 4547 |
# Required-Stop: ${lsb_required_stop} |
| 4548 |
# Default-Start: ${start_runlevels} |
| 4549 |
# Default-Stop: ${stop_runlevels} |
| 4550 |
# Short-Description: ${svc_description:-no description} |
| 4551 |
### END INIT INFO |
| 4552 |
# Generated by PolyPackage ${pp_version} |
| 4553 |
# ${copyright} |
| 4554 |
|
| 4555 |
. |
| 4556 |
|
| 4557 |
if test x"${svc_description}" = x"${pp_deb_default_svc_description}"; then |
| 4558 |
svc_description= |
| 4559 |
fi |
| 4560 |
|
| 4561 |
#-- write service-specific definitions |
| 4562 |
cat <<. >>$out |
| 4563 |
NAME="${_cmd_name}" |
| 4564 |
DESC="${svc_description:-$svc service}" |
| 4565 |
USER="${user}" |
| 4566 |
GROUP="${group}" |
| 4567 |
PIDFILE="${pidfile}" |
| 4568 |
STOP_SIGNAL="${stop_signal}" |
| 4569 |
RELOAD_SIGNAL="${reload_signal}" |
| 4570 |
CMD="${_cmd}" |
| 4571 |
DAEMON="${_cmd_path}" |
| 4572 |
DAEMON_ARGS="${_cmd_args}" |
| 4573 |
SCRIPTNAME=${script} |
| 4574 |
. |
| 4575 |
|
| 4576 |
#-- write the generic part of the init script |
| 4577 |
cat <<'.' >>$out |
| 4578 |
|
| 4579 |
[ -x "$DAEMON" ] || exit 0 |
| 4580 |
|
| 4581 |
[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
| 4582 |
|
| 4583 |
[ -f /etc/default/rcS ] && . /etc/default/rcS |
| 4584 |
|
| 4585 |
. /lib/lsb/init-functions |
| 4586 |
|
| 4587 |
do_start() |
| 4588 |
{ |
| 4589 |
# Return |
| 4590 |
# 0 if daemon has been started |
| 4591 |
# 1 if daemon was already running |
| 4592 |
# 2 if daemon could not be started |
| 4593 |
if [ -n "$PIDFILE" ] |
| 4594 |
then |
| 4595 |
pidfile_opt="--pidfile $PIDFILE" |
| 4596 |
else |
| 4597 |
pidfile_opt="--make-pidfile --background --pidfile /var/run/$NAME.pid" |
| 4598 |
fi |
| 4599 |
if [ -n "$USER" ] |
| 4600 |
then |
| 4601 |
user_opt="--user $USER" |
| 4602 |
fi |
| 4603 |
if [ -n "$GROUP" ] |
| 4604 |
then |
| 4605 |
group_opt="--group $GROUP" |
| 4606 |
fi |
| 4607 |
|
| 4608 |
start-stop-daemon --start --quiet $pidfile_opt $user_opt --exec $DAEMON --test > /dev/null \ |
| 4609 |
|| return 1 |
| 4610 |
|
| 4611 |
# Note: there seems to be no way to tell whether the daemon will fork itself or not, so pass |
| 4612 |
# --background for now |
| 4613 |
start-stop-daemon --start --quiet $pidfile_opt $user_opt --exec $DAEMON -- \ |
| 4614 |
$DAEMON_ARGS \ |
| 4615 |
|| return 2 |
| 4616 |
} |
| 4617 |
|
| 4618 |
do_stop() |
| 4619 |
{ |
| 4620 |
# Return |
| 4621 |
# 0 if daemon has been stopped |
| 4622 |
# 1 if daemon was already stopped |
| 4623 |
# 2 if daemon could not be stopped |
| 4624 |
# other if a failure occurred |
| 4625 |
if [ -n "$PIDFILE" ] |
| 4626 |
then |
| 4627 |
pidfile_opt="--pidfile $PIDFILE" |
| 4628 |
else |
| 4629 |
pidfile_opt="--pidfile /var/run/$NAME.pid" |
| 4630 |
fi |
| 4631 |
if [ -n "$USER" ] |
| 4632 |
then |
| 4633 |
user_opt="--user $USER" |
| 4634 |
fi |
| 4635 |
if [ -n $STOP_SIGNAL ] |
| 4636 |
then |
| 4637 |
signal_opt="--signal $STOP_SIGNAL" |
| 4638 |
fi |
| 4639 |
start-stop-daemon --stop --quiet $signal_opt --retry=TERM/30/KILL/5 $pidfile_opt --name $NAME |
| 4640 |
RETVAL="$?" |
| 4641 |
[ "$RETVAL" = 2 ] && return 2 |
| 4642 |
# Wait for children to finish too if this is a daemon that forks |
| 4643 |
# and if the daemon is only ever run from this initscript. |
| 4644 |
# If the above conditions are not satisfied then add some other code |
| 4645 |
# that waits for the process to drop all resources that could be |
| 4646 |
# needed by services started subsequently. A last resort is to |
| 4647 |
# sleep for some time. |
| 4648 |
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON |
| 4649 |
[ "$?" = 2 ] && return 2 |
| 4650 |
# Many daemons don't delete their pidfiles when they exit. |
| 4651 |
test -z $PIDFILE || rm -f $PIDFILE |
| 4652 |
return "$RETVAL" |
| 4653 |
} |
| 4654 |
|
| 4655 |
do_reload() { |
| 4656 |
# |
| 4657 |
# If the daemon can reload its configuration without |
| 4658 |
# restarting (for example, when it is sent a SIGHUP), |
| 4659 |
# then implement that here. |
| 4660 |
# |
| 4661 |
if [ -n "$PIDFILE" ] |
| 4662 |
then |
| 4663 |
pidfile_opt="--pidfile $PIDFILE" |
| 4664 |
else |
| 4665 |
pidfile_opt="--pidfile /var/run/$NAME.pid" |
| 4666 |
fi |
| 4667 |
if [ -n "$RELOAD_SIGNAL" ] |
| 4668 |
then |
| 4669 |
start-stop-daemon --stop --signal $RELOAD_SIGNAL --quiet $pidfile_opt --name $NAME |
| 4670 |
fi |
| 4671 |
return 0 |
| 4672 |
} |
| 4673 |
|
| 4674 |
case "$1" in |
| 4675 |
start) |
| 4676 |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
| 4677 |
do_start |
| 4678 |
case "$?" in |
| 4679 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 4680 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 4681 |
esac |
| 4682 |
;; |
| 4683 |
stop) |
| 4684 |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
| 4685 |
do_stop |
| 4686 |
case "$?" in |
| 4687 |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 4688 |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 4689 |
esac |
| 4690 |
;; |
| 4691 |
reload|force-reload) |
| 4692 |
if [ -n "$RELOAD_SIGNAL" ] |
| 4693 |
then |
| 4694 |
log_daemon_msg "Reloading $DESC" "$NAME" |
| 4695 |
do_reload |
| 4696 |
log_end_msg $? |
| 4697 |
else |
| 4698 |
# Do a restart instead |
| 4699 |
"$0" restart |
| 4700 |
fi |
| 4701 |
;; |
| 4702 |
restart) |
| 4703 |
# |
| 4704 |
# If the "reload" option is implemented then remove the |
| 4705 |
# 'force-reload' alias |
| 4706 |
# |
| 4707 |
log_daemon_msg "Restarting $DESC" "$NAME" |
| 4708 |
do_stop |
| 4709 |
case "$?" in |
| 4710 |
0|1) |
| 4711 |
do_start |
| 4712 |
case "$?" in |
| 4713 |
0) log_end_msg 0 ;; |
| 4714 |
1) log_end_msg 1 ;; # Old process is still running |
| 4715 |
*) log_end_msg 1 ;; # Failed to start |
| 4716 |
esac |
| 4717 |
;; |
| 4718 |
*) |
| 4719 |
# Failed to stop |
| 4720 |
log_end_msg 1 |
| 4721 |
;; |
| 4722 |
esac |
| 4723 |
;; |
| 4724 |
*) |
| 4725 |
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 |
| 4726 |
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
| 4727 |
exit 3 |
| 4728 |
;; |
| 4729 |
esac |
| 4730 |
|
| 4731 |
: |
| 4732 |
. |
| 4733 |
chmod 755 $out |
| 4734 |
|
| 4735 |
# Create systemd service file |
| 4736 |
pp_systemd_make_service_file $svc |
| 4737 |
} |
| 4738 |
pp_backend_deb_function() { |
| 4739 |
case "$1" in |
| 4740 |
pp_mkgroup) cat<<'.';; |
| 4741 |
/usr/sbin/groupmod "$1" 2>/dev/null && return 0 |
| 4742 |
/usr/sbin/groupadd "$1" |
| 4743 |
. |
| 4744 |
pp_mkuser:depends) echo pp_mkgroup;; |
| 4745 |
pp_mkuser) cat<<'.';; |
| 4746 |
pp_tmp_system= |
| 4747 |
id -u "$1" >/dev/null 2>/dev/null && return 0 |
| 4748 |
# deb 3.1's useradd changed API in 4.0. Gah! |
| 4749 |
/usr/sbin/useradd --help 2>&1 | /bin/grep -q .--system && |
| 4750 |
pp_tmp_system=--system |
| 4751 |
pp_mkgroup "${2:-$1}" || return 1 |
| 4752 |
/usr/sbin/useradd \ |
| 4753 |
-g "${2:-$1}" \ |
| 4754 |
-d "${3:-/nonexistent}" \ |
| 4755 |
-s "${4:-/bin/false}" \ |
| 4756 |
$pp_tmp_system \ |
| 4757 |
"$1" |
| 4758 |
. |
| 4759 |
pp_havelib) cat<<'.';; |
| 4760 |
for pp_tmp_dir in `echo "/usr/lib:/lib${3:+:$3}" | tr : ' '`; do |
| 4761 |
test -r "$pp_tmp_dir/lib$1.so{$2:+.$2}" && return 0 |
| 4762 |
done |
| 4763 |
return 1 |
| 4764 |
. |
| 4765 |
*) false;; |
| 4766 |
esac |
| 4767 |
} |
| 4768 |
|
| 4769 |
pp_platforms="$pp_platforms kit" |
| 4770 |
|
| 4771 |
pp_backend_kit_detect () { |
| 4772 |
test x"$1" = x"OSF1" |
| 4773 |
} |
| 4774 |
|
| 4775 |
pp_backend_kit_init () { |
| 4776 |
pp_kit_name= |
| 4777 |
pp_kit_package= |
| 4778 |
pp_kit_desc= |
| 4779 |
pp_kit_version= |
| 4780 |
pp_kit_subset= |
| 4781 |
pp_readlink_fn=pp_ls_readlink |
| 4782 |
pp_kit_startlevels="2 3" |
| 4783 |
pp_kit_stoplevels="0 2 3" |
| 4784 |
} |
| 4785 |
|
| 4786 |
pp_backend_kit () { |
| 4787 |
typeset mi_file k_file svc outfile |
| 4788 |
typeset desc |
| 4789 |
|
| 4790 |
pp_backend_kit_names > /dev/null |
| 4791 |
|
| 4792 |
if test -z "$pp_kit_desc"; then |
| 4793 |
pp_kit_desc="$description" |
| 4794 |
fi |
| 4795 |
|
| 4796 |
mi_file="$pp_wrkdir/$pp_kit_subset.mi" |
| 4797 |
k_file="$pp_wrkdir/$pp_kit_subset.k" |
| 4798 |
scp_file="$pp_wrkdir/$pp_kit_subset.scp" |
| 4799 |
|
| 4800 |
desc="${pp_kit_desc:-$description}" |
| 4801 |
|
| 4802 |
cat <<-. >> $k_file |
| 4803 |
NAME='$name' |
| 4804 |
CODE=$pp_kit_name |
| 4805 |
VERS=$pp_kit_version |
| 4806 |
MI=$mi_file |
| 4807 |
COMPRESS=0 |
| 4808 |
%% |
| 4809 |
$pp_kit_subset . 0 '$desc' |
| 4810 |
. |
| 4811 |
|
| 4812 |
if test -n "$pp_services"; then |
| 4813 |
for svc in $pp_services; do |
| 4814 |
pp_kit_make_service $svc |
| 4815 |
pp_prepend $pp_wrkdir/%preun.run <<-. |
| 4816 |
/sbin/init.d/$svc stop |
| 4817 |
. |
| 4818 |
done |
| 4819 |
fi |
| 4820 |
|
| 4821 |
pp_backend_kit_make_mi "$mi_file" |
| 4822 |
pp_backend_kit_make_scp |
| 4823 |
#rm -rf $pp_wrkdir/kit_dest |
| 4824 |
mkdir -p $pp_wrkdir/kit_dest |
| 4825 |
pp_backend_kit_kits $k_file $pp_opt_destdir $pp_wrkdir/kit_dest |
| 4826 |
tar cvf $pp_wrkdir/$pp_kit_subset.tar -C $pp_wrkdir/kit_dest . |
| 4827 |
gzip -c $pp_wrkdir/$pp_kit_subset.tar > $pp_wrkdir/$pp_kit_subset.tar.gz |
| 4828 |
#rm -rf $pp_wrkdir/$pp_kit_subset.tar $pp_wrkdir/scps |
| 4829 |
} |
| 4830 |
|
| 4831 |
pp_backend_kit_make_mi () { |
| 4832 |
# XXX this information should go into the .inv files |
| 4833 |
typeset t m o g f p st line dm |
| 4834 |
while read t m o g f p st; do |
| 4835 |
case $t in |
| 4836 |
f|d) |
| 4837 |
echo "0 .$p $pp_kit_subset" |
| 4838 |
echo " chmod $m $p" >> $pp_wrkdir/%post.run |
| 4839 |
if [ x"$o" = x"-" ] ; then |
| 4840 |
echo " chown root $p" >> $pp_wrkdir/%post.run |
| 4841 |
else |
| 4842 |
echo " chown $o $p" >> $pp_wrkdir/%post.run |
| 4843 |
fi |
| 4844 |
if [ x"$g" = x"-" ] ; then |
| 4845 |
echo " chgrp 0 $p" >> $pp_wrkdir/%post.run |
| 4846 |
else |
| 4847 |
echo " chgrp $g $p" >> $pp_wrkdir/%post.run |
| 4848 |
fi |
| 4849 |
;; |
| 4850 |
s) |
| 4851 |
echo " ln -s $st $p" >> $pp_wrkdir/%post.run |
| 4852 |
echo " rm -f $p" >> $pp_wrkdir/%preun.run |
| 4853 |
;; |
| 4854 |
esac |
| 4855 |
done < $pp_wrkdir/%files.run | sort -k3 |uniq > $1 |
| 4856 |
} |
| 4857 |
|
| 4858 |
|
| 4859 |
pp_backend_kit_make_scp () { |
| 4860 |
scpdir="$pp_wrkdir/scps" |
| 4861 |
mkdir "$scpdir" && touch "$scpdir"/$pp_kit_subset.scp |
| 4862 |
cat <<EOF >"$scpdir"/$pp_kit_subset.scp |
| 4863 |
|
| 4864 |
. /usr/share/lib/shell/libscp |
| 4865 |
|
| 4866 |
case "\$ACT" in |
| 4867 |
PRE_L) |
| 4868 |
STL_ScpInit |
| 4869 |
|
| 4870 |
|
| 4871 |
|
| 4872 |
;; |
| 4873 |
POST_L) |
| 4874 |
STL_ScpInit |
| 4875 |
STL_LinkCreate |
| 4876 |
EOF |
| 4877 |
|
| 4878 |
cat $pp_wrkdir/%post.run >>"$scpdir"/$pp_kit_subset.scp |
| 4879 |
cat >>"$scpdir"/$pp_kit_subset.scp <<EOF |
| 4880 |
;; |
| 4881 |
PRE_D) |
| 4882 |
STL_ScpInit |
| 4883 |
STL_LinkRemove |
| 4884 |
EOF |
| 4885 |
cat $pp_wrkdir/%preun.run >>"$scpdir"/$pp_kit_subset.scp |
| 4886 |
cat >>"$scpdir"/$pp_kit_subset.scp <<EOF |
| 4887 |
;; |
| 4888 |
POST_D) |
| 4889 |
|
| 4890 |
;; |
| 4891 |
C) |
| 4892 |
STL_ScpInit |
| 4893 |
|
| 4894 |
case "\$1" in |
| 4895 |
INSTALL) |
| 4896 |
echo "Installation of the \$_DESC (\$_SUB) subset is complete." |
| 4897 |
;; |
| 4898 |
DELETE) |
| 4899 |
;; |
| 4900 |
esac |
| 4901 |
|
| 4902 |
;; |
| 4903 |
V) |
| 4904 |
|
| 4905 |
;; |
| 4906 |
esac |
| 4907 |
|
| 4908 |
exit 0 |
| 4909 |
EOF |
| 4910 |
chmod 744 "$scpdir"/$pp_kit_subset.scp |
| 4911 |
} |
| 4912 |
|
| 4913 |
|
| 4914 |
pp_backend_kit_cleanup () { |
| 4915 |
: |
| 4916 |
} |
| 4917 |
|
| 4918 |
pp_backend_kit_names () { |
| 4919 |
if test -z "$pp_kit_name"; then |
| 4920 |
pp_warn "pp_kit_name not specified, using XXX" |
| 4921 |
pp_kit_name=XXX |
| 4922 |
fi |
| 4923 |
case "$pp_kit_name" in |
| 4924 |
???) : ok;; |
| 4925 |
*) pp_error "\$pp_kit_name $pp_kit_name must be three characters";; |
| 4926 |
esac |
| 4927 |
if test -z "$pp_kit_package"; then |
| 4928 |
pp_warn "pp_kit_package not specified, using YYYY" |
| 4929 |
pp_kit_package=YYYY |
| 4930 |
fi |
| 4931 |
if test -z "$pp_kit_version"; then |
| 4932 |
pp_kit_version=`echo $version|tr -d '.a-zA-Z'` |
| 4933 |
fi |
| 4934 |
case "$pp_kit_version" in |
| 4935 |
[0-9]) pp_kit_version="${pp_kit_version}00";; |
| 4936 |
[0-9][0-9]) pp_kit_version="${pp_kit_version}0";; |
| 4937 |
[0-9][0-9][0-9]) : ok;; |
| 4938 |
*) pp_error "\$pp_kit_version $pp_kit_version must be three digits, ";; |
| 4939 |
esac |
| 4940 |
if test -z "$pp_kit_subset"; then |
| 4941 |
pp_kit_subset="$pp_kit_name$pp_kit_package$pp_kit_version" |
| 4942 |
fi |
| 4943 |
echo "$pp_kit_subset.tar.gz" |
| 4944 |
} |
| 4945 |
|
| 4946 |
pp_backend_kit_install_script () { |
| 4947 |
typeset pkgname platform |
| 4948 |
|
| 4949 |
pkgname=`pp_backend_kit_names` |
| 4950 |
platform="`pp_backend_kit_probe`" |
| 4951 |
|
| 4952 |
echo "#!/bin/sh" |
| 4953 |
pp_install_script_common |
| 4954 |
cat <<. |
| 4955 |
|
| 4956 |
cpt_to_tags () { |
| 4957 |
test x"\$*" = x"all" && set -- $pp_components |
| 4958 |
for cpt |
| 4959 |
do |
| 4960 |
echo "$name.\$cpt" |
| 4961 |
done |
| 4962 |
} |
| 4963 |
|
| 4964 |
test \$# -eq 0 && usage |
| 4965 |
op="\$1"; shift |
| 4966 |
|
| 4967 |
case "\$op" in |
| 4968 |
list-components) |
| 4969 |
test \$# -eq 0 || usage \$op |
| 4970 |
echo "$pp_components" |
| 4971 |
;; |
| 4972 |
list-services) |
| 4973 |
test \$# -eq 0 || usage \$op |
| 4974 |
echo "$pp_services" |
| 4975 |
;; |
| 4976 |
list-files) |
| 4977 |
test \$# -ge 1 || usage \$op |
| 4978 |
echo \${PP_PKGDESTDIR:-.}/$pkgname |
| 4979 |
;; |
| 4980 |
install) |
| 4981 |
test \$# -ge 1 || usage \$op |
| 4982 |
verbose echo \${PP_PKGDESTDIR:-\`pwd\`}/$pkgname \`cpt_to_tags "\$@"\` |
| 4983 |
#verbose swinstall -x verbose=0 -s \${PP_PKGDESTDIR:-\`pwd\`}/$pkgname \`cpt_to_tags "\$@"\` |
| 4984 |
;; |
| 4985 |
uninstall) |
| 4986 |
test \$# -ge 1 || usage \$op |
| 4987 |
verbose echo \`cpt_to_tags "\$@"\` |
| 4988 |
#verbose swremove -x verbose=0 \`cpt_to_tags "\$@"\` |
| 4989 |
;; |
| 4990 |
start|stop) |
| 4991 |
test \$# -ge 1 || usage \$op |
| 4992 |
ec=0 |
| 4993 |
for svc |
| 4994 |
do |
| 4995 |
verbose /sbin/init.d/\$svc \$op |
| 4996 |
[ \$? -eq 4 -o \$? -eq 0 ] || ec=1 |
| 4997 |
done |
| 4998 |
exit \$ec |
| 4999 |
;; |
| 5000 |
print-platform) |
| 5001 |
echo "$platform" |
| 5002 |
;; |
| 5003 |
*) |
| 5004 |
usage |
| 5005 |
;; |
| 5006 |
esac |
| 5007 |
. |
| 5008 |
} |
| 5009 |
|
| 5010 |
pp_backend_kit_function () { |
| 5011 |
case "$1" in |
| 5012 |
pp_mkgroup) cat <<'.';; |
| 5013 |
grep "^$1:" /etc/group >/dev/null || |
| 5014 |
/usr/sbin/groupadd $1 |
| 5015 |
. |
| 5016 |
pp_mkuser) cat <<'.';; |
| 5017 |
eval user=\$$# |
| 5018 |
grep "^$user:" /etc/passwd >/dev/null || |
| 5019 |
/usr/sbin/useradd -s /usr/bin/false "$@" |
| 5020 |
. |
| 5021 |
pp_havelib) cat <<'.';; |
| 5022 |
for dir in `echo /usr/lib${3+:$3} | tr : ' '`; do |
| 5023 |
test -r "$dir/lib$1.${2-sl}" && return 0 |
| 5024 |
done |
| 5025 |
return 1 |
| 5026 |
. |
| 5027 |
*) pp_error "unknown function request: $1";; |
| 5028 |
esac |
| 5029 |
} |
| 5030 |
|
| 5031 |
pp_backend_kit_init_svc_vars () { |
| 5032 |
: |
| 5033 |
} |
| 5034 |
|
| 5035 |
pp_backend_kit_probe () { |
| 5036 |
echo tru64-`uname -r | sed 's/V\([0-9]*\)\.\([0-9]*\)/\1\2/'` |
| 5037 |
} |
| 5038 |
|
| 5039 |
pp_kit_service_group_script () { |
| 5040 |
typeset grp svcs scriptpath out |
| 5041 |
grp="$1" |
| 5042 |
svcs="$2" |
| 5043 |
scriptpath="/sbin/init.d/$grp" |
| 5044 |
out="$pp_destdir$scriptpath" |
| 5045 |
|
| 5046 |
pp_add_file_if_missing $scriptpath run 755 || return 0 |
| 5047 |
|
| 5048 |
cat <<-. > $out |
| 5049 |
#!/sbin/sh |
| 5050 |
# generated by pp $pp_version |
| 5051 |
svcs="$svcs" |
| 5052 |
. |
| 5053 |
|
| 5054 |
cat <<-'.' >> $out |
| 5055 |
#-- starts services in order.. stops them all if any break |
| 5056 |
pp_start () { |
| 5057 |
undo= |
| 5058 |
for svc in $svcs; do |
| 5059 |
/sbin/init.d/$svc start |
| 5060 |
case $? in |
| 5061 |
0|4) |
| 5062 |
undo="$svc $undo" |
| 5063 |
;; |
| 5064 |
*) |
| 5065 |
if test -n "$undo"; then |
| 5066 |
for svc in $undo; do |
| 5067 |
/sbin/init.d/$svc stop |
| 5068 |
done |
| 5069 |
return 1 |
| 5070 |
fi |
| 5071 |
;; |
| 5072 |
esac |
| 5073 |
done |
| 5074 |
return 0 |
| 5075 |
} |
| 5076 |
|
| 5077 |
#-- stops services in reverse |
| 5078 |
pp_stop () { |
| 5079 |
reverse= |
| 5080 |
for svc in $svcs; do |
| 5081 |
reverse="$svc $reverse" |
| 5082 |
done |
| 5083 |
rc=0 |
| 5084 |
for svc in $reverse; do |
| 5085 |
/sbin/init.d/$svc stop || rc=$? |
| 5086 |
done |
| 5087 |
return $rc |
| 5088 |
} |
| 5089 |
|
| 5090 |
case "$1" in |
| 5091 |
start_msg) echo "Starting $svcs";; |
| 5092 |
stop_msg) echo "Stopping $svcs";; |
| 5093 |
start) pp_start;; |
| 5094 |
stop) pp_stop;; |
| 5095 |
*) echo "usage: $0 {start|stop|start_msg|stop_msg}" |
| 5096 |
exit 1;; |
| 5097 |
esac |
| 5098 |
. |
| 5099 |
} |
| 5100 |
|
| 5101 |
pp_kit_service_script () { |
| 5102 |
typeset svc scriptpath out |
| 5103 |
|
| 5104 |
svc="$1" |
| 5105 |
scriptpath="/sbin/init.d/$svc" |
| 5106 |
|
| 5107 |
pp_load_service_vars "$svc" |
| 5108 |
|
| 5109 |
test -n "$user" -a x"$user" != x"root" && |
| 5110 |
cmd="SHELL=/usr/bin/sh /usr/bin/su $user -c \"exec `echo $cmd | sed -e 's,[$\\\`],\\&,g'`\"" |
| 5111 |
if test -z "$pidfile"; then |
| 5112 |
pidfile="/var/run/$svc.pid" |
| 5113 |
cmd="$cmd & echo \$! > \$pidfile" |
| 5114 |
fi |
| 5115 |
|
| 5116 |
pp_add_file_if_missing $scriptpath run 755 |
| 5117 |
|
| 5118 |
cat <<-. > $pp_destdir$scriptpath |
| 5119 |
svc="$svc" |
| 5120 |
pidfile="$pidfile" |
| 5121 |
|
| 5122 |
pp_start () { |
| 5123 |
$cmd |
| 5124 |
} |
| 5125 |
. |
| 5126 |
cat <<-'.' >>$pp_destdir$scriptpath |
| 5127 |
pp_stop () { |
| 5128 |
if test ! -s "$pidfile"; then |
| 5129 |
echo "Unable to stop $svc (no pid file)" |
| 5130 |
return 1 |
| 5131 |
else |
| 5132 |
read pid < "$pidfile" |
| 5133 |
if kill -0 "$pid" 2>/dev/null; then |
| 5134 |
if kill -${stop_signal:-TERM} "$pid"; then |
| 5135 |
rm -f "$pidfile" |
| 5136 |
return 0 |
| 5137 |
else |
| 5138 |
echo "Unable to stop $svc" |
| 5139 |
return 1 |
| 5140 |
fi |
| 5141 |
else |
| 5142 |
rm -f "$pidfile" |
| 5143 |
return 0 |
| 5144 |
fi |
| 5145 |
fi |
| 5146 |
} |
| 5147 |
|
| 5148 |
pp_running () { |
| 5149 |
if test ! -s "$pidfile"; then |
| 5150 |
return 1 |
| 5151 |
else |
| 5152 |
read pid < "$pidfile" |
| 5153 |
kill -0 "$pid" 2>/dev/null |
| 5154 |
fi |
| 5155 |
} |
| 5156 |
case "$1" in |
| 5157 |
start_msg) echo "Starting the $svc service";; |
| 5158 |
stop_msg) echo "Stopping the $svc service";; |
| 5159 |
start) |
| 5160 |
if pp_running; then |
| 5161 |
echo "$svc already running"; |
| 5162 |
exit 0 |
| 5163 |
elif pp_start; then |
| 5164 |
echo "$svc started"; |
| 5165 |
# rc(1M) says we should exit 4, but nobody expects it! |
| 5166 |
exit 0 |
| 5167 |
else |
| 5168 |
exit 1 |
| 5169 |
fi |
| 5170 |
;; |
| 5171 |
stop) |
| 5172 |
if pp_stop; then |
| 5173 |
echo "$svc stopped"; |
| 5174 |
exit 0 |
| 5175 |
else |
| 5176 |
exit 1 |
| 5177 |
fi |
| 5178 |
;; |
| 5179 |
*) echo "usage: $0 {start|stop|start_msg|stop_msg}" |
| 5180 |
exit 1 |
| 5181 |
;; |
| 5182 |
esac |
| 5183 |
. |
| 5184 |
} |
| 5185 |
|
| 5186 |
pp_kit_make_service () { |
| 5187 |
typeset level priority startlevels stoplevels |
| 5188 |
typeset svc svcvar |
| 5189 |
|
| 5190 |
svc="$1" |
| 5191 |
svcvar=`pp_makevar $svc` |
| 5192 |
|
| 5193 |
#-- don't do anything if the script exists |
| 5194 |
if test -s "$pp_destdir/sbin/init.d/$svc"; then |
| 5195 |
pp_error "$pp_destdir/sbin/init.d/$svc exists" |
| 5196 |
return |
| 5197 |
fi |
| 5198 |
|
| 5199 |
# symlink the script, depending on the priorities chosen |
| 5200 |
eval priority='${pp_kit_priority_'$svcvar'}' |
| 5201 |
test -z "$priority" && priority="${pp_kit_priority:-50}" |
| 5202 |
|
| 5203 |
eval startlevels='${pp_kit_startlevels_'$svcvar'}' |
| 5204 |
test -z "$startlevels" && startlevels="$pp_kit_startlevels" |
| 5205 |
|
| 5206 |
eval stoplevels='${pp_kit_stoplevels_'$svcvar'}' |
| 5207 |
test -z "$stoplevels" && stoplevels="$pp_kit_stoplevels" |
| 5208 |
|
| 5209 |
# create the script and config file |
| 5210 |
pp_kit_service_script $svc |
| 5211 |
|
| 5212 |
# fix the priority up |
| 5213 |
case "$priority" in |
| 5214 |
???) :;; |
| 5215 |
??) priority=0$priority;; |
| 5216 |
?) priority=00$priority;; |
| 5217 |
esac |
| 5218 |
|
| 5219 |
if test x"$stoplevels" = x"auto"; then |
| 5220 |
stoplevels= |
| 5221 |
test -z "$startlevels" || for level in $startlevels; do |
| 5222 |
stoplevels="$stoplevels `expr $level - 1`" |
| 5223 |
done |
| 5224 |
fi |
| 5225 |
|
| 5226 |
# create the symlinks |
| 5227 |
test -z "$startlevels" || for level in $startlevels; do |
| 5228 |
echo " ln -s /sbin/init.d/$svc /sbin/rc$level.d/S$priority$svc" >>$pp_wrkdir/%post.run |
| 5229 |
echo " rm /sbin/rc$level.d/S$priority$svc" >>$pp_wrkdir/%preun.run |
| 5230 |
done |
| 5231 |
test -z "$stoplevels" || for level in $stoplevels; do |
| 5232 |
echo " ln -s /sbin/init.d/$svc /sbin/rc$level.d/K$priority$svc" >>$pp_wrkdir/%post.run |
| 5233 |
echo " rm -f /sbin/rc$level.d/K$priority$svc" >>$pp_wrkdir/%preun.run |
| 5234 |
done |
| 5235 |
} |
| 5236 |
|
| 5237 |
|
| 5238 |
|
| 5239 |
|
| 5240 |
pp_backend_kit_sizes () { |
| 5241 |
awk ' |
| 5242 |
BEGIN { root = usr = var = 0; } |
| 5243 |
{ |
| 5244 |
if (substr($9, 1, 1) != "l") |
| 5245 |
if (substr($10, 1, 6) == "./var/") |
| 5246 |
var += $2; |
| 5247 |
else if (substr($10, 1, 10) == "./usr/var/") |
| 5248 |
var += $2 |
| 5249 |
else if (substr($10, 1, 6) == "./usr/") |
| 5250 |
usr += $2 |
| 5251 |
else |
| 5252 |
root += $2 |
| 5253 |
} |
| 5254 |
END { printf "%d\t%d\t%d", root, usr, var } |
| 5255 |
' "$@" |
| 5256 |
} |
| 5257 |
|
| 5258 |
pp_kit_kits_global () { |
| 5259 |
line=`sed -n '/^%%/q;/^'$2'=/{s/^'$2'=//p;q;}' <"$1"` |
| 5260 |
test -z "$line" && return 1 |
| 5261 |
eval "echo $line" |
| 5262 |
: |
| 5263 |
} |
| 5264 |
|
| 5265 |
pp_backend_kit_kits () { |
| 5266 |
typeset KITFILE FROMDIR TODIR |
| 5267 |
typeset SCPDIR |
| 5268 |
|
| 5269 |
SCPDIR="$pp_wrkdir/scps" |
| 5270 |
|
| 5271 |
PATH="/usr/lbin:/usr/bin:/etc:/usr/ucb:$PATH"; export PATH # XXX |
| 5272 |
#umask 2 # XXX |
| 5273 |
|
| 5274 |
test $# -ge 3 || pp_die "pp_backend_kit_kits: too few arguments" |
| 5275 |
KITFILE="$1"; shift |
| 5276 |
FROMDIR="$1"; shift |
| 5277 |
TODIR="$1"; shift |
| 5278 |
|
| 5279 |
test -f "$KITFILE" || pp_die "$KITFILE not found" |
| 5280 |
test -d "$FROMDIR" || pp_die "$FROMDIR not found" |
| 5281 |
test -d "$TODIR" || pp_die "$TODIR not found" |
| 5282 |
|
| 5283 |
INSTCTRL="$TODIR/instctrl" |
| 5284 |
mkdir -p "$INSTCTRL" || pp_die "cannot create instctrl directory" |
| 5285 |
chmod 775 "$INSTCTRL" |
| 5286 |
|
| 5287 |
grep "%%" $KITFILE > /dev/null || pp_die "no %% in $KITFILE" |
| 5288 |
|
| 5289 |
typeset NAME CODE VERS MI ROOT COMPRESS |
| 5290 |
typeset S_LIST ALLSUBS |
| 5291 |
|
| 5292 |
NAME=`pp_kit_kits_global "$KITFILE" NAME` || pp_die "no NAME in $KITFILE" |
| 5293 |
CODE=`pp_kit_kits_global "$KITFILE" CODE` || pp_die "no CODE in $KITFILE" |
| 5294 |
VERS=`pp_kit_kits_global "$KITFILE" VERS` || pp_die "no VERS in $KITFILE" |
| 5295 |
MI=`pp_kit_kits_global "$KITFILE" MI` || pp_die "no MI in $KITFILE" |
| 5296 |
ROOT=`pp_kit_kits_global "$KITFILE" ROOT` |
| 5297 |
COMPRESS=`pp_kit_kits_global "$KITFILE" COMPRESS` |
| 5298 |
|
| 5299 |
test -f "$MI" || pp_die "Inventory file $MI not found" |
| 5300 |
|
| 5301 |
case "$ROOT" in |
| 5302 |
*ROOT) |
| 5303 |
test -f "$TODIR/$ROOT" || |
| 5304 |
pp_die "Root image $ROOT not found in $TODIR" ;; |
| 5305 |
esac |
| 5306 |
|
| 5307 |
ALLSUBS=`awk 'insub==1 {print $1} /^%%/ {insub=1}' <"$KITFILE"` |
| 5308 |
test $# -eq 0 && set -- $ALLSUBS |
| 5309 |
|
| 5310 |
pp_debug "Creating $# $NAME subsets." |
| 5311 |
pp_debug "ALLSUBS=<$ALLSUBS>" |
| 5312 |
|
| 5313 |
if test x"$COMPRESS" = x"1"; then |
| 5314 |
COMPRESS=: |
| 5315 |
else |
| 5316 |
COMPRESS=false |
| 5317 |
fi |
| 5318 |
|
| 5319 |
#rm -f *.ctrl Volume* |
| 5320 |
|
| 5321 |
for SUB |
| 5322 |
do |
| 5323 |
test -z "$SUB" && pp_die "SUB is empty" |
| 5324 |
|
| 5325 |
typeset INV CTRL ROOTSIZE USRSIZE VARSIZE TSSUB |
| 5326 |
#rm -f Volume* |
| 5327 |
case $SUB in |
| 5328 |
.*) :;; |
| 5329 |
*) pp_verbose rm -f "$TODIR/$SUB"* "$INSTCTRL/$SUB"*;; |
| 5330 |
esac |
| 5331 |
|
| 5332 |
TSSUB="$pp_wrkdir/ts.$SUB" |
| 5333 |
|
| 5334 |
pp_debug "kits: Subset $SUB" |
| 5335 |
|
| 5336 |
INV="$SUB.inv" |
| 5337 |
CTRL="$SUB.ctrl" |
| 5338 |
pp_debug "kits: Generating media creation information..." |
| 5339 |
|
| 5340 |
# Invcutter takes as input |
| 5341 |
# SUB dir/path |
| 5342 |
# and generates stl_inv(4) files, like this |
| 5343 |
# f 0 00000 0 0 100644 2/11/09 010 f dir/path none SUB |
| 5344 |
grep " $SUB\$" "$MI" | |
| 5345 |
pp_verbose /usr/lbin/invcutter \ |
| 5346 |
-v "$VERS" -f "$FROMDIR" > "$INSTCTRL/$INV" || |
| 5347 |
pp_die "failed to create $INSTCTRL/$INV" |
| 5348 |
chmod 664 "$INSTCTRL/$INV" |
| 5349 |
|
| 5350 |
pp_backend_kit_sizes "$INSTCTRL/$INV" > "$pp_wrkdir/kit.sizes" |
| 5351 |
read ROOTSIZE USRSIZE VARSIZE < "$pp_wrkdir/kit.sizes" |
| 5352 |
|
| 5353 |
# Prefix each line with $FROMDIR. This will be stripped |
| 5354 |
awk '$1 != "d" {print from $10}' from="$FROMDIR/" \ |
| 5355 |
> "$TSSUB" < "$INSTCTRL/$INV" || |
| 5356 |
pp_die "failed" |
| 5357 |
|
| 5358 |
NVOLS=0 |
| 5359 |
|
| 5360 |
pp_debug "kits: Creating $SUB control file..." |
| 5361 |
|
| 5362 |
sed '1,/^%%/d;/^'"$SUB"'/{p;q;}' < "$KITFILE" > "$pp_wrkdir/kit.line" |
| 5363 |
read _SUB _IGNOR DEPS FLAGS DESC < "$pp_wrkdir/kit.line" |
| 5364 |
if test -z "$_SUB"; then |
| 5365 |
pp_warn "No such subset $SUB in $KITFILE" |
| 5366 |
continue |
| 5367 |
fi |
| 5368 |
DEPS=`echo $DEPS | tr '|' ' '` |
| 5369 |
case $FLAGS in |
| 5370 |
FLGEXP*) pp_verbose FLAGS='"${'"$FLAGS"'}"' ;; |
| 5371 |
esac |
| 5372 |
case $DESC in |
| 5373 |
*%*) DESC=`echo $DESC|awk -F% '{printf "%-36s%%%s\n", $1, $2}'`;; |
| 5374 |
esac |
| 5375 |
|
| 5376 |
cat > "$INSTCTRL/$CTRL" <<-. |
| 5377 |
NAME='$NAME $SUB' |
| 5378 |
DESC=$DESC |
| 5379 |
ROOTSIZE=$ROOTSIZE |
| 5380 |
USRSIZE=$USRSIZE |
| 5381 |
VARSIZE=$VARSIZE |
| 5382 |
NVOLS=1:$NVOLS |
| 5383 |
MTLOC=1:$TLOC |
| 5384 |
DEPS="$DEPS" |
| 5385 |
FLAGS=$FLAGS |
| 5386 |
. |
| 5387 |
chmod 664 "$INSTCTRL/$CTRL" |
| 5388 |
|
| 5389 |
pp_debug "kits: Making tar image" |
| 5390 |
|
| 5391 |
pp_verbose tar cfPR "$TODIR/$SUB" "$FROMDIR/" "$TSSUB" || |
| 5392 |
pp_error "problem creating kit file" |
| 5393 |
|
| 5394 |
if $COMPRESS; then |
| 5395 |
pp_debug "kits: Compressing" |
| 5396 |
(cd "$TODIR" && compress -f -v "$SUB") || |
| 5397 |
pp_die "problem compressing $TODIR/$SUB" |
| 5398 |
SPC=`expr $SUB : '\(...\).*'` # first three characters |
| 5399 |
SVC=`expr $SUB : '.*\(...\)'` # last three characters |
| 5400 |
: > "$INSTCTRL/$SPC$SVC.comp" |
| 5401 |
chmod 664 "$INSTCTRL/$SPC$SVC.comp" |
| 5402 |
pp_debug "kits: Padding compressed file to 10kB" # wtf? |
| 5403 |
rm -f "$TODIR/$SUB" |
| 5404 |
pp_verbose \ |
| 5405 |
dd if="$TODIR/$SUB.Z" of="$TODIR/$SUB" bs=10k conv=sync || |
| 5406 |
pp_die "problem moving compressed file" |
| 5407 |
rm -f "$TODIR/$SUB.Z" |
| 5408 |
fi |
| 5409 |
chmod 664 "$TODIR/$SUB" |
| 5410 |
|
| 5411 |
if test -f "$SCPDIR/$SUB.scp"; then |
| 5412 |
cp "$SCPDIR/$SUB.scp" "$INSTCTRL/$SUB.scp" |
| 5413 |
chmod 755 "$INSTCTRL/$SUB.scp" |
| 5414 |
else |
| 5415 |
pp_debug "kits: null subset control program for $SUB" |
| 5416 |
: > "$INSTCTRL/$SUB.scp" |
| 5417 |
chmod 744 "$INSTCTRL/$SUB.scp" |
| 5418 |
fi |
| 5419 |
|
| 5420 |
pp_debug "kits: Finished creating media image for $SUB" |
| 5421 |
done |
| 5422 |
|
| 5423 |
pp_debug "kits: Creating $CODE.image" |
| 5424 |
|
| 5425 |
case "$ROOT" in |
| 5426 |
*ROOT) ALLSUBS="$ROOT $ALLSUBS" |
| 5427 |
;; |
| 5428 |
esac |
| 5429 |
|
| 5430 |
(cd "$TODIR" && sum $ALLSUBS) > "$INSTCTRL/$CODE.image" |
| 5431 |
chmod 664 "$INSTTRL/$CODE.image" |
| 5432 |
pp_debug "kits: Creating INSTCTRL" |
| 5433 |
(cd "$INSTCTRL" && tar cpvf - *) > "$TODIR/INSTCTRL" |
| 5434 |
chmod 664 "$TODIR/INSTCTRL" |
| 5435 |
cp "$INSTCTRL/$CODE.image" "$TODIR/$CODE.image" |
| 5436 |
chmod 664 "$TODIR/$CODE.image" |
| 5437 |
|
| 5438 |
pp_debug "kits: Media image production complete" |
| 5439 |
} |
| 5440 |
|
| 5441 |
pp_platforms="$pp_platforms rpm" |
| 5442 |
|
| 5443 |
pp_backend_rpm_detect () { |
| 5444 |
test x"$1" = x"Linux" -a ! -f /etc/debian_version |
| 5445 |
} |
| 5446 |
|
| 5447 |
pp_backend_rpm_init () { |
| 5448 |
|
| 5449 |
pp_rpm_version= |
| 5450 |
pp_rpm_summary= |
| 5451 |
pp_rpm_description= |
| 5452 |
pp_rpm_group="Applications/Internet" |
| 5453 |
pp_rpm_license="Unspecified" |
| 5454 |
pp_rpm_vendor= |
| 5455 |
pp_rpm_url= |
| 5456 |
pp_rpm_packager= |
| 5457 |
pp_rpm_provides= |
| 5458 |
pp_rpm_requires= |
| 5459 |
pp_rpm_requires_pre= |
| 5460 |
pp_rpm_requires_post= |
| 5461 |
pp_rpm_requires_preun= |
| 5462 |
pp_rpm_requires_postun= |
| 5463 |
pp_rpm_release= |
| 5464 |
pp_rpm_epoch= |
| 5465 |
pp_rpm_dev_group="Development/Libraries" |
| 5466 |
pp_rpm_dbg_group="Development/Tools" |
| 5467 |
pp_rpm_doc_group="Documentation" |
| 5468 |
pp_rpm_dev_description= |
| 5469 |
pp_rpm_dbg_description= |
| 5470 |
pp_rpm_doc_description= |
| 5471 |
pp_rpm_dev_requires= |
| 5472 |
pp_rpm_dev_requires_pre= |
| 5473 |
pp_rpm_dev_requires_post= |
| 5474 |
pp_rpm_dev_requires_preun= |
| 5475 |
pp_rpm_dev_requires_postun= |
| 5476 |
pp_rpm_dbg_requires= |
| 5477 |
pp_rpm_dbg_requires_pre= |
| 5478 |
pp_rpm_dbg_requires_post= |
| 5479 |
pp_rpm_dbg_requires_preun= |
| 5480 |
pp_rpm_dbg_requires_postun= |
| 5481 |
pp_rpm_doc_requires= |
| 5482 |
pp_rpm_doc_requires_pre= |
| 5483 |
pp_rpm_doc_requires_post= |
| 5484 |
pp_rpm_doc_requires_preun= |
| 5485 |
pp_rpm_doc_requires_postun= |
| 5486 |
pp_rpm_dev_provides= |
| 5487 |
pp_rpm_dbg_provides= |
| 5488 |
pp_rpm_doc_provides= |
| 5489 |
|
| 5490 |
pp_rpm_autoprov= |
| 5491 |
pp_rpm_autoreq= |
| 5492 |
pp_rpm_autoreqprov= |
| 5493 |
|
| 5494 |
pp_rpm_dbg_pkgname=debug |
| 5495 |
pp_rpm_dev_pkgname=devel |
| 5496 |
pp_rpm_doc_pkgname=doc |
| 5497 |
|
| 5498 |
pp_rpm_defattr_uid=root |
| 5499 |
pp_rpm_defattr_gid=root |
| 5500 |
|
| 5501 |
pp_rpm_detect_arch |
| 5502 |
pp_rpm_detect_distro |
| 5503 |
pp_rpm_rpmbuild=`pp_rpm_detect_rpmbuild` |
| 5504 |
|
| 5505 |
# SLES8 doesn't always come with readlink |
| 5506 |
test -x /usr/bin/readlink -o -x /bin/readlink || |
| 5507 |
pp_readlink_fn=pp_ls_readlink |
| 5508 |
} |
| 5509 |
|
| 5510 |
pp_rpm_detect_arch () { |
| 5511 |
pp_rpm_arch=auto |
| 5512 |
|
| 5513 |
#-- Find the default native architecture that RPM is configured to use |
| 5514 |
cat <<-. >$pp_wrkdir/dummy.spec |
| 5515 |
Name: dummy |
| 5516 |
Version: 1 |
| 5517 |
Release: 1 |
| 5518 |
Summary: dummy |
| 5519 |
Group: ${pp_rpm_group} |
| 5520 |
License: ${pp_rpm_license} |
| 5521 |
%description |
| 5522 |
dummy |
| 5523 |
. |
| 5524 |
$pp_opt_debug && cat $pp_wrkdir/dummy.spec |
| 5525 |
pp_rpm_arch_local=`rpm -q --qf '%{arch}\n' --specfile $pp_wrkdir/dummy.spec` |
| 5526 |
rm $pp_wrkdir/dummy.spec |
| 5527 |
|
| 5528 |
#-- Ask the kernel what machine architecture is in use |
| 5529 |
local arch |
| 5530 |
for arch in "`uname -m`" "`uname -p`"; do |
| 5531 |
case "$arch" in |
| 5532 |
i?86) |
| 5533 |
pp_rpm_arch_std=i386 |
| 5534 |
break |
| 5535 |
;; |
| 5536 |
x86_64|ppc|ppc64|ppc64le|ia64|s390|s390x) |
| 5537 |
pp_rpm_arch_std="$arch" |
| 5538 |
break |
| 5539 |
;; |
| 5540 |
powerpc) |
| 5541 |
# Probably AIX |
| 5542 |
case "`/usr/sbin/lsattr -El proc0 -a type -F value`" in |
| 5543 |
PowerPC_POWER*) pp_rpm_arch_std=ppc64;; |
| 5544 |
*) pp_rpm_arch_std=ppc;; |
| 5545 |
esac |
| 5546 |
break |
| 5547 |
;; |
| 5548 |
*) pp_rpm_arch_std=unknown |
| 5549 |
;; |
| 5550 |
esac |
| 5551 |
done |
| 5552 |
|
| 5553 |
#-- Later on, when files are processed, we use 'file' to determine |
| 5554 |
# what platform ABIs are used. This is used when pp_rpm_arch == auto |
| 5555 |
pp_rpm_arch_seen= |
| 5556 |
} |
| 5557 |
|
| 5558 |
pp_rpm_detect_distro () { |
| 5559 |
pp_rpm_distro= |
| 5560 |
if test -f /etc/whitebox-release; then |
| 5561 |
pp_rpm_distro=`awk ' |
| 5562 |
/^White Box Enterprise Linux release/ { print "wbel" $6; exit; } |
| 5563 |
' /etc/whitebox-release` |
| 5564 |
elif test -f /etc/mandrakelinux-release; then |
| 5565 |
pp_rpm_distro=`awk ' |
| 5566 |
/^Mandrakelinux release/ { print "mand" $3; exit; } |
| 5567 |
' /etc/mandrake-release` |
| 5568 |
elif test -f /etc/mandrake-release; then |
| 5569 |
pp_rpm_distro=`awk ' |
| 5570 |
/^Linux Mandrake release/ { print "mand" $4; exit; } |
| 5571 |
/^Mandrake Linux release/ { print "mand" $4; exit; } |
| 5572 |
' /etc/mandrake-release` |
| 5573 |
elif test -f /etc/fedora-release; then |
| 5574 |
pp_rpm_distro=`awk ' |
| 5575 |
/^Fedora Core release/ { print "fc" $4; exit; } |
| 5576 |
/^Fedora release/ { print "f" $3; exit; } |
| 5577 |
' /etc/fedora-release` |
| 5578 |
elif test -f /etc/redhat-release; then |
| 5579 |
pp_rpm_distro=`sed -n \ |
| 5580 |
-e 's/^Red Hat Linux.*release \([0-9][0-9\.]*\).*/rh\1/p' \ |
| 5581 |
-e 's/^Red Hat Enterprise Linux.*release \([0-9][0-9\.]*\).*/rhel\1/p' \ |
| 5582 |
-e 's/^Rocky Linux.*release \([0-9][0-9\.]*\).*/rhel\1/p' \ |
| 5583 |
-e 's/^AlmaLinux.*release \([0-9][0-9\.]*\).*/rhel\1/p' \ |
| 5584 |
-e 's/^CentOS.*release \([0-9]\{1,\}\)\(\.[0-9]*\)\{0,1\}.*/centos\1\2/p' \ |
| 5585 |
/etc/redhat-release` |
| 5586 |
elif test -f /etc/SuSE-release; then |
| 5587 |
pp_rpm_distro=`awk ' |
| 5588 |
/^SuSE Linux [0-9]/ { print "suse" $3; exit; } |
| 5589 |
/^SUSE LINUX [0-9]/ { print "suse" $3; exit; } |
| 5590 |
/^openSUSE [0-9]/ { print "suse" $2; exit; } |
| 5591 |
/^S[uU]SE Linux Enterprise Server [0-9]/ { print "sles" $5; exit; } |
| 5592 |
/^S[uU]SE LINUX Enterprise Server [0-9]/ { print "sles" $5; exit; } |
| 5593 |
/^SuSE SLES-[0-9]/ { print "sles" substr($2,6); exit; } |
| 5594 |
' /etc/SuSE-release` |
| 5595 |
elif test -f /etc/os-release; then |
| 5596 |
pp_rpm_distro="`. /etc/os-release && echo \$ID\$VERSION`" |
| 5597 |
elif test -f /etc/pld-release; then |
| 5598 |
pp_rpm_distro=`awk ' |
| 5599 |
/^[^ ]* PLD Linux/ { print "pld" $1; exit; } |
| 5600 |
' /etc/pld-release` |
| 5601 |
elif test X"`uname -s 2>/dev/null`" = X"AIX"; then |
| 5602 |
local r v |
| 5603 |
r=`uname -r` |
| 5604 |
v=`uname -v` |
| 5605 |
pp_rpm_distro="aix$v$r" |
| 5606 |
fi |
| 5607 |
pp_rpm_distro=`echo $pp_rpm_distro | tr -d .` |
| 5608 |
test -z "$pp_rpm_distro" && |
| 5609 |
pp_warn "unknown distro" |
| 5610 |
} |
| 5611 |
|
| 5612 |
pp_rpm_detect_rpmbuild () { |
| 5613 |
local cmd |
| 5614 |
for cmd in rpmbuild rpm; do |
| 5615 |
if command -v $cmd > /dev/null 2>&1; then |
| 5616 |
echo $cmd |
| 5617 |
return 0 |
| 5618 |
fi |
| 5619 |
done |
| 5620 |
|
| 5621 |
pp_error "Could not find rpmbuild" |
| 5622 |
# Default to `rpmbuild` in case it magically appears |
| 5623 |
echo rpmbuild |
| 5624 |
return 1 |
| 5625 |
} |
| 5626 |
|
| 5627 |
pp_rpm_label () { |
| 5628 |
local label arg |
| 5629 |
label="$1"; shift |
| 5630 |
for arg |
| 5631 |
do |
| 5632 |
test -z "$arg" || echo "$label: $arg" |
| 5633 |
done |
| 5634 |
} |
| 5635 |
|
| 5636 |
pp_rpm_writefiles () { |
| 5637 |
local _l t m o g f p st fo farch |
| 5638 |
while read t m o g f p st; do |
| 5639 |
_l="$p" |
| 5640 |
test $t = d && _l="%dir ${_l%/}/" |
| 5641 |
if test $t = s; then |
| 5642 |
# rpm warns if %attr contains a mode for symlinks |
| 5643 |
m=- |
| 5644 |
elif test x"$m" = x"-"; then |
| 5645 |
case "$t" in |
| 5646 |
d) m=755;; |
| 5647 |
f) m=644;; |
| 5648 |
esac |
| 5649 |
fi |
| 5650 |
test x"$o" = x"-" && o="${pp_rpm_defattr_uid:-root}" |
| 5651 |
test x"$g" = x"-" && g="${pp_rpm_defattr_gid:-root}" |
| 5652 |
_l="%attr($m,$o,$g) $_l" |
| 5653 |
|
| 5654 |
if test "$t" = "f" -a x"$pp_rpm_arch" = x"auto"; then |
| 5655 |
fo=`file "${pp_destdir}$p" 2>/dev/null` |
| 5656 |
#NB: The following should match executables and shared objects, |
| 5657 |
#relocatable objects. It will not match .a files however. |
| 5658 |
case "$fo" in |
| 5659 |
*": ELF 32-bit LSB "*", Intel 80386"*) |
| 5660 |
farch=i386;; |
| 5661 |
*": ELF 64-bit LSB "*", AMD x86-64"*|\ |
| 5662 |
*": ELF 64-bit LSB "*", x86-64"*) |
| 5663 |
farch=x86_64;; |
| 5664 |
*": ELF 32-bit MSB "*", PowerPC"*) |
| 5665 |
farch=ppc;; |
| 5666 |
*": ELF 64-bit LSB "*", 64-bit PowerPC"*) |
| 5667 |
farch=ppc64le;; |
| 5668 |
*": ELF 64-bit MSB "*", 64-bit PowerPC"*) |
| 5669 |
farch=ppc64;; |
| 5670 |
*": ELF 64-bit LSB "*", IA-64"*) |
| 5671 |
farch=ia64;; |
| 5672 |
*": ELF 32-bit MSB "*", IBM S/390"*) |
| 5673 |
farch=s390;; |
| 5674 |
*": ELF 64-bit MSB "*", IBM S/390"*) |
| 5675 |
farch=s390x;; |
| 5676 |
*"executable (RISC System/6000)"*) |
| 5677 |
farch=ppc;; |
| 5678 |
*"64-bit XCOFF executable"*) |
| 5679 |
farch=ppc64;; |
| 5680 |
*": ELF 64-bit LSB "*", ARM aarch64"*) |
| 5681 |
farch=aarch64;; |
| 5682 |
*" ELF "*) |
| 5683 |
farch=ELF;; |
| 5684 |
*) |
| 5685 |
farch=noarch;; |
| 5686 |
esac |
| 5687 |
# If file(1) doesn't provide enough info, try readelf(1) |
| 5688 |
if test "$farch" = "ELF"; then |
| 5689 |
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` |
| 5690 |
case "$fo" in |
| 5691 |
"ELF32 Intel 80386") |
| 5692 |
farch=i386;; |
| 5693 |
"ELF64 "*[xX]"86-64") |
| 5694 |
farch=x86_64;; |
| 5695 |
"ELF32 PowerPC") |
| 5696 |
farch=ppc;; |
| 5697 |
"ELF64 PowerPC"*) |
| 5698 |
farch=ppc64;; |
| 5699 |
"ELF64 IA-64") |
| 5700 |
farch=ia64;; |
| 5701 |
"ELF32 IBM S/390") |
| 5702 |
farch=s390;; |
| 5703 |
"ELF64 IBM S/390") |
| 5704 |
farch=s390x;; |
| 5705 |
"ELF64 AArch64") |
| 5706 |
farch=aarch64;; |
| 5707 |
*) |
| 5708 |
farch=noarch;; |
| 5709 |
esac |
| 5710 |
fi |
| 5711 |
pp_debug "file: $fo -> $farch" |
| 5712 |
test x"$farch" = x"noarch" || pp_add_to_list pp_rpm_arch_seen $farch |
| 5713 |
fi |
| 5714 |
|
| 5715 |
case $f in |
| 5716 |
*v*) _l="%config(noreplace) $_l";; |
| 5717 |
*m*) _l="%config(missingok) $_l";; |
| 5718 |
esac |
| 5719 |
echo "$_l" |
| 5720 |
done |
| 5721 |
echo |
| 5722 |
} |
| 5723 |
|
| 5724 |
pp_rpm_subname () { |
| 5725 |
case "$1" in |
| 5726 |
run) : ;; |
| 5727 |
dbg) echo "${2}${pp_rpm_dbg_pkgname}";; |
| 5728 |
dev) echo "${2}${pp_rpm_dev_pkgname}";; |
| 5729 |
doc) echo "${2}${pp_rpm_doc_pkgname}";; |
| 5730 |
*) pp_error "unknown component '$1'"; |
| 5731 |
esac |
| 5732 |
} |
| 5733 |
|
| 5734 |
pp_rpm_depend () { |
| 5735 |
local _name _vers |
| 5736 |
while read _name _vers; do |
| 5737 |
case "$_name" in ""| "#"*) continue ;; esac |
| 5738 |
echo "Requires: $_name ${_vers:+>= $_vers}" |
| 5739 |
done |
| 5740 |
} |
| 5741 |
|
| 5742 |
pp_rpm_conflict () { |
| 5743 |
local _name _vers |
| 5744 |
while read _name _vers; do |
| 5745 |
case "$_name" in ""| "#"*) continue ;; esac |
| 5746 |
echo "Conflicts: $_name ${_vers:+>= $_vers}" |
| 5747 |
done |
| 5748 |
} |
| 5749 |
|
| 5750 |
pp_rpm_override_requires () { |
| 5751 |
local orig_find_requires |
| 5752 |
|
| 5753 |
if test -z "$pp_rpm_depend_filter_cmd"; then |
| 5754 |
return 0 |
| 5755 |
fi |
| 5756 |
|
| 5757 |
orig_find_requires=`rpm --eval '%{__find_requires}'` |
| 5758 |
cat << EOF > "$pp_wrkdir/filtered-find-requires" |
| 5759 |
$orig_find_requires \$@ | $pp_rpm_depend_filter_cmd |
| 5760 |
EOF |
| 5761 |
chmod +x "$pp_wrkdir/filtered-find-requires" |
| 5762 |
echo "%define __find_requires $pp_wrkdir/filtered-find-requires" |
| 5763 |
# Might be necessary for old versions of RPM? Not for 4.4.2. |
| 5764 |
#echo "%define _use_internal_dependency_generator 0" |
| 5765 |
} |
| 5766 |
|
| 5767 |
pp_backend_rpm () { |
| 5768 |
local cmp specfile _summary _group _desc _pkg _subname svc _script |
| 5769 |
|
| 5770 |
specfile=$pp_wrkdir/$name.spec |
| 5771 |
: > $specfile |
| 5772 |
|
| 5773 |
#-- force existence of a 'run' component |
| 5774 |
pp_add_component run |
| 5775 |
: >> $pp_wrkdir/%files.run |
| 5776 |
|
| 5777 |
if test -z "$pp_rpm_arch"; then |
| 5778 |
pp_error "Unknown RPM architecture" |
| 5779 |
return 1 |
| 5780 |
fi |
| 5781 |
|
| 5782 |
#-- Write the header components of the RPM spec file |
| 5783 |
cat <<-. >>$specfile |
| 5784 |
Name: ${pp_rpm_name:-$name} |
| 5785 |
Version: ${pp_rpm_version:-$version} |
| 5786 |
Release: ${pp_rpm_release:-1} |
| 5787 |
Summary: ${pp_rpm_summary:-$summary} |
| 5788 |
Group: ${pp_rpm_group} |
| 5789 |
License: ${pp_rpm_license} |
| 5790 |
. |
| 5791 |
pp_rpm_label "URL" "$pp_rpm_url" >>$specfile |
| 5792 |
pp_rpm_label "Vendor" "${pp_rpm_vendor:-$vendor}" >>$specfile |
| 5793 |
pp_rpm_label "Packager" "$pp_rpm_packager" >>$specfile |
| 5794 |
pp_rpm_label "Provides" "$pp_rpm_provides" >>$specfile |
| 5795 |
pp_rpm_label "Requires(pre)" "$pp_rpm_requires_pre" >>$specfile |
| 5796 |
pp_rpm_label "Requires(post)" "$pp_rpm_requires_post" >>$specfile |
| 5797 |
pp_rpm_label "Requires(preun)" "$pp_rpm_requires_preun" >>$specfile |
| 5798 |
pp_rpm_label "Requires(postun)" "$pp_rpm_requires_postun" >>$specfile |
| 5799 |
pp_rpm_label "AutoProv" "$pp_rpm_autoprov" >>$specfile |
| 5800 |
pp_rpm_label "AutoReq" "$pp_rpm_autoreq" >>$specfile |
| 5801 |
pp_rpm_label "AutoReqProv" "$pp_rpm_autoreqprov" >>$specfile |
| 5802 |
|
| 5803 |
test -n "$pp_rpm_serial" && pp_warn "pp_rpm_serial deprecated" |
| 5804 |
if test -n "$pp_rpm_epoch"; then |
| 5805 |
#-- Epoch was introduced in RPM 2.5.6 |
| 5806 |
case `$pp_rpm_rpmbuild --version 2>/dev/null` in |
| 5807 |
1.*|2.[0-5].*|2.5.[0-5]) |
| 5808 |
pp_rpm_label "Serial" $pp_rpm_epoch >>$specfile;; |
| 5809 |
*) |
| 5810 |
pp_rpm_label "Epoch" $pp_rpm_epoch >>$specfile;; |
| 5811 |
esac |
| 5812 |
fi |
| 5813 |
|
| 5814 |
if test -n "$pp_rpm_requires"; then |
| 5815 |
pp_rpm_label "Requires" "$pp_rpm_requires" >>$specfile |
| 5816 |
elif test -s $pp_wrkdir/%depend.run; then |
| 5817 |
pp_rpm_depend < $pp_wrkdir/%depend.run >> $specfile |
| 5818 |
fi |
| 5819 |
if test -s $pp_wrkdir/%conflict.run; then |
| 5820 |
pp_rpm_conflict < $pp_wrkdir/%conflict.run >> $specfile |
| 5821 |
fi |
| 5822 |
|
| 5823 |
pp_rpm_override_requires >> $specfile |
| 5824 |
|
| 5825 |
cat <<-. >>$specfile |
| 5826 |
|
| 5827 |
%description |
| 5828 |
${pp_rpm_description:-$description} |
| 5829 |
. |
| 5830 |
|
| 5831 |
for cmp in $pp_components; do |
| 5832 |
case $cmp in |
| 5833 |
run) continue;; |
| 5834 |
dev) _summary="development tools for $pp_rpm_summary" |
| 5835 |
_group="$pp_rpm_dev_group" |
| 5836 |
_desc="${pp_rpm_dev_description:-Development libraries for $name. $pp_rpm_description.}" |
| 5837 |
;; |
| 5838 |
doc) _summary="documentation for $pp_rpm_summary" |
| 5839 |
_group="$pp_rpm_doc_group" |
| 5840 |
_desc="${pp_rpm_doc_description:-Documentation for $name. $pp_rpm_description.}" |
| 5841 |
;; |
| 5842 |
dbg) _summary="diagnostic tools for $pp_rpm_summary" |
| 5843 |
_group="$pp_rpm_dbg_group" |
| 5844 |
_desc="${pp_rpm_dbg_description:-Diagnostic tools for $name.}" |
| 5845 |
;; |
| 5846 |
esac |
| 5847 |
|
| 5848 |
_subname=`pp_rpm_subname $cmp` |
| 5849 |
cat <<-. |
| 5850 |
|
| 5851 |
%package $_subname |
| 5852 |
Summary: $name $_summary |
| 5853 |
Group: $_group |
| 5854 |
. |
| 5855 |
for _script in pre post preun postun; do |
| 5856 |
eval '_pkg="$pp_rpm_'$cmp'_requires_'$_script'"' |
| 5857 |
if test -n "$_pkg"; then |
| 5858 |
eval pp_rpm_label "Requires($_script)" $_pkg |
| 5859 |
fi |
| 5860 |
done |
| 5861 |
eval '_pkg="$pp_rpm_'$cmp'_requires"' |
| 5862 |
if test -n "$_pkg"; then |
| 5863 |
eval pp_rpm_label Requires ${pp_rpm_name:-$name} $_pkg |
| 5864 |
elif test -s $pp_wrkdir/%depend.$cmp; then |
| 5865 |
pp_rpm_depend < $pp_wrkdir/%depend.$cmp >> $specfile |
| 5866 |
fi |
| 5867 |
if test -s $pp_wrkdir/%conflict.$cmp; then |
| 5868 |
pp_rpm_conflict < $pp_wrkdir/%conflict.$cmp >> $specfile |
| 5869 |
fi |
| 5870 |
|
| 5871 |
eval '_pkg="$pp_rpm_'$cmp'_provides"' |
| 5872 |
eval pp_rpm_label Provides $_pkg |
| 5873 |
|
| 5874 |
cat <<-. |
| 5875 |
|
| 5876 |
%description $_subname |
| 5877 |
$_desc |
| 5878 |
. |
| 5879 |
done >>$specfile |
| 5880 |
|
| 5881 |
#-- NB: we do not put any %prep, %build or %install RPM sections |
| 5882 |
# into the spec file. |
| 5883 |
|
| 5884 |
#-- add service start/stop code |
| 5885 |
if test -n "$pp_services"; then |
| 5886 |
pp_rpm_service_install_common >> $pp_wrkdir/%post.run |
| 5887 |
|
| 5888 |
#-- record the uninstall commands in reverse order |
| 5889 |
for svc in $pp_services; do |
| 5890 |
pp_load_service_vars $svc |
| 5891 |
|
| 5892 |
pp_rpm_service_make_service_files $svc || |
| 5893 |
pp_error "could not create service files for $svc" |
| 5894 |
|
| 5895 |
#-- append %post code to install the svc |
| 5896 |
pp_rpm_service_install $svc >> $pp_wrkdir/%post.run |
| 5897 |
|
| 5898 |
#-- prepend %preun code to uninstall svc |
| 5899 |
# (use files in case vars are modified) |
| 5900 |
pp_rpm_service_remove $svc | pp_prepend $pp_wrkdir/%preun.run |
| 5901 |
done |
| 5902 |
|
| 5903 |
pp_rpm_service_remove_common | pp_prepend $pp_wrkdir/%preun.run |
| 5904 |
fi |
| 5905 |
|
| 5906 |
# make convenience service groups |
| 5907 |
if test -n "$pp_service_groups"; then |
| 5908 |
for grp in $pp_service_groups; do |
| 5909 |
pp_rpm_service_group_make_init_script \ |
| 5910 |
$grp "`pp_service_get_svc_group $grp`" |
| 5911 |
done |
| 5912 |
fi |
| 5913 |
|
| 5914 |
#-- Write the RPM %file sections |
| 5915 |
# (do this after services, since services adds to %files.run) |
| 5916 |
for cmp in $pp_components; do |
| 5917 |
_subname=`pp_rpm_subname $cmp` |
| 5918 |
|
| 5919 |
if test -s $pp_wrkdir/%check.$cmp; then |
| 5920 |
echo "" |
| 5921 |
echo "%pre $_subname" |
| 5922 |
cat $pp_wrkdir/%check.$cmp |
| 5923 |
echo : # causes script to exit true by default |
| 5924 |
fi |
| 5925 |
|
| 5926 |
if test -s $pp_wrkdir/%files.$cmp; then |
| 5927 |
echo "" |
| 5928 |
echo "%files $_subname" |
| 5929 |
pp_rpm_writefiles < $pp_wrkdir/%files.$cmp |
| 5930 |
fi |
| 5931 |
|
| 5932 |
if test -n "$pp_rpm_ghost"; then |
| 5933 |
for ghost in $pp_rpm_ghost; do |
| 5934 |
echo "%ghost $ghost" |
| 5935 |
done |
| 5936 |
fi |
| 5937 |
|
| 5938 |
if test -s $pp_wrkdir/%pre.$cmp; then |
| 5939 |
echo "" |
| 5940 |
echo "%pre $_subname" |
| 5941 |
cat $pp_wrkdir/%pre.$cmp |
| 5942 |
echo : # causes script to exit true |
| 5943 |
fi |
| 5944 |
|
| 5945 |
if test -s $pp_wrkdir/%post.$cmp; then |
| 5946 |
echo "" |
| 5947 |
echo "%post $_subname" |
| 5948 |
cat $pp_wrkdir/%post.$cmp |
| 5949 |
echo : # causes script to exit true |
| 5950 |
fi |
| 5951 |
|
| 5952 |
if test -s $pp_wrkdir/%preun.$cmp; then |
| 5953 |
echo "" |
| 5954 |
echo "%preun $_subname" |
| 5955 |
cat $pp_wrkdir/%preun.$cmp |
| 5956 |
echo : # causes script to exit true |
| 5957 |
fi |
| 5958 |
|
| 5959 |
if test -s $pp_wrkdir/%postun.$cmp; then |
| 5960 |
echo "" |
| 5961 |
echo "%postun $_subname" |
| 5962 |
cat $pp_wrkdir/%postun.$cmp |
| 5963 |
echo : # causes script to exit true |
| 5964 |
fi |
| 5965 |
done >>$specfile |
| 5966 |
|
| 5967 |
#-- create a suitable work area for rpmbuild |
| 5968 |
cat <<-. >$pp_wrkdir/.rpmmacros |
| 5969 |
%_topdir $pp_wrkdir |
| 5970 |
# XXX Note escaped %% for use in headerSprintf |
| 5971 |
%_rpmfilename %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm |
| 5972 |
. |
| 5973 |
mkdir $pp_wrkdir/RPMS |
| 5974 |
mkdir $pp_wrkdir/BUILD |
| 5975 |
|
| 5976 |
if test x"$pp_rpm_arch" = x"auto"; then |
| 5977 |
#-- Reduce the arch_seen list to exactly one item |
| 5978 |
case "$pp_rpm_arch_seen" in |
| 5979 |
"i386 x86_64"|"x86_64 i386") |
| 5980 |
pp_rpm_arch_seen=x86_64;; |
| 5981 |
*"s390 s390x"* | *"s390x s390"* ) |
| 5982 |
pp_rpm_arch_seen=s390x;; |
| 5983 |
*"aarch64"* ) |
| 5984 |
pp_rpm_arch_seen=aarch64;; |
| 5985 |
*" "*) |
| 5986 |
pp_error "detected multiple targets: $pp_rpm_arch_seen" |
| 5987 |
pp_rpm_arch_seen=unknown;; # not detected |
| 5988 |
"") |
| 5989 |
pp_warn "detected no binaries: using target noarch" |
| 5990 |
pp_rpm_arch_seen=noarch;; |
| 5991 |
*) |
| 5992 |
pp_debug "detected architecture $pp_rpm_arch_seen" |
| 5993 |
esac |
| 5994 |
pp_rpm_arch="$pp_rpm_arch_seen" |
| 5995 |
fi |
| 5996 |
|
| 5997 |
. $pp_wrkdir/%fixup |
| 5998 |
|
| 5999 |
$pp_opt_debug && cat $specfile |
| 6000 |
|
| 6001 |
pp_debug "creating: `pp_backend_rpm_names`" |
| 6002 |
|
| 6003 |
pp_debug "pp_rpm_arch_seen = <${pp_rpm_arch_seen}>" |
| 6004 |
pp_debug "pp_rpm_arch = <${pp_rpm_arch}>" |
| 6005 |
|
| 6006 |
HOME=$pp_wrkdir \ |
| 6007 |
pp_verbose \ |
| 6008 |
$pp_rpm_rpmbuild -bb \ |
| 6009 |
--buildroot="$pp_destdir/" \ |
| 6010 |
--target="${pp_rpm_arch}" \ |
| 6011 |
--define='_unpackaged_files_terminate_build 0' \ |
| 6012 |
--define='_use_internal_dependency_generator 0' \ |
| 6013 |
`$pp_opt_debug && echo --verbose || echo --quiet` \ |
| 6014 |
$pp_rpm_rpmbuild_extra_flags \ |
| 6015 |
$specfile || |
| 6016 |
pp_error "Problem creating RPM packages" |
| 6017 |
|
| 6018 |
for f in `pp_backend_rpm_names`; do |
| 6019 |
# The package might be in an arch-specific subdir |
| 6020 |
pkgfile=not-found |
| 6021 |
for dir in $pp_wrkdir/RPMS/${pp_rpm_arch} $pp_wrkdir/RPMS; do |
| 6022 |
if test -f $dir/$f; then |
| 6023 |
pkgfile=$dir/$f |
| 6024 |
fi |
| 6025 |
done |
| 6026 |
if test x"$pkgfile" = x"not-found"; then |
| 6027 |
pp_error "Problem predicting RPM filename: $f" |
| 6028 |
else |
| 6029 |
ln $pkgfile $pp_wrkdir/$f |
| 6030 |
fi |
| 6031 |
done |
| 6032 |
} |
| 6033 |
|
| 6034 |
pp_rpm_output_name () { |
| 6035 |
echo "${pp_rpm_name:-$name}`pp_rpm_subname "$1" -`-${pp_rpm_version:-$version}-${pp_rpm_release:-1}.${pp_rpm_arch}.rpm" |
| 6036 |
} |
| 6037 |
|
| 6038 |
pp_backend_rpm_names () { |
| 6039 |
local cmp _subname |
| 6040 |
for cmp in $pp_components; do |
| 6041 |
pp_rpm_output_name $cmp |
| 6042 |
done |
| 6043 |
} |
| 6044 |
|
| 6045 |
pp_backend_rpm_cleanup () { |
| 6046 |
: |
| 6047 |
} |
| 6048 |
|
| 6049 |
pp_rpm_print_requires () { |
| 6050 |
local _subname _name |
| 6051 |
|
| 6052 |
echo "CPU:$pp_rpm_arch" |
| 6053 |
## XXX should be lines of the form (from file/ldd/objdump) |
| 6054 |
# EXEC:/bin/sh |
| 6055 |
# RTLD:libc.so.4:open |
| 6056 |
rpm -q --requires -p $pp_wrkdir/`pp_rpm_output_name $1` |sed -e '/^rpmlib(/d;s/ //g;s/^/RPM:/' | sort -u |
| 6057 |
} |
| 6058 |
|
| 6059 |
pp_backend_rpm_install_script () { |
| 6060 |
local cmp _subname |
| 6061 |
|
| 6062 |
echo "#!/bin/sh" |
| 6063 |
pp_install_script_common |
| 6064 |
|
| 6065 |
cat <<. |
| 6066 |
|
| 6067 |
cmp_to_pkgname () { |
| 6068 |
local oi name |
| 6069 |
if test x"\$1" = x"--only-installed"; then |
| 6070 |
#-- only print if installation detected |
| 6071 |
oi=false |
| 6072 |
shift |
| 6073 |
else |
| 6074 |
oi=true |
| 6075 |
fi |
| 6076 |
test x"\$*" = x"all" && |
| 6077 |
set -- $pp_components |
| 6078 |
for cmp |
| 6079 |
do |
| 6080 |
case \$cmp in |
| 6081 |
. |
| 6082 |
for cmp in $pp_components; do |
| 6083 |
_subname=`pp_rpm_subname $cmp -` |
| 6084 |
echo "$cmp) name=${pp_rpm_name:-$name}${_subname};;" |
| 6085 |
done |
| 6086 |
cat <<. |
| 6087 |
*) usage;; |
| 6088 |
esac |
| 6089 |
if \$oi || rpm -q "\$name" >/dev/null 2>/dev/null; then |
| 6090 |
echo "\$name" |
| 6091 |
fi |
| 6092 |
done |
| 6093 |
} |
| 6094 |
|
| 6095 |
|
| 6096 |
cmp_to_pathname () { |
| 6097 |
test x"\$*" = x"all" && |
| 6098 |
set -- $pp_components |
| 6099 |
for cmp |
| 6100 |
do |
| 6101 |
case \$cmp in |
| 6102 |
. |
| 6103 |
for cmp in $pp_components; do |
| 6104 |
echo "$cmp) echo \${PP_PKGDESTDIR:-.}/`pp_rpm_output_name $cmp` ;;" |
| 6105 |
done |
| 6106 |
cat <<. |
| 6107 |
*) usage;; |
| 6108 |
esac |
| 6109 |
done |
| 6110 |
} |
| 6111 |
|
| 6112 |
print_requires () { |
| 6113 |
test x"\$*" = x"all" && |
| 6114 |
set -- $pp_components |
| 6115 |
for cmp |
| 6116 |
do |
| 6117 |
case \$cmp in |
| 6118 |
. |
| 6119 |
for cmp in $pp_components; do |
| 6120 |
echo "$cmp) cat <<'._end'" |
| 6121 |
pp_rpm_print_requires $cmp |
| 6122 |
echo "._end"; echo ';;' |
| 6123 |
done |
| 6124 |
cat <<. |
| 6125 |
*) usage;; |
| 6126 |
esac |
| 6127 |
done |
| 6128 |
} |
| 6129 |
|
| 6130 |
test \$# -eq 0 && usage |
| 6131 |
op="\$1"; shift |
| 6132 |
case "\$op" in |
| 6133 |
list-components) |
| 6134 |
test \$# -eq 0 || usage \$op |
| 6135 |
echo $pp_components |
| 6136 |
;; |
| 6137 |
list-services) |
| 6138 |
test \$# -eq 0 || usage \$op |
| 6139 |
echo $pp_services |
| 6140 |
;; |
| 6141 |
list-files) |
| 6142 |
test \$# -ge 1 || usage \$op |
| 6143 |
cmp_to_pathname "\$@" |
| 6144 |
;; |
| 6145 |
install) |
| 6146 |
test \$# -ge 1 || usage \$op |
| 6147 |
verbose rpm -U --replacepkgs --oldpackage \ |
| 6148 |
\`cmp_to_pathname "\$@"\` |
| 6149 |
;; |
| 6150 |
uninstall) |
| 6151 |
test \$# -ge 1 || usage \$op |
| 6152 |
pkgs=\`cmp_to_pkgname --only-installed "\$@"\` |
| 6153 |
if test -z "\$pkgs"; then |
| 6154 |
verbosemsg "nothing to uninstall" |
| 6155 |
else |
| 6156 |
verbose rpm -e \$pkgs |
| 6157 |
fi |
| 6158 |
;; |
| 6159 |
start|stop) |
| 6160 |
test \$# -ge 1 || usage \$op |
| 6161 |
ec=0 |
| 6162 |
for svc |
| 6163 |
do |
| 6164 |
verbose /etc/init.d/\$svc \$op || ec=1 |
| 6165 |
done |
| 6166 |
exit \$ec |
| 6167 |
;; |
| 6168 |
print-platform) |
| 6169 |
test \$# -eq 0 || usage \$op |
| 6170 |
echo "linux-${pp_rpm_arch}" |
| 6171 |
;; |
| 6172 |
print-requires) |
| 6173 |
test \$# -ge 1 || usage \$op |
| 6174 |
print_requires "\$@" |
| 6175 |
;; |
| 6176 |
*) |
| 6177 |
usage |
| 6178 |
;; |
| 6179 |
esac |
| 6180 |
. |
| 6181 |
|
| 6182 |
} |
| 6183 |
|
| 6184 |
pp_backend_rpm_probe () { |
| 6185 |
echo "${pp_rpm_distro}-${pp_rpm_arch_std}" |
| 6186 |
} |
| 6187 |
|
| 6188 |
pp_backend_rpm_vas_platforms () { |
| 6189 |
case "$pp_rpm_arch_std" in |
| 6190 |
x86_64) echo "linux-x86_64.rpm linux-x86.rpm";; |
| 6191 |
*86) echo "linux-x86.rpm";; |
| 6192 |
s390) echo "linux-s390";; |
| 6193 |
s390x) echo "linux-s390x";; |
| 6194 |
ppc*) echo "linux-glibc23-ppc64 linux-glibc22-ppc64";; |
| 6195 |
ia64) echo "linux-ia64";; |
| 6196 |
*) pp_die "unknown architecture $pp_rpm_arch_std";; |
| 6197 |
esac |
| 6198 |
} |
| 6199 |
|
| 6200 |
pp_rpm_service_install_common () { |
| 6201 |
cat <<-'.' |
| 6202 |
|
| 6203 |
_pp_install_service () { |
| 6204 |
local svc level |
| 6205 |
svc="$1" |
| 6206 |
if [ -x /usr/lib/lsb/install_initd -a ! -r /etc/redhat-release ] |
| 6207 |
then |
| 6208 |
# LSB-style install |
| 6209 |
/usr/lib/lsb/install_initd /etc/init.d/$svc &> /dev/null |
| 6210 |
elif [ -x /sbin/chkconfig ]; then |
| 6211 |
# Red Hat/chkconfig-style install |
| 6212 |
/sbin/chkconfig --add $svc &> /dev/null |
| 6213 |
/sbin/chkconfig $svc off &> /dev/null |
| 6214 |
else |
| 6215 |
: # manual links under /etc/init.d |
| 6216 |
fi |
| 6217 |
} |
| 6218 |
|
| 6219 |
_pp_enable_service () { |
| 6220 |
local svc level |
| 6221 |
svc="$1" |
| 6222 |
if [ -x /usr/lib/lsb/install_initd -a ! -r /etc/redhat-release ] |
| 6223 |
then |
| 6224 |
# LSB-style install |
| 6225 |
: # not sure how to enable |
| 6226 |
elif [ -x /sbin/chkconfig ]; then |
| 6227 |
# Red Hat/chkconfig-style install |
| 6228 |
/sbin/chkconfig $svc on &> /dev/null |
| 6229 |
else |
| 6230 |
# manual install |
| 6231 |
set -- `sed -n -e 's/^# Default-Start://p' /etc/init.d/$svc` |
| 6232 |
start_priority=`sed -n -e 's/^# X-Quest-Start-Priority:[[:space:]]*//p' /etc/init.d/$svc` |
| 6233 |
stop_priority=`sed -n -e 's/^# X-Quest-Stop-Priority:[[:space:]]*//p' /etc/init.d/$svc` |
| 6234 |
|
| 6235 |
# Provide default start & stop priorities of 20 & 80 in |
| 6236 |
# accordance with Debian update-rc.d defaults |
| 6237 |
if [ -z "$start_priority" ]; then |
| 6238 |
start_priority=20 |
| 6239 |
fi |
| 6240 |
if [ -z "$stop_priority" ]; then |
| 6241 |
stop_priority=80 |
| 6242 |
fi |
| 6243 |
|
| 6244 |
if [ -d "/etc/rc.d" ];then |
| 6245 |
rcdir=/etc/rc.d |
| 6246 |
else |
| 6247 |
rcdir=/etc |
| 6248 |
fi |
| 6249 |
|
| 6250 |
for level |
| 6251 |
do ln -sf /etc/init.d/$svc $rcdir/rc$level.d/S$start_priority$svc; done |
| 6252 |
set -- `sed -n -e 's/^# Default-Stop://p' /etc/init.d/$svc` |
| 6253 |
for level |
| 6254 |
do ln -sf /etc/init.d/$svc $rcdir/rc$level.d/K$stop_priority$svc; done |
| 6255 |
fi |
| 6256 |
} |
| 6257 |
. |
| 6258 |
pp_systemd_service_install_common |
| 6259 |
} |
| 6260 |
|
| 6261 |
pp_rpm_service_remove_common () { |
| 6262 |
cat <<-'.' |
| 6263 |
|
| 6264 |
_pp_remove_service () { |
| 6265 |
local svc |
| 6266 |
svc="$1" |
| 6267 |
/etc/init.d/$svc stop >/dev/null 2>&1 |
| 6268 |
if [ -x /usr/lib/lsb/remove_initd -a ! -r /etc/redhat-release ] |
| 6269 |
then |
| 6270 |
/usr/lib/lsb/remove_initd /etc/init.d/$svc &> /dev/null |
| 6271 |
elif [ -x /sbin/chkconfig ]; then |
| 6272 |
/sbin/chkconfig --del $svc &> /dev/null |
| 6273 |
else |
| 6274 |
if [ -d "/etc/rc.d" ];then |
| 6275 |
rcdir=/etc/rc.d |
| 6276 |
else |
| 6277 |
rcdir=/etc |
| 6278 |
fi |
| 6279 |
|
| 6280 |
rm -f $rcdir/rc?.d/[SK]??$svc |
| 6281 |
fi |
| 6282 |
} |
| 6283 |
. |
| 6284 |
pp_systemd_service_remove_common |
| 6285 |
} |
| 6286 |
|
| 6287 |
pp_rpm_service_install () { |
| 6288 |
echo "" |
| 6289 |
echo "_pp_systemd_init" |
| 6290 |
echo 'if test -n "$systemctl_cmd"; then' |
| 6291 |
echo " _pp_systemd_install $1" |
| 6292 |
test $enable = yes && echo " _pp_systemd_enable $1" |
| 6293 |
echo "else" |
| 6294 |
echo " _pp_install_service $1" |
| 6295 |
test $enable = yes && echo " _pp_enable_service $1" |
| 6296 |
echo "fi" |
| 6297 |
} |
| 6298 |
|
| 6299 |
pp_rpm_service_remove () { |
| 6300 |
cat <<-. |
| 6301 |
|
| 6302 |
if [ "\$1" = "remove" -o "\$1" = "0" ]; then |
| 6303 |
# only remove the service if not upgrade |
| 6304 |
_pp_remove_service $1 |
| 6305 |
_pp_systemd_disable $1 |
| 6306 |
_pp_systemd_remove $1 |
| 6307 |
fi |
| 6308 |
. |
| 6309 |
} |
| 6310 |
|
| 6311 |
|
| 6312 |
pp_backend_rpm_init_svc_vars () { |
| 6313 |
|
| 6314 |
reload_signal= |
| 6315 |
start_runlevels=${pp_rpm_default_start_runlevels-"2 3 4 5"} # == lsb default-start |
| 6316 |
stop_runlevels=${pp_rpm_default_stop_runlevels-"0 1 6"} # == lsb default-stop |
| 6317 |
svc_description="${pp_rpm_default_svc_description}" # == lsb short descr |
| 6318 |
svc_process= |
| 6319 |
svc_init_filename="${pp_rpm_svc_init_filename}" # == $svc.init |
| 6320 |
svc_init_filepath="${pp_rpm_svc_init_filepath}" # == /etc/init.d/ by default |
| 6321 |
|
| 6322 |
lsb_required_start='$local_fs $network' |
| 6323 |
lsb_should_start= |
| 6324 |
lsb_required_stop= |
| 6325 |
lsb_description= |
| 6326 |
|
| 6327 |
start_priority=50 |
| 6328 |
stop_priority=50 #-- stop_priority = 100 - start_priority |
| 6329 |
} |
| 6330 |
|
| 6331 |
pp_rpm_service_group_make_init_script () { |
| 6332 |
local grp=$1 |
| 6333 |
local svcs="$2" |
| 6334 |
local script=/etc/init.d/$grp |
| 6335 |
local out=$pp_destdir$script |
| 6336 |
|
| 6337 |
pp_add_file_if_missing $script run 755 m || return 0 |
| 6338 |
|
| 6339 |
cat <<-. >>$out |
| 6340 |
#!/bin/sh |
| 6341 |
svcs="$svcs" |
| 6342 |
. |
| 6343 |
|
| 6344 |
cat <<-'.' >>$out |
| 6345 |
|
| 6346 |
#-- prints usage message |
| 6347 |
pp_usage () { |
| 6348 |
echo "usage: $0 {start|stop|status|restart|reload|condrestart|try-restart|force-reload}" >&2 |
| 6349 |
return 2 |
| 6350 |
} |
| 6351 |
|
| 6352 |
#-- starts services in order.. stops them all if any break |
| 6353 |
pp_start () { |
| 6354 |
undo= |
| 6355 |
for svc in $svcs; do |
| 6356 |
if /etc/init.d/$svc start; then |
| 6357 |
undo="$svc $undo" |
| 6358 |
else |
| 6359 |
if test -n "$undo"; then |
| 6360 |
for svc in $undo; do |
| 6361 |
/etc/init.d/$svc stop |
| 6362 |
done |
| 6363 |
return 1 |
| 6364 |
fi |
| 6365 |
fi |
| 6366 |
done |
| 6367 |
return 0 |
| 6368 |
} |
| 6369 |
|
| 6370 |
#-- stops services in reverse |
| 6371 |
pp_stop () { |
| 6372 |
reverse= |
| 6373 |
for svc in $svcs; do |
| 6374 |
reverse="$svc $reverse" |
| 6375 |
done |
| 6376 |
rc=0 |
| 6377 |
for svc in $reverse; do |
| 6378 |
/etc/init.d/$svc stop || rc=$? |
| 6379 |
done |
| 6380 |
return $rc |
| 6381 |
} |
| 6382 |
|
| 6383 |
#-- returns true only if all services return true status |
| 6384 |
pp_status () { |
| 6385 |
rc=0 |
| 6386 |
for svc in $svcs; do |
| 6387 |
/etc/init.d/$svc status || rc=$? |
| 6388 |
done |
| 6389 |
return $rc |
| 6390 |
} |
| 6391 |
|
| 6392 |
pp_reload () { |
| 6393 |
rc=0 |
| 6394 |
for svc in $svcs; do |
| 6395 |
/etc/init.d/$svc reload || rc=$? |
| 6396 |
done |
| 6397 |
return $rc |
| 6398 |
} |
| 6399 |
|
| 6400 |
case "$1" in |
| 6401 |
start) pp_start;; |
| 6402 |
stop) pp_stop;; |
| 6403 |
restart) pp_stop; pp_start;; |
| 6404 |
status) pp_status;; |
| 6405 |
try-restart|condrestart) |
| 6406 |
if pp_status >/dev/null; then |
| 6407 |
pp_restart |
| 6408 |
fi;; |
| 6409 |
reload) pp_reload;; |
| 6410 |
force-reload) if pp_status >/dev/null; then |
| 6411 |
pp_reload |
| 6412 |
else |
| 6413 |
pp_restart |
| 6414 |
fi;; |
| 6415 |
*) pp_usage;; |
| 6416 |
esac |
| 6417 |
. |
| 6418 |
chmod 755 $out |
| 6419 |
} |
| 6420 |
|
| 6421 |
pp_rpm_service_make_service_files () { |
| 6422 |
local svc=${svc_init_filename:-$1} |
| 6423 |
local script="${svc_init_filepath:-"/etc/init.d"}/$svc" |
| 6424 |
local out=$pp_destdir$script |
| 6425 |
local _process _cmd _rpmlevels |
| 6426 |
|
| 6427 |
pp_add_file_if_missing $script run 755 m || return 0 |
| 6428 |
|
| 6429 |
#-- start out as an empty shell script |
| 6430 |
cat <<-'.' >$out |
| 6431 |
#!/bin/sh |
| 6432 |
. |
| 6433 |
|
| 6434 |
#-- determine the process name from $cmd unless $svc_process is given |
| 6435 |
set -- $cmd |
| 6436 |
_process=${svc_process:-"$1"} |
| 6437 |
|
| 6438 |
#-- construct a start command that builds a pid file if needed |
| 6439 |
_cmd="$cmd"; |
| 6440 |
if test -z "$pidfile"; then |
| 6441 |
pidfile=/var/run/$svc.pid |
| 6442 |
_cmd="$cmd & echo \$! > \$pidfile" |
| 6443 |
fi |
| 6444 |
if test "$user" != "root"; then |
| 6445 |
_cmd="su $user -c exec $_cmd"; |
| 6446 |
fi |
| 6447 |
|
| 6448 |
#-- generate the Red Hat chkconfig headers |
| 6449 |
_rpmlevels=`echo $start_runlevels | tr -d ' '` |
| 6450 |
cat <<-. >>$out |
| 6451 |
# chkconfig: ${_rpmlevels:--} ${start_priority:-50} ${stop_priority:-50} |
| 6452 |
# description: ${svc_description:-no description} |
| 6453 |
# processname: ${_process} |
| 6454 |
# pidfile: ${pidfile} |
| 6455 |
. |
| 6456 |
|
| 6457 |
#-- generate the LSB init info |
| 6458 |
cat <<-. >>$out |
| 6459 |
### BEGIN INIT INFO |
| 6460 |
# Provides: ${svc} |
| 6461 |
# Required-Start: ${lsb_required_start} |
| 6462 |
# Should-Start: ${lsb_should_start} |
| 6463 |
# Required-Stop: ${lsb_required_stop} |
| 6464 |
# Default-Start: ${start_runlevels} |
| 6465 |
# Default-Stop: ${stop_runlevels} |
| 6466 |
# Short-Description: ${svc_description} |
| 6467 |
### END INIT INFO |
| 6468 |
# Generated by PolyPackage ${pp_version} |
| 6469 |
# ${copyright} |
| 6470 |
|
| 6471 |
prog="`echo $cmd | sed -e 's: .*::' -e 's:^.*/::'`" |
| 6472 |
|
| 6473 |
. |
| 6474 |
|
| 6475 |
if test x"${svc_description}" = x"${pp_rpm_default_svc_description}"; then |
| 6476 |
svc_description= |
| 6477 |
fi |
| 6478 |
|
| 6479 |
#-- write service-specific definitions |
| 6480 |
cat <<. >>$out |
| 6481 |
#-- definitions specific to service ${svc} |
| 6482 |
svc_name="${svc_description:-$svc service}" |
| 6483 |
user="${user}" |
| 6484 |
pidfile="${pidfile}" |
| 6485 |
stop_signal="${stop_signal}" |
| 6486 |
reload_signal="${reload_signal}" |
| 6487 |
pp_exec_cmd () { $_cmd; } |
| 6488 |
. |
| 6489 |
|
| 6490 |
#-- write the generic part of the init script |
| 6491 |
cat <<'.' >>$out |
| 6492 |
|
| 6493 |
#-- use system message logging, if available |
| 6494 |
if [ -f /lib/lsb/init-functions -a ! -r /etc/redhat-release ]; then |
| 6495 |
. /lib/lsb/init-functions |
| 6496 |
pp_success_msg () { log_success_msg "$@"; } |
| 6497 |
pp_failure_msg () { log_failure_msg "$@"; } |
| 6498 |
pp_warning_msg () { log_warning_msg "$@"; } |
| 6499 |
elif [ -f /etc/init.d/functions ]; then |
| 6500 |
. /etc/init.d/functions |
| 6501 |
pp_success_msg () { echo -n "$*"; success "$@"; echo; } |
| 6502 |
pp_failure_msg () { echo -n "$*"; failure "$@"; echo; } |
| 6503 |
pp_warning_msg () { echo -n "$*"; warning "$@"; echo; } |
| 6504 |
else |
| 6505 |
pp_success_msg () { echo ${1:+"$*:"} OK; } |
| 6506 |
pp_failure_msg () { echo ${1:+"$*:"} FAIL; } |
| 6507 |
pp_warning_msg () { echo ${1:+"$*:"} WARNING; } |
| 6508 |
fi |
| 6509 |
|
| 6510 |
#-- prints a status message |
| 6511 |
pp_msg () { echo -n "$*: "; } |
| 6512 |
|
| 6513 |
#-- prints usage message |
| 6514 |
pp_usage () { |
| 6515 |
echo "usage: $0 {start|stop|status|restart|reload|condrestart|try-restart|force-reload}" >&2 |
| 6516 |
return 2 |
| 6517 |
} |
| 6518 |
|
| 6519 |
#-- reloads the service, if possible |
| 6520 |
# returns 0=success 1=failure 3=unimplemented |
| 6521 |
pp_reload () { |
| 6522 |
test -n "$reload_signal" || return 3 # unimplemented |
| 6523 |
pp_msg "Reloading ${svc_name}" |
| 6524 |
if pp_signal -${reload_signal}; then |
| 6525 |
pp_success_msg |
| 6526 |
return 0 |
| 6527 |
else |
| 6528 |
pp_failure_msg "not running" |
| 6529 |
return 1 |
| 6530 |
fi |
| 6531 |
} |
| 6532 |
|
| 6533 |
#-- delivers signal $1 to the pidfile |
| 6534 |
# returns 0=success 1=failure |
| 6535 |
pp_signal () { |
| 6536 |
if test -s "$pidfile"; then |
| 6537 |
read pid < "$pidfile" 2>/dev/null |
| 6538 |
kill "$@" "$pid" 2>/dev/null |
| 6539 |
else |
| 6540 |
return 1 |
| 6541 |
fi |
| 6542 |
} |
| 6543 |
|
| 6544 |
#-- verifies that ${svc_name} is running |
| 6545 |
# returns 0=success 1=failure |
| 6546 |
pp_running () { |
| 6547 |
if test -s "$pidfile"; then |
| 6548 |
read pid < "$pidfile" 2>/dev/null |
| 6549 |
if test ${pid:-0} -gt 1 && kill -0 "$pid" 2>/dev/null; then |
| 6550 |
# make sure name matches |
| 6551 |
pid="`ps -p $pid 2>/dev/null | sed -n \"s/^ *\($pid\) .*$prog *$/\1/p\"`" |
| 6552 |
if test -n "$pid"; then |
| 6553 |
return 0 |
| 6554 |
fi |
| 6555 |
fi |
| 6556 |
fi |
| 6557 |
return 1 |
| 6558 |
} |
| 6559 |
|
| 6560 |
#-- prints information about the service status |
| 6561 |
# returns 0=running 1=crashed 3=stopped |
| 6562 |
pp_status () { |
| 6563 |
pp_msg "Checking for ${svc_name}" |
| 6564 |
if pp_running; then |
| 6565 |
pp_success_msg "running" |
| 6566 |
return 0 |
| 6567 |
elif test -s "$pidfile"; then |
| 6568 |
pp_failure_msg "not running (crashed)" |
| 6569 |
return 1 |
| 6570 |
else |
| 6571 |
pp_failure_msg "not running" |
| 6572 |
return 3 |
| 6573 |
fi |
| 6574 |
} |
| 6575 |
|
| 6576 |
#-- starts the service |
| 6577 |
# returns 0=success 1=failure |
| 6578 |
pp_start () { |
| 6579 |
pp_msg "Starting ${svc_name}" |
| 6580 |
if pp_status >/dev/null; then |
| 6581 |
pp_warning_msg "already started" |
| 6582 |
return 0 |
| 6583 |
elif pp_exec_cmd; then |
| 6584 |
pp_success_msg |
| 6585 |
return 0 |
| 6586 |
else |
| 6587 |
pp_failure_msg "cannot start" |
| 6588 |
return 1 |
| 6589 |
fi |
| 6590 |
} |
| 6591 |
|
| 6592 |
#-- stops the service |
| 6593 |
# returns 0=success (always) |
| 6594 |
pp_stop () { |
| 6595 |
pp_msg "Stopping ${svc_name}" |
| 6596 |
if pp_signal -${stop_signal}; then |
| 6597 |
pp_success_msg |
| 6598 |
else |
| 6599 |
pp_success_msg "already stopped" |
| 6600 |
fi |
| 6601 |
rm -f "$pidfile" |
| 6602 |
return 0 |
| 6603 |
} |
| 6604 |
|
| 6605 |
#-- stops and starts the service |
| 6606 |
pp_restart () { |
| 6607 |
pp_stop |
| 6608 |
pp_start |
| 6609 |
} |
| 6610 |
|
| 6611 |
case "$1" in |
| 6612 |
start) pp_start;; |
| 6613 |
stop) pp_stop;; |
| 6614 |
restart) pp_restart;; |
| 6615 |
status) pp_status;; |
| 6616 |
try-restart|condrestart) |
| 6617 |
if pp_status >/dev/null; then |
| 6618 |
pp_restart |
| 6619 |
fi;; |
| 6620 |
reload) pp_reload;; |
| 6621 |
force-reload) if pp_status >/dev/null; then |
| 6622 |
pp_reload |
| 6623 |
else |
| 6624 |
pp_restart |
| 6625 |
fi;; |
| 6626 |
*) pp_usage;; |
| 6627 |
esac |
| 6628 |
|
| 6629 |
. |
| 6630 |
chmod 755 $out |
| 6631 |
|
| 6632 |
# Create systemd service file |
| 6633 |
pp_systemd_make_service_file $svc |
| 6634 |
} |
| 6635 |
pp_backend_rpm_function () { |
| 6636 |
case "$1" in |
| 6637 |
pp_mkgroup) cat<<'.';; |
| 6638 |
/usr/sbin/groupadd -f -r "$1" |
| 6639 |
. |
| 6640 |
pp_mkuser:depends) echo pp_mkgroup;; |
| 6641 |
pp_mkuser) cat<<'.';; |
| 6642 |
pp_mkgroup "${2:-$1}" || return 1 |
| 6643 |
/usr/sbin/useradd \ |
| 6644 |
-g "${2:-$1}" \ |
| 6645 |
-M -d "${3:-/nonexistent}" \ |
| 6646 |
-s "${4:-/bin/false}" \ |
| 6647 |
-r "$1" |
| 6648 |
. |
| 6649 |
pp_havelib) cat<<'.';; |
| 6650 |
for pp_tmp_dir in `echo "/usr/lib:/lib${3:+:$3}" | tr : ' '`; do |
| 6651 |
test -r "$pp_tmp_dir/lib$1.so{$2:+.$2}" && return 0 |
| 6652 |
done |
| 6653 |
return 1 |
| 6654 |
. |
| 6655 |
*) false;; |
| 6656 |
esac |
| 6657 |
} |
| 6658 |
|
| 6659 |
: NOTES <<. |
| 6660 |
|
| 6661 |
# creating a dmg file for publishing on the web |
| 6662 |
hdiutil create -srcfolder /path/foo foo.dmg |
| 6663 |
hdiutil internet-enable -yes /path/foo.dmg |
| 6664 |
# Layout for packages |
| 6665 |
<name>-<cpy>/component/<file> |
| 6666 |
<name>-<cpt>/extras/postinstall |
| 6667 |
<name>-<cpt>/extras/postupgrade |
| 6668 |
# /Developer/usr/bin/packagemaker (man packagemaker) |
| 6669 |
|
| 6670 |
Make a bunch of packages, and then build a 'distribution' |
| 6671 |
which is only understood by macos>10.4 |
| 6672 |
|
| 6673 |
# Message files in the resource path used are |
| 6674 |
Welcome.{rtf,html,rtfd,txt} - limited text shown in Intro |
| 6675 |
ReadMe.{rtf,html,rtfd,txt} - scrollable/printable, after Intro |
| 6676 |
License.{rtf,html,rtfd,txt} - ditto, user must click 'Accept' |
| 6677 |
background.{jpg,tif,gif,pict,eps,pdf} 620x418 background image |
| 6678 |
|
| 6679 |
# These scripts looked for in the resource path |
| 6680 |
InstallationCheck $pkgpath $defaultloc $targetvol |
| 6681 |
0:ok 32:warn 32+x:warn[1] 64:stop 96+x:stop[2] |
| 6682 |
VolumeCheck $volpath |
| 6683 |
0:ok 32:failure 32+x:failure[3] |
| 6684 |
preflight $pkgpath $targetloc $targetvol [priv] |
| 6685 |
preinstall $pkgpath $targetloc $targetvol [priv] |
| 6686 |
preupgrade $pkgpath $targetloc $targetvol [priv] |
| 6687 |
postinstall $pkgpath $targetloc $targetvol [priv] |
| 6688 |
postupgrade $pkgpath $targetloc $targetvol [priv] |
| 6689 |
postflight $pkgpath $targetloc $targetvol [priv] |
| 6690 |
0:ok else fail (for all scripts) |
| 6691 |
|
| 6692 |
A detailed reason is deduced by finding an index x (16..31) |
| 6693 |
in the file InstallationCheck.strings or VolumeCheck.strings. |
| 6694 |
|
| 6695 |
Scripts marked [priv] are executed with root privileges. |
| 6696 |
None of the [priv] scripts are used by metapackages. |
| 6697 |
|
| 6698 |
# Default permissions |
| 6699 |
Permissions of existing directories should match those |
| 6700 |
of a clean install of the OS; typically root:admin 0775 |
| 6701 |
New directories or files should be 0775 or 0664 with the |
| 6702 |
appropriate user:group. |
| 6703 |
Exceptions: |
| 6704 |
/etc root:admin 0755 |
| 6705 |
/var root:admin 0755 |
| 6706 |
|
| 6707 |
<http://mirror.informatimago.com/next/developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution/Concepts/sd_pkg_flags.html> |
| 6708 |
Info.plist = { |
| 6709 |
CFBundleGetInfoString: "1.2.3, One Identity LLC.", |
| 6710 |
CFBundleIdentifier: "com.quest.rc.openssh", |
| 6711 |
CFBundleShortVersionString: "1.2.3", |
| 6712 |
IFMajorVersion: 1, |
| 6713 |
IFMinorVersion: 2, |
| 6714 |
IFPkgFlagAllowBackRev: false, |
| 6715 |
IFPkgFlagAuthorizationAction: "AdminAuthorization", |
| 6716 |
IFPkgFlagDefaultLocation: "/", |
| 6717 |
IFPkgFlagFollowLinks: true, |
| 6718 |
IFPkgFlagInstallFat: false, |
| 6719 |
IFPkgFlagInstalledSize: <integer>, # this is added by packagemaker |
| 6720 |
IFPkgFlagIsRequired: false, |
| 6721 |
IFPkgFlagOverwritePermissions: false, |
| 6722 |
IFPkgFlagRelocatable: false, |
| 6723 |
IFPkgFlagRestartAction: "NoRestart", |
| 6724 |
IFPkgFlagRootVolumeOnly: false, |
| 6725 |
IFPkgFlagUpdateInstalledLanguages: false, |
| 6726 |
IFPkgFormatVersion= 0.10000000149011612, |
| 6727 |
IFRequirementDicts: [ { |
| 6728 |
Level = "requires", |
| 6729 |
SpecArgument = "/opt/quest/lib/libvas.4.2.0.dylib", |
| 6730 |
SpecType = "file", |
| 6731 |
TestObject = true, |
| 6732 |
TestOperator = "eq", } ] |
| 6733 |
} |
| 6734 |
|
| 6735 |
Description.plist = { |
| 6736 |
IFPkgDescriptionDescription = "this is the description text", |
| 6737 |
IFPkgDescriptionTitle = "quest-openssh" |
| 6738 |
} |
| 6739 |
|
| 6740 |
# Startup scripts |
| 6741 |
'launchd' is a kind of combined inetd and rc/init.d system. |
| 6742 |
<https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/DesigningDaemons.html> |
| 6743 |
Create a /Library/LaunchDaemons/$daemonname.plist file |
| 6744 |
Examples found in /System/Library/LaunchDaemons/ |
| 6745 |
See manual page launchd.plist(5) for details: |
| 6746 |
|
| 6747 |
{ Label: "com.quest.rc.foo", # required |
| 6748 |
Program: "/sbin/program", |
| 6749 |
ProgramArguments: [ "/sbin/program", "arg1", "arg2" ], # required |
| 6750 |
RunAtLoad: true, |
| 6751 |
WatchPaths: [ "/etc/crontab" ], |
| 6752 |
QueueDirectories: [ "/var/cron/tabs" ], |
| 6753 |
inetdCompatibility: { Wait: false }, # inetd-only |
| 6754 |
OnDemand: false, # recommended |
| 6755 |
SessionCreate: true, |
| 6756 |
UserName: "nobody", |
| 6757 |
InitGroups: true, |
| 6758 |
Sockets: { # inetd only |
| 6759 |
Listeners: { |
| 6760 |
SockServiceName: "ssh", |
| 6761 |
Bonjour: ["ssh", "sftp-ssh"], } }, |
| 6762 |
Disabled: false, |
| 6763 |
StandardErrorPath: "/dev/null", |
| 6764 |
} |
| 6765 |
|
| 6766 |
|
| 6767 |
How to add a new user |
| 6768 |
dscl . -create /Users/$user |
| 6769 |
dscl . -create /Users/$user UserShell /bin/bash |
| 6770 |
dscl . -create /Users/$user RealName "$user" |
| 6771 |
dscl . -create /Users/$user UniqueID $uid |
| 6772 |
dscl . -create /Users/$user PrimaryGroupID $gid |
| 6773 |
dscl . -create /Users/$user NFSHomeDirectory /Users/$user |
| 6774 |
dscl . -passwd /Users/$user "$passwd" |
| 6775 |
mkdir /Users/$user |
| 6776 |
chown $uid.$gid /Users/$user |
| 6777 |
|
| 6778 |
. |
| 6779 |
|
| 6780 |
|
| 6781 |
pp_platforms="$pp_platforms macos" |
| 6782 |
|
| 6783 |
pp_backend_macos_detect () { |
| 6784 |
[ x"$1" = x"Darwin" ] |
| 6785 |
} |
| 6786 |
|
| 6787 |
pp_backend_macos_init () { |
| 6788 |
pp_macos_default_bundle_id_prefix="com.quest.rc." |
| 6789 |
pp_macos_bundle_id= |
| 6790 |
pp_macos_bundle_vendor= |
| 6791 |
pp_macos_bundle_version= |
| 6792 |
pp_macos_bundle_info_string= |
| 6793 |
pp_macos_pkg_type=bundle |
| 6794 |
pp_macos_pkg_background= |
| 6795 |
pp_macos_pkg_background_dark= |
| 6796 |
pp_macos_pkg_license= |
| 6797 |
pp_macos_pkg_readme= |
| 6798 |
pp_macos_pkg_welcome= |
| 6799 |
pp_macos_sudo=sudo |
| 6800 |
pp_macos_installer_plugin= |
| 6801 |
# OS X puts the library version *before* the .dylib extension |
| 6802 |
pp_shlib_suffix='*.dylib' |
| 6803 |
} |
| 6804 |
|
| 6805 |
pp_macos_plist () { |
| 6806 |
typeset in |
| 6807 |
in="" |
| 6808 |
while test $# -gt 0; do |
| 6809 |
case "$1" in |
| 6810 |
|
| 6811 |
start-plist) cat <<-.; in=" "; shift ;; |
| 6812 |
<?xml version="1.0" encoding="UTF-8"?> |
| 6813 |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 6814 |
<plist version="1.0"> |
| 6815 |
. |
| 6816 |
end-plist) echo "</plist>"; in=; shift;; |
| 6817 |
|
| 6818 |
'[') echo "$in<array>"; in="$in "; shift;; |
| 6819 |
']') echo "$in</array>"; in="${in# }"; shift;; |
| 6820 |
'{') echo "<dict>"; in="$in "; shift;; |
| 6821 |
'}') echo "</dict>"; in="${in# }"; shift;; |
| 6822 |
key) shift; echo "$in<key>$1</key>"; shift;; |
| 6823 |
string) shift; |
| 6824 |
echo "$1" | sed -e 's/&/&/g;s/</\</g;s/>/\>/g;' \ |
| 6825 |
-e 's/^/'"$in"'<string>/;s/$/<\/string>/'; |
| 6826 |
shift;; |
| 6827 |
true) echo "$in<true/>"; shift;; |
| 6828 |
false) echo "$in<false/>"; shift;; |
| 6829 |
real) shift; echo "$in<real>$1</real>"; shift;; |
| 6830 |
integer) shift; echo "$in<integer>$1</integer>"; shift;; |
| 6831 |
date) shift; echo "$in<date>$1</date>"; shift;; # ISO 8601 format |
| 6832 |
data) shift; echo "$in<data>$1</data>"; shift;; # base64 encoded |
| 6833 |
*) pp_error "pp_macos_plist: bad argument '$1'"; shift;; |
| 6834 |
esac |
| 6835 |
done |
| 6836 |
} |
| 6837 |
|
| 6838 |
pp_macos_rewrite_cpio () { |
| 6839 |
typeset script |
| 6840 |
script=$pp_wrkdir/cpio-rewrite.pl |
| 6841 |
cat <<-'.' >$script |
| 6842 |
#!/usr/bin/perl |
| 6843 |
# |
| 6844 |
# Filter a cpio file, applying the user/group/mode specified in %files |
| 6845 |
# |
| 6846 |
# A CPIO header block has octal fields at the following offset/lengths: |
| 6847 |
# 0 6 magic |
| 6848 |
# 6 6 dev |
| 6849 |
# 12 6 ino |
| 6850 |
# 18 6 mode |
| 6851 |
# 24 6 uid |
| 6852 |
# 30 6 gid |
| 6853 |
# 36 6 nlink |
| 6854 |
# 42 6 rdev |
| 6855 |
# 48 11 mtime |
| 6856 |
# 59 6 namesize (including NUL terminator) |
| 6857 |
# 65 11 filesize |
| 6858 |
# 76 -- |
| 6859 |
# |
| 6860 |
use strict; |
| 6861 |
use warnings; |
| 6862 |
no strict 'subs'; |
| 6863 |
|
| 6864 |
# set %uid, %gid, %mode based on %files |
| 6865 |
my (%uid, %gid, %mode, %users, %groups); |
| 6866 |
my %type_map = ( d => 0040000, f => 0100000, s => 0120000 ); |
| 6867 |
while (<DATA>) { |
| 6868 |
my ($type,$mode,$uid,$gid,$flags,$name) = |
| 6869 |
m/^(.) (\S+) (\S+) (\S+) (\S+) (\S+)/; |
| 6870 |
$mode = $type eq "f" ? "0644" : "0755" if $mode eq "-"; |
| 6871 |
$uid = 0 if $uid eq "-"; |
| 6872 |
$gid = 0 if $gid eq "-"; |
| 6873 |
if ($uid ne "=" and $uid =~ m/\D/) { |
| 6874 |
unless (exists $users{$uid}) { |
| 6875 |
my @pw = getpwnam($uid) or die "bad username '$uid'"; |
| 6876 |
$users{$uid} = $pw[2]; |
| 6877 |
} |
| 6878 |
$uid = $users{$uid}; |
| 6879 |
} |
| 6880 |
if ($gid ne "=" and $gid =~ m/\D/) { |
| 6881 |
unless (exists $groups{$gid}) { |
| 6882 |
my @gr = getgrnam($gid) or die "bad group'$gid'"; |
| 6883 |
$groups{$gid} = $gr[2]; |
| 6884 |
} |
| 6885 |
$gid = $groups{$gid}; |
| 6886 |
} |
| 6887 |
$name =~ s:/$:: if $type eq "d"; |
| 6888 |
$name = ".".$name."\0"; |
| 6889 |
$uid{$name} = sprintf("%06o",int($uid)) unless $uid eq "="; |
| 6890 |
$gid{$name} = sprintf("%06o",int($gid)) unless $gid eq "="; |
| 6891 |
$mode{$name} = sprintf("%06o",oct($mode)|$type_map{$type}) unless $mode eq "="; |
| 6892 |
} |
| 6893 |
undef %users; |
| 6894 |
undef %groups; |
| 6895 |
# parse the cpio file |
| 6896 |
my $hdrlen = 76; |
| 6897 |
while (read(STDIN, my $header, $hdrlen)) { |
| 6898 |
my ($name, $namesize, $filesize); |
| 6899 |
my $filepad = 0; |
| 6900 |
if ($header =~ m/^07070[12]/) { |
| 6901 |
# SVR4 ASCII format, convert to ODC |
| 6902 |
if ($hdrlen == 76) { |
| 6903 |
# Read in rest of header and update header len for SVR4 |
| 6904 |
read(STDIN, $header, 110 - 76, 76); |
| 6905 |
$hdrlen = 110; |
| 6906 |
} |
| 6907 |
my $ino = hex(substr($header, 6, 8)) & 0x3ffff; |
| 6908 |
my $mode = hex(substr($header, 14, 8)) & 0x3ffff; |
| 6909 |
my $uid = hex(substr($header, 22, 8)) & 0x3ffff; |
| 6910 |
my $gid = hex(substr($header, 30, 8)) & 0x3ffff; |
| 6911 |
my $nlink = hex(substr($header, 38, 8)) & 0x3ffff; |
| 6912 |
my $mtime = hex(substr($header, 46, 8)) & 0xffffffff; |
| 6913 |
$filesize = hex(substr($header, 54, 8)) & 0xffffffff; |
| 6914 |
my $dev_maj = hex(substr($header, 62, 8)); |
| 6915 |
my $dev_min = hex(substr($header, 70, 8)); |
| 6916 |
my $dev = &makedev($dev_maj, $dev_min) & 0x3ffff; |
| 6917 |
my $rdev_maj = hex(substr($header, 78, 8)); |
| 6918 |
my $rdev_min = hex(substr($header, 86, 8)); |
| 6919 |
my $rdev = &makedev($rdev_maj, $rdev_min) & 0x3ffff; |
| 6920 |
$namesize = hex(substr($header, 94, 8)) & 0x3ffff; |
| 6921 |
read(STDIN, $name, $namesize); |
| 6922 |
# Header + name is padded to a multiple of 4 bytes |
| 6923 |
my $namepad = (($hdrlen + $namesize + 3) & 0xfffffffc) - ($hdrlen + $namesize); |
| 6924 |
read(STDIN, my $padding, $namepad) if ($namepad); |
| 6925 |
# File data is padded to be a multiple of 4 bytes |
| 6926 |
$filepad = (($filesize + 3) & 0xfffffffc) - $filesize; |
| 6927 |
|
| 6928 |
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); |
| 6929 |
$header = $new_header; |
| 6930 |
} elsif ($header =~ m/^070707/) { |
| 6931 |
# POSIX Portable ASCII Format |
| 6932 |
$namesize = oct(substr($header, 59, 6)); |
| 6933 |
$filesize = oct(substr($header, 65, 11)); |
| 6934 |
read(STDIN, $name, $namesize); |
| 6935 |
} else { |
| 6936 |
die "bad magic"; |
| 6937 |
} |
| 6938 |
# update uid, gid and mode (already in octal) |
| 6939 |
substr($header, 24, 6) = $uid{$name} if exists $uid{$name}; |
| 6940 |
substr($header, 30, 6) = $gid{$name} if exists $gid{$name}; |
| 6941 |
substr($header, 18, 6) = $mode{$name} if exists $mode{$name}; |
| 6942 |
print($header, $name); |
| 6943 |
# check for trailer at EOF |
| 6944 |
last if $filesize == 0 && $name =~ /^TRAILER!!!\0/; |
| 6945 |
# copy-through the file data |
| 6946 |
while ($filesize > 0) { |
| 6947 |
my $seg = 8192; |
| 6948 |
$seg = $filesize if $filesize < $seg; |
| 6949 |
read(STDIN, my $data, $seg); |
| 6950 |
print $data; |
| 6951 |
$filesize -= $seg; |
| 6952 |
} |
| 6953 |
# If file data is padded, skip it |
| 6954 |
read(STDIN, my $padding, $filepad) if ($filepad); |
| 6955 |
} |
| 6956 |
# pass through any padding at the end (blocksize-dependent) |
| 6957 |
for (;;) { |
| 6958 |
my $numread = read(STDIN, my $data, 8192); |
| 6959 |
last unless $numread; |
| 6960 |
print $data; |
| 6961 |
} |
| 6962 |
exit(0); |
| 6963 |
|
| 6964 |
sub makedev { |
| 6965 |
(((($_[0] & 0xff)) << 24) | ($_[1] & 0xffffff)); |
| 6966 |
} |
| 6967 |
__DATA__ |
| 6968 |
. |
| 6969 |
# Append to the script the %files data |
| 6970 |
cat "$@" </dev/null >> $script |
| 6971 |
/usr/bin/perl $script || pp_error "pp_macos_rewrite_cpio error"; |
| 6972 |
} |
| 6973 |
|
| 6974 |
pp_macos_files_bom () { |
| 6975 |
typeset _l t m o g f p st owner |
| 6976 |
while read t m o g f p st; do |
| 6977 |
# make sure that $m is padded up to 4 digits long |
| 6978 |
case "$m" in |
| 6979 |
?) m="000$m";; |
| 6980 |
??) m="00$m";; |
| 6981 |
???) m="0$m";; |
| 6982 |
?????*) pp_error "pp_macos_writebom: mode '$m' too long";; |
| 6983 |
esac |
| 6984 |
|
| 6985 |
# convert owner,group into owner/group in octal |
| 6986 |
case $o in -) o=0;; esac |
| 6987 |
case $g in -) g=0;; esac |
| 6988 |
owner=`pp_d2o $o`/`pp_d2o $g` |
| 6989 |
|
| 6990 |
case $t in |
| 6991 |
f) |
| 6992 |
test x"$m" = x"000-" && m=0644 |
| 6993 |
echo ".$p 10$m $owner ` |
| 6994 |
/usr/bin/cksum < "${pp_destdir}$p" | |
| 6995 |
awk '{print $2 " " $1}'`" |
| 6996 |
;; |
| 6997 |
d) |
| 6998 |
test x"$m" = x"000-" && m=0755 |
| 6999 |
echo ".${p%/} 4$m $owner" |
| 7000 |
;; |
| 7001 |
s) |
| 7002 |
test x"$m" = x"000-" && m=0755 |
| 7003 |
rl=`/usr/bin/readlink "${pp_destdir}$p"` |
| 7004 |
#test x"$rl" = x"$st" || |
| 7005 |
# pp_error "symlink mismatch $rl != $st" |
| 7006 |
echo ".$p 12$m $owner ` |
| 7007 |
/usr/bin/readlink -n "${pp_destdir}$p" | |
| 7008 |
/usr/bin/cksum | |
| 7009 |
awk '{print $2 " " $1}'` $st" |
| 7010 |
;; |
| 7011 |
esac |
| 7012 |
done |
| 7013 |
} |
| 7014 |
|
| 7015 |
pp_macos_bom_fix_parents () { |
| 7016 |
perl -pe ' |
| 7017 |
sub dirname { my $d=shift; $d=~s,/[^/]*$,,; $d; } |
| 7018 |
sub chk { my $d=shift; |
| 7019 |
&chk(&dirname($d)) if $d =~ m,/,; |
| 7020 |
unless ($seen{$d}++) { |
| 7021 |
# Make sure we do not override system directories |
| 7022 |
if ($d =~ m:^\./(etc|var)$:) { |
| 7023 |
my $tgt = "private/$1"; |
| 7024 |
my ($sum, $len) = split(/\s+/, `/usr/bin/printf "$tgt" | /usr/bin/cksum /dev/stdin`); |
| 7025 |
print "$d\t120755\t0/0\t$len\t$sum\t$tgt\n"; |
| 7026 |
} elsif ($d eq "." || $d eq "./Library") { |
| 7027 |
print "$d\t41775\t0/80\n"; |
| 7028 |
} elsif ($d eq "./Applications" || $d eq "./Developer") { |
| 7029 |
print "$d\t40775\t0/80\n"; |
| 7030 |
} else { |
| 7031 |
print "$d\t40755\t0/0\n"; |
| 7032 |
} |
| 7033 |
} |
| 7034 |
} |
| 7035 |
m/^(\S+)\s+(\d+)/; |
| 7036 |
if (oct($2) & 040000) { |
| 7037 |
$seen{$1}++; # directory |
| 7038 |
} |
| 7039 |
&chk(&dirname($1));' |
| 7040 |
} |
| 7041 |
|
| 7042 |
pp_macos_files_size () { |
| 7043 |
typeset _l t m o g f p st owner |
| 7044 |
while read t m o g f p st; do |
| 7045 |
case $t in |
| 7046 |
f) wc -c < "${pp_destdir}$p";; |
| 7047 |
s) echo 4095;; |
| 7048 |
d) ;; # always seems to be zero |
| 7049 |
esac |
| 7050 |
done | awk '{n+=1+int($1/4096)} END {print n*4}' |
| 7051 |
} |
| 7052 |
|
| 7053 |
pp_o2d () { |
| 7054 |
awk 'BEGIN { x=0; '`echo "$1" | |
| 7055 |
sed -e 's/./x=x*8+&;/g'`'print x;}' </dev/null |
| 7056 |
} |
| 7057 |
pp_d2o () { |
| 7058 |
case "$1" in |
| 7059 |
[0-7]) echo $1;; |
| 7060 |
*) awk 'BEGIN { printf("%o\n", 0+('"$1"'));}' < /dev/null;; |
| 7061 |
esac |
| 7062 |
} |
| 7063 |
|
| 7064 |
pp_macos_mkbom () { |
| 7065 |
#/usr/bin/mkbom -i $1 $2 |
| 7066 |
typeset path mode ugid size cksum linkpath |
| 7067 |
typeset bomstage |
| 7068 |
|
| 7069 |
# Use mkbom if it understands -i (avoids a copy) |
| 7070 |
if /usr/bin/mkbom -i /dev/null "$2" 2>/dev/null; then |
| 7071 |
rm -f "$2" |
| 7072 |
/usr/bin/mkbom -i "$1" "$2" |
| 7073 |
return |
| 7074 |
fi |
| 7075 |
|
| 7076 |
# On 10.4 we have this nonsense. |
| 7077 |
pp_warn "mkbom workaround: copying source files to staging area" |
| 7078 |
|
| 7079 |
bomstage=$pp_wrkdir/bom_stage |
| 7080 |
$pp_macos_sudo /bin/mkdir "$bomstage" |
| 7081 |
while IFS=' ' read path mode ugid size cksumi linkpath; do |
| 7082 |
if test -h "$pp_destdir/$path"; then |
| 7083 |
$pp_macos_sudo /bin/ln -s "$linkpath" "$bomstage/$path" |
| 7084 |
else |
| 7085 |
if test -d "$pp_destdir/$path"; then |
| 7086 |
$pp_macos_sudo /bin/mkdir -p "$bomstage/$path" |
| 7087 |
else |
| 7088 |
$pp_macos_sudo /bin/cp "$pp_destdir/$path" "$bomstage/$path" |
| 7089 |
fi |
| 7090 |
$pp_macos_sudo /bin/chmod $mode "$bomstage/$path" |
| 7091 |
$pp_macos_sudo /usr/sbin/chown `echo $ugid| tr / :` "$bomstage/$path" |
| 7092 |
fi |
| 7093 |
done <"$1" |
| 7094 |
(cd $bomstage && $pp_macos_sudo mkbom . $pp_wrkdir/bom_stage.bom) || |
| 7095 |
pp_error "mkbom failed" |
| 7096 |
$pp_macos_sudo mv $pp_wrkdir/bom_stage.bom "$2" |
| 7097 |
} |
| 7098 |
|
| 7099 |
pp_backend_macos () { |
| 7100 |
: ${pp_macos_bundle_id:=$pp_macos_default_bundle_id_prefix$name} |
| 7101 |
case "$pp_macos_pkg_type" in |
| 7102 |
bundle) pp_backend_macos_bundle;; |
| 7103 |
flat) pp_backend_macos_flat;; |
| 7104 |
*) pp_error "unsupported package type $pp_macos_pkg_type";; |
| 7105 |
esac |
| 7106 |
} |
| 7107 |
|
| 7108 |
pp_backend_macos_bundle () { |
| 7109 |
typeset pkgdir Contents Resources lprojdir svc |
| 7110 |
typeset Info_plist Description_plist |
| 7111 |
typeset bundle_vendor bundle_version size cmp filelists |
| 7112 |
|
| 7113 |
mac_version=`sw_vers -productVersion` |
| 7114 |
bundle_vendor=${pp_macos_bundle_vendor:-$vendor} |
| 7115 |
|
| 7116 |
if test -z "$pp_macos_bundle_version"; then |
| 7117 |
bundle_version=`echo "$version.0.0.0" | sed -n -e 's/[^0-9.]//g' \ |
| 7118 |
-e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p'` |
| 7119 |
else |
| 7120 |
bundle_version="$pp_macos_bundle_version" |
| 7121 |
fi |
| 7122 |
source_version=`echo $version | sed 's/.*\.//'` |
| 7123 |
|
| 7124 |
# build the package layout |
| 7125 |
pkgdir=$pp_wrkdir/$name.pkg |
| 7126 |
Contents=$pkgdir/Contents |
| 7127 |
Resources=$Contents/Resources |
| 7128 |
lprojdir=$Resources/en.lproj |
| 7129 |
mkdir $pkgdir $Contents $Resources $lprojdir || |
| 7130 |
pp_error "Can't make package temporary directories" |
| 7131 |
|
| 7132 |
echo "major: 1" > $Resources/package_version |
| 7133 |
echo "minor: 0" >> $Resources/package_version |
| 7134 |
echo "pmkrpkg1" > $Contents/PkgInfo |
| 7135 |
case $mac_version in |
| 7136 |
"10.6"*) |
| 7137 |
xattr -w "com.apple.TextEncoding" "macintosh;0" "$Resources/package_version" |
| 7138 |
xattr -w "com.apple.TextEncoding" "macintosh;0" "$Contents/PkgInfo" |
| 7139 |
;; |
| 7140 |
esac |
| 7141 |
|
| 7142 |
# Copy welcome file/dir for display at package install time. |
| 7143 |
if test -n "$pp_macos_pkg_welcome"; then |
| 7144 |
typeset sfx |
| 7145 |
sfx=`echo "$pp_macos_pkg_welcome"|sed 's/^.*\.\([^\.]*\)$/\1/'` |
| 7146 |
case "$sfx" in |
| 7147 |
rtf|html|rtfd|txt) ;; |
| 7148 |
*) sfx=txt;; |
| 7149 |
esac |
| 7150 |
cp -R ${pp_macos_pkg_welcome} $Resources/Welcome.$sfx |
| 7151 |
fi |
| 7152 |
|
| 7153 |
# Copy readme file/dir for display at package install time. |
| 7154 |
if test -n "$pp_macos_pkg_readme"; then |
| 7155 |
typeset sfx |
| 7156 |
sfx=`echo "$pp_macos_pkg_readme"|sed 's/^.*\.\([^\.]*\)$/\1/'` |
| 7157 |
case "$sfx" in |
| 7158 |
rtf|html|rtfd|txt) ;; |
| 7159 |
*) sfx=txt;; |
| 7160 |
esac |
| 7161 |
cp -R ${pp_macos_pkg_readme} $Resources/ReadMe.$sfx |
| 7162 |
fi |
| 7163 |
|
| 7164 |
# Copy license file/dir for display at package install time. |
| 7165 |
if test -n "$pp_macos_pkg_license"; then |
| 7166 |
typeset sfx |
| 7167 |
sfx=`echo "$pp_macos_pkg_license"|sed 's/^.*\.\([^\.]*\)$/\1/'` |
| 7168 |
case "$sfx" in |
| 7169 |
rtf|html|rtfd|txt) ;; |
| 7170 |
*) sfx=txt;; |
| 7171 |
esac |
| 7172 |
cp -R ${pp_macos_pkg_license} $Resources/License.$sfx |
| 7173 |
fi |
| 7174 |
|
| 7175 |
# Add services (may modify %files) |
| 7176 |
for svc in $pp_services .; do |
| 7177 |
test . = "$svc" && continue |
| 7178 |
pp_macos_add_service $svc |
| 7179 |
done |
| 7180 |
|
| 7181 |
# Find file lists (%files.* includes ignore files) |
| 7182 |
for cmp in $pp_components; do |
| 7183 |
test -f $pp_wrkdir/%files.$cmp && filelists="$filelists${filelists:+ }$pp_wrkdir/%files.$cmp" |
| 7184 |
done |
| 7185 |
|
| 7186 |
# compute the installed size |
| 7187 |
size=`cat $filelists | pp_macos_files_size` |
| 7188 |
|
| 7189 |
#-- Create Info.plist |
| 7190 |
Info_plist=$Contents/Info.plist |
| 7191 |
pp_macos_plist \ |
| 7192 |
start-plist \{ \ |
| 7193 |
key CFBundleGetInfoString string \ |
| 7194 |
"${pp_macos_bundle_info_string:-$version $bundle_vendor}" \ |
| 7195 |
key CFBundleIdentifier string \ |
| 7196 |
"${pp_macos_bundle_id}" \ |
| 7197 |
key CFBundleName string "$name" \ |
| 7198 |
key CFBundleShortVersionString string "$bundle_version.$source_version" \ |
| 7199 |
key IFMajorVersion integer 1 \ |
| 7200 |
key IFMinorVersion integer 0 \ |
| 7201 |
key IFPkgFlagAllowBackRev false \ |
| 7202 |
key IFPkgFlagAuthorizationAction string "RootAuthorization" \ |
| 7203 |
key IFPkgFlagDefaultLocation string "/" \ |
| 7204 |
key IFPkgFlagFollowLinks true \ |
| 7205 |
key IFPkgFlagInstallFat true \ |
| 7206 |
key IFPkgFlagInstalledSize integer $size \ |
| 7207 |
key IFPkgFlagIsRequired false \ |
| 7208 |
key IFPkgFlagOverwritePermissions true \ |
| 7209 |
key IFPkgFlagRelocatable false \ |
| 7210 |
key IFPkgFlagRestartAction string "NoRestart" \ |
| 7211 |
key IFPkgFlagRootVolumeOnly true \ |
| 7212 |
key IFPkgFlagUpdateInstalledLanguages false \ |
| 7213 |
key IFPkgFlagUseUserMask false \ |
| 7214 |
key IFPkgFormatVersion real 0.10000000149011612 \ |
| 7215 |
key SourceVersion string $source_version \ |
| 7216 |
\} end-plist> $Info_plist |
| 7217 |
|
| 7218 |
# write en.lproj/Description.plist |
| 7219 |
Description_plist=$lprojdir/Description.plist |
| 7220 |
pp_macos_plist \ |
| 7221 |
start-plist \{ \ |
| 7222 |
key IFPkgDescriptionDeleteWarning string "" \ |
| 7223 |
key IFPkgDescriptionDescription string "$pp_macos_bundle_info_string" \ |
| 7224 |
key IFPkgDescriptionTitle string "$name" \ |
| 7225 |
key IFPkgDescriptionVersion string "$bundle_version.$source_version" \ |
| 7226 |
\} end-plist > $Description_plist |
| 7227 |
|
| 7228 |
# write Resources/files |
| 7229 |
awk '{print $6}' $filelists > $Resources/files |
| 7230 |
|
| 7231 |
# write package size file |
| 7232 |
printf \ |
| 7233 |
"NumFiles 0 |
| 7234 |
InstalledSize $size |
| 7235 |
CompressedSize 0 |
| 7236 |
" > $Resources/$name.sizes |
| 7237 |
|
| 7238 |
# write Resources/preinstall |
| 7239 |
for cmp in $pp_components; do |
| 7240 |
if test -s $pp_wrkdir/%pre.$cmp; then |
| 7241 |
if test ! -s $Resources/preinstall; then |
| 7242 |
echo "#!/bin/sh" > $Resources/preinstall |
| 7243 |
chmod +x $Resources/preinstall |
| 7244 |
fi |
| 7245 |
cat $pp_wrkdir/%pre.$cmp >> $Resources/preinstall |
| 7246 |
echo : >> $Resources/preinstall |
| 7247 |
fi |
| 7248 |
done |
| 7249 |
|
| 7250 |
# write Resources/postinstall |
| 7251 |
for cmp in $pp_components; do |
| 7252 |
if test -s $pp_wrkdir/%post.$cmp; then |
| 7253 |
if test ! -s $Resources/postinstall; then |
| 7254 |
echo "#!/bin/sh" > $Resources/postinstall |
| 7255 |
chmod +x $Resources/postinstall |
| 7256 |
fi |
| 7257 |
cat $pp_wrkdir/%post.$cmp >> $Resources/postinstall |
| 7258 |
echo : >> $Resources/postinstall |
| 7259 |
fi |
| 7260 |
done |
| 7261 |
|
| 7262 |
# write Resources/postupgrade |
| 7263 |
for cmp in $pp_components; do |
| 7264 |
if test -s $pp_wrkdir/%postup.$cmp; then |
| 7265 |
if test ! -s $Resources/postupgrade; then |
| 7266 |
echo "#!/bin/sh" > $Resources/postupgrade |
| 7267 |
chmod +x $Resources/postupgrade |
| 7268 |
fi |
| 7269 |
cat $pp_wrkdir/%postup.$cmp >> $Resources/postupgrade |
| 7270 |
echo : >> $Resources/postupgrade |
| 7271 |
fi |
| 7272 |
done |
| 7273 |
|
| 7274 |
# write Resources/preremove |
| 7275 |
for cmp in $pp_components; do |
| 7276 |
if test -s $pp_wrkdir/%preun.$cmp; then |
| 7277 |
if test ! -s $Resources/preremove; then |
| 7278 |
echo "#!/bin/sh" > $Resources/preremove |
| 7279 |
chmod +x $Resources/preremove |
| 7280 |
fi |
| 7281 |
cat $pp_wrkdir/%preun.$cmp >> $Resources/preremove |
| 7282 |
echo : >> $Resources/preremove |
| 7283 |
fi |
| 7284 |
done |
| 7285 |
|
| 7286 |
# write Resources/postremove |
| 7287 |
for cmp in $pp_components; do |
| 7288 |
if test -s $pp_wrkdir/%postun.$cmp; then |
| 7289 |
if test ! -s $Resources/postremove; then |
| 7290 |
echo "#!/bin/sh" > $Resources/postremove |
| 7291 |
chmod +x $Resources/postremove |
| 7292 |
fi |
| 7293 |
cat $pp_wrkdir/%postun.$cmp >> $Resources/postremove |
| 7294 |
echo : >> $Resources/postremove |
| 7295 |
fi |
| 7296 |
done |
| 7297 |
|
| 7298 |
# write uninstall info |
| 7299 |
echo "version=$version" > $Resources/uninstall |
| 7300 |
if [ -n "$pp_macos_requires" ];then |
| 7301 |
echo "requires=$pp_macos_requires" >> $Resources/uninstall |
| 7302 |
fi |
| 7303 |
|
| 7304 |
. $pp_wrkdir/%fixup |
| 7305 |
|
| 7306 |
# Create the bill-of-materials (Archive.bom) |
| 7307 |
cat $filelists | pp_macos_files_bom | sort | |
| 7308 |
pp_macos_bom_fix_parents > $pp_wrkdir/tmp.bomls |
| 7309 |
|
| 7310 |
pp_macos_mkbom $pp_wrkdir/tmp.bomls $Contents/Archive.bom |
| 7311 |
|
| 7312 |
# Create the cpio archive (Archive.pax.gz) |
| 7313 |
( |
| 7314 |
cd $pp_destdir && |
| 7315 |
awk '{ print "." $6 }' $filelists | sed 's:/$::' | sort | /usr/bin/cpio -o | pp_macos_rewrite_cpio $filelists | gzip -9f -c > $Contents/Archive.pax.gz |
| 7316 |
) |
| 7317 |
|
| 7318 |
# Copy installer plugins if any |
| 7319 |
if test -n "$pp_macos_installer_plugin"; then |
| 7320 |
if test ! -f "$pp_macos_installer_plugin/InstallerSections.plist"; then |
| 7321 |
pp_error "Missing InstallerSections.plist file in $pp_macos_installer_plugin" |
| 7322 |
fi |
| 7323 |
mkdir -p $pkgdir/Plugins |
| 7324 |
cp -R "$pp_macos_installer_plugin"/* $pkgdir/Plugins |
| 7325 |
fi |
| 7326 |
|
| 7327 |
test -d $pp_wrkdir/bom_stage && $pp_macos_sudo rm -rf $pp_wrkdir/bom_stage |
| 7328 |
|
| 7329 |
rm -f ${name}-${version}.dmg |
| 7330 |
hdiutil create -fs HFS+ -srcfolder $pkgdir -volname $name ${name}-${version}.dmg |
| 7331 |
} |
| 7332 |
|
| 7333 |
pp_backend_macos_flat () { |
| 7334 |
typeset pkgdir bundledir Resources lprojdir svc |
| 7335 |
typeset Info_plist Description_plist |
| 7336 |
typeset bundle_vendor bundle_version size numfiles cmp filelists |
| 7337 |
|
| 7338 |
mac_version=`sw_vers -productVersion` |
| 7339 |
bundle_vendor=${pp_macos_bundle_vendor:-$vendor} |
| 7340 |
|
| 7341 |
if test -z "$pp_macos_bundle_version"; then |
| 7342 |
bundle_version=`echo "$version.0.0.0" | sed -n -e 's/[^0-9.]//g' \ |
| 7343 |
-e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p'` |
| 7344 |
else |
| 7345 |
bundle_version="$pp_macos_bundle_version" |
| 7346 |
fi |
| 7347 |
source_version=`echo $version | sed 's/.*\.//'` |
| 7348 |
|
| 7349 |
# build the flat package layout |
| 7350 |
pkgdir=$pp_wrkdir/pkg |
| 7351 |
pkgfile=$name-$version.pkg |
| 7352 |
bundledir=$pp_wrkdir/pkg/$pkgfile |
| 7353 |
Resources=$pkgdir/Resources |
| 7354 |
lprojdir=$Resources/en.lproj |
| 7355 |
mkdir $pkgdir $bundledir $Resources $lprojdir || |
| 7356 |
pp_error "Can't make package temporary directories" |
| 7357 |
|
| 7358 |
# Add services (may modify %files) |
| 7359 |
for svc in $pp_services .; do |
| 7360 |
test . = "$svc" && continue |
| 7361 |
pp_macos_add_service $svc |
| 7362 |
done |
| 7363 |
|
| 7364 |
# Find file lists (%files.* includes ignore files) |
| 7365 |
for cmp in $pp_components; do |
| 7366 |
test -f $pp_wrkdir/%files.$cmp && filelists="$filelists${filelists:+ }$pp_wrkdir/%files.$cmp" |
| 7367 |
done |
| 7368 |
|
| 7369 |
# compute the installed size and number of files/dirs |
| 7370 |
size=`cat $filelists | pp_macos_files_size` |
| 7371 |
numfiles=`cat $filelists | wc -l` |
| 7372 |
numfiles="${numfiles##* }" |
| 7373 |
|
| 7374 |
# Write Distribution file |
| 7375 |
cat <<-. >$pkgdir/Distribution |
| 7376 |
<?xml version="1.0" encoding="UTF-8"?> |
| 7377 |
<installer-gui-script minSpecVersion="1"> |
| 7378 |
<title>$name $version</title> |
| 7379 |
<options customize="never" allow-external-scripts="no"/> |
| 7380 |
<domains enable_localSystem="true"/> |
| 7381 |
. |
| 7382 |
if test -n "$pp_macos_pkg_welcome"; then |
| 7383 |
cp -R "${pp_macos_pkg_welcome}" $Resources |
| 7384 |
echo " <welcome file=\"${pp_macos_pkg_welcome##*/}\"/>" >>$pkgdir/Distribution |
| 7385 |
fi |
| 7386 |
if test -n "$pp_macos_pkg_readme"; then |
| 7387 |
cp -R "${pp_macos_pkg_readme}" $Resources |
| 7388 |
echo " <readme file=\"${pp_macos_pkg_readme##*/}\"/>" >>$pkgdir/Distribution |
| 7389 |
fi |
| 7390 |
if test -n "$pp_macos_pkg_license"; then |
| 7391 |
cp -R "${pp_macos_pkg_license}" $Resources |
| 7392 |
echo " <license file=\"${pp_macos_pkg_license##*/}\"/>" >>$pkgdir/Distribution |
| 7393 |
fi |
| 7394 |
if test -n "$pp_macos_pkg_background"; then |
| 7395 |
cp -R "${pp_macos_pkg_background}" $Resources |
| 7396 |
echo " <background file=\"${pp_macos_pkg_background##*/}\" scaling=\"proportional\" alignment=\"left\"/>" >>$pkgdir/Distribution |
| 7397 |
fi |
| 7398 |
if test -n "$pp_macos_pkg_background_dark"; then |
| 7399 |
cp -R "${pp_macos_pkg_background_dark}" $Resources |
| 7400 |
echo " <background-darkAqua file=\"${pp_macos_pkg_background_dark##*/}\" scaling=\"proportional\" alignment=\"left\"/>" >>$pkgdir/Distribution |
| 7401 |
fi |
| 7402 |
cat <<-. >>$pkgdir/Distribution |
| 7403 |
<choices-outline> |
| 7404 |
<line choice="choice0"/> |
| 7405 |
</choices-outline> |
| 7406 |
<choice id="choice0" title="$name $version"> |
| 7407 |
<pkg-ref id="${pp_macos_bundle_id}"/> |
| 7408 |
</choice> |
| 7409 |
<pkg-ref id="${pp_macos_bundle_id}" installKBytes="$size" version="$version" auth="Root">#$pkgfile</pkg-ref> |
| 7410 |
</installer-gui-script> |
| 7411 |
. |
| 7412 |
|
| 7413 |
# write scripts archive |
| 7414 |
# XXX - missing preupgrade, preflight, postflight |
| 7415 |
mkdir $pp_wrkdir/scripts |
| 7416 |
for cmp in $pp_components; do |
| 7417 |
if test -s $pp_wrkdir/%pre.$cmp; then |
| 7418 |
if test ! -s $pp_wrkdir/scripts/preinstall; then |
| 7419 |
echo "#!/bin/sh" > $pp_wrkdir/scripts/preinstall |
| 7420 |
chmod +x $pp_wrkdir/scripts/preinstall |
| 7421 |
fi |
| 7422 |
cat $pp_wrkdir/%pre.$cmp >> $pp_wrkdir/scripts/preinstall |
| 7423 |
echo : >> $pp_wrkdir/scripts/preinstall |
| 7424 |
fi |
| 7425 |
if test -s $pp_wrkdir/%post.$cmp; then |
| 7426 |
if test ! -s $pp_wrkdir/scripts/postinstall; then |
| 7427 |
echo "#!/bin/sh" > $pp_wrkdir/scripts/postinstall |
| 7428 |
chmod +x $pp_wrkdir/scripts/postinstall |
| 7429 |
fi |
| 7430 |
cat $pp_wrkdir/%post.$cmp >> $pp_wrkdir/scripts/postinstall |
| 7431 |
echo : >> $pp_wrkdir/scripts/postinstall |
| 7432 |
fi |
| 7433 |
if test -s $pp_wrkdir/%postup.$cmp; then |
| 7434 |
if test ! -s $pp_wrkdir/scripts/postupgrade; then |
| 7435 |
echo "#!/bin/sh" > $pp_wrkdir/scripts/postupgrade |
| 7436 |
chmod +x $pp_wrkdir/scripts/postupgrade |
| 7437 |
fi |
| 7438 |
cat $pp_wrkdir/%postup.$cmp >> $pp_wrkdir/scripts/postupgrade |
| 7439 |
echo : >> $pp_wrkdir/scripts/postupgrade |
| 7440 |
fi |
| 7441 |
# XXX - not supported |
| 7442 |
if test -s $pp_wrkdir/%preun.$cmp; then |
| 7443 |
if test ! -s $pp_wrkdir/scripts/preremove; then |
| 7444 |
echo "#!/bin/sh" > $pp_wrkdir/scripts/preremove |
| 7445 |
chmod +x $pp_wrkdir/scripts/preremove |
| 7446 |
fi |
| 7447 |
cat $pp_wrkdir/%preun.$cmp >> $pp_wrkdir/scripts/preremove |
| 7448 |
echo : >> $pp_wrkdir/scripts/preremove |
| 7449 |
fi |
| 7450 |
# XXX - not supported |
| 7451 |
if test -s $pp_wrkdir/%postun.$cmp; then |
| 7452 |
if test ! -s $pp_wrkdir/scripts/postremove; then |
| 7453 |
echo "#!/bin/sh" > $pp_wrkdir/scripts/postremove |
| 7454 |
chmod +x $pp_wrkdir/scripts/postremove |
| 7455 |
fi |
| 7456 |
cat $pp_wrkdir/%postun.$cmp >> $pp_wrkdir/scripts/postremove |
| 7457 |
echo : >> $pp_wrkdir/scripts/postremove |
| 7458 |
fi |
| 7459 |
done |
| 7460 |
if test "`echo $pp_wrkdir/scripts/*`" != "$pp_wrkdir/scripts/*"; then |
| 7461 |
# write scripts archive, scripts are mode 0755 uid/gid 0/0 |
| 7462 |
# resetting the owner and mode is not strictly required |
| 7463 |
( |
| 7464 |
cd $pp_wrkdir/scripts || pp_error "Can't cd to $pp_wrkdir/scripts" |
| 7465 |
rm -f $pp_wrkdir/tmp.files.scripts |
| 7466 |
for s in *; do |
| 7467 |
echo "f 0755 0 0 - ./$s" >>$pp_wrkdir/tmp.files.scripts |
| 7468 |
done |
| 7469 |
find . -type f | /usr/bin/cpio -o | pp_macos_rewrite_cpio $pp_wrkdir/tmp.files.scripts | gzip -9f -c > $bundledir/Scripts |
| 7470 |
) |
| 7471 |
fi |
| 7472 |
|
| 7473 |
# Write PackageInfo file |
| 7474 |
cat <<-. >$bundledir/PackageInfo |
| 7475 |
<?xml version="1.0" encoding="UTF-8"?> |
| 7476 |
<pkg-info format-version="2" identifier="${pp_macos_bundle_id}" version="$version" install-location="/" relocatable="false" overwrite-permissions="true" followSymLinks="true" auth="root"> |
| 7477 |
<payload installKBytes="$size" numberOfFiles="$numfiles"/> |
| 7478 |
. |
| 7479 |
if test -s $bundledir/Scripts; then |
| 7480 |
echo " <scripts>" >>$bundledir/PackageInfo |
| 7481 |
for s in preflight postflight preinstall postinstall preupgrade postupgrade; do |
| 7482 |
if test -s "$pp_wrkdir/scripts/$s"; then |
| 7483 |
echo " <$s file=\"$s\"/>" >>$bundledir/PackageInfo |
| 7484 |
fi |
| 7485 |
done |
| 7486 |
echo " </scripts>" >>$bundledir/PackageInfo |
| 7487 |
fi |
| 7488 |
cat <<-. >>$bundledir/PackageInfo |
| 7489 |
</pkg-info> |
| 7490 |
. |
| 7491 |
|
| 7492 |
. $pp_wrkdir/%fixup |
| 7493 |
|
| 7494 |
# Create the bill-of-materials (Bom) |
| 7495 |
cat $filelists | pp_macos_files_bom | sort | |
| 7496 |
pp_macos_bom_fix_parents > $pp_wrkdir/tmp.bomls |
| 7497 |
pp_macos_mkbom $pp_wrkdir/tmp.bomls $bundledir/Bom |
| 7498 |
|
| 7499 |
# Create the cpio payload |
| 7500 |
( |
| 7501 |
cd $pp_destdir || pp_error "Can't cd to $pp_destdir" |
| 7502 |
awk '{ print "." $6 }' $filelists | sed 's:/$::' | sort | /usr/bin/cpio -o | pp_macos_rewrite_cpio $filelists | gzip -9f -c > $bundledir/Payload |
| 7503 |
) |
| 7504 |
awk '{print $6}' $filelists > $name.files |
| 7505 |
|
| 7506 |
# Copy installer plugins if any |
| 7507 |
if test -n "$pp_macos_installer_plugin"; then |
| 7508 |
if test ! -f "$pp_macos_installer_plugin/InstallerSections.plist"; then |
| 7509 |
pp_error "Missing InstallerSections.plist file in $pp_macos_installer_plugin" |
| 7510 |
fi |
| 7511 |
mkdir -p $pkgdir/Plugins |
| 7512 |
cp -R "$pp_macos_installer_plugin"/* $pkgdir/Plugins |
| 7513 |
fi |
| 7514 |
|
| 7515 |
test -d $pp_wrkdir/bom_stage && $pp_macos_sudo rm -rf $pp_wrkdir/bom_stage |
| 7516 |
|
| 7517 |
# Create the flat package with xar (like pkgutil --flatten does) |
| 7518 |
# Note that --distribution is only supported by macOS 10.6 and above |
| 7519 |
xar_flags="--compression=bzip2 --no-compress Scripts --no-compress Payload" |
| 7520 |
case $mac_version in |
| 7521 |
"10.5"*) ;; |
| 7522 |
*) xar_flags="$xar_flags --distribution";; |
| 7523 |
esac |
| 7524 |
(cd $pkgdir && /usr/bin/xar $xar_flags -cf "../$pkgfile" *) |
| 7525 |
|
| 7526 |
echo "version=$version" > $name.uninstall |
| 7527 |
} |
| 7528 |
|
| 7529 |
pp_backend_macos_cleanup () { |
| 7530 |
: |
| 7531 |
} |
| 7532 |
|
| 7533 |
pp_backend_macos_names () { |
| 7534 |
case "$pp_macos_pkg_type" in |
| 7535 |
bundle) echo ${name}.pkg;; |
| 7536 |
flat) echo ${name}-${version}.pkg;; |
| 7537 |
*) pp_error "unsupported package type $pp_macos_pkg_type";; |
| 7538 |
esac |
| 7539 |
} |
| 7540 |
|
| 7541 |
pp_backend_macos_install_script () { |
| 7542 |
echo '#!/bin/sh' |
| 7543 |
typeset pkgname platform |
| 7544 |
|
| 7545 |
pkgname="`pp_backend_macos_names`" |
| 7546 |
platform="`pp_backend_macos_probe`" |
| 7547 |
pp_install_script_common |
| 7548 |
|
| 7549 |
cat <<. |
| 7550 |
test \$# -eq 0 && usage |
| 7551 |
op="\$1"; shift |
| 7552 |
|
| 7553 |
case "\$op" in |
| 7554 |
list-components) |
| 7555 |
test \$# -eq 0 || usage \$op |
| 7556 |
echo "$pp_components" |
| 7557 |
;; |
| 7558 |
list-services) |
| 7559 |
test \$# -eq 0 || usage \$op |
| 7560 |
echo "$pp_services" |
| 7561 |
;; |
| 7562 |
list-files) |
| 7563 |
test \$# -ge 1 || usage \$op |
| 7564 |
echo \${PP_PKGDESTDIR:-.}/"$pkgname" |
| 7565 |
;; |
| 7566 |
install) |
| 7567 |
test \$# -ge 1 || usage \$op |
| 7568 |
vol=/Volumes/pp\$\$ |
| 7569 |
pkg=\$vol/${name}-${version}.pkg |
| 7570 |
hdiutil attach -readonly -mountpoint \$vol \ |
| 7571 |
\${PP_PKGDESTDIR:-.}/"$pkgname" |
| 7572 |
trap "hdiutil detach \$vol" 0 |
| 7573 |
installer -pkginfo -pkg \$pkg |
| 7574 |
installer -verbose -pkg \$pkg -target / |
| 7575 |
;; |
| 7576 |
uninstall) |
| 7577 |
test \$# -ge 1 || usage \$op |
| 7578 |
# XXX |
| 7579 |
echo "Uninstall not implemented" >&2 |
| 7580 |
exit 1;; |
| 7581 |
start|stop) |
| 7582 |
test \$# -ge 1 || usage \$op |
| 7583 |
ec=0 |
| 7584 |
for svc |
| 7585 |
do |
| 7586 |
# XXX |
| 7587 |
echo "\${op} not implemented" >&2 |
| 7588 |
ec=1 |
| 7589 |
done |
| 7590 |
exit \$ec |
| 7591 |
;; |
| 7592 |
print-platform) |
| 7593 |
echo "$platform" |
| 7594 |
;; |
| 7595 |
*) |
| 7596 |
usage;; |
| 7597 |
esac |
| 7598 |
. |
| 7599 |
} |
| 7600 |
|
| 7601 |
pp_backend_macos_init_svc_vars () { |
| 7602 |
pp_macos_start_services_after_install=true |
| 7603 |
pp_macos_service_name= |
| 7604 |
pp_macos_default_service_id_prefix="com.quest.rc." |
| 7605 |
pp_macos_service_id= |
| 7606 |
pp_macos_service_user= |
| 7607 |
pp_macos_service_group= |
| 7608 |
pp_macos_service_initgroups= |
| 7609 |
pp_macos_service_umask= |
| 7610 |
pp_macos_service_cwd= |
| 7611 |
pp_macos_service_nice= |
| 7612 |
pp_macos_svc_plist_file= |
| 7613 |
} |
| 7614 |
|
| 7615 |
pp_macos_launchd_plist () { |
| 7616 |
typeset svc svc_id |
| 7617 |
|
| 7618 |
svc="$1" |
| 7619 |
svc_id="$2" |
| 7620 |
|
| 7621 |
set -- $cmd |
| 7622 |
|
| 7623 |
if [ -n "$pp_macos_svc_plist_file" ]; then |
| 7624 |
echo "## Launchd plist file already defined at $pp_macos_svc_plist_file" |
| 7625 |
return |
| 7626 |
fi |
| 7627 |
|
| 7628 |
echo "## Generating the launchd plist file for $svc" |
| 7629 |
pp_macos_svc_plist_file="$pp_wrkdir/$svc.plist" |
| 7630 |
cat <<-. > $pp_macos_svc_plist_file |
| 7631 |
<?xml version="1.0" encoding="UTF-8"?> |
| 7632 |
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN |
| 7633 |
http://www.apple.com/DTDs/PropertyList-1.0.dtd > |
| 7634 |
<plist version="1.0"> |
| 7635 |
<dict> |
| 7636 |
<key>Label</key> |
| 7637 |
<string>$svc_id</string> |
| 7638 |
<key>ProgramArguments</key> |
| 7639 |
<array> |
| 7640 |
. |
| 7641 |
while test $# != 0; do |
| 7642 |
printf " <string>$1</string>\n" >> $pp_macos_svc_plist_file |
| 7643 |
shift |
| 7644 |
done |
| 7645 |
cat <<-. >> $pp_macos_svc_plist_file |
| 7646 |
</array> |
| 7647 |
<key>KeepAlive</key> |
| 7648 |
<true/> |
| 7649 |
. |
| 7650 |
if test -n "$pp_macos_service_user"; then |
| 7651 |
printf " <key>UserName</key>\n" >> $pp_macos_svc_plist_file |
| 7652 |
printf " <string>$pp_macos_service_user</string>\n" >> $pp_macos_svc_plist_file |
| 7653 |
fi |
| 7654 |
if test -n "$pp_macos_service_group"; then |
| 7655 |
printf " <key>GroupName</key>\n" >> $pp_macos_svc_plist_file |
| 7656 |
printf " <string>$pp_macos_service_group</string>\n" >> $pp_macos_svc_plist_file |
| 7657 |
fi |
| 7658 |
if test -n "$pp_macos_service_initgroups"; then |
| 7659 |
printf " <key>InitGroups</key>\n" >> $pp_macos_svc_plist_file |
| 7660 |
printf " <string>$pp_macos_service_initgroups</string>\n" >> $pp_macos_svc_plist_file |
| 7661 |
fi |
| 7662 |
if test -n "$pp_macos_service_umask"; then |
| 7663 |
printf " <key>Umask</key>\n" >> $pp_macos_svc_plist_file |
| 7664 |
printf " <string>$pp_macos_service_umask</string>\n" >> $pp_macos_svc_plist_file |
| 7665 |
fi |
| 7666 |
if test -n "$pp_macos_service_cwd"; then |
| 7667 |
printf " <key>WorkingDirectory</key>\n" >> $pp_macos_svc_plist_file |
| 7668 |
printf " <string>$pp_macos_service_cwd</string>\n" >> $pp_macos_svc_plist_file |
| 7669 |
fi |
| 7670 |
if test -n "$pp_macos_service_nice"; then |
| 7671 |
printf " <key>Nice</key>\n" >> $pp_macos_svc_plist_file |
| 7672 |
printf " <string>$pp_macos_service_nice</string>\n" >> $pp_macos_svc_plist_file |
| 7673 |
fi |
| 7674 |
cat <<-. >> $pp_macos_svc_plist_file |
| 7675 |
</dict> |
| 7676 |
</plist> |
| 7677 |
. |
| 7678 |
} |
| 7679 |
|
| 7680 |
pp_macos_add_service () { |
| 7681 |
typeset svc svc_id plist_file plist_dir |
| 7682 |
|
| 7683 |
pp_load_service_vars "$1" |
| 7684 |
svc=${pp_macos_service_name:-$1} |
| 7685 |
svc_id=${pp_macos_service_id:-$pp_macos_default_service_id_prefix$svc} |
| 7686 |
|
| 7687 |
#-- create a plist file for svc |
| 7688 |
pp_macos_launchd_plist "$svc" "$svc_id" |
| 7689 |
|
| 7690 |
#-- copy the plist file into place and add to %files |
| 7691 |
plist_dir="/Library/LaunchDaemons" |
| 7692 |
plist_file="$plist_dir/$svc_id.plist" |
| 7693 |
mkdir -p "$pp_destdir/$plist_dir" |
| 7694 |
cp "$pp_macos_svc_plist_file" "$pp_destdir/$plist_file" |
| 7695 |
pp_add_file_if_missing "$plist_file" |
| 7696 |
|
| 7697 |
#-- add code to start the service on install & upgrade |
| 7698 |
${pp_macos_start_services_after_install} && <<-. >> $pp_wrkdir/%post.$svc |
| 7699 |
# start service '$svc' automatically after install |
| 7700 |
launchctl load "$plist_file" |
| 7701 |
. |
| 7702 |
${pp_macos_start_services_after_install} && <<-. >> $pp_wrkdir/%postup.$svc |
| 7703 |
# start service '$svc' automatically after upgrade |
| 7704 |
# This is necessary if the service is new since the previous version. |
| 7705 |
# XXX: Does launchd automatically reload an service if its binary |
| 7706 |
# is replaced? |
| 7707 |
launchctl load "$plist_file" |
| 7708 |
. |
| 7709 |
} |
| 7710 |
|
| 7711 |
pp_backend_macos_probe () { |
| 7712 |
typeset name vers arch |
| 7713 |
case `sw_vers -productName` in |
| 7714 |
"macOS") name="macos";; |
| 7715 |
"Mac OS X") name="macos";; |
| 7716 |
*) name="unknown";; |
| 7717 |
esac |
| 7718 |
vers=`sw_vers -productVersion | awk -F. '{ printf "%d%02d\n", $1, $2 }'` |
| 7719 |
arch=`arch` |
| 7720 |
echo "$name$vers-$arch" |
| 7721 |
} |
| 7722 |
|
| 7723 |
pp_backend_macos_vas_platforms () { |
| 7724 |
echo "osx" # XXX non-really sure what they do.. it should be "macos" |
| 7725 |
} |
| 7726 |
pp_backend_macos_function () { |
| 7727 |
case "$1" in |
| 7728 |
_pp_macos_search_unused) cat<<'.';; |
| 7729 |
# Find an unused value in the given path |
| 7730 |
# args: path attribute minid [maxid] |
| 7731 |
pp_tmp_val=$3 |
| 7732 |
while :; do |
| 7733 |
test $pp_tmp_val -ge ${4:-999999} && return 1 |
| 7734 |
/usr/bin/dscl . -search "$1" "$2" $pp_tmp_val | |
| 7735 |
grep . > /dev/null || break |
| 7736 |
pp_tmp_val=`expr $pp_tmp_val + 1` |
| 7737 |
done |
| 7738 |
echo $pp_tmp_val |
| 7739 |
. |
| 7740 |
pp_mkgroup:depends) echo _pp_macos_search_unused;; |
| 7741 |
pp_mkgroup) cat<<'.';; |
| 7742 |
set -e |
| 7743 |
/usr/bin/dscl . -read /Groups/"$1" >/dev/null 2>&1 && return |
| 7744 |
pp_tmp_gid=`_pp_macos_search_unused /Groups PrimaryGroupID 100` |
| 7745 |
/usr/bin/dscl . -create /Groups/"$1" |
| 7746 |
/usr/bin/dscl . -create /Groups/"$1" PrimaryGroupID $pp_tmp_gid |
| 7747 |
/usr/bin/dscl . -create /Groups/"$1" RealName "Group $1" |
| 7748 |
/usr/bin/dscl . -create /Groups/"$1" GroupMembership "" |
| 7749 |
/usr/bin/dscl . -create /Groups/"$1" Password '*' |
| 7750 |
. |
| 7751 |
pp_mkuser:depends) echo pp_mkgroup _pp_macos_search_unused;; |
| 7752 |
pp_mkuser) cat<<'.';; |
| 7753 |
set -e |
| 7754 |
/usr/bin/dscl . -read /Users/"$1" >/dev/null 2>&1 && return |
| 7755 |
pp_tmp_uid=`_pp_macos_search_unused /Users UniqueID 100` |
| 7756 |
pp_mkgroup "${2:-$1}" |
| 7757 |
pp_tmp_gid=`/usr/bin/dscl . -read /Groups/"${2:-$1}" \ |
| 7758 |
PrimaryGroupID | awk '{print $2}'` |
| 7759 |
/usr/bin/dscl . -create /Users/"$1" |
| 7760 |
/usr/bin/dscl . -create /Users/"$1" PrimaryGroupID $pp_tmp_gid |
| 7761 |
/usr/bin/dscl . -create /Users/"$1" NFSHomeDirectory \ |
| 7762 |
"${3:-/var/empty}" |
| 7763 |
/usr/bin/dscl . -create /Users/"$1" UserShell \ |
| 7764 |
"${4:-/usr/bin/false}" |
| 7765 |
/usr/bin/dscl . -create /Users/"$1" RealName "$1" |
| 7766 |
/usr/bin/dscl . -create /Users/"$1" UniqueID $pp_tmp_uid |
| 7767 |
/usr/bin/dscl . -create /Users/"$1" Password '*' |
| 7768 |
. |
| 7769 |
pp_havelib) cat<<'.';; |
| 7770 |
# (use otool -L to find dependent libraries) |
| 7771 |
for pp_tmp_dir in `echo "${3:+$3:}/usr/local/lib:/lib:/usr/lib" | |
| 7772 |
tr : ' '`; do |
| 7773 |
test -r "$pp_tmp_dir/lib$1{$2:+.$2}.dylib" && return 0 |
| 7774 |
done |
| 7775 |
return 1 |
| 7776 |
. |
| 7777 |
*) false;; |
| 7778 |
esac |
| 7779 |
} |
| 7780 |
|
| 7781 |
pp_platforms="$pp_platforms inst" |
| 7782 |
|
| 7783 |
pp_backend_inst_detect () { |
| 7784 |
case "$1" in |
| 7785 |
IRIX*) return 0;; |
| 7786 |
*) return 1;; |
| 7787 |
esac |
| 7788 |
} |
| 7789 |
|
| 7790 |
pp_backend_inst_init () { |
| 7791 |
pp_readlink_fn=pp_ls_readlink |
| 7792 |
} |
| 7793 |
|
| 7794 |
pp_backend_inst_create_idb() |
| 7795 |
{ |
| 7796 |
typeset t m o g f p st |
| 7797 |
|
| 7798 |
while read t m o g f p st; do |
| 7799 |
if test x"$o" = x"-"; then |
| 7800 |
o="root" |
| 7801 |
fi |
| 7802 |
if test x"$g" = x"-"; then |
| 7803 |
g="sys" |
| 7804 |
fi |
| 7805 |
case "$t" in |
| 7806 |
f) test x"$m" = x"-" && m=444 |
| 7807 |
echo "f 0$m $o $g $p $p $name.sw.base" |
| 7808 |
;; |
| 7809 |
d) test x"$m" = x"-" && m=555 |
| 7810 |
echo "d 0$m $o $g $p $p $name.sw.base" |
| 7811 |
;; |
| 7812 |
s) test x"$m" = x"-" && m=777 |
| 7813 |
test x"$m" = x"777" || |
| 7814 |
pp_warn "$p: invalid mode $m for symlink, should be 777 or -" |
| 7815 |
echo "l 0$m $o $g $p $p $name.sw.base symval($st)" |
| 7816 |
;; |
| 7817 |
esac |
| 7818 |
done |
| 7819 |
} |
| 7820 |
|
| 7821 |
pp_backend_inst_create_spec() |
| 7822 |
{ |
| 7823 |
echo "product $name" |
| 7824 |
echo " id \"${summary}. Version: ${version}\"" |
| 7825 |
echo " image sw" |
| 7826 |
echo " id \"Software\"" |
| 7827 |
echo " version $version" |
| 7828 |
echo " order 9999" |
| 7829 |
echo " subsys base" |
| 7830 |
echo " id \"Base Software\"" |
| 7831 |
echo " replaces self" |
| 7832 |
echo " exp $name.sw.base" |
| 7833 |
echo " endsubsys" |
| 7834 |
echo " endimage" |
| 7835 |
echo "endproduct" |
| 7836 |
} |
| 7837 |
|
| 7838 |
pp_backend_inst () { |
| 7839 |
curdir=`pwd` |
| 7840 |
|
| 7841 |
cd "$pp_opt_wrkdir" |
| 7842 |
|
| 7843 |
# initialize |
| 7844 |
pp_inst_tardist=tardist |
| 7845 |
pp_inst_spec=${name}.spec |
| 7846 |
pp_inst_idb=${name}.idb |
| 7847 |
|
| 7848 |
rm -rf $pp_inst_tardist $pp_inst_spec $pp_inst_idb |
| 7849 |
mkdir -p $pp_inst_tardist |
| 7850 |
|
| 7851 |
# Create idb file |
| 7852 |
(for _cmp in $pp_components; do |
| 7853 |
cat %files.$_cmp | sort +4u -6 | pp_backend_inst_create_idb |
| 7854 |
done) >> $pp_inst_idb |
| 7855 |
|
| 7856 |
pp_backend_inst_create_spec >> $pp_inst_spec |
| 7857 |
|
| 7858 |
# Generate tardist |
| 7859 |
gendist -verbose -all -root / -source $pp_opt_destdir -idb $pp_inst_idb -spec $pp_inst_spec -dist $pp_inst_tardist $name |
| 7860 |
tar -cvf `pp_backend_inst_names` $pp_inst_tardist |
| 7861 |
|
| 7862 |
cd "$curdir" |
| 7863 |
} |
| 7864 |
|
| 7865 |
pp_backend_inst_cleanup () { |
| 7866 |
: |
| 7867 |
} |
| 7868 |
|
| 7869 |
pp_backend_inst_names () { |
| 7870 |
echo ${name}-${version}.tardist |
| 7871 |
} |
| 7872 |
|
| 7873 |
pp_backend_inst_install_script () { |
| 7874 |
: |
| 7875 |
} |
| 7876 |
|
| 7877 |
pp_backend_inst_function () { |
| 7878 |
echo false |
| 7879 |
} |
| 7880 |
|
| 7881 |
pp_backend_inst_init_svc_vars () { |
| 7882 |
: |
| 7883 |
} |
| 7884 |
|
| 7885 |
pp_backend_inst_probe () { |
| 7886 |
cpu=`hinv|sed -n '/^CPU/{s/000 /k /;s/^CPU: //;s/ Process.*//;s/^MIPS //;p;q;}'|tr A-Z a-z` |
| 7887 |
echo irix`uname -r`-$cpu |
| 7888 |
} |
| 7889 |
|
| 7890 |
pp_backend_inst_vas_platforms () { |
| 7891 |
echo "irix-65" |
| 7892 |
} |
| 7893 |
|
| 7894 |
pp_platforms="$pp_platforms null" |
| 7895 |
|
| 7896 |
pp_backend_null_detect () { |
| 7897 |
! : |
| 7898 |
} |
| 7899 |
|
| 7900 |
pp_backend_null_init () { |
| 7901 |
: |
| 7902 |
} |
| 7903 |
|
| 7904 |
|
| 7905 |
pp_backend_null () { |
| 7906 |
: |
| 7907 |
} |
| 7908 |
|
| 7909 |
pp_backend_null_cleanup () { |
| 7910 |
: |
| 7911 |
} |
| 7912 |
|
| 7913 |
pp_backend_null_names () { |
| 7914 |
: |
| 7915 |
} |
| 7916 |
|
| 7917 |
pp_backend_null_install_script () { |
| 7918 |
: |
| 7919 |
} |
| 7920 |
|
| 7921 |
pp_backend_null_function () { |
| 7922 |
echo false |
| 7923 |
} |
| 7924 |
|
| 7925 |
pp_backend_null_init_svc_vars () { |
| 7926 |
: |
| 7927 |
} |
| 7928 |
|
| 7929 |
pp_backend_null_probe () { |
| 7930 |
echo unknown-unknown |
| 7931 |
} |
| 7932 |
|
| 7933 |
pp_backend_null_vas_platforms () { |
| 7934 |
: |
| 7935 |
} |
| 7936 |
|
| 7937 |
pp_platforms="$pp_platforms bsd" |
| 7938 |
|
| 7939 |
pp_bsd_munge_text () { |
| 7940 |
# Insert a leading space on each line, replace blank lines with a |
| 7941 |
#space followed by a full-stop. |
| 7942 |
test -z "$1" && pp_die "pp_bsd_munge_text requires a parameter" |
| 7943 |
echo ${1} | sed "s,^\(.*\)$, \1, " | sed "s,^[ \t]*$, .,g" |
| 7944 |
} |
| 7945 |
|
| 7946 |
pp_backend_bsd_detect () { |
| 7947 |
test x"$1" = x"FreeBSD" -o x"$1" = x"DragonFly" |
| 7948 |
} |
| 7949 |
|
| 7950 |
pp_backend_bsd_init () { |
| 7951 |
|
| 7952 |
# Get the OS revision |
| 7953 |
pp_bsd_detect_os |
| 7954 |
|
| 7955 |
# Get the arch (i386/x86_64) |
| 7956 |
pp_bsd_detect_arch |
| 7957 |
|
| 7958 |
pp_bsd_name= |
| 7959 |
pp_bsd_version= |
| 7960 |
pp_bsd_origin= |
| 7961 |
pp_bsd_comment= |
| 7962 |
pp_bsd_arch= |
| 7963 |
pp_bsd_abi= |
| 7964 |
pp_bsd_www= |
| 7965 |
pp_bsd_maintainer= |
| 7966 |
pp_bsd_prefix="/usr/local/" |
| 7967 |
pp_bsd_desc= |
| 7968 |
pp_bsd_message= |
| 7969 |
|
| 7970 |
# Newer "pkg" (>=1.17.0) generates package.pkg, before that package.txz. |
| 7971 |
if pp_is_version_greater 1.17.0 "$(pkg --version)"; then |
| 7972 |
pp_bsd_pkg_sfx=pkg |
| 7973 |
else |
| 7974 |
pp_bsd_pkg_sfx=txz |
| 7975 |
fi |
| 7976 |
|
| 7977 |
# pp_bsd_category must be in array format comma separated |
| 7978 |
# pp_bsd_category=[security,network] |
| 7979 |
pp_bsd_category= |
| 7980 |
|
| 7981 |
# pp_bsd_licenselogic can be one of the following: single, and, or unset |
| 7982 |
pp_bsd_licenselogic= |
| 7983 |
|
| 7984 |
# pp_bsd_licenses must be in array format comma separated |
| 7985 |
# pp_bsd_licenses=[GPLv2,MIT] |
| 7986 |
pp_bsd_licenses= |
| 7987 |
|
| 7988 |
# pp_bsd_annotations. These can be any key: value pair |
| 7989 |
# key must be separated by a : |
| 7990 |
# keyvalue pairs must be comma separated |
| 7991 |
# pp_bsd_annotations="repo_type: binary, somekey: somevalue" |
| 7992 |
# since all packages created by PolyPackage will be of type binary |
| 7993 |
# let's just set it now. |
| 7994 |
pp_bsd_annotations="repo_type: binary" |
| 7995 |
|
| 7996 |
pp_bsd_dbg_pkgname="debug" |
| 7997 |
pp_bsd_dev_pkgname="devel" |
| 7998 |
pp_bsd_doc_pkgname="doc" |
| 7999 |
|
| 8000 |
# Make sure any programs we require are installed |
| 8001 |
pp_bsd_check_required_programs |
| 8002 |
|
| 8003 |
} |
| 8004 |
|
| 8005 |
pp_bsd_cmp_full_name () { |
| 8006 |
typeset prefix |
| 8007 |
prefix="${pp_bsd_name:-$name}" |
| 8008 |
case "$1" in |
| 8009 |
run) echo "${prefix}" ;; |
| 8010 |
dbg) echo "${prefix}-${pp_bsd_dbg_pkgname}";; |
| 8011 |
dev) echo "${prefix}-${pp_bsd_dev_pkgname}";; |
| 8012 |
doc) echo "${prefix}-${pp_bsd_doc_pkgname}";; |
| 8013 |
*) pp_error "unknown component '$1'"; |
| 8014 |
esac |
| 8015 |
} |
| 8016 |
|
| 8017 |
pp_bsd_check_required_programs () { |
| 8018 |
local p needed notfound ok |
| 8019 |
needed= notfound= |
| 8020 |
|
| 8021 |
# list of programs FreeBSD needs in order to create a binary package |
| 8022 |
for prog in ${pp_bsd_required_programs:-"pkg"} |
| 8023 |
do |
| 8024 |
if command -v $prog 2>&1 > /dev/null; then |
| 8025 |
pp_debug "$prog: found" |
| 8026 |
else |
| 8027 |
pp_debug "$prog: not found" |
| 8028 |
case "$prog" in |
| 8029 |
pkg) p=pkg;; |
| 8030 |
*) pp_die "Unexpected pkg tool $prog";; |
| 8031 |
esac |
| 8032 |
notfound="$notfound $prod" |
| 8033 |
pp_contains "$needed" "$p" || needed="$needed $p" |
| 8034 |
fi |
| 8035 |
done |
| 8036 |
if [ -n "$notfound" ]; then |
| 8037 |
pp_error "cannot find these programs: $notfound" |
| 8038 |
pp_error "please install these packages: $needed" |
| 8039 |
fi |
| 8040 |
} |
| 8041 |
|
| 8042 |
pp_bsd_detect_os () { |
| 8043 |
typeset revision |
| 8044 |
|
| 8045 |
pp_bsd_os=`uname -s` |
| 8046 |
revision=`uname -r` |
| 8047 |
pp_bsd_os_rev=`echo $revision | awk -F '-' '{print $1}'` |
| 8048 |
} |
| 8049 |
|
| 8050 |
pp_bsd_detect_arch() { |
| 8051 |
pp_bsd_platform="`uname -m`" |
| 8052 |
case $pp_bsd_platform in |
| 8053 |
amd64|x86_64) pp_bsd_platform_std=x86_64;; |
| 8054 |
i386) pp_bsd_platform_std=i386;; |
| 8055 |
*) pp_bsd_platform_std=unknown;; |
| 8056 |
esac |
| 8057 |
} |
| 8058 |
|
| 8059 |
pp_bsd_label () { |
| 8060 |
local label arg |
| 8061 |
label="$1"; shift |
| 8062 |
for arg |
| 8063 |
do |
| 8064 |
test -z "$arg" || echo "$label: $arg" |
| 8065 |
done |
| 8066 |
} |
| 8067 |
|
| 8068 |
pp_bsd_make_annotations () { |
| 8069 |
|
| 8070 |
test -z $1 && pp_die "pp_bsd_make_annotations requires a parameter" |
| 8071 |
manifest=$1 |
| 8072 |
|
| 8073 |
# Add annotations. These can be any key: value pair |
| 8074 |
# key must be separated by a : |
| 8075 |
# key:value pairs must be comma separated. |
| 8076 |
if test -n "$pp_bsd_annotations"; then |
| 8077 |
pp_debug "Processing annotations:" |
| 8078 |
pp_bsd_label "annotations" "{" >> $manifest |
| 8079 |
|
| 8080 |
SAVEIFS=$IFS |
| 8081 |
IFS=, |
| 8082 |
for annotate in $pp_bsd_annotations; do |
| 8083 |
# Remove any spaces at the start of the line |
| 8084 |
annotate=`echo $annotate | sed 's/^ *//'` |
| 8085 |
pp_debug " $annotate" |
| 8086 |
echo " $annotate" >> $manifest |
| 8087 |
done |
| 8088 |
IFS=$SAVEIFS |
| 8089 |
echo "}" >> $manifest |
| 8090 |
fi |
| 8091 |
} |
| 8092 |
|
| 8093 |
pp_bsd_make_depends() { |
| 8094 |
typeset package origin version |
| 8095 |
cmp=$1 |
| 8096 |
manifest=$2 |
| 8097 |
|
| 8098 |
if test -s $pp_wrkdir/%depend.${cmp}; then |
| 8099 |
echo "deps: {" >> $manifest |
| 8100 |
cat $pp_wrkdir/%depend.${cmp} | while read package origin version; do |
| 8101 |
if test x != x$package; then |
| 8102 |
pp_debug "Processing dependency: $package" |
| 8103 |
if test x != x$origin -a x != x$version; then |
| 8104 |
pp_debug " $package: {origin: \"$origin\", version: \"$version\"}" |
| 8105 |
echo " $package: {origin: \"$origin\", version: \"$version\"}" >> $manifest |
| 8106 |
else |
| 8107 |
pp_warn "Dependency $package is missing origin or version or both" |
| 8108 |
fi |
| 8109 |
fi |
| 8110 |
done |
| 8111 |
echo "}" >> $manifest |
| 8112 |
fi |
| 8113 |
} |
| 8114 |
|
| 8115 |
pp_bsd_make_messages () { |
| 8116 |
test -z $1 && pp_die "pp_bsd_make_messages requires a parameter" |
| 8117 |
manifest=$1 |
| 8118 |
|
| 8119 |
pp_debug "Processing messages" |
| 8120 |
|
| 8121 |
# Empty messages: [ ] is OK in the manifest |
| 8122 |
pp_bsd_label "messages" "[" >> $manifest |
| 8123 |
# Look for a single message in the variable pp_bsd_message |
| 8124 |
if test -n "$pp_bsd_message"; then |
| 8125 |
echo " { message: \"`pp_bsd_munge_text "$pp_bsd_message"`\" }," >> $manifest |
| 8126 |
fi |
| 8127 |
local a=1 |
| 8128 |
# Look for messages in the variables pp_bsd_message_[1..n] |
| 8129 |
var="pp_bsd_messages_1" |
| 8130 |
while [ -n "${!var}" ]; do |
| 8131 |
echo " { message: \"`pp_bsd_munge_text "${!var}"`\" }," >> $manifest |
| 8132 |
a=`expr $a + 1` |
| 8133 |
var="pp_bsd_messages_$a" |
| 8134 |
done |
| 8135 |
echo "]" >> $manifest |
| 8136 |
} |
| 8137 |
|
| 8138 |
pp_bsd_make_manifest() { |
| 8139 |
local cmp manifest |
| 8140 |
|
| 8141 |
cmp="$1" |
| 8142 |
manifest="$2" |
| 8143 |
|
| 8144 |
package_name=`pp_bsd_cmp_full_name $cmp` |
| 8145 |
|
| 8146 |
# Required for pkg +MANIFEST |
| 8147 |
cat <<-. >> $manifest |
| 8148 |
name: "${package_name}" |
| 8149 |
version: "${pp_bsd_version:-$version}" |
| 8150 |
origin: "${pp_bsd_origin}" |
| 8151 |
www: "${pp_bsd_www}" |
| 8152 |
desc: "`pp_bsd_munge_text "${pp_bsd_desc:-$description}"`" |
| 8153 |
comment: "${pp_bsd_comment:-$summary}" |
| 8154 |
maintainer: "${pp_bsd_maintainer}" |
| 8155 |
prefix: "${pp_bsd_prefix}" |
| 8156 |
. |
| 8157 |
|
| 8158 |
# Optional, so if they are not included in the pkg-product.pp file then do not create the label |
| 8159 |
pp_bsd_label "categories" "${pp_bsd_categories}" >> $manifest |
| 8160 |
pp_bsd_label "arch" "${pp_bsd_arch}" >> $manifest |
| 8161 |
pp_bsd_label "abi" "${pp_bsd_abi}" >> $manifest |
| 8162 |
pp_bsd_label "licenselogic" "${pp_bsd_licenselogic}" >> $manifest |
| 8163 |
pp_bsd_label "licenses" "${pp_bsd_licenses}" >> $manifest |
| 8164 |
|
| 8165 |
pp_bsd_make_annotations $manifest |
| 8166 |
pp_bsd_make_depends $cmp $manifest |
| 8167 |
|
| 8168 |
pp_bsd_make_messages $manifest |
| 8169 |
} |
| 8170 |
|
| 8171 |
pp_bsd_fakeroot () { |
| 8172 |
if test -s $pp_wrkdir/fakeroot.save; then |
| 8173 |
fakeroot -i $pp_wrkdir/fakeroot.save -s $pp_wrkdir/fakeroot.save "$@" |
| 8174 |
else |
| 8175 |
fakeroot -s $pp_wrkdir/fakeroot.save "$@" |
| 8176 |
fi |
| 8177 |
} |
| 8178 |
|
| 8179 |
pp_bsd_make_data() { |
| 8180 |
# t = file type |
| 8181 |
# m = file mode |
| 8182 |
# o = file owner |
| 8183 |
# g = file group |
| 8184 |
# f = ? |
| 8185 |
# p = file path |
| 8186 |
# st = file link |
| 8187 |
# |
| 8188 |
# EXAMPLE: f 755 root httpd v /usr/bin/hello goodbye |
| 8189 |
# -> /usr/bin/hello: {uname: root, gname: httpd, perm: 755 } goodbye |
| 8190 |
typeset _l t m o g f p st datadir |
| 8191 |
cmp=$1 |
| 8192 |
datadir=$pp_wrkdir/`pp_bsd_cmp_full_name $cmp` |
| 8193 |
local path |
| 8194 |
|
| 8195 |
outfilelist="$pp_wrkdir/files.list.$cmp" |
| 8196 |
outdirslist="$pp_wrkdir/dirs.list.$cmp" |
| 8197 |
|
| 8198 |
pp_debug "Processing $pp_wrkdir/%file.${cmp}" |
| 8199 |
|
| 8200 |
echo "files: {" > $outfilelist |
| 8201 |
echo "directories: {" > $outdirslist |
| 8202 |
|
| 8203 |
cat $pp_wrkdir/%files.${cmp} | while read t m o g f p st; do |
| 8204 |
test x"$o" = x"-" && o="${pp_bsd_defattr_uid:-root}" |
| 8205 |
test x"$g" = x"-" && g="${pp_bsd_defattr_gid:-wheel}" |
| 8206 |
if test x"$m" = x"-"; then |
| 8207 |
case "$t" in |
| 8208 |
d) m=755;; |
| 8209 |
f) m=644;; |
| 8210 |
esac |
| 8211 |
fi |
| 8212 |
path=$p |
| 8213 |
case "$t" in |
| 8214 |
f) # Files |
| 8215 |
case "$f" in |
| 8216 |
*v*) |
| 8217 |
# For now just skip the file if it is volatile, we |
| 8218 |
# will need to remove it in the pre uninstall script |
| 8219 |
pp_warn "file $path was marked as volatile, skipping" |
| 8220 |
;; |
| 8221 |
*) |
| 8222 |
# If the directory doesn't exist where we are going to copy this file, then create it first |
| 8223 |
if [ ! -d `dirname "$datadir$path"` ]; then |
| 8224 |
pp_debug "creating directory `dirname "$datadir$path"`" |
| 8225 |
mkdir -p `dirname "$datadir$path"` |
| 8226 |
fi |
| 8227 |
|
| 8228 |
pp_debug "install -D $datadir -o $o -g $g -m ${m} -v $pp_destdir$p $datadir$path" |
| 8229 |
pp_bsd_fakeroot install -D $datadir -o $o -g $g -m ${m} -v $pp_destdir$p $datadir$path |
| 8230 |
echo " \"$path\": \"-\", \"$path\": {uname: $o, gname: $g, perm: ${m}}" >> $outfilelist |
| 8231 |
;; |
| 8232 |
esac |
| 8233 |
;; |
| 8234 |
d) # Directories |
| 8235 |
pp_debug "install -D $datadir -o $o -g $g -m ${m} -d -v $datadir$path"; |
| 8236 |
pp_bsd_fakeroot install -D $datadir -o $o -g $g -m ${m} -d -v $datadir$path; |
| 8237 |
echo " \"$path\": \"-\", \"$path\": {uname: $o, gname: $g, perm: ${m}}" >> $outdirslist; |
| 8238 |
;; |
| 8239 |
s) # Symlinks |
| 8240 |
pp_debug "Found symlink: $datadir$path"; |
| 8241 |
# Remove leading / |
| 8242 |
rel_p=`echo $p | sed s,^/,,` |
| 8243 |
(cd $datadir; ln -sf $st $rel_p); |
| 8244 |
# Do we care if the file doesn't exist? Just symnlink it regardless and throw a warning? This will be important in the case |
| 8245 |
# where we depend on other packages to be installed and will be using the libs from that package. |
| 8246 |
if [ ! -e "$datadir$path" ]; then |
| 8247 |
pp_warn "$datadir$path does not exist" |
| 8248 |
fi |
| 8249 |
echo " \"$path\": \"$st\"" >> $outfilelist; |
| 8250 |
;; |
| 8251 |
*) pp_error "Unsupported data file type: %t";; |
| 8252 |
esac |
| 8253 |
done |
| 8254 |
|
| 8255 |
echo "}" >> $outfilelist |
| 8256 |
echo "}" >> $outdirslist |
| 8257 |
cat $outfilelist >> $manifest |
| 8258 |
cat $outdirslist >> $manifest |
| 8259 |
|
| 8260 |
pp_debug "Finished processing $pp_wrkdir/%file.${cmp}" |
| 8261 |
} |
| 8262 |
|
| 8263 |
pp_bsd_makebsd() { |
| 8264 |
typeset cmp |
| 8265 |
typeset package_build_dir |
| 8266 |
local manifest postinstall preinstall preuninstall postuninstall preupgrade postupgrade |
| 8267 |
|
| 8268 |
cmp="$1" |
| 8269 |
|
| 8270 |
if test -z "$pp_bsd_platform"; then |
| 8271 |
pp_error "Unknown BSD architecture" |
| 8272 |
return 1 |
| 8273 |
fi |
| 8274 |
|
| 8275 |
_subname=`pp_bsd_cmp_full_name $cmp` |
| 8276 |
package_build_dir=$pp_wrkdir/$_subname |
| 8277 |
|
| 8278 |
manifest="$package_build_dir/+MANIFEST" |
| 8279 |
postinstall="$package_build_dir/+POST_INSTALL" |
| 8280 |
preinstall="$package_build_dir/+PRE_INSTALL" |
| 8281 |
preuninstall="$package_build_dir/+PRE_DEINSTALL" |
| 8282 |
postuninstall="$package_build_dir/+POST_DEINSTALL" |
| 8283 |
preupgrade="$package_build_dir/+PRE_UPGRADE" |
| 8284 |
postupgrade="$package_build_dir/+POST_UPGRADE" |
| 8285 |
|
| 8286 |
# Create package dir |
| 8287 |
mkdir -p $package_build_dir |
| 8288 |
|
| 8289 |
pp_bsd_make_manifest $cmp $manifest |
| 8290 |
pp_bsd_make_data $cmp |
| 8291 |
|
| 8292 |
pp_debug "Processing pre/post install scripts" |
| 8293 |
|
| 8294 |
if test -s $pp_wrkdir/%pre.$cmp; then |
| 8295 |
pp_debug "Found %pre.$cmp" |
| 8296 |
{ |
| 8297 |
cat "$pp_wrkdir/%pre.$cmp" |
| 8298 |
} > $preinstall |
| 8299 |
pp_debug "Created $preinstall" |
| 8300 |
fi |
| 8301 |
|
| 8302 |
if test -s $pp_wrkdir/%post.$cmp; then |
| 8303 |
pp_debug "Found %post.$cmp" |
| 8304 |
{ |
| 8305 |
echo "# Post install script for " |
| 8306 |
cat "$pp_wrkdir/%post.$cmp" |
| 8307 |
} > $postinstall |
| 8308 |
pp_debug "Created $postinstall" |
| 8309 |
fi |
| 8310 |
|
| 8311 |
pp_debug "Processing pre/post uninstall scripts" |
| 8312 |
|
| 8313 |
if test -s $pp_wrkdir/%preun.$cmp; then |
| 8314 |
pp_debug "Found %preun.$cmp" |
| 8315 |
{ |
| 8316 |
echo "# Pre uninstall script for ${pp_bsd_name:-$name}" |
| 8317 |
cat "$pp_wrkdir/%preun.$cmp" |
| 8318 |
} > $preuninstall |
| 8319 |
pp_debug "Created pkg $preuninstall" |
| 8320 |
fi |
| 8321 |
|
| 8322 |
if test -s $pp_wrkdir/%postun.$cmp; then |
| 8323 |
pp_debug "Found %postun.$cmp" |
| 8324 |
{ |
| 8325 |
echo "# Post uninstall script for ${pp_bsd_name:-$name}" |
| 8326 |
cat "$pp_wrkdir/%postun.$cmp" |
| 8327 |
} > $postuninstall |
| 8328 |
pp_debug "Created $postuninstall" |
| 8329 |
fi |
| 8330 |
|
| 8331 |
if test -s $pp_wrkdir/%preup.$cmp; then |
| 8332 |
pp_debug "Found %preup.$cmp" |
| 8333 |
{ |
| 8334 |
echo "# Pre upgrade script for ${pp_bsd_name:-$name}" |
| 8335 |
cat "$pp_wrkdir/%preup.$cmp" |
| 8336 |
} > $preupgrade |
| 8337 |
pp_debug "Created pkg $preupgrade" |
| 8338 |
fi |
| 8339 |
|
| 8340 |
if test -s $pp_wrkdir/%postup.$cmp; then |
| 8341 |
pp_debug "Found %postup.$cmp" |
| 8342 |
{ |
| 8343 |
echo "# Post upgrade script for ${pp_bsd_name:-$name}" |
| 8344 |
cat "$pp_wrkdir/%postup.$cmp" |
| 8345 |
} > $postupgrade |
| 8346 |
pp_debug "Created $postupgrade" |
| 8347 |
fi |
| 8348 |
} |
| 8349 |
|
| 8350 |
pp_backend_bsd() { |
| 8351 |
#get-files-dir-entries |
| 8352 |
#create-manifest |
| 8353 |
#create-preuninstall |
| 8354 |
#create-postinstall |
| 8355 |
#create-package |
| 8356 |
# |
| 8357 |
pp_bsd_handle_services |
| 8358 |
|
| 8359 |
for cmp in $pp_components |
| 8360 |
do |
| 8361 |
_subname=`pp_bsd_cmp_full_name $cmp` |
| 8362 |
pp_debug "Generating packaging specific files for $_subname" |
| 8363 |
pp_bsd_makebsd $cmp |
| 8364 |
done |
| 8365 |
|
| 8366 |
# call this to fixup any files before creating the actual packages |
| 8367 |
. $pp_wrkdir/%fixup |
| 8368 |
|
| 8369 |
for cmp in $pp_components |
| 8370 |
do |
| 8371 |
_subname=`pp_bsd_cmp_full_name $cmp` |
| 8372 |
package_build_dir=$pp_wrkdir/$_subname |
| 8373 |
# Build the actual packages now |
| 8374 |
pp_debug "Building FreeBSD $_subname" |
| 8375 |
pp_debug "Running package create command: pkg create -m $package_build_dir -r $pp_wrkdir/`pp_bsd_cmp_full_name $cmp` -o $pp_wrkdir" |
| 8376 |
pp_bsd_fakeroot pkg create -m $package_build_dir -r $pp_wrkdir/`pp_bsd_cmp_full_name $cmp` -o $pp_wrkdir -v |
| 8377 |
done |
| 8378 |
|
| 8379 |
} |
| 8380 |
|
| 8381 |
pp_bsd_name () { |
| 8382 |
typeset cmp="${1:-run}" |
| 8383 |
echo `pp_bsd_cmp_full_name $cmp`"-${pp_bsd_version:-$version}.${pp_bsd_pkg_sfx}" |
| 8384 |
} |
| 8385 |
|
| 8386 |
pp_backend_bsd_names () { |
| 8387 |
for cmp in $pp_components; do |
| 8388 |
echo `pp_bsd_cmp_full_name $cmp`"-${pp_bsd_version:-$version}.${pp_bsd_pkg_sfx}" |
| 8389 |
done |
| 8390 |
} |
| 8391 |
|
| 8392 |
pp_backend_bsd_cleanup () { |
| 8393 |
: |
| 8394 |
} |
| 8395 |
|
| 8396 |
pp_backend_bsd_probe () { |
| 8397 |
echo "${pp_bsd_os}${pp_bsd_os_rev}-${pp_bsd_platform_std}" |
| 8398 |
} |
| 8399 |
|
| 8400 |
|
| 8401 |
pp_backend_bsd_vas_platforms() { |
| 8402 |
case "${pp_bsd_platform_std}" in |
| 8403 |
x86_64) echo "FreeBSD-x86_64.${pp_bsd_pkg_sfx} FreeBSD-i386.${pp_bsd_pkg_sfx}";; |
| 8404 |
i386) echo "FreeBSD-i386.${pp_bsd_pkg_sfx}";; |
| 8405 |
*) pp_die "unknown architecture $pp_bsd_platform_std";; |
| 8406 |
esac |
| 8407 |
} |
| 8408 |
|
| 8409 |
|
| 8410 |
pp_backend_bsd_install_script () { |
| 8411 |
typeset cmp _cmp_full_name |
| 8412 |
|
| 8413 |
echo "#!/bin/sh" |
| 8414 |
pp_install_script_common |
| 8415 |
|
| 8416 |
cat <<. |
| 8417 |
|
| 8418 |
cmp_to_pkgname () { |
| 8419 |
test x"\$*" = x"all" && set -- $pp_components |
| 8420 |
for cmp |
| 8421 |
do |
| 8422 |
case \$cmp in |
| 8423 |
. |
| 8424 |
for cmp in $pp_components; do |
| 8425 |
echo " $cmp) echo '`pp_bsd_cmp_full_name $cmp`';;" |
| 8426 |
done |
| 8427 |
|
| 8428 |
cat <<. |
| 8429 |
*) usage;; |
| 8430 |
esac |
| 8431 |
done |
| 8432 |
} |
| 8433 |
|
| 8434 |
cmp_to_pathname () { |
| 8435 |
test x"\$*" = x"all" && |
| 8436 |
set -- $pp_components |
| 8437 |
for cmp |
| 8438 |
do |
| 8439 |
case \$cmp in |
| 8440 |
. |
| 8441 |
for cmp in $pp_components; do |
| 8442 |
echo " $cmp) echo \${PP_PKGDESTDIR:-.}/'`pp_bsd_name $cmp`';;" |
| 8443 |
done |
| 8444 |
|
| 8445 |
cat <<. |
| 8446 |
*) usage;; |
| 8447 |
esac |
| 8448 |
done |
| 8449 |
} |
| 8450 |
|
| 8451 |
test \$# -eq 0 && usage |
| 8452 |
op="\$1"; shift |
| 8453 |
case "\$op" in |
| 8454 |
list-components) |
| 8455 |
test \$# -eq 0 || usage \$op |
| 8456 |
echo $pp_components |
| 8457 |
;; |
| 8458 |
list-services) |
| 8459 |
test \$# -eq 0 || usage \$op |
| 8460 |
echo $pp_services |
| 8461 |
;; |
| 8462 |
list-files) |
| 8463 |
test \$# -ge 1 || usage \$op |
| 8464 |
cmp_to_pathname "\$@" |
| 8465 |
;; |
| 8466 |
install) |
| 8467 |
test \$# -ge 1 || usage \$op |
| 8468 |
pkg add \`cmp_to_pathname "\$@"\` |
| 8469 |
;; |
| 8470 |
uninstall) |
| 8471 |
test \$# -ge 1 || usage \$op |
| 8472 |
pkg remove \`cmp_to_pkgname "\$@"\`; : |
| 8473 |
;; |
| 8474 |
start|stop) |
| 8475 |
test \$# -ge 1 || usage \$op |
| 8476 |
ec=0 |
| 8477 |
for svc |
| 8478 |
do |
| 8479 |
/etc/rc.d/\$svc \$op || ec=1 |
| 8480 |
done |
| 8481 |
exit \$ec |
| 8482 |
;; |
| 8483 |
print-platform) |
| 8484 |
test \$# -eq 0 || usage \$op |
| 8485 |
echo "${pp_bsd_os}-${pp_bsd_platform}" |
| 8486 |
echo '`pp_backend_bsd_probe`' |
| 8487 |
;; |
| 8488 |
*) |
| 8489 |
usage |
| 8490 |
;; |
| 8491 |
esac |
| 8492 |
. |
| 8493 |
} |
| 8494 |
pp_backend_bsd_init_svc_vars () { |
| 8495 |
svc_process_regex="${pp_bsd_svc_process_regex}" |
| 8496 |
svc_description=$summary |
| 8497 |
svc_init_prefix="${pp_bsd_prefix}" |
| 8498 |
svc_init_filename="${pp_bsd_svc_init_filename}" # == $svc |
| 8499 |
svc_init_filepath="${pp_bsd_svc_init_filepath}" # == $pp_bsd_prefix/etc/rc.d/ by default |
| 8500 |
|
| 8501 |
bsd_svc_before="${pp_bsd_svc_before}" |
| 8502 |
bsd_svc_require="${pp_bsd_svc_require}" |
| 8503 |
bsd_svc_keyword="${pp_bsd_svc_keyword}" |
| 8504 |
|
| 8505 |
} |
| 8506 |
|
| 8507 |
pp_bsd_service_make_init_info() { |
| 8508 |
local svc=$1 |
| 8509 |
local out=$2 |
| 8510 |
cat <<-. >$out |
| 8511 |
#!/bin/sh |
| 8512 |
# |
| 8513 |
# FreeBSD Script Header Detail |
| 8514 |
# |
| 8515 |
# PROVIDE: $svc |
| 8516 |
. |
| 8517 |
|
| 8518 |
if [ ! -z "$bsd_svc_before" ]; then |
| 8519 |
cat <<-. >>$out |
| 8520 |
# BEFORE: $bsd_svc_before |
| 8521 |
. |
| 8522 |
fi |
| 8523 |
|
| 8524 |
if [ ! -z "$bsd_svc_require" ]; then |
| 8525 |
cat <<-. >>$out |
| 8526 |
# REQUIRE: $bsd_svc_require |
| 8527 |
. |
| 8528 |
fi |
| 8529 |
|
| 8530 |
if [ ! -z "$bsd_svc_keyword" ]; then |
| 8531 |
cat <<-. >>$out |
| 8532 |
# KEYWORD: $bsd_svc_keyword |
| 8533 |
. |
| 8534 |
fi |
| 8535 |
|
| 8536 |
cat <<-'.' >>$out |
| 8537 |
### END INIT INFO |
| 8538 |
|
| 8539 |
. |
| 8540 |
|
| 8541 |
} |
| 8542 |
|
| 8543 |
pp_bsd_service_make_init_set_vars() { |
| 8544 |
local svc=$1 |
| 8545 |
local out=$2 |
| 8546 |
|
| 8547 |
svc_command="$cmd" |
| 8548 |
svc_pre_command="${pp_bsd_svc_pre_command}" |
| 8549 |
svc_pre_command_args="${pp_bsd_svc_pre_command_args}" |
| 8550 |
|
| 8551 |
local run_command="${svc_pre_command:-$svc_command}" |
| 8552 |
local run_pre_command_args="${svc_pre_command:+"${svc_pre_command_args}"}" |
| 8553 |
local run_post_command_args="${svc_command:+"${svc_command_args}"}" |
| 8554 |
local run_post_command_without_pre_command="${svc_pre_command:+"$svc_command"}" |
| 8555 |
local run_post_command_with_args="${run_post_command_without_pre_command}${run_post_command_args:+" $run_post_command_args"}" |
| 8556 |
local run_command_args="${run_pre_command_args:+"$run_pre_command_args"}${run_post_command_with_args:+" $run_post_command_with_args"}" |
| 8557 |
|
| 8558 |
# https://www.freebsd.org/cgi/man.cgi?query=rc.subr |
| 8559 |
cat <<-. >>$out |
| 8560 |
# FreeBSD rc subroutines |
| 8561 |
. /etc/rc.subr |
| 8562 |
|
| 8563 |
# 0: Not running. |
| 8564 |
# 1: Running normally |
| 8565 |
# 2: Running, but no PID file. |
| 8566 |
# 3: Running, but PID file doesn't match running processes. |
| 8567 |
# If the PID file is found but no process, the file is removed and 0 is returned. |
| 8568 |
DAEMON_RUNNING=0 |
| 8569 |
|
| 8570 |
name="$svc" |
| 8571 |
desc="${svc_description:-\$name}" |
| 8572 |
|
| 8573 |
start_cmd="\${name}_start" |
| 8574 |
status_cmd="\${name}_status" |
| 8575 |
stop_cmd="\${name}_stop" |
| 8576 |
|
| 8577 |
# Loads any variables set in /etc/rc.conf.d/\$name |
| 8578 |
load_rc_config \$name |
| 8579 |
|
| 8580 |
: \${${svc}_enable:="Yes"} |
| 8581 |
: \${${svc}_pidfile:="${pidfile:-/var/run/\${name\}.pid}"} |
| 8582 |
: \${${svc}_args:="$run_command_args"} |
| 8583 |
: \${${svc}_cmd:="$run_command"} |
| 8584 |
|
| 8585 |
# Regex used in the pp_check_daemon_running ps check to find our running processe(s) |
| 8586 |
# If it's set in /etc/rc.conf.d/\$name this will be used first |
| 8587 |
# then check if pp_bsd_svc_process_regex is set, finally set to the \${name}_cmd |
| 8588 |
# When set to \${name}_cmd pp_check_daemon_running will only find the parent process pid |
| 8589 |
: \${${svc}_process_regex:="${pp_bsd_svc_process_regex:-${cmd}}"} |
| 8590 |
|
| 8591 |
# For additional information about the rc.subr see: |
| 8592 |
# https://www.freebsd.org/cgi/man.cgi?query=rc.subr |
| 8593 |
rcvar="\${name}_enable" |
| 8594 |
|
| 8595 |
pidfile=\${${svc}_pidfile} |
| 8596 |
|
| 8597 |
command="\$${svc}_cmd" |
| 8598 |
command_args="\$${svc}_args" |
| 8599 |
|
| 8600 |
. |
| 8601 |
|
| 8602 |
} |
| 8603 |
|
| 8604 |
pp_bsd_service_make_init_body() { |
| 8605 |
local svc=$1 |
| 8606 |
local out=$2 |
| 8607 |
|
| 8608 |
cat<<-'.' >>$out |
| 8609 |
pp_exec_cmd() { (eval $command $command_args) } |
| 8610 |
|
| 8611 |
pp_success_msg () { echo ${1:+"$*:"} OK; } |
| 8612 |
pp_failure_msg () { echo ${1:+"$*:"} FAIL; } |
| 8613 |
pp_warning_msg () { echo ${1:+"$*:"} WARNING; } |
| 8614 |
|
| 8615 |
#-- prints a status message |
| 8616 |
pp_msg () { echo -n "$*: "; } |
| 8617 |
|
| 8618 |
# Kills process $1. |
| 8619 |
# First a sigterm, then wait up to 10 seconds |
| 8620 |
# before issuing a sig kill. |
| 8621 |
pp_signal () { |
| 8622 |
# Kill the processes the nice way first |
| 8623 |
if [ -z "$1" ]; then |
| 8624 |
# No pid file. Use the list from pp_check_daemon_running |
| 8625 |
kill $PROCESSES 2>/dev/null |
| 8626 |
else |
| 8627 |
kill $1 2>/dev/null |
| 8628 |
fi |
| 8629 |
count=1 |
| 8630 |
|
| 8631 |
#Check to make sure the processes died, if not kill them the hard way |
| 8632 |
while [ $count -le 10 ]; do |
| 8633 |
sleep 1 |
| 8634 |
pp_check_daemon_running |
| 8635 |
if [ $DAEMON_RUNNING -eq 0 ]; then |
| 8636 |
break; |
| 8637 |
fi |
| 8638 |
if [ $count -eq 1 ]; then |
| 8639 |
# We tried killing the pid associated to the pidfile, now try the ones we found from pp_check_daemon_running |
| 8640 |
kill $PROCESSES 2>/dev/null |
| 8641 |
fi |
| 8642 |
count=`expr $count + 1` |
| 8643 |
done |
| 8644 |
# Check one more time to make sure we got them all |
| 8645 |
if [ $DAEMON_RUNNING -ne 0 ]; then |
| 8646 |
# These guys don't want to go down the nice way, now just kill them |
| 8647 |
kill -9 $PROCESSES 2>/dev/null |
| 8648 |
fi |
| 8649 |
# make sure to remove the pidfile |
| 8650 |
rm -f $pidfile |
| 8651 |
} |
| 8652 |
|
| 8653 |
# Check to see if the daemon process is running |
| 8654 |
# Sets the PROCESSES global variable with all pids that match |
| 8655 |
# ${name}_process_regex |
| 8656 |
# Sets global variable DAEMON_RUNNING to one of the following: |
| 8657 |
# 0: Not Running |
| 8658 |
# 1: Running normally |
| 8659 |
# 2: Running, but no PID file |
| 8660 |
# 3: Running, but PID file doesn't match running processes. |
| 8661 |
# |
| 8662 |
pp_check_daemon_running() |
| 8663 |
{ |
| 8664 |
DAEMON_RUNNING=0 |
| 8665 |
. |
| 8666 |
cat<<-. >>$out |
| 8667 |
|
| 8668 |
PROCESSES="\`eval ps -axo pid,args | grep "\${${svc}_process_regex}" | grep -v grep | awk '{print \$1}'\`" |
| 8669 |
|
| 8670 |
. |
| 8671 |
cat<<-'.' >>$out |
| 8672 |
if [ -f $pidfile ]; then |
| 8673 |
if [ ! -z "$PROCESSES" ]; then |
| 8674 |
PARENT_PID=`cat $pidfile 2>/dev/null` |
| 8675 |
PPROCESS=`echo $PROCESSES | grep "${PARENT_PID:-"NOPID"}"` |
| 8676 |
if [ $? -eq 0 ]; then |
| 8677 |
DAEMON_RUNNING=1 |
| 8678 |
else |
| 8679 |
DAEMON_RUNNING=3 |
| 8680 |
fi |
| 8681 |
else |
| 8682 |
rm -r $pidfile |
| 8683 |
fi |
| 8684 |
else |
| 8685 |
if [ ! -z "$PROCESSES" ]; then |
| 8686 |
DAEMON_RUNNING=2 |
| 8687 |
fi |
| 8688 |
fi |
| 8689 |
} |
| 8690 |
. |
| 8691 |
cat <<-. >>$out |
| 8692 |
|
| 8693 |
# starts the service |
| 8694 |
${svc}_start() |
| 8695 |
. |
| 8696 |
cat <<-'.' >>$out |
| 8697 |
{ |
| 8698 |
pp_msg "Starting ${desc}" |
| 8699 |
pp_check_daemon_running |
| 8700 |
|
| 8701 |
if [ $DAEMON_RUNNING -eq 0 ]; then |
| 8702 |
pp_exec_cmd |
| 8703 |
RETVAL=$? |
| 8704 |
if [ $RETVAL -eq 0 ]; then |
| 8705 |
pp_success_msg |
| 8706 |
else |
| 8707 |
pp_failure_msg "cannot start" |
| 8708 |
fi |
| 8709 |
else |
| 8710 |
if [ $DAEMON_RUNNING -eq 1 ]; then |
| 8711 |
pp_success_msg "${name} appears to be running already" |
| 8712 |
else |
| 8713 |
pp_warning_msg "${name} is already running but without a pid file" |
| 8714 |
fi |
| 8715 |
fi |
| 8716 |
} |
| 8717 |
|
| 8718 |
. |
| 8719 |
|
| 8720 |
cat <<-. >>$out |
| 8721 |
# stops the service |
| 8722 |
${svc}_stop() |
| 8723 |
. |
| 8724 |
|
| 8725 |
cat <<-'.' >>$out |
| 8726 |
{ |
| 8727 |
pp_msg "Stopping ${desc}" |
| 8728 |
pp_check_daemon_running |
| 8729 |
|
| 8730 |
if [ $DAEMON_RUNNING -ne 0 ]; then |
| 8731 |
pp_signal `cat $pidfile 2>/dev/null` |
| 8732 |
if [ -n "$pidfile" ]; then |
| 8733 |
loop_cnt=1 |
| 8734 |
while [ -e ${pidfile} ]; do |
| 8735 |
sleep 1 |
| 8736 |
loop_cnt=`expr $loop_cnt + 1` |
| 8737 |
if [ $loop_cnt -eq 10 ]; then |
| 8738 |
break |
| 8739 |
fi |
| 8740 |
done |
| 8741 |
fi |
| 8742 |
rm -f $pidfile |
| 8743 |
|
| 8744 |
pp_success_msg |
| 8745 |
else |
| 8746 |
pp_failure_msg |
| 8747 |
echo -n "$desc does not appear to be running." |
| 8748 |
echo |
| 8749 |
fi |
| 8750 |
} |
| 8751 |
. |
| 8752 |
|
| 8753 |
cat <<-. >>$out |
| 8754 |
# prints information about the service status |
| 8755 |
# returns: |
| 8756 |
# 0=running |
| 8757 |
# 1=Not running |
| 8758 |
# 2=Running without pidfile |
| 8759 |
# 3=Running with pid that doesn't match pidfile |
| 8760 |
${svc}_status() |
| 8761 |
. |
| 8762 |
|
| 8763 |
cat <<-'.' >>$out |
| 8764 |
{ |
| 8765 |
pp_msg "Checking ${desc}" |
| 8766 |
pp_check_daemon_running |
| 8767 |
if [ $DAEMON_RUNNING -eq 1 ]; then |
| 8768 |
pp_success_msg "PID $PARENT_PID: running" |
| 8769 |
return 0 |
| 8770 |
else |
| 8771 |
if [ $DAEMON_RUNNING -eq 0 ]; then |
| 8772 |
pp_failure_msg "not running" |
| 8773 |
return 1 |
| 8774 |
elif [ $DAEMON_RUNNING -eq 2 ]; then |
| 8775 |
pp_warning_msg "running without a pid file" |
| 8776 |
return 2 |
| 8777 |
else |
| 8778 |
pp_warning_msg "running but pid file doesn't match running processe()" |
| 8779 |
return 3 |
| 8780 |
fi |
| 8781 |
fi |
| 8782 |
} |
| 8783 |
|
| 8784 |
run_rc_command "$1" |
| 8785 |
. |
| 8786 |
} |
| 8787 |
|
| 8788 |
pp_bsd_service_make_init_script () { |
| 8789 |
local svc=${svc_init_filename:-$1} |
| 8790 |
local script="${svc_init_filepath:-"${svc_init_prefix}/etc/rc.d"}/$svc" |
| 8791 |
script=`echo $script | sed 's://*:/:g'` |
| 8792 |
local out=$pp_destdir$script |
| 8793 |
|
| 8794 |
pp_add_file_if_missing $script run 755 || return 0 |
| 8795 |
|
| 8796 |
pp_bsd_service_make_init_info "$svc" "$out" |
| 8797 |
pp_bsd_service_make_init_set_vars "$svc" "$out" |
| 8798 |
pp_bsd_service_make_init_body "$svc" "$out" |
| 8799 |
|
| 8800 |
chmod 755 $out |
| 8801 |
|
| 8802 |
} |
| 8803 |
|
| 8804 |
pp_bsd_handle_services () { |
| 8805 |
if test -n "$pp_services"; then |
| 8806 |
for svc in $pp_services; do |
| 8807 |
pp_load_service_vars $svc |
| 8808 |
# Append some code to %post to install the svc TODO: Figure out why/what |
| 8809 |
pp_bsd_service_make_init_script $svc |
| 8810 |
# prepend some code to %preun to uninstall svc TODO: Figure out why/what |
| 8811 |
done |
| 8812 |
fi |
| 8813 |
} |
| 8814 |
pp_backend_bsd_function() { |
| 8815 |
case "$1" in |
| 8816 |
pp_mkgroup) cat<<'.';; |
| 8817 |
/usr/sbin/pw group show "$1" 2>/dev/null && return 0 |
| 8818 |
/usr/sbin/pw group add "$1" |
| 8819 |
. |
| 8820 |
pp_mkuser:depends) echo pp_mkgroup;; |
| 8821 |
pp_mkuser) cat<<'.';; |
| 8822 |
#Check if user exists |
| 8823 |
/usr/sbin/pw user show "$1" 2>/dev/null && return 0 |
| 8824 |
pp_mkgroup "${2:-$1}" || return 1 |
| 8825 |
echo "Creating user $1" |
| 8826 |
/usr/sbin/pw user add \ |
| 8827 |
-n "$1" \ |
| 8828 |
-d "${3:-/nonexistent}" \ |
| 8829 |
-g "${2:-$1}" \ |
| 8830 |
-s "${4:-/bin/false}" |
| 8831 |
. |
| 8832 |
pp_havelib) cat<<'.';; |
| 8833 |
for pp_tmp_dir in `echo "/usr/local/lib:/usr/lib:/lib${3:+:$3}" | tr : ' '`; do |
| 8834 |
test -r "$pp_tmp_dir/lib$1.so{$2:+.$2}" && return 0 |
| 8835 |
done |
| 8836 |
return 1 |
| 8837 |
. |
| 8838 |
*) false;; |
| 8839 |
esac |
| 8840 |
} |
| 8841 |
pp_systemd_make_service_file() { |
| 8842 |
local svc f |
| 8843 |
|
| 8844 |
if [ "${pp_systemd_disabled:-false}" = "true" ]; then |
| 8845 |
return |
| 8846 |
fi |
| 8847 |
|
| 8848 |
svc="$1" |
| 8849 |
f="${pp_systemd_service_dir:-/opt/quest/libexec/vas}/$svc.service" |
| 8850 |
pp_add_file_if_missing $f run 644 v || return 0 |
| 8851 |
|
| 8852 |
cat <<. >$pp_destdir$f |
| 8853 |
|
| 8854 |
[Unit] |
| 8855 |
Description=${pp_systemd_service_description:-"systemd service file for $svc"} |
| 8856 |
${pp_systemd_service_man:+"Documentation=$pp_systemd_service_man"} |
| 8857 |
${pp_systemd_service_documentation:+"Documentation=$pp_systemd_service_documentation"} |
| 8858 |
${pp_systemd_service_requires:+"Requires=$pp_systemd_service_requires"} |
| 8859 |
After=${pp_systemd_service_after:-"syslog.target network.target auditd.service"} |
| 8860 |
${pp_systemd_service_before:+"Before=$pp_systemd_service_before"} |
| 8861 |
${pp_systemd_service_wants:+"Wants=$pp_systemd_service_wants"} |
| 8862 |
${pp_systemd_service_conflicts:+"Conflicts=$pp_systemd_service_conflicts"} |
| 8863 |
|
| 8864 |
[Service] |
| 8865 |
ExecStart=${pp_systemd_service_exec:-"/opt/quest/sbin/$svc"} ${pp_systemd_service_exec_args} |
| 8866 |
KillMode=${pp_systemd_service_killmode:-process} |
| 8867 |
Type=${pp_systemd_service_type:-forking} |
| 8868 |
${pp_systemd_service_pidfile:+"PIDFile=$pp_systemd_service_pidfile"} |
| 8869 |
|
| 8870 |
[Install] |
| 8871 |
WantedBy=${pp_systemd_system_target:-"multi-user.target"} |
| 8872 |
. |
| 8873 |
} |
| 8874 |
|
| 8875 |
pp_systemd_service_init_common () { |
| 8876 |
cat <<. |
| 8877 |
|
| 8878 |
_pp_systemd_init () { |
| 8879 |
systemd_service_dir=${pp_systemd_service_dir:-/opt/quest/libexec/vas} |
| 8880 |
systemd_target=${pp_systemd_system_target:-"multi-user.target"} |
| 8881 |
systemd_target_wants="\${systemd_target}.wants" |
| 8882 |
|
| 8883 |
pkg_config_cmd=${pp_systemd_pkg_config_cmd:-"\$(command -v pkg-config)"} |
| 8884 |
systemctl_cmd=${pp_systemd_systemctl_cmd:-"\$(command -v systemctl)"} |
| 8885 |
|
| 8886 |
# See if pkg-config is installed to get the default locations for this OS, if not installed then just use what we hard code. |
| 8887 |
# So far works on Debian 8, OpenSuse12.3, Ubuntu 16.04, RHEL 7.3 |
| 8888 |
# See systemd wiki for more OS interactions https://en.wikipedia.org/wiki/Systemd |
| 8889 |
if [ -x "\$pkg_config_cmd" ]; then |
| 8890 |
systemd_system_unit_dir="\$(pkg-config systemd --variable=systemdsystemunitdir)" |
| 8891 |
systemd_system_conf_dir="\$(pkg-config systemd --variable=systemdsystemconfdir)" |
| 8892 |
fi |
| 8893 |
|
| 8894 |
#if pkg-config does not exist or if the \$pkg_config_cmd command returns nothing |
| 8895 |
if test -z "\$systemd_system_unit_dir"; then |
| 8896 |
systemdsystemunitdirs="/lib/systemd/system /usr/lib/systemd/system" |
| 8897 |
for dir in \$systemdsystemunitdirs; do |
| 8898 |
if [ -d "\$dir/\$systemd_target_wants" ]; then |
| 8899 |
systemd_system_unit_dir="\$dir" |
| 8900 |
break |
| 8901 |
fi |
| 8902 |
done |
| 8903 |
fi |
| 8904 |
|
| 8905 |
# In the case where \$systemd_system_conf_dir is empty hard code the path |
| 8906 |
if test -z "\$systemd_system_conf_dir"; then |
| 8907 |
systemd_system_conf_dir="/etc/systemd/system" |
| 8908 |
fi |
| 8909 |
|
| 8910 |
# if the \$svc.pp file defines the systemd unit dir then use it. |
| 8911 |
${pp_systemd_system_unit_dir:+"# systemd_system_unit_dir defined by variable pp_systemd_system_unit_dir from the \$svc.pp file"} |
| 8912 |
systemd_system_unit_dir="${pp_systemd_system_unit_dir:-"\$systemd_system_unit_dir"}" |
| 8913 |
|
| 8914 |
# if the \$svc.pp file defines the systemd conf dir then use it. |
| 8915 |
${pp_systemd_system_conf_dir:+"# systemd_system_conf_dir defined by variable pp_systemd_system_conf_dir from the \$svc.pp file"} |
| 8916 |
systemd_system_conf_dir="${pp_systemd_system_conf_dir:-"\$systemd_system_conf_dir"}" |
| 8917 |
} |
| 8918 |
. |
| 8919 |
} |
| 8920 |
|
| 8921 |
pp_systemd_service_install_common () { |
| 8922 |
if [ "${pp_systemd_disabled:-false}" = "true" ]; then |
| 8923 |
cat<<'.' |
| 8924 |
|
| 8925 |
# systemd support disabled |
| 8926 |
_pp_systemd_init () { |
| 8927 |
return |
| 8928 |
} |
| 8929 |
|
| 8930 |
_pp_systemd_install () { |
| 8931 |
return |
| 8932 |
} |
| 8933 |
|
| 8934 |
_pp_systemd_enable () { |
| 8935 |
return |
| 8936 |
} |
| 8937 |
. |
| 8938 |
return |
| 8939 |
fi |
| 8940 |
|
| 8941 |
pp_systemd_service_init_common |
| 8942 |
|
| 8943 |
cat<<'.' |
| 8944 |
|
| 8945 |
_pp_systemd_install () { |
| 8946 |
local svc="$1" |
| 8947 |
|
| 8948 |
# If $systemctl_cmd is not set, then call _pp_systemd_init. If still not |
| 8949 |
# set, we do not know where the systemctl command is so do nothing; |
| 8950 |
# systemd must not be on this system. |
| 8951 |
if test -z "$systemctl_cmd"; then |
| 8952 |
_pp_systemd_init |
| 8953 |
fi |
| 8954 |
|
| 8955 |
if test -x "$systemctl_cmd" && test -d "$systemd_system_conf_dir/$systemd_target_wants"; then |
| 8956 |
# If our service file still exists (upgrade) remove the link/file and systemctl |
| 8957 |
# will recreate it if/when we enable the $svc service. |
| 8958 |
rm -f "$systemd_system_conf_dir/$systemd_target_wants/$svc.service" |
| 8959 |
|
| 8960 |
# Copy the $svc.service file to the correct systemd_system_unit_dir location |
| 8961 |
if [ "x$systemd_service_dir" != "x$systemd_system_unit_dir" ]; then |
| 8962 |
cp -f "$systemd_service_dir/$svc.service" "$systemd_system_unit_dir/$svc.service" |
| 8963 |
chmod 644 "$systemd_system_unit_dir/$svc.service" |
| 8964 |
fi |
| 8965 |
fi |
| 8966 |
} |
| 8967 |
|
| 8968 |
_pp_systemd_enable () { |
| 8969 |
local svc="$1" |
| 8970 |
local RUNNING=0 |
| 8971 |
|
| 8972 |
# If $systemctl_cmd is not set, then call _pp_systemd_init. If still not |
| 8973 |
# set, we do not know where the systemctl command is so do nothing; |
| 8974 |
# systemd must not be on this system. |
| 8975 |
if test -z "$systemctl_cmd"; then |
| 8976 |
_pp_systemd_init |
| 8977 |
fi |
| 8978 |
|
| 8979 |
if test -x "$systemctl_cmd" && test -f "$systemd_system_unit_dir/$svc.service"; then |
| 8980 |
# stop the daemon using the old init script before enabling systemd for the service |
| 8981 |
# we do this so we do not "orphan" the process. Because init started it and if we enable systemd |
| 8982 |
# it will not know about this process and will not be able to stop it. |
| 8983 |
if [ -x "/etc/init.d/$svc" ]; then |
| 8984 |
output="$(/etc/init.d/$svc status 2>&1)" |
| 8985 |
RUNNING=$? |
| 8986 |
if [ $RUNNING -eq 0 ]; then |
| 8987 |
case "$output" in |
| 8988 |
*"not running"*) |
| 8989 |
# systemd is reporting the status (compatibility package is installed) |
| 8990 |
RUNNING=1 |
| 8991 |
;; |
| 8992 |
*) # it is really running |
| 8993 |
/etc/init.d/$svc stop > /dev/null 2>&1 |
| 8994 |
;; |
| 8995 |
esac |
| 8996 |
fi |
| 8997 |
fi |
| 8998 |
|
| 8999 |
# If the service is not running according to its sysv script (eg. systemd service |
| 9000 |
# is not using a pidfile the sysv script needs), or its sysv script is not present any more, |
| 9001 |
# check how systemd thinks. |
| 9002 |
# We also try to restart the service in case something went wrong with it. |
| 9003 |
if $systemctl_cmd is-active "$svc" >/dev/null 2>&1 || $systemctl_cmd is-failed "$svc" >/dev/null 2>&1; then |
| 9004 |
$systemctl_cmd stop "$svc" >/dev/null 2>&1 |
| 9005 |
RUNNING=0 |
| 9006 |
fi |
| 9007 |
|
| 9008 |
# Enable the $svc.service |
| 9009 |
$systemctl_cmd daemon-reload >/dev/null 2>&1 |
| 9010 |
|
| 9011 |
# We do not need the init.d script any more, and it causes problems on SLES |
| 9012 |
# where systemd sysv compatibility is enforced and broken on default installs |
| 9013 |
rm -f "/etc/init.d/$svc" |
| 9014 |
|
| 9015 |
$systemctl_cmd enable $svc.service >/dev/null 2>&1 |
| 9016 |
|
| 9017 |
# Now that the service has been enabled, start it again if it was running before. |
| 9018 |
if [ $RUNNING -eq 0 ]; then |
| 9019 |
$systemctl_cmd start $svc.service >/dev/null 2>&1 |
| 9020 |
fi |
| 9021 |
fi |
| 9022 |
} |
| 9023 |
. |
| 9024 |
} |
| 9025 |
|
| 9026 |
pp_systemd_service_remove_common () { |
| 9027 |
if [ "${pp_systemd_disabled:-false}" = "true" ]; then |
| 9028 |
cat<<'.' |
| 9029 |
|
| 9030 |
# systemd support disabled |
| 9031 |
_pp_systemd_init () { |
| 9032 |
return |
| 9033 |
} |
| 9034 |
|
| 9035 |
_pp_systemd_disable () { |
| 9036 |
return |
| 9037 |
} |
| 9038 |
|
| 9039 |
_pp_systemd_remove () { |
| 9040 |
return |
| 9041 |
} |
| 9042 |
. |
| 9043 |
return |
| 9044 |
fi |
| 9045 |
|
| 9046 |
pp_systemd_service_init_common |
| 9047 |
|
| 9048 |
cat<<'.' |
| 9049 |
|
| 9050 |
_pp_systemd_disable () { |
| 9051 |
local svc="$1" |
| 9052 |
|
| 9053 |
# If $systemctl_cmd is not set, then call _pp_systemd_init. |
| 9054 |
# If still not set, we do not know where the systemctl command |
| 9055 |
# is so do nothing; systemd must not be on this system. |
| 9056 |
if test -z "$systemctl_cmd"; then |
| 9057 |
_pp_systemd_init |
| 9058 |
fi |
| 9059 |
|
| 9060 |
systemd_service_file="$systemd_system_conf_dir/$systemd_target_wants/$svc.service" |
| 9061 |
|
| 9062 |
# Remove systemd symlink (enabled) unit service file |
| 9063 |
if test -e $systemd_service_file; then |
| 9064 |
# Disable the $svc service |
| 9065 |
if test -x "$systemctl_cmd"; then |
| 9066 |
$systemctl_cmd disable $svc.service > /dev/null 2>&1 |
| 9067 |
else |
| 9068 |
# For some reason systemctl is not install but our service file exists |
| 9069 |
# Just delete the symlink then |
| 9070 |
rm -f "$systemd_service_file" |
| 9071 |
fi |
| 9072 |
fi |
| 9073 |
} |
| 9074 |
|
| 9075 |
_pp_systemd_remove () { |
| 9076 |
local svc="$1" |
| 9077 |
|
| 9078 |
# If $systemctl_cmd is not set, then call _pp_systemd_init. |
| 9079 |
# If still not set, we do not know where the systemctl command |
| 9080 |
# is so do nothing; systemd must not be on this system. |
| 9081 |
if test -z "$systemctl_cmd"; then |
| 9082 |
_pp_systemd_init |
| 9083 |
fi |
| 9084 |
|
| 9085 |
$systemctl_cmd stop $svc.service > /dev/null 2>&1 |
| 9086 |
|
| 9087 |
# Remove the systemd unit service file |
| 9088 |
if [ "x$systemd_service_dir" != "x$systemd_system_unit_dir" ]; then |
| 9089 |
rm -f "$systemd_system_unit_dir/$svc.service" |
| 9090 |
fi |
| 9091 |
|
| 9092 |
if test -x "$systemctl_cmd"; then |
| 9093 |
$systemctl_cmd daemon-reload |
| 9094 |
$systemctl_cmd reset-failed $svc.service >/dev/null 2>&1 || true |
| 9095 |
fi |
| 9096 |
} |
| 9097 |
. |
| 9098 |
} |
| 9099 |
|
| 9100 |
|
| 9101 |
quest_require_vas () { |
| 9102 |
typeset v d |
| 9103 |
|
| 9104 |
if test $# -ne 1; then |
| 9105 |
return |
| 9106 |
fi |
| 9107 |
set -- `echo "$1" | tr . ' '` 0 0 0 |
| 9108 |
|
| 9109 |
for d |
| 9110 |
do |
| 9111 |
echo $d | grep '^[0-9][0-9]*$' > /dev/null || |
| 9112 |
pp_error "quest_require_vas: Bad version component $d" |
| 9113 |
done |
| 9114 |
|
| 9115 |
test $# -lt 4 && |
| 9116 |
pp_error "quest_require_vas: missing version number" |
| 9117 |
|
| 9118 |
case "$1.$2.$3.$4" in |
| 9119 |
*.0.0.0) v=$1;; |
| 9120 |
*.*.0.0) v=$1.$2;; |
| 9121 |
*.*.*.0) v=$1.$2.$3;; |
| 9122 |
*) v=$1.$2.$3.$4;; |
| 9123 |
esac |
| 9124 |
|
| 9125 |
cat <<. |
| 9126 |
if test -x /opt/quest/bin/vastool && |
| 9127 |
/opt/quest/bin/vastool -v | |
| 9128 |
awk 'NR == 1 {print \$4}' | |
| 9129 |
awk -F. '{ if (\$1<$1 || \$1==$1 && ( \ |
| 9130 |
\$2<$2 || \$2==$2 && ( \ |
| 9131 |
\$3<$3 || \$2==$3 && ( \ |
| 9132 |
\$4<$4 )))) exit(1); }' |
| 9133 |
then |
| 9134 |
exit 0 |
| 9135 |
else |
| 9136 |
echo "Requires VAS $v or later" |
| 9137 |
exit 1 |
| 9138 |
fi |
| 9139 |
. |
| 9140 |
} |
| 9141 |
pp_main ${1+"$@"} |