]> git.ozlabs.org Git - petitboot/blobdiff - utils/pb-udhcpc
utils/pb-udhcpc: remove bashism when reading mac address
[petitboot] / utils / pb-udhcpc
index ff231780829630dd4823c7c56396acb8ab760e1a..60cfa58df604d2567121a749a7be586b1c8ab982 100644 (file)
@@ -10,23 +10,52 @@ PBOOT_USER_EVENT_SOCKET="/tmp/petitboot.ev"
 log="/var/log/petitboot/pb-udhcpc.log"
 
 pb_add () {
-       k_server_ip=${rootpath%%:*}
-       k_root_dir=${rootpath#*:}
+       # Looks like udhcpc will give us different names, depending if the
+       # parameter was in the header, or specified by options
+       [ -z "$bootfile" ] && bootfile=${boot_file}
 
-       [ ${k_server_ip} != ${rootpath} ] || k_server_ip=${serverid}
+       mac=$(cat /sys/class/net/$interface/address)
+       paramstr=''
 
-       pb-event add@/net/${interface} \
-               name=netboot \
-               image=tftp://${siaddr}/${boot_file} \
-               args="root=/dev/nfs ip=any nfsroot=${k_server_ip}:${k_root_dir}"
+       # Collect relevant DHCP response parameters into $paramstr
+       for name in pxeconffile pxepathprefix bootfile mac ip siaddr \
+               serverid tftp
+       do
+               value=$(eval "echo \${$name}")
+               [ -n "$value" ] || continue;
+
+               paramstr="$paramstr $name=$value"
+       done
+
+       pb-event dhcp@{interface} $paramstr
+
+       # Check if an explicit config file present
+       if [ -n "${conffile}" ]
+       then
+               return;
+       fi
+
+        # Finally, add an option for the boot_file parameter
+       paramstr='name=netboot'
+
+       # Collect relevant parameters to add an option to the boot_file parameter
+       for name in rootpath siaddr boot_file
+        do
+                value=$(eval "echo \${$name}")
+                [ -n "$value" ] || continue;
+
+                paramstr="$paramstr $name=$value"
+        done
+
+       pb-event add@{interface} $paramstr
 }
 
 pb_remove () {
-       pb-event remove@/net/${interface} name=netboot
+       pb-event remove@${interface} name=netboot
 }
 
 case "$1" in
-bound | renew)
+bound)
        pb_add
        ;;
 deconfig)