This is the first user of usbmount, so several things
to note...

 - The usbmount scripts don't get a tty, which means
   that we need sudo to allow nontty usage (changed
   in xs-config for root)

 - We check manifest.md5 with a custom utility called
   xs-check-signature, initially a wrapper around md5sum
   that ensures that all files in the directory are in
   the manifest. This script is not included here.

 - We use /usr/bin/logger (to syslog) for output and
   logging, we log to the 'user' facility. Moodle will
   later have a 'tail -f /var/log/user.log'.

 - Stock syslog.conf in fedora drop the user messages,
   so xs-config has been updated to log to user.log

 - It is important to show progress towards completion
   so each msg has an indication of how far along we are.

 - We'll need to localise these. Tricky -
---
 Makefile                            |    2 +
 usbmount-50-xs-rsync-installcontent |   62 +++++++++++++++++++++++++++++++++++
 xs-rsync.spec.in                    |    2 +
 3 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100755 usbmount-50-xs-rsync-installcontent

diff --git a/Makefile b/Makefile
index 729b0b4..f78173f 100644
--- a/Makefile
+++ b/Makefile
@@ -82,6 +82,8 @@ install:
        install -D -m 644 xinetd-xs-rsyncd.conf 
$(DESTDIR)/etc/xinetd.d/xs-rsyncd
        install -D -m 644 crond-xs-rsync.conf   $(DESTDIR)/etc/cron.d/xs-rsync
 
+       install -D -m 755 usbmount-50-xs-rsync-installcontent 
$(DESTDIR)/etc/usbmount/mount.d/50-xs-rsync-installcontent
+
        # root owned
        install -D -d $(DESTDIR)/library/xs-rsync
        install -D -d $(DESTDIR)/library/xs-rsync/xobuilds-packed
diff --git a/usbmount-50-xs-rsync-installcontent 
b/usbmount-50-xs-rsync-installcontent
new file mode 100755
index 0000000..9bfeed4
--- /dev/null
+++ b/usbmount-50-xs-rsync-installcontent
@@ -0,0 +1,62 @@
+#!/bin/bash -x
+# Part of the xs-sync package
+# Author: Martin Langhoff <[EMAIL PROTECTED]>
+# Copyright: One Laptop per Child
+
+set -e
+
+VERBOSE=no
+
+# Log a string via the syslog facility.
+log()
+{
+    if test $1 != debug || expr "$VERBOSE" : "[yY]" > /dev/null; then
+       logger -p user.$1 -t "xs-rsync[$$]" -- "$2"
+    fi
+}
+STEPS=5
+
+if [ -e $UM_MOUNTPOINT/xs-xobuilds -a \
+     -e $UM_MOUNTPOINT/xs-xobuilds/manifest.md5 ];then
+    log notice 'Found xobuilds to install!';
+    log notice "[1/$STEPS] Checking signature]";
+
+    xs-check-signature $UM_MOUNTPOINT/xs-xobuilds/manifest.md5
+
+    log notice "[2/$STEPS] Checking checksum on external disk";
+    pushd $UM_MOUNTPOINT/xs-xobuilds
+    md5sum -c manifest.md5
+    popd
+
+    ## Do we have enough space?
+    # note: we could use awk {'print $4'} instead of the
+    # perl regex, but it breaks with long /dev nodes
+    # such as those from LVMs -which wrap. The regex captures the
+    # number just left of the number with the percentage sign.
+    NEED=`du -s -B1M $UM_MOUNTPOINT/xs-xobuilds | awk {'print $1'}`
+    HAVE=`df -B1M /library/xs-rsync | tail -n1 | \
+         perl -pe 'm/(\d+)\s+\d+\%/; $_=$1;'`
+    if [ $NEED -gt $HAVE ];then
+       log err 'Not enough free space in /library for this xo image - 
cancelling';
+       exit 1;
+    fi
+
+    ### Copy it first - as the media is bound to be slow
+    # - make this atomic by cp'ing to a tmpdir, and mv'ing into place
+    #   to be fail-safe
+    # - remove - manifest.md5
+    # - TODO? we could avoid cp'ing files we already have using
+    #   rsync --copy-dest instead of cp
+    #
+    log notice "[3/$STEPS] Copying xo-builds to xobuilds-packed";
+    TMPDEST=`mktemp -d -p /library/xs-rsync/tmp`
+    cp $UM_MOUNTPOINT/xs-xobuilds/* $TMPDEST
+    rm $TMPDEST/manifest.md5
+    mv $TMPDEST/* /library/xs-rsync/xobuilds-packed/
+
+    log notice "[4/$STEPS] Refreshing XO builds available";
+    (/usr/bin/xs-refresh-xobuilds.py 2>&1 ) | logger -p user.debug -t 
"xs-rsync[$$]"
+    log notice "[5/$STEPS] Finished - XOs can now update.";
+
+
+fi # end if we have xs-xobuilds/manifest.md5
\ No newline at end of file
diff --git a/xs-rsync.spec.in b/xs-rsync.spec.in
index 0fc0c46..3b0f103 100644
--- a/xs-rsync.spec.in
+++ b/xs-rsync.spec.in
@@ -20,6 +20,7 @@ Requires:       fakeroot
 Requires:       fakechroot
 Requires:       bash
 Requires:       vixie-cron
+Requires:       usbmount
 
 %description
 XS rsync provides support for publishing resources on the XS via rsync.
@@ -79,6 +80,7 @@ make install DESTDIR=$RPM_BUILD_ROOT
 %config(noreplace) %{_sysconfdir}/xs-rsyncd.conf.in
 %config(noreplace) %{_sysconfdir}/xinetd.d/xs-rsyncd
 %config(noreplace) %{_sysconfdir}/cron.d/xs-rsync
+%config(noreplace) %{_sysconfdir}/usbmount/mount.d/50-xs-rsync-installcontent
 %dir  /library/xs-rsync/xobuilds-packed
 %attr(755, xs-rsync, xs-rsync) %dir /library/xs-rsync/pub
 %attr(755, xs-rsync, xs-rsync) %dir /library/xs-rsync/pub/builds
-- 
1.5.5.1

_______________________________________________
Server-devel mailing list
Server-devel@lists.laptop.org
http://lists.laptop.org/listinfo/server-devel

Reply via email to