#!/bin/bash

# This file is part of DPU ZTP package.

# This script hooks into NetworkManager(8) via its scripts
# and tries to initiate automated provisioning process once
# it received a special 'ZTP_PROVISION_URL' option in the DHCP lease
#

if [ -n "$DHCP4_DHCP_LEASE_TIME" ] || [ -n "$DHCP6_DHCP_LEASE_TIME" ]; then
  if [ "$2" = "dhcp4-change" ] || [ "$2" = "dhcp6-change" ] || [ "$2" = "up" ] ; then
    if [ -n "$DHCP4_ZTP_PROVISION_URL" ] ; then
      /usr/sbin/ztp -q "$DHCP4_ZTP_PROVISION_URL"
    fi
    if [ -n "$DHCP6_ZTP_PROVISION_URL" ] ; then
      /usr/sbin/ztp -q "$DHCP6_ZTP_PROVISION_URL"
    fi
  fi
fi
