Added policy files from old "initrd" project.
authorMichael Brown <mcb30@dolphin.home>
Mon, 19 Nov 2007 00:41:46 +0000 (00:41 +0000)
committerMichael Brown <mcb30@dolphin.home>
Mon, 19 Nov 2007 00:41:46 +0000 (00:41 +0000)
Makefile
policy/bin/welcome.sh [new file with mode: 0755]
policy/etc/group [new file with mode: 0644]
policy/etc/init.d/rcS [new file with mode: 0755]
policy/etc/inittab [new file with mode: 0644]
policy/etc/passwd [new file with mode: 0644]
policy/etc/protocols [new file with mode: 0644]
policy/usr/share/udhcpc/default.script [new file with mode: 0755]

index 5a95878..62de8bc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ SKEL_DEVS += /dev/urandom
 
 skeleton.bp : $(BOOTPACK)
        rm -rf skeleton
-       mkdir -p skeleton/{bin,dev,etc,lib,mnt,proc,sbin,sys}
+       mkdir -p skeleton/{bin,dev,etc,lib/modules,mnt,proc,sbin,sys}
        mkdir -p skeleton/{usr/{bin,sbin,share}}
        mkdir -p skeleton/{var/{lock,log,run}}
        $(BOOTPACK) -o $@ skeleton=/ $(SKEL_DEVS)
@@ -55,6 +55,23 @@ BOOTPACKS += busybox.bp
 clean ::
        $(MAKE) -C busybox clean
 
+# Policy boot pack
+
+POL_FILES :=
+POL_FILES += policy/etc/passwd
+POL_FILES += policy/etc/group
+POL_FILES += policy/etc/protocols
+POL_FILES += policy/etc/inittab
+POL_FILES += policy/etc/init.d/rcS
+POL_FILES += policy/usr/share/udhcpc/default.script
+POL_FILES += policy/bin/welcome.sh
+
+policy.bp : $(POL_FILES) $(BOOTPACK)
+       $(BOOTPACK) -o $@ \
+               `echo $(POL_FILES) | sed 's/policy\(\S*\)/policy\1=\1/g'`
+
+BOOTPACKS += policy.bp
+
 # Boot pack common instructions
 
 bootpacks : $(BOOTPACKS)
diff --git a/policy/bin/welcome.sh b/policy/bin/welcome.sh
new file mode 100755 (executable)
index 0000000..e0d9351
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+for arg in `cat /proc/cmdline`; do
+    if [ "${arg##bootfile=}" != "${arg}" ]; then
+       bootfile="${arg##bootfile=}"
+    fi
+done
+
+clear
+echo
+echo
+echo "gPXE Universal Boot"
+echo "==================="
+echo
+echo
+/sbin/lsmod
+echo
+echo
+/sbin/route
+echo
+echo
+echo "Booted from $bootfile:"
+echo
+wget -q "$bootfile" -O -
+echo
+
+export PS1="\u@\h:\w# "
+exec /bin/sh
diff --git a/policy/etc/group b/policy/etc/group
new file mode 100644 (file)
index 0000000..1dbf901
--- /dev/null
@@ -0,0 +1 @@
+root:x:0:
diff --git a/policy/etc/init.d/rcS b/policy/etc/init.d/rcS
new file mode 100755 (executable)
index 0000000..1047733
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+netdevs () {
+    egrep '^[[:space:]]*[[:alnum:]]*:' /proc/net/dev | cut -d: -f1
+}
+
+modules () {
+    find /lib/modules -type f
+}
+
+/bin/mount -t proc none /proc
+/bin/mount -t sysfs none /sys
+/usr/sbin/setlogcons 5
+/sbin/mdev -s
+/sbin/ifconfig lo up 127.0.0.1
+
+# Unzip any gzipped modules
+for module in `modules` ; do
+    if [ "${module%%.gz}" != "${module}" ]; then
+       gunzip $module
+    fi
+done
+
+# Load any modules
+for dummy in `modules` ; do
+    for module in `modules` ; do
+       name=`basename "${module%%.ko}"`
+       if ! lsmod | egrep "^$name[[:space:]]" > /dev/null ; then
+           insmod $module
+       fi
+    done
+done
+
+# Bring up any non-loopback net devices using udhcpc
+for netdev in `netdevs`; do
+    if [ "${netdev}" != "lo" ]; then
+       udhcpc $netdev
+    fi
+done
diff --git a/policy/etc/inittab b/policy/etc/inittab
new file mode 100644 (file)
index 0000000..0f3d5bd
--- /dev/null
@@ -0,0 +1,9 @@
+::sysinit:/etc/init.d/rcS
+::ctrlaltdel:/sbin/reboot
+::shutdown:/bin/umount -a -r
+::restart:/sbin/init
+
+tty1::respawn:-/bin/welcome.sh
+tty2::askfirst:-/bin/sh
+tty3::askfirst:-/bin/sh
+tty4::askfirst:-/bin/sh
diff --git a/policy/etc/passwd b/policy/etc/passwd
new file mode 100644 (file)
index 0000000..eb85a55
--- /dev/null
@@ -0,0 +1 @@
+root:x:0:0:root:/root:/bin/sh
diff --git a/policy/etc/protocols b/policy/etc/protocols
new file mode 100644 (file)
index 0000000..e111370
--- /dev/null
@@ -0,0 +1,3 @@
+ip     0       IP
+tcp    6       TCP
+udp    17      UDP
diff --git a/policy/usr/share/udhcpc/default.script b/policy/usr/share/udhcpc/default.script
new file mode 100755 (executable)
index 0000000..c9d98af
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+# Borrowed from http://www.doit.org/udhcpc/
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+
+RESOLV_CONF="/etc/resolv.conf"
+
+update_interface()
+{
+  [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
+  [ -n "$subnet" ] && NETMASK="netmask $subnet"
+  /sbin/ifconfig $interface $ip $BROADCAST $NETMASK
+}
+
+update_routes()
+{
+  if [ -n "$router" ]
+  then
+    while /sbin/route del default gw 0.0.0.0 dev $interface 2>/dev/null
+    do :
+    done
+
+    for i in $router
+    do
+      /sbin/route add default gw $i dev $interface
+    done
+  fi
+}
+
+update_hostname()
+{
+  if [ -n "$hostname" ]
+  then
+    hostname $hostname
+  fi
+}
+
+update_dns()
+{
+  echo -n > $RESOLV_CONF
+  [ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
+  for i in $dns
+  do
+    echo adding dns $i
+    echo nameserver $i >> $RESOLV_CONF
+  done
+}
+
+deconfig()
+{
+  /sbin/ifconfig $interface 0.0.0.0
+}
+
+case "$1" in
+  bound)
+    update_interface;
+    update_routes;
+    update_hostname;
+    update_dns;
+  ;;
+
+  renew)
+    update_interface;
+    update_routes;
+    update_dns;
+  ;;
+
+  deconfig)
+    deconfig;
+  ;;
+
+  *)
+    echo "Usage: $0 {bound|renew|deconfig}"
+    exit 1
+    ;;
+esac
+
+exit 0