|
41 | 41 | mkdir -p "$(dirname "$SUDO_BIN")" |
42 | 42 | cat > "$SUDO_BIN" <<'WRAPPER' |
43 | 43 | #!/bin/sh |
44 | | - exec distrobox-host-exec podman exec -it -u root "$CONTAINER_ID" "$@" |
| 44 | + # Use whichever container runtime distrobox picked (podman or docker). |
| 45 | + RUNTIME="''${DBX_CONTAINER_MANAGER:-}" |
| 46 | + if [ -z "$RUNTIME" ]; then |
| 47 | + if command -v podman >/dev/null 2>&1; then |
| 48 | + RUNTIME=podman |
| 49 | + elif command -v docker >/dev/null 2>&1; then |
| 50 | + RUNTIME=docker |
| 51 | + else |
| 52 | + echo "sudo-fix: no podman or docker on host" >&2 |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + fi |
| 56 | + exec distrobox-host-exec "$RUNTIME" exec -it -u root "$CONTAINER_ID" "$@" |
45 | 57 | WRAPPER |
46 | 58 | chmod +x "$SUDO_BIN" |
47 | 59 | ''; |
48 | 60 |
|
| 61 | + # ONE-TIME bootstrap for the rhel10 container. |
| 62 | + # Why this exists: distrobox-init runs `dnf install` for base shell tools |
| 63 | + # immediately after creation. The rhel10 INI mounts the (empty) host |
| 64 | + # subscription dirs over /etc/rhsm and /etc/pki/entitlement, which shadows |
| 65 | + # UBI's bundled certs. With no certs, DNF falls onto subscribed RHEL repos |
| 66 | + # and fails — a chicken-and-egg the assemble flow can't break. |
| 67 | + # |
| 68 | + # The fix: register in a plain podman container (no volume shadowing), |
| 69 | + # copy the resulting certs into the host volume dirs, then let distrobox |
| 70 | + # assemble re-create rhel10 normally — now with populated volumes. |
| 71 | + # |
| 72 | + # Run once via `db-rhel-bootstrap`. After it succeeds, `db-up`/`db-rm` |
| 73 | + # cycles preserve the registration via the host volumes, and `db-rhel-init` |
| 74 | + # handles routine refresh + base package install. |
| 75 | + "distrobox/rhel10-bootstrap.sh".text = '' |
| 76 | + #!/bin/sh |
| 77 | + set -e |
| 78 | +
|
| 79 | + HOST_DIR="$HOME/.local/share/distrobox/rhel10" |
| 80 | + IMAGE="registry.access.redhat.com/ubi10/ubi:latest" |
| 81 | + TMP_NAME="rhel10-bootstrap" |
| 82 | +
|
| 83 | + # Detect whichever container runtime distrobox is using (docker on this |
| 84 | + # host today, podman on systems with virtualisation.podman.enable). |
| 85 | + RUNTIME="''${DBX_CONTAINER_MANAGER:-}" |
| 86 | + if [ -z "$RUNTIME" ]; then |
| 87 | + if command -v podman >/dev/null 2>&1; then |
| 88 | + RUNTIME=podman |
| 89 | + elif command -v docker >/dev/null 2>&1; then |
| 90 | + RUNTIME=docker |
| 91 | + else |
| 92 | + echo "!! No podman or docker on host." >&2 |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | + fi |
| 96 | + echo ">> Using container runtime: $RUNTIME" |
| 97 | +
|
| 98 | + echo ">> 1/6 Pulling $IMAGE" |
| 99 | + "$RUNTIME" pull "$IMAGE" |
| 100 | +
|
| 101 | + echo ">> 2/6 Tearing down any previous bootstrap container" |
| 102 | + "$RUNTIME" rm -f "$TMP_NAME" >/dev/null 2>&1 || true |
| 103 | +
|
| 104 | + echo ">> 3/6 Starting temporary bootstrap container (no volume shadowing)" |
| 105 | + "$RUNTIME" run -d --name "$TMP_NAME" "$IMAGE" sleep infinity >/dev/null |
| 106 | +
|
| 107 | + echo ">> 4/6 Registering with Red Hat (interactive)" |
| 108 | + "$RUNTIME" exec -it "$TMP_NAME" subscription-manager register |
| 109 | + # RHEL 9.x+ defaults to Simple Content Access (SCA), which dropped |
| 110 | + # `subscription-manager attach`. Registration alone grants entitlements. |
| 111 | + # On older orgs that still require classic attach, opt-in with |
| 112 | + # ATTACH=1 db-rhel-bootstrap. |
| 113 | + if [ "''${ATTACH:-0}" = "1" ]; then |
| 114 | + "$RUNTIME" exec -it "$TMP_NAME" subscription-manager attach --auto |
| 115 | + fi |
| 116 | + "$RUNTIME" exec -it "$TMP_NAME" subscription-manager refresh |
| 117 | +
|
| 118 | + echo ">> 5/6 Copying entitlement state to $HOST_DIR" |
| 119 | + mkdir -p "$HOST_DIR"/rhsm "$HOST_DIR"/pki-entitlement "$HOST_DIR"/pki-consumer "$HOST_DIR"/var-lib-rhsm |
| 120 | + "$RUNTIME" cp "$TMP_NAME":/etc/rhsm/. "$HOST_DIR/rhsm/" |
| 121 | + "$RUNTIME" cp "$TMP_NAME":/etc/pki/entitlement/. "$HOST_DIR/pki-entitlement/" |
| 122 | + "$RUNTIME" cp "$TMP_NAME":/etc/pki/consumer/. "$HOST_DIR/pki-consumer/" |
| 123 | + "$RUNTIME" cp "$TMP_NAME":/var/lib/rhsm/. "$HOST_DIR/var-lib-rhsm/" |
| 124 | + "$RUNTIME" rm -f "$TMP_NAME" >/dev/null |
| 125 | +
|
| 126 | + echo ">> 6/6 Re-creating rhel10 via distrobox assemble (volumes populated)" |
| 127 | + distrobox stop rhel10 -Y >/dev/null 2>&1 || true |
| 128 | + distrobox rm rhel10 -Y >/dev/null 2>&1 || true |
| 129 | + distrobox assemble create --file "$HOME/.config/distrobox/distrobox.ini" --name rhel10 |
| 130 | +
|
| 131 | + echo "" |
| 132 | + echo ">> Bootstrap complete. Use 'db-rhel' to enter, or 'db-rhel-init' to install base packages." |
| 133 | + ''; |
| 134 | + |
| 135 | + # Routine post-bootstrap setup for the rhel10 container. |
| 136 | + # Run via `db-rhel-init` after `db-rhel-bootstrap` has populated the host |
| 137 | + # volumes. Idempotent: refreshes the entitlement and installs base packages. |
| 138 | + "distrobox/rhel10-register.sh".text = '' |
| 139 | + #!/bin/sh |
| 140 | + set -e |
| 141 | +
|
| 142 | + # Verify subscription is active (volumes carry it across rebuilds). |
| 143 | + if ! sudo subscription-manager status >/dev/null 2>&1; then |
| 144 | + echo "!! Not registered. Run 'db-rhel-bootstrap' first." >&2 |
| 145 | + exit 1 |
| 146 | + fi |
| 147 | +
|
| 148 | + sudo subscription-manager refresh |
| 149 | + sudo dnf -y clean all |
| 150 | + sudo dnf -y makecache |
| 151 | + sudo dnf install -y git vim htop |
| 152 | + ''; |
| 153 | + |
| 154 | + # Enable EPEL inside the rhel10 container. |
| 155 | + # Runs from init_hooks on every db-up. Idempotent: skips work that's |
| 156 | + # already done. Requires CodeReady Builder repo for EPEL build-time deps. |
| 157 | + "distrobox/rhel10-epel.sh".text = '' |
| 158 | + #!/bin/sh |
| 159 | + set -e |
| 160 | +
|
| 161 | + # CodeReady Builder ships EPEL's build-time deps. Enable both the full |
| 162 | + # RHEL and UBI variants — whichever the active subscription exposes |
| 163 | + # will succeed; the other returns non-fatal "repo not found". |
| 164 | + for REPO in \ |
| 165 | + codeready-builder-for-rhel-10-x86_64-rpms \ |
| 166 | + codeready-builder-for-ubi-10-x86_64-rpms; do |
| 167 | + sudo subscription-manager repos --enable "$REPO" 2>&1 \ |
| 168 | + | grep -v "matches no repositories" || true |
| 169 | + done |
| 170 | +
|
| 171 | + if rpm -q epel-release >/dev/null 2>&1; then |
| 172 | + echo ">> epel-release already installed" |
| 173 | + else |
| 174 | + echo ">> installing epel-release" |
| 175 | + sudo dnf install -y \ |
| 176 | + https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm |
| 177 | + fi |
| 178 | + ''; |
| 179 | + |
49 | 180 | "distrobox/nvidia-setup.sh".text = '' |
50 | 181 | #!/bin/sh |
51 | 182 | # 1. Enable 32-bit architecture and multiverse repos |
|
95 | 226 | init_hooks="sh /home/${userConfig.username}/.config/distrobox/sudo-fix.sh" |
96 | 227 | shell=/bin/bash |
97 | 228 |
|
| 229 | + # === Alpine OpenRC Sandbox === |
| 230 | + # For testing OpenRC service management (rc-service, rc-update, openrc-run scripts). |
| 231 | + # NVIDIA disabled: musl libc binaries don't pair with glibc host driver. |
| 232 | + # OpenRC won't run as PID 1 in distrobox — start it manually with `openrc default`. |
| 233 | + [alpy] |
| 234 | + image=alpine:latest |
| 235 | + pull=true |
| 236 | + additional_packages="openrc openrc-init bash shadow util-linux git vim curl wget fastfetch eudev" |
| 237 | + init=false |
| 238 | + nvidia=false |
| 239 | + shell=/bin/bash |
| 240 | + init_hooks="sh /home/${userConfig.username}/.config/distrobox/sudo-fix.sh" |
| 241 | +
|
| 242 | + # === RHEL 10 (UBI image + real Red Hat subscription) === |
| 243 | + # Persists subscription state across db-rm/db-up via host volume mounts. |
| 244 | + # First-time bootstrap (volumes empty) MUST run `db-rhel-init` before |
| 245 | + # `db-rhel`: the helper registers with subscription-manager and installs |
| 246 | + # base packages. After that, certs live in the host volumes and every |
| 247 | + # subsequent rebuild picks them back up. |
| 248 | + # additional_packages is intentionally empty: dnf needs a working repo, |
| 249 | + # which needs subscription certs, which only exist after first register. |
98 | 250 | [rhel10] |
99 | 251 | image=registry.access.redhat.com/ubi10/ubi:latest |
100 | 252 | pull=true |
101 | | - additional_packages="subscription-manager git vim" |
102 | 253 | init=false |
103 | 254 | nvidia=true |
104 | 255 | shell=/bin/bash |
105 | 256 | volume="/home/${userConfig.username}/.local/share/distrobox/rhel10/rhsm:/etc/rhsm /home/${userConfig.username}/.local/share/distrobox/rhel10/pki-entitlement:/etc/pki/entitlement /home/${userConfig.username}/.local/share/distrobox/rhel10/pki-consumer:/etc/pki/consumer /home/${userConfig.username}/.local/share/distrobox/rhel10/var-lib-rhsm:/var/lib/rhsm" |
106 | | - init_hooks="sh /home/${userConfig.username}/.config/distrobox/sudo-fix.sh && if [ ! -f /etc/rhsm/ca/redhat-uep.pem ]; then dnf reinstall -y subscription-manager-rhsm-certificates subscription-manager; fi" |
| 257 | + init_hooks="sh /home/${userConfig.username}/.config/distrobox/sudo-fix.sh && sh /home/${userConfig.username}/.config/distrobox/rhel10-epel.sh" |
107 | 258 | ''; |
108 | 259 | }; |
109 | 260 |
|
110 | 261 | # Ensure host directories exist for shared Distrobox state. |
| 262 | + # The rhel10/* dirs hold subscription state populated by db-rhel-bootstrap. |
| 263 | + # Ownership left unset (`-`) so systemd-tmpfiles won't re-chown live certs: |
| 264 | + # after bootstrap the dirs are owned by Chief; the rhel10 distrobox runs |
| 265 | + # rootful via docker (no userns remap), so root inside the container can |
| 266 | + # still read them. |
111 | 267 | systemd.user.tmpfiles.rules = [ |
112 | 268 | "d %h/.local/share/distrobox/bin 0755 - - - -" |
113 | 269 |
|
114 | | - # Persistent RHEL subscription volumes use UID/GID 100000, which maps to the container's root user. |
115 | | - "d %h/.local/share/distrobox/rhel10/rhsm 0755 100000 100000 - -" |
116 | | - "d %h/.local/share/distrobox/rhel10/pki-entitlement 0755 100000 100000 - -" |
117 | | - "d %h/.local/share/distrobox/rhel10/pki-consumer 0755 100000 100000 - -" |
118 | | - "d %h/.local/share/distrobox/rhel10/var-lib-rhsm 0750 100000 100000 - -" |
| 270 | + "d %h/.local/share/distrobox/rhel10/rhsm 0755 - - - -" |
| 271 | + "d %h/.local/share/distrobox/rhel10/pki-entitlement 0755 - - - -" |
| 272 | + "d %h/.local/share/distrobox/rhel10/pki-consumer 0755 - - - -" |
| 273 | + "d %h/.local/share/distrobox/rhel10/var-lib-rhsm 0750 - - - -" |
119 | 274 | ]; |
120 | 275 |
|
121 | 276 | # Alias to easily create/update these containers |
|
126 | 281 | db-ubu = "distrobox enter ubu"; |
127 | 282 | db-debian = "distrobox enter debi"; |
128 | 283 | db-rhel = "distrobox enter rhel10"; |
| 284 | + db-rhel-bootstrap = "bash /home/${userConfig.username}/.config/distrobox/rhel10-bootstrap.sh"; |
| 285 | + db-rhel-init = "distrobox enter rhel10 -- bash /home/${userConfig.username}/.config/distrobox/rhel10-register.sh"; |
| 286 | + db-alpine = "distrobox enter alpy"; |
129 | 287 | }; |
130 | 288 | } |
0 commit comments