Hi people,
        i'm the administrator of several computers labs with around 300
computers with dual boot and i needed to "autoupdate" them frequently.
        With the inclusion of the "IMAGE_RETRIEVAL_TIME" recently in the CVS
version os systemimager, i managed to create a little script to do this
action really easy.
        Apart of this, i usually modified the images via chroot, so the
IMAGE_RETRIEVAL_TIME is not update (only via getimage), that's why i
created a new command, touchimage to do that.
        Some work is still necesary and the inclusion of a IMAGE_SERVER file in
the client images will be really useful.
        
        Anyway, i included my work here. MAybe is not so good to include it in
the official release, but someone can have the same problem and we can
improved a littel more.
        Comments are really welcomed.

        Ghe Rivero
diff -urN --exclude CVS systemimager/etc/default/si-client systemimager.local/etc/default/si-client
--- systemimager/etc/default/si-client	1970-01-01 01:00:00.000000000 +0100
+++ systemimager.local/etc/default/si-client	2004-06-26 00:59:29.000000000 +0200
@@ -0,0 +1,7 @@
+## SystemImager client update
+
+# Change to 1 to enable 
+ENABLED=0
+
+# ImageServer to use
+SERVER=
diff -urN --exclude CVS systemimager/etc/init.d/systemimager-client-updateimage systemimager.local/etc/init.d/systemimager-client-updateimage
--- systemimager/etc/init.d/systemimager-client-updateimage	1970-01-01 01:00:00.000000000 +0100
+++ systemimager.local/etc/init.d/systemimager-client-updateimage	2004-06-26 00:54:41.000000000 +0200
@@ -0,0 +1,82 @@
+#! /bin/sh
+#
+#   Written 
+#       by Ghe Rivero <[EMAIL PROTECTED]>.
+#
+#   $Id: systemimager-client-update,v 0.1 2004/06/25 03:03:32 Ghe Rivero Exp $
+#
+# description: Updates the client with the last SystemImager image available
+#
+# Support for LSB compliant init system:
+### BEGIN INIT INFO
+# Provides: systemimager
+# Required-Start: $network $syslog
+# Required-Stop:
+# Default-Start:  3 5
+# Default-Stop:   0 1 2 6
+# Short-Description: Updates the client with the last SystemImager image
+# Description: connects to the SystemImager server and look for
+#						a new image to retrive it.
+#
+### END INIT INFO
+
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin
+DESC="SystemImager update client system"
+
+TMPDIR=`mktemp -d /tmp/si-client.XXXXXX` || exit 1
+
+test -f /etc/default/si-client && . /etc/default/si-client
+
+test "$ENABLED" != "0" || exit 0
+
+set -e
+
+case "$1" in
+  start)
+	echo  -n "Starting $DESC: "
+	
+	test -f /etc/systemimager/IMAGE_RETRIEVAL_TIME && LAST_RETRIEVAL_TIME=`cat /etc/systemimager/IMAGE_RETRIEVAL_TIME`
+	
+	if [ -f /etc/systemimager/IMAGE_LAST_SYNCED_TO ]
+	then
+	        IMAGE=`cat /etc/systemimager/IMAGE_LAST_SYNCED_TO`
+	else
+	        echo  "/etc/systemimager/IMAGE_LAST_SYNCED_TO not found"
+		exit 1;
+	fi
+	
+	rsync $SERVER:$IMAGE//etc/systemimager/IMAGE_RETRIEVAL_TIME $TMPDIR/IMAGE_RETRIEVAL_TIME --timeout=5 -c
+	
+	test -f $TMPDIR/IMAGE_RETRIEVAL_TIME && NEW_RETRIEVAL_TIME=`cat $TMPDIR/IMAGE_RETRIEVAL_TIME`
+
+	if [ -z "$NEW_RETRIEVAL_TIME" ]
+	then 
+		echo "No update available"
+	fi
+	
+	if [  "$LAST_RETRIEVAL_TIME" -ne "$NEW_RETRIEVAL_TIME" ]
+	then
+		updateclient -server $SERVER -image $IMAGE
+	else
+		echo "Already updated"
+	fi
+	;;
+
+  stop)
+	echo "Stopping $DESC: "
+	;;
+
+  restart|force-reload)
+	$0 stop
+	sleep 1
+	$1 start
+	
+	;;
+
+  *)
+	echo "Usage: $1 {start|stop|restart|orce-reload}" >&2
+	exit 1
+	;;
+esac
+
+exit 0
Los ficheros systemimager/etc/init.d/.systemimager-client-updateimage.swp y systemimager.local/etc/init.d/.systemimager-client-updateimage.swp son distintos
diff -urN --exclude CVS systemimager/lib/SystemImager/Options.pm systemimager.local/lib/SystemImager/Options.pm
--- systemimager/lib/SystemImager/Options.pm	2004-06-26 00:51:12.000000000 +0200
+++ systemimager.local/lib/SystemImager/Options.pm	2004-06-26 00:55:41.000000000 +0200
@@ -27,6 +27,8 @@
 #   pushupdate_options_header
 #   updateclient_options_body
 #   updateclient_options_header
