223 lines
7.0 KiB
Bash
Executable File
223 lines
7.0 KiB
Bash
Executable File
#! /bin/bash
|
|
# Shared .setup between all Debian/Ubuntu flavors
|
|
|
|
set -ex
|
|
|
|
# Enable a console on ttyS0 so that we can log-in via vm-run.
|
|
# and make the boot up more verbose
|
|
sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT/# GRUB_CMDLINE_LINUX_DEFAULT/' /etc/default/grub
|
|
|
|
# We install all dependencies of the cockpit packages since we want
|
|
# them to not spontaneously change from one test run to the next when
|
|
# the distribution repository is updated.
|
|
#
|
|
COCKPIT_DEPS="\
|
|
cryptsetup \
|
|
docker.io \
|
|
libblockdev-mdraid2 \
|
|
libjson-glib-1.0-0 \
|
|
libpcp3 \
|
|
libpolkit-agent-1-0 \
|
|
libpolkit-gobject-1-0 \
|
|
libpwquality-tools \
|
|
libssh-4 \
|
|
libteam-utils \
|
|
libvirt-daemon-system \
|
|
libvirt-dbus \
|
|
libosinfo-bin \
|
|
network-manager \
|
|
pcp \
|
|
policykit-1 \
|
|
python3-dbus \
|
|
qemu-block-extra \
|
|
realmd \
|
|
selinux-basics \
|
|
thin-provisioning-tools \
|
|
unattended-upgrades \
|
|
tuned \
|
|
xdg-utils \
|
|
udisks2 \
|
|
udisks2-lvm2 \
|
|
"
|
|
|
|
# We also install the packages necessary to join a FreeIPA domain so
|
|
# that we don't have to go to the network during a test run.
|
|
IPA_CLIENT_PACKAGES="\
|
|
freeipa-client \
|
|
sssd-tools \
|
|
sssd-dbus \
|
|
packagekit \
|
|
"
|
|
|
|
TEST_PACKAGES="\
|
|
acl \
|
|
curl \
|
|
firewalld \
|
|
gdb \
|
|
iproute2 \
|
|
mdadm \
|
|
nfs-server \
|
|
qemu-kvm \
|
|
socat \
|
|
systemd-coredump \
|
|
virtinst \
|
|
xfsprogs \
|
|
sosreport \
|
|
"
|
|
|
|
RELEASE=$(grep -m1 ^deb /etc/apt/sources.list | awk '{print $3}')
|
|
case "$RELEASE" in
|
|
bionic)
|
|
# these packages are not in Ubuntu 18.04
|
|
COCKPIT_DEPS="${COCKPIT_DEPS/libvirt-dbus /}"
|
|
;;
|
|
esac
|
|
|
|
if [ "${1#ubuntu}" != "$1" ]; then
|
|
# our tests need scsi_debug, which the cloud kernel does not have; install full kernel
|
|
TEST_PACKAGES="$TEST_PACKAGES linux-image-generic"
|
|
fi
|
|
|
|
# our cloud-init.iso does not set up the host name
|
|
echo "127.0.1.1 $(hostname)" >> /etc/hosts
|
|
|
|
if grep -q 'ID=ubuntu' /etc/os-release; then
|
|
PBUILDER_OPTS='COMPONENTS="main universe"'
|
|
|
|
# We want to use/test NetworkManager instead of netplan/networkd for ethernets
|
|
mkdir -p /etc/NetworkManager/conf.d
|
|
touch /etc/NetworkManager/conf.d/10-globally-managed-devices.conf
|
|
fi
|
|
|
|
# some cloud images have a pre-defined admin user or group, for them cloud-init admin creation fails
|
|
userdel -r admin || true
|
|
groupdel admin || true
|
|
useradd -m -U -c Administrator -G sudo -s /bin/bash admin
|
|
echo admin:foobar | chpasswd
|
|
cp -r ~root/.ssh ~admin/
|
|
chown -R admin:admin ~admin/.ssh
|
|
|
|
# avoid NM-wait-online hanging on disconnected interfaces
|
|
mkdir -p /etc/NetworkManager/conf.d/
|
|
printf '[main]\nno-auto-default=*\n' > /etc/NetworkManager/conf.d/noauto.conf
|
|
|
|
if [ "${1#debian}" != "$1" ]; then
|
|
# HACK: Debian's cloud-init generates a *.cfg file, but /etc/network/interfaces sources extension-less files
|
|
mv /etc/network/interfaces.d/50-cloud-init.cfg /etc/network/interfaces.d/50-cloud-init
|
|
fi
|
|
|
|
# debian-testing image gets bootstrapped from debian stable; upgrade
|
|
if [ "$1" = "debian-testing" ]; then
|
|
rm --verbose -f /etc/apt/sources.list.d/*
|
|
echo 'deb http://deb.debian.org/debian testing main' > /etc/apt/sources.list
|
|
fi
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get -y update
|
|
# apt go-faster
|
|
echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/90nolanguages
|
|
apt-get install -y eatmydata
|
|
# remove packages that we don't need
|
|
for p in lxd snapd landscape-common accountsservice open-vm-tools ufw cloud-init; do eatmydata apt-get purge -y --auto-remove $p || true; done
|
|
|
|
# HACK: work around fuse 2.9.9-1 install failure (https://bugs.debian.org/935496)
|
|
if [ "$1" = "debian-testing" ]; then
|
|
rm /dev/fuse
|
|
# this needs to happen right away, as upgrading other packages triggers udev events which recreate /dev/fuse
|
|
eatmydata apt-get install -y fuse
|
|
fi
|
|
|
|
# HACK: debian-stable image got /usr/bin/qemu-img removed, even though qemu-utils package is installed
|
|
if [ "$1" = "debian-stable" ]; then
|
|
eatmydata apt-get install --reinstall -y qemu-utils
|
|
fi
|
|
|
|
# install our dependencies
|
|
DEBIAN_FRONTEND=noninteractive eatmydata apt-get -y dist-upgrade
|
|
eatmydata apt-get -y install $TEST_PACKAGES $COCKPIT_DEPS $IPA_CLIENT_PACKAGES
|
|
|
|
# Prepare for building
|
|
#
|
|
|
|
# extract control files and adjust them for our release, so that we can parse the build deps
|
|
mkdir -p /tmp/out
|
|
curl -L https://github.com/cockpit-project/cockpit/archive/master.tar.gz | tar -C /tmp/out --strip-components=1 --wildcards -zxf - '*/debian/'
|
|
/tmp/out/tools/debian/adjust-for-release $(lsb_release -sc)
|
|
|
|
# Disable build-dep installation for the real builds
|
|
cat > ~/.pbuilderrc <<- EOF
|
|
DISTRIBUTION=$RELEASE
|
|
PBUILDERSATISFYDEPENDSCMD=true
|
|
$PBUILDER_OPTS
|
|
EOF
|
|
|
|
eatmydata apt-get -y install dpkg-dev pbuilder
|
|
|
|
pbuilder --create --extrapackages "fakeroot $PBUILDER_EXTRA"
|
|
/usr/lib/pbuilder/pbuilder-satisfydepends-classic --control /tmp/out/tools/debian/control --force-version --echo|grep apt-get | pbuilder --login --save-after-login
|
|
rm -rf /tmp/out
|
|
|
|
# Debian does not automatically start the default libvirt network
|
|
virsh net-autostart default
|
|
|
|
# Don't automatically update on boot or daily
|
|
systemctl disable apt-daily.service apt-daily.timer || true
|
|
|
|
# Enable coredumping via systemd
|
|
echo "kernel.core_pattern=|/lib/systemd/systemd-coredump %P %u %g %s %t %c %e" > /etc/sysctl.d/50-coredump.conf
|
|
printf 'DefaultLimitCORE=infinity\n' >> /etc/systemd/system.conf
|
|
|
|
# HACK: we need to restart it in case aufs-dkms was installed after docker.io
|
|
# and thus docker.io auto-switches its backend
|
|
systemctl restart docker || journalctl -u docker
|
|
I=$(docker info)
|
|
if ! echo "$I" | grep -Eq 'Storage.*(aufs|overlay)'; then
|
|
echo "ERROR! docker does not use aufs or overlayfs"
|
|
exit 1
|
|
fi
|
|
|
|
# docker images that we need for integration testing
|
|
/var/lib/testvm/docker-images.setup
|
|
|
|
rm -rf /var/lib/docker/devicemapper
|
|
|
|
# in case there are unnecessary packages
|
|
eatmydata apt-get -y autoremove || true
|
|
|
|
# disable udev network names, our tests expect the kernel schema
|
|
sed -i '/GRUB_CMDLINE_LINUX=/ s/"$/ net.ifnames=0 biosdevname=0"/' /etc/default/grub
|
|
rm -f /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/75-cloud-ifupdown.rules
|
|
update-grub
|
|
sed -i 's/ens[^[:space:]:]*/eth0/' /etc/network/interfaces /etc/network/interfaces.d/* /etc/netplan/*.yaml || true
|
|
update-initramfs -u
|
|
|
|
|
|
# reduce image size
|
|
apt-get clean
|
|
pbuilder clean
|
|
rm -f /var/cache/apt/*cache.bin
|
|
/var/lib/testvm/zero-disk.setup
|
|
|
|
# Final tweaks
|
|
|
|
# Enable persistent journal
|
|
mkdir -p /var/log/journal
|
|
|
|
# Allow root login with password
|
|
sed -i 's/^[# ]*PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
|
|
|
|
# At least debian-9 virt-install image only has RSA key
|
|
[ -e /etc/ssh/ssh_host_ed25519_key ] || ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
|
|
[ -e /etc/ssh/ssh_host_ecdsa_key ] || ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa
|
|
|
|
# Prevent SSH from hanging for a long time when no external network access
|
|
echo 'UseDNS no' >> /etc/ssh/sshd_config
|
|
|
|
# HACK: https://bugzilla.mindrot.org/show_bug.cgi?id=2512
|
|
# Disable the restarting of sshd when networking changes
|
|
ln -snf /bin/true /etc/network/if-up.d/openssh-server
|
|
|
|
# Stop showing 'To run a command as administrator (user "root"), use "sudo <command>". See "man
|
|
# sudo_root" for details.` message in admins terminal.
|
|
touch /home/admin/.sudo_as_admin_successful
|