|
| 1 | +#!/bin/bash |
| 2 | +# automation/41-mios-dropin-fanout.sh |
| 3 | +# |
| 4 | +# Fans canonical drop-in content from /usr/share/mios/dropins/ into the |
| 5 | +# per-unit *.d/ directories at image build time. |
| 6 | +# |
| 7 | +# Why a script instead of committing 60+ identical files (or symlinks): |
| 8 | +# systemd's drop-in mechanism is per-unit -- there is no top-level |
| 9 | +# "apply this drop-in to many services" facility. The MiOS image |
| 10 | +# historically shipped 60+ byte-identical .conf files spread across |
| 11 | +# *.service.d/ / *.socket.d/ / *.mount.d/ / *.target.d/ for the four |
| 12 | +# common condition gates (virt-gate, bare-metal-only, mios-virt-gate, |
| 13 | +# mios-wsl2). Editing one gate meant editing 14+ files. |
| 14 | +# |
| 15 | +# Symlinks would deduplicate at the filesystem layer, but creating |
| 16 | +# them on Windows authoring hosts requires SeCreateSymbolicLink- |
| 17 | +# Privilege or Developer Mode (Git Bash falls back to file-copy |
| 18 | +# without them); neither is reliable in a typical author setup. |
| 19 | +# |
| 20 | +# So: store one canonical .conf per gate under usr/share/mios/dropins/ |
| 21 | +# (committed, edited as a single source of truth), and fan it out at |
| 22 | +# image build time via this script. The deployed image carries the |
| 23 | +# fanned-out files exactly as before -- systemd reads them through its |
| 24 | +# normal *.d/ scanner -- but the source tree stays small and edits |
| 25 | +# propagate cleanly without filesystem-symlink dependencies. |
| 26 | +# |
| 27 | +# How to add a new gate: |
| 28 | +# 1. Drop the canonical content at usr/share/mios/dropins/NAME.conf. |
| 29 | +# 2. Add an entry to GATES below mapping NAME to the units it gates. |
| 30 | +# 3. The next image build picks it up automatically. |
| 31 | +# |
| 32 | +# How to extend an existing gate to a new unit: |
| 33 | +# 1. Append the unit name (with explicit suffix: foo.service, |
| 34 | +# bar.socket, baz.mount, ...) to that gate's UNITS list. |
| 35 | +# 2. The next image build creates the drop-in. |
| 36 | +# |
| 37 | +# Idempotent: running this script repeatedly produces the same result, |
| 38 | +# overwriting any prior copy (so an edit to the canonical propagates |
| 39 | +# even on incremental rebuilds). |
| 40 | + |
| 41 | +set -euo pipefail |
| 42 | + |
| 43 | +# Build context root: in the Containerfile RUN that calls this script, |
| 44 | +# /tmp/build is the writable copy of the repo and the image's /usr/lib/ |
| 45 | +# already exists. Read canonicals from the former, write drop-ins into |
| 46 | +# the latter (the image hasn't yet absorbed usr/share/mios/dropins/ |
| 47 | +# at this point in the build). |
| 48 | +DROPIN_SRC="${CTX:-/tmp/build}/usr/share/mios/dropins" |
| 49 | +SYSTEMD_SYSTEM_DIR="/usr/lib/systemd/system" |
| 50 | + |
| 51 | +# Each line: GATE_NAME:UNIT1,UNIT2,... |
| 52 | +# GATE_NAME maps to ${DROPIN_SRC}/${GATE_NAME}.conf |
| 53 | +# UNITs include the explicit suffix (.service, .socket, .mount, .target). |
| 54 | +# The drop-in lands at ${SYSTEMD_SYSTEM_DIR}/${UNIT}.d/10-${GATE_NAME}.conf |
| 55 | +GATES=( |
| 56 | + "virt-gate:mios-cdi-detect.service,mios-ceph-bootstrap.service,mios-flatpak-install.service,mios-gpu-amd.service,mios-gpu-intel.service,mios-gpu-nvidia.service,mios-gpu-status.service,mios-grd-setup.service,mios-k3s-init.service,mios-libvirtd-setup.service,mios-nvidia-cdi.service,mios-role.service,mios-selinux-init.service,mios-waydroid-init.service" |
| 57 | + |
| 58 | + "bare-metal-only:corosync.service,crowdsec.service,crowdsec-firewall-bouncer.service,mios-ha-bootstrap.service,multipathd.service,nfs-server.service,nmb.service,nvidia-powerd.service,osbuild-composer.service,osbuild-worker@1.service,pacemaker.service,pcsd.service,smb.service" |
| 59 | + |
| 60 | + "mios-virt-gate:audit-rules.service,auditd.service,bootloader-update.service,ceph-bootstrap.service,chronyd.service,coreos-populate-lvmdevices.service,coreos-printk-quiet.service,dev-binderfs.mount,fapolicyd.service,firewalld.service,gdm.service,nvidia-powerd.service,tuned.service,usbguard.service,waydroid-container.service" |
| 61 | + |
| 62 | + "mios-wsl2:avahi-daemon.service,avahi-daemon.socket,boot.mount,boot-complete.target,cloud-config.service,cloud-init-local.service,cloud-init-network.service,greenboot-healthcheck.service,qemu-guest-agent.service,rpm-ostree-fix-shadow-mode.service,stratisd.service,systemd-homed.service,systemd-logind.service,var-lib-nfs-rpc_pipefs.mount,virtlxcd.service,virtlxcd-admin.socket,virtlxcd-ro.socket,zincati.service" |
| 63 | +) |
| 64 | + |
| 65 | +count=0 |
| 66 | +for entry in "${GATES[@]}"; do |
| 67 | + gate_name="${entry%%:*}" |
| 68 | + units_csv="${entry#*:}" |
| 69 | + src="${DROPIN_SRC}/${gate_name}.conf" |
| 70 | + |
| 71 | + if [[ ! -f "$src" ]]; then |
| 72 | + echo "[mios-dropin-fanout] FATAL: canonical missing at $src" >&2 |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | + |
| 76 | + IFS=',' read -ra units <<< "$units_csv" |
| 77 | + for unit in "${units[@]}"; do |
| 78 | + dropin_dir="${SYSTEMD_SYSTEM_DIR}/${unit}.d" |
| 79 | + dropin_file="${dropin_dir}/10-${gate_name}.conf" |
| 80 | + install -d -m 0755 "$dropin_dir" |
| 81 | + install -m 0644 "$src" "$dropin_file" |
| 82 | + count=$((count + 1)) |
| 83 | + done |
| 84 | +done |
| 85 | + |
| 86 | +echo "[mios-dropin-fanout] fanned out $count drop-ins from ${#GATES[@]} canonical gates" |
0 commit comments