]> git.ozlabs.org Git - petitboot/blob - utils/pb-udhcpc
utils: Always pass MAC address in pb-udhcpc
[petitboot] / utils / pb-udhcpc
1 #!/bin/sh
2 #
3 # Petitboot udhcpc user script.  Should be run by udhcpc when
4 # there is a change in the dhcp configuration.  For more info
5 # see the udhcpc man page and the Linux kernel source file
6 # Documentation/filesystems/nfsroot.txt.
7 #
8
9 PBOOT_USER_EVENT_SOCKET="/tmp/petitboot.ev"
10 log="/var/log/petitboot/pb-udhcpc.log"
11
12 pb_add () {
13         # Looks like udhcpc will give us different names, depending if the
14         # parameter was in the header, or specified by options
15         [ -z "$bootfile" ] && bootfile=${boot_file}
16
17         mac=$(cat /sys/class/net/$interface/address)
18         paramstr=''
19
20         # Collect relevant DHCP response parameters into $paramstr
21         for name in pxeconffile pxepathprefix bootfile mac ip siaddr \
22                 serverid tftp
23         do
24                 value=$(eval "echo \${$name}")
25                 [ -n "$value" ] || continue;
26
27                 paramstr="$paramstr $name=$value"
28         done
29
30         pb-event dhcp@${interface} $paramstr
31
32         # Check if an explicit boot file present. If there is, add it as
33         # an option directly.
34         if [ -z "${bootfile}" ]
35         then
36                 return;
37         fi
38
39         paramstr=""
40
41         # Collect relevant parameters to add an option to the bootfile
42         # parameter
43         for name in rootpath siaddr bootfile mac
44         do
45                 value=$(eval "echo \${$name}")
46                 [ -n "$value" ] || continue;
47
48                 paramstr="$paramstr $name=$value"
49         done
50
51         pb-event add@${interface} name="netboot $interface ($bootfile)" \
52                 $paramstr
53 }
54
55 pb_remove () {
56         mac=$(cat /sys/class/net/$interface/address)
57         pb-event remove@${interface} mac=$mac
58 }
59
60 case "$1" in
61 bound)
62         pb_add
63         ;;
64 deconfig)
65         pb_remove
66         ;;
67 *)
68         ;;
69 esac
70
71 printf "--- $1 ---\n" >> ${log}
72 set >> ${log}
73 printf "---------------\n" >> ${log}