-
Notifications
You must be signed in to change notification settings - Fork 3
/
profile.bashrc
210 lines (169 loc) · 7.3 KB
/
profile.bashrc
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
## ehooks patching system.
if [[ ${EBUILD_PHASE} == "setup" ]]; then
## Get gentoo-unity7 repo path via portageq tool.
PORTAGE_QUERY_TOOL=portageq
[[ -e "${PORTAGE_BIN_PATH}"/portageq-wrapper ]] && PORTAGE_QUERY_TOOL="${PORTAGE_BIN_PATH}"/portageq-wrapper
if "${PORTAGE_QUERY_TOOL}" get_repo_path / gentoo-unity7 >/dev/null 2>&1; then
REPO_ROOT=$("${PORTAGE_QUERY_TOOL}" get_repo_path / gentoo-unity7)
else
die "portageq: gentoo-unity7 repo path not found. If you have recently updated sys-apps/portage then you should re-run 'emerge -avuDU --with-bdeps=y @world' to catch any updates."
fi
## Look for ehooks in setup phase.
local \
pkg \
basedir="${REPO_ROOT}"/profiles/ehooks
EHOOKS_SOURCE=()
for pkg in generic ${CATEGORY}/{${P}-${PR},${P},${P%.*},${P%.*.*},${PN}}{:${SLOT%/*},}; do
if [[ -d ${EHOOKS_PATH:=${basedir}}/${pkg} ]]; then
true
elif [[ -d ${basedir}/${pkg} ]]; then
EHOOKS_PATH="${basedir}"
else
continue
fi
local prev_shopt=$(shopt -p nullglob)
shopt -s nullglob
EHOOKS_SOURCE+=( "${EHOOKS_PATH}/${pkg}"/*.ehooks )
${prev_shopt}
[[ ${pkg} != "generic" ]] && break
done
## Define function to check if USE flag is declared.
ehooks_use() {
return $("${PORTAGE_QUERY_TOOL}" has_version / unity-base/gentoo-unity-env["$1"])
}
## Define function to skip all related ehooks if USE flag is not declared.
ehooks_require() {
if ! "${PORTAGE_QUERY_TOOL}" has_version / unity-base/gentoo-unity-env["$1"]; then
echo " * USE flag '$1' not declared: skipping related ehooks..."
exit ${SKIP_CODE}
fi
}
## Define function to apply ehooks.
ehooks_apply() {
## Process EHOOKS_SOURCE.
if [[ ${EHOOKS_SOURCE[@]} == *"${FUNCNAME[1]}"* ]]; then
local \
x \
log="${T}/ehooks.log" \
color_norm=$(tput sgr0) \
color_bold=$(tput bold) \
color_red=$(tput setaf 1)
> "${log}"
## Append bug information to 'die' command.
local \
bugapnd="eerror \"S: '\${S}'\"" \
bugmsg="eerror \"${color_bold}Please submit ehooks bug at ${color_norm}'https://github.com/c4pp4/gentoo-unity7/issues'.\"" \
buglog="eerror \"${color_bold}The ehooks log is located at ${color_norm}'${log}'.\""
source <(declare -f die | sed -e "/${bugapnd}/a ${bugmsg}" -e "/${bugapnd}/a ${buglog}")
## End of modifying 'die' command
if [[ ${EHOOKS_ACCEPT} != "yes" ]]; then
eerror
eerror "Warning!"
eerror
eerror "Patches from gentoo-unity7 overlay will be applied to ${CATEGORY}/${PN} and some other packages from the Gentoo tree via ehooks patching system."
eerror "For more details, see ${REPO_ROOT}/docs/ehooks.md - Chapter I."
eerror "Set EHOOKS_ACCEPT=\"yes\" in make.conf to confirm you agree with it."
eerror
echo "Acceptance needed" > "${log}"
die "$(<${log})"
fi
declare -F ehooks 1>/dev/null \
&& ( echo "ehooks: function name collision" > "${log}" && die "$(<${log})" )
echo "${color_red}${color_bold}>>> Loading gentoo-unity7 ehooks ...${color_norm}"
for x in "${EHOOKS_SOURCE[@]}"; do
## Process current phase.
if [[ ${x} == *"${FUNCNAME[1]}.ehooks" ]]; then
[[ -r ${x} ]] \
|| ( echo "${x##*/}: file not readable" > "${log}" && die "$(<${log})" )
source "${x}" 2>"${log}"
[[ -s ${log} ]] \
&& die "$(<${log})"
declare -F ehooks 1>/dev/null \
|| ( echo "ehooks: function not found" > "${log}" && die "$(<${log})" )
einfo "Processing ${x} ..."
local EHOOKS_FILESDIR=${x%/*}/files
## Check for eautoreconf.
if [[ ${EBUILD_PHASE} == prepare ]]; then
if declare -f ehooks | grep -q "eautoreconf"; then
if ! declare -F eautoreconf 1>/dev/null; then
local eautoreconf_names="eautoreconf _at_uses_pkg _at_uses_autoheader _at_uses_automake _at_uses_gettext _at_uses_glibgettext _at_uses_intltool _at_uses_gtkdoc _at_uses_gnomedoc _at_uses_libtool _at_uses_libltdl eaclocal_amflags eaclocal _elibtoolize eautoheader eautoconf eautomake autotools_env_setup autotools_run_tool ALL_AUTOTOOLS_MACROS autotools_check_macro autotools_check_macro_val _autotools_m4dir_include autotools_m4dir_include autotools_m4sysdir_include gnuconfig_findnewest elibtoolize tc-getLD tc-getPROG _tc-getPROG"
x=$("${PORTAGE_QUERY_TOOL}" get_repo_path / gentoo)/eclass
local -a fn_source=(
"${x}/autotools.eclass"
"${x}/libtool.eclass"
"${x}/gnuconfig.eclass"
"${x}/toolchain-funcs.eclass"
)
for x in "${fn_source[@]}"; do
[[ -f ${x} ]] \
|| ( echo "${x}: file not found" > "${log}" && die "$(<${log})" )
source <(awk "/^(${eautoreconf_names// /|})(\(\)|=\(\$)/ { p = 1 } p { print } /(^(}|\))|; })\$/ { p = 0 }" ${x} 2>/dev/null)
done
declare -F eautoreconf 1>/dev/null \
|| ( echo "eautoreconf: function not found" > "${log}" && die "$(<${log})" )
fi
fi
fi ## End of checking for eautoreconf.
## Output information messages to fd 3 instead of stderr (issue #193).
local msgfunc_names="einfo einfon ewarn ebegin __eend __vecho"
for x in ${msgfunc_names}; do
source <(declare -f ${x} | sed "s/\(1>&\)2/\13/")
done
## Define exit code to skip ehooks.
local SKIP_CODE=99
## Log errors to screen and logfile via fd 3.
exec 3>&1
ehooks 2>&1 >&3 | tee -a "${log}"
## Clear source when exit status SKIP_CODE is returned.
## Needs to be right after the ehooks call.
[[ ${PIPESTATUS[0]} -eq ${SKIP_CODE} ]] && EHOOKS_SOURCE=()
[[ -s ${log} ]] \
&& die "$(<${log})"
## Sanitize.
exec 3>&-
for x in ${msgfunc_names}; do
source <(declare -f ${x} | sed "s/\(1>&\)3/\12/")
done
unset -f ehooks
if [[ -n ${eautoreconf_names} ]]; then
eautoreconf_names="${eautoreconf_names/ elibtoolize tc-getLD tc-getPROG _tc-getPROG}"
for x in ${eautoreconf_names}; do
unset ${x}
done
fi
## Exit the current loop when source is cleared.
[[ -z ${EHOOKS_SOURCE[@]} ]] && break
fi ## End of processing current phase.
done
echo "${color_red}${color_bold}>>> Done.${color_norm}"
## Sanitize 'die' command.
source <(declare -f die | sed "/ehooks/d")
fi ## End of processing EHOOKS_SOURCE.
} ## End of ehooks_apply function.
pre_pkg_setup() { ehooks_apply; }
post_pkg_setup() { ehooks_apply; }
pre_src_unpack() { ehooks_apply; }
post_src_unpack() { ehooks_apply; }
pre_src_prepare() { ehooks_apply; }
post_src_prepare() { ehooks_apply; }
pre_src_configure() { ehooks_apply; }
post_src_configure() { ehooks_apply; }
pre_src_compile() { ehooks_apply; }
post_src_compile() { ehooks_apply; }
pre_src_install() { ehooks_apply; }
post_src_install() { ehooks_apply; }
pre_pkg_preinst() { ehooks_apply; }
post_pkg_preinst() { ehooks_apply; }
pre_pkg_postinst() { ehooks_apply; }
post_pkg_postinst() { ehooks_apply; }
fi ## End of setup phase.
## Check for {pre,post} function name collision with ehooks patching system.
if [[ ${EBUILD_PHASE} == "unpack" ]]; then
local x
local -a EHOOKS_FUNC=()
for x in {pre,post}_pkg_{setup,preinst,postinst} {pre,post}_src_{unpack,prepare,configure,compile,install}; do
! declare -F ${x} 1>/dev/null || declare -f ${x} | grep -q "ehooks_apply" || EHOOKS_FUNC+=( "'${x}'," )
done
[[ -n ${EHOOKS_FUNC[@]} ]] && EHOOKS_FUNC[-1]="${EHOOKS_FUNC[-1]%,}" && die "ehooks: function name collision\n If you have ${EHOOKS_FUNC[@]} inside '${EROOT}/etc/portage/bashrc', call 'ehooks_apply' function inside it or use generic ehooks instead.\n For more details, see ${REPO_ROOT}/docs/ehooks.md - Chapter II. - Generic ehooks."
fi
## End of ehooks patching system.