merge of 8eaefa4f638dc67e29fb59fca3c6a98e4049eb09
authorMichael Lauer <mickey@vanille-media.de>
Sun, 24 Dec 2006 17:40:06 +0000 (17:40 +0000)
committerMichael Lauer <mickey@vanille-media.de>
Sun, 24 Dec 2006 17:40:06 +0000 (17:40 +0000)
     and f6f04acc928b89f8740f4f2ef14b479a36781bc5

35 files changed:
conf/distro/angstrom-2007.1.conf
packages/busybox/busybox-1.2.1/df_rootfs.patch [new file with mode: 0644]
packages/busybox/busybox_1.2.1.bb
packages/images/openprotium-image.bb
packages/initscripts/initscripts-1.0/openprotium/checkroot.sh [new file with mode: 0755]
packages/initscripts/initscripts-1.0/openprotium/devices.patch [deleted file]
packages/initscripts/initscripts-openprotium_1.0.bb
packages/meta/openprotium-packages.bb
packages/openprotium-init/.mtn2git_empty [new file with mode: 0644]
packages/openprotium-init/files/.mtn2git_empty [new file with mode: 0644]
packages/openprotium-init/files/boot/.mtn2git_empty [new file with mode: 0644]
packages/openprotium-init/files/boot/disk [new file with mode: 0644]
packages/openprotium-init/files/boot/flash [new file with mode: 0644]
packages/openprotium-init/files/boot/network [new file with mode: 0644]
packages/openprotium-init/files/boot/nfs [new file with mode: 0644]
packages/openprotium-init/files/boot/udhcpc.script [new file with mode: 0644]
packages/openprotium-init/files/conffiles [new file with mode: 0644]
packages/openprotium-init/files/functions [new file with mode: 0644]
packages/openprotium-init/files/initscripts/.mtn2git_empty [new file with mode: 0644]
packages/openprotium-init/files/initscripts/fixfstab [new file with mode: 0644]
packages/openprotium-init/files/initscripts/loadmodules.sh [new file with mode: 0644]
packages/openprotium-init/files/initscripts/rmrecovery [new file with mode: 0644]
packages/openprotium-init/files/initscripts/sysconfsetup [new file with mode: 0644]
packages/openprotium-init/files/initscripts/syslog.buffer [new file with mode: 0644]
packages/openprotium-init/files/initscripts/syslog.file [new file with mode: 0644]
packages/openprotium-init/files/initscripts/syslog.network [new file with mode: 0644]
packages/openprotium-init/files/initscripts/umountinitrd.sh [new file with mode: 0644]
packages/openprotium-init/files/links.conf [new file with mode: 0644]
packages/openprotium-init/files/modulefunctions [new file with mode: 0644]
packages/openprotium-init/files/reflash [new file with mode: 0644]
packages/openprotium-init/files/sysconf [new file with mode: 0644]
packages/openprotium-init/files/turnup [new file with mode: 0644]
packages/openprotium-init/openprotium-init_0.10.bb [new file with mode: 0644]
packages/slugos-init/files/reflash
packages/slugos-init/slugos-init_0.10.bb

index 59ef9d3..9f42680 100644 (file)
@@ -8,7 +8,7 @@
 
 #DISTRO_VERSION = "2007.3"
 DISTRO_VERSION = "test-${DATE}"
-DISTRO_REVISION = "26"
+DISTRO_REVISION = "27"
 
 require conf/distro/include/angstrom.inc
 require conf/distro/include/sane-srcdates.inc
@@ -94,6 +94,10 @@ PREFERRED_VERSION_freetype = "2.2.1"
 #fix screen corruption issues
 PREFERRED_VERSION_cairo = "1.3.10"
 
+#work around a segfault in gcc for armv4t
+PREFERRED_VERSION_glib-2.0_ep93xx = "2.12.3"
+PREFERRED_VERSION_glib-2.0_h6300  = "2.12.3"
+
 #Small machines prefer kdrive, but we might ship full Xorg in other images
 PREFERRED_PROVIDER_virtual/xserver ?= "xserver-kdrive"
 PREFERRED_PROVIDER_xserver ?= "xserver-kdrive"
