2016-09-30 10:13:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2016-12-09 10:33:56 +00:00
|
|
|
# Copyright 2016 SUSE Linux GmbH
|
2016-09-30 10:13:09 +00:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
# dib-lint: disable=safe_sudo
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-09-30 10:13:09 +00:00
|
|
|
function cleanup() {
|
2016-11-02 22:05:05 +00:00
|
|
|
sudo umount $TARGET_ROOT/proc
|
|
|
|
sudo umount $TARGET_ROOT/dev/pts
|
|
|
|
sudo umount $TARGET_ROOT/dev
|
|
|
|
sudo umount $TARGET_ROOT/sys
|
2016-09-30 10:13:09 +00:00
|
|
|
sudo umount $TMP_MOUNT_PATH/var/cache/zypp
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
ZYPPER_TARGET_OPTS="--non-interactive --gpg-auto-import-keys --root $TARGET_ROOT"
|
2017-02-20 19:48:50 +00:00
|
|
|
ZYPPER_INSTALL_OPTS="--no-recommends"
|
2016-09-30 10:13:09 +00:00
|
|
|
|
2017-06-28 08:53:38 +00:00
|
|
|
DIB_DISTRIBUTION_MIRROR=${DIB_DISTRIBUTION_MIRROR:-http://download.opensuse.org}
|
|
|
|
|
|
|
|
case ${DIB_RELEASE} in
|
|
|
|
# We are using "=>" as the assignment symbol since "@" "=" etc could be used in the URI itself.
|
|
|
|
# Remember, we can't export an array in bash so we use a string instead.
|
|
|
|
# Repo format: {name}=>{uri}
|
|
|
|
# Old openSUSE releases
|
|
|
|
13*)
|
|
|
|
ZYPPER_REPOS="update=>${DIB_DISTRIBUTION_MIRROR}/update/${DIB_RELEASE}/ "
|
|
|
|
ZYPPER_REPOS+="oss=>${DIB_DISTRIBUTION_MIRROR}/distribution/${DIB_RELEASE}/repo/oss/"
|
|
|
|
;;
|
|
|
|
# New Leap releases
|
|
|
|
42*)
|
|
|
|
ZYPPER_REPOS="update=>${DIB_DISTRIBUTION_MIRROR}/update/leap/${DIB_RELEASE}/oss/ "
|
|
|
|
ZYPPER_REPOS+="oss=>${DIB_DISTRIBUTION_MIRROR}/distribution/leap/${DIB_RELEASE}/repo/oss/"
|
|
|
|
;;
|
|
|
|
# Tumbleweed
|
|
|
|
tumbleweed)
|
|
|
|
ZYPPER_REPOS="update=>${DIB_DISTRIBUTION_MIRROR}/update/${DIB_RELEASE}/ "
|
|
|
|
ZYPPER_REPOS+="oss=>${DIB_DISTRIBUTION_MIRROR}/${DIB_RELEASE}/repo/oss/"
|
|
|
|
;;
|
|
|
|
*) echo "Unsupported openSUSE release: ${DIB_RELEASE}"; exit 1 ;;
|
|
|
|
esac
|
|
|
|
|
2016-09-30 10:13:09 +00:00
|
|
|
for repo in ${ZYPPER_REPOS}; do
|
|
|
|
reponame=repo-${repo%%=>*}
|
|
|
|
repouri=${repo##*=>}
|
|
|
|
sudo zypper ${ZYPPER_TARGET_OPTS} addrepo --name ${reponame} --keep-packages ${repouri} ${reponame}
|
|
|
|
done
|
|
|
|
|
|
|
|
# It appears that zypper will clean up the repo's cache when it (re-)adds the
|
|
|
|
# repo so we need to add the cache now, once the repos are added. This is
|
|
|
|
# similar to what the zypper/50-zypper-cache script does
|
|
|
|
ZYPPER_CACHE_DIR=$DIB_IMAGE_CACHE/zypper
|
|
|
|
mkdir -p $ZYPPER_CACHE_DIR
|
|
|
|
|
|
|
|
sudo mkdir -p $TMP_MOUNT_PATH/var/cache/zypp
|
|
|
|
sudo mount --bind $ZYPPER_CACHE_DIR $TMP_MOUNT_PATH/var/cache/zypp
|
|
|
|
|
2016-10-31 23:18:28 +00:00
|
|
|
# Refresh it so we get updated data in cased we switched DIB_RELEASE
|
|
|
|
# since last run.
|
|
|
|
sudo zypper ${ZYPPER_TARGET_OPTS} refresh
|
|
|
|
|
2016-11-02 22:05:05 +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
|
2016-11-02 22:05:05 +00:00
|
|
|
sudo mount -t sysfs none $TARGET_ROOT/sys
|
|
|
|
|
2016-09-30 10:13:09 +00:00
|
|
|
# Install filesystem, base and useful tools
|
|
|
|
sudo zypper ${ZYPPER_TARGET_OPTS} install ${ZYPPER_INSTALL_OPTS} filesystem
|
|
|
|
# Install basic components in order
|
2017-03-28 13:58:42 +00:00
|
|
|
sudo zypper ${ZYPPER_TARGET_OPTS} install ${ZYPPER_INSTALL_OPTS} ${DIB_OPENSUSE_PATTERNS} python zypper sudo
|
2016-09-30 10:13:09 +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
|
|
|
|
# default to UTC
|
2017-07-13 20:50:47 +00:00
|
|
|
sudo chroot $TARGET_ROOT ln -sf /usr/share/zoneinfo/UTC \
|
2016-09-30 10:13:09 +00:00
|
|
|
/etc/localtime
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2016-11-02 22:05:05 +00:00
|
|
|
# Unmounting of all the mount points is handled by the cleanup EXIT
|
2016-09-30 10:13:09 +00:00
|
|
|
# handler so there is nothing else to do here
|