#!/bin/bash # ============================================================================ # DarkForge Linux — dhcpcd service # ============================================================================ # DHCP client daemon for ethernet. Uses interface from rc.conf. # ============================================================================ . /etc/rc.conf DAEMON="/usr/sbin/dhcpcd" # Auto-detect network interface if configured one doesn't exist IFACE="${NETWORK_INTERFACE}" if [ ! -d "/sys/class/net/${IFACE}" ] || [ "${IFACE}" = "lo" ]; then # Find first non-loopback ethernet interface for d in /sys/class/net/*; do name=$(basename "$d") [ "$name" = "lo" ] && continue # Skip wireless (has wireless/ subdir) [ -d "$d/wireless" ] && continue IFACE="$name" echo " NOTE: ${NETWORK_INTERFACE} not found, using ${IFACE}" break done fi PIDFILE="/run/dhcpcd-${IFACE}.pid" case "$1" in start) echo " Starting dhcpcd on ${IFACE}..." if [ "${NETWORK_DHCP}" = "yes" ]; then ${DAEMON} -q "${IFACE}" && echo " dhcpcd started" else # Static IP configuration ip addr add "${NETWORK_IP}/${NETWORK_MASK}" dev "${IFACE}" ip link set "${IFACE}" up ip route add default via "${NETWORK_GATEWAY}" if [ -n "${NETWORK_DNS}" ]; then echo "# Generated by rc.d/dhcpcd" > /etc/resolv.conf for dns in ${NETWORK_DNS}; do echo "nameserver ${dns}" >> /etc/resolv.conf done fi echo " Static IP configured: ${NETWORK_IP}" fi ;; stop) echo " Stopping dhcpcd..." if [ -f "${PIDFILE}" ]; then ${DAEMON} -x "${IFACE}" 2>/dev/null fi echo " dhcpcd stopped" ;; restart) $0 stop sleep 2 $0 start ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 ;; esac