+#   touchimage_options_body
+#   touchimage_options_header
 #
 ################################################################################
 
@@ -433,6 +435,38 @@
 EOF
 }
 
+#
+# Usage:
+#
+#   $help = $help . SystemImager::Options->touchimage_options_header();
+#
+sub touchimage_options_header {
+
+return << "EOF";
+Usage: touchimage --image IMAGENAME"
+  or   touchimage --image IMAGENAME --directory DIRECTORYNAME"
+
+EOF
+}
+
+
+#
+# Usage:
+#
+#   $help = $help . SystemImager::Options->mkclientnetboot_options_body();
+#
+sub touchimage_options_body {
+
+return << "EOF";
+ --image IMAGENAME
+    Where IMAGENAME is the name of the image you are updating.
+    
+ --directory PATH
+    The full path and directory name where the image is stored.
+    The image name itself will be placed inside the directory specified here.
+
+EOF
+}
 
 return 1;
 
diff -urN --exclude CVS systemimager/sbin/touchimage systemimager.local/sbin/touchimage
--- systemimager/sbin/touchimage	1970-01-01 01:00:00.000000000 +0100
+++ systemimager.local/sbin/touchimage	2004-06-26 00:40:05.000000000 +0200
@@ -0,0 +1,98 @@
+#!/usr/bin/perl -w
+#
+# "SystemImager" 
+#
+#
+#  $Id: touchimage,v 0.1 2004/06/26 05:53:57 Ghe Rivero Exp $
+#
+# TODO
+#    - Add help entrys to SystemImager::Options
+#
+
+# set system path for system() calls
+$ENV{PATH} = "/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin";
+
+# version
+$version_number="SYSTEMIMAGER_VERSION_STRING";
+
+# use the long options module to allow us to use, well, long options ;)
+use lib "/USR_PREFIX/lib/systemimager/perl";
+use Getopt::Long;
+use SystemImager::Server;
+use SystemImager::Common;
+use SystemImager::Config;
+use SystemImager::Options;
+use vars qw($config $VERSION);
+
+my $config_dir = "/etc/systemimager";
+
+my $image;
+my $default_image_dir = $config->default_image_dir();
+
+if (!$default_image_dir) {
+    die "DEFAULT_IMAGEDIR not defined in the config file.";
+}
+
+### BEGIN Program ###
+
+# figure out the program name
+$0  =~ /(.*)\/+([^\/]*)$/;
+$program_name = $2;
+
+$version_info = <<"EOF";
+$program_name (part of SystemImager) v$version_number
+
+EOF
+
+$version_info .= SystemImager::Options->copyright();
+
+$get_help = "          Try \"$program_name -help\" for more options.";
+
+# set help information
+$help_info = $version_info  .  SystemImager::Options->touch_options_header();
+$help_info = $help_info .  SystemImager::Options->generic_options_help_version();
+$help_info = $help_info .  SystemImager::Options->touchimage_options_body();
+$help_info = $help_info .  SystemImager::Options->generic_footer();
+
+### BEGIN evaluate options ###
+GetOptions(
+    "image=s"           => \$image,
+    "directory=s"       => \$default_image_dir,
+    "help"              => \$help,
+    "version"           => \$version,
+) || die "$help_info";
+
+#if requested, print help information
+if ($help) {
+  print "$help_info";
+  exit 0;
+}
+
+# if requested, print version and copyright information
+if ($version) {
+  print "$version_info";
+  exit 0;
+}
+
+# be sure program is run by root
+SystemImager::Common->check_if_root();
+ 
+# image must be set.
+unless ($image) {
+    	die "\n$program_name: You must specify -image.\n$get_help\n\n";
+}
+
+#be sure $image doesn't start with a hyphen
+if($image){
+  if ($image =~ /^-/) {
+    die "\n$program_name: Image name can't start with a hyphen.\n$get_help\n\n";
+  }
+}
+
+# be sure $default_image_dir is an absolute path starting with /
+unless ($default_image_dir =~ /^\//) {
+  die "\n$program_name: -directory must be an absolute path starting with \"/\".\n$get_help\n\n";
+}
+
+$imagedir = "$default_image_dir/$image";
+SystemImager::Server->record_image_retrieval_time($imagedir);

Reply via email to