Merge "Rework yum-minimal locale cleanup"

This commit is contained in:
Jenkins 2016-05-31 06:42:20 +00:00 committed by Gerrit Code Review
commit 419568884c
2 changed files with 77 additions and 51 deletions

View File

@ -23,58 +23,56 @@ set -o pipefail
# effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb --keep-services "$target"
# Fedora 24 has a much better way to handle just installing some
# languages; see bug. We should support that at the right time.
if [[ $DISTRO_NAME == "fedora" && $DIB_RELEASE -gt 23 ]]; then
echo "Locale support for Fedora 24 is incomplete"
echo " see: https://bugs.launchpad.net/diskimage-builder/+bug/1571488"
die "Cannot cleanup locales on > Fedora 23"
# This is only required on CentOS ... see notes in
# root.d/08-yum-chroot about %_install_langs
if [[ $DISTRO_NAME != "fedora" ]]; then
# Stripping *all* locales is a bad idea. For now, we take the
# suggestion in [1] for reducing this
# [1] https://bugzilla.redhat.com/show_bug.cgi?id=156477
if [ ! -f /usr/lib/locale/locale-archive ]; then
die "locale-archive not found? Can not do cleanup."
fi
# now the archive has everything in it, and is about 100MiB. Strip it
# to just en_US (basically, this is the locale we support if you ssh
# in, other than POSIX)
localedef --delete-from-archive \
$(localedef --list-archive | grep -v '^en_US' | xargs)
# This removes the locales from the archive index but doesn't rebuild
# the file, so it is still the same size (maybe it is sparse?
# presumably as it's mmapped you don't want to fiddle with the offsets
# of locales in the archive on a live system. We are not live).
# build-locale-archive is a tool provided by the RH packaging of
# glibc. Documentation is scarce, but it takes the pre-built locales
# in the tmpl file and creates an archive. It seems originally the
# installer would set some flags to rpm to tell the package what
# languages to pick out of the template, but along the way, this was
# reverted to install them (size considered less important than locale
# support).
# We hack this by moving the locale-archive we've removed the extra
# locales from to the template, then re-run the build.
mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.tmpl
# rebuild archive from template
/usr/sbin/build-locale-archive
# leave empty template behind as package does. I think this stops
# upgrades redoing things
echo > /usr/lib/locale/locale-archive.tmpl
# remove the unnecessary source locale files and iconv files
pushd /usr/share/locale
find . ! -name 'locale.alias' -delete
popd
rm -rf {lib.lib64}/gconv
fi
# Stripping *all* locales is a bad idea. For now, we take the
# suggestion in [1] for reducing this
# [1] https://bugzilla.redhat.com/show_bug.cgi?id=156477
if [ ! -f /usr/lib/locale/locale-archive ]; then
die "locale-archive not found? Can not do cleanup."
fi
# now the archive has everything in it, and is about 100MiB. Strip it
# to just en_US (basically, this is the locale we support if you ssh
# in, other than POSIX)
localedef --delete-from-archive \
$(localedef --list-archive | grep -v '^en_US' | xargs)
# This removes the locales from the archive index but doesn't rebuild
# the file, so it is still the same size (maybe it is sparse?
# presumably as it's mmapped you don't want to fiddle with the offsets
# of locales in the archive on a live system. We are not live).
# build-locale-archive is a tool provided by the RH packaging of
# glibc. Documentation is scarce, but it takes the pre-built locales
# in the tmpl file and creates an archive. It seems originally the
# installer would set some flags to rpm to tell the package what
# languages to pick out of the template, but along the way, this was
# reverted to install them (size considered less important than locale
# support).
# We hack this by moving the locale-archive we've removed the extra
# locales from to the template, then re-run the build.
mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.tmpl
# rebuild archive from template
/usr/sbin/build-locale-archive
# leave empty template behind as package does. I think this stops
# upgrades redoing things
echo > /usr/lib/locale/locale-archive.tmpl
# remove the unnecessary source locale files and iconv files
pushd /usr/share/locale
find . ! -name 'locale.alias' -delete
popd
rm -rf {lib.lib64}/gconv
# docs
rm -rf /usr/share/{doc,info,gnome/help}
# cracklib

View File

@ -128,6 +128,29 @@ function _install_pkg_manager {
flock -w 1200 9 || die "Can not lock .rpmmacros"
echo "%_dbpath /var/lib/rpm" >> $HOME/.rpmmacros
# Fedora 24 has a much better way to handle just installing some
# languages; see bug. We should support that at the right time.
if [[ $DISTRO_NAME == "fedora" && $DIB_RELEASE -gt 23 ]]; then
echo "Locale support for Fedora 24 is incomplete"
echo " see: https://bugs.launchpad.net/diskimage-builder/+bug/1571488"
die "Cannot cleanup locales on > Fedora 23"
fi
# _install_langs is a rpm macro that limits the translation
# files, etc installed by packages. For Fedora 23 [1], the
# glibc-common package will obey this to only install the
# listed locales, keeping things much smaller (we still have
# to clean up locales manually on centos7). We install just
# en_US because people often ssh in with that locale, but
# leave out everything else. Note that yum has an option to
# set this from the command-line [2], but the yum in trusty we
# are using is too old to have it. So we set it directly in
# the macros file
#
# [1] http://pkgs.fedoraproject.org/cgit/rpms/glibc.git/commit/glibc.spec?h=f23&id=91764bd9ec690d4b8a886c0a3a104aac12d340d2
# [2] http://yum.baseurl.org/gitweb?p=yum.git;a=commit;h=26128173b362474456e8f0642073ecb0322ed031
echo "%_install_langs C:en_US:en_US.UTF-8" >> $HOME/.rpmmacros
sudo -E yum -y \
--setopt=cachedir=$YUM_CACHE/$ARCH/$DIB_RELEASE \
--setopt=reposdir=$TARGET_ROOT/etc/yum.repos.d \
@ -137,7 +160,8 @@ function _install_pkg_manager {
# We modified the base system - make sure we clean up always!
rm $HOME/.rpmmacros.dib.lock
sed -i '$ d' $HOME/.rpmmacros
# sed makes it easy to remove last line, but not last n lines...
sed -i '$ d' $HOME/.rpmmacros; sed -i '$ d' $HOME/.rpmmacros;
if [ $rc != 0 ]; then
die "Initial yum install to chroot failed! Can not continue."
fi
@ -193,6 +217,10 @@ else
sudo -E chroot $TARGET_ROOT rpm --rebuilddb
sudo -E chroot $TARGET_ROOT ${YUM} clean all
# populate the lang reduction macro in the chroot
echo "%_install_langs C:en_US:en_US.UTF-8" | \
sudo tee -a $TARGET_ROOT/etc/rpm/macros.langs > /dev/null
# bootstrap the environment within the chroot; bring in new
# metadata with an update and install some base packages we need.
sudo -E chroot $TARGET_ROOT ${YUM} -y update