]> git.ozlabs.org Git - petitboot/blob - utils/pb-udhcpc
discover/device-handler: Ensure we free unresolved boot options on remove
[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=$(< /sys/class/net/$interface/address)
18         paramstr=''
19
20         # Collect relevant DHCP response parameters into $paramstr
21         for name in pxeconffile bootfile mac ip siaddr serverid tftp
22         do
23                 value=$(eval "echo \${$name}")
24                 [ -n "$value" ] || continue;
25
26                 paramstr="$paramstr $name=$value"
27         done
28
29         pb-event dhcp@{interface} $paramstr
30
31         # Check if an explicit config file present
32         if [ -n "${conffile}" ]
33         then
34                 return;
35         fi
36
37         # Finally, add an option for the boot_file parameter
38         paramstr='name=netboot'
39
40         # Collect relevant parameters to add an option to the boot_file parameter
41         for name in rootpath siaddr boot_file
42         do
43                 value=$(eval "echo \${$name}")
44                 [ -n "$value" ] || continue;
45
46                 paramstr="$paramstr $name=$value"
47         done
48
49         pb-event add@{interface} $paramstr
50 }
51
52 pb_remove () {
53         pb-event remove@${interface} name=netboot
54 }
55
56 case "$1" in
57 bound)
58         pb_add
59         ;;
60 deconfig)
61         pb_remove
62         ;;
63 *)
64         ;;
65 esac
66
67 printf "--- $1 ---\n" >> ${log}
68 set >> ${log}
69 printf "---------------\n" >> ${log}