test/parser: Add new test cases to pxe parser
[petitboot] / utils / pb-udhcpc
index bc0f759c09c525805c08709ce22d00b01531a249..3494985d3fc33dfcb6ed0b74b9b5d74368ba10b4 100644 (file)
@@ -7,23 +7,54 @@
 #
 
 PBOOT_USER_EVENT_SOCKET="/tmp/petitboot.ev"
-log="pb-udhcpc.log"
+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=$(< /sys/class/net/$interface/address)
+       paramstr=''
 
-       echo -ne "add@/net/${interface}\0name=netboot\0image=tftp://${siaddr}${boot_file}\0args=root=/dev/nfs ip=any nfsroot=${k_server_ip}:${k_root_dir}\0" | pb-event
+       # Collect relevant DHCP response parameters into $paramstr
+       for name in conffile 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 () {
-       echo -ne "remove@/net/${interface}\0name=netboot\0" | pb-event
+       pb-event remove@${interface} name=netboot
 }
 
 case "$1" in
-bound | renew)
+bound)
        pb_add
        ;;
 deconfig)
@@ -33,6 +64,6 @@ deconfig)
        ;;
 esac
 
-echo "--- $1 ---" >> ${log}
+printf "--- $1 ---\n" >> ${log}
 set >> ${log}
-echo "---------------" >> ${log}
+printf "---------------\n" >> ${log}