diff --git a/packages/busybox/busybox-1.2.1/df_rootfs.patch b/packages/busybox/busybox-1.2.1/df_rootfs.patch
new file mode 100644 (file)
index 0000000..486318a
--- /dev/null
@@ -0,0 +1,34 @@
+--- busybox-1.2.1/coreutils/df.c.orig  2006-11-11 13:25:00.000000000 -0600
++++ busybox-1.2.1/coreutils/df.c       2006-11-11 13:23:15.000000000 -0600
+@@ -47,6 +47,7 @@
+       struct statfs s;
+       static const char hdr_1k[] = "1k-blocks"; /* default display is kilobytes */
+       const char *disp_units_hdr = hdr_1k;
++      int root_done = 0;
+ #ifdef CONFIG_FEATURE_HUMAN_READABLE
+       bb_opt_complementally = "h-km:k-hm:m-hk";
+@@ -112,16 +113,19 @@
+                                                                          ) / (blocks_used + s.f_bavail);
+                       }
+-                      if (strcmp(device, "rootfs") == 0) {
+-                              continue;
+-                      } else if (strcmp(device, "/dev/root") == 0) {
++                      if (strcmp(device, "/dev/root") == 0 || strcmp(device, "rootfs") == 0) {
+                               /* Adjusts device to be the real root device,
+                               * or leaves device alone if it can't find it */
+-                              if ((device = find_block_device("/")) == NULL) {
++                              if ((device = find_block_device(mount_point)) == NULL) {
+                                       goto SET_ERROR;
+                               }
+                       }
++                      if (strcmp(mount_point, "/") == 0) {
++                              if (root_done) continue;
++                              root_done = 1;
++                      }
++
+ #ifdef CONFIG_FEATURE_HUMAN_READABLE
+                       bb_printf("%-20s %9s ", device,
+                                         make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr));
index 36ffd03..9205b57 100644 (file)
@@ -1,8 +1,9 @@
 require busybox.inc
 
-PR = "r9"
+PR = "r10"
 
 SRC_URI += "file://wget-long-options.patch;patch=1 \
+          file://df_rootfs.patch;patch=1 \
            file://defconfig"
 
 do_configure () {
index ba25af3..5efb401 100644 (file)
@@ -18,11 +18,18 @@ USE_DEVFS = "1"
 # dev entries!)
 SLUGOS_DEVICE_TABLE = "${@bb.which(bb.data.getVar('BBPATH', d, 1), 'files/device_table-slugos.txt')}"
 
-# IMAGE_PREPROCESS_COMMAND is run before making the image.  In SlugOS the
-# kernel image is removed from the root file system to recover the space used -
-# SlugOS is assumed to boot from a separate kernel image in flash (not in the
-# root file system), if this is not the case the following must not be done!
-IMAGE_PREPROCESS_COMMAND += "rm ${IMAGE_ROOTFS}/boot/uImage*;"
+# IMAGE_PREPROCESS_COMMAND is run before making the image.  
+# We use this to do a few things:
+# . remove the uImage, which is in a separate part of the flash already.
+# . adjust the default run level (sysvinit is 5 by default, we like 3)
+# . set a default root password, which is no more secure than a blank one
+#      (since it is documented, in case you were wondering)
+# . make the boot more verbose
+#
+IMAGE_PREPROCESS_COMMAND += "rm ${IMAGE_ROOTFS}/boot/uImage-*;"
+IMAGE_PREPROCESS_COMMAND += "sed -i -es,^id:5:initdefault:,id:3:initdefault:, ${IMAGE_ROOTFS}/etc/inittab;"
+IMAGE_PREPROCESS_COMMAND += "sed -i -es,^root::0,root:BTMzOOAQfESg6:0, ${IMAGE_ROOTFS}/etc/passwd;"
+IMAGE_PREPROCESS_COMMAND += "sed -i -es,^VERBOSE=no,VERBOSE=very, ${IMAGE_ROOTFS}/etc/default/rcS;"
 
 # Always just make a new flash image.
 PACK_IMAGE = 'storcenter_pack_image;'
@@ -76,7 +83,7 @@ OPENPROTIUM_KERNEL = "kernel-module-dummy \
 
 RDEPENDS = " \
        kernel base-files base-passwd netbase \
-        busybox initscripts-openprotium slugos-init \
+        busybox initscripts-openprotium openprotium-init \
         update-modules sysvinit tinylogin \
        module-init-tools modutils-initscripts \
         ipkg-collateral ipkg ipkg-link \
@@ -101,11 +108,8 @@ IPKG_INSTALL = "${RDEPENDS}"
 inherit image_ipk
 
 storcenter_pack_image() {
-       ls -ltr ${DEPLOY_DIR_IMAGE}/uImage*
-       pwd
-       echo ${IMAGE_NAME}
        # find latest kernel
-       KERNEL=`ls -ltr ${DEPLOY_DIR_IMAGE}/uImage* | tail -1 | awk '{print $9}'`
+       KERNEL=`ls -tr ${DEPLOY_DIR_IMAGE}/uImage* | tail -1`
        if [ -z "$KERNEL" ]; then
                oefatal "No kernel found in ${DEPLOY_DIR_IMAGE}. Bitbake linux-storcenter to create one."
                exit 1
diff --git a/packages/initscripts/initscripts-1.0/openprotium/checkroot.sh b/packages/initscripts/initscripts-1.0/openprotium/checkroot.sh
new file mode 100755 (executable)
index 0000000..c69a773
--- /dev/null
@@ -0,0 +1,212 @@
+#
+# checkroot.sh Check to root filesystem.
+#
+# Version:     @(#)checkroot.sh  2.84  25-Jan-2002  miquels@cistron.nl
+#
+
+. /etc/default/rcS
+
+#
+# Set SULOGIN in /etc/default/rcS to yes if you want a sulogin to be spawned
+# from this script *before anything else* with a timeout, like SCO does.
+#
+test "$SULOGIN" = yes && sulogin -t 30 $CONSOLE
+
+#
+# Ensure that bdflush (update) is running before any major I/O is
+# performed (the following fsck is a good example of such activity :).
+#
+test -x /sbin/update && update
+
+#
+# Read /etc/fstab.
+#
+exec 9>&0 </etc/fstab
+rootmode=rw
+rootopts=rw
+test "$ENABLE_ROOTFS_FSCK" = yes && rootcheck="yes" || rootcheck="no"
+swap_on_md=no
+devfs=
+while read fs mnt type opts dump pass junk
+do
+       case "$fs" in
+               ""|\#*)
+                       continue;
+                       ;;
+               /dev/md*)
+                       # Swap on md device.
+                       test "$type" = swap && swap_on_md=yes
+                       ;;
+               /dev/*)
+                       ;;
+               *)
+                       # Might be a swapfile.
+                       test "$type" = swap && swap_on_md=yes
+                       ;;
+       esac
+       
+       test "$type" = devfs && devfs="$fs"
+
+       # Currently we do not care about the other entries
+       if test "$mnt" = "/"
+       then
+               #echo "[$fs] [$mnt] [$type] [$opts] [$dump] [$pass] [$junk]"
+
+               rootopts="$opts"                
+               roottype="$type"
+
+               #The "spinner" is broken on busybox sh  
+               TERM=dumb
+                       
+               test "$pass" = 0 -o "$pass" = "" && rootcheck=no
+               
+               # Enable fsck for ext2 and ext3 rootfs, disable for everything else                             
+               case "$type" in
+               ext2|ext3)      rootcheck=yes;;
+               *)              rootcheck=no;;
+               esac
+               
+               if test "$rootcheck" = yes
+               then
+                       if ! test -x "/sbin/fsck.${roottype}"
+                       then
+                               echo -e "\n * * * WARNING: /sbin/fsck.${roottype} is missing! * * *\n"
+                               rootcheck=no
+                       fi
+               fi
+               
+               case "$opts" in
+                       ro|ro,*|*,ro|*,ro,*)
+                               rootmode=ro
+                               ;;
+               esac
+       fi
+done
+exec 0>&9 9>&-
+
+#
+# Activate the swap device(s) in /etc/fstab. This needs to be done
+# before fsck, since fsck can be quite memory-hungry.
+#
+doswap=no
+test -d /proc/1 || mount -n /proc
+case "`uname -r`" in
+       2.[0123].*)
+               if test $swap_on_md = yes && grep -qs resync /proc/mdstat
+               then
+                       test "$VERBOSE" != no && echo "Not activating swap - RAID array resyncing"
+               else
+                       doswap=yes
+               fi
+               ;;
+       *)
+               doswap=yes
+               ;;
+esac
+if test $doswap = yes
+then
+       test "$VERBOSE" != no && echo "Activating swap"
+       swapon -a 2> /dev/null
+fi
+
+#
+# Check the root filesystem.
+#
+if test -f /fastboot || test $rootcheck = no
+then
+  test $rootcheck = yes && echo "Fast boot, no filesystem check"
+else
+  #
+  # Ensure that root is quiescent and read-only before fsck'ing.
+  #
+  mount -n -o remount,ro /
+  if test $? = 0
+  then
+    if test -f /forcefsck
+    then
+       force="-f"
+    else
+       force=""
+    fi
+    if test "$FSCKFIX" = yes
+    then
+       fix="-y"
+    else
+       fix="-a"
+    fi
+    spinner="-C"
+    case "$TERM" in
+        dumb|network|unknown|"") spinner="" ;;
+    esac
+    test `uname -m` = s390 && spinner="" # This should go away
+    test "$VERBOSE" != no && echo "Checking root filesystem..."
+    fsck $spinner $force $fix /
+    #
+    # If there was a failure, drop into single-user mode.
+    #
+    # NOTE: "failure" is defined as exiting with a return code of
+    # 2 or larger.  A return code of 1 indicates that filesystem
+    # errors were corrected but that the boot may proceed.
+    #
+    
+    echo "RETURNCODE: [$RTC]"
+    
+    if test "$RTC" -gt 3
+    then
+    
+      # Since this script is run very early in the boot-process, it should be safe to assume that the
+      # output is printed to VT1. However, some distributions use a bootsplash to hide the "ugly" boot
+      # messages and having the bootsplash "hang" due to a waiting fsck prompt is less than ideal
+      chvt 1
+    
+      # Surprise! Re-directing from a HERE document (as in
+      # "cat << EOF") won't work, because the root is read-only.
+      echo
+      echo "fsck failed.  Please repair manually and reboot. " 
+      echo "Please note that the root filesystem is currently "
+      echo "mounted read-only.  To remount it read-write:"
+      echo
+      echo "   # mount -n -o remount,rw /"
+      echo
+      echo "CONTROL-D will exit from this shell"
+      echo "and REBOOT the system."
+      echo
+      # Start a single user shell on the console
+      /sbin/sulogin $CONSOLE
+      reboot -f
+    fi
+  else
+    echo "*** ERROR!  Cannot fsck root fs because it is not mounted read-only!"
+    echo
+  fi
+fi
+
+devrootfound=$(grep "/dev/root" /proc/mounts | \
+        awk '{if ($4 = /rw/) print "found";}' )                                 
+
+if [ -n "$devrootfound" -a "$devrootfound" = "found" ]; then
+       echo "Read/write /dev/root found."            
+       exit 0                                                   
+fi
+
+if mount -vf -o remount / 2> /dev/null | \
+       awk '{if ($6 ~ /rw/) exit 0; else exit 1; }' && \
+       ! touch -c / 2> /dev/null 
+       then
+               echo " Remounting root filesystem read/write"
+               mount -n -o remount,$rootmode /
+fi
+
+if test "$rootmode" = rw
+then
+       if test ! -L /etc/mtab
+       then
+               rm -f /etc/mtab~ /etc/nologin
+               : > /etc/mtab
+       fi
+       mount -f -o remount /
+       mount -f /proc
+       test "$devfs" && grep -q '^devfs /dev' /proc/mounts && mount -f "$devfs"
+fi
+
+: exit 0
diff --git a/packages/initscripts/initscripts-1.0/openprotium/devices.patch b/packages/initscripts/initscripts-1.0/openprotium/devices.patch
deleted file mode 100644 (file)
index 2583b62..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# Patch to allow /dev to reside permanently in the file
-# system.
-#
---- old/devices        2005-05-28 21:51:39.012078699 -0700
-+++ new/devices        2005-06-12 00:16:29.222686303 -0700
-@@ -6,7 +6,7 @@
- . /etc/default/rcS
- # exit without doing anything if udev is active
--if test -e /dev/.udev -o -e /dev/.udevdb; then
-+if test -e /dev/.udev -o -e /dev/.udevdb -o -e /dev/.permanent; then
-       exit 0
- fi
-@@ -37,12 +37,20 @@
-       mknod /dev/ppp c 108 0
-       if test "$VERBOSE" != "no"; then echo "done"; fi
- else
--      if test "$VERBOSE" != "no"; then echo -n "Mounting /dev ramdisk: "; fi
--      mount -t ramfs ramfs /dev || mount -t tmpfs ramfs /dev
--      if test $? -ne 0; then
--              if test "$VERBOSE" != "no"; then echo "failed"; fi
-+      if test -e /dev/.noram
-+      then
-+              # There should be no files, any files will damage the
-+              # makedevs script below.
-+              rm $(find /dev -type f -print)
-+              :>/dev/.noram
-       else
--              if test "$VERBOSE" != "no"; then echo "done"; fi
-+              if test "$VERBOSE" != "no"; then echo -n "Mounting /dev ramdisk: "; fi
-+              mount -t ramfs ramfs /dev || mount -t tmpfs ramfs /dev
-+              if test $? -ne 0; then
-+                      if test "$VERBOSE" != "no"; then echo "failed"; fi
-+              else
-+                      if test "$VERBOSE" != "no"; then echo "done"; fi
-+              fi
-       fi
-       if test "$VERBOSE" != "no"; then echo -n "Populating /dev: "; fi
-       cd /
-@@ -60,6 +68,10 @@
-               if test "$VERBOSE" != "no"; then echo "failed"; fi
-       else
-               if test "$VERBOSE" != "no"; then echo "done"; fi
-+              if test -e /dev/.noram
-+              then
-+                      :>/dev/.permanent
-+              fi
-       fi
- fi
index 4266211..31f25ce 100644 (file)
@@ -23,7 +23,7 @@ SRC_URI += "file://openprotium/devices"
 SRC_URI += "file://openprotium/halt"
 SRC_URI += "file://openprotium/reboot"
 SRC_URI += "file://openprotium/flashclean"
-SRC_URI += "file://openprotium/devices.patch;patch=1"
+SRC_URI += "file://openprotium/checkroot.sh"
 
 # Without this it is not possible to patch checkroot.sh
 S = "${WORKDIR}"
@@ -43,6 +43,7 @@ do_install_append() {
        install -m 0755 ${WORKDIR}/openprotium/reboot   ${D}${sysconfdir}/init.d
        install -m 0755 ${WORKDIR}/openprotium/devices  ${D}${sysconfdir}/init.d
        install -m 0755 ${WORKDIR}/openprotium/flashclean  ${D}${sysconfdir}/init.d
+       install -m 0755 ${WORKDIR}/openprotium/checkroot.sh  ${D}${sysconfdir}/init.d
 
        # Remove the do install links (this detects a change to the
        # initscripts .bb file - it will cause a build failure here.)
index ec4261f..47f0cfe 100644 (file)
@@ -5,7 +5,7 @@
 DESCRIPTION = "Packages that are compatible with the Openprotium on the iomega Storcenter"
 HOMEPAGE = "http://www.openprotium.org"
 LICENSE = "MIT"
-PR = "r1"
+PR = "r2"
 CONFLICTS = "db3"
 PROVIDES += "${OPENPROTIUM_IMAGENAME}-packages"
 
@@ -34,15 +34,28 @@ ALLOW_EMPTY = "1"
 #      wakelan \
 #      wireless-tools \
 #      wpa-supplicant \
+#      bluez-utils-nodbus \
+#      libxml2 \
 #      madwifi-ng \
 #      motion \
+#      ftpd-topfield \
+#      eciadsl \
 #      netpbm \
 #      reiserfsprogs reiser4progs \
+#      libgphoto2 \
+#      python \
 #      mpd \
+#      memtester \
+#      puppy \
+#      samba \
+#      sane-backends \
+#      vsftpd \
+#      zd1211 \
 
-OPENIOM_PACKAGES = "\
+OPENPROTIUM_PACKAGES = "\
        alsa-lib \
        alsa-utils \
+       apache2 \
        audiofile \
        aumix \
        autoconf \
@@ -51,7 +64,6 @@ OPENIOM_PACKAGES = "\
        bind \
        binutils \
        bison \
-       bluez-utils-nodbus \
        bridge-utils \
        bzip2 \
        ccxstream \
@@ -68,7 +80,6 @@ OPENIOM_PACKAGES = "\
        dnsmasq \
        e2fsprogs \
        e2fsprogs-libs \
-       eciadsl \
        expat \
        ez-ipupdate \
        fetchmail \
@@ -76,7 +87,7 @@ OPENIOM_PACKAGES = "\
        findutils \
        flex \
        flite \
-       ftpd-topfield \
+       gallery \
        gawk \
        gcc \
        gdbm \
@@ -95,7 +106,6 @@ OPENIOM_PACKAGES = "\
        less \
        libao \
        libdvb \
-       libgphoto2 \
        libid3tag \
        liblockfile \
        libmad \
@@ -107,7 +117,6 @@ OPENIOM_PACKAGES = "\
        libupnp \
        libusb \
        libvorbis \
-       libxml2 \
        litestream \
        lrzsz \
        lsof \
@@ -117,11 +126,11 @@ OPENIOM_PACKAGES = "\
        mailx \
        make \
        mdadm \
-       memtester \
        mgetty \
        miau \
        microcom \
        minicom \
+       modphp \
        mt-daapd \
        mtd-utils \
        mutt \
@@ -145,15 +154,11 @@ OPENIOM_PACKAGES = "\
        pkgconfig \
        ppp \
        procps \
-       puppy \
        pvrusb2-mci \
        pwc \
-       python \
        quilt \
        rng-tools \
        rsync \
-       samba \
-       sane-backends \
        sed \
        setpwc \
        setserial \
@@ -171,10 +176,8 @@ OPENIOM_PACKAGES = "\
        util-linux \
        vim \
        vlan \
-       vsftpd \
        watchdog \
        wget \
-       zd1211 \
        zip \
        zlib \
        "
@@ -249,14 +252,14 @@ SLUGOS_OPTIONAL_PACKAGES = "\
 # you can place these in the top level openembedded/conf/distro/openprotium.conf
 # file to fine-tune what's happening
 #
-OPENIOM_EXTRA_PACKAGES ?= ""
+OPENPROTIUM_EXTRA_PACKAGES ?= ""
 
 # The package-index at the end causes regeneration of the Packages.gz and
 # other control files.
 # openprotium-native \
 DEPENDS = "\
        openprotium-image \
-       ${OPENIOM_PACKAGES} \
-       ${OPENIOM_EXTRA_PACKAGES} \
+       ${OPENPROTIUM_PACKAGES} \
+       ${OPENPROTIUM_EXTRA_PACKAGES} \
        package-index \
        "
diff --git a/packages/openprotium-init/.mtn2git_empty b/packages/openprotium-init/.mtn2git_empty
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/packages/openprotium-init/files/.mtn2git_empty b/packages/openprotium-init/files/.mtn2git_empty
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/packages/openprotium-init/files/boot/.mtn2git_empty b/packages/openprotium-init/files/boot/.mtn2git_empty
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/packages/openprotium-init/files/boot/disk b/packages/openprotium-init/files/boot/disk
new file mode 100644 (file)
index 0000000..b4bbaf1
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/sh
+# boot from the hard disk partition "$1" (which
+# must be given) using options from the rest of
+# the command line.
+#
+# Use the standard init path (see /etc/init.d/rcS)
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin
+#
+# Load the helper functions
+. /etc/default/functions
+. /etc/default/modulefunctions
+#
+#
+if test -n "$1"
+then
+       device="$1"
+       shift
+        # proc is needed for UUID mount and module load
+        mount -t proc proc /proc
+        # load USB & SCSI storage modules (/proc required!)
+       if [ "$(machine)" != "storcenter" ]; then
+               echo "boot: loading modules required for disk boot"
+               loaddiskmods
+               # waiting for disk (FIXME)
+               sleep=6
+               test "$sleep" -gt 0 && sleep "$sleep"
+       else
+               # make the device links so turnup can use short disk names.
+               # probably only necessary on devfs based systems.
+               /etc/init.d/devices start
+               scc -l redflash -f auto
+       fi
+       #
+       # fire the boot
+       echo "boot: rootfs: mount $* $device [$UUID]"
+       #
+       # Mount read-write because before exec'ing init
+       # If a UUID is given (in the environment) this
+       # is used in preference to the device, but if
+       # the UUID mount fails a standard device mount
+       # is attempted.
+       if      test -n "$UUID" &&
+               mount "$@" -U "$UUID" /mnt ||
+               mount "$@" "$device" /mnt
+       then
+               # checkmount checks for sh, chroot, init
+               # and /mnt (i.e. /mnt/mnt in this case)
+               if checkmount /mnt
+               then
+                       # if mounted, then move /dev to the new root
+                       mount --bind /dev /mnt/dev
+                       # pivot to /initrd if available, else /mnt
+                       cd /
+                       if test -d /mnt/initrd
+                       then
+                               swivel mnt initrd
+                       else
+                               swivel mnt mnt
+                       fi
+                       # swivel failed
+               fi
+               # Failure: unmount the partition
+               umount /mnt
+       fi
+fi
+# fallback - use the flash boot
+exec /boot/flash
diff --git a/packages/openprotium-init/files/boot/flash b/packages/openprotium-init/files/boot/flash
new file mode 100644 (file)
index 0000000..40f64c9
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+# boot from the current (flash) root partition
+# nothing need be done apart from setting the
+# system LED status correctly
+. /etc/default/functions
+scc -l redflash -f auto
+test -x /sbin/init && exec /sbin/init
+# fallback if /sbin/init has been deleted (bad!)
+scc -l red 
+exec <>/dev/console >&0 2>&0
+test -x /sbin/sulogin && exec /sbin/sulogin
+test -x /bin/sh && exec /bin/sh
+exit 1
diff --git a/packages/openprotium-init/files/boot/network b/packages/openprotium-init/files/boot/network
new file mode 100644 (file)
index 0000000..599250e
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+# bring up the network before boot, used to allow
+# netconsole logging and NFS boot.  This runs out
+# of flash, but that's ok because the script doesn't
+# leave any process running.
+#
+# NOTE: /etc/default/functions defines ifup as a shell
+# function!
+. /etc/default/functions
+#
+# Now all the information for booting should be in the configuration
+# file.  Config the loopback and network interfaces.
+ifconfig lo 127.0.0.1 up
+iface="$(config iface)"
+test -n "$iface" && ifup "$iface"
+# exit code is true only if the interface config has succeeded
diff --git a/packages/openprotium-init/files/boot/nfs b/packages/openprotium-init/files/boot/nfs
new file mode 100644 (file)
index 0000000..7cfce66
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+# boot from the nfs partition "$1" (which
+# must be given) using options from the rest of
+# the command line.
+#
+# Use the standard init path (see /etc/init.d/rcS)
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin
+#
+. /etc/default/functions
+scc -l redflash -f auto
+#
+if /boot/network
+then
+       # network is up and running, the NFS mount will
+       # now succeed (possibly), use /boot/disk
+       exec /boot/disk "$@"
+fi
+# fallback - use the flash boot
+exec /boot/flash
diff --git a/packages/openprotium-init/files/boot/udhcpc.script b/packages/openprotium-init/files/boot/udhcpc.script
new file mode 100644 (file)
index 0000000..3f437e3
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+# executed by udhcpc to do the real work of configuring an interface
+# writes the result (if any) to file descriptor 9
+case "$1" in
+deconfig)      # ignored
+       :;;
+renew|bound)   # this gives the real information
+       test -n "$ip" && {
+               echo "ip='$ip'"
+               echo "subnet='$subnet'"
+               echo "broadcast='$broadcast'"
+               echo "router='$router'"
+       } >&9;;
+leasefail)     # ignore - probably no dhcp server
+       :;;
+*)     echo "udhcpc: $*: command not recognised" >&2;;
+esac
diff --git a/packages/openprotium-init/files/conffiles b/packages/openprotium-init/files/conffiles
new file mode 100644 (file)
index 0000000..e1408a3
--- /dev/null
@@ -0,0 +1,55 @@
+# conffiles
+# Known SlugOS configuration files.  These files are preserved on
+# a flash upgrade.  Other configuration files, found from:
+#
+#    /usr/lib/ipkg/*.conffiles
+#    /etc/*.conf
+#
+# are preserved too with an operation of 'diff' if they have been
+# changed since /etc/.configured was created.
+#
+# Lines starting with # are comments, other lines have
+# two fields:
+#
+# operation file 
+#
+# The file must *NOT* have a leading /
+#
+# operation may be:
+#   ignore    Do not preserve this file
+#   preserve  Preserve this file unconditionally
+#   diff      Compare file with the new version, ask if different
+#
+preserve       linuxrc
+preserve       etc/.configured
+preserve       etc/TZ
+diff           etc/default/conffiles
+diff           etc/default/devpts
+preserve       etc/default/rcS
+preserve       etc/default/sysconf
+diff           etc/default/usbd
+preserve       etc/defaultdomain
+preserve       etc/dropbear/dropbear_dss_host_key
+preserve       etc/dropbear/dropbear_rsa_host_key
+preserve       etc/ssh/ssh_host_dsa_key
+preserve       etc/ssh/ssh_host_dsa_key.pub
+preserve       etc/ssh/ssh_host_rsa_key
+preserve       etc/ssh/ssh_host_rsa_key.pub
+preserve       etc/fstab
+preserve       etc/group
+preserve       etc/gshadow
+preserve       etc/hostname
+preserve       etc/hosts
+preserve       etc/localtime
+ignore         etc/modules
+ignore         etc/modules.conf
+preserve       etc/motd
+preserve       etc/network/interfaces
+preserve       etc/ntp.drift
+preserve       etc/passwd
+preserve       etc/profile
+preserve       etc/resolv.conf
+preserve       etc/shadow
+preserve       etc/syslog.conf
+preserve       etc/timezone
+preserve       root/.ssh/authorized_keys
diff --git a/packages/openprotium-init/files/functions b/packages/openprotium-init/files/functions
new file mode 100644 (file)
index 0000000..25832cf
--- /dev/null
@@ -0,0 +1,413 @@
+#!/bin/sh
+# . this file to load the following utility functions
+#
+# hardware
+#  the 'Hardware' string from cpuinfo, or, if not found
+#  try a little harder with 'machine'
+hardware(){
+       local hdw
+        hdw=`sed -n 's!^Hardware       *: !!p' /proc/cpuinfo`
+       test -n "$hdw" || {
+               hdw=`sed -n 's!^machine         *: !!p' /proc/cpuinfo`
+       }
+       echo $hdw
+}
+#
+# machine
+#  outputs an identifier of the current machine - i.e. the board
+#  slugos is running on.
+machine(){
+       case "$(hardware)" in
+       *Coyote*)       echo coyote;;
+       *IXDPG425*)     echo ixdpg425;;
+       *WRV54G*)       echo wrv54g;;
+       *IXDP425*)      echo ixdp425;;
+       *IXDP465*)      echo ixdp465;;
+       *IXCDP1100*)    echo ixcdp1100*;;
+       *Avila*)        echo avila;;
+       *Loft*)         echo loft;;
+       *NAS?100d*)     echo nas100d;;
+       *NSLU2*)        echo nslu2;;
+       *StorCenter*)   echo storcenter;;
+       *)              echo unknown;;
+       esac
+}
+#
+# single_user_ok
+#  if the machine is capable of single user interaction return
+#  true, else return false.  The result of this function is
+#  preempted by setting SULOGIN to 'yes' or 'ok' in /etc/default/rcS
+single_user_ok() {
+       # list known good machines in the 'case'
+       test "$SULOGIN" = yes -o "$SULOGIN" = ok ||
+               case "$(machine)" in
+               ixdp*|avila|loft)
+                       test "$SULOGIN" != never;;
+               *)      return 1;;
+               esac
+}
+#
+# load_functions "source"
+#  load the functions in '/sbin/source' - relies on /sbin/source being
+#  a shell script and having support for this function.
+load_functions(){
+       test -n "$1" -a -x "/sbin/$1" && . "/sbin/$1" || {
+               echo "$0: /sbin/$1: script not found" >&2
+               return 1
+       }
+}
+#
+# mtdev "name"
+#  return (output) the character device name for flash parition "name"
+#  /proc/mtd has the general form:
+#    dev:    size   erasesize  name
+#    mtd5: 00020000 00020000 "FIS directory"
+#  use this rather than hard-wiring the device because the partition
+#  table can change - looking in /proc/mtd is more reliable.
+mtdev(){
+       if test $(machine) = storcenter ; then                               
+       sed -n 's!^mtd\([0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/mtd/\1!p' /proc/mtd
+       else
+       sed -n 's!^\(mtd[0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/\1!p' /proc/mtd
+       fi
+}
+#
+# mtblockdev "name"
+#  as mtdev but output the name of the block (not character) device
+mtblockdev(){
+       if test "$(machine)" = storcenter ; then
+       sed -n 's!^mtd\([0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/mtdblock/\1!p' /proc/mtd
+       else
+       sed -n 's!^mtd\([0-9][0-9]*\):[^"]*"'"$1"'"$!/dev/mtdblock\1!p' /proc/mtd
+       fi
+}
+#
+# mtsize "name"
+#  the size of the partition as a hexadecimal value (with 0x at the front)
+mtsize(){
+       sed -n 's!^mtd[0-9][0-9]*: \([^ ]*\)[^"]*"'"$1"'"$!0x\1!p' /proc/mtd
+}
+#
+# sysvalmatch "section" "name" 'pattern' "configuration file"
+# sysvalof "section" "name" "configuration file"
+# sysval "section" "name"
+#  outputs the value of the SysConf variable 'name' from section 'section',
+#  if there are multiple definitions only the last is output
+# NOTE: these functions should only be used internally, add entries to 'config'
+#  below if necessary.  This is because 'config' does the defaulting.
+sysvalmatch(){
+       sed -n '/^\['"$1"'\]$/,/^\[.*\]$/s/^'"$2"'=\('"$3"'\)$/\1/p' "$4" | sed -n '$p'
+}
+sysvalof(){
+       sysvalmatch "$1" "$2" '.*' "$3"
+}
+sysval(){
+       test -r "$config_root/etc/default/sysconf" &&
+               sysvalof "$1" "$2" "$config_root/etc/default/sysconf"
+}
+#
+# syssection "section"
+#  outputs all the values from the given section changed to the format "name value"
+#  (i.e. the '=' is dropped).
+syssection(){
+       test -r "$config_root/etc/default/sysconf" &&
+               sed -n '/^\['"$1"'\]$/,/^\[.*\]$/s/^\([^=]*\)=\(.*\)$/\1 \2/p' "$config_root/etc/default/sysconf"
+}
+#
+# config "value"
+#  convenience callers for specific values to avoid mis-typing in scripts
+#  NOTE: this function does the defaulting, 'sysval' does not!
+# config_root: if set this will override the root where config/sysval
+#              looks for /etc/default/sysconf
+config(){
+       local mac
+       mac="$(test -r /proc/net/maclist &&
+               sed -n '/^[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]$/p' /proc/net/maclist |
+               sed -n 1p)"
+       #
+       case "$1" in
+       mac)    test -n "$mac" && echo "$mac";;
+       host)   if test -n "$(sysval network disk_server_name)"
+               then
+                       sysval network disk_server_name
+               elif test -n "$(sysval network default_server_name)"
+               then
+                       sysval network default_server_name
+               elif test -n "$mac"
+               then
+                       echo "$mac" | sed -n 's/^\(..\):\(..\):\(..\):\(..\):\(..\):\(..\)$/slug\1\2\3\4\5\6/p'
+               else
+                       # because we want the name to remain constant:
+                       echo "openprotium"
+               fi;;
+       domain) sysval network w_d_name;;
+       iface)  if test -n "$(sysval network lan_interface)"
+               then
+                       sysval network lan_interface
+               else
+                       echo eth0
+               fi;;
+       ip)     if test -n "$(sysval network ip_addr)"
+               then
+                       sysval network ip_addr
+               else
+                       echo 192.168.1.16
+               fi;;
+       netmask)sysval network netmask;;
+       gateway)sysval network gateway;;
+       dns)    sysval network dns_server1;;
+       dns2)   sysval network dns_server2;;
+       dns3)   sysval network dns_server3;;
+       boot)   if test -n "$(sysval network bootproto)"
+               then
+                       sysval network bootproto
+               else
+                       echo dhcp
+               fi;;
+       valid)  test -r "$config_root/etc/default/sysconf" -a -n "$mac";;
+       *)      return 1;;
+       esac
+}
+#
+# checkif "iface"
+#  Validate an interface name by making sure that it exists
+#  in /proc/net/dev (and is not lo).  The listing outputs the
+#  interface followed by a :, the check function looks for
+#  something of the form '$1[a-zA-Z0-9]*:' and outputs the
+#  part preceding the ':'
+checkif(){
+       sed -n '/^[     ]*lo:/d;s/^[    ]*\('"$1"'[a-zA-Z0-9]*\):.*$/\1/p;tE;d;:E;q' /proc/net/dev
+}
+#
+# checkmount "mountpoint"
+#  tests an already mounted mountpoint to see whether to attempt to
+#  boot with this as root.  Returns success if it appears ok.
+checkmount(){
+       # basic test for init (the kernel will try to load this)
+       # but require a shell in bin/sh too
+       test    \( -d "$1/mnt" \) -a \
+               \( -x "$1/bin/sh" -o -h "$1/bin/sh" \) -a \
+               \( -x "$1/usr/sbin/chroot" -o -h "$1/usr/sbin/chroot" -o \
+                  -x "$1/sbin/chroot" -o -h "$1/sbin/chroot" \) -a \
+               \( -x "$1/sbin/init" -o -h "$1/sbin/init" -o \
+                  -x "$1/etc/init" -o -h "$1/etc/init" -o \
+                  -x "$1/bin/init" -o -h "$1/bin/init" \)
+}
+#
+# swivel "new root" "old root"
+#  NOTE: the arguments must be paths relative to /, bad things
+#  will happen if the arguments themselves start with /
+#  Pivot to a new root.  This does all the fancy pivot_root stuff
+#  including closing streams and does a umount /proc - it doesn't
+#  matter if this fails (failure codes are ignored), but if /proc
+#  was mounted it must be restored by the caller on return.
+#  Normally this function never returns!
+#  On return 0,1,2 are connected to /dev/console - this may not
+#  have been true before!
+swivel(){
+       cd "$1"
+       exec <&- >&- 2>&-
+       # This is just-in-case the called mounted /proc and was
+       # unable to close it because of the streams
+       umount /proc 2>/dev/null
+       if pivot_root . "$2"
+       then
+               # everything must move out of the old root, this process
+               # is $2/bin/sh so it must die, IO is redirected
+               # just in case - typically it will be to a device so it
+               # won't hold the old root open.
+               # the exec here is the first point at which the old root
+               # is unused - before the exec regardless of the close of
+               # 0,1,2 above ash still has *this* shell script open!
+               # (it's on fd 10).
+               # init closes all file descriptors, there's no point
+               # supplying it with fds.
+               # NOTE: this used to use $2/usr/sbin/chroot, however on
+               # linux / is already . when the command is executed
+               # therefore it is essential to use the local (new root)
+               # chroot to ensure it gets the correct shared libraries.
+               if test -x usr/sbin/chroot -o -h usr/sbin/chroot
+               then
+                       chroot=usr/sbin/chroot
+               elif test -x sbin/chroot -o -h sbin/chroot
+               then
+                       chroot=sbin/chroot
+               else
+                       chroot=chroot
+               fi
+               #
+               exec "$chroot" . bin/sh -c "\
+                       test -x sbin/init && exec sbin/init
+                       test -x etc/init && exec etc/init
+                       test -x bin/init && exec bin/init
+                       mount -t sysfs sysfs /mnt
+                       umount /mnt
+                       sync;sync;sync
+                       exit 1"
+       fi
+       #
+       # recovery - must restore the old root
+       cd "$2"
+       sbin/pivot_root . "$1"
+       # cd is back to $1 - either pivot_root doesn't change it and the
+       # chroot above was not executed, or pivot_root does change it and
+       # has just changed it back!
+       exec <>/dev/console >&0 2>&0
+}
+#
+# ifup "interface"
+#  bring that interface up with the configured ip and other
+#  information
+ifup(){
+       local ip hostname router subnet iface HOSTNAME NETMASK BROADCAST
+
+       iface="$1"
+       ip="$(config ip)"
+       hostname="$(config host)"
+       router="$(config gateway)"
+       broadcast=
+
+       if test -n "$ip"
+       then
+               # only if an ip was specified
+               subnet="$(config netmask)"
+       else
+               ip=192.168.1.77
+       fi
+
+       # First try udhcpc - note that the /boot/udhcpc.script
+       # simply records the values returned and the udhcpc
+       # is not left running so this will only work for
+       # the lease length time!
+       ifconfig "$iface" up
+       if test "$(config boot)" != static
+       then
+               test -n "$hostname" && HOSTNAME="-H $hostname"
+               # The script writes the required shell variable assignments
+               # to file descriptor 9
+               eval $(udhcpc -i "$iface" -n -q -r "$ip" $HOSTNAME -s /boot/udhcpc.script 9>&1 >/dev/null)
+       fi
+
+       test -n "$broadcast" && BROADCAST="broadcast $broadcast"
+       test -n "$subnet" && NETMASK="netmask $subnet"
+
+       if ifconfig "$iface" "$ip" $NETMASK $BROADCAST
+       then
+               for route in $router
+               do
+                       route add default gw "$route" dev "$iface"
+               done
+               return 0
+       else
+               ifconfig "$iface" down
+               return 1
+       fi
+}
+#
+# ifdown "interface"
+#  take the interface down
+ifdown(){
+       ifconfig "$1" down
+}
+#
+# mountflash "flash device" "flash root directory" {mount options}
+#  Finds and mounts the flash file system on the given directory
+mountflash(){
+       local ffsdev ffsdir
+
+       ffsdev="$1"
+       test -n "$ffsdev" -a -b "$ffsdev" || {
+               echo "$0: unable to find flash file system to copy ($ffsdev)" >&2
+               return 1
+       }
+       shift
+
+       ffsdir="$1"
+       test -n "$ffsdir" -a -d "$ffsdir" || {
+               echo "$0: mountflash $ffsdir: not a directory (internal error)" >&2
+               return 1
+       }
+       shift
+
+       mount -t jffs2 "$@" "$ffsdev" "$ffsdir" || {
+               echo "$0: $ffsdev: unable to mount flash file system on $ffsdir" >&2
+               return 1
+       }
+       return 0
+}
+#
+# umountflash [-r] "flash device"
+#  unmount any instance of the given flash device, if -r is specified a mount on
+#  root is an error, otherwise a mount on root is ignored (and remains).
+umountflash(){
+       local rootok ffsno ffsdev
+       rootok=1
+       case "$1" in
+       -r)     rootok=
+               shift;;
+       esac
+       #
+       # The argument is ffsdev
+       ffsdev="$1"
+       ffsno="$(devio "<<$ffsdev" prd)"
+       test -n "$ffsno" -a "$ffsno" -ge 0 || {
+               echo "$0: $ffsdev: device number $ffsno is not valid, cannot continue." >&2
+               return 1
+       }
+       #
+       # Make sure that Flashdisk isn't mounted on /
+       if test -z "$rootok" -a "$(devio "<</etc/init.d/sysconfsetup" prd)" -eq "$ffsno"
+       then
+               echo "$0: $ffsdev is mounted on /, use turnup ram" >&2
+               return 1
+       fi
+       #
+       # The function is currently always used interactively, so output 
+       echo "$0: umounting any existing mount of $ffsdev" >&2
+       #
+       # check each mount point, do this last first because otherwise nested
+       # mounts of ffsdev cannot be umounted.
+       ffs_umount() {
+               local device mp type options stuff
+
+               read device mp type options stuff
+               test -z "$device" && return 0
+
+               # handle following entries first
+               ffs_umount || return 1
+
+               # handle this entry, since this is currently only used for unmounting
+               # the flash root partition we know a file which must exist...
+               case "$mp/$type" in
+               //jffs2);; # skip /
+               */jffs2)test "$(devio "<<$mp/etc/init.d/sysconfsetup" prd 2>/dev/null)" -ne "$ffsno" ||
+                       umount "$mp" || {
+                               echo "$0: $mp: unable to umount $ffsdev" >&2
+                               return 1
+                       };;
+               esac
+
+               return 0
+       }
+       #
+       ffs_umount </proc/mounts || {
+               echo "$0: umount $ffsdev from all mount points then re-run $0" >&2
+               return 1
+       }
+
+       return 0
+}
+
+#
+# uuid_by_partition
+#  output a list of partitions and their UUIDs
+uuid_by_partition() {
+       blkid -c /dev/null -s UUID | sed -n 's/^\([^:]*\): .*UUID="\([^"]*\)".*$/\1 \2/p'
+}
+
+#
+# partition_of uuid
+#  return the partition corresponding to the UUID
+partition_of() {
+       sed -n 's/^\([^ ]*\) '"$1"'$/\1/p'
+}
diff --git a/packages/openprotium-init/files/initscripts/.mtn2git_empty b/packages/openprotium-init/files/initscripts/.mtn2git_empty
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/packages/openprotium-init/files/initscripts/fixfstab b/packages/openprotium-init/files/initscripts/fixfstab
new file mode 100644 (file)
index 0000000..67116a1
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/sh
+# validate /etc/fstab against the current UUID list in
+# /etc/uuid_by_partition
+#
+. /etc/default/functions
+pfile=/etc/uuid_by_partition
+
+#
+# use debug to find out what is going on
+test "$1" = start -o "$1" = debug || exit 0
+
+#
+# obtain the current list of parititions with UUIDs
+newlist="$(uuid_by_partition)"
+
+if test -r "$pfile"
+then
+       # read the old list
+       oldlist="$(cat "$pfile")"
+       #
+       # if it hasn't changed nothing need be done
+       test "$newlist" = "$oldlist" && exit 0
+       #
+       # it has changed, but this only matters if
+       # a previously existing uuid has moved, build
+       # a list of old device vs new device for every
+       # uuid which has moved
+       changedlist="$(
+               {       echo "$oldlist"
+                       echo "$newlist"
+               } | awk 'device[$2] == ""{device[$2] = $1}
+                       device[$2] != $1{print device[$2], $1}')"
+
+       if test -n "$changedlist"
+       then
+               # at least one partition has moved, scan the
+               # current fstab to see if it has a reference
+               # to this partition
+               changedfstab="$(
+                       {       echo "$changedlist"
+                               echo '#fstab'
+                               cat /etc/fstab
+                       } | awk 'BEGIN{list=1}
+                               list==1 && $0=="#fstab"{list=0; continue}
+                               list==1{new[$1] = $2; continue}
+                               new[$1] != ""{print $1, new[$1]}')"
+
+               # if this list is not empty edit the fstab
+               if test -n "$changedfstab"
+               then
+                       rm -f /tmp/fstab.$$
+                       # if the edit fails then do not overwrite the old
+                       # partition list - just exit with an error
+                       {       echo "$changedlist"
+                               echo '#fstab'
+                               cat /etc/fstab
+                       } | awk 'BEGIN{list=1}
+                               list==1 && $0=="#fstab"{list=0; continue}
+                               list==1{new[$1] = $2; continue}
+                               new[$1] != ""{$1 = new[$1]}
+                               {print}' >/tmp/fstab.$$ || {
+                               if test "$1" = start
+                               then
+                                       logger -s "/etc/init.d/fixfstab: /tmp/fstab.$$: awk failed"
+                               else
+                                       echo "debug: awk script failed with:" >&2
+                                       echo "$changedlist" >&2
+                                       echo "output in /tmp/fstab.$$" >&2
+                               fi
+                               exit 1
+                       }
+
+                       if test "$1" = start
+                       then
+                               mv /tmp/fstab.$$ /etc/fstab || {
+                                       logger -s "/etc/init.d/fixfstab: /tmp/fstab.$$: update failed"
+                                       exit 1
+                               }
+                       else
+                               echo "debug: fstab changed:"
+                               diff -u /etc/fstab /tmp/fstab.$$
+                       fi
+               fi
+       fi
+fi
+
+# write the new list to the file, only if we
+# are doing something...
+test "$1" = start && echo "$newlist" >"$pfile"
+
+exit 0
diff --git a/packages/openprotium-init/files/initscripts/loadmodules.sh b/packages/openprotium-init/files/initscripts/loadmodules.sh
new file mode 100644 (file)
index 0000000..c5d44d1
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+. /etc/default/modulefunctions # Load module loading logic
+
+loadnetmods
+
+loaddiskmods
+
+loadmiscmods
+
+exit 0
diff --git a/packages/openprotium-init/files/initscripts/rmrecovery b/packages/openprotium-init/files/initscripts/rmrecovery
new file mode 100644 (file)
index 0000000..eec822b
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Run to remove /.recovery if the boot seems to have succeeded
+test -e /.recovery && rm -f /.recovery
+exit 0
diff --git a/packages/openprotium-init/files/initscripts/sysconfsetup b/packages/openprotium-init/files/initscripts/sysconfsetup
new file mode 100644 (file)
index 0000000..a4f9074
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+# This script is run once when the system first boots.  Its sole
+# purpose is to create /etc/default/sysconf (the overall system
+# configuration file) and other files derived from this.
+#
+# The script runs immediately after S10checkroot.sh - this is the
+# point at which the rootfs will be mounted rw even if the kernel
+# booted with it ro.
+#
+# rm or mv the file (/etc/default/sysconf) to recreate it, run this
+# script with the reload option to overwrite the system files.  The
+# configuration files described in sysconf_reload (in
+# /sbin/sysconf) will be overwritten on reload.
+#
+# start:  standard startup, do a complete (auto) restore if necessary
+# reinit: always do a complete auto restore
+# reload: just reload sysconf (no config files!)
+#
+# /etc/default/functions contains useful utility functions - it's
+# in a separate file so that it can be loaded by any script
+. /etc/default/functions
+load_functions sysconf || exit 1
+#
+case "$1" in
+start) test -s /etc/default/sysconf || {
+               if sysconf_read
+               then
+                       if sysconf_valid
+                       then
+                               sysconf_restore auto
+                       else
+                               sysconf_reload
+                       fi
+               else
+                       sysconf_default
+                       sysconf_reload
+               fi
+       };;
+
+reload)        test -s /etc/default/sysconf || sysconf_read || sysconf_default
+       sysconf_reload;;
+
+reinit)        sysconf_restore auto;;
+
+*)     ;;
+esac
diff --git a/packages/openprotium-init/files/initscripts/syslog.buffer b/packages/openprotium-init/files/initscripts/syslog.buffer
new file mode 100644 (file)
index 0000000..9285c02
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+#
+# Invoke the syslog startup if the configuration
+# uses (only) 'buffer' as the DESTINATION
+DESTINATION=
+test -f /etc/syslog.conf && . /etc/syslog.conf
+doit=
+
+for d in $DESTINATION
+do
+       case "$d" in
+       buffer) doit=1;;
+       file)   exit 0;;
+       remote) exit 0;;
+       *)      echo "/etc/syslog.conf: $d: unknown destination" >&2
+               exit 1;;
+       esac
+done
+
+test -n "$doit" -a -x /etc/init.d/syslog &&
+       exec /etc/init.d/syslog "$@"
+
+exit 0
diff --git a/packages/openprotium-init/files/initscripts/syslog.file b/packages/openprotium-init/files/initscripts/syslog.file
new file mode 100644 (file)
index 0000000..80ee5f0
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+#
+# Invoke the syslog startup if the configuration
+# uses 'file' (and, optionally, buffer) as the DESTINATION
+DESTINATION=
+test -f /etc/syslog.conf && . /etc/syslog.conf
+doit=
+
+for d in $DESTINATION
+do
+       case "$d" in
+       buffer) :;;
+       file)   doit=1;;
+       remote) exit 0;;
+       *)      echo "/etc/syslog.conf: $d: unknown destination" >&2
+               exit 1;;
+       esac
+done
+
+test -n "$doit" -a -x /etc/init.d/syslog &&
+       exec /etc/init.d/syslog "$@"
+
+exit 0
diff --git a/packages/openprotium-init/files/initscripts/syslog.network b/packages/openprotium-init/files/initscripts/syslog.network
new file mode 100644 (file)
index 0000000..3d7f4ab
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# Invoke the syslog startup if the configuration
+# uses 'remote', or doesn't use 'buffer' or 'file'
+DESTINATION=
+test -f /etc/syslog.conf && . /etc/syslog.conf
+doit=
+doneit=
+
+for d in $DESTINATION
+do
+       case "$d" in
+       buffer) doneit=1;;
+       file)   doneit=1;;
+       remote) doit=1;;
+       *)      doit=1
+               echo "/etc/syslog.conf: $d: unknown destination" >&2
+               exit 1;;
+       esac
+done
+
+# One of doneit or doit is set unless the DESTINATION value
+# is empty (which is probably an error), let syslog handle
+# the error.
+test \( -n "$doit" -o -z "$doneit" \) -a -x /etc/init.d/syslog &&
+       exec /etc/init.d/syslog "$@"
+
+exit 0
diff --git a/packages/openprotium-init/files/initscripts/umountinitrd.sh b/packages/openprotium-init/files/initscripts/umountinitrd.sh
new file mode 100644 (file)
index 0000000..b590ae6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# umount /mnt, which is where the initrd ends up mounted
+# if the directory /initrd is not present, if this fails
+# then the /initrd is mounted and we want to remount that
+# ro - this works round the shutdown -r hang problem
+. /etc/default/functions
+#
+# if we are turnup'ed to disk, then just unmount the initrd all together
+#
+if [ -e /initrd/dev/.devfsd ]; then 
+       [ "$VERBOSE" = "very" ] && echo "Unmounting initrd..."
+       umount /initrd/dev
+       umount /initrd
+       exit 0
+fi
+
+while read device directory remainder
+do
+       case "$directory" in
+       /mnt)   echo "InitRD: unmount initrd on /mnt" >&2
+               umount /mnt;;
+       /initrd)# need the device for a remount
+               ffspart=Flashdisk
+               ffsdev="$(mtblockdev $ffspart)"
+               echo "InitRD: remount $ffdev read-only on /initrd" >&2
+               if test -n "$ffsdev" -a -b "$ffsdev"
+               then
+                       mount -o remount,ro "$ffsdev" /initrd
+               else
+                       echo "Flashdisk: $ffsdev: flash device not found" >&2
+               fi;;
+       esac
+done </proc/mounts
diff --git a/packages/openprotium-init/files/links.conf b/packages/openprotium-init/files/links.conf
new file mode 100644 (file)
index 0000000..fdd1f3c
--- /dev/null
@@ -0,0 +1,6 @@
+# This file does not exist. Please do not ask the debian maintainer about it.
+# You may use it to do strange and wonderful things, at your risk.
+
+# The new RTC class does not create the /dev/rtc symlink, and udev rules don't get run for built-in modules.
+# So it looks like we have to do this here for the moment, until someone comes up with a better idea ...
+L rtc          rtc0
diff --git a/packages/openprotium-init/files/modulefunctions b/packages/openprotium-init/files/modulefunctions
new file mode 100644 (file)
index 0000000..430e376
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/sh
+# "." this file, then call the appropriate routines to load modules
+# you might need.  This is run from /etc/rcS.d/S21loadmodules.sh
+# at boot time.  Possible examples are commented out, none of which
+# are needed on openprotium since they are already in the kernel.
+
+. /etc/default/functions
+
+
+loaddiskmods(){
+       :
+#      modprobe scsi_mod
+#      modprobe sd_mod 
+#      modprobe usbcore 
+#      case "$(machine)" in
+#          nslu2)                     
+#              modprobe ehci-hcd
+#              modprobe ohci-hcd
+#              ;;
+#      esac
+#      modprobe usb-storage
+}
+
+loadnetmods(){
+       :
+#      modprobe af_packet
+#      case "$(machine)" in
+#          ixdp425|nslu2|nas100d)
+#              modprobe ixp4xx_mac
+#              ;;                     
+#      esac
+}
+
+loadmiscmods(){
+       :
+#      modprobe ixp4xx_rng
+#      modprobe i2c_dev
+}
+
diff --git a/packages/openprotium-init/files/reflash b/packages/openprotium-init/files/reflash
new file mode 100644 (file)
index 0000000..f294782
--- /dev/null
@@ -0,0 +1,163 @@
+#!/bin/sh
+#
+# Open Protium Reflash. This script will take a firmware image consisting
+# of a compressed linux kernel image, concatentated with a jffs2 root 
+# filesystem image. The kernel MTD device is discovered by locating
+# the MTD partition with the tag "kernel" and the filesystem MTD device
+# is dicovered by locating the MTD partition with the tag "filesystem."
+# There is no TOC inside the firmware images so there is no direct way 
+# to validate that the sizes of the parts in the firmware match the 
+# existing MTD partitions. So there could be a mismatch. However, a
+# a mismatch size will be detect as this script mounts the newly laid
+# done filesystem, a mismatch guarantees this to fail. That being said
+# the script does validate the total size to prevent overwriting 
+# uboot. Furthermore the script makes sure the fsdev is not in use and
+# that the various images are block aligned.
+
+flimg=$1
+if [ -z "$flimg" ]; then
+       echo "Usage: reflash <image file>"
+       exit 1
+fi
+
+if [ \! -f $flimg -o \! -r $flimg ]; then
+       #
+       # not a file or not readable
+       #
+       echo "error: Image file [$flimg] not available"
+       exit 1
+fi
+
+dmesg | grep StorCenter >/dev/null 2>&1
+if [ $? -ne 0 ]; then
+       exit 0
+fi
+
+blksize=512
+mtd=/proc/mtd
+mtab=/proc/mounts
+mntdir=/tmp/fs.$$
+
+ktag=kernel
+fstag=filesystem
+
+kdev=` grep  $ktag $mtd | awk -F: '{print $1}' | sed -e 's?mtd?/dev/mtdblock/?g'`
+fsdev=`grep $fstag $mtd | awk -F: '{print $1}' | sed -e 's?mtd?/dev/mtdblock/?g'`
+
+flsize=`ls -l $flimg     | awk '{print $5}'`
+ksize=`grep   $ktag $mtd | awk '{print "0x" $2}'`
+fssize=`grep $fstag $mtd | awk '{print "0x" $2}'`
+
+#
+# Size comes out of dc in exp notation and test wont accept a hex number
+# so dumo it in hex then use awk to convert to decimal
+#
+size=0x`dc 16  o $ksize $fssize + p`
+size=`echo $size | awk '{printf ("%d",$1)}'`
+
+#
+# Make sure we are block aligned
+#
+kblks=`dc $ksize $blksize / p`
+r=`dc $ksize $blksize % p`
+if [ $r -ne 0 ]; then 
+       echo "error: Kernel partition is not block aligned."
+       exit 1
+fi
+
+#
+# Make sure we are block aligned
+#
+fsblks=`dc $fssize $blksize / p`
+r=`dc $fssize $blksize % p`
+if [ $r -ne 0 ]; then 
+       echo "error: Filesystem partition is not block aligned."
+       exit 1
+fi
+
+#
+# Check to see that we have enough room
+#
+if [ $flsize -gt $size ]; then
+       echo "error: Image size is bigger then available space."
+       exit 1
+fi
+
+#
+# Is fsdev mounted?
+#
+grep $fsdev $mtab > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+       echo "error: $fsdev mounted"
+       exit 1
+fi
+
+#
+# If root is a jffs2 then close enough, im out
+#
+grep jffs2 $mtab > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+       echo "error: $fsdev may be mounted"
+       exit 1
+fi
+
+
+#
+# Mount fsdev and save fsdev/linuxrc
+#
+mkdir $mntdir /tmp/$$
+mount -t jffs2 $fsdev $mntdir
+if [ $? -ne 0 ]; then
+       echo "error: Unable to mount $fsdev"
+       exit 1
+fi
+echo "Preserving /linuxrc in /tmp/$$"
+cp $mntdir/linuxrc* /tmp/$$
+umount $mntdir
+
+echo "Image:"
+echo " Name  : $flimg"
+echo " Length: $flsize"
+echo
+echo "Kernel:"
+echo " Device: $kdev"
+echo " Length: $ksize"
+echo " Blocks: $kblks"
+echo 
+echo "Filesystem:"
+echo " Device: $fsdev"
+echo " Length: $fssize"
+echo " Blocks: $fsblks"
+echo
+echo 'Ready to flash, Continue? (yes/no)'
+read continue
+if [ "z$continue" != "zyes" ]; then
+       rm -rf $mntdir /tmp/$$
+       exit 0
+fi
+
+#
+# Lets do the flash
+#
+echo Preserving existing flash in: $flimg.sav.$$ 
+dd of=$flimg.sav.$$ if=$kdev  bs=$blksize count=$kblks
+dd of=$flimg.sav.$$ if=$fsdev bs=$blksize count=$fsblks seek=$kblks
+
+echo Flashing new firmware....
+dd if=$flimg of=$kdev  bs=$blksize count=$kblks
+dd if=$flimg of=$fsdev bs=$blksize count=$fsblks skip=$kblks
+sync
+sleep 5 
+
+#
+# Mount fsdev and restore fsdev/linuxrc
+#
+mount -t jffs2 $fsdev $mntdir
+if [ $? -ne 0 ]; then
+       echo "error: Unable to re-mount $fsdev"
+       exit 1
+fi
+echo "Restoring /linuxrc"
+cp /tmp/$$/linuxrc* $mntdir
+umount $mntdir
+rm -rf $mntdir /tmp/$$
diff --git a/packages/openprotium-init/files/sysconf b/packages/openprotium-init/files/sysconf
new file mode 100644 (file)
index 0000000..8866c07
--- /dev/null
@@ -0,0 +1,793 @@
+#!/bin/sh
+# sysconf
+#
+# utility to manipulate system configuration information help
+# in a RedBoot SysConf partition
+#
+# load the utility functions (unless this is being called just
+# to load these functions!)
+test "$1" != sysconf && . /etc/default/functions
+
+# NSLU2 flash layout is non-standard.
+case "$(machine)" in
+nslu2)
+       kpart="Kernel"
+       syspart="SysConf"
+       ffspart="Flashdisk";;
+*)
+       kpart="kernel"
+       syspart="sysconfig"
+       ffspart="filesystem";;
+esac
+#
+# sysconf_valid
+#  return true if the SysConf partition exists and seems to be
+#  potentially valid (it starts with a reasonable length).
+sysconf_valid(){
+       local sysdev
+       sysdev="$(mtblockdev $syspart)"
+       test -n "$sysdev" -a -b "$sysdev" &&
+               devio "<<$sysdev" '!! b.10>s32768<&!'
+}
+
+#
+# sysconf_read [prefix]
+#  read the $syspart partition (if present) writing the result into
+#  /etc/default/sysconf, if the result is empty it will be removed.
+sysconf_read(){
+       local sysdev sedcmd mac config_root
+       config_root="$1"
+       rm -f /tmp/sysconf.new
+       sysdev="$(mtblockdev $syspart)"
+       if sysconf_valid
+       then
+               # Read the defined part of $syspart into /etc/default/sysconf.
+               # $syspart has lines of two forms:
+               #
+               #  [section]
+               #  name=value
+               #
+               # In practice $syspart also contains other stuff, use the command:
+               #
+               #  devio '<</dev/mtd1;cpb'
+               #
+               # to examine the current settings.  The badly formatted stuff
+               # is removed (to be exact, the sed script selects only lines
+               # which match one of the two above).  The lan interface, which
+               # on NSLU2 defaults to ixp0, is changed to the correct value for
+               # slugos, eth0.  The bootproto, which LinkSys sets to static in
+               # manufacturing, is reset to dhcp if the IP is still the
+               # original (192.168.1.77)
+               sedcmd='/^\[[^][]*\]$/p;'
+               # only do the ip_addr and lan_interface fixups on NSLU2
+               if test "$(machine)" = nslu2
+               then
+                       sedcmd="$sedcmd"'
+                               s/^lan_interface=ixp0$/lan_interface=eth0/;
+                               /^ip_addr=192\.168\.1\.77$/,/^bootproto/s/^bootproto=static$/bootproto=dhcp/;'
+               fi
+               # always fix up the hardware addr if it is present
+               mac="$(config mac)"
+               if test -n "$mac"
+               then
+                       sedcmd="$sedcmd"'
+                               s/^hw_addr=.*$/hw_addr='"$mac"'/;'
+               fi
+               # and only print lines of the correct form
+               sedcmd="$sedcmd"'
+                       /^[-a-zA-Z0-9_][-a-zA-Z0-9_]*=/p'
+
+               devio "<<$sysdev" cpb fb1,10 | sed -n "$sedcmd" >/tmp/sysconf.new
+       fi
+       #
+       # test the result - sysconf must be non-empty
+       if test -s /tmp/sysconf.new
+       then
+               mv /tmp/sysconf.new "$config_root/etc/default/sysconf"
+       else
+               rm -f /tmp/sysconf.new
+               return 1
+       fi
+}
+
+#
+# sysconf_default [prefix]
+#  Provde a default /etc/default/sysconf when there is no $syspart partition,
+#  or when it is invalid, this function will read from an existing sysconf,
+#  copying the values into the new one.
+# sysconf_line tag config-tag
+#  write an appropriate line if the config value is non-empty
+sysconf_line(){
+       config "$2" | {
+               local value
+               read value
+               test -n "$value" && echo "$1"="$value"
+       }
+}
+#
+sysconf_default(){
+       local config_root
+       config_root="$1"
+       {       echo '[network]'
+               sysconf_line hw_addr mac
+               sysconf_line disk_server_name host
+               sysconf_line w_d_name domain
+               sysconf_line lan_interface iface
+               sysconf_line ip_addr ip
+               sysconf_line netmask netmask
+               sysconf_line gateway gateway
+               sysconf_line dns_server1 dns
+               sysconf_line dns_server2 dns2
+               sysconf_line dns_server3 dns3
+               sysconf_line bootproto boot
+       } >/tmp/sysconf.new
+       mv /tmp/sysconf.new "$config_root/etc/default/sysconf"
+}
+
+#
+# sysconf_reload [prefix]
+#  read the values from /etc/default/sysconf and use these values to set
+#  up the following system files:
+#
+#   /etc/hostname
+#   /etc/defaultdomain
+#   /etc/resolv.conf
+#   /etc/network/interfaces
+#   /etc/motd
+#
+sysconf_reload(){
+       local config_root host domain iface boot ip netmask gateway ifname iftype
+       config_root="$1"
+       host="$(config host)"
+       test -n "$host" && echo "$host" >"$config_root/etc/hostname"
+       domain="$(config domain)"
+       test -n "$domain" && echo "$domain" >"$config_root/etc/defaultdomain"
+       #
+       # The DNS server information gives up to three nameservers,
+       # but this currently only binds in the first.
+       {
+               test -n "$domain" && echo "search $domain"
+               test -n "$(config dns)" && echo "nameserver $(config dns)"
+               test -n "$(config dns2)" && echo "nameserver $(config dns2)"
+               test -n "$(config dns3)" && echo "nameserver $(config dns3)"
+       } >"$config_root/etc/resolv.conf"
+       #
+       # Ethernet information.  This goes into /etc/network/interfaces,
+       # however this is only used for static setup (and this is not
+       # the default).  With dhcp the slugos udhcp script,
+       # /etc/udhcpc.d/50default, loads the values from sysconf.
+       iface="$(config iface)"
+       boot="$(config boot)"
+       # Only dhcp and static are supported at present - bootp
+       # support requires installation of appropriate packages
+       # dhcp is the fail-safe
+       case "$boot" in
+       dhcp|static) ;;
+       *) boot=dhcp;;
+       esac
+       #
+       ip="$(config ip)"
+       netmask="$(config netmask)"
+       gateway="$(config gateway)"
+       {
+               echo "# /etc/network/interfaces"
+               echo "# configuration file for ifup(8), ifdown(8)"
+               echo "#"
+               echo "# The loopback interface"
+               echo "auto lo"
+               echo "iface lo inet loopback"
+               echo "#"
+               echo "# The interface used by default during boot"
+               echo "auto $iface"
+               echo "# Automatically generated from /etc/default/sysconf"
+               echo "# address, netmask and gateway are ignored for 'dhcp'"
+               echo "# but required for 'static'"
+               echo "iface $iface inet $boot"
+               # The following are ignored for DHCP but are harmless
+               test -n "$ip"      && echo "    address $ip"
+               test -n "$netmask" && echo "    netmask $netmask"
+               test -n "$gateway" && echo "    gateway $gateway"
+               #
+               # Now read all the other ARPHRD_ETHER (type=1) interfaces
+               # and add an entry for each.
+               for ifname in $(test -d /sys/class/net && ls /sys/class/net)
+               do
+                       if test -r "/sys/class/net/$ifname/type" -a "$ifname" != "$iface"
+                       then
+                               read iftype <"/sys/class/net/$ifname/type"
+                               case "$iftype" in
+                               1)      echo "#"
+                                       echo "# /sys/class/net/$ifname:"
+                                       echo "auto $ifname"
+                                       echo "iface $ifname inet dhcp";;
+                               esac
+                       fi
+               done
+       } >"$config_root/etc/network/interfaces"
+       #
+       # Finally rewrite /etc/motd
+       {       echo "Host name:           $host"
+               echo "Domain name:         $domain"
+               echo "Host MAC:            $(config mac)"
+               echo "Network boot method: $boot"
+               case "$boot" in
+               static) echo "Host IP address:     $ip";;
+               esac
+               echo "Use 'turnup init' to reset the configuration"
+               echo "Use 'turnup preserve' to save the configuration permanently"
+               echo "Use 'turnup restore' to restore a previously saved configuration"
+               echo "Use 'turnup disk|nfs -i <device> options to initialise a non-flash root"
+               echo "Use 'turnup help' for more information"
+       } >"$config_root/etc/motd"
+}
+
+#
+# sysconf_save_conffiles <flash-directory> <dest> <list>
+#  preserve the configuration files in a directory or in a CPIO archive
+#  (which is *not* compressed).  If <dest> is a directory the files are
+#  copied, otherwise a CPIO archive is made with that name.  <list> is
+#  the listing file giving the preserved files and the processing option.
+sysconf_save_conffiles(){
+       local ffsdir dest list file
+       ffsdir="$1"
+       saved="$2"
+       list="$3"
+       test -n "$ffsdir" -a -r "$ffsdir/etc/default/conffiles" -a -n "$saved" -a -n "$list" || {
+               echo "sysconf_save_conffiles: invalid arguments: '$*'" >&2
+               echo " usage sysconf_save_conffiles <flash-directory> <dest> <list>" >&2
+               return 1
+       }
+       #
+       (       cd "$ffsdir"
+               find etc/*.conf $(sed 's!^/!!' usr/lib/ipkg/info/*.conffiles) ! -type d -newer etc/.configured -print |
+                       sed 's/^/diff /'
+               exec sed 's/#.*$//;/^[  ]*$/d' etc/default/conffiles
+       ) | sed 's!^/*!!' |
+       awk '{ op=$1; $1=""; file[$0]=op }
+               END{ for (f in file) if (file[f] != "ignore") print file[f] f }' |
+       while read op file
+       do
+               if test -e "$ffsdir/$file"
+               then
+                       echo "$op $file" >&3
+                       echo "$file"
+               fi
+       done 3>"$list" | (
+               cd "$ffsdir"
+               if test -d "$saved"
+               then
+                       exec cpio -p -d -m -u "$saved"
+               else
+                       exec cpio -o -H crc >"$saved"
+               fi
+       )
+}
+
+#
+# sysconf_verify file
+#  this is called with the name of a 'diff' file which is, indeed,
+#  different and with all the std streams connected to the tty.  It
+#  returns a status code to say whether (0) or not (1) to copy the
+#  file over.
+#
+# globals: the following must be defined in the calling context!
+#  saved:  the directory containing the unpacked saved files
+#  ffsdir: the flash directory to which the files are being restored (/)
+#
+sysconf_verify_help() {
+       echo "Please specify how to handle this file or link, the options are as follows,"
+       echo "two character abbreviations may be used:"
+       echo
+       echo " keep:    retain the old file, overwrite the new flash image file"
+       echo " upgrade: retain the new file, the old (saved) file is not used"
+       echo " diff:    display the differences between the old and the new using diff -u"
+       echo " shell:   temporarily start an interactive shell (sh -i), exit to continue"
+       echo " skip:    ignore this file for the moment.  The file is left in the directory"
+       echo "          $saved and many be handled after this script has completed"
+}
+#
+sysconf_verify() {
+       local command file
+
+       # return 1 here causes the file not to be overwritten,
+       # control should never get here!
+       test -n "$sysconf_noninteractive" && {
+               echo "$0: $*: changed file cannot be handled non-interactively" >&2
+               return 1
+       }
+
+       file="$1"
+       echo "$0: $file: configuration file changed."
+       sysconf_verify_help "$file"
+       while :
+       do
+               echo -n "option: "
+               read command
+               case "$command" in
+               ke*)    return 0;;
+               up*)    rm "$saved/$file"
+                       return 1;;
+               di*)    echo "DIFF OLD($saved) NEW($ffsdir)"
+                       diff -u "$saved/$file" "$ffsdir/$file";;
+               sh*)    PS1="$file: " sh -i;;
+               sk*)    return 1;;
+               *)      sysconf_verify_help "$file";;
+               esac
+       done
+}
+# the same, but for a link
+sysconf_verify_link() {
+       local command link
+
+       # return 1 here causes the file not to be overwritten,
+       # control should never get here!
+       test -n "$sysconf_noninteractive" && {
+               echo "$0: $*: changed link cannot be handled non-interactively" >&2
+               return 1
+       }
+
+       link="$1"
+       echo "reflash: $link: configuration link changed."
+       sysconf_verify_help "$link"
+       while :
+       do
+               echo -n "option: "
+               read command
+               case "$command" in
+               ke*)    return 0;;
+               up*)    rm "$saved/$link"
+                       return 1;;
+               di*)    echo "DIFF:"
+                       echo "OLD($saved): $link -> $(readlink "$saved/$link")"
+                       echo "NEW($ffsdir): $link -> $(readlink "$ffsdir/$link")";;
+               sh*)    PS1="$link: " sh -i;;
+               sk*)    return 1;;
+               *)      sysconf_verify_help "$link";;
+               esac
+       done
+}
+
+#
+# sysconf_restore_conffiles <flash-directory> <source-dir> <restore>
+#  restore the configuration files from a directory.  'source-dir'
+#  If <source> is a directory of files from sysconf_save_conffiles.  The
+#  list of files restored is written to the third argument (restore),
+#  but is not required (/dev/null would be ok).
+#
+#  the list of files to restore is read from stdin, along with the
+#  processing option for each file (the format is as produced by
+#  sysconf_save_conffiles in the 'list' output).
+sysconf_restore_conffiles(){
+       local ffsdir saved restore
+       # these are the globals used by the above function
+       ffsdir="$1"
+       saved="$2"
+       restore="$3"
+       test -n "$ffsdir" -a -r "$ffsdir/etc/default/conffiles" -a -d "$saved" -a -n "$restore" || {
+               echo "restore_conffiles: invalid arguments: '$*'" >&2
+               echo " usage sysconf_restore_conffiles <flash-directory> <source-dir> <list>" >&2
+               return 1
+       }
+       #
+       # read the list and process each given file
+       while read op file
+       do
+               # handle .configured specially (to preserve the original datestamp)
+               if test "$file" = "etc/.configured"
+               then
+                       # this should definately not fail because of the test above!
+                       if cp -a "$saved/$file" "$ffsdir/$file"
+                       then
+                               echo "$file" >&3
+                       else
+                               echo "sysconf_restore_conffiles: $file: timestamp copy failed (ignored)" >&2
+                       fi
+               elif test -h "$saved/file" -o -h "$ffsdir/$file"
+               then
+                       # new or old symbolic link
+                       if test -h "$saved/$file" -a -h "$ffsdir/$file" &&
+                               test "$(readlink "$saved/$file")" = "$(readlink "$ffsdir/$file")"
+                       then
+                               # no change
+                               echo "$file" >&3
+                       else
+                               # assume a change regardless
+                               case "$op" in
+                               preserve)
+                                       echo "$file"
+                                       echo "$file" >&3;;
+                               diff)   # need user input
+                                       if sysconf_verify_link "$file" <>/dev/tty >&0 2>&0
+                                       then
+                                               echo "$file"
+                                               echo "$file" >&3
+                                       fi;;
+                               esac
+                       fi
+               else
+                       # only overwrite if necessary
+                       if test -e "$ffsdir/$file" && cmp -s "$saved/$file" "$ffsdir/$file"
+                       then
+                               # do not overwrite
+                               echo "$file" >&3
+                       elif test ! -e "$ffsdir/$file"
+                       then
+                               # always preserve
+                               echo "$file"
+                               echo "$file" >&3
+                       else
+                               case "$op" in
+                               preserve)
+                                       echo "$file"
+                                       echo "$file" >&3;;
+                               diff)   # the files are different, get user input
+                                       if sysconf_verify "$file" <>/dev/tty >&0 2>&0
+                                       then
+                                               echo "$file"
+                                               echo "$file" >&3
+                                       fi;;
+                               esac
+                       fi
+               fi
+       done 3>"$restore" | (cd "$saved"; exec cpio -p -d -u "$ffsdir")
+}
+
+#
+# sysconf_test_restore <flash-directory> <source-dir>
+#  return true only if the restore does not need to do an interactive
+#  compare
+sysconf_test_restore(){
+       local ffsdir saved
+       # these are the globals used by the above function
+       ffsdir="$1"
+       saved="$2"
+       # this is an error case, but return 0 so that the error is
+       # detected later
+       test -n "$ffsdir" -a -r "$ffsdir/etc/default/conffiles" -a -d "$saved" ||
+               return 0
+       #
+       # read the list and check each diff file (this is just a copy of the
+       # logic above with all the work removed!)
+       while read op file
+       do
+               # handle .configured specially (to preserve the original datestamp)
+               if test "$op" != diff
+               then
+                       : # no diff required
+               elif test "$file" = "etc/.configured"
+               then
+                       : # special handling
+               elif test -h "$saved/file" -o -h "$ffsdir/$file"
+               then
+                       # new or old symbolic link
+                       if test -h "$saved/$file" -a -h "$ffsdir/$file" &&
+                               test "$(readlink "$saved/$file")" = "$(readlink "$ffsdir/$file")"
+                       then
+                               : # no change
+                       else
+                               # assume a change regardless
+                               return 1
+                       fi
+               else
+                       # only overwrite if necessary
+                       if test -e "$ffsdir/$file" && cmp -s "$saved/$file" "$ffsdir/$file"
+                       then
+                               : # do not overwrite
+                       elif test ! -e "$ffsdir/$file"
+                       then
+                               : # always preserve
+                       else
+                               # a change
+                               return 1
+                       fi
+               fi
+       done
+
+       return 0
+}
+
+#
+# sysconf_save
+#  save the system configuration to $syspart - $syspart must exist and
+#  there must be a writeable device for it.
+sysconf_save(){
+       local sysdev ffsdev ffsdir saved list size status
+       ffsdev="$(mtblockdev $ffspart)"
+       sysdev="$(mtblockdev $syspart)"
+       status=1
+       if test -n "$sysdev" -a -b "$sysdev" -a -n "$ffsdev" -a -b "$ffsdev"
+       then
+               # this will succeed silently if the flash device is on /
+               umountflash "$ffsdev" || exit 1
+               #
+               # Everything is umounted, now remount on a temporary directory.
+               ffsdir="/tmp/flashdisk.$$"
+               mkdir "$ffsdir" || {
+                       echo "$0: $ffsdir: failed to create temporary directory" >&2
+                       exit 1
+               }
+               #
+               mountflash "$ffsdev" "$ffsdir" -o ro || {
+                       rmdir "$ffsdir"
+                       exit 1
+               }
+               # need temporary files for the cpio output and the listing
+               saved=/tmp/cpio.$$
+               list=/tmp/preserve.$$
+               rm -rf "$saved" "$list"
+               sysconf_save_conffiles "$ffsdir" "$saved" "$list" || {
+                       echo "$0: $saved: archive of saved configuration files failed" >&2
+                       rm -rf "$saved"
+                       rm "$list"
+                       umount "$ffsdir" && rmdir "$ffsdir" ||
+                               echo "$0: $ffsdir: temporary directory cleanup failed" >&2
+                       return 1
+               }
+               # ignore the error in this case:
+               umount "$ffsdir" && rmdir "$ffsdir" ||
+                       echo "$0: $ffsdir: temporary directory cleanup failed" >&2
+               #
+               # we now have:
+               #  /etc/default/sysconf the basic config
+               #  /tmp/preserve.$$     the list of saved files
+               #  /tmp/cpio.$$         the CPIO archive of those files
+               #
+               # make one big file with the sysconf data followed by the
+               # compressed archive in /tmp/sysconf.$$
+               {       {       cat /etc/default/sysconf
+                               echo '[preserve]'
+                       } | sed -n '1,/^\[preserve\]^/p'
+                       while read op file
+                       do
+                               echo "$op"="$file"
+                       done <"$list"
+               } >/tmp/sysconf.$$
+               size="$(devio "<</tmp/sysconf.$$" 'pr$')"
+               gzip -9 <"$saved" >>/tmp/sysconf.$$
+               #
+               # more cleanup, then try to write the new sysconf to $syspart
+               # the format is a 4 byte big-endian length then the text data
+               # if the data won't fit exit with error code 7
+               rm "$saved" "$list"
+               devio -p "<</tmp/sysconf.$$" ">>$sysdev" '
+                       $( $4+ # >
+                       !! 7
+                       $) 0
+                       wb '"$size"',4
+                       cp $'
+               case $? in
+               0)      echo " done" >&2
+                       status=0;;
+               1)      echo " failed" >&2
+                       echo " $syspart could not be written (no changes made)" >&2;;
+               3)      echo " failed" >&2
+                       echo " $syspart partially written, you may want to reset it" >&2;;
+               7)      echo " failed" >&2
+                       echo " $syspart is too small: $size bytes required" >&2
+                       echo " No change made" >&2;;
+               *)      echo " failed" >&2
+                       echo " Internal error writing $syspart" >&2;;
+               esac
+               #
+               rm -f /tmp/sysconf.$$
+       else
+               echo "sysconf save: $syspart or $ffspart partition not found" >&2
+               echo " A RedBoot partition named '$syspart' must exist in the system" >&2
+               echo " flash memory for this command to work, and there must be a" >&2
+               echo " block device to access this partition (udev will normally" >&2
+               echo " create this automatically.  The flash partition contents must" >&2
+               echo " also be accessible in a partition called '$ffspart'" >&2
+               echo
+               echo " To create the $syspart partition use the 'fis create' command" >&2
+               echo " in the RedBoot boot loader, it is sufficient to make the" >&2
+               echo " partition one erase block in size unless you have substantially" >&2
+               echo " increased the size of the files listed in /etc/default/conffiles" >&2
+       fi
+
+       return $status
+}
+
+#
+# sysconf_restore [auto]
+#  restore previously saved configuration information from $syspart
+sysconf_restore_error(){
+       local root
+       root="$1"
+       shift
+       #       -------------------------------------------------------------------------------
+       {       echo "          WARNING: saved configuration files not restored"
+               test -n "$1" && echo "$*"
+               echo
+               echo "The configuration of this machine has been reinitialised using the values"
+               echo "from /etc/default/sysconf, however configuration files saved in the $syspart"
+               echo "partition have not been restored."
+               echo
+               echo "You can restore these files by correcting any reported errors then running"
+               echo
+               echo "  sysconf restore"
+               echo
+               echo "from the command line.  This will completely reinitialise the configuration"
+               echo "using the information in the $syspart partition."
+       } >"$root/etc/motd"
+       cat "$root/etc/motd" >&2
+}
+#
+sysconf_restore(){
+       local sysdev ffsdev ffsdir saved restore size status sysconf_noninteractive config_root
+
+       # if set this means 'do no diff' - this avoids the code above which
+       # would open /dev/tty and therefore allows this stuff to be done from
+       # an init script
+       sysconf_noninteractive=
+       test "$1" = auto && sysconf_noninteractive=1
+
+       ffsdev="$(mtblockdev $ffspart)"
+       sysdev="$(mtblockdev $syspart)"
+       status=1
+       if test -n "$sysdev" -a -b "$sysdev" -a -n "$ffsdev" -a -b "$ffsdev" &&
+               sysconf_valid
+       then
+               # this will succeed silently if the flash device is on /
+               umountflash "$ffsdev" || exit 1
+               #
+               # Everything is umounted, now remount on a temporary directory.
+               ffsdir="/tmp/flashdisk.$$"
+               config_root="$ffsdir"
+               mkdir "$ffsdir" || {
+                       echo "$0: $ffsdir: failed to create temporary directory" >&2
+                       exit 1
+               }
+               #
+               mountflash "$ffsdev" "$ffsdir" || {
+                       rmdir "$ffsdir"
+                       exit 1
+               }
+               #
+               # first restore the $syspart section
+               sysconf_read "$ffsdir" || sysconf_default "$ffsdir"
+               #
+               # now use this to regenerate the system files
+               sysconf_reload "$ffsdir"
+               #
+               # now examine the [preserve] section, if it is there restore
+               # it if possible.
+               if test -n "$(syssection preserve)"
+               then
+                       # 'saved' is a directory, 'restore' is a file (which is
+                       # used to detect unrestored files).  The directory needs
+                       # to be populated with files.
+                       saved=/tmp/cpio.$$
+                       restore=/tmp/restore.$$
+                       rm -rf "$saved" "$restore"
+                       #
+                       mkdir "$saved" || {
+                               sysconf_restore_error "$ffsdir" "$saved: failed to create temporary directory"
+                               return 1
+                       }
+                       #
+                       # the CPIO archive is gzip compressed after the text part
+                       # of sysconf, gzip will handle the LZ stream termination
+                       # correctly (and break the pipe) so we don't need to know
+                       # the real length of the data
+                       devio "<<$sysdev" '<=b4+.' 'cp $s-' | gunzip | (
+                               cd "$saved"
+                               exec cpio -i -d -m -u
+                       ) || {
+                               rm -rf "$saved"
+                               sysconf_restore_error "$ffsdir" "$saved: cpio -i failed"
+                               return 1
+                       }
+                       # either there must be no 'diff' files or it must
+                       # be possible to interact with a real user.
+                       if test -z "$sysconf_noninteractive" ||
+                               syssection preserve | sysconf_test_restore "$ffsdir" "$saved"
+                       then
+                               #
+                               # remove the 'init' motd from sysconf_reload
+                               rm "$ffsdir/etc/motd"
+                               #
+                               # now restore from the directory, using the information in
+                               # the preserve section, if this fails in a non-interactive
+                               # setting the system might not reboot
+                               syssection preserve |
+                                       sysconf_restore_conffiles "$ffsdir" "$saved" "$restore" || {
+                                       # there is a chance of the user cleaning this up
+#------------------------------------------------------------------------------
+                                       sysconf_restore_error "$ffsdir" \
+"$0: $saved: restore of saved configuration files failed.
+  The flash file system is mounted on $ffsdir.
+  The saved files are in $saved and the list of files selected for
+  restore is in $restore.
+  You should restore any required configuration from $saved, then umount
+  $ffsdir and reboot."
+                                               # this prevents cleanup/umount
+                                               return 1
+                               }
+                               #
+                               # remove the copied files (i.e. the ones which were preserved)
+                               (       cd "$saved"
+                                       exec rm $(cat "$restore")
+                               )
+                               rm "$restore"
+                               #
+                               # clean up, files left in $saved need to be handled by the user
+                               files="$(find "$saved" ! -type d -print)"
+                               if test -n "$files"
+                               then
+#------------------------------------------------------------------------------
+                                       sysconf_restore_error "$ffsdir" \
+"$0: some saved configuration files have not been handled:
+
+$files
+
+These files can be examined in $saved and restored to
+$ffsdir if required.  The saved files are in a temporary
+directory and will not be retained across a reboot - copy then elsewhere if
+you are unsure whether they are needed."
+                                       return 1
+                               fi
+                               #
+                               # so this is safe now (no files, links etc)
+                               rm -rf "$saved"
+                       else
+                               rm -rf "$saved"
+                               # non-interactive and some changed diff files
+                               sysconf_restore_error "$ffsdir" \
+"$0: some of the saved configuration files must be
+examined before restoration"
+                               # but continue to the umount
+                       fi
+               fi
+               #
+               # ignore the error in this case:
+               umount "$ffsdir" && rmdir "$ffsdir" ||
+                       echo "$0: $ffsdir: temporary directory cleanup failed" >&2
+               status=0
+       else
+               echo "sysconf restore: $syspart or $ffspart partition not found" >&2
+               echo " You must have used 'sysconf save' to save configuration data" >&2
+               echo " into the $syspart partition before using this command.  The command" >&2
+               echo " will restore the configuration data to the flash root partition" >&2
+               echo " named '$ffspart' - this must also be accessible." >&2
+       fi
+
+       return $status
+}
+
+#
+# sysconf_help
+#  help text
+sysconf_help(){
+       #     -------------------------------------------------------------------------------
+       echo "sysconf: usage: sysconf read|default|reload|save|restore" >&2
+       echo " read:    the current $syspart partition is read into /etc/default/sysconf" >&2
+       echo " default: a default /etc/default/sysconf is created" >&2
+       echo " reload:  system configuration files are recreated from /etc/default/sysconf" >&2
+       echo " save:    /etc/default/sysconf and the files listed in /etc/default/conffiles" >&2
+       echo "          are written to the $syspart partition" >&2
+       echo " restore: the configuration information in the $syspart partition saved by" >&2
+       echo "          'sysconf save' is restored" >&2
+}
+
+#
+# the real commands
+#if [ "$(machine)" = "storcenter" ]; then
+#      echo "sysconf not (yet) supported on storcenter"
+#      exit 0
+#fi
+sysconf_command="$1"
+test $# -gt 0 && shift
+case "$sysconf_command" in
+read)  sysconf_read "$@";;
+default)sysconf_default "$@";;
+reload)        sysconf_reload "$@";;
+save)  sysconf_save "$@";;
+restore)sysconf_restore "$@";;
+valid)  sysconf_valid "$@";;
+
+sysconf)# just load the functions
+       ;;
+
+*)     # help text
+       sysconf_help "$@";;
+esac
diff --git a/packages/openprotium-init/files/turnup b/packages/openprotium-init/files/turnup
new file mode 100644 (file)
index 0000000..73befd2
--- /dev/null
@@ -0,0 +1,861 @@
+#!/bin/sh
+# turnup
+# See the help block at the end for documentation.
+#
+. /etc/default/functions
+
+#
+# configuration
+#  The following variables control which directories in /var end
+#  up on the rootfs and which end up in a temporary file system.
+INRAM_MEMSTICK="/var/cache /var/lock /var/log /var/run /var/tmp /var/lib/ipkg"
+INRAM_NFS="/var/cache /var/lock /var/run /var/tmp"
+INRAM_DISK=""
+
+#
+# force: override certain checks
+force=
+
+#
+# pfile: the uuid/partition file
+pfile=/etc/uuid_by_partition
+
+#
+# fstype new
+#  The type of the file system mounted on "new"  Outputs the last
+#  piece of information found, which should be the one for the
+#  currently visible mount!
+fstype() {
+       local cwd dev mp type options pass freq result
+       cwd="$(cd "$1"; /bin/pwd)"
+       result=
+       while read dev mp type options pass freq
+       do
+               case "$mp" in
+               "$cwd") result="$type";;
+               esac
+       done </proc/mounts
+       echo "$result"
+}
+
+#
+# fsoptions arguments
+#  Collapses the mount (-o) options into a single list which is
+#  printed on stdout.  Accepts an arbitrary list of options and
+#  just joins them together.
+fsoptions() {
+       local options
+       options=
+       while test $# -gt 1
+       do
+               case "$1" in
+               -t)     shift;;
+               -o)     if test -n "$2"
+                       then
+                               if test -n "$options"
+                               then
+                                       options="$options,$2"
+                               else
+                                       options="$2"
+                               fi
+                       fi
+                       shift;;
+               esac
+               shift
+       done
+       if test -n "$options"
+       then
+               echo "$options"
+       else
+               echo defaults
+       fi
+}
+
+#
+# get_flash <directory> {mount options}
+#  mount the flash device, writeable, on the given directory
+get_flash() {
+       local ffsdir ffsdev
+
+       ffsdir="$1"
+       shift
+       test -n "$ffsdir" -a -d "$ffsdir" || {
+               echo "$0: $ffsdir: internal error, flash mount point not a directory" >&2
+               return 1
+       }
+
+       case "$(machine)" in
+       nslu2)  ffsdev="$(mtblockdev Flashdisk)";;
+       *)      ffsdev="$(mtblockdev filesystem)";;
+       esac
+       umountflash "$ffsdev" &&
+       mountflash "$ffsdev" "$ffsdir" "$@"
+}
+
+#
+# check_rootfs [-i] <root fs directory>
+#  Make sure the candidate rootfs is empty
+#  Environment: rootdev=device or NFS root path
+check_rootfs() {
+       local fcount
+
+       case "$1" in
+       -i)     shift
+               case "$force" in
+               -f) return 0;;
+               esac
+
+               fcount="$(find "$1" ! -type d -print | wc -l)"
+               test "$fcount" -eq 0 && return 0
+
+               echo "turnup: $rootdev: partition contains existing files, specify -f to overwrite" >&2
+               return 1;;
+       *)      checkmount "$1" && return 0
+
+               echo "turnup: $rootdev: partition does not seem to be a valid root partition" >&2
+               echo "  The partition must contain a full operating system.  To ensure that" >&2
+               echo "  this is the case it is checked for the following, all of which must" >&2
+               echo "  exist for the bootstrap to work:" >&2
+               echo
+               echo "  1) A directory /mnt." >&2
+               echo "  2) A command line interpreter program in /bin/sh." >&2
+               echo "  3) The program chroot in /sbin or /usr/sbin." >&2
+               echo "  4) The program init in /sbin, /etc or /bin." >&2
+               echo
+               echo "  One or more of these items is missing.  Mount $rootdev on /mnt" >&2
+               echo "  and examine its contents.  You can use turnup disk|nfs -i -f" >&2
+               echo "  to copy this operating system onto the disk, but it may overwrite" >&2
+               echo "  files on the disk." >&2
+               return 1;;
+       esac
+}
+
+#
+# copy_rootfs old new
+#  Make a copy of the given root file system, copying only the
+#  directories needed.  The root must be the flash file system
+copy_rootfs() {
+       local old new
+       old="$1"
+       new="$2"
+       test -d "$old" -a -d "$new" || {
+               echo "turnup: rootfs: copy $old $new: not a directory" >&2
+               return 1
+       }
+       #
+       # There are no problem file names in the flash file system, so
+       # it is possible to use -print, not -print0.  The following
+       # files and directories are not copied:
+       #
+       #   /dev/*
+       #   /boot, /boot/*
+       #   /linuxrc*
+       #   /var/*
+       echo "turnup: copying root file system" >&2
+       (       cd "$1"
+               find . -mount -print |
+               sed '\@^./dev/@d;\@^./boot/@d;\@^./boot$@d;\@^./linuxrc@d;\@^./var/@d' |
+               cpio -p -d -m -u "$2"
+       ) || {
+               echo "turnup: rootfs: cpio $old $new failed" >&2
+               return 1
+       }
+       echo "done" >&2
+}
+
+#
+# setup_dev new device_table
+#  In flash file systems /dev is in ramfs, in disk systems /dev
+#  can be populated permanently.  This is done by creating a
+#  single entry '.noram' in /dev - the devices init script will
+#  then populate the directory without overmounting it.  The
+#  devices in the passed in device table are also created, but
+#  note that this is insufficient, /etc/init.d/devices must
+#  also run.
+setup_dev() {
+       test -n "$1" -a -d "$1"/dev -a -r "$2" || {
+               echo "turnup: setup_dev($1,$2): expected a directory and a file" >&2
+               return 1
+       }
+       echo "turnup: initialising dev file system" >&2
+       # init tries to open the following devices:
+       #       /dev/console
+       #       /dev/tty0
+       #       /dev/null
+       # syslog, and maybe other things, only work if fd 1 is valid, therefore
+       # we must create these devices here...
+       makedevs --root="$1" --devtable="$2"
+       :>"$1"/dev/.noram
+       return 0
+}
+
+#
+# setup_bootdev new device_table
+#  As above but actually uses the supplied device table - this is possible if
+#  the table is just used for boot because the extra setup is not required.
+setup_bootdev() {
+       test -n "$1" -a -d "$1"/dev -a -r "$2" || {
+               echo "turnup: setup_bootdev($1,$2): expected a directory and a file" >&2
+               return 1
+       }
+       # NOTE: this fails silently with 0 return code(!) when a directory
+       # does not exist yet things are created within it.
+       makedevs -r "$1" -D "$2"
+}
+
+#
+# setup_var new type
+#  Populates /var.
+#  Removes the /var tmpfs entry from /etc/fstab.
+#  Creates links from /var into /media/ram for NFS and Memstick.
+setup_var() {
+       local ram_targets directory
+
+       test -n "$1" -a -d "$1"/var || {
+               echo "turnup: setup_var($1,$2): expected a directory" >&2
+               return 1
+       }
+       case "$2" in
+       disk|nfs|memstick);;
+       *)      echo "turnup: setup_var($1,$2): expected 'disk', 'nfs' or 'memstick'" >&2
+               return 1;;
+       esac
+       #
+       # populate /var, there is a shell script to do this, but it uses
+       # absolute path names
+       chroot "$1" /bin/busybox sh /etc/init.d/populate-volatile.sh || {
+               echo "turnup: /var: could not populate directory" >&2
+               return 1
+       }
+
+       case "$2" in
+       disk)   ram_targets="$INRAM_DISK";;
+       nfs)    ram_targets="$INRAM_NFS";;
+       memstick)
+               ram_targets="$INRAM_MEMSTICK";;
+       esac
+
+       for directory in $ram_targets
+       do
+               rm -rf "$1/$directory"
+               ln -s "/media/ram/$directory" "$1/$directory"
+       done
+       # the startup link is left for the moment, this seems safer
+       #rm "$1"/etc/rc?.d/[KS]??populate-var.sh
+       # remove the /var tmpfs entry from the new /etc/fstab
+       sed -i '\@[     ]/var[  ][      ]*tmpfs[        ]@d' "$1"/etc/fstab
+       echo "turnup: tmpfs will no longer be mounted on /var" >&2
+       #
+       # Previous versions of turnup removed populate-var.sh from the
+       # startup links, this one doesn't, so /var can be made back into
+       # a tmpfs just by a change to /etc/fstab.
+       return 0
+}
+
+#
+# setup_syslog new
+#  Moves the syslog to a file - appropriate for disk and nfs types, not
+#  otherwise.
+setup_syslog() {
+       test -n "$1" -a -d "$1"/etc || {
+               echo "turnup: setup_syslog($1): expected a directory" >&2
+               return 1
+       }
+       #
+       # if the syslog is to the buffer redirect it to a file
+       if egrep -q '^DESTINATION="buffer"' "$1"/etc/syslog.conf
+       then
+               if cp "$1"/etc/syslog.conf "$1"/etc/syslog.conf.sav
+               then
+                       # the busybox syslog will fail with ROTATESIZE and ROTATEGENS
+                       sed -i 's!DESTINATION="buffer"!DESTINATION="file"!
+                               /^ROTATESIZE=/d
+                               /^ROTATEGENS=/d' "$1"/etc/syslog.conf
+                       echo "turnup: /etc/syslog.conf: changed to file buffering" >&2
+                       echo " Old (buffer) version in /etc/syslog.conf.sav" >&2
+                       echo " Log messages will be in /var/log/messages" >&2
+               else
+                       echo "turnup: /etc/syslog.conf: failed to make a copy" >&2
+                       echo " syslog will log to a buffer" >&2
+               fi
+       fi
+       return 0
+}
+
+#
+# setup_rootfs type new device_table
+#  Populates the /dev and /var directories, alters the startup to
+#  not mount or populate them further.  Does the right thing according
+#  to the given $type
+setup_rootfs() {
+       local type new table
+       type="$1"
+       new="$2"
+       table="$3"
+
+       test -n "$new" -a -d "$new" -a -f "$table" || {
+               echo "turnup: setup_rootfs($type,$new,$table): expected a directory and a file" >&2
+               return 1
+       }
+
+       case "$type" in
+       flash)  return 0;;
+       disk)   setup_dev "$new" "$table" &&
+               setup_var "$new" "$type" &&
+               setup_syslog "$new";;
+       memstick)
+               setup_bootdev "$new" "$table" &&
+               setup_var "$new" "$type" ;;
+       nfs)    setup_dev "$new" "$table" &&
+               setup_var "$new" "$type" &&
+               setup_syslog "$new";;
+       *)      echo "turnup: setup_rootfs: $type: unknown rootfs type" >&2
+               return 1;;
+       esac
+       # return code of last setup function
+}
+
+#
+# setup_fstab new fsdev fstype fsoptions
+#  Alters the /etc/fstab entry for / to refer to the correct device and
+#  have the correct type and options.  Essential for checkroot to remount
+#  / with the correct options.  Writes the initial uuid file.
+#  bad, since sed won't fail even if it changes nothing.
+setup_fstab() {
+       sed -i '\@^[^   ]*[     ][      ]*/[    ]@s@^.*$@'"$2   /       $3      $4      1  1"'@' "$1"/etc/fstab
+       egrep -q "^$2   /       $3      $4      1  1\$" "$1"/etc/fstab || {
+               echo "turnup: /etc/fstab: root(/) entry not changed" >&2
+               echo "  you probably need to check the options in /etc/fstab" >&2
+               echo "  to ensure that the root partition is mounted correctly" >&2
+               return 1
+       }
+       #
+       # build $pfile
+       uuid_by_partition >"$1""$pfile" ||
+               echo "turnup: $pfile: blkid failed (ignored)" >&2
+       return 0
+}
+
+#
+# boot_rootfs <boot type> <flash file system> <sleep time> (<device> <uuid>|<nfsroot>) [options]
+#  Change the flash partition (not the current root!) to boot off
+#  the new root file system
+boot_rootfs() {
+       local type ffs sleep device uuid opt
+
+       type="$1"
+       ffs="$2"
+       sleep="$3"
+       device="$4"
+       uuid=
+
+       # test this first as the test does not depend on the correctness
+       # of the other arguments
+       test -n "$ffs" -a -d "$ffs" || {
+               echo "turnup: boot_rootfs($type, $ffs, $device): expected directory" >&2
+               return 1
+       }
+       test -x "$ffs"/boot/"$type" || {
+               echo "turnup: boot_rootfs($type, $ffs, $device): invalid boot type $type" >&2
+               return 1
+       }
+       shift
+       shift
+
+       case "$type" in
+       disk)   test -n "$device" -a -b "$device" || {
+                       echo "turnup: boot_rootfs($ffs, $type, $device): expected block device" >&2
+                       return 1
+               }
+               uuid="$3"
+               shift 3;;
+       nfs)    shift 2;;
+       flash)  ;;
+       ram)    ;;
+       *)      echo "turnup: boot_rootfs($type, $ffs, $device): unknown type" >&2
+               return 1;;
+       esac
+
+       #
+       # The /linuxrc records the correct options to mount the device,
+       # since we have already mounted if correctly with these options
+       # we can be sure (maybe) that the boot will work.  If not /boot/disk
+       # falls back to flash.
+       #
+       # This modifies the boot process, until this point no harm has been
+       # done to the system, but at this point the boot rootfs will change
+       rm -f "$ffs"/linuxrc.new || {
+               echo "turnup: boot_rootfs: failed to remove $ffs/linuxrc.new" >&2
+               return 1
+       }
+       case "$type" in
+       flash)  ln -s "boot/flash" "$ffs"/linuxrc.new || {
+                       echo "turnup: boot_rootfs: failed to create $ffs/linuxrc.new" >&2
+                       return 1
+               };;
+       ram)    {       echo '#!/bin/sh'
+                       echo 'rm -f /linuxrc.new'
+                       echo 'ln -s boot/flash /linuxrc.new'
+                       echo 'mv /linuxrc.new /linuxrc'
+                       echo 'exec /boot/ram /dev/ram0'
+                       echo 'exec /boot/flash'
+               } >"$ffs"/linuxrc.new &&
+               chmod 744 "$ffs"/linuxrc.new || {
+                       echo "turnup: boot_rootfs: failed to write $ffs/linuxrc.new" >&2
+                       return 1
+               };;
+       *)      {       echo '#!/bin/sh'
+                       test "$sleep" -gt 0 && echo -n "sleep='$sleep' "
+                       test -n "$uuid" && echo -n "UUID='$uuid' "
+                       echo -n "exec '/boot/$type' '$device'"
+                       for opt in "$@"
+                       do
+                               echo -n " '$opt'"
+                       done
+                       echo
+                       echo 'exec /boot/flash'
+               } >"$ffs"/linuxrc.new &&
+               chmod 744 "$ffs"/linuxrc.new || {
+                       echo "turnup: boot_rootfs: failed to write $ffs/linuxrc.new" >&2
+                       return 1
+               };;
+       esac
+       rm -f "$ffs"/linuxrc.sav || {
+               echo "turnup: boot_rootfs: failed to remove $ffs/linuxrc.sav" >&2
+               return 1
+       }
+       ln "$ffs"/linuxrc "$ffs"/linuxrc.sav || {
+               echo "turnup: boot_rootfs: failed to save /linuxrc.sav" >&2
+               return 1
+       }
+       mv -f "$ffs"/linuxrc.new "$ffs"/linuxrc || {
+               echo "turnup: boot_rootfs: failed to install new /linuxrc" >&2
+               return 1
+       }
+       return 0
+}
+
+#
+# disk [-m] [-i] [-s<time>] <device> {options}
+#  Carefully copy the flash file system to the named device.
+disk() {
+       local setup_type sleep init device uuid new ffs fst fso
+
+       setup_type=disk
+       sleep=0
+       init=
+       while test $# -gt 0
+       do
+               case "$1" in
+               -f)     force="$1"
+                       shift;;
+               -m)     setup_type=memstick
+                       shift;;
+               -i)     init="$1"
+                       shift;;
+               -s*)    sleep="${1#-s}"
+                       sleep="${sleep:-10}"
+                       shift;;
+               *)      break;;
+               esac
+       done
+
+       device="$1"
+       test -n "$device" -a -b "$device" || {
+               echo "turnup disk: $device: block device required" >&2
+               return 1
+       }
+       shift
+
+       # find the uuid if available
+       uuid="$(blkid -c /dev/null -s UUID -o value "$device")"
+       # XXX nasty hack - using the UUID fails on storcenter, for now,
+       # probably due to various devfs problems.  fix later.
+       if [ $(machine) = storcenter ]; then
+               uuid=
+       fi
+
+       # make temporary directories for the mount points
+       new="/tmp/rootfs.$$"
+       ffs="/tmp/flashdisk.$$"
+       mkdir "$new" "$ffs" || {
+               echo "turnup: disk: failed to create temporary directories" >&2
+               return 1
+       }
+
+       # make sure we can get to the flash file system first
+       get_flash "$ffs" || {
+               rmdir "$new" "$ffs"
+               return 1
+       }
+
+       # Now mount the device with the given options, note that specifying
+       # read only is *not* an option, this is important because the boot/disk
+       # script needs a rw file system
+       status=1
+       fst=
+       fso="$(fsoptions "$@")"
+       if      if test -n "$uuid"
+               then
+                       mount "$@" -U "$uuid" "$new"
+               else
+                       mount "$@" "$device" "$new"
+               fi
+       then
+               fst="$(fstype "$new")"
+               umount "$new" ||
+                       echo "turnup disk: $device($new): umount does not seem to work" >&2
+       fi
+
+       if test -n "$fst" &&
+               if test -n "$uuid"
+               then
+                       mount -t "$fst" -o "$fso" -U "$uuid" "$new"
+               else
+                       mount -t "$fst" -o "$fso" "$device" "$new"
+               fi
+       then
+               if rootdev="$device" check_rootfs $init "$new" && {
+                       test -z "$init" || {
+                               copy_rootfs "$ffs" "$new" &&
+                               setup_rootfs "$setup_type" "$new" "$ffs"/etc/device_table
+                       }
+                  }
+               then
+                       setup_fstab "$new" "$device" "$fst" "$fso"
+                       status=0
+               fi
+
+               # clean up the disk.  It is worrying if this umount fails!
+               umount "$new" || test "$force" = "-f" || {
+                       echo "turnup disk: $device: umount failed" >&2
+                       echo "  you must unmount this device cleanly yourself, then use" >&2
+                       if test -z "$init"
+                       then
+                               echo "  turnup with the -f option to boot from the device" >&2
+                       else
+                               echo "  turnup without the -i option to boot from the device" >&2
+                       fi
+                       status=1
+               }
+
+               # if everything went ok boot from this disk
+               if test $status -eq 0
+               then
+                       # memsticks boot like disks, so ignore the -m
+                       boot_rootfs disk "$ffs" "$sleep" "$device" "$uuid" -t "$fst" -o "$fso"
+               fi
+       else
+               echo "turnup disk: $device($*): unable to mount device on $new" >&2
+               # If it worked first time
+               if test -n "$fst"
+               then
+                       echo "  options used: -t $fst -o $fso [error in this script]" >&2
+                       test -n "$uuid" &&
+                               echo "  uuid: $uuid (passed with -U)" >&2
+               fi
+       fi
+
+       # clean up the flash file system
+       umount "$ffs"
+       rmdir "$new" "$ffs"
+       return $status
+}
+
+#
+# boot_reset <type>
+#  Resets the boot type to flash or ram, as appropriate
+boot_reset() {
+       local ffs typ status
+
+       case "$1" in
+       flash|ram)type="$1"
+               shift;;
+       *)      echo "turnup: boot_reset($1): invalid type" >&2
+               return 1;;
+       esac
+
+       ffs="/tmp/flashdisk.$$"
+       mkdir "$ffs" || {
+               echo "turnup: $1: failed to create temporary directory" >&2
+               return 1
+       }
+
+       get_flash "$ffs" || {
+               rmdir "$ffs"
+               return 1
+       }
+
+       # now try to set the /linuxrc appropriately
+       boot_rootfs "$type" "$ffs"
+       status=$?
+
+       # clean up
+       umount "$ffs"
+       rmdir "$ffs"
+       return $status
+}
+
+#
+# nfs [-i] <root partition> {options}
+#  Copy the flash file system to the given NFS root partition.
+nfs() {
+       local init nfsroot new ffs
+
+       init=
+       while test $# -gt 0
+       do
+               case "$1" in
+               -i)     init="$1"
+                       shift;;
+               -f)     force="$1"
+                       shift;;
+               *)      break;;
+               esac
+       done
+
+       nfsroot="$1"
+       test -n "$nfsroot" || {
+               echo "turnup nfs: $nfsroot: NFS root file system required" >&2
+               return 1
+       }
+       shift
+
+       # make temporary directories for the mount points
+       new="/tmp/rootfs.$$"
+       ffs="/tmp/flashdisk.$$"
+       mkdir "$new" "$ffs" || {
+               echo "turnup nfs: failed to create temporary directories" >&2
+               return 1
+       }
+
+       # make sure we can get to the flash file system first
+       get_flash "$ffs" || {
+               rmdir "$new" "$ffs"
+               return 1
+       }
+
+       # Now mount the device with the given options, note that specifying
+       # read only is *not* an option, this is important because the boot/disk
+       # script needs a rw file system
+       status=1
+       fst=
+       # These settings for for NFS, something better will probably have to
+       # be done to support other network file systems.
+       nfsopt="nolock,noatime,hard,intr,rsize=1024,wsize=1024"
+       fso="$(fsoptions -o "$nfsopt" "$@")"
+       if mount -o "$nfsopt" "$@" "$nfsroot" "$new"
+       then
+               fst="$(fstype "$new")"
+               umount "$new" ||
+                       echo "turnup nfs: $nfsroot($new): umount does not seem to work" >&2
+       fi
+
+       if test -n "$fst" && mount -t "$fst" -o "$fso" "$nfsroot" "$new"
+       then
+               if :>"$new"/ttt && test -O "$new"/ttt && rm "$new"/ttt
+               then
+                       if rootdev="$nfsroot" check_rootfs $init "$new" && {
+                               test -z "$init" || {
+                                       copy_rootfs "$ffs" "$new" &&
+                                       setup_rootfs nfs "$new" "$ffs"/etc/device_table
+                               }
+                          }
+                       then
+                               setup_fstab "$new" "$nfsroot" "$fst" "$fso"
+                               status=0
+                       fi
+               else
+                       echo "turnup nfs: $nfsroot: partition must be exported no_root_squash" >&2
+               fi
+
+               # clean up the disk.  It is worrying if this umount fails!
+               umount "$new" || test "$force" = "-f" || {
+                       echo "turnup nfs: $nfsroot: umount failed" >&2
+                       if test $status -eq 0
+                       then
+                               echo "  you must unmount this partition cleanly yourself, then use" >&2
+                               if test -z "$init"
+                               then
+                                       echo "  turnup with the -f option to boot from the NFS root" >&2
+                               else
+                                       echo "  turnup without the -i option to boot from the NFS root" >&2
+                               fi
+                               status=1
+                       fi
+               }
+
+               # if everything went ok boot from this disk
+               if test $status -eq 0
+               then
+                       # the options used are exactly those which worked before.
+                       boot_rootfs nfs "$ffs" 0 "$nfsroot" -t nfs -o "$fso"
+               fi
+       else
+               echo "turnup nfs: $nfsroot($*): unable to mount device on $new" >&2
+               # If it worked first time
+               if test -n "$fst"
+               then
+                       echo "  options obtained: -t $fst -o $fso" >&2
+               fi
+       fi
+
+       # clean up the flash file system
+       umount "$ffs"
+       rmdir "$new" "$ffs"
+       return $status
+}
+
+#
+# read_one 'prompt' 'group' 'name'
+#  read a single value
+read_one() {
+       local n o
+       o="$(sysval "$2" "$3")"
+       echo -n "$1 [$o]: " >/dev/tty
+       read n </dev/tty
+       test -z "$n" && n="$o"
+       eval "$3='$n'"
+}
+
+#
+# init_network
+#  Change the network initialisation
+init_network() {
+       # fix the root password
+       echo "Please enter a new password for 'root'." >/dev/tty
+       echo "The password must be non-empty for ssh login to succeed!" >/dev/tty
+       passwd
+       # now the network configuration
+       read_one "Host name" network disk_server_name
+       read_one "Domain name" network w_d_name
+       read_one "Boot protocol (dhcp|static)" network bootproto
+       case "$bootproto" in
+       static) read_one "IP address" network ip_addr
+               read_one "IP netmask" network netmask
+               read_one "IP gateway" network gateway
+               read_one "First DNS server" network dns_server1
+               read_one "Second DNS server" network dns_server2
+               read_one "Third DNS server" network dns_server3
+               echo "$ip_addr       $disk_server_name" >> /etc/hosts
+               ;;
+       dhcp)   sed -i -e "s/localhost\$/localhost $disk_server_name/" /etc/hosts
+               ;;
+       *)      bootproto=dhcp;;
+       esac
+       #
+       # The other stuff which cannot be changed
+       hw_addr="$(config mac)"
+       lan_interface="$(config iface)"
+       #
+       # Write this out to a new sysconf
+       {       echo "[network]"
+               echo "hw_addr=$hw_addr"
+               echo "lan_interface=$lan_interface"
+               test -n "$disk_server_name" && echo "disk_server_name=$disk_server_name"
+               test -n "$w_d_name" && echo "w_d_name=$w_d_name"
+               echo "bootproto=$bootproto"
+               case "$bootproto" in
+               static) echo "ip_addr=$ip_addr"
+                       test -n "$netmask" && echo "netmask=$netmask"
+                       test -n "$gateway" && echo "gateway=$gateway"
+                       test -n "$dns_server1" && echo "dns_server1=$dns_server1"
+                       test -n "$dns_server2" && echo "dns_server2=$dns_server2"
+                       test -n "$dns_server3" && echo "dns_server3=$dns_server3"
+                       ;;
+               esac
+       } >/etc/default/sysconf
+       #
+       # And reload the result
+       sysconf reload
+       #
+       # The remove the spurious 'init' motd
+       rm /etc/motd
+}
+
+#
+# Basic command switch (this should be the only thing in this
+# script which actually does anything!)
+case "$1" in
+init)  shift
+       if init_network "$@"
+       then
+               echo "turnup init: you must reboot for the changes to take effect" >&2
+               echo " You may want to run 'turnup preserve' to save these settings," >&2
+               echo " after making any additional configuration changes which you" >&2
+               echo " require." >&2
+       else
+               exit 1
+       fi;;
+disk)  shift
+       disk "$@";;
+memstick)
+       shift
+       disk -m "$@" -o noatime;;
+nfs)   shift
+       nfs "$@";;
+flash) boot_reset flash;;
+ram)   boot_reset ram;;
+preserve)
+       shift
+       sysconf save "$@";;
+restore)
+       shift
+       sysconf restore "$@";;
+*)     echo "\
+usage: turnup command [options]
+ commands:
+  help
+    output this help
+  init
+    correct errors in network information
+    initialise network information when DHCP is not available
+    change network information
+  disk [-i] [-s<seconds>] <device>|<uuid> [mount options]
+    With -i make <device> a bootable file system then (with or
+    without -i) arrange for the next reboot to use that device.
+    The device must already be formatted as a file system, with
+    -i it must be completely empty, without it must contain an
+    apparently bootable file system. -s (for example -s5)
+    specifies a delay in seconds to wait at boot time before
+    mounting the device.
+  memstick [-i] <device>|<uuid> [mount options]
+    Behaves as disk however options appropriate to a flash memory
+    stick are automatically added
+  nfs [-i] <nfs mount path> [mount options]
+    <nfs mount path> must be a mountable NFS file system.  With
+    -i the partition must be empty and is initialised with a
+    bootable file system.  Without -i the partition must already
+    contain a bootable file system.  In either case the NFS
+    partition must be available to be mounted without root id
+    sqashing (i.e. root must be root) and it will be selected
+    as the root file system for subsequent reboots.
+    A default set of -o options are provided, additional options
+    may be given on the command line (multiple -o options will
+    be combined into a single -o).
+  flash
+    Revert to booting from the flash disk on next reboot.
+  ram
+    Boot (once) into a ramdisk, subsequent boots will be to
+    the flash file system.
+  preserve
+    Save the system configuration to the SysConf partition, you
+    will need to create the SysConf partition from the boot loader
+    before using this if SysConf does not already exist.  This
+    just runs 'sysconf save'.
+  restore
+    Restore a previously saved system configuration.  This just
+    runs 'sysconf restore'.
+ disk formatting:
+  The argument to 'nfs' or 'disk' must be an empty partition
+  of sufficient size to hold the root file system (at least
+  16MByte but more is recommended to allow package installation).
+  An appropriate ext3 partition can be made using the command:
+
+    mke2fs -j <device>  # for example: /dev/sda1
+
+  An appropriate NFS partition can be emptied using 'rm', but
+  must be set up (exported) on the NFS server." >&2
+       exit 0;;
+esac
+# Exit with return code from command.
diff --git a/packages/openprotium-init/openprotium-init_0.10.bb b/packages/openprotium-init/openprotium-init_0.10.bb
new file mode 100644 (file)
index 0000000..5ec63b1
--- /dev/null
@@ -0,0 +1,148 @@
+DESCRIPTION = "OpenProtium initial boot and config"
+SECTION = "base"
+PRIORITY = "required"
+LICENSE = "GPL"
+DEPENDS = "base-files devio"
+RDEPENDS = "busybox devio"
+PR = "r71"
+
+SRC_URI = "file://boot/flash \
+          file://boot/disk \
+          file://boot/nfs \
+          file://boot/network \
+          file://boot/udhcpc.script \
+          file://initscripts/fixfstab \
+          file://initscripts/syslog.buffer \
+          file://initscripts/syslog.file \
+          file://initscripts/syslog.network \
+          file://initscripts/rmrecovery \
+          file://initscripts/sysconfsetup \
+          file://initscripts/umountinitrd.sh \
+          file://initscripts/loadmodules.sh \
+          file://functions \
+          file://modulefunctions \
+          file://conffiles \
+          file://sysconf \
+          file://turnup \
+          file://reflash \
+          file://links.conf \
+          "
+
+SBINPROGS = ""
+USRSBINPROGS = ""
+CPROGS = "${USRSBINPROGS} ${SBINPROGS}"
+SCRIPTS = "turnup reflash sysconf"
+BOOTSCRIPTS = "flash disk nfs network udhcpc.script"
+INITSCRIPTS = "syslog.buffer syslog.file syslog.network \
+       rmrecovery sysconfsetup umountinitrd.sh \
+       fixfstab loadmodules.sh"
+
+# This just makes things easier...
+
+S="${WORKDIR}"
+
+do_compile() {
+       set -ex
+       for p in ${CPROGS}
+       do
+               ${CC} ${CFLAGS} -o $p $p.c
+       done
+       set +ex
+}
+
+do_install() {
+       set -ex
+
+       # Directories
+        install -d ${D}${sysconfdir} \
+                   ${D}${sysconfdir}/default \
+                   ${D}${sysconfdir}/init.d \
+                  ${D}${sysconfdir}/modutils \
+                   ${D}${sysconfdir}/udev \
+                  ${D}${sbindir} \
+                  ${D}${base_sbindir} \
+                  ${D}/initrd \
+                  ${D}/boot
+                 
+       # linuxrc
+       rm -f ${D}/linuxrc
+       ln -s boot/flash ${D}/linuxrc
+
+       # C programs
+       for p in ${USRSBINPROGS}
+       do
+               install -m 0755 $p ${D}${sbindir}/$p
+       done
+       for p in ${SBINPROGS}
+       do
+               install -m 0755 $p ${D}${base_sbindir}/$p
+       done
+
+       # Shell scripts
+       for p in ${SCRIPTS}
+       do
+               install -m 0755 $p ${D}${base_sbindir}/$p
+       done
+
+       #
+       # Init scripts
+       install -m 0644 functions ${D}${sysconfdir}/default
+       install -m 0644 modulefunctions ${D}${sysconfdir}/default       
+       for s in ${INITSCRIPTS}
+       do
+               install -m 0755 initscripts/$s ${D}${sysconfdir}/init.d/
+       done
+
+       #
+       # Udev configuration files
+       install -m 0644 links.conf ${D}${sysconfdir}/udev
+
+       #
+       # Boot scripts
+       for p in ${BOOTSCRIPTS}
+       do
+               install -m 0755 boot/$p ${D}/boot
+       done
+
+       # Configuration files
+       install -m 0644 conffiles ${D}${sysconfdir}/default
+
+       set +ex
+}
+
+# If the package is installed on an NSLU2 $D will be empty, in that
+# case it is normal to run 'start' and 'stop', but because the conf
+# files installed don't actually start or stop anything this is
+# unnecessary, so the package postfoo handling is simplified here.
+#NB: do not use '08' (etc) for the first argument after start/stop,
+# the value is interpreted as an octal number if there is a leading
+# zero.
+pkg_postinst_openprotium-init() {
+       opt=
+       test -n "$D" && opt="-r $D"
+       update-rc.d $opt hwclock.sh             start  8 S . start 45 0 6 .
+       update-rc.d $opt umountinitrd.sh        start  9 S .
+       update-rc.d $opt fixfstab               start 10 S .
+       update-rc.d $opt syslog.buffer          start 11 S . start 49 0 6 .
+       update-rc.d $opt sysconfsetup           start 12 S .
+       update-rc.d $opt loadmodules.sh         start 21 S .
+       update-rc.d $opt syslog.file            start 39 S . start 47 0 6 .
+       update-rc.d $opt syslog.network         start 44 S . start 39 0 6 .
+       update-rc.d $opt rmrecovery             start 99 1 2 3 4 5 .
+}
+
+pkg_postrm_openprotium-init() {
+       opt=
+       test -n "$D" && opt="-r $D"
+       for s in ${INITSCRIPTS}
+       do
+               update-rc.d $opt "$s" remove
+       done
+}
+
+PACKAGES = "${PN}"
+FILES_${PN} = "/"
+
+# It is bad to overwrite /linuxrc as it puts the system back to
+# a flash boot (and the flash has potentially not been upgraded!)
+CONFFILES_${PN} = "/linuxrc ${sysconfdir}/default/conffiles"
index 7ba60e6..2a3a3e3 100644 (file)
@@ -16,10 +16,23 @@ load_functions sysconf
 case "$(machine)" in
 nslu2)
        isnslu2=1
