|
| 1 | +#!/bin/bash |
| 2 | +set -exuo pipefail |
| 3 | + |
| 4 | +if [ "$TMT_REBOOT_COUNT" -eq 0 ]; then |
| 5 | + ARCH=$(uname -m) |
| 6 | + TEMPDIR=$(mktemp -d) |
| 7 | + trap 'rm -rf -- "$TEMPDIR"' EXIT |
| 8 | + |
| 9 | + # Get OS data. |
| 10 | + source /etc/os-release |
| 11 | + case ""${ID}-${VERSION_ID}"" in |
| 12 | + "centos-9") |
| 13 | + TIER1_IMAGE_URL="quay.io/centos-bootc/centos-bootc:stream9" |
| 14 | + BOOTC_COPR_REPO_DISTRO="centos-stream-9-${ARCH}" |
| 15 | + ;; |
| 16 | + "centos-10") |
| 17 | + TIER1_IMAGE_URL="quay.io/centos-bootc/centos-bootc:stream10" |
| 18 | + BOOTC_COPR_REPO_DISTRO="centos-stream-10-${ARCH}" |
| 19 | + ;; |
| 20 | + "fedora-"*) |
| 21 | + TIER1_IMAGE_URL="quay.io/fedora/fedora-bootc:${VERSION_ID}" |
| 22 | + BOOTC_COPR_REPO_DISTRO="fedora-${VERSION_ID}-${ARCH}" |
| 23 | + ;; |
| 24 | + *) |
| 25 | + echo "Don't work with this distro" |
| 26 | + exit 1 |
| 27 | + ;; |
| 28 | + esac |
| 29 | + |
| 30 | + ls -al /root/.ssh |
| 31 | + cat /root/.ssh/authorized_keys |
| 32 | + cp -r /root/.ssh "$TEMPDIR" |
| 33 | + |
| 34 | + if [[ "$VERSION_ID" == "43" ]]; then |
| 35 | + BOOTC_COPR_REPO_DISTRO="fedora-rawhide-${ARCH}" |
| 36 | + fi |
| 37 | + |
| 38 | + CONTAINERFILE=${TEMPDIR}/Containerfile |
| 39 | + tee "$CONTAINERFILE" > /dev/null << REALEOF |
| 40 | +FROM $TIER1_IMAGE_URL |
| 41 | +
|
| 42 | +RUN <<EORUN |
| 43 | +set -xeuo pipefail |
| 44 | +
|
| 45 | +mkdir -p -m 0700 /var/roothome |
| 46 | +
|
| 47 | +cat <<EOF >> /etc/yum.repos.d/bootc.repo |
| 48 | +[bootc] |
| 49 | +name=bootc |
| 50 | +baseurl=https://download.copr.fedorainfracloud.org/results/rhcontainerbot/bootc/${BOOTC_COPR_REPO_DISTRO}/ |
| 51 | +enabled=1 |
| 52 | +gpgcheck=0 |
| 53 | +repo_gpgcheck=0 |
| 54 | +EOF |
| 55 | +
|
| 56 | +dnf -y update bootc |
| 57 | +dnf -y install cloud-init rsync |
| 58 | +ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants |
| 59 | +dnf -y clean all |
| 60 | +rm -rf /var/cache /var/lib/dnf |
| 61 | +EORUN |
| 62 | +COPY .ssh /var/roothome/.ssh |
| 63 | +REALEOF |
| 64 | + |
| 65 | + cat "$CONTAINERFILE" |
| 66 | + sudo podman build --tls-verify=false -t localhost/bootc:tmt -f "$CONTAINERFILE" "$TEMPDIR" |
| 67 | + sudo podman images |
| 68 | + sudo podman run \ |
| 69 | + --rm \ |
| 70 | + --tls-verify=false \ |
| 71 | + --privileged \ |
| 72 | + --pid=host \ |
| 73 | + -v /:/target \ |
| 74 | + -v /dev:/dev \ |
| 75 | + -v /var/lib/containers:/var/lib/containers \ |
| 76 | + -v /root/.ssh:/output \ |
| 77 | + --security-opt label=type:unconfined_t \ |
| 78 | + "localhost/bootc:tmt" \ |
| 79 | + bootc install to-existing-root --target-transport containers-storage |
| 80 | + |
| 81 | + tmt-reboot |
| 82 | +elif [ "$TMT_REBOOT_COUNT" -eq 1 ]; then |
| 83 | + bootc status |
| 84 | + echo "bootc install to-existing-root succeed" |
| 85 | + exit 0 |
| 86 | +fi |
0 commit comments