Add udhcpc utility script
authorGeoff Levand <geoffrey.levand@am.sony.com>
Sun, 12 Apr 2009 15:11:56 +0000 (15:11 +0000)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 30 Jun 2009 07:29:24 +0000 (15:29 +0800)
Add a udhcpc utility script.  udhcpc can be configured to run a
specified script when there is a change in the dhcp configuration.
This udhcpc utility script will write a petitboot netboot message
to the petitboot user event socket.

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
rules.mk
utils/udhcpc [new file with mode: 0644]

index 3251b0454607bf2c1505d1b894a07caeb3662c94..9a6cf57736ca42fa9f10b8e87634b97be40d91b2 100644 (file)
--- a/rules.mk
+++ b/rules.mk
@@ -30,6 +30,7 @@ endif
 # other to install
 artwork = background.jpg cdrom.png hdd.png usbpen.png tux.png cursor.gz
 rules = utils/99-petitboot.rules
+udhcpc = utils/udhcpc
 
 # client/daemon lib objs
 list_objs = lib/list/list.o
@@ -115,7 +116,7 @@ $(parser_test): $(parser_test_objs)
 
 parser-test: $(parser_test)
 
-install: all $(rules)
+install: all $(rules) $(udhcpc)
        $(INSTALL) -d $(DESTDIR)$(sbindir)/
        $(INSTALL) $(daemons) $(uis) $(utils) $(DESTDIR)$(sbindir)/
        $(INSTALL) -d $(DESTDIR)$(pkgdatadir)/artwork/
@@ -123,6 +124,7 @@ install: all $(rules)
                $(DESTDIR)$(pkgdatadir)/artwork/
        $(INSTALL) -d $(DESTDIR)$(pkgdatadir)/utils
        $(INSTALL) -m 644 $(top_srcdir)/$(rules) $(DESTDIR)$(pkgdatadir)/utils
+       $(INSTALL) -m 644 $(top_srcdir)/$(udhcpc) $(DESTDIR)$(pkgdatadir)/utils
 
 dist: $(PACKAGE)-$(VERSION).tar.gz
 
diff --git a/utils/udhcpc b/utils/udhcpc
new file mode 100644 (file)
index 0000000..bc0f759
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# Petitboot udhcpc user script.  Should be run by udhcpc when
+# there is a change in the dhcp configuration.  For more info
+# see the udhcpc man page and the Linux kernel source file
+# Documentation/filesystems/nfsroot.txt.
+#
+
+PBOOT_USER_EVENT_SOCKET="/tmp/petitboot.ev"
+log="pb-udhcpc.log"
+
+pb_add () {
+       k_server_ip=${rootpath%%:*}
+       k_root_dir=${rootpath#*:}
+
+       [ ${k_server_ip} != ${rootpath} ] || k_server_ip=${serverid}
+
+       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
+}
+
+pb_remove () {
+       echo -ne "remove@/net/${interface}\0name=netboot\0" | pb-event
+}
+
+case "$1" in
+bound | renew)
+       pb_add
+       ;;
+deconfig)
+       pb_remove
+       ;;
+*)
+       ;;
+esac
+
+echo "--- $1 ---" >> ${log}
+set >> ${log}
+echo "---------------" >> ${log}