#!/bin/sh# image-customize script to prepare a bots VM for testing cockpit# The cockpit packages will be installed separatelyset -euif type firewall-cmd >/dev/null 2>&1; thenfirewall-cmd --add-service=cockpit --permanentfi. /usr/lib/os-release# our tests expect cockpit.socket to not be running after boot, only after start_cockpit()# socket isn't present on CoreOS or with cockpit/ws scenarioHAVE_COCKPIT_SOCKET=if [ -n "$(systemctl --no-legend list-unit-files cockpit.socket || true)" ]; thenHAVE_COCKPIT_SOCKET=1fiif [ -n "$HAVE_COCKPIT_SOCKET" ]; thensystemctl disable cockpit.socketfi# OS specific hacksif [ "$ID" = "debian" ] || [ "$ID" = "ubuntu" ]; then# avoid random dpkg database locks, they break our package related testssystemctl disable apt-daily-upgrade.timer# takes a lot of memory and does not have a chance of working anywaysystemctl disable apt-listchanges.timer || true# create public firewalld zone for our firewall testssystemctl start firewalldfirewall-cmd --zone=public --permanent --add-interface=eth1# disarm 10-cloudimg-settings.confsed -i '/.*PasswordAuthentication no/d' /etc/ssh/sshd_config $(ls /etc/ssh/sshd_config.d/* 2>/dev/null || true)fiif [ "$ID" = "debian" ]; then# make libpwquality less aggressive, so that our "foobar" password worksprintf 'dictcheck = 0\nminlen = 6\n' >> /etc/security/pwquality.conf# Allow libvirtd coredumpsecho '* soft core unlimited' >> /etc/security/limits.conffiif [ "$ID" = "opensuse-tumbleweed" ]; then# Zypper will take forever to work out these don't have net access# Let's lo themecho "127.0.1.1 download.opensuse.org" >> /etc/hostsecho "127.0.1.1 codecs.opensuse.org" >> /etc/hostsfiif [ "$ID" = "ubuntu" ] && [ "$VERSION_ID" = "26.04" ]; then# HACK: https://launchpad.net/bugs/2151857echo '/usr/share/coreutils/locales/** r,' > /etc/apparmor.d/local/whofiPLATFORM_ID="${PLATFORM_ID:-}"if [ "${PLATFORM_ID#platform:el}" != "$PLATFORM_ID" ]; then# allow /usr/local/bin/ in sudo shells, to use our installed tools like the Python bridge# Fedora, Debian etc. do thatecho 'Defaults secure_path = /sbin:/usr/sbin:/usr/local/bin:/bin:/usr/bin' > /etc/sudoers.d/usr-localfi# HACK: unbreak subuid assignment for current and new users; see# https://bugzilla.redhat.com/show_bug.cgi?id=2382662# https://issues.redhat.com/browse/RHEL-103765if [ -e /etc/login.defs ]; thensed -i '/^SUB_.ID_COUNT/ s/\b0/65536/' /etc/login.defsfiif ! grep -q admin /etc/subuid; thenusermod --add-subuids 100000-165535 adminusermod --add-subgids 100000-165535 adminfi# start cockpit once to ensure it works, and generate the certificate (to avoid re-doing that for each test)if [ -n "$HAVE_COCKPIT_SOCKET" ]; thensystemctl start cockpitsystemctl stop cockpitfi# clean out the journaljournalctl --flushjournalctl --sync || killall systemd-journaldrm -rf /var/log/journal/*rm -rf /var/lib/NetworkManager/dhclient-*.lease