File indexing completed on 2024-04-28 05:02:35

0001 #!/usr/bin/env bash
0002 
0003 set -euo pipefail
0004 
0005 finalimagename=""
0006 
0007 TEMPDIR="$(mktemp --tmpdir -d "$(basename "${0/.sh}")"-XXXXX.d)"
0008 export TEMPDIR
0009 function cleanup_on_exit {
0010         rm -rf "${TEMPDIR}"
0011 }
0012 trap cleanup_on_exit EXIT
0013 
0014 function buildahsetx() {
0015         set -x
0016         buildah "${@}"
0017         exitcode=$?
0018         { set +x ; } 2>/dev/null
0019         return ${exitcode}
0020 }
0021 
0022 function podmansetx() {
0023         set -x
0024         podman "${@}"
0025         exitcode=$?
0026         { set +x ; } 2>/dev/null
0027         return ${exitcode}
0028 }
0029 
0030 function create_directories() {
0031         local id
0032         id=$1
0033 
0034         for d in source build xdg-config-home kbibtex-podman ; do
0035                 buildahsetx run --user root "${id}" -- mkdir -p "/tmp/${d}" || exit 1
0036         done
0037         for d in runtime cache config ; do
0038                 buildahsetx run --user root "${id}" -- mkdir -m 700 -p "/tmp/xdg-${d}-dir" || exit 1
0039         done
0040 }
0041 
0042 function set_environment() {
0043         buildahsetx config --env QT_PLUGIN_PATH=/usr/lib/qt/plugins --env QT_X11_NO_MITSHM=1 --env KDEDIRS=/usr --env XDG_RUNTIME_DIR=/tmp/xdg-runtime-dir --env XDG_CACHE_HOME=/tmp/xdg-cache-home --env XDG_CONFIG_HOME=/tmp/xdg-config-home --env XDG_DATA_DIRS=/usr/share --env XDG_DATA_HOME=/tmp/xdg-data-home --env XDG_CURRENT_DESKTOP=KDE "$1"
0044 }
0045 
0046 function create_user() {
0047         local id
0048         id=$1
0049         local username
0050         username="${2:-kdeuser}"
0051 
0052         echo "Creating user '${username}' in working container '${id}'"
0053 
0054         [[ "${username}" != "neon" ]] && buildahsetx run --user root "${id}" -- useradd --home-dir /tmp --no-log-init --no-create-home --shell /bin/bash --user-group "${username}"
0055         for d in source build xdg-config-home kbibtex-podman ; do
0056                 buildahsetx run --user root "${id}" -- chown -R "${username}:${username}" "/tmp/${d}" || exit 1
0057         done
0058         for d in runtime cache config ; do
0059                 buildahsetx run --user root "${id}" -- chown -R "${username}:${username}" "/tmp/xdg-${d}-dir" || exit 1
0060         done
0061 }
0062 
0063 function copy_config_files_to_image() {
0064         local id
0065         id=$1
0066         echo "Copying configuration files into working container '${id}'"
0067 
0068         cat <<EOF >"${TEMPDIR}/etc-fonts-local.conf"
0069 <?xml version='1.0' encoding='UTF-8'?>
0070 <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
0071 <fontconfig>
0072  <!-- Generic name aliasing -->
0073  <alias>
0074   <family>sans-serif</family>
0075   <prefer>
0076    <family>IBM Plex Sans</family>
0077   </prefer>
0078  </alias>
0079  <alias>
0080   <family>serif</family>
0081   <prefer>
0082    <family>IBM Plex Serif</family>
0083   </prefer>
0084  </alias>
0085  <alias>
0086   <family>monospace</family>
0087   <prefer>
0088    <family>IBM Plex Mono</family>
0089   </prefer>
0090  </alias>
0091 </fontconfig>
0092 EOF
0093         buildahsetx copy "${id}" "${TEMPDIR}/etc-fonts-local.conf" /etc/fonts/local.conf || exit 1
0094 
0095         # Make KDE use double-click
0096         cat <<EOF >"${TEMPDIR}/kbibtex-kdeglobals"
0097 [General]
0098 ColorScheme=Breeze
0099 Name=Breeze
0100 widgetStyle=Breeze
0101 
0102 [Icons]
0103 Theme=breeze
0104 
0105 [KDE]
0106 SingleClick=false
0107 ColorScheme=Breeze
0108 LookAndFeelPackage=org.kde.breeze.desktop
0109 widgetStyle=breeze
0110 EOF
0111         buildahsetx copy "${id}" "${TEMPDIR}/kbibtex-kdeglobals" /tmp/xdg-config-home/kdeglobals || exit 1
0112 }
0113 
0114 
0115 function create_ubuntu_ddebslist() {
0116         local CODENAME
0117         CODENAME="$1"
0118 
0119         {
0120                 echo "deb http://ddebs.ubuntu.com ${CODENAME} main restricted universe multiverse"
0121                 echo "deb http://ddebs.ubuntu.com ${CODENAME}-updates main restricted universe multiverse"
0122                 echo "deb http://ddebs.ubuntu.com ${CODENAME}-proposed main restricted universe multiverse"
0123         } >"${TEMPDIR}/ddebs.list"
0124 }
0125 
0126 
0127 function build_archlinux() {
0128         local FROMIMAGE
0129         FROMIMAGE="docker://archlinux:latest"
0130         local IMAGENAME
0131         IMAGENAME="archlinux-kde-devel"
0132         local WORKINGCONTAINERNAME
0133         WORKINGCONTAINERNAME="working-$(sed -r 's!docker://!!g;s![^a-z0-9.-]+!-!g' <<<"${FROMIMAGE}")"
0134 
0135         # Remove any residual images of the same name, ignore errors such as if no such image
0136         buildah rm "${WORKINGCONTAINERNAME}" 2>/dev/null >&2
0137         podman rmi -f "${IMAGENAME}" 2>/dev/null >&2
0138 
0139         # Pull base image from remote repository
0140         id=$(buildahsetx from --name "${WORKINGCONTAINERNAME}" "${FROMIMAGE}") || exit 1
0141         [[ -n "${id}" ]] || { echo "ID is empty" >&2 ; exit 1 ; }
0142         echo "Using ID ${id} for '${IMAGENAME}'"
0143 
0144         create_directories "${id}"
0145         set_environment "${id}"
0146 
0147         # DISTRIBUTION-SPECIFIC CODE BEGINS HERE
0148         buildahsetx run --user root "${id}" -- pacman -Syu --noconfirm || exit 1
0149         # TODO install BibUtils
0150         buildahsetx run --user root "${id}" -- pacman -S --noconfirm cmake gcc make extra-cmake-modules poppler-qt5 qt5-xmlpatterns qt5-networkauth qt5-webengine ki18n kxmlgui kio kiconthemes kparts kcoreaddons kservice kwallet kcrash kdoctools ktexteditor breeze-icons frameworkintegration gdb xdg-desktop-portal-kde git gettext ttf-ibm-plex sudo okular appstream || exit 1
0151         buildahsetx run --user root "${id}" -- rm -f /var/cache/pacman/pkg/*.pkg* || exit 1
0152         # DISTRIBUTION-SPECIFIC CODE ENDS HERE
0153 
0154         copy_config_files_to_image "${id}" || exit 1
0155         create_user "${id}" || exit 1
0156 
0157         buildahsetx commit "${id}" "${IMAGENAME}" 2>&1 | tee "${TEMPDIR}/buildah-commit-output.txt" || exit 1
0158         buildahcommitlastline="$(tail -n 1 <"${TEMPDIR}/buildah-commit-output.txt")"
0159         grep -qP '^[0-9a-f]{24,96}$' <<<"${buildahcommitlastline}" && finalimagename="${buildahcommitlastline}"
0160 
0161         return 0
0162 }
0163 
0164 
0165 function build_debian10() {
0166         local FROMIMAGE
0167         FROMIMAGE="docker://debian:buster"
0168         local IMAGENAME
0169         IMAGENAME="debian10-kde-devel"
0170         local WORKINGCONTAINERNAME
0171         WORKINGCONTAINERNAME="working-$(sed -r 's!docker://!!g;s![^a-z0-9.-]+!-!g' <<<"${FROMIMAGE}")"
0172 
0173         # Remove any residual images of the same name, ignore errors such as if no such image
0174         buildah rm "${WORKINGCONTAINERNAME}" 2>/dev/null >&2
0175         podman rmi -f "${IMAGENAME}" 2>/dev/null >&2
0176 
0177         # Pull base image from remote repository
0178         id=$(buildahsetx from --name "${WORKINGCONTAINERNAME}" "${FROMIMAGE}") || exit 1
0179         [[ -n "${id}" ]] || { echo "ID is empty" >&2 ; exit 1 ; }
0180         echo "Using ID ${id} for '${IMAGENAME}'"
0181 
0182         create_directories "${id}"
0183         set_environment "${id}"
0184 
0185         # DISTRIBUTION-SPECIFIC CODE BEGINS HERE
0186         echo "deb http://ftp.se.debian.org/debian/ buster main contrib" >"${TEMPDIR}/etc-apt-sources.list"
0187         buildahsetx copy "${id}" "${TEMPDIR}/etc-apt-sources.list" /etc/apt/sources.list || exit 1
0188         buildahsetx run --user root "${id}" -- apt update || exit 1
0189         buildahsetx run --user root "${id}" -- apt dist-upgrade -y || exit 1
0190         # TODO install BibUtils
0191         buildahsetx run --user root "${id}" -- apt install -y sudo fonts-ibm-plex cmake g++ make extra-cmake-modules libicu-dev libpoppler-qt5-dev libqt5xmlpatterns5-dev libqt5networkauth5-dev libqt5webenginewidgets5 qtwebengine5-dev libqt5webchannel5-dev libkf5i18n-dev libkf5xmlgui-dev libkf5kio-dev libkf5iconthemes-dev libkf5parts-dev libkf5coreaddons-dev libkf5service-dev libkf5wallet-dev libkf5crash-dev libkf5doctools-dev libkf5texteditor-dev breeze-icon-theme kde-style-breeze frameworkintegration gdb xdg-desktop-portal-kde git gettext okular appstream || exit 1
0192         buildahsetx run --user root "${id}" -- apt -y clean || exit 1
0193         # DISTRIBUTION-SPECIFIC CODE ENDS HERE
0194 
0195         copy_config_files_to_image "${id}" || exit 1
0196         create_user "${id}" || exit 1
0197 
0198         buildahsetx commit "${id}" "${IMAGENAME}" 2>&1 | tee "${TEMPDIR}/buildah-commit-output.txt" || exit 1
0199         buildahcommitlastline="$(tail -n 1 <"${TEMPDIR}/buildah-commit-output.txt")"
0200         grep -qP '^[0-9a-f]{24,96}$' <<<"${buildahcommitlastline}" && finalimagename="${buildahcommitlastline}"
0201 
0202         return 0
0203 }
0204 
0205 
0206 function build_debian11() {
0207         local FROMIMAGE
0208         FROMIMAGE="docker://debian:bullseye"
0209         local IMAGENAME
0210         IMAGENAME="debian11-kde-devel"
0211         local WORKINGCONTAINERNAME
0212         WORKINGCONTAINERNAME="working-$(sed -r 's!docker://!!g;s![^a-z0-9.-]+!-!g' <<<"${FROMIMAGE}")"
0213 
0214         # Remove any residual images of the same name, ignore errors such as if no such image
0215         buildah rm "${WORKINGCONTAINERNAME}" 2>/dev/null >&2
0216         podman rmi -f "${IMAGENAME}" 2>/dev/null >&2
0217 
0218         # Pull base image from remote repository
0219         id=$(buildahsetx from --name "${WORKINGCONTAINERNAME}" "${FROMIMAGE}") || exit 1
0220         [[ -n "${id}" ]] || { echo "ID is empty" >&2 ; exit 1 ; }
0221         echo "Using ID ${id} for '${IMAGENAME}'"
0222 
0223         create_directories "${id}"
0224         set_environment "${id}"
0225 
0226         # DISTRIBUTION-SPECIFIC CODE BEGINS HERE
0227         echo "deb http://ftp.se.debian.org/debian/ bullseye main contrib" >"${TEMPDIR}/etc-apt-sources.list"
0228         buildahsetx copy "${id}" "${TEMPDIR}/etc-apt-sources.list" /etc/apt/sources.list || exit 1
0229         buildahsetx run --user root "${id}" -- apt update || exit 1
0230         buildahsetx run --user root "${id}" -- apt -y full-upgrade || exit 1
0231         # TODO install BibUtils
0232         buildahsetx run --user root "${id}" -- apt install -y sudo fonts-ibm-plex cmake g++ make extra-cmake-modules libicu-dev libpoppler-qt5-dev libqt5xmlpatterns5-dev libqt5networkauth5-dev libqt5webenginewidgets5 qtwebengine5-dev libqt5webchannel5-dev libkf5i18n-dev libkf5xmlgui-dev libkf5kio-dev libkf5iconthemes-dev libkf5parts-dev libkf5coreaddons-dev libkf5service-dev libkf5wallet-dev libkf5crash-dev libkf5doctools-dev libkf5texteditor-dev breeze-icon-theme kde-style-breeze frameworkintegration gdb xdg-desktop-portal-kde git gettext okular appstream || exit 1
0233         buildahsetx run --user root "${id}" -- apt -y clean || exit 1
0234         # DISTRIBUTION-SPECIFIC CODE ENDS HERE
0235 
0236         copy_config_files_to_image "${id}" || exit 1
0237         create_user "${id}" || exit 1
0238 
0239         buildahsetx commit "${id}" "${IMAGENAME}" 2>&1 | tee "${TEMPDIR}/buildah-commit-output.txt" || exit 1
0240         buildahcommitlastline="$(tail -n 1 <"${TEMPDIR}/buildah-commit-output.txt")"
0241         grep -qP '^[0-9a-f]{24,96}$' <<<"${buildahcommitlastline}" && finalimagename="${buildahcommitlastline}"
0242 
0243         return 0
0244 }
0245 
0246 
0247 function build_debian12() {
0248         local FROMIMAGE
0249         FROMIMAGE="docker://debian:bookworm"
0250         local IMAGENAME
0251         IMAGENAME="debian12-kde-devel"
0252         local WORKINGCONTAINERNAME
0253         WORKINGCONTAINERNAME="working-$(sed -r 's!docker://!!g;s![^a-z0-9.-]+!-!g' <<<"${FROMIMAGE}")"
0254 
0255         # Remove any residual images of the same name, ignore errors such as if no such image
0256         buildahsetx rm "${WORKINGCONTAINERNAME}" 2>/dev/null >&2
0257         podmansetx rmi -f "${IMAGENAME}" 2>/dev/null >&2
0258 
0259         # Pull base image from remote repository
0260         id=$(buildahsetx from --name "${WORKINGCONTAINERNAME}" "${FROMIMAGE}") || exit 1
0261         [[ -n "${id}" ]] || { echo "ID is empty" >&2 ; exit 1 ; }
0262         echo "Using ID ${id} for '${IMAGENAME}'"
0263 
0264         create_directories "${id}"
0265         set_environment "${id}"
0266 
0267         # DISTRIBUTION-SPECIFIC CODE BEGINS HERE
0268         echo "deb http://ftp.se.debian.org/debian/ bookworm main contrib" >"${TEMPDIR}/etc-apt-sources.list"
0269         buildahsetx copy "${id}" "${TEMPDIR}/etc-apt-sources.list" /etc/apt/sources.list || exit 1
0270         buildahsetx run --user root "${id}" -- apt update || exit 1
0271         buildahsetx run --user root "${id}" -- apt -y full-upgrade || exit 1
0272         # TODO install BibUtils
0273         buildahsetx run --user root "${id}" -- apt install -y sudo fonts-ibm-plex cmake g++ make extra-cmake-modules libicu-dev libpoppler-qt5-dev libqt5xmlpatterns5-dev libqt5networkauth5-dev libqt5webenginewidgets5 qtwebengine5-dev libqt5webchannel5-dev libkf5i18n-dev libkf5xmlgui-dev libkf5kio-dev libkf5iconthemes-dev libkf5parts-dev libkf5coreaddons-dev libkf5service-dev libkf5wallet-dev libkf5crash-dev libkf5doctools-dev libkf5texteditor-dev breeze-icon-theme kde-style-breeze frameworkintegration gdb xdg-desktop-portal-kde git gettext okular appstream || exit 1
0274         buildahsetx run --user root "${id}" -- apt -y clean || exit 1
0275         # DISTRIBUTION-SPECIFIC CODE ENDS HERE
0276 
0277         copy_config_files_to_image "${id}" || exit 1
0278         create_user "${id}" || exit 1
0279 
0280         buildahsetx commit "${id}" "${IMAGENAME}" 2>&1 | tee "${TEMPDIR}/buildah-commit-output.txt" || exit 1
0281         buildahcommitlastline="$(tail -n 1 <"${TEMPDIR}/buildah-commit-output.txt")"
0282         grep -qP '^[0-9a-f]{24,96}$' <<<"${buildahcommitlastline}" && finalimagename="${buildahcommitlastline}"
0283 
0284         return 0
0285 }
0286 
0287 
0288 function build_kdeneon() {
0289         local FROMIMAGE
0290         FROMIMAGE="invent-registry.kde.org/neon/docker-images/plasma:unstable"
0291         local IMAGENAME
0292         IMAGENAME="kdeneon-kde-devel"
0293         local WORKINGCONTAINERNAME
0294         WORKINGCONTAINERNAME="working-$(sed -r 's!docker://!!g;s![^a-z0-9.-]+!-!g' <<<"${FROMIMAGE}")"
0295 
0296         # Remove any residual images of the same name, ignore errors such as if no such image
0297         buildah rm "${WORKINGCONTAINERNAME}" #2>/dev/null >&2
0298         podman rmi -f "${IMAGENAME}" 2>/dev/null >&2
0299 
0300         # Pull base image from remote repository
0301         id=$(buildahsetx from --name "${WORKINGCONTAINERNAME}" "${FROMIMAGE}") || exit 1
0302         [[ -n "${id}" ]] || { echo "ID is empty" >&2 ; exit 1 ; }
0303         echo "Using ID ${id} for '${IMAGENAME}'"
0304 
0305         create_directories "${id}"
0306         set_environment "${id}"
0307 
0308         # DISTRIBUTION-SPECIFIC CODE BEGINS HERE
0309         buildahsetx run --user root "${id}" -- apt install -y ubuntu-dbgsym-keyring || exit 1
0310         buildahsetx run --user root "${id}" -- apt update || exit 1
0311         buildahsetx run --user root "${id}" -- apt -y full-upgrade || exit 1
0312         # TODO install BibUtils
0313         buildahsetx run --user root "${id}" -- apt -y install sudo fonts-ibm-plex cmake g++ make libicu-dev qt6-networkauth-dev qt6-webengine-dev libpoppler-qt6-dev qt6-base-dev-tools kf6-syntax-highlighting-dev kf6-extra-cmake-modules kf6-syntax-highlighting-dev kf6-ki18n-dev kf6-kxmlgui-dev kf6-kiconthemes-dev kf6-kparts-dev kf6-kcoreaddons-dev kf6-kservice-dev kf6-ktextwidgets-dev kf6-kwallet-dev kf6-kcrash-dev kf6-kdoctools-dev kf6-ktexteditor-dev kf6-breeze-icon-theme gdb valgrind git gettext || exit 1
0314         buildahsetx run --user root "${id}" -- apt -y clean || exit 1
0315         # DISTRIBUTION-SPECIFIC CODE ENDS HERE
0316 
0317         copy_config_files_to_image "${id}" || exit 1
0318         create_user "${id}" neon || exit 1
0319 
0320         buildahsetx commit "${id}" "${IMAGENAME}" 2>&1 | tee "${TEMPDIR}/buildah-commit-output.txt" || exit 1
0321         buildahcommitlastline="$(tail -n 1 <"${TEMPDIR}/buildah-commit-output.txt")"
0322         grep -qP '^[0-9a-f]{24,96}$' <<<"${buildahcommitlastline}" && finalimagename="${buildahcommitlastline}"
0323 
0324         return 0
0325 }
0326 
0327 
0328 function build_fedora() {
0329         local variant="${1:-latest}"
0330         local FROMIMAGE
0331         FROMIMAGE="docker://fedora:${variant}"
0332         local IMAGENAME
0333         IMAGENAME="fedora-${variant}-kde-devel"
0334         local WORKINGCONTAINERNAME
0335         WORKINGCONTAINERNAME="working-$(sed -r 's!docker://!!g;s![^a-z0-9.-]+!-!g' <<<"${FROMIMAGE}")"
0336 
0337         # Remove any residual images of the same name, ignore errors such as if no such image
0338         buildah rm "${WORKINGCONTAINERNAME}" 2>/dev/null >&2
0339         podman rmi -f "${IMAGENAME}" 2>/dev/null >&2
0340 
0341         # Pull base image from remote repository
0342         id=$(buildahsetx from --name "${WORKINGCONTAINERNAME}" "${FROMIMAGE}") || exit 1
0343         [[ -n "${id}" ]] || { echo "ID is empty" >&2 ; exit 1 ; }
0344         echo "Using ID ${id} for '${IMAGENAME}'"
0345 
0346         create_directories "${id}"
0347         set_environment "${id}"
0348 
0349         # DISTRIBUTION-SPECIFIC CODE BEGINS HERE
0350         # TODO install BibUtils
0351         buildahsetx run --user root "${id}" -- dnf install -y cmake g++ make extra-cmake-modules libicu-devel poppler-qt5-devel qt5-qtxmlpatterns-devel qt5-qtnetworkauth-devel qt5-qtwebengine-devel kf5-ki18n-devel kf5-kxmlgui-devel kf5-kio-devel kf5-kiconthemes-devel kf5-kparts-devel kf5-kcoreaddons-devel kf5-kservice-devel kf5-kwallet-devel kf5-kcrash-devel kf5-kdoctools-devel kf5-ktexteditor-devel breeze-icon-theme kf5-frameworkintegration gdb xdg-desktop-portal-kde git gettext okular appstream bison libevent-devel openssl-devel libretls-devel || exit 1
0352         # DISTRIBUTION-SPECIFIC CODE ENDS HERE
0353 
0354         copy_config_files_to_image "${id}" || exit 1
0355         create_user "${id}" || exit 1
0356 
0357         buildahsetx commit "${id}" "${IMAGENAME}" 2>&1 | tee "${TEMPDIR}/buildah-commit-output.txt" || exit 1
0358         buildahcommitlastline="$(tail -n 1 <"${TEMPDIR}/buildah-commit-output.txt")"
0359         grep -qP '^[0-9a-f]{24,96}$' <<<"${buildahcommitlastline}" && finalimagename="${buildahcommitlastline}"
0360 
0361         return 0
0362 }
0363 
0364 
0365 function build_ubuntu2204() {
0366         local FROMIMAGE
0367         FROMIMAGE="docker://ubuntu:22.04"
0368         local IMAGENAME
0369         IMAGENAME="ubuntu2204-kde-devel"
0370         local WORKINGCONTAINERNAME
0371         WORKINGCONTAINERNAME="working-$(sed -r 's!docker://!!g;s![^a-z0-9.-]+!-!g' <<<"${FROMIMAGE}")"
0372 
0373         # Remove any residual images of the same name, ignore errors such as if no such image
0374         buildahsetx rm "${WORKINGCONTAINERNAME}" 2>/dev/null >&2
0375         podmansetx rmi -f "${IMAGENAME}" 2>/dev/null >&2
0376 
0377         # Pull base image from remote repository
0378         id=$(buildahsetx from --name "${WORKINGCONTAINERNAME}" "${FROMIMAGE}") || exit 1
0379         [[ -n "${id}" ]] || { echo "ID is empty" >&2 ; exit 1 ; }
0380         echo "Using ID ${id} for '${IMAGENAME}'"
0381 
0382         create_directories "${id}"
0383         set_environment "${id}"
0384 
0385         # DISTRIBUTION-SPECIFIC CODE BEGINS HERE
0386         export TZ="Europe/Berlin"
0387         buildahsetx config --user root --env TZ="${TZ}" "${id}"
0388         echo "${TZ}" >"${TEMPDIR}/timezone"
0389         buildahsetx copy "${id}" "${TEMPDIR}/timezone" /etc/timezone || exit 1
0390         buildahsetx run --user root "${id}" -- ln -snf /usr/share/zoneinfo/"${TZ}" /etc/localtime || exit 1
0391         buildahsetx run --user root "${id}" -- apt update || exit 1
0392         create_ubuntu_ddebslist jammy
0393         buildahsetx copy "${id}" "${TEMPDIR}/ddebs.list" /etc/apt/sources.list.d/ddebs.list || exit 1
0394         buildahsetx run --user root "${id}" -- apt install -y ubuntu-dbgsym-keyring || exit 1
0395         buildahsetx run --user root "${id}" -- apt update || exit 1
0396         buildahsetx run --user root "${id}" -- apt -y full-upgrade || exit 1
0397         # TODO install BibUtils
0398         buildahsetx run --user root "${id}" -- apt install -y sudo fonts-ibm-plex cmake g++ make extra-cmake-modules libicu-dev libpoppler-qt5-dev libqt5xmlpatterns5-dev libqt5networkauth5-dev libqt5webenginewidgets5 qtwebengine5-dev libqt5webchannel5-dev libkf5i18n-dev libkf5xmlgui-dev libkf5kio-dev libkf5iconthemes-dev libkf5parts-dev libkf5coreaddons-dev libkf5service-dev libkf5wallet-dev libkf5crash-dev libkf5doctools-dev libkf5texteditor-dev breeze-icon-theme kde-style-breeze frameworkintegration gdb valgrind xdg-desktop-portal-kde git gettext okular appstream || exit 1
0399         buildahsetx run --user root "${id}" -- apt -y clean || exit 1
0400         # DISTRIBUTION-SPECIFIC CODE ENDS HERE
0401 
0402         copy_config_files_to_image "${id}" || exit 1
0403         create_user "${id}" || exit 1
0404 
0405         buildahsetx commit "${id}" "${IMAGENAME}" 2>&1 | tee "${TEMPDIR}/buildah-commit-output.txt" || exit 1
0406         buildahcommitlastline="$(tail -n 1 <"${TEMPDIR}/buildah-commit-output.txt")"
0407         grep -qP '^[0-9a-f]{24,96}$' <<<"${buildahcommitlastline}" && finalimagename="${buildahcommitlastline}"
0408 
0409         return 0
0410 }
0411 
0412 
0413 function build_ubuntu2210() {
0414         local FROMIMAGE
0415         FROMIMAGE="docker://ubuntu:22.10"
0416         local IMAGENAME
0417         IMAGENAME="ubuntu2210-kde-devel"
0418         local WORKINGCONTAINERNAME
0419         WORKINGCONTAINERNAME="working-$(sed -r 's!docker://!!g;s![^a-z0-9.-]+!-!g' <<<"${FROMIMAGE}")"
0420 
0421         # Remove any residual images of the same name, ignore errors such as if no such image
0422         buildahsetx rm "${WORKINGCONTAINERNAME}" 2>/dev/null >&2
0423         podmansetx rmi -f "${IMAGENAME}" 2>/dev/null >&2
0424 
0425         # Pull base image from remote repository
0426         id=$(buildahsetx from --name "${WORKINGCONTAINERNAME}" "${FROMIMAGE}") || exit 1
0427         [[ -n "${id}" ]] || { echo "ID is empty" >&2 ; exit 1 ; }
0428         echo "Using ID ${id} for '${IMAGENAME}'"
0429 
0430         create_directories "${id}"
0431         set_environment "${id}"
0432 
0433         # DISTRIBUTION-SPECIFIC CODE BEGINS HERE
0434         export TZ="Europe/Berlin"
0435         buildahsetx config --user root --env TZ="${TZ}" "${id}"
0436         echo "${TZ}" >"${TEMPDIR}/timezone"
0437         buildahsetx copy "${id}" "${TEMPDIR}/timezone" /etc/timezone || exit 1
0438         buildahsetx run --user root "${id}" -- ln -snf /usr/share/zoneinfo/"${TZ}" /etc/localtime || exit 1
0439         buildahsetx run --user root "${id}" -- apt update || exit 1
0440         create_ubuntu_ddebslist kinetic
0441         buildahsetx copy "${id}" "${TEMPDIR}/ddebs.list" /etc/apt/sources.list.d/ddebs.list || exit 1
0442         buildahsetx run --user root "${id}" -- apt install -y ubuntu-dbgsym-keyring || exit 1
0443         buildahsetx run --user root "${id}" -- apt update || exit 1
0444         buildahsetx run --user root "${id}" -- apt -y full-upgrade || exit 1
0445         # TODO install BibUtils
0446         buildahsetx run --user root "${id}" -- apt install -y sudo fonts-ibm-plex cmake g++ make extra-cmake-modules libicu-dev libpoppler-qt5-dev libqt5xmlpatterns5-dev libqt5networkauth5-dev libqt5webenginewidgets5 qtwebengine5-dev libqt5webchannel5-dev libkf5i18n-dev libkf5xmlgui-dev libkf5kio-dev libkf5iconthemes-dev libkf5parts-dev libkf5coreaddons-dev libkf5service-dev libkf5wallet-dev libkf5crash-dev libkf5doctools-dev libkf5texteditor-dev breeze-icon-theme kde-style-breeze frameworkintegration gdb valgrind xdg-desktop-portal-kde git gettext okular appstream || exit 1
0447         buildahsetx run --user root "${id}" -- apt -y clean || exit 1
0448         # DISTRIBUTION-SPECIFIC CODE ENDS HERE
0449 
0450         copy_config_files_to_image "${id}" || exit 1
0451         create_user "${id}" || exit 1
0452 
0453         buildahsetx commit "${id}" "${IMAGENAME}" 2>&1 | tee "${TEMPDIR}/buildah-commit-output.txt" || exit 1
0454         buildahcommitlastline="$(tail -n 1 <"${TEMPDIR}/buildah-commit-output.txt")"
0455         grep -qP '^[0-9a-f]{24,96}$' <<<"${buildahcommitlastline}" && finalimagename="${buildahcommitlastline}"
0456 
0457         return 0
0458 }
0459 
0460 
0461 if (( $# == 1 )) ; then
0462         if [[ $1 == "--cleanup" ]] ; then
0463                 buildahsetx images -f dangling=true
0464                 echo "!!! Remove any with  podman rmi -f IMAGE-HEX"
0465                 echo
0466                 podmansetx image ls
0467                 echo "!!! Remove any with  podman rmi -f IMAGE-HEX"
0468                 echo
0469                 podmansetx container ls
0470                 echo "!!! Remove any with  buildah rm CONTAINER-HEX"
0471                 echo
0472                 buildahsetx containers
0473                 echo "!!! Remove any with  buildah rm CONTAINER-HEX"
0474                 exit 0
0475         elif [[ $1 == "archlinux" ]] ; then
0476                 build_archlinux || exit 1
0477         elif [[ $1 == "debian10" || $1 == "buster" ]] ; then
0478                 build_debian10 || exit 1
0479         elif [[ $1 == "debian11" || $1 == "bullseye" ]] ; then
0480                 build_debian11 || exit 1
0481         elif [[ $1 == "debian12" || $1 == "bookworm" ]] ; then
0482                 build_debian12 || exit 1
0483         elif [[ $1 == "fedora" ]] ; then
0484                 build_fedora latest || exit 1
0485         elif [[ $1 == "fedora3"* || $1 == "fedora4"* ]] ; then
0486                 build_fedora "${1:6}" || exit 1
0487         elif [[ $1 == "ubuntu2204" ]] ; then
0488                 build_ubuntu2204 || exit 1
0489         elif [[ $1 == "ubuntu"* ]] ; then
0490                 build_ubuntu2210 || exit 1
0491         elif [[ $1 == "kdeneon" ]] ; then
0492                 build_kdeneon || exit 1
0493         else
0494                 echo "Unknown argument, expecting one of the following:  archlinux  debian10  debian11  debian12  fedora  fedora36  fedora37  fedora38  ubuntu2204  ubuntu2210  kdeneon" >&2
0495                 echo "To get help how to clean up previously created images or containers, run  $(basename "$0") --cleanup" >&2
0496                 exit 1
0497         fi
0498 else
0499         echo "Missing argument, expecting one of the following:  archlinux  debian10  debian11  debian12  fedora  fedora36  fedora37  fedora38  ubuntu2204  ubuntu2210  kdeneon" >&2
0500         echo "To get help how to clean up previously created images or containers, run  $(basename "$0") --cleanup" >&2
0501         exit 1
0502 fi
0503 
0504 if [[ -n "${finalimagename}" ]] ; then
0505         echo "-------------------------------------------------------------------------------"
0506         echo "To run a container with just Bash, issue:"
0507         echo "  podman container run --rm --net=host --tty --interactive ${finalimagename} /bin/bash"
0508         echo "-------------------------------------------------------------------------------"
0509 fi