Files
ignition/ignition-suse-generator

64 lines
1.7 KiB
Bash

#!/bin/bash
set -e
# Generators don't have logging right now
# https://github.com/systemd/systemd/issues/15638
exec 1>/dev/kmsg; exec 2>&1
UNIT_DIR="${1:-/tmp}"
cmdline=( $(</proc/cmdline) )
cmdline_arg() {
local name="$1" value="$2"
for arg in "${cmdline[@]}"; do
if [[ "${arg%%=*}" == "${name}" ]]; then
value="${arg#*=}"
fi
done
echo "${value}"
}
add_requires() {
local name="$1"; shift
local target="$1"; shift
local requires_dir="${UNIT_DIR}/${target}.requires"
mkdir -p "${requires_dir}"
ln -sf "../${name}" "${requires_dir}/${name}"
}
add_requires ignition-complete.target firstboot.target
add_requires ignition-diskful.target ignition-complete.target
# TODO: Add support for ignition-subsequent.target, when needed?
echo "PLATFORM_ID=$(cmdline_arg ignition.platform.id)" > /run/ignition.env
. /run/ignition.env
add_requires ignition-mount-initrd-fstab.service ignition-files.service
add_requires ignition-umount-initrd-fstab.service ignition-files.service
add_requires ignition-enable-network.service ignition-fetch.service
if [ -z "${PLATFORM_ID}" ]; then
platform="metal"
detectedvirt="$(systemd-detect-virt || true)"
case "${detectedvirt}" in
*vmware*)
if modinfo -F name vmw_vsock_virtio_transport >/dev/null; then
platform="vmware"
fi
;;
*oracle*)
if modinfo -F name vboxguest >/dev/null; then
platform="virtualbox"
fi
;;
*kvm*|*qemu*)
if modinfo -F name qemu_fw_cfg >/dev/null; then
platform="qemu"
fi
;;
esac
echo "PLATFORM_ID=${platform}" > /run/ignition.env
fi