]> git.ozlabs.org Git - petitboot/blob - utils/pb-udhcpc
utils/pb-udhcpc: Fix incorrect reference to $interface
[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 config file present
33         if [ -n "${conffile}" ]
34         then
35                 return;
36         fi
37
38         # Finally, add an option for the boot_file parameter
39         paramstr='name=netboot'
40
41         # Collect relevant parameters to add an option to the boot_file parameter
42         for name in rootpath siaddr boot_file
43         do
44                 value=$(eval "echo \${$name}")
45                 [ -n "$value" ] || continue;
46
47                 paramstr="$paramstr $name=$value"
48         done
49
50         pb-event add@${interface} $paramstr
51 }
52
53 pb_remove () {
54         pb-event remove@${interface} name=netboot
55 }
56
57 case "$1" in
58 bound)
59         pb_add
60         ;;
61 deconfig)
62         pb_remove
63         ;;
64 *)
65         ;;
66 esac
67
68 printf "--- $1 ---\n" >> ${log}
69 set >> ${log}
70 printf "---------------\n" >> ${log}