summaryrefslogblamecommitdiffstats
path: root/builder/modules.d/slx-network/scripts/setup-bootif-network.stage4
blob: 7ccb94e6819d63bf893fe3e2a3e676e709b7704d (plain) (tree)



















































                                                                                             
#!/bin/bash
# For arrays

export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin

. /run/openslx/network.conf

net_if="$1"
net_ip="$(ip addr show dev "${net_if}" | grep -m1 '^\s*inet ' | \
	awk -F " " '{print $2}' | awk -F "/" '{print $1}')"

# set default options
declare -a udhcpc_opts
udhcpc_opts+=("-t" "8")
udhcpc_opts+=("-O" "domain")
udhcpc_opts+=("-O" "nissrv")
udhcpc_opts+=("-O" "nisdomain")
udhcpc_opts+=("-O" "wpad")
udhcpc_opts+=("-O" "search")
udhcpc_opts+=("-O" "wins")

# need to renew?
if [ -n "$net_ip" ]; then
	udhcpc_opts+=( "-r" "$net_ip" )
fi

primary="br0"
[ -n "$SLX_BRIDGE" ] && primary="$SLX_BRIDGE"

# send machine uuid during DHCP if acting on primary interface
if [ "$primary" = "$net_if" ] && [ "$SLX_NET_DHCP_UUID" = "yes" ]; then
	uid=$(dmidecode -s system-uuid | \
		sed -r 's/^(..)(..)(..)(..)-(..)(..)-(..)(..)-(....)-/00\4\3\2\1\6\5\8\7\9/')
	if [ "${#uid}" = 34 ]; then
		echo "Using SMBIOS uid for DHCP"
		udhcpc_opts+=( "-x" "0x3d:$uid" )
	fi
fi

mkdir -p /run/udhcpc || echo "Could not create '/run/udhcpc'."

udhcpc "${udhcpc_opts[@]}" -i "${net_if}" \
	-s /opt/openslx/scripts/udhcpc-trigger \
	-p "/run/udhcpc/udhcpc.${net_if}.pid"
ret=$?

if [ "${ret}" != 0 ]; then
	echo "udhcpc" "Could not run 'udhcpc ${udhcpc_opts[*]}' on ${net_if}."
fi

exit "${ret}"