2015-03-22 14:04:46 +00:00
|
|
|
#!/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.
|
|
|
|
#
|
2016-04-08 05:46:21 +00:00
|
|
|
|
|
|
|
# dib-lint: disable=safe_sudo
|
|
|
|
|
2015-03-22 14:04:46 +00:00
|
|
|
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
set -eu
|
|
|
|
set -o pipefail
|
|
|
|
|
Fix /dev/pts mount options handling
The current implementation - as introduced in
Iee44703297a15b14c715f4bfb7bae67f613aceee - has some shortcomings / bugs,
like:
* the 'grep' check is too sloppy
* when /dev/pts is already mounted multiple times the current implementation
fails:
$ mount | grep devpts | sed 's/.*(\(.*\))/\1/'
rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
* code duplication
* Using the undocumented and non-robust output
of 'mount'.
This patch fixed the above problems.
Change-Id: Ib0c7358772480c56d405659a6a32afd60c311686
Signed-off-by: Andreas Florath <andreas@florath.net>
2017-11-23 19:50:31 +00:00
|
|
|
source $_LIB/common-functions
|
|
|
|
|
2015-03-22 14:04:46 +00:00
|
|
|
if [ -f ${TARGET_ROOT}/.extra_settings ] ; then
|
|
|
|
. ${TARGET_ROOT}/.extra_settings
|
|
|
|
fi
|
|
|
|
ARCH=${ARCH:-x86_64}
|
|
|
|
if [ $ARCH = amd64 ]; then
|
|
|
|
ARCH=x86_64
|
2021-04-01 02:13:12 +00:00
|
|
|
elif [[ "arm64" == "$ARCH" ]]; then
|
|
|
|
ARCH="aarch64"
|
2015-03-22 14:04:46 +00:00
|
|
|
fi
|
|
|
|
# Calling elements will need to set DISTRO_NAME and DIB_RELEASE
|
|
|
|
# TODO Maybe deal with DIB_DISTRIBUTION_MIRROR
|
|
|
|
http_proxy=${http_proxy:-}
|
2015-10-15 18:16:44 +00:00
|
|
|
YUM=${YUM:-yum}
|
2015-03-22 14:04:46 +00:00
|
|
|
|
2015-09-24 04:55:48 +00:00
|
|
|
WORKING=$(mktemp --tmpdir=${TMP_DIR:-/tmp} -d)
|
|
|
|
EACTION="rm -r $WORKING"
|
|
|
|
trap "$EACTION" EXIT
|
2015-03-22 14:04:46 +00:00
|
|
|
|
2015-09-24 04:55:48 +00:00
|
|
|
YUM_CACHE=$DIB_IMAGE_CACHE/yum
|
2015-10-23 04:17:18 +00:00
|
|
|
mkdir -p $YUM_CACHE
|
2015-03-22 14:04:46 +00:00
|
|
|
|
2021-08-27 06:36:15 +00:00
|
|
|
# Debian Bullseye and beyond only has DNF locally
|
|
|
|
HOST_YUM_DOWNLOADER="yumdownloader"
|
|
|
|
HOST_YUM="yum"
|
|
|
|
if ! command -v yumdownloader &> /dev/null
|
|
|
|
then
|
|
|
|
HOST_YUM_DOWNLOADER="dnf download"
|
|
|
|
HOST_YUM="dnf"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
Fixup RPM db path when building Fedora on Ubuntu
On Debian/Ubuntu installs of RPM, /usr/lib/rpm/macros sets
%_dbpath %(echo $HOME/.rpmdb)
which makes quite a bit of sense, because RPM is not the system
packager and thus RPM is setup to install things into a hierarchy in
the users homedir.
However, this messes things up when building a Fedora chroot on an
Ubuntu platform.
We use RPM & yum from the base-system to bootstrap the Fedora chroot.
While both obey --root flags, they still pick up the %_dbpath macro
and so end up creating the RPM database in <chroot>/home/user/.rpmdb
After we have bootstrapped yum/dnf, we execute further installation
commands from inside the chroot -- where we now have the Fedora
version of /usr/lib/rpm/macros and hence have _dbpath set to
/var/lib/rpm -- except there is no rpm database there.
Should anyone be finding this in the future, the actual issue that
appears is
$ sudo chroot /opt/dib_tmp/image.b6B5S3f6/mnt dnf makecache
Error: Failed to synchronize cache for repo 'fedora' from \
'https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=x86_64': \
Cannot prepare internal mirrorlist: file "repomd.xml" was not found in metalink
Note the issue there is that $releasever is not expanded, because the
rpmdb where this info is kept is not populated.
The trick is to make sure we override this value when using the host
rpm/yum to setup the chroot. The bare rpm calls, which we use to
install the repos, have a --dbpath argument where we can override
this. yum does not however, so we override this in the global
~/.rpmmacros while we are installing the packaging tools and
dependencies into the chroot.
Copious comments are included, because this is super-confusing.
Change-Id: I20801150ea02d1c64f118eb969fb2aec473476f7
2015-10-23 04:42:00 +00:00
|
|
|
# Note, on Debian/Ubuntu, %_dbpath is set in the RPM macros as
|
|
|
|
# ${HOME}/.rpmdb/ -- this makes sense as RPM isn't the system
|
|
|
|
# packager. This path is relative to the "--root" argument
|
|
|
|
_RPM="rpm --dbpath=/var/lib/rpm"
|
|
|
|
|
2015-09-24 04:55:48 +00:00
|
|
|
# install the [fedora|centos]-[release|repo] packages inside the
|
|
|
|
# chroot, which are needed to bootstrap yum/dnf
|
|
|
|
#
|
|
|
|
# note this runs outside the chroot, where we're assuming the platform
|
2021-08-27 06:36:15 +00:00
|
|
|
# has yum/yumdownloader/dnf download
|
2015-09-24 04:55:48 +00:00
|
|
|
function _install_repos {
|
2016-02-11 04:42:10 +00:00
|
|
|
local packages
|
2016-11-10 03:22:17 +00:00
|
|
|
local rc
|
2016-02-11 04:42:10 +00:00
|
|
|
|
|
|
|
# pre-install the base system packages via rpm. We previously
|
|
|
|
# just left it up to yum to drag these in when we "yum install
|
|
|
|
# yum" in the chroot in _install_pkg_manager. This raised a small
|
|
|
|
# problem that inside the empty chroot yum went ahead and did a
|
|
|
|
# mkdir for /var/run to put some pid file in, which then messed up
|
|
|
|
# the "filesystem" package making /var/run a symlink to /run
|
|
|
|
# ... which leads to odd issues with a running system.
|
|
|
|
#
|
|
|
|
# TODO: these packages still have some small %posttrans stuff that
|
|
|
|
# depends on other packages (see rhbz#1306489) ... maybe the idea
|
|
|
|
# is that they are only installed in one big transaction with the
|
|
|
|
# rest of the system? but we don't want to use yum to do this
|
|
|
|
# (see above) so ...
|
2021-07-27 17:45:50 +00:00
|
|
|
packages="${DIB_YUM_MINIMAL_BOOTSTRAP_PACKAGES:-} "
|
|
|
|
packages+="basesystem filesystem setup "
|
2019-05-02 23:57:33 +00:00
|
|
|
if [[ ${DISTRO_NAME} = fedora && ${DIB_RELEASE} -gt 29 ]]; then
|
2019-08-15 05:56:13 +00:00
|
|
|
packages+="fedora-release-cloud fedora-release-common "
|
2021-09-28 10:35:15 +00:00
|
|
|
elif [[ ${DISTRO_NAME} == 'centos' && ${DIB_RELEASE} = '9-stream' ]]; then
|
|
|
|
packages+="bash glibc ncurses-libs "
|
2021-04-01 02:13:12 +00:00
|
|
|
elif [[ ${DISTRO_NAME} == 'openeuler' ]]; then
|
|
|
|
packages+="openEuler-release "
|
2019-05-02 23:57:33 +00:00
|
|
|
else
|
|
|
|
packages+="${DISTRO_NAME}-release "
|
|
|
|
fi
|
2017-11-20 04:16:45 +00:00
|
|
|
|
|
|
|
# Starting in F21 this was split into a separate package
|
|
|
|
if [[ ${DISTRO_NAME} == 'fedora' ]]; then
|
|
|
|
packages+="fedora-repos "
|
|
|
|
fi
|
|
|
|
|
|
|
|
# F27 started putting gpg keys into this separate package
|
|
|
|
if [[ ${DISTRO_NAME} = fedora && ${DIB_RELEASE} -gt 26 ]]; then
|
|
|
|
packages+="fedora-gpg-keys "
|
2015-03-22 14:04:46 +00:00
|
|
|
fi
|
2015-09-24 00:14:18 +00:00
|
|
|
|
2020-01-15 18:37:03 +00:00
|
|
|
# CentOS 8.1 split repositories and GPG keys out into subpackages
|
2021-09-28 10:35:15 +00:00
|
|
|
if [[ ${DISTRO_NAME} = centos && ${DIB_RELEASE%-stream} -gt 7 ]]; then
|
2021-02-22 23:57:05 +00:00
|
|
|
packages+="centos-gpg-keys "
|
2020-02-19 09:37:26 +00:00
|
|
|
if [[ "$DIB_RELEASE" =~ (stream) ]]; then
|
2020-11-02 15:58:34 +00:00
|
|
|
packages+="centos-stream-release centos-stream-repos "
|
2021-02-22 23:57:05 +00:00
|
|
|
else
|
|
|
|
packages+="centos-linux-release centos-linux-repos "
|
2020-02-19 09:37:26 +00:00
|
|
|
fi
|
2020-01-15 18:37:03 +00:00
|
|
|
fi
|
|
|
|
|
2021-04-01 02:13:12 +00:00
|
|
|
# For openEuler, install other required repos and gpy-keys packages.
|
|
|
|
if [[ ${DISTRO_NAME} == 'openeuler' ]]; then
|
|
|
|
packages+="openEuler-repos openEuler-gpg-keys "
|
|
|
|
fi
|
|
|
|
|
2017-06-20 00:42:10 +00:00
|
|
|
# By default, parent elements (fedora-minimal, centos-minimal)
|
|
|
|
# have a yum.repos.d directory in the element with a default repo;
|
|
|
|
# this is copied to TMP_HOOK_PATH by the usual hook-copying
|
|
|
|
# routines. In the gate, environment.d files for the funtional
|
|
|
|
# tests will set DIB_YUM_MINIMAL_BOOTSTRAP_REPOS -- this contains
|
|
|
|
# mirrors correct for the region setup by contrib/setup-gate-mirrors.sh
|
2019-09-25 00:53:39 +00:00
|
|
|
local repo=${DIB_YUM_MINIMAL_BOOTSTRAP_REPOS:-}
|
|
|
|
if [[ -z ${repo} ]]; then
|
|
|
|
# take in preference more specific subdirs
|
|
|
|
if [[ -d ${TMP_HOOKS_PATH}/yum.repos.d/${DIB_RELEASE} ]]; then
|
|
|
|
repo=${TMP_HOOKS_PATH}/yum.repos.d/${DIB_RELEASE}
|
|
|
|
else
|
|
|
|
repo=${TMP_HOOKS_PATH}/yum.repos.d
|
|
|
|
fi
|
|
|
|
fi
|
2017-06-20 00:42:10 +00:00
|
|
|
|
2016-11-10 03:22:17 +00:00
|
|
|
# yumdownloader puts repo xml files and such into a directory
|
|
|
|
# ${TMPDIR}/yum-$USER-random. Since we don't need this once the
|
|
|
|
# initial download happens, redirect TMPDIR for this call so we
|
|
|
|
# can clean it up nicely
|
|
|
|
local temp_tmp
|
|
|
|
temp_tmp=$(mktemp -d)
|
2021-08-27 06:36:15 +00:00
|
|
|
TMPDIR=${temp_tmp} ${HOST_YUM_DOWNLOADER} --verbose \
|
2021-09-28 10:35:15 +00:00
|
|
|
--releasever=${DIB_RELEASE} \
|
2017-06-20 00:42:10 +00:00
|
|
|
--setopt=reposdir=$repo \
|
2019-12-12 19:22:22 +00:00
|
|
|
--setopt=cachedir=$temp_tmp \
|
2016-02-11 04:42:10 +00:00
|
|
|
--destdir=$WORKING \
|
2016-11-10 03:22:17 +00:00
|
|
|
${packages} && rc=$? || rc=$?
|
|
|
|
rm -rf ${temp_tmp}
|
|
|
|
if [[ ${rc} != 0 ]]; then
|
|
|
|
die "Failed to download initial packages: ${packages}"
|
|
|
|
fi
|
2016-02-11 04:42:10 +00:00
|
|
|
|
2015-09-24 00:14:18 +00:00
|
|
|
# --nodeps works around these wanting /bin/sh in some fedora
|
|
|
|
# releases, see rhbz#1265873
|
Fixup RPM db path when building Fedora on Ubuntu
On Debian/Ubuntu installs of RPM, /usr/lib/rpm/macros sets
%_dbpath %(echo $HOME/.rpmdb)
which makes quite a bit of sense, because RPM is not the system
packager and thus RPM is setup to install things into a hierarchy in
the users homedir.
However, this messes things up when building a Fedora chroot on an
Ubuntu platform.
We use RPM & yum from the base-system to bootstrap the Fedora chroot.
While both obey --root flags, they still pick up the %_dbpath macro
and so end up creating the RPM database in <chroot>/home/user/.rpmdb
After we have bootstrapped yum/dnf, we execute further installation
commands from inside the chroot -- where we now have the Fedora
version of /usr/lib/rpm/macros and hence have _dbpath set to
/var/lib/rpm -- except there is no rpm database there.
Should anyone be finding this in the future, the actual issue that
appears is
$ sudo chroot /opt/dib_tmp/image.b6B5S3f6/mnt dnf makecache
Error: Failed to synchronize cache for repo 'fedora' from \
'https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=x86_64': \
Cannot prepare internal mirrorlist: file "repomd.xml" was not found in metalink
Note the issue there is that $releasever is not expanded, because the
rpmdb where this info is kept is not populated.
The trick is to make sure we override this value when using the host
rpm/yum to setup the chroot. The bare rpm calls, which we use to
install the repos, have a --dbpath argument where we can override
this. yum does not however, so we override this in the global
~/.rpmmacros while we are installing the packaging tools and
dependencies into the chroot.
Copious comments are included, because this is super-confusing.
Change-Id: I20801150ea02d1c64f118eb969fb2aec473476f7
2015-10-23 04:42:00 +00:00
|
|
|
sudo $_RPM --root $TARGET_ROOT --nodeps -ivh $WORKING/*rpm
|
2017-06-20 00:42:10 +00:00
|
|
|
|
|
|
|
# install the bootstrap mirror repos over the default ones, if
|
|
|
|
# set. we will remove this at the end so the final image has
|
|
|
|
# regular mirrors
|
|
|
|
if [[ -n ${DIB_YUM_MINIMAL_BOOTSTRAP_REPOS:-} ]]; then
|
|
|
|
for repo in $TARGET_ROOT/etc/yum.repos.d/*.repo; do
|
|
|
|
sudo mv $repo $repo.USING_MIRROR
|
|
|
|
done
|
|
|
|
sudo cp ${DIB_YUM_MINIMAL_BOOTSTRAP_REPOS}/* \
|
|
|
|
$TARGET_ROOT/etc/yum.repos.d/
|
|
|
|
fi
|
|
|
|
|
2019-08-15 14:20:21 +00:00
|
|
|
if [[ -n ${DIB_YUM_MINIMAL_EXTRA_REPOS:-} ]]; then
|
|
|
|
sudo cp ${DIB_YUM_MINIMAL_EXTRA_REPOS}/* \
|
|
|
|
$TARGET_ROOT/etc/yum.repos.d/
|
|
|
|
fi
|
2021-04-01 02:13:12 +00:00
|
|
|
|
|
|
|
# For openEuler, some repos like update are disabled by default.
|
|
|
|
# Ensure all the repo is enabled, so that we get the latest packages.
|
|
|
|
if [[ ${DISTRO_NAME} == 'openeuler' ]]; then
|
|
|
|
sudo sed -i 's/enabled=0/enabled=1/' $TARGET_ROOT/etc/yum.repos.d/*.repo
|
|
|
|
fi
|
2015-09-24 04:55:48 +00:00
|
|
|
}
|
2015-03-22 14:04:46 +00:00
|
|
|
|
2015-09-24 04:55:48 +00:00
|
|
|
# _install_pkg_manager packages...
|
|
|
|
#
|
|
|
|
# install the package manager packages. This is done outside the chroot
|
|
|
|
# and with yum from the build system.
|
|
|
|
# TODO: one day build systems will be dnf only, but we don't handle
|
|
|
|
# that right now
|
|
|
|
function _install_pkg_manager {
|
|
|
|
# Install into the chroot, using the gpg keys from the release
|
|
|
|
# rpm's installed in the chroot
|
|
|
|
sudo sed -i "s,/etc/pki/rpm-gpg,$TARGET_ROOT/etc/pki/rpm-gpg,g" \
|
|
|
|
$TARGET_ROOT/etc/yum.repos.d/*repo
|
2015-03-22 14:04:46 +00:00
|
|
|
|
Fixup RPM db path when building Fedora on Ubuntu
On Debian/Ubuntu installs of RPM, /usr/lib/rpm/macros sets
%_dbpath %(echo $HOME/.rpmdb)
which makes quite a bit of sense, because RPM is not the system
packager and thus RPM is setup to install things into a hierarchy in
the users homedir.
However, this messes things up when building a Fedora chroot on an
Ubuntu platform.
We use RPM & yum from the base-system to bootstrap the Fedora chroot.
While both obey --root flags, they still pick up the %_dbpath macro
and so end up creating the RPM database in <chroot>/home/user/.rpmdb
After we have bootstrapped yum/dnf, we execute further installation
commands from inside the chroot -- where we now have the Fedora
version of /usr/lib/rpm/macros and hence have _dbpath set to
/var/lib/rpm -- except there is no rpm database there.
Should anyone be finding this in the future, the actual issue that
appears is
$ sudo chroot /opt/dib_tmp/image.b6B5S3f6/mnt dnf makecache
Error: Failed to synchronize cache for repo 'fedora' from \
'https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=x86_64': \
Cannot prepare internal mirrorlist: file "repomd.xml" was not found in metalink
Note the issue there is that $releasever is not expanded, because the
rpmdb where this info is kept is not populated.
The trick is to make sure we override this value when using the host
rpm/yum to setup the chroot. The bare rpm calls, which we use to
install the repos, have a --dbpath argument where we can override
this. yum does not however, so we override this in the global
~/.rpmmacros while we are installing the packaging tools and
dependencies into the chroot.
Copious comments are included, because this is super-confusing.
Change-Id: I20801150ea02d1c64f118eb969fb2aec473476f7
2015-10-23 04:42:00 +00:00
|
|
|
# See notes on $_RPM variable -- we need to override the
|
|
|
|
# $HOME-based dbpath set on debian/ubuntu here. Unfortunately,
|
|
|
|
# yum does not have a way to override rpm macros from the command
|
|
|
|
# line. So we modify the user's ~/.rpmmacros to set %_dbpath back
|
|
|
|
# to "/var/lib/rpm" (note, this is taken relative to the
|
|
|
|
# --installroot).
|
|
|
|
#
|
|
|
|
# Also note, we only want this done around this call -- this is
|
|
|
|
# the only place we are using yum outside the chroot, and hence
|
|
|
|
# picking up the base-system's default rpm macros. For example,
|
|
|
|
# the yumdownloader calls above in _install_repos want to use
|
|
|
|
# ~/.rpmdb/ ... there is nothing in the build-system /var/lib/rpm!
|
2015-12-01 20:26:26 +00:00
|
|
|
#
|
|
|
|
# Another issue we hit is having to set --releasedir here. yum
|
|
|
|
# determines $releasevar based on (more or less) "rpm -q
|
|
|
|
# --whatprovides $distroverpkg". By default, this is
|
|
|
|
# "redhat-release" (fedora-release provides redhat-release) but
|
|
|
|
# some platforms like CentOS override it in /etc/yum.conf (to
|
|
|
|
# centos-release in their case). You can't override this (see
|
|
|
|
# [1]), but setting --releasever works around this.
|
|
|
|
#
|
|
|
|
# [1] https://bugzilla.redhat.com/show_bug.cgi?id=1287333
|
Fixup RPM db path when building Fedora on Ubuntu
On Debian/Ubuntu installs of RPM, /usr/lib/rpm/macros sets
%_dbpath %(echo $HOME/.rpmdb)
which makes quite a bit of sense, because RPM is not the system
packager and thus RPM is setup to install things into a hierarchy in
the users homedir.
However, this messes things up when building a Fedora chroot on an
Ubuntu platform.
We use RPM & yum from the base-system to bootstrap the Fedora chroot.
While both obey --root flags, they still pick up the %_dbpath macro
and so end up creating the RPM database in <chroot>/home/user/.rpmdb
After we have bootstrapped yum/dnf, we execute further installation
commands from inside the chroot -- where we now have the Fedora
version of /usr/lib/rpm/macros and hence have _dbpath set to
/var/lib/rpm -- except there is no rpm database there.
Should anyone be finding this in the future, the actual issue that
appears is
$ sudo chroot /opt/dib_tmp/image.b6B5S3f6/mnt dnf makecache
Error: Failed to synchronize cache for repo 'fedora' from \
'https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=x86_64': \
Cannot prepare internal mirrorlist: file "repomd.xml" was not found in metalink
Note the issue there is that $releasever is not expanded, because the
rpmdb where this info is kept is not populated.
The trick is to make sure we override this value when using the host
rpm/yum to setup the chroot. The bare rpm calls, which we use to
install the repos, have a --dbpath argument where we can override
this. yum does not however, so we override this in the global
~/.rpmmacros while we are installing the packaging tools and
dependencies into the chroot.
Copious comments are included, because this is super-confusing.
Change-Id: I20801150ea02d1c64f118eb969fb2aec473476f7
2015-10-23 04:42:00 +00:00
|
|
|
(
|
|
|
|
flock -w 1200 9 || die "Can not lock .rpmmacros"
|
|
|
|
echo "%_dbpath /var/lib/rpm" >> $HOME/.rpmmacros
|
2016-04-19 23:42:42 +00:00
|
|
|
|
2017-07-18 04:51:18 +00:00
|
|
|
local _lang_pack=""
|
|
|
|
local _extra_pkgs=""
|
2016-06-23 06:02:16 +00:00
|
|
|
|
2019-09-25 01:30:12 +00:00
|
|
|
if [[ $DISTRO_NAME == "fedora" ]] || \
|
2020-02-19 09:37:26 +00:00
|
|
|
[[ $DISTRO_NAME == "centos" && $DIB_RELEASE > "7" ]]; then
|
2019-09-25 01:30:12 +00:00
|
|
|
# glibc from F24 onwards has split locales into "langpack"
|
|
|
|
# packages. Host yum doesn't understand the
|
|
|
|
# weak-dependencies glibc now uses to get the
|
|
|
|
# minimal-langpack and chooses a random(ish) one that
|
|
|
|
# satisfies the locale dependency (rhbz#1349258).
|
|
|
|
# Work-around this by explicitly requring the minimal and
|
|
|
|
# english (for en_US.UTF-8) pack.
|
2016-07-15 03:24:32 +00:00
|
|
|
_lang_pack="glibc-minimal-langpack glibc-langpack-en"
|
Rework yum-minimal locale cleanup
It turns out our manual locale cleanup is causing issues (see
I54490b17a7f8b2f977369044fcc6bb49cc13768e). Upon further
investigation, I think this is a better approach than manually
deleting repos.
glibc on Fedora obeys the %_install_langs macro for reducing the
installed locales (as mentioned in the comments, F24 has moved to
having different packages, but worry about that later).
So our existing clear-out is really only required for CentOS, whose
glibc does not have any way to indicate to build less locales.
However, %_install_langs is still correct there, as it restricts some
of the translation files and other things installed with the %lang
macro in spec files.
This is complicated by us having to set this at glibc-common install
time, which happens with the "yum" from outside the chroot (i.e. on
trusty). Since this is too old to have flags to pass this, we need to
fiddle with rpmmacros.
I've tested this with fedora-minimal builds and the locales file is
about 2MiB, which is what it was after the cleanups, and the listed
locales are only those we expect (i.e. it appears to be working).
Change-Id: I528a68beeb7b2ceec25ccbec1900670501608158
2016-05-31 04:53:05 +00:00
|
|
|
fi
|
|
|
|
|
2017-07-18 04:51:18 +00:00
|
|
|
# Yum has some issues choosing weak dependencies. It can end
|
|
|
|
# up choosing "coreutils-single" instead of "coreutils" which
|
|
|
|
# causes problems later when a package actually requires
|
|
|
|
# coreutils. For more info see
|
|
|
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1286445
|
|
|
|
# Really all we can do is pre-install the right thing
|
|
|
|
_extra_pkgs+="coreutils "
|
|
|
|
|
2020-02-19 09:37:26 +00:00
|
|
|
# Legacy yum reads vars from directory /etc/yum/vars and, unlike dnf,
|
|
|
|
# does not provide setopt=varsdir. So, if $YUM is legacy yum and our
|
|
|
|
# target root is dnf, symlink dnf vars.
|
|
|
|
if [[ ! -d $TARGET_ROOT/etc/yum/vars ]]; then
|
|
|
|
sudo mkdir -p $TARGET_ROOT/etc/yum
|
|
|
|
sudo ln -s $TARGET_ROOT/etc/dnf/vars $TARGET_ROOT/etc/yum/vars
|
|
|
|
fi
|
|
|
|
|
2021-08-27 06:36:15 +00:00
|
|
|
sudo -E ${HOST_YUM} -y \
|
2016-09-19 23:18:00 +00:00
|
|
|
--disableexcludes=all \
|
2015-03-22 14:04:46 +00:00
|
|
|
--setopt=cachedir=$YUM_CACHE/$ARCH/$DIB_RELEASE \
|
|
|
|
--setopt=reposdir=$TARGET_ROOT/etc/yum.repos.d \
|
2020-02-19 09:37:26 +00:00
|
|
|
--releasever=${DIB_RELEASE/-*/} \
|
2015-03-22 14:04:46 +00:00
|
|
|
--installroot $TARGET_ROOT \
|
2017-07-18 04:51:18 +00:00
|
|
|
install $@ ${_lang_pack} ${_extra_pkgs} && rc=$? || rc=$?
|
2016-04-19 23:42:42 +00:00
|
|
|
|
2020-02-19 09:37:26 +00:00
|
|
|
# we may have symlinked yum/vars -> dnf/vars, unset if so
|
|
|
|
sudo unset $TARGET_ROOT/etc/yum/vars 2>/dev/null || true
|
|
|
|
|
2017-10-22 16:16:04 +00:00
|
|
|
# Note we've modified the base system's .rpmmacros. Ensure we
|
|
|
|
# clean it up *always*
|
Rework yum-minimal locale cleanup
It turns out our manual locale cleanup is causing issues (see
I54490b17a7f8b2f977369044fcc6bb49cc13768e). Upon further
investigation, I think this is a better approach than manually
deleting repos.
glibc on Fedora obeys the %_install_langs macro for reducing the
installed locales (as mentioned in the comments, F24 has moved to
having different packages, but worry about that later).
So our existing clear-out is really only required for CentOS, whose
glibc does not have any way to indicate to build less locales.
However, %_install_langs is still correct there, as it restricts some
of the translation files and other things installed with the %lang
macro in spec files.
This is complicated by us having to set this at glibc-common install
time, which happens with the "yum" from outside the chroot (i.e. on
trusty). Since this is too old to have flags to pass this, we need to
fiddle with rpmmacros.
I've tested this with fedora-minimal builds and the locales file is
about 2MiB, which is what it was after the cleanups, and the listed
locales are only those we expect (i.e. it appears to be working).
Change-Id: I528a68beeb7b2ceec25ccbec1900670501608158
2016-05-31 04:53:05 +00:00
|
|
|
# sed makes it easy to remove last line, but not last n lines...
|
|
|
|
sed -i '$ d' $HOME/.rpmmacros; sed -i '$ d' $HOME/.rpmmacros;
|
2016-04-19 23:42:42 +00:00
|
|
|
if [ $rc != 0 ]; then
|
|
|
|
die "Initial yum install to chroot failed! Can not continue."
|
|
|
|
fi
|
2017-10-22 16:16:04 +00:00
|
|
|
) 9>$DIB_LOCKFILES/.rpmmacros.dib.lock
|
2016-04-19 23:42:42 +00:00
|
|
|
|
2015-09-24 04:55:48 +00:00
|
|
|
# Set gpg path back because subsequent actions will take place in
|
|
|
|
# the chroot
|
|
|
|
sudo sed -i "s,$TARGET_ROOT/etc/pki/rpm-gpg,/etc/pki/rpm-gpg,g" \
|
|
|
|
$TARGET_ROOT/etc/yum.repos.d/*repo
|
|
|
|
}
|
2015-03-22 14:04:46 +00:00
|
|
|
|
2016-12-09 03:41:24 +00:00
|
|
|
# Note this is not usually done for root.d elements (see
|
|
|
|
# lib/common-functions:mount_proc_dev_sys) but it's important that
|
|
|
|
# we have things like /dev/urandom around inside the chroot for
|
|
|
|
# the rpm [pre|post]inst scripts within the packages.
|
|
|
|
sudo mkdir -p $TARGET_ROOT/proc $TARGET_ROOT/dev $TARGET_ROOT/sys
|
|
|
|
sudo mount -t proc none $TARGET_ROOT/proc
|
|
|
|
sudo mount --bind /dev $TARGET_ROOT/dev
|
Fix /dev/pts mount options handling
The current implementation - as introduced in
Iee44703297a15b14c715f4bfb7bae67f613aceee - has some shortcomings / bugs,
like:
* the 'grep' check is too sloppy
* when /dev/pts is already mounted multiple times the current implementation
fails:
$ mount | grep devpts | sed 's/.*(\(.*\))/\1/'
rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
* code duplication
* Using the undocumented and non-robust output
of 'mount'.
This patch fixed the above problems.
Change-Id: Ib0c7358772480c56d405659a6a32afd60c311686
Signed-off-by: Andreas Florath <andreas@florath.net>
2017-11-23 19:50:31 +00:00
|
|
|
sudo mount -t devpts $(mount_dev_pts_options) devpts $TARGET_ROOT/dev/pts
|
2021-07-01 23:26:20 +00:00
|
|
|
# Mounting /sys as RO indicates to various systemd things
|
|
|
|
# that we are in a container
|
|
|
|
sudo mount -o ro -t sysfs none $TARGET_ROOT/sys
|
2016-12-09 03:41:24 +00:00
|
|
|
|
|
|
|
# initalize rpmdb
|
|
|
|
sudo mkdir -p $TARGET_ROOT/var/lib/rpm
|
|
|
|
sudo $_RPM --root $TARGET_ROOT --initdb
|
|
|
|
|
|
|
|
# this makes sure that running yum/dnf in the chroot it can get
|
|
|
|
# out to download stuff
|
|
|
|
sudo mkdir $TARGET_ROOT/etc
|
|
|
|
sudo cp /etc/resolv.conf $TARGET_ROOT/etc/resolv.conf
|
|
|
|
|
|
|
|
# Bind mount the external yum cache inside the chroot. Same logic
|
|
|
|
# as in the yum element to provide for yum caching copied here
|
|
|
|
# because the sequencing is wrong otherwise
|
|
|
|
sudo mkdir -p $TMP_MOUNT_PATH/tmp/yum
|
|
|
|
sudo mount --bind $YUM_CACHE $TMP_MOUNT_PATH/tmp/yum
|
|
|
|
|
|
|
|
_install_repos
|
|
|
|
|
2019-09-25 03:49:55 +00:00
|
|
|
# Install package manager
|
|
|
|
|
|
|
|
# We are somewhat fighting against the "yum" version on the host to
|
|
|
|
# get things installed correctly. Fedora 27 onwards has a
|
|
|
|
# "curl-minimal" package that will get pulled in by default for the
|
|
|
|
# initial install (ianw: I think because the yum doesn't understand
|
|
|
|
# weak dependencies correctly). This causes problems later if/when
|
|
|
|
# "curl" gets installed (you need to add --allowerasing to let dnf get
|
|
|
|
# rid of the old package). To avoid this, just install the full curl
|
|
|
|
# and first up. On Centos, it's different again and we need to
|
|
|
|
# specify libcurl as well, or the minimal libcurl packages come in
|
|
|
|
# causing similar problems. *But* -- we can't also do that on Fedora
|
|
|
|
# it seems, as it seems like as part of the Fedora modular updates
|
|
|
|
# (https://docs.fedoraproject.org/en-US/modularity/) we can pick up
|
|
|
|
# seemingly mismatched libraries.
|
2021-04-01 02:13:12 +00:00
|
|
|
if [[ ${DISTRO_NAME} =~ (fedora|openeuler) ]]; then
|
2019-09-25 03:49:55 +00:00
|
|
|
_install_pkg_manager dnf dnf-plugins-core curl
|
2020-02-19 09:37:26 +00:00
|
|
|
elif [[ ${DISTRO_NAME} == centos && $DIB_RELEASE > "7" ]]; then
|
2019-09-25 03:49:55 +00:00
|
|
|
_install_pkg_manager dnf dnf-plugins-core curl libcurl
|
2015-09-24 04:55:48 +00:00
|
|
|
else
|
2016-12-09 03:41:24 +00:00
|
|
|
_install_pkg_manager yum
|
|
|
|
fi
|
Rework yum-minimal locale cleanup
It turns out our manual locale cleanup is causing issues (see
I54490b17a7f8b2f977369044fcc6bb49cc13768e). Upon further
investigation, I think this is a better approach than manually
deleting repos.
glibc on Fedora obeys the %_install_langs macro for reducing the
installed locales (as mentioned in the comments, F24 has moved to
having different packages, but worry about that later).
So our existing clear-out is really only required for CentOS, whose
glibc does not have any way to indicate to build less locales.
However, %_install_langs is still correct there, as it restricts some
of the translation files and other things installed with the %lang
macro in spec files.
This is complicated by us having to set this at glibc-common install
time, which happens with the "yum" from outside the chroot (i.e. on
trusty). Since this is too old to have flags to pass this, we need to
fiddle with rpmmacros.
I've tested this with fedora-minimal builds and the locales file is
about 2MiB, which is what it was after the cleanups, and the listed
locales are only those we expect (i.e. it appears to be working).
Change-Id: I528a68beeb7b2ceec25ccbec1900670501608158
2016-05-31 04:53:05 +00:00
|
|
|
|
2020-04-21 20:27:03 +00:00
|
|
|
# sort of like run_in_target; but we're not in a phase where that
|
|
|
|
# works yet. strip unnecessary external env vars that can cause
|
|
|
|
# problems.
|
|
|
|
function _run_chroot {
|
|
|
|
local cmd="$@"
|
|
|
|
sudo -E chroot $TARGET_ROOT env -u TMPDIR sh -c "$cmd"
|
|
|
|
}
|
|
|
|
|
2016-12-09 03:41:24 +00:00
|
|
|
# we just installed yum/dnf with "outside" tools (yum/rpm) which
|
|
|
|
# might have created /var/lib/[yum|rpm] (etc) that are slighlty
|
|
|
|
# incompatible. Refresh everything with the in-chroot tools
|
2020-04-21 20:27:03 +00:00
|
|
|
_run_chroot rpm --rebuilddb
|
|
|
|
_run_chroot ${YUM} clean all
|
2016-12-09 03:41:24 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2017-11-20 04:56:31 +00:00
|
|
|
_base_packages="systemd passwd findutils sudo util-linux-ng "
|
2016-12-09 03:41:24 +00:00
|
|
|
|
|
|
|
# This package is split out from systemd on >F24, dracut is
|
|
|
|
# missing the dependency and will fail to make an initrd without
|
|
|
|
# it; see
|
|
|
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1398505
|
2017-11-20 04:56:31 +00:00
|
|
|
_base_packages+="systemd-udev "
|
|
|
|
|
|
|
|
# bootstrap the environment within the chroot; bring in new
|
|
|
|
# metadata with an update and install some base packages we need.
|
2020-04-21 20:27:03 +00:00
|
|
|
_run_chroot ${YUM} -y update
|
|
|
|
_run_chroot ${YUM} -y \
|
2017-11-20 04:56:31 +00:00
|
|
|
--setopt=cachedir=/tmp/yum/$ARCH/$DIB_RELEASE \
|
|
|
|
install ${_base_packages}
|
2015-03-22 14:04:46 +00:00
|
|
|
|
2016-12-09 03:41:24 +00:00
|
|
|
# Put in a dummy /etc/resolv.conf over the temporary one we used
|
|
|
|
# to bootstrap. systemd has a bug/feature [1] that it will assume
|
|
|
|
# you want systemd-networkd as the network manager and create a
|
|
|
|
# broken symlink to /run/... if the base image doesn't have one.
|
|
|
|
# This broken link confuses things like dhclient.
|
|
|
|
# [1] https://bugzilla.redhat.com/show_bug.cgi?id=1197204
|
|
|
|
echo -e "# This file intentionally left blank\n" | \
|
|
|
|
sudo tee $TARGET_ROOT/etc/resolv.conf
|
|
|
|
|
|
|
|
# set the most reliable UTF-8 locale
|
|
|
|
echo -e 'LANG="en_US.UTF-8"' | \
|
|
|
|
sudo tee $TARGET_ROOT/etc/locale.conf
|
2016-07-15 03:24:32 +00:00
|
|
|
# default to UTC
|
2020-04-21 20:27:03 +00:00
|
|
|
_run_chroot ln -sf /usr/share/zoneinfo/UTC \
|
2016-12-09 03:41:24 +00:00
|
|
|
/etc/localtime
|
|
|
|
|
|
|
|
# cleanup
|
|
|
|
# TODO : move this into a exit trap; and reconsider how
|
|
|
|
# this integrates with the global exit cleanup path.
|
|
|
|
sudo umount $TMP_MOUNT_PATH/tmp/yum
|
|
|
|
sudo umount $TARGET_ROOT/proc
|
|
|
|
sudo umount $TARGET_ROOT/dev/pts
|
|
|
|
sudo umount $TARGET_ROOT/dev
|
|
|
|
sudo umount $TARGET_ROOT/sys
|
|
|
|
|
|
|
|
# RPM doesn't know whether files have been changed since install
|
|
|
|
# At this point though, we know for certain that we have changed no
|
|
|
|
# config files, so anything marked .rpmnew is just a bug.
|
|
|
|
for newfile in $(sudo find $TARGET_ROOT -type f -name '*rpmnew') ; do
|
|
|
|
sudo mv $newfile $(echo $newfile | sed 's/.rpmnew$//')
|
|
|
|
done
|
2015-03-22 14:04:46 +00:00
|
|
|
|
|
|
|
sudo rm -f ${TARGET_ROOT}/.extra_settings
|