+       isdsmg600=
+       imageok=1
+       usrpart=
        kpart="Kernel"
        ffspart="Flashdisk";;
+dsmg600)
+       isnslu2=
+       isdsmg600=1
+       imageok=1
+       usrpart="usr"
+       kpart="kernel"
+       ffspart="filesystem";;
 *)
        isnslu2=
+       isdsmg600=
+       imageok=
+       usrpart=
        kpart="kernel"
        ffspart="filesystem";;
 esac
@@ -32,9 +45,12 @@ esac
 ffsfile=
 kfile=
 imgfile=
+preserve_config=1
 while test $# -gt 0
 do
        case "$1" in
+       -n)     preserve_config=
+               shift;;
        -k)     shift
                test $# -gt 0 || {
                        echo "reflash: -k: give the file containing the kernel image" >&2
@@ -50,9 +66,10 @@ do
                ffsfile="$1"
                shift;;
        -i)     shift
-               test -n "$isnslu2" || {
-                       echo "reflash: -i: only supported on the LinkSys NSLU2" >&2
-                       echo " use -k and -j to specify the kernel and root file system" >&2
+               test -n "$imageok" || {
+                       echo "reflash: -i: only supported on the LinkSys NSLU2"     >&2
+                       echo " and the D-Link DSM-G600 systems; use -k and -j"      >&2
+                       echo " to specify the kernel and root file system instead." >&2
                        exit 1
                }
                test $# -gt 0 || {
@@ -61,15 +78,16 @@ do
                }
                imgfile="$1"
                shift;;
