ignition/ignition-suse-generator

54 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
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="$(systemd-detect-virt || true)"
case "${platform}" in
*vmware*) platform="vmware" ;;
*oracle*) platform="virtualbox" ;;
*kvm*|*qemu*) platform="qemu" ;;
*) platform="metal" ;;
esac
echo "PLATFORM_ID=${platform}" > /run/ignition.env
fi