Hi Marc

On Mon, Oct 29, 2007 at 8:33 PM, Gordon Farquharson
<[EMAIL PROTECTED]> wrote:

>  I'd like to add the flash-apex script (submitted previously) to the
>  apex package, and have it run after apex is installed. Is this a good
>  idea? If so, is the postinst script the best way to achieve this goal,
>  and are there any references other than the one below for writing
>  postinst scripts?

The patch below is my attempt at adding the flash-apex script and a
postinst script to the apex package. The diff is created between apex
version 1.5.13 and an imaginary version 1.5.14.

Would it be possible for you to incorporate these changes, along with
the changes in #451882, into your latest apex version, and upload the
new package?

Thanks.

Gordon

diff -Naur apex-1.5.13/debian/changelog apex-1.5.14/debian/changelog
--- apex-1.5.13/debian/changelog        2007-06-25 18:25:59.000000000 -0600
+++ apex-1.5.14/debian/changelog        2008-03-02 21:16:41.000000000 -0700
@@ -1,3 +1,10 @@
+apex (1.5.14) UNRELEASED; urgency=low
+
+  * Add flash-apex script.
+  * Add postinst script to run flash-apex on installation.
+
+ -- Marc Singer <[EMAIL PROTECTED]>  Sun,  2 Mar 2008 21:14:09 -0700
+
 apex (1.5.8) unstable; urgency=low

   * Added 'release' comand to the apex-env.
diff -Naur apex-1.5.13/debian/postinst apex-1.5.14/debian/postinst
--- apex-1.5.13/debian/postinst 1969-12-31 17:00:00.000000000 -0700
+++ apex-1.5.14/debian/postinst 2008-03-02 17:57:00.000000000 -0700
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# Abort if any command returns an error value
+set -e
+
+if [ "$1" = "configure" ] && [ -x /usr/sbin/flash-apex ]; then
+       /usr/sbin/flash-apex
+fi
diff -Naur apex-1.5.13/debian/rules apex-1.5.14/debian/rules
--- apex-1.5.13/debian/rules    2007-06-25 18:14:03.000000000 -0600
+++ apex-1.5.14/debian/rules    2008-03-02 21:37:39.000000000 -0700
@@ -58,6 +58,7 @@
        install -m 0644 src/arch-arm/rom/apex.bin\
                  debian/$(package)/boot/apex.flash
        install -m 0755 usr/apex-env debian/$(package)/usr/sbin
+       install -m 0755 usr/flash-apex debian/$(package)/usr/sbin
        dh_strip
        dh_installchangelogs ChangeLog
        dh_installdocs -a
diff -Naur apex-1.5.13/usr/flash-apex apex-1.5.14/usr/flash-apex
--- apex-1.5.13/usr/flash-apex  1969-12-31 17:00:00.000000000 -0700
+++ apex-1.5.14/usr/flash-apex  2008-03-02 17:33:26.000000000 -0700
@@ -0,0 +1,92 @@
+#!/bin/sh
+
+# Copyright (C) 2006  Joey Hess  <[EMAIL PROTECTED]>
+# Copyright (C) 2006  Martin Michlmayr <[EMAIL PROTECTED]>
+# Copyright (C) 2007  Gordon Farquharson <[EMAIL PROTECTED]>
+
+# This code is covered by the GNU General Public License.
+
+set -e
+
+error() {
+       echo "$@" >&2
+       exit 1
+}
+
+check_mtd() {
+       if [ ! -e /proc/mtd ]; then
+               error "/proc/mtd doesn't exist"
+       fi
+}
+
+mtdblock() {
+       grep "$1" /proc/mtd | cut -d: -f 1 | sed 's/mtd/\/dev\/mtdblock/'
+}
+
+# See http://www.nslu2-linux.org/wiki/Info/BootFlash -- the NSLU2 uses a
+# 16 byte MTD header, the first four bytes (big endian) give the length of
+# the remainder of the image, and the remaining bytes are zero.  Generate
+# this header.
+sercomm_header() {
+       perl -e 'print pack("N4", shift)' "$1"
+}
+
+nslu2_swap() {
+       if [ "$little_endian" ]; then
+               devio "<<"$1 "xp $,4"
+       else
+               cat $1
+       fi
+}
+
+apex_file=/boot/apex.flash
+
+if [ ! -e $apex_file ]; then
+       error "Can't find $apex_file"
+fi
+
+machine=$(grep "^Hardware" /proc/cpuinfo | sed 's/Hardware\s*:\s*//')
+case "$machine" in
+       "Linksys NSLU2")
+               check_mtd
+               case "$(dpkg --print-architecture)" in
+                       arm|armel)
+                               little_endian=1
+                       ;;
+                       armeb)
+                               little_endian=0
+                       ;;
+               esac
+               mtdloader=$(mtdblock Loader)
+               if [ -z "$mtdloader" ]; then
+                       error "Cannot find mtd partition 'Loader'"
+               fi
+               lsize=$(wc -c $apex_file | awk '{print $1}')
+               mtdblocksize=131072
+               pad=$(expr $mtdblocksize - $lsize - 16)
+               # Store non-default APEX configuration
+               tmp=$(tempfile)
+               (apex-env printenv | egrep -v '\*=') > $tmp
+               printf "Flashing loader: " >&2
+               (
+                       sercomm_header $(expr $lsize + 16)
+                       nslu2_swap $apex_file
+                       perl -e "print pack(\"C\", 0xff) x $pad"
+               ) > "$mtdloader" || error "failed."
+               # Write the stored APEX configuration. For each line,
+               # remove whitespace from the start and the end of the
+               # line, and use all the characters, including
+               # whitespace, after '=' as the value.
+               while read line
+               do
+                       key=$(echo $line | cut -d '=' -f1 | awk '{print $1}')
+                       val=$(echo $line | awk '{$1=""; $2=""; print 
substr($0,3)}')
+                       apex-env setenv "$key" "$val"
+               done < $tmp
+               rm $tmp
+               echo "done." >&2
+       ;;
+       *)
+               error "Unsupported platform."
+       ;;
+esac

-- 
Gordon Farquharson
GnuPG Key ID: 32D6D676



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to