-       *)      if test -n "$isnslu2"
+       *)      if test -n "$imageok"
                then
-                       echo "reflash: usage: $0 [-k kernel] [-j rootfs] [-i image]" >&2
+                       echo "reflash: usage: $0 [-n] [-k kernel] [-j rootfs] [-i image]" >&2
                else
-                       echo "reflash: usage: $0 [-k kernel] [-j rootfs]" >&2
+                       echo "reflash: usage: $0 [-n] [-k kernel] [-j rootfs]" >&2
                fi
+               echo "  -n: do not attempt to preserve the configuration" >&2
                echo "  -k file: the new compressed kernel image ('zImage')" >&2
                echo "  -j file: the new root file system (jffs2)" >&2
-               test -n "$isnslu2" &&
+               test -n "$imageok" &&
                        echo "  -i file: a complete flash image (gives both kernel and jffs2)" >&2
                echo " The current jffs2 will be umounted if mounted." >&2
                exit 1;;
@@ -77,7 +95,7 @@ do
 done
 #
 # Sanity check on the arguments (note that the first case can only fire
-# on NSLU2 because of the check for -i above.)
+# on NSLU2 or DSM-G600 because of the check for -i above.)
 if test -n "$imgfile" -a -n "$ffsfile" -a -n "$kfile"
 then
        echo "reflash: specify at most two files" >&2
