summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/slx-network/scripts/setup-bootif-network.stage4
blob: 4f41dfed88390221a6191e5c552aa504082a512a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#
# This script sets up the main network interface we booted from,
# as designated by SLX_PXE_NETIF in /opt/openslx/config
# It will run on either the bridge (SLX_BRIDGE is set) or the
# physical interface directly.

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

. /opt/openslx/config

if [ -z "$SLX_PXE_NETIF" ]; then
	echo "Missing network information of the main boot interface."
	exit 1
fi

MAIN_NETIF="$SLX_PXE_NETIF"
[ -n "$SLX_VLAN_ID" ] && MAIN_NETIF="${SLX_PXE_NETIF}.${SLX_VLAN_ID}"
[ -n "$SLX_BRIDGE" ]  && MAIN_NETIF="${SLX_BRIDGE}"
readonly MAIN_NETIF

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

# send machine uuid during DHCP if configured
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 "$MAIN_NETIF" \
	-r "${SLX_PXE_CLIENT_IP}" \
	-s /opt/openslx/scripts/udhcpc-trigger \
	-p "/run/udhcpc/udhcpc.${MAIN_NETIF}.pid"
ret=$?

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

exit "${ret}"