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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
|
#!/bin/bash
# ebuild-default-functions.sh; default functions for ebuild env that aren't saved- specific to the portage instance.
# Copyright 2005-2006 Brian Harring <ferringb@gmail.com>
# Copyright 2004-2006 Gentoo Foundation
has_version()
{
# if there is a predefined portageq call, use it.
# why? Because if we're being called from an ebuild daemon/processor, it can hijack the call, and access the
# running portage instance already, saving at least .5s in load up of portageq.
# time emerge -s mod_php w/out the hijack == 23s
# time emerge -s mod_php w/ the hijack == < 6s
local -i e
[ "${EBUILD_PHASE}" == "depend" ] && echo "QA Notice: has_version() in global scope: ${CATEGORY}/$PF" >&2
# return shell-true/shell-false if exists.
# Takes single depend-type atoms.
# XXX: harring; portageq should be in path if there isn't a func. if not, well, tough cookies
portageq 'has_version' "${ROOT}" "$1"
return $?
}
best_version()
{
local -i e
# see above
portageq 'best_version' "${ROOT}" "$1"
return $?
}
check_KV()
{
if [ -z "${KV}" ]; then
eerror ""
eerror "Could not determine your kernel version."
eerror "Make sure that you have /usr/src/linux symlink."
eerror "And that said kernel has been configured."
eerror "You can also simply run the following command"
eerror "in the kernel referenced by /usr/src/linux:"
eerror " make include/linux/version.h"
eerror ""
die
fi
}
# adds ".keep" files so that dirs aren't auto-cleaned
keepdir()
{
dodir "$@"
local x
if [ "$1" == "-R" ] || [ "$1" == "-r" ]; then
shift
find "$@" -type d -printf "${D}/%p/.keep\n" | tr "\n" "\0" | $XARGS -0 -n100 touch || die "Failed to recursive create .keep files"
else
for x in "$@"; do
touch "${D}/${x}/.keep" || die "Failed to create .keep in ${D}/${x}"
done
fi
}
# sandbox support functions
addread()
{
export SANDBOX_READ="$SANDBOX_READ:$1"
}
addwrite()
{
export SANDBOX_WRITE="$SANDBOX_WRITE:$1"
}
adddeny()
{
export SANDBOX_DENY="$SANDBOX_DENY:$1"
}
addpredict()
{
export SANDBOX_PREDICT="$SANDBOX_PREDICT:$1"
}
unpack()
{
local x y myfail tarvars srcdir
if [ "$USERLAND" == "BSD" ]; then
tarvars=""
else
tarvars="--no-same-owner"
fi
[ -z "$*" ] && die "Nothing passed to the 'unpack' command"
for x in "$@"; do
echo ">>> Unpacking ${x} to ${PWD}"
myfail="failure unpacking ${x}"
y="${x%.*}"
y="${y##*.}"
if [ "${x:0:2}" == "./" ]; then
srcdir=''
else
srcdir="${DISTDIR}"
fi
[ ! -s "${srcdir}/${x}" ] && die "$myfail: empty file"
case "${x##*.}" in
tar)
tar ${tarvars} -xf "${src}${x}" || die "$myfail"
;;
tgz)
tar ${tarvars} -xzf "${srcdir}${x}" || die "$myfail"
;;
tbz2)
bzip2 -dc "${srcdir}${x}" | tar ${tarvars} -xf -
assert "$myfail"
;;
ZIP|zip|jar)
unzip -qo "${srcdir}${x}" || die "$myfail"
;;
gz|Z|z)
if [ "${y}" == "tar" ]; then
gzip -dc "${srcdir}${x}" | tar ${tarvars} -xf -
assert "$myfail"
else
gzip -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
fi
;;
bz2)
if [ "${y}" == "tar" ]; then
bzip2 -dc "${srcdir}${x}" | tar ${tarvars} -xf -
assert "$myfail"
else
bzip2 -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
fi
;;
RAR|rar)
unrar x -idq "${srcdir}/${x}" || die "$myfail"
;;
LHa|LHA|lha|lzh)
lha xqf "${srcdir}/${x}" || die "$myfail"
;;
*)
echo "unpack ${x}: file format not recognized. Ignoring."
;;
esac
done
}
dyn_setup()
{
MUST_EXPORT_ENV="yes"
if [ "$USERLAND" == "Linux" ]; then
# The next bit is to ease the broken pkg_postrm()'s
# some of the gcc ebuilds have that nuke the new
# /lib/cpp and /usr/bin/cc wrappers ...
# Make sure we can have it disabled somehow ....
if [ "${DISABLE_GEN_GCC_WRAPPERS}" != "yes" ]; then
# Create /lib/cpp if missing or a symlink
if [ -L /lib/cpp -o ! -e /lib/cpp ]; then
[ -L /lib/cpp ] && rm -f /lib/cpp
gen_wrapper /lib/cpp cpp
fi
# Create /usr/bin/cc if missing for a symlink
if [ -L /usr/bin/cc -o ! -e /usr/bin/cc ]; then
[ -L /usr/bin/cc ] && rm -f /usr/bin/cc
gen_wrapper /usr/bin/cc gcc
fi
fi
fi
pkg_setup
}
dyn_unpack()
{
trap "abort_unpack" SIGINT SIGQUIT
local newstuff="no"
MUST_EXPORT_ENV="yes"
if [ -e "${WORKDIR}" ]; then
local x
local checkme
for x in ${AA}; do
echo ">>> Checking ${x}'s mtime..."
if [ "${DISTDIR}/${x}" -nt "${WORKDIR}" ]; then
echo ">>> ${x} has been updated; recreating WORKDIR..."
newstuff="yes"
rm -rf "${WORKDIR}"
break
fi
done
if [ "${EBUILD}" -nt "${WORKDIR}" ]; then
echo ">>> ${EBUILD} has been updated; recreating WORKDIR..."
newstuff="yes"
rm -rf "${WORKDIR}"
fi
fi
install -m0700 -d "${WORKDIR}" || die "Failed to create dir '${WORKDIR}'"
[ -d "$WORKDIR" ] && cd "${WORKDIR}"
echo ">>> Unpacking source..."
src_unpack
echo ">>> Source unpacked."
trap SIGINT SIGQUIT
}
abort_handler()
{
local msg
if [ "$2" != "fail" ]; then
msg="${EBUILD}: ${1} aborted; exiting."
else
msg="${EBUILD}: ${1} failed; exiting."
fi
echo
echo "$msg"
echo
eval ${3}
#unset signal handler
trap SIGINT SIGQUIT
}
abort_compile()
{
abort_handler "src_compile" $1
exit 1
}
abort_unpack()
{
abort_handler "src_unpack" $1
exit 1
}
abort_package()
{
abort_handler "dyn_package" $1
rm -f "${PKGDIR}"/All/${PF}.t*
exit 1
}
abort_test()
{
abort_handler "dyn_test" $1
exit 1
}
abort_install()
{
abort_handler "src_install" $1
exit 1
}
dyn_compile()
{
MUST_EXPORT_ENV="yes"
export DESTTREE=/usr
export INSDESTTREE=""
export EXEDESTTREE=""
export DOCDESTTREE=""
export INSOPTIONS="-m0644"
export EXEOPTIONS="-m0755"
export LIBOPTIONS="-m0644"
export DIROPTIONS="-m0755"
export MOPREFIX=${PN}
trap "abort_compile" SIGINT SIGQUIT
[ "${CFLAGS-unset}" != "unset" ] && export CFLAGS
[ "${CXXFLAGS-unset}" != "unset" ] && export CXXFLAGS
[ "${LIBCFLAGS-unset}" != "unset" ] && export LIBCFLAGS
[ "${LIBCXXFLAGS-unset}" != "unset" ] && export LIBCXXFLAGS
[ "${LDFLAGS-unset}" != "unset" ] && export LDFLAGS
[ "${ASFLAGS-unset}" != "unset" ] && export ASFLAGS
[ ! -z "${DISTCC_DIR}" ] && addwrite "${DISTCC_DIR}"
if [ ! -e "${T}/build-info" ]; then
mkdir "${T}/build-info"
fi
cp "${EBUILD}" "${T}/build-info/"
if [ -d "${S}" ]; then
cd "${S}"
fi
#our custom version of libtool uses $S and $D to fix
#invalid paths in .la files
export S D
#some packages use an alternative to $S to build in, cause
#our libtool to create problematic .la files
export PWORKDIR="$WORKDIR"
src_compile
#|| abort_compile "fail"
cd "${T}/build-info"
echo "$ASFLAGS" > ASFLAGS
echo "$CATEGORY" > CATEGORY
echo "$CBUILD" > CBUILD
echo "$CC" > CC
echo "$CDEPEND" > CDEPEND
echo "$CFLAGS" > CFLAGS
echo "$CHOST" > CHOST
echo "$CXX" > CXX
echo "$CXXFLAGS" > CXXFLAGS
echo "$DEPEND" > DEPEND
echo "$EXTRA_ECONF" > EXTRA_ECONF
echo "$FEATURES" > FEATURES
echo "$INHERITED" > INHERITED
echo "$IUSE" > IUSE
echo "$PKGUSE" > PKGUSE
echo "$LDFLAGS" > LDFLAGS
echo "$LIBCFLAGS" > LIBCFLAGS
echo "$LIBCXXFLAGS" > LIBCXXFLAGS
echo "$LICENSE" > LICENSE
echo "$PDEPEND" > PDEPEND
echo "$PF" > PF
echo "$PROVIDE" > PROVIDE
echo "$RDEPEND" > RDEPEND
echo "$RESTRICT" > RESTRICT
echo "$SLOT" > SLOT
echo "$USE" > USE
export_environ "${T}/build-info/environment.bz2" 'bzip2 -c9'
if hasq nostrip $FEATURES $RESTRICT; then
touch DEBUGBUILD
fi
trap SIGINT SIGQUIT
}
dyn_test()
{
trap "abort_test" SIGINT SIGQUIT
echo ">>> Test phase [enabled]: ${CATEGORY}/${PF}"
MUST_EXPORT_ENV="yes"
if [ -d "${S}" ]; then
cd "${S}"
fi
src_test
trap SIGINT SIGQUIT
}
stat_perms()
{
local f
f=$(stat -c '%f' "$1")
f=$(printf "%o" 0x$f)
f=${f:${#f}-4}
echo $f
}
dyn_install()
{
trap "abort_install" SIGINT SIGQUIT
rm -rf "${D}"
mkdir "${D}"
if [ -d "${S}" ]; then
cd "${S}"
fi
echo
echo ">>> Install ${PF} into ${D} category ${CATEGORY}"
#our custom version of libtool uses $S and $D to fix
#invalid paths in .la files
export S D
#some packages uses an alternative to $S to build in, cause
#our libtool to create problematic .la files
export PWORKDIR="$WORKDIR"
src_install
#|| abort_install "fail"
prepall
cd "${D}"
declare -i UNSAFE=0
for i in $(find "${D}/" -type f -perm -2002); do
UNSAFE=$(($UNSAFE + 1))
echo "UNSAFE SetGID: $i"
done
for i in $(find "${D}/" -type f -perm -4002); do
UNSAFE=$(($UNSAFE + 1))
echo "UNSAFE SetUID: $i"
done
if type -p scanelf > /dev/null ; then
# Make sure we disallow insecure RUNPATH/RPATH's
# Don't want paths that point to the tree where the package was built
# (older, broken libtools would do this). Also check for null paths
# because the loader will search $PWD when it finds null paths.
f=$(scanelf -qyRF '%r %p' "${D}" | grep -E "(${WORKDIR}|${D}|: |::|^ )")
if [[ -n ${f} ]] ; then
echo -ne '\a\n'
echo "QA Notice: the following files contain insecure RUNPATH's"
echo " Please file a bug about this at http://bugs.gentoo.org/"
echo " For more information on this issue, kindly review:"
echo " http://bugs.gentoo.org/81745"
echo "${f}"
echo -ne '\a\n'
die "Insecure binaries detected"
fi
# Check for setid binaries but are not built with BIND_NOW
f=$(scanelf -qyRF '%b %p' "${D}")
if [[ -n ${f} ]] ; then
echo -ne '\a\n'
echo "QA Notice: the following files are setXid, dyn linked, and using lazy bindings"
echo " This combination is generally discouraged. Try re-emerging the package:"
echo " LDFLAGS='-Wl,-z,now' emerge ${PN}"
echo "${f}"
echo -ne '\a\n'
[[ ${FEATURES/stricter} != "${FEATURES}" ]] \
&& die "Aborting due to lazy bindings"
sleep 1
fi
# TEXTREL's are baaaaaaaad
f=$(scanelf -qyRF '%t %p' "${D}")
if [[ -n ${f} ]] ; then
echo -ne '\a\n'
echo "QA Notice: the following files contain runtime text relocations"
echo " Text relocations require a lot of extra work to be preformed by the"
echo " dynamic linker which will cause serious performance impact on IA-32"
echo " and might not function properly on other architectures hppa for example."
echo " If you are a programmer please take a closer look at this package and"
echo " consider writing a patch which addresses this problem."
echo "${f}"
echo -ne '\a\n'
[[ ${FEATURES/stricter} != "${FEATURES}" ]] \
&& die "Aborting due to textrels"
sleep 1
fi
# Check for files with executable stacks
f=$(scanelf -qyRF '%e %p' "${D}")
if [[ -n ${f} ]] ; then
echo -ne '\a\n'
echo "QA Notice: the following files contain executable stacks"
echo " Files with executable stacks will not work properly (or at all!)"
echo " on some architectures/operating systems. A bug should be filed"
echo " at http://bugs.gentoo.org/ to make sure the file is fixed."
echo "${f}"
echo -ne '\a\n'
[[ ${FEATURES/stricter} != "${FEATURES}" ]] \
&& die "Aborting due to +x stack"
sleep 1
fi
# Save NEEDED information
scanelf -qyRF '%p %n' "${D}" | sed -e 's:^:/:' > "${T}/build-info/NEEDED"
fi
if [[ $UNSAFE > 0 ]]; then
die "There are ${UNSAFE} unsafe files. Portage will not install them."
fi
local file s
find "${D}/" -user portage -print | while read file; do
ewarn "file $file was installed with user portage!"
s=$(stat_perms "$file")
chown root "$file"
#XXX: Stable does not have the symlink test
[ -h "$file" ] || chmod "$s" "$file"
done
find "${D}/" -group portage -print | while read file; do
# Too annoying - uncommenting this as it's a regression
#ewarn "file $file was installed with group portage!"
s=$(stat_perms "$file")
if [ "$USERLAND" == "BSD" ]; then
chgrp wheel "$file"
else
chgrp root "$file"
fi
#XXX: Stable does not have the symlink test
[ -h "$file" ] || chmod "$s" "$file"
done
if hasq multilib-strict ${FEATURES} && [ -x /usr/bin/file -a -x /usr/bin/find -a \
-n "${MULTILIB_STRICT_DIRS}" -a -n "${MULTILIB_STRICT_DENY}" ]; then
MULTILIB_STRICT_EXEMPT=${MULTILIB_STRICT_EXEMPT:-"(perl5|gcc|gcc-lib)"}
for dir in ${MULTILIB_STRICT_DIRS}; do
[ -d "${D}/${dir}" ] || continue
for file in $(find ${D}/${dir} -type f | egrep -v "^${D}/${dir}/${MULTILIB_STRICT_EXEMPT}"); do
file ${file} | egrep -q "${MULTILIB_STRICT_DENY}" && die "File ${file} matches a file type that is not allowed in ${dir}"
done
done
fi
echo ">>> Completed installing ${PF} into ${D}"
echo
MUST_EXPORT_ENV="yes"
trap SIGINT SIGQUIT
}
dyn_postinst()
{
pkg_postinst
}
dyn_preinst()
{
# set IMAGE depending if this is a binary or compile merge
local IMAGE=${D}
[ "${EMERGE_FROM}" == "binary" ] && IMAGE=${PKG_TMPDIR}/${PF}/bin/
# Make sure D is where the package expects it
D=${IMAGE} pkg_preinst
# remove man pages
if hasq noman $FEATURES; then
rm -fR "${IMAGE}"/usr/share/man
fi
# remove info pages
if hasq noinfo $FEATURES; then
rm -fR "${IMAGE}"/usr/share/info
fi
# remove docs
if hasq nodoc $FEATURES; then
rm -fR "${IMAGE}"/usr/share/doc
fi
# hopefully this will someday allow us to get rid of the no* feature flags
# we don't want globbing for initial expansion, but afterwards, we do
#XXX: rewrite this to use a while loop instead.
local shopts=$-
set -o noglob
for no_inst in `echo "${INSTALL_MASK}"` ; do
set +o noglob
einfo "Removing ${no_inst}"
# normal stuff
rm -Rf "${IMAGE}"/${no_inst} &> /dev/null
# we also need to handle globs (*.a, *.h, etc)
find "${IMAGE}" -name ${no_inst} -exec rm -fR {} \; &> /dev/null
done
# set everything back the way we found it
set +o noglob
set -${shopts}
# remove share dir if unnessesary
if hasq nodoc $FEATURES -o hasq noman $FEATURES -o hasq noinfo $FEATURES; then
rmdir "${IMAGE}"/usr/share &> /dev/null
fi
# Smart FileSystem Permissions
if hasq sfperms $FEATURES; then
for i in $(find "${IMAGE}"/ -type f -perm -4000); do
ebegin ">>> SetUID: [chmod go-r] $i "
chmod go-r "$i"
eend $?
done
for i in $(find "${IMAGE}"/ -type f -perm -2000); do
ebegin ">>> SetGID: [chmod o-r] $i "
chmod o-r "$i"
eend $?
done
fi
# total suid control.
if hasq suidctl $FEATURES > /dev/null ; then
sfconf=/etc/portage/suidctl.conf
echo ">>> Preforming suid scan in ${IMAGE}"
for i in $(find "${IMAGE}"/ -type f \( -perm -4000 -o -perm -2000 \) ); do
if [ -s "${sfconf}" ]; then
suid=$(grep ^${i/${IMAGE}/}$ ${sfconf})
if [ "${suid}" = "${i/${IMAGE}/}" ]; then
echo "- ${i/${IMAGE}/} is an approved suid file"
else
echo ">>> Removing sbit on non registered ${i/${IMAGE}/}"
sleepbeep 6
chmod ugo-s "${i}"
grep ^#${i/${IMAGE}/}$ ${sfconf} > /dev/null || {
# sandbox prevents us from writing directly
# to files outside of the sandbox, but this
# can easly be bypassed using the addwrite() function
addwrite "${sfconf}"
echo ">>> Appending commented out entry to ${sfconf} for ${PF}"
ls_ret=`ls -ldh "${i}"`
echo "## ${ls_ret%${IMAGE}*}${ls_ret#*${IMAGE}}" >> ${sfconf}
echo "#${i/${IMAGE}/}" >> ${sfconf}
# no delwrite() eh?
# delwrite ${sconf}
}
fi
else
echo "suidctl feature set but you are lacking a ${sfconf}"
fi
done
fi
# SELinux file labeling (needs to always be last in dyn_preinst)
if hasq selinux $FEATURES || use selinux; then
# only attempt to label if setfiles is executable
# and 'context' is available on selinuxfs.
if [ -f /selinux/context -a -x /usr/sbin/setfiles ]; then
echo ">>> Setting SELinux security labels"
if [ -f ${POLICYDIR}/file_contexts/file_contexts ]; then
cp -f "${POLICYDIR}/file_contexts/file_contexts" "${T}"
else
make -C "${POLICYDIR}" FC=${T}/file_contexts "${T}/file_contexts"
fi
addwrite /selinux/context
/usr/sbin/setfiles -r "${IMAGE}" "${T}/file_contexts" "${IMAGE}" \
|| die "Failed to set SELinux security labels."
else
# nonfatal, since merging can happen outside a SE kernel
# like during a recovery situation
echo "!!! Unable to set SELinux security labels"
fi
fi
MUST_EXPORT_ENV="yes"
trap SIGINT SIGQUIT
}
# debug-print() gets called from many places with verbose status information useful
# for tracking down problems. The output is in $T/eclass-debug.log.
# You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
# The special "on" setting echoes the information, mixing it with the rest of the
# emerge output.
# You can override the setting by exporting a new one from the console, or you can
# set a new default in make.*. Here the default is "" or unset.
# in the future might use e* from /etc/init.d/functions.sh if i feel like it
debug-print()
{
if [ "$EBUILD_PHASE" == "depend" ] && [ -z "${PORTAGE_DEBUG}" ]; then
return
fi
# if $T isn't defined, we're in dep calculation mode and
# shouldn't do anything
[ -z "$T" ] && return 0
while [ "$1" ]; do
# extra user-configurable targets
if [ "$ECLASS_DEBUG_OUTPUT" == "on" ]; then
echo "debug: $1"
elif [ -n "$ECLASS_DEBUG_OUTPUT" ]; then
echo "debug: $1" >> $ECLASS_DEBUG_OUTPUT
fi
# default target
echo "$1" >> "${T}/eclass-debug.log"
# let the portage user own/write to this file
chmod g+w "${T}/eclass-debug.log" &>/dev/null
shift
done
}
# The following 2 functions are debug-print() wrappers
debug-print-function()
{
str="$1: entering function"
shift
debug-print "$str, parameters: $*"
}
debug-print-section()
{
debug-print "now in section $*"
}
internal_inherit()
{
# default, backwards compatible beast.
local location overlay
location="${ECLASSDIR}/${1}.eclass"
if [ -n "$PORTDIR_OVERLAY" ]; then
local overlay
for overlay in ${PORTDIR_OVERLAY}; do
if [ -e "${overlay}/eclass/${1}.eclass" ]; then
location="${overlay}/eclass/${1}.eclass"
debug-print " eclass exists: ${location}"
fi
done
fi
debug-print "inherit: $1 -> $location"
source "$location" || die "died sourcing $location in inherit()"
return 0
}
# Sources all eclasses in parameters
declare -ix ECLASS_DEPTH=0
inherit()
{
local SAVED_INHERIT_COUNT=0 INHERITED_ALREADY=0
if [[ $ECLASS_DEPTH < 0 ]] && [ "${EBUILD_PHASE}" == "depend" ]; then
echo "QA Notice: ${CATEGORY}/${PF} makes multiple inherit calls: $1" >&2
SAVED_INHERIT_COUNT=$ECLASS_DEPTH
ECLASS_DEPTH=0
fi
if hasq $1 $INHERITED && [ "${EBUILD_PHASE}" == "depend" ]; then
#echo "QA notice: $1 is inherited multiple times: ${CATEGORY}/${PF}" >&2
INHERITED_ALREADY=1
fi
ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
if [[ $ECLASS_DEPTH > 1 ]]; then
debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
fi
local location olocation
local PECLASS
local B_IUSE
local B_DEPEND
local B_RDEPEND
local B_CDEPEND
local B_PDEPEND
while [ -n "$1" ]; do
# PECLASS is used to restore the ECLASS var after recursion.
PECLASS="$ECLASS"
export ECLASS="$1"
if [ "$EBUILD_PHASE" != "depend" ]; then
if ! hasq $ECLASS $INHERITED; then
echo
echo "QA Notice: ECLASS '$ECLASS' illegal conditional inherit in $CATEGORY/$PF" >&2
echo
fi
fi
#We need to back up the value of DEPEND and RDEPEND to B_DEPEND and B_RDEPEND
#(if set).. and then restore them after the inherit call.
#turn off glob expansion
set -f
# Retain the old data and restore it later.
unset B_IUSE B_DEPEND B_RDEPEND B_CDEPEND B_PDEPEND
[ "${IUSE-unset}" != "unset" ] && B_IUSE="${IUSE}"
[ "${DEPEND-unset}" != "unset" ] && B_DEPEND="${DEPEND}"
[ "${RDEPEND-unset}" != "unset" ] && B_RDEPEND="${RDEPEND}"
[ "${CDEPEND-unset}" != "unset" ] && B_CDEPEND="${CDEPEND}"
[ "${PDEPEND-unset}" != "unset" ] && B_PDEPEND="${PDEPEND}"
unset IUSE DEPEND RDEPEND CDEPEND PDEPEND
#turn on glob expansion
set +f
if ! internal_inherit "$1"; then
die "failed sourcing $1 in inherit()"
fi
#turn off glob expansion
set -f
# If each var has a value, append it to the global variable E_* to
# be applied after everything is finished. New incremental behavior.
[ "${IUSE-unset}" != "unset" ] && export E_IUSE="${E_IUSE} ${IUSE}"
[ "${DEPEND-unset}" != "unset" ] && export E_DEPEND="${E_DEPEND} ${DEPEND}"
[ "${RDEPEND-unset}" != "unset" ] && export E_RDEPEND="${E_RDEPEND} ${RDEPEND}"
[ "${CDEPEND-unset}" != "unset" ] && export E_CDEPEND="${E_CDEPEND} ${CDEPEND}"
[ "${PDEPEND-unset}" != "unset" ] && export E_PDEPEND="${E_PDEPEND} ${PDEPEND}"
[ "${B_IUSE-unset}" != "unset" ] && IUSE="${B_IUSE}"
[ "${B_IUSE-unset}" != "unset" ] || unset IUSE
[ "${B_DEPEND-unset}" != "unset" ] && DEPEND="${B_DEPEND}"
[ "${B_DEPEND-unset}" != "unset" ] || unset DEPEND
[ "${B_RDEPEND-unset}" != "unset" ] && RDEPEND="${B_RDEPEND}"
[ "${B_RDEPEND-unset}" != "unset" ] || unset RDEPEND
[ "${B_CDEPEND-unset}" != "unset" ] && CDEPEND="${B_CDEPEND}"
[ "${B_CDEPEND-unset}" != "unset" ] || unset CDEPEND
[ "${B_PDEPEND-unset}" != "unset" ] && PDEPEND="${B_PDEPEND}"
[ "${B_PDEPEND-unset}" != "unset" ] || unset PDEPEND
#turn on glob expansion
set +f
if hasq $1 $INHERITED && [ $INHERITED_ALREADY == 0 ]; then
#
# enable this one eclasses no longer fool with eclass and inherited.
# if [ "${EBUILD_PHASE}" == "depend" ]; then
# echo "QA Notice: ${CATEGORY}/${PF}: eclass $1 is incorrectly setting \$INHERITED." >&2
# fi
:
else
INHERITED="$INHERITED $ECLASS"
fi
export ECLASS="$PECLASS"
shift
done
ECLASS_DEPTH=$(($ECLASS_DEPTH - 1))
if [[ $ECLASS_DEPTH == 0 ]]; then
ECLASS_DEPTH=$(($SAVED_INHERIT_COUNT - 1))
fi
}
# Exports stub functions that call the eclass's functions, thereby making them default.
# For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
# code will be eval'd:
# src_unpack() { base_src_unpack; }
EXPORT_FUNCTIONS()
{
if [ -z "$ECLASS" ]; then
echo "EXPORT_FUNCTIONS without a defined ECLASS" >&2
exit 1
fi
while [ "$1" ]; do
debug-print "EXPORT_FUNCTIONS: ${1} -> ${ECLASS}_${1}"
eval "$1() { ${ECLASS}_$1 "\$@" ; }" > /dev/null
shift
done
}
# adds all parameters to E_DEPEND and E_RDEPEND, which get added to DEPEND
# and RDEPEND after the ebuild has been processed. This is important to
# allow users to use DEPEND="foo" without frying dependencies added by an
# earlier inherit. It also allows RDEPEND to work properly, since a lot
# of ebuilds assume that an unset RDEPEND gets its value from DEPEND.
# Without eclasses, this is true. But with them, the eclass may set
# RDEPEND itself (or at least used to) which would prevent RDEPEND from
# getting its value from DEPEND. This is a side-effect that made eclasses
# have unreliable dependencies.
newdepend()
{
debug-print-function newdepend $*
debug-print "newdepend: E_DEPEND=$E_DEPEND E_RDEPEND=$E_RDEPEND"
while [ -n "$1" ]; do
case $1 in
"/autotools")
do_newdepend DEPEND sys-devel/autoconf sys-devel/automake sys-devel/make
;;
"/c")
do_newdepend DEPEND sys-devel/gcc virtual/libc
do_newdepend RDEPEND virtual/libc
;;
*)
do_newdepend DEPEND $1
;;
esac
shift
done
}
newrdepend()
{
debug-print-function newrdepend $*
do_newdepend RDEPEND $1
}
newcdepend()
{
debug-print-function newcdepend $*
do_newdepend CDEPEND $1
}
newpdepend()
{
debug-print-function newpdepend $*
do_newdepend PDEPEND $1
}
do_newdepend()
{
# This function does a generic change determining whether we're in an
# eclass or not. If we are, we change the E_* variables for deps.
debug-print-function do_newdepend $*
[ -z "$1" ] && die "do_newdepend without arguments"
# Grab what we're affecting... Figure out if we're affecting eclasses.
[[ ${ECLASS_DEPTH} > 0 ]] && TARGET="E_$1"
[[ ${ECLASS_DEPTH} > 0 ]] || TARGET="$1"
shift # $1 was a variable name.
while [ -n "$1" ]; do
# This bit of evil takes TARGET and uses it to evaluate down to a
# variable. This is a sneaky way to make this infinately expandable.
# The normal translation of this would look something like this:
# E_DEPEND="${E_DEPEND} $1" :::::: Cool, huh? :)
eval export ${TARGET}=\"\${${TARGET}} \$1\"
shift
done
}
# this is a function for removing any directory matching a passed in pattern from
# PATH
remove_path_entry()
{
save_IFS
IFS=":"
stripped_path="${PATH}"
while [ -n "$1" ]; do
cur_path=""
for p in ${stripped_path}; do
if [ "${p/${1}}" == "${p}" ]; then
cur_path="${cur_path}:${p}"
fi
done
stripped_path="${cur_path#:*}"
shift
done
restore_IFS
PATH="${stripped_path}"
}
QA_INTERCEPTORS="javac java-config python python-config perl grep egrep fgrep sed gcc g++ cc bash awk nawk pkg-config"
enable_qa_interceptors()
{
# Turn of extended glob matching so that g++ doesn't get incorrectly matched.
shopt -u extglob
# QA INTERCEPTORS
local FUNC_SRC BIN BODY BIN_PATH
for BIN in ${QA_INTERCEPTORS}; do
BIN_PATH=$(type -pf ${BIN})
if [ "$?" != "0" ]; then
BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
else
BODY="${BIN_PATH} \"\$@\"; return \$?"
fi
FUNC_SRC="function ${BIN}() {
echo -n \"QA Notice: ${BIN} in global scope: \" >&2
if [ \$ECLASS_DEPTH -gt 0 ]; then
echo \"eclass \${ECLASS}\" >&2
else
echo \"\${CATEGORY}/\${PF}\" >&2
fi
${BODY}
}";
eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
done
}
disable_qa_interceptors()
{
for x in $QA_INTERCEPTORS; do
unset -f $x
done
}
useq()
{
local u="${1}"
local neg=0
if [ "${u:0:1}" == "!" ]; then
u="${u:1}"
neg=1
fi
local x
# Make sure we have this USE flag in IUSE
if ! hasq "${u}" ${IUSE} ${E_IUSE} && ! hasq "${u}" ${PORTAGE_ARCHLIST} selinux; then
echo "QA Notice: USE Flag '${u}' not in IUSE for ${CATEGORY}/${PF}" >&2
fi
for x in ${USE}; do
if [ "${x}" == "${u}" ]; then
if [ ${neg} -eq 1 ]; then
return 1
else
return 0
fi
fi
done
if [ ${neg} -eq 1 ]; then
return 0
else
return 1
fi
}
usev()
{
if useq ${1}; then
echo "${1}"
return 0
fi
return 1
}
# Used to generate the /lib/cpp and /usr/bin/cc wrappers
gen_wrapper()
{
cat > $1 << END
#!/bin/sh
$2 "\$@"
END
chmod 0755 $1
}
insopts()
{
INSOPTIONS=""
for x in $*; do
#if we have a debug build, let's not strip anything
if hasq nostrip $FEATURES $RESTRICT && [ "$x" == "-s" ]; then
continue
else
INSOPTIONS="$INSOPTIONS $x"
fi
done
export INSOPTIONS
}
diropts()
{
DIROPTIONS=""
for x in $*; do
DIROPTIONS="${DIROPTIONS} $x"
done
export DIROPTIONS
}
exeopts()
{
EXEOPTIONS=""
for x in $*; do
#if we have a debug build, let's not strip anything
if hasq nostrip $FEATURES $RESTRICT && [ "$x" == "-s" ]; then
continue
else
EXEOPTIONS="$EXEOPTIONS $x"
fi
done
export EXEOPTIONS
}
libopts()
{
LIBOPTIONS=""
for x in $*; do
#if we have a debug build, let's not strip anything
if hasq nostrip $FEATURES $RESTRICT && [ "$x" == "-s" ]; then
continue
else
LIBOPTIONS="$LIBOPTIONS $x"
fi
done
export LIBOPTIONS
}
DONT_EXPORT_VARS="${DONT_EXPORT_VARS} ECLASS_DEPTH"
true
|