@@ -93,7 +111,7 @@ fi
 # Perform basic checks on the input (must exist, size must be ok).
 if test -n "$imgfile"
 then
-       if test -r "$imgfile"
+       if test -r "$imgfile" -a -n "$isnslu2"
        then
                # read the partition table and from this find the offset
                # and size of $kpart and $ffspart partitions.  The following
@@ -162,6 +180,53 @@ EOI
                        echo "reflash: $imgfile: failed to find $ffspart" >&2
                        exit 1
                }
+       elif test -r "$imgfile" -a -n "$isdsmg600"
+       then
+               #
+               # For the DSM-G600, this is really easy - the image is just
+               # a tar file.  So, extract the contents of the tar file, and
+               # set the kernel and filesystem variables (if not already set)
+               # to point to the extracted content.  Content will look like:
+               # 
+               # drwxr-xr-x 500/500         0 2006-11-25 23:47:59 firmupgrade
+               # -rw-r--r-- 500/500   4718592 2006-12-02 16:32:51 firmupgrade/rootfs.gz
+               # -rw-r--r-- 500/500        40 2006-11-25 22:15:41 firmupgrade/version.msg
+               # -rw-r--r-- 500/500         0 2006-11-25 23:47:59 firmupgrade/usr.cramfs
+               # -rw-rw-r-- 500/500   1306872 2006-12-02 16:33:37 firmupgrade/ip-ramdisk
+               # 
+               # Heuristic: if the size of usr.cramfs is zero, the firmware
+               # is not a D-Link firmware for the device.  (The version.msg
+               # file is not useful for this purpose; it describes the hardware,
+               # not the firmware version in the image!)
+               # 
+               # TODO: If usr.cramfs is non-zero, we should flash that, too, just
+               #       to make sure that it matches the native firmware's kernel
+               #       and rootfs that we're now flashing back onto the device.
+
+               echo "reflash: unpacking DSM-G600 image file" >&2
+               tar -x -f "$imgfile" -C /var/tmp || {
+                       echo "reflash: unable to unpack image file to be flashed" >&2
+                       exit 1
+               }
+
+               if test -z "$kfile"
+               then
+                       kfile="/var/tmp/firmupgrade/ip-ramdisk"
+               fi
+
+               if test -z "$ffsfile"
+               then
+                       ffsfile="/var/tmp/firmupgrade/rootfs.gz"
+               fi
+
+               if test -s "/var/tmp/firmupgrade/usr.cramfs"
+               then
+                       echo "reflash: Native flash being restored" >&2
+                       usrfile="/var/tmp/firmupgrade/usr.cramfs"
+                       preserve_config=
+                       dsmg600_native_flash=1
+               fi
+
        else
                echo "reflash: $imgfile: image file not found" >&2
                exit 1
