blob: 6823ea42f40db72e55eae36944bb7f1bbff76857 (
plain) (
blame)
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
|
function __save_bash_options () {
local _set _state _option
while read _set _state _option ; do
case "${_state}" in
-o) __BASH_SET_ENABLED+=( "${_option}" ) ;;
+o) __BASH_SET_DISABLED+=( "${_option}" ) ;;
esac
done < <(
set +o
)
while read _option _state ; do
case "${_state}" in
on) __BASH_SHOPT_ENABLED+=( "${_option}" ) ;;
off) __BASH_SHOPT_DISABLED+=( "${_option}" ) ;;
esac
done < <(
shopt
)
}
function __restore_bash_options () {
local _option
if [[ -n ${__BASH_SET_ENABLED} ]] ; then
for _option in "${_BASH_SET_ENABLED[@]}" ; do
set -o "${_option}"
done
fi
if [[ -n ${__BASH_SET_DISABLED} ]] ; then
for _option in "${__BASH_SET_DISABLED[@]}" ; do
set +o "${_option}"
done
fi
if [[ -n ${__BASH_SHOPT_ENABLED} ]] ; then
shopt -s "${__BASH_SHOPT_ENABLED[@]}"
fi
if [[ -n ${__BASH_SHOPT_DISABLED} ]] ; then
shopt -u "${__BASH_SHOPT_DISABLED[@]}"
fi
}
function __load_make_conf () {
if (( ${#} != 1 )) ; then
return 1
fi
declare -g "${1}=$(env -i "PATH=/usr/bin" portageq envvar ${1})"
return $?
}
function __drop-non-systemd () {
local _opt
case "${EAPI:-0}" in
[5-6]) ;;
[7-8]) _opt="-r" ;;
*) die "Unsupported EAPI ${EAPI}" ;;
esac
if ! has_version ${_opt} sys-apps/systemd ; then
return 0
fi
local -a _DIRS=(
/etc/conf.d
/etc/init.d
/etc/logrotate.d
/etc/syslog-ng
)
local _dir
for _dir in ${_DIRS[@]} ; do
_dir="${_ed}${_dir}"
if [[ -e "${_dir}" ]] ; then
einfo "Removing ${_dir#${_ed}}"
rm -rf "${_dir}"
fi
done
}
function __drop-nls-man-pages () {
local -a _DIRS=(
/usr/share/man
/usr/share/postgresql-*/man
/usr/share/binutils-data/*/*/man
/usr/lib*/icedtea*/man
/usr/lib*/node_modules/npm/man
/usr/lib*/node_modules/npm/node_modules/request/node_modules/http-signature/node_modules/ctype/man
/usr/lib*/node_modules/npm/node_modules/request/node_modules/http-signature/node_modules/sshpk/man
/usr/lib*/php*/man
/opt/icedtea-bin*/man
)
local _dir
for _dir in ${_DIRS[@]} ; do
find "${_ed}" \
-path "${_ed}${_dir}" |
sort |
while read ; do
if has noman ${FEATURES} ; then
einfo "Removing ${REPLY#${_ed}}"
rm -rf "${REPLY}"
else
# Drop non man? directories
find "${REPLY}" \
-mindepth 1 -maxdepth 1 \
-type d \
-name 'man*' -prune -o -print |
sort |
while read ; do
einfo "Removing ${REPLY#${_ed}}"
rm -rf "${REPLY}"
done
fi
done
done
}
function __drop-nls-locales () {
local -a _DIRS=(
/usr/share/locale
/usr/share/help
)
__load_make_conf L10N
local _dir _l
for _dir in ${_DIRS[@]} ; do
if [[ ! -d "${_ed}${_dir}" ]] ; then
continue
fi
find "${_ed}${_dir}" \
-mindepth 1 -maxdepth 1 \
-type d |
sort |
while read ; do
_l="${REPLY##*/}"
if [[ "${_l}" == "C" ]] ; then
continue
elif has "${_l}" ${LINGUAS} ; then
continue
elif has "${_l/_/-}" ${L10N} ; then
continue
fi
einfo "Removing ${REPLY#${_ed}}"
rm -rf "${REPLY}"
done
done
}
function __drop-doc () {
# FEATURES=nodoc does not care about everything
if ! has nodoc ${FEATURES} ; then
return 0
fi
local -a _DIRS=(
/opt/ekopath/docs
/usr/lib64/python*/site-packages/enum/doc
/usr/lib64/python*/site-packages/numpy/doc
/usr/share/graphviz/doc
/usr/share/gtk-doc/html
/usr/share/sgml/docbook/xsl-stylesheets/doc
/usr/share/sgml/docbook/xsl-stylesheets/slides/doc
/usr/share/texmf-dist/source/latex/koma-script/doc
/usr/share/texmf-site/doc
/usr/share/texmf-site/tex/generic/pgf/graphdrawing/lua/pgf/gd/doc
/usr/share/texmf-site/tex/latex/pgf/doc
/usr/share/vim/vim74/doc
/usr/share/vim/vimfiles/doc
)
local _dir
for _dir in ${_DIRS[@]} ; do
find "${_ed}" \
-path "${_ed}${_dir}" |
sort |
while read ; do
einfo "Removing ${REPLY#${_ed}}"
rm -rf "${REPLY}"
done
done
}
function __drop-unneeded () {
local -a _FILES=(
/etc/*.sample
/etc/avahi/avahi-dnsconfd.action
/etc/avahi/services/sftp-ssh.service
/etc/avahi/services/ssh.service
/etc/conf.d/*-s6
/etc/conf.d/*-supervise
/etc/conf.d/pydoc*
/etc/cups/*.default
/etc/dnsdist/dnsdist.conf-dist
/etc/dnsdist/dnsdist.conf.example
/etc/elinks/*.sample
/etc/exim/auth_conf.sub
/etc/exim/exim.conf.dist
/etc/exim/exim.conf.exiscan-acl
/etc/exim/system_filter.exim
/etc/init.d/*-s6
/etc/init.d/*-supervise
/etc/init.d/pydoc*
/etc/pkcs11/*.example
/etc/rmt
/etc/snmp/*.example
/etc/squid/*.default
/etc/squid/*.documented
/etc/ssh/ssh_config.d
/etc/ssh/sshd_config.d
/etc/ssl/*.dist
/etc/sudo_logsrvd.conf
/etc/sudoers.dist
/etc/varnish/example.vcl
/etc/vsftpd/*.example
/etc/xinetd.d
/usr/lib/tmpfiles.d/connman_resolvconf.conf
/usr/share/emacs
/usr/share/fish/vendor_completions.d
/usr/share/zsh/site-functions
/var/svc.d
# See https://gitlab.gnome.org/GNOME/gnome-keyring/-/issues/34
/etc/xdg/autostart/gnome-keyring-ssh.desktop
)
local _file
for _file in ${_FILES[@]} ; do
find "${_ed}" \
-path "${_ed}${_file}" |
sort |
while read ; do
einfo "Removing ${REPLY#${_ed}}"
rm -rf "${REPLY}"
done
done
}
function __drop-empty-dir () {
local i
while (( i++ < 64 )) &&
[[ $(find "${_ed}" -mindepth 1 -type d -empty) ]] ; do
find "${_ed}" \
-mindepth 1 \
-type d \
-empty |
sort |
while read ; do
einfo "Removing ${REPLY#${_ed}}"
rm -rf "${REPLY}"
done
done
if (( i >= 64 )) ; then
eerror "${FUNCNAME} recursed more than ${i} time, that's bad"
fi
}
function __install_own_file () {
local _PROFILE_PATH="${BASH_SOURCE[0]%/profiles*}"
if [[ $? != 0 || ! ${_PROFILE_PATH} ]] ; then
return 1
fi
local _dir
for _dir in "${PF}" "${P}" "${PN}:${SLOT}" "${PN}" ; do
if [[ -d "${_PROFILE_PATH}/factory-default/${CATEGORY}/${_dir}" ]] ; then
_FACTORY_DIRECTORY="${_PROFILE_PATH}/factory-default/${CATEGORY}/${_dir}"
break
fi
done
if [[ ! ${_FACTORY_DIRECTORY} ]] ; then
return 0
fi
find "${_FACTORY_DIRECTORY}" \
\( -type f -or -type l \) \
-printf '%P\n' |
sort |
while read ; do
if [[ -e "${_ed}/${REPLY}" ]] ; then
einfo "Store original ${REPLY} to /usr/share/gentoo-factory/${CATEGORY}/${PF}"
install -D -m 0644 \
"${_ed}/${REPLY}" \
"${_ed}/usr/share/gentoo-factory/${CATEGORY}/${PF}/${REPLY}" \
|| die
chmod --reference="${_ed}/${REPLY}" "${_ed}/usr/share/gentoo-factory/${CATEGORY}/${PF}/${REPLY}" \
|| die
fi
einfo "Install ${REPLY} from factory-default"
if [[ -f "${_FACTORY_DIRECTORY}/${REPLY}" ]] ; then
install -D -m 0644 \
"${_FACTORY_DIRECTORY}/${REPLY}" \
"${_ed}/${REPLY}" \
|| die
if [[ -e "${_ed}/usr/share/gentoo-factory/${CATEGORY}/${PF}/${REPLY}" ]] ; then
chmod --reference="${_ed}/usr/share/gentoo-factory/${CATEGORY}/${PF}/${REPLY}" "${_ed}/${REPLY}" \
|| die
else
chmod --reference="${_FACTORY_DIRECTORY}/${REPLY}" "${_ed}/${REPLY}" \
|| die
fi
elif [[ -L "${_FACTORY_DIRECTORY}/${REPLY}" ]] ; then
cp -P "${_FACTORY_DIRECTORY}/${REPLY}" \
"${_ed}/${REPLY}" \
|| die
fi
done
}
function __drop-distfiles () {
if [[ "${PORTAGE_REMOVE_DISTFILES}" != "Yes" ]] ; then
return 0
fi
local _r
if has fetch ${RESTRICT} ; then
continue
elif has mirror ${RESTRICT} ; then
continue
fi
if [[ -d "${DISTDIR}" ]] ; then
find "${DISTDIR}" -type l |
while read ; do
_r="$(readlink -f "${REPLY}")"
einfo "Removing ${_r}"
rm -f "${_r}"
done
fi
if [[ -n "${EGIT_DIR}" ]] ; then
if [[ -d "${EGIT_DIR}" ]] ; then
einfo "Removing ${EGIT_DIR}"
rm -rf "${EGIT_DIR}"
fi
if [[ -d "${EGIT3_STORE_DIR}" ]] ; then
find "${EGIT3_STORE_DIR}" -mindepth 0 -type d -empty |
while read ; do
einfo "Removing ${REPLY}"
rm -rf "${REPLY}"
done
fi
fi
}
function post_src_install () {
if [[ ${ED} ]] ; then
local _ed="${ED}"
else
local _ed="${D}"
fi
# Get rid of trailing /
local _ed="${_ed/%\/}"
if [[ ! -d "${_ed}" ]] ; then
return 0
fi
__install_own_file
}
function pre_pkg_preinst () {
if [[ ${ED} ]] ; then
local _ed="${ED}"
else
local _ed="${D}"
fi
# Get rid of trailing /
local _ed="${_ed/%\/}"
if [[ ! -d "${_ed}" ]] ; then
return 0
fi
__save_bash_options
set -o noglob
__drop-non-systemd
__drop-nls-man-pages
__drop-nls-locales
__drop-doc
__drop-unneeded
__drop-empty-dir
__restore_bash_options
}
function post_pkg_postinst () {
__drop-distfiles
}
# vim: syntax=sh
|