diskimage-builder/diskimage_builder/elements/yum-minimal/pre-install.d/03-yum-cleanup
Ian Wienand 97c01e48ed Move elements & lib relative to diskimage_builder package
Currently we have all our elements and library files in a top-level
directory and install them into
<root>/share/diskimage-builder/[elements|lib] (where root is either /
or the root of a virtualenv).

The problem with this is that editable/development installs (pip -e)
do *not* install data_files.  Thus we have no canonical location to
look for elements -- leading to the various odd things we do such as a
whole bunch of guessing at the top of disk-image-create and having a
special test-loader in tests/test_elements.py so we can run python
unit tests on those elements that have it.

data_files is really the wrong thing to use for what are essentially
assets of the program.  data_files install works well for things like
config-files, init.d files or dropping documentation files.

By moving the elements under the diskimage_builder package, we always
know where they are relative to where we import from.  In fact,
pkg_resources has an api for this which we wrap in the new
diskimage_builder/paths.py helper [1].

We use this helper to find the correct path in the couple of places we
need to find the base-elements dir, and for the paths to import the
library shell functions.

Elements such as svc-map and pkg-map include python unit-tests, which
we do not need tests/test_elements.py to special-case load any more.
They just get found automatically by the normal subunit loader.

I have a follow-on change (I69ca3d26fede0506a6353c077c69f735c8d84d28)
to move disk-image-create to a regular python entry-point.

Unfortunately, this has to move to work with setuptools.  You'd think
a symlink under diskimage_builder/[elements|lib] would work, but it
doesn't.

[1] this API handles stuff like getting files out of .zip archive
modules, which we don't do.  Essentially for us it's returning
__file__.

Change-Id: I5e3e3c97f385b1a4ff2031a161a55b231895df5b
2016-11-01 17:27:41 -07:00

87 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
# effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb --keep-services "$target"
# 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
# docs
rm -rf /usr/share/{doc,info,gnome/help}
# cracklib
rm -rf /usr/share/cracklib
# i18n
rm -rf /usr/share/i18n
# sln
rm -rf /sbin/sln
# ldconfig
rm -rf /etc/ld.so.cache /var/cache/ldconfig
mkdir -p --mode=0755 /var/cache/ldconfig