forked from tinkerbell/hook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdhcp.sh
More file actions
executable file
·40 lines (33 loc) · 1.5 KB
/
dhcp.sh
File metadata and controls
executable file
·40 lines (33 loc) · 1.5 KB
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
#!/bin/sh
# This script will run the dhcp client. If `vlan_id=` in `/proc/cmdline` has a value, it will run the dhcp client only on the
# VLAN interface.
# This script accepts an input parameter of true or false.
# true: run the dhcp client with the one shot option
# false: run the dhcp client as a service
set -x
run_dhcp_client() {
one_shot="$1"
al="en*"
vlan_id=$(sed -n 's/.* vlan_id=\([0-9]*\).*/\1/p' /proc/cmdline)
if [ -n "$vlan_id" ]; then
al="en*.*"
fi
if [ "$one_shot" = "true" ]; then
# always return true for the one shot dhcp call so it doesn't block Hook from starting up.
# the --nobackground is not used here because when it is used, dhcpcd doesn't honor the --timeout option
# and waits indefinitely for a response. For one shot, we want to timeout after the 30 second default.
/sbin/dhcpcd -f /dhcpcd.conf --allowinterfaces "${al}" -1 || true
# use busybox's ntpd to set the time after getting an IP address; don't fail
echo 'sleep 1 second before calling ntpd' && sleep 1
/usr/sbin/ntpd -n -q -dd -p pool.ntp.org || true
else
/sbin/dhcpcd --nobackground -f /dhcpcd.conf --allowinterfaces "${al}"
fi
}
if [ -f /run/network/interfaces ]; then
echo "the /run/network/interfaces file exists, so static IP's are in use. we will not be running the dhcp client."
exit 0
fi
# we always return true so that a failure here doesn't block the next container service from starting. Ideally, we always
# want the getty service to start so we can debug failures.
run_dhcp_client "$1" || true