forked from sudo-project/sudo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pp
executable file
·8804 lines (7730 loc) · 246 KB
/
pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# Copyright 2019 One Identity LLC. ALL RIGHTS RESERVED
pp_revision="20190919"
# Copyright 2018 One Identity LLC. ALL RIGHTS RESERVED.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of One Identity LLC. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Please see <http://rc.quest.com/topics/polypkg/> for more information
pp_version="1.0.0.$pp_revision"
pp_copyright="Copyright 2018, One Identity LLC. ALL RIGHTS RESERVED."
pp_opt_debug=false
pp_opt_destdir="$DESTDIR"
pp_opt_install_script=
pp_opt_list=false
pp_opt_no_clean=false
pp_opt_no_package=false
pp_opt_only_front=false
pp_opt_platform=
pp_opt_probe=false
pp_opt_strip=false
pp_opt_save_unstripped=false
pp_opt_vas_platforms=false
pp_opt_wrkdir="`pwd`/pp.work.$$"
pp_opt_verbose=false
pp_opt_version=false
pp_opt_input="-"
pp_opt_init_vars=""
pp_opt_eval=
test -n "$PP_NO_CLEAN" && pp_opt_no_clean=true
test -n "$PP_DEBUG" && pp_opt_debug=true
test -n "$PP_VERBOSE" && pp_opt_verbose=true
pp_main_cleanup () {
pp_debug "main_cleanup"
pp_remove_later_now
if $pp_opt_no_clean || test x"$pp_platform" = x"unknown"; then
: no cleanup
else
pp_backend_${pp_platform}_cleanup
$pp_errors && pp_die "Errors during cleanup"
if test -d "$pp_wrkdir"; then
if $pp_opt_debug; then
pp_debug "not removing $pp_wrkdir"
else
pp_verbose rm -rf "$pp_wrkdir"
fi
fi
fi
}
pp_parseopts () {
typeset a n _var _val
while test $# -gt 0; do
# convert -[dilpv] to --long-options
case "$1" in
--?*=?*) n=`echo "$1" | sed -ne 's/^--\([^=]*\)=.*/\1/p'`
a=`echo "$1" | sed -ne 's/^--[^=]*=\(.*\)/\1/p'`
shift
set -- "--$n" "$a" "$@";;
--?*) : ;;
-d) shift; set -- "--debug" "$@";;
-d*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--debug" "$@";;
-i) shift; set -- "--install-script" "$@";;
-i*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--install-script" "$a" "$@";;
-l) shift; set -- "--list" "$@";;
-l*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--list" "$@";;
-p) shift; set -- "--platform" "$@";;
-p*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--platform" "$a" "$@";;
-v) shift; set -- "--verbose" "$@";;
-v*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--verbose" "$@";;
-\?) shift; set -- "--help" "$@";;
-\?*) a=`echo "$1" | sed -ne 's/^-.//'`
shift; set -- "--help" "$@";;
esac
case "$1" in
--destdir|--eval|--install-script|--platform|--wrkdir)
test $# -ge 2 || pp_error "missing argument to $1";;
esac
case "$1" in
--) shift;break;;
--debug) pp_opt_debug=true; shift;;
--destdir) pp_opt_destdir="$2"; shift;shift;;
--eval) pp_opt_eval="$2"; shift;shift;; # undoc
--install-script) pp_opt_install_script="$2"; shift;shift;;
--list) pp_opt_list=true; shift;;
--no-clean) pp_opt_no_clean=true; shift;;
--no-package) pp_opt_no_package=true; shift;;
--only-front) pp_opt_only_front=true; shift;;
--platform) pp_opt_platform="$2"; shift;shift;;
--probe) pp_opt_probe=true; shift;;
--strip) pp_opt_strip=true; shift;;
--save-unstripped) pp_opt_save_unstripped=true; shift;;
--wrkdir) pp_opt_wrkdir="$2"; shift;shift;;
--vas-platforms) pp_opt_vas_platforms=true; shift;;
--verbose) pp_opt_verbose=true; shift;;
--version) pp_opt_version=true; shift;;
--help) pp_errors=true; shift;;
-) break;;
-*) pp_error "unknown option $1"; shift;;
*) break;;
esac
done
pp_opt_input=-
if test $# -gt 0; then
pp_opt_input="$1"
shift
fi
#-- extra arguments of the form Foo=bar alter *global* vars
while test $# -gt 0; do
case "$1" in
-*) pp_error "unexpected option '$1'"
shift;;
*=*) _val="${1#*=}"
_var=${1%="$_val"}
_val=`echo "$_val"|sed -e 's/[$"\\]/\\&/g'`
pp_debug "setting $_var = \"$_val\""
pp_opt_init_vars="$pp_opt_init_vars$_var=\"$_val\";"
shift;;
*) pp_error "unexpected argument $1'"
shift;;
esac
done
test $# -gt 0 &&
pp_error "unknown argument $1"
if $pp_errors; then
cat <<. >&2
polypkg $pp_version $pp_copyright
usage: $0 [options] [input.pp] [var=value ...]
-d --debug -- write copious info to stderr
--destdir=path -- file root, defaults to \$DESTDIR
-? --help -- display this information
-i --install-script=path -- create an install helper script
-l --list -- write package filenames to stdout
--no-clean -- don't remove temporary files
--no-package -- do everything but create packages
--only-front -- only perform front-end actions
-p --platform=platform -- defaults to local platform
--probe -- print local system identifier, then exit
--strip -- strip debug symbols from binaries before
packaging (modifies files in destdir)
--save-unstripped -- save unstripped binaries to
\$name-\$version-unstripped.tar.gz
--wrkdir=path -- defaults to subdirectory of \$TMPDIR or /tmp
-v --verbose -- write info to stderr
--version -- display version and quit
.
exit 1
fi
}
pp_drive () {
# initialise the front and back ends
pp_model_init
pp_frontend_init
$pp_opt_only_front || pp_backend_init
# run the front-end to generate the intermediate files
# set $pp_input_dir to be the 'include dir' if needed
pp_debug "calling frontend on $pp_opt_input"
case "$pp_opt_input" in
-) pp_input_dir=.
test -t 1<&0 &&
pp_warn "reading directives from standard input"
pp_frontend
;;
*/*) pp_input_dir=${pp_opt_input%/*}
pp_frontend <"$pp_opt_input"
;;
*) pp_input_dir=.
pp_frontend <"$pp_opt_input"
;;
esac
pp_files_ignore_others
pp_service_scan_groups
# some sanity checks after front-end processing
if test x"$pp_platform" != x"null"; then
pp_debug "sanity checks"
test -n "$pp_components" || pp_error "No components?"
pp_check_var_is_defined "name"
pp_check_var_is_defined "version"
pp_files_check_duplicates
pp_files_check_coverage
pp_die_if_errors "Errors during sanity checks"
fi
# stop now if we're only running the front
$pp_opt_only_front && return
if test x"$pp_opt_strip" = x"true"; then
pp_strip_binaries
fi
# run the back-end to generate the package
pp_debug "calling backend"
pp_backend
pp_die_if_errors "Errors during backend processing"
# copy the resulting package files to PP_PKGDESTDIR or .
for f in `pp_backend_names` -; do
test x"$f" = x"-" && continue
pp_debug "copying: $f to `pwd`"
if pp_verbose cp -r $pp_wrkdir/$f ${PP_PKGDESTDIR:-.}; then
echo "${PP_PKGDESTDIR:+$PP_PKGDESTDIR/}$f"
else
pp_error "$f: missing package"
fi
done
pp_die_if_errors "Errors during package copying"
}
pp_install_script () {
pp_debug "writing install script to $pp_opt_install_script"
rm -f $pp_opt_install_script
pp_backend_install_script > $pp_opt_install_script
pp_die_if_errors "Errors during package install script"
chmod +x $pp_opt_install_script
}
pp_main () {
# If PP_DEV_PATH is set, then jump to that script.
# (Useful when working on polypkg source that isn't installed)
if test -n "$PP_DEV_PATH" -a x"$PP_DEV_PATH" != x"$0"; then
pp_warn "switching from $0 to $PP_DEV_PATH ..."
exec "$PP_DEV_PATH" "$@" || exit 1
fi
pp_set_expand_converter_or_reexec "$@"
pp_parseopts "$@"
if $pp_opt_version; then
#-- print version and exit
echo "polypkg $pp_version"
exit 0
fi
pp_set_platform
trap 'pp_main_cleanup' 0
pp_wrkdir="$pp_opt_wrkdir"
pp_debug "pp_wrkdir = $pp_wrkdir"
rm -rf "$pp_wrkdir"
mkdir -p "$pp_wrkdir"
pp_destdir="$pp_opt_destdir"
pp_debug "pp_destdir = $pp_destdir"
if $pp_opt_probe; then
pp_backend_init
pp_backend_probe
elif $pp_opt_vas_platforms; then
pp_backend_init
pp_backend_vas_platforms
elif test -n "$pp_opt_eval"; then
#-- execute a shell command
eval "$pp_opt_eval" || exit
else
pp_drive
if test -n "$pp_opt_install_script"; then
pp_install_script
fi
fi
exit 0
}
pp_errors=false
if test -n "$TERM" -a -t 1 && (tput op) >/dev/null 2>/dev/null; then
pp_col_redfg=`tput setf 4` 2>/dev/null
pp_col_bluefg=`tput setf 1` 2>/dev/null
pp_col_reset=`tput op` 2>/dev/null
else
pp_col_redfg='['
pp_col_bluefg='['
pp_col_reset=']'
fi
pp__warn () {
if test x"" = x"$pp_lineno"; then
echo "$1 $2" >&2
else
echo "$1 line $pp_lineno: $2" >&2
fi
}
pp_warn () {
pp__warn "pp: ${pp_col_redfg}warning${pp_col_reset}" "$*"
}
pp_error () {
pp__warn "pp: ${pp_col_redfg}error${pp_col_reset}" "$*"
pp_errors=true
}
pp_die () {
pp_error "$@"
exit 1
}
pp_die_if_errors () {
$pp_errors && pp_die "$@"
}
pp_debug () {
$pp_opt_debug && echo "${pp_col_bluefg}debug${pp_col_reset} $*" >&2
}
pp_verbose () {
$pp_opt_verbose && echo "pp: ${pp_col_bluefg}info${pp_col_reset} $*" >&2
"$@";
}
pp_substitute () {
sed -e 's,%(\([^)]*\)),`\1`,g' \
-e 's,%{\([^}]*\)},${\1},g' \
-e 's,$,,' |
tr '' '\012' |
sed -e '/^[^]/s/["$`\\]/\\&/g' \
-e 's/^//' \
-e '1s/^/echo "/' \
-e '$s,$,",' \
-e 's,,"echo ",g' |
tr -d '\012' |
tr '' '\012'
echo
}
pp_incr () {
eval "$1=\`expr \$$1 + 1\`"
}
pp_decr () {
eval "$1=\`expr \$$1 - 1\`"
}
pp_check_var_is_defined () {
if eval test -z "\"\$$1\""; then
pp_error "\$$1: not set"
eval "$1=undefined"
fi
}
pp_contains () {
case " $1 " in
*" $2 "*) return 0;;
*) return 1;;
esac
}
pp_contains_all () {
typeset _s _c
_l="$1"; shift
for _w
do
pp_contains "$_l" "$_w" || return 1
done
return 0
}
pp_contains_any () {
typeset _s _c
_l="$1"; shift
for _w
do
pp_contains "$_l" "$_w" && return 0
done
return 1
}
pp_add_to_list () {
if eval test -z \"\$$1\"; then
eval $1='"$2"'
elif eval pp_contains '"$'$1'"' '"$2"'; then
: already there
else
eval $1='"$'$1' $2"'
fi
}
pp_unique () {
typeset result element
result=
for element
do
pp_add_to_list result $element
done
echo $result
}
pp_mode_strip_altaccess () {
case "$1" in
??????????[+.])
echo `echo "$1" | cut -b -10`;;
*)
echo "$1";;
esac
}
pp_mode_from_ls () {
typeset umode gmode omode smode
set -- `pp_mode_strip_altaccess "$1"`
case "$1" in
?--[-X]??????) umode=0;;
?--[xs]??????) umode=1;;
?-w[-X]??????) umode=2;;
?-w[xs]??????) umode=3;;
?r-[-X]??????) umode=4;;
?r-[xs]??????) umode=5;;
?rw[-X]??????) umode=6;;
?rw[xs]??????) umode=7;;
*) pp_error "bad user mode $1";;
esac
case "$1" in
????--[-S]???) gmode=0;;
????--[xs]???) gmode=1;;
????-w[-S]???) gmode=2;;
????-w[xs]???) gmode=3;;
????r-[-X]???) gmode=4;;
????r-[xs]???) gmode=5;;
????rw[-X]???) gmode=6;;
????rw[xs]???) gmode=7;;
*) pp_error "bad group mode $1";;
esac
case "$1" in
???????--[-T]) omode=0;;
???????--[xt]) omode=1;;
???????-w[-T]) omode=2;;
???????-w[xt]) omode=3;;
???????r-[-T]) omode=4;;
???????r-[xt]) omode=5;;
???????rw[-T]) omode=6;;
???????rw[xt]) omode=7;;
*) pp_error "bad other mode $1";;
esac
case "$1" in
???[-x]??[-x]??[-x]) smode=;;
???[-x]??[-x]??[tT]) smode=1;;
???[-x]??[Ss]??[-x]) smode=2;;
???[-x]??[Ss]??[tT]) smode=3;;
???[Ss]??[-x]??[-x]) smode=4;;
???[Ss]??[-x]??[tT]) smode=5;;
???[Ss]??[Ss]??[-x]) smode=6;;
???[Ss]??[Ss]??[tT]) smode=7;;
*) pp_error "bad set-id mode $1";;
esac
echo "$smode$umode$gmode$omode"
}
pp_find_recurse () {
pp_debug "find: ${1#$pp_destdir}/"
for f in "$1"/.* "$1"/*; do
case "$f" in */.|*/..) continue;; esac # should never happen!
if test -d "$f" -o -f "$f" -o -h "$f"; then
if test -d "$f" -a ! -h "$f"; then
echo "${f#$pp_destdir}/"
pp_find_recurse "$f"
else
echo "${f#$pp_destdir}"
fi
fi
done
}
pp_prepend () {
#test -t && pp_warn "pp_prepend: stdin is a tty?"
if test -f $1; then
pp_debug "prepending to $1"
mv $1 $1._prepend
cat - $1._prepend >$1
rm -f $1._prepend
else
pp_debug "prepend: creating $1"
cat >$1
fi
}
pp_note_file_used() {
echo "$1" >> $pp_wrkdir/all.files
}
pp_create_dir_if_missing () {
case "$1" in
*/) pp_error "pp_create_dir_if_missing: trailing / forbidden";;
"") return 0;;
*) if test ! -d "$pp_destdir$1"; then
pp_debug "fabricating directory $1/"
pp_create_dir_if_missing "${1%/*}"
mkdir "$pp_destdir$1" &&
pp_note_file_used "$1/"
pp_remove_later "$1" &&
chmod ${2:-755} "$pp_destdir$1"
fi;;
esac
}
pp_add_file_if_missing () {
typeset dir
#-- check that the file isn't already declared in the component
if test -s $pp_wrkdir/%files.${2:-run}; then
awk "\$6 == \"$1\" {exit 1}" < $pp_wrkdir/%files.${2:-run} || return 1
fi
pp_create_dir_if_missing "${1%/*}"
pp_debug "fabricating file $1"
echo "f ${3:-755} - - ${4:--} $1" >> $pp_wrkdir/%files.${2:-run}
pp_note_file_used "$1"
pp_remove_later "$1"
return 0
}
pp_add_transient_file () {
test -f "$pp_destdir$1" && pp_die "$pp_destdir$1: exists"
pp_create_dir_if_missing "${1%/*}"
pp_debug "transient file $1"
pp_note_file_used "$1"
pp_remove_later "$1"
}
pp_remove_later () {
{
echo "$1"
test -s $pp_wrkdir/pp_cleanup && cat $pp_wrkdir/pp_cleanup
} > $pp_wrkdir/pp_cleanup.new
mv $pp_wrkdir/pp_cleanup.new $pp_wrkdir/pp_cleanup
}
pp_ls_readlink () {
if test -h "$1"; then
ls -1ld "$1" | sed -ne 's,.* -> ,,p'
else
echo "$1: not a symbolic link" >&2
return 1
fi
}
pp_remove_later_now () {
typeset f
if test -s $pp_wrkdir/pp_cleanup; then
pp_debug "pp_remove_later_now"
while read f; do
pp_debug "removing $pp_destdir$f"
if test -d $pp_destdir$f; then
rmdir $pp_destdir$f
else
rm $pp_destdir$f
fi
done < $pp_wrkdir/pp_cleanup
rm $pp_wrkdir/pp_cleanup
fi
}
pp_readlink() {
pp_debug "&& pp_readlink_fn=$pp_readlink_fn"
if test -n "$pp_readlink_fn"; then
pp_debug "&& calling $pp_readlink_fn $*"
"$pp_readlink_fn" "$@"
else
readlink "$@"
fi
}
pp_install_script_common () {
cat <<-.
# Automatically generated for
# $name $version ($pp_platform)
# by PolyPackage $pp_version
usage () {
case "$1" in
"list-services")
echo "usage: \$0 list-services" ;;
"list-components")
echo "usage: \$0 list-components" ;;
"list-files")
echo "usage: \$0 list-files {cpt...|all}" ;;
"install")
echo "usage: \$0 install {cpt...|all}" ;;
"uninstall")
echo "usage: \$0 uninstall {cpt...|all}" ;;
"start")
echo "usage: \$0 start {svc...}" ;;
"stop")
echo "usage: \$0 stop {svc...}" ;;
"print-platform")
echo "usage: \$0 print-platform" ;;
*)
echo "usage: \$0 [-q] command [args]"
echo " list-services"
echo " list-components"
echo " list-files {cpt...|all}"
echo " install {cpt...|all}"
echo " uninstall {cpt...|all}"
echo " start {svc...}"
echo " stop {svc...}"
echo " print-platform"
;;
esac >&2
exit 1
}
if test x"\$1" = x"-q"; then
shift
verbose () { "\$@"; }
verbosemsg () { : ; }
else
verbose () { echo "+ \$*"; "\$@"; }
verbosemsg () { echo "\$*"; }
fi
.
}
pp_functions () {
typeset func deps allfuncs
allfuncs=
while test $# -gt 0; do
pp_add_to_list allfuncs "$1"
deps=`pp_backend_function "$1:depends"`
shift
set -- `pp_unique "$@" $deps`
done
for func in $allfuncs
do
pp_debug "generating function code for '$1'"
echo ""
echo "$func () {"
case "$func" in
pp_mkgroup|pp_mkuser|pp_havelib) echo <<.;;
if test \$# -lt 1; then
echo "$func: not enough arguments" >&2
return 1
fi
.
esac
pp_backend_function "$func" || cat <<.
echo "$func: not implemented" >&2
return 1
.
echo "}"
done
}
pp_function () {
pp_functions "$1"
}
pp_makevar () {
#-- convert all non alpha/digits to underscores
echo "$*" | tr -c '[a-z][A-Z][0-9]\012' '[_*]'
}
pp_getpwuid () {
awk -F: '$3 == uid { if (!found) print $1; found=1; } END { if (!found) exit 1; }' uid="$1" \
< /etc/passwd || pp_error "no local username for uid $1"
}
pp_getgrgid () {
awk -F: '$3 == gid { if (!found) print $1; found=1; } END { if (!found) exit 1; }' gid="$1" \
< /etc/group || pp_error "no local group for gid $1"
}
pp_backend_function_getopt () {
cat <<'..'
pp_getopt () {
_pp_optstring="$1"; shift; eval `_pp_getopt "$_pp_optstring"`
}
_pp_getopt_meta=s,[\\\\\"\'\`\$\&\;\(\)\{\}\#\%\ \ ],\\\\\&,g
_pp_protect () {
sed "$_pp_getopt_meta" <<. | tr '\012' ' '
$*
.
}
_pp_protect2 () {
sed "s,^..,,$pp_getopt_meta" <<. | tr '\012' ' '
$*
.
}
_pp_nonl () {
tr '\012' ' ' <<.
$*
.
}
_pp_getopt () {
_pp_nonl '_pp_nonl set --; while test $# -gt 0; do case "$1" in "--") shift; break;;'
sed 's/\([^: ]:*\)/<@<\1>@>/g;
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' <<.
$1
.
_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'
echo
}
..
}
pp_copy_unstripped () {
typeset filedir realdir
filedir="`dirname ${1#$pp_destdir}`"
realdir="$pp_wrkdir/unstripped/$filedir"
mkdir -p "$realdir"
# Can't use hardlinks because `strip` modifies the original file in-place
cp "$1" "$realdir"
}
pp_package_stripped_binaries () {
(cd "$pp_wrkdir/unstripped" && tar -c .) \
| gzip > "$name-dbg-$version.tar.gz"
rm -rf "$pp_wrkdir/unstripped"
}
pp_strip_binaries () {
if test x"$pp_opt_save_unstripped" = x"true"; then
rm -rf "$pp_wrkdir/unstripped"
mkdir "$pp_wrkdir/unstripped"
fi
for f in `find "$pp_destdir" -type f`; do
if file "$f" | awk '{print $2}' | grep ^ELF >/dev/null 2>&1; then
if test x"$pp_opt_save_unstripped" = x"true"; then
if file "$f" | LC_MESSAGES=C grep 'not stripped' >/dev/null 2>&1; then
pp_debug "Saving unstripped binary $f"
pp_copy_unstripped "$f"
else
pp_debug "$f is already stripped; not saving a copy"
fi
fi
pp_debug "Stripping unnecessary symbols from $f"
strip "$f"
fi
done
if test x"$pp_opt_save_unstripped" = x"true"; then
pp_package_stripped_binaries
fi
}
pp_if_true=0
pp_if_false=0
pp_frontend_init () {
name=
version=
build_number=
summary="no summary"
description="No description"
copyright="Copyright 2018 One Identity LLC. ALL RIGHTS RESERVED."
#-- if the user supplied extra arguments on the command line
# then load them now.
pp_debug "pp_opt_init_vars=$pp_opt_init_vars"
test -n "$pp_opt_init_vars" && eval "$pp_opt_init_vars"
}
pp_is_qualifier () {
typeset ret
case "$1" in
"["*"]") ret=true;;
*) ret=false;;
esac
pp_debug "is_qualifier: $* -> $ret"
test $ret = true
}
pp_eval_qualifier () {
typeset ret
case "$1" in
"[!$pp_platform]"| \
"[!"*",$pp_platform]"| \
"[!$pp_platform,"*"]"| \
"[!"*",$pp_platform,"*"]") ret=false;;
"[!"*"]") ret=true;;
"[$pp_platform]"| \
"["*",$pp_platform]"| \
"[$pp_platform,"*"]"| \
"["*",$pp_platform,"*"]") ret=true;;
"["*"]") ret=false;;
*) pp_die "pp_eval_qualifier: bad qualifier '$1'"
esac
pp_debug "eval: $* -> $ret"
test true = $ret
}
pp_frontend_if () {
typeset ifcmd ifret
ifcmd="$1";
shift
case "$ifcmd" in
%if) if test 0 = $pp_if_false; then
case "$*" in
true |1) pp_incr pp_if_true;;
false|0) pp_incr pp_if_false;;
*)
ifret=true
if pp_is_qualifier "$*"; then
pp_eval_qualifier "$*" || ifret=false
else
eval test "$@" || ifret=false
pp_debug "evaluating test $* -> $ifret"
fi
pp_incr pp_if_$ifret
;;
esac
else
pp_incr pp_if_false
fi;;
%else) test $# = 0 || pp_warn "ignoring argument to %else"
if test $pp_if_false -gt 1; then
: no change
elif test $pp_if_false = 1; then
pp_incr pp_if_true
pp_decr pp_if_false
elif test $pp_if_true = 0; then
pp_die "unmatched %else"
else
pp_incr pp_if_false
pp_decr pp_if_true
fi;;
%endif) test $# = 0 || pp_warn "ignoring argument to %endif"
if test $pp_if_false -gt 0; then
pp_decr pp_if_false
elif test $pp_if_true -gt 0; then
pp_decr pp_if_true
else
pp_die "unmatched %endif"
fi;;
*) pp_die "frontend_if: unknown cmd $ifcmd";;
esac
}
pp_frontend () {
typeset section newsection sed_word sed_ws line cpt svc
typeset section_enabled newsection_enabled s sed sed_candidate
section='%_initial'
newsection='%_initial'
section_enabled=:
newsection_enabled=:
sed_word="[a-zA-Z_][a-zA-Z_0-9]*"
sed_ws="[ ]"
#-- not all seds are created equal
sed=
for sed_candidate in ${PP_SED:-sed} /usr/xpg4/bin/sed; do
if echo 'foo' | $sed_candidate -ne '/^\(x\)*foo/p' | grep foo > /dev/null
then
sed="$sed_candidate"
break
fi
done
test -z "$sed" &&
pp_die "sed is broken on this system"
pp_lineno=0
#-- Note: this sed script should perform similar to pp_eval_qualifier()
$sed -e "/^#/s/.*//" \
-e "/^\\[!\\($sed_word,\\)*$pp_platform\\(,$sed_word\\)*\\]/s/.*//" \
-e "s/^\\[\\($sed_word,\\)*$pp_platform\\(,$sed_word\\)*\\]$sed_ws*//" \
-e "s/^\\[!\\($sed_word,\\)*$sed_word\\]$sed_ws*//" \
-e "/^\\[\\($sed_word,\\)*$sed_word\\]/s/.*//" \
-e "s/^%$sed_ws*/%/" \
-e "s/^$sed_ws/%\\\\&/" \
> $pp_wrkdir/frontend.tmp
#-- add an ignore section at the end to force section completion
echo '%ignore' >> $pp_wrkdir/frontend.tmp
echo >> $pp_wrkdir/frontend.tmp
exec 0<$pp_wrkdir/frontend.tmp
: > $pp_wrkdir/tmp
: > $pp_wrkdir/%fixup
while read -r line; do
#-- Convert leading double-% to single-%, or switch sections
pp_incr pp_lineno
pp_debug "line $pp_lineno: $line"
set -f
set -- $line
set +f
#pp_debug "line $pp_lineno: $*"
case "$line" in %*)
case "$1" in
%if|%else|%endif)
pp_debug "processing if directive $1"
pp_frontend_if "$@"
continue;;
esac
test 0 -ne $pp_if_false && continue # ignore lines %if'd out
case "$1" in
%set|%fixup|%ignore)
pp_debug "processing new section $1"
newsection="$1"; shift
newsection_enabled=:
if pp_is_qualifier "$1"; then
pp_eval_qualifier "$1" || newsection_enabled=false
shift
fi
test $# -eq 0 || pp_warn "ignoring extra arguments: $line"
continue;;
%pre|%post|%preun|%postup|%preup|%postun|%files|%depend|%check|%conflict)
pp_debug "processing new component section $*"
s="$1"; shift
if test $# -eq 0 || pp_is_qualifier "$1"; then
cpt=run
else
cpt="$1"
shift
fi
newsection="$s.$cpt"
newsection_enabled=:
if test $# -gt 0 && pp_is_qualifier "$1"; then
pp_eval_qualifier "$1" || newsection_enabled=false
shift
fi
test $# -eq 0 ||
pp_warn "ignoring extra arguments: $line"
case "$cpt" in
run|dbg|doc|dev)
$newsection_enabled && pp_add_component "$cpt";;
x-*) :;; # useful for discarding stuff
*) pp_error "unknown component: $1 $cpt";;
esac
continue;;
%pp)
newsection="%ignore"; shift
if test $# -gt 0; then
pp_set_api_version "$1"
shift
else
pp_error "%pp: missing version"
fi
test $# -gt 0 &&
pp_error "%pp: too many arguments"
continue;;
%service)