set -e
PERSIST_KERNEL_NET_PARAMS=("ipv6.disable" "net.ifnames" "net.naming-scheme")
PERSIST_DRACUT_NET_PARAMS=("ip" "ifname" "rd.route" "bootdev" "BOOTIF" "rd.bootif" "nameserver" "rd.peerdns" "biosdevname" "vlan" "bond" "team" "bridge" "rd.net.timeout.carrier" "coreos.no_persist_ip" "coreos.force_persist_ip")
PERSIST_S390X_PARAMS=("rd.dasd" "rd.zfcp" "rd.znet" "zfcp.allow_lun_scan" "cio_ignore")
INSTALLER_CONFIG_DIR=/etc/coreos/installer.d
args=("install")
IFS=" " read -r -a cmdline <<< "$(</proc/cmdline)"
karg() {
local name="$1" value="$2"
for arg in "${cmdline[@]}"; do
if [[ "${arg%%=*}" == "${name}" ]]; then
value="${arg#*=}"
fi
done
echo "${value}"
}
karg_bool() {
local value
value=$(karg "$@")
case "$value" in
""|0|no|off) return 1;;
*) return 0;;
esac
}
copy_arg() {
local arg="$1"; shift
local opt="$1"; shift
local value
value="$(karg "${arg}")"
if [ -n "${value}" ]; then
args+=("${opt}" "${value}")
fi
}
if [ "$(karg coreos.inst)" = yes ]; then
echo '"coreos.inst=yes" is deprecated and no longer has any effect.'
fi
have_config_file=
for file in "${INSTALLER_CONFIG_DIR}/"*; do
if [ -f "${file}" ]; then
args+=("--config-file" "${file}")
have_config_file=1
fi
done
device="$(karg coreos.inst.install_dev)"
if [ -n "${device}" ]; then
if [ "${device##*/}" = "${device}" ]; then
echo "The \"coreos.inst.install_dev=$device\" syntax is deprecated."
echo "Use \"coreos.inst.install_dev=/dev/$device\" instead."
device="/dev/${device}"
fi
args+=("${device}")
elif [ -z "${have_config_file}" ]; then
echo "No install device specified."
exit 1
fi
ignition_url="$(karg coreos.inst.ignition_url)"
if [ -n "${ignition_url}" ] && [ "${ignition_url}" != "skip" ]; then
args+=("--ignition-url" "${ignition_url}" "--insecure-ignition")
fi
firstboot_args=""
for item in "${cmdline[@]}"; do
for param in "${PERSIST_KERNEL_NET_PARAMS[@]}" "${PERSIST_DRACUT_NET_PARAMS[@]}"; do
if [[ $item =~ ^$param(=.*)?$ ]]; then
firstboot_args+="${item} "
fi
done
for param in "${PERSIST_S390X_PARAMS[@]}"; do
if [[ $item =~ ^$param(=.*)?$ ]]; then
args+=("--append-karg" "${item}")
fi
done
done
if [ -n "${firstboot_args}" ]; then
args+=("--firstboot-args" "rd.neednet=1 ${firstboot_args}")
fi
copy_arg coreos.inst.image_url --image-url
copy_arg coreos.inst.platform_id --platform
copy_arg coreos.inst.stream --stream
copy_arg coreos.inst.save_partlabel --save-partlabel
copy_arg coreos.inst.save_partindex --save-partindex
if karg_bool coreos.inst.insecure; then
args+=("--insecure")
fi
if karg_bool coreos.inst.secure_ipl; then
args+=("--secure-ipl")
fi
args+=("--fetch-retries" "infinite")
udevadm settle
echo "coreos-installer ${args[*]}"
coreos-installer "${args[@]}"
rm -rf "${INSTALLER_CONFIG_DIR}"