#!/bin/sh
#
# Copyright © 2021 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
#
# This software product is a proprietary product of Nvidia Corporation and its affiliates
# (the "Company") and all right, title, and interest in and to the software
# product, including all associated intellectual property rights, are and
# shall remain exclusively with the Company.
#
# This software product is governed by the End User License Agreement
# provided with the software product.

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/cumulus/bin

# Fixups needed first time a system is booted.
# This runs from the cumulus-firstboot-after-networking.service,
# after networking on the first boot after an image is installed.

# We only run once.  Disable ourselves as our very first action, so
# if something goes wrong, we won't run again.
[ -f /etc/cumulus-firstboot-after-networking-done ] && exit 0
touch /etc/cumulus-firstboot-after-networking-done
/bin/systemctl --no-block disable cumulus-firstboot-after-networking.service

#
# Run all of the scripts in
# /usr/lib/cumulus/firstboot-after-networking.d/*.firstboot
# under the mgmt VRF.
#
FIRSTBOOT_DIR="/usr/lib/cumulus/firstboot-after-networking.d"
[ -d "${FIRSTBOOT_DIR}" ] && {
    scripts=$(/bin/ls ${FIRSTBOOT_DIR}/*.firstboot 2>/dev/null) && {
        for s in ${scripts} ; do
            vrf task exec mgmt ${s}
        done
    }
}

exit 0