@@ -193,6 +258,19 @@ then
 else
        ffsfile="$imgfile"
 fi
+if test -n "$usrfile"
+then
+       if test ! -r "$usrfile"
+       then
+               echo "reflash: $usrfile: usr file system image file not found" >&2
+               exit 1
+       fi
+       # values override those from the image
+       imgusrsize="$(devio "<<$usrfile" 'pr$')"
+       imgusroffset=0
+else
+       usrfile=
+fi
 #
 # INPUTS OK, CHECKING THE ENVIRONMENT
 # -----------------------------------
@@ -238,6 +316,26 @@ then
                exit 1
        }
 fi
+#
+usrdev=
+usrsize=0
+if test -n "$usrfile"
+then
+       usrdev="$(mtblockdev $usrpart)"
+       test -n "$usrdev" -a -b "$usrdev" || {
+               echo "reflash: $usrpart($usrdev): cannot find $usrpart mtd partition." >&2
+               echo "  check /proc/mtd, either the partition does not exist or there is no" >&2
+               echo "  corresponding block device." >&2
+               exit 1
+       }
+       usrsize="$(devio "<<$usrdev" 'pr$')"
+       #
+       # check the input file size
+       test -n "$imgusrsize" -a "$imgusrsize" -gt 0 -a "$imgusrsize" -le "$usrsize" || {
+               echo "reflash: $usrfile: bad $usrpart size ($imgusrsize, max $usrsize)" >&2
+               exit 1
+       }
+fi
 
 #
 # INPUTS OK, ENVIRONMENT OK, UMOUNT ANY EXISTING MOUNT OF THE FLASHDISK
