diff options
author | Bertrand Jacquin <bertrand@jacquin.bzh> | 2015-11-22 01:48:15 +0000 |
---|---|---|
committer | Bertrand Jacquin <bertrand@jacquin.bzh> | 2015-11-22 17:59:44 +0000 |
commit | 642c64c292782c7941f8ede6c22d92286e1c5731 (patch) | |
tree | 8bf9bcec331c1ac9a86259b3767e24ff922d5407 | |
parent | profiles/common: Use consistent name while purging files (diff) | |
download | portage-642c64c292782c7941f8ede6c22d92286e1c5731.tar.xz |
profiles/common: Handle glob for __drop-doc and __drop-unneeded
-rw-r--r-- | profiles/common/profile.bashrc | 77 |
1 files changed, 65 insertions, 12 deletions
diff --git a/profiles/common/profile.bashrc b/profiles/common/profile.bashrc index 9f6f848f..7bdd391d 100644 --- a/profiles/common/profile.bashrc +++ b/profiles/common/profile.bashrc @@ -1,3 +1,49 @@ +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 __drop-nls-man-pages () { local -a _FILES=( /usr/share/man @@ -75,12 +121,13 @@ function __drop-doc () { local _file for _file in ${_FILES[@]} ; do - if [[ ! -d "${_ed}/${_file}" ]] ; then - continue - fi - - einfo "Removing ${_file}" - rm -rf "${_ed}/${_file}" + find "${_ed}" \ + -path "${_ed}${_file}" | + sort | + while read ; do + einfo "Removing ${REPLY#${_ed}}" + rm -rf "${REPLY}" + done done } @@ -101,12 +148,13 @@ function __drop-unneeded () { local _file for _file in ${_FILES[@]} ; do - if [[ ! -e "${_ed}/${_file}" ]] ; then - continue - fi - - einfo "Removing ${_file}" - rm -rf "${_ed}/${_file}" + find "${_ed}" \ + -path "${_ed}${_file}" | + sort | + while read ; do + einfo "Removing ${REPLY#${_ed}}" + rm -rf "${REPLY}" + done done } @@ -208,11 +256,16 @@ function pre_pkg_preinst () { return 0 fi + __save_bash_options + set -o noglob + __drop-nls-man-pages __drop-nls-locales __drop-doc __drop-unneeded __drop-empty-dir + + __restore_bash_options } # vim: syntax=sh |