#!/bin/bash
set -euo pipefail
mapfile -t interfaces < /run/fds/network/interfaces
(( ${#interfaces[@]} > 0 ))
for interface in "${interfaces[@]}"; do
    [[ $interface =~ ^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,14}$ ]]
    # This profile is IPv4 DHCP. Do not leave autonomous kernel IPv6 routing
    # active outside the managed client's lifetime.
    if [[ -e /proc/sys/net/ipv6/conf/$interface/disable_ipv6 ]]; then
        printf '1\n' >"/proc/sys/net/ipv6/conf/$interface/disable_ipv6"
    fi
done
exec /usr/bin/dhcpcd --nobackground --noipv6 --noipv4ll "${interfaces[@]}"