@@ -280,7 +378,7 @@ fi
 # PRESERVE EXISTING CONFIGURATION
 # -------------------------------
 # Only required if the flash partition will be written
-if test -n "$ffsdev"
+if test -n "$ffsdev" -a -n "$preserve_config"
 then
        echo "reflash: preserving existing configuration file" >&2
        #
@@ -352,6 +450,14 @@ do_ffs() {
                fb #t-,255'
 }
 #
+do_usr() {
+       devio $progress "$@" "<<$usrfile" ">>$usrdev" '
+               # usrfs is at imgusroffset[imgusrsize]
+               ' "<= $imgusroffset" "cp $imgusrsize" '
+               # fill with 255
+               fb #t-,255'
+}
+#
 # check_status $? type file(offset,size) device
 #  check the devio status code (given in $1)
 check_status() {
@@ -384,6 +490,13 @@ check_status() {
        esac
 }
 #
+if test -n "$usrdev"
+then
+       echo -n "reflash: writing usrfs to $usrdev " >&2
+       do_usr
+       check_status $? usrfs "$usrfile($imgusroffset,$imgusrsize)" "$usrdev"
+fi
+#
 if test -n "$ffsdev"
 then
        echo -n "reflash: writing rootfs to $ffsdev " >&2
@@ -399,6 +512,19 @@ then
 fi
 #
 # verify - this just produces a warning
+if test -n "$usrdev"
+then
+       echo -n "reflash: verifying new usr image " >&2
+       if do_usr -v
+       then
+               echo " done" >&2
+       else
+               echo " failed" >&2
+               echo "reflash: WARNING: usrfs flash image verification failed" >&2
+               echo "  The system is may be bootable." >&2
+       fi
+fi
+#
 if test -n "$ffsdev"
 then
        echo -n "reflash: verifying new flash image " >&2
@@ -432,7 +558,7 @@ fi
 # RESTORE THE OLD CONFIGURATION
 # -----------------------------
 # If not write the rootfs none of the following is required - exit now.
-test -n "$ffsdev" || exit 0
+test -n "$ffsdev" -a -n "$preserve_config" || exit 0
 #
 echo "reflash: restoring saved configuration files" >&2
 #
index 94f156f..4b9235e 100644 (file)
@@ -4,7 +4,7 @@ PRIORITY = "required"
 LICENSE = "GPL"
 DEPENDS = "base-files devio"
 RDEPENDS = "busybox devio"
-PR = "r76"
+PR = "r77"
 
 SRC_URI = "file://boot/flash \
           file://boot/disk \