#!/bin/sh
# This file is part of cloud-init. See LICENSE file for license information.

# This script is used on non-systemd systems. It is called by the
# cloud-init-hotplug init.d script.
#
# Creates a named pipe and then continually listens to this pipe. The pipe
# is written to by the hook-hotplug script (which is called by a udev rule
# upon a network device event). Anything received via the pipe is then
# passed on via the "cloud-init devel hotplug-hook handle" command.

PIPE="/run/cloud-init/share/hook-hotplug-cmd"

[ -p $PIPE ] || mkfifo -m700 $PIPE

while true; do
  # shellcheck disable=SC2162
  if read args < $PIPE; then
    # shellcheck disable=SC2086
    /usr/bin/cloud-init devel hotplug-hook $args
  fi
done
