blob: 6823ea42f40db72e55eae36944bb7f1bbff76857 (
plain) (
tree)
|
|
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
|