[CUWiN-Dev] cuwin media-builder cgi, anyone?

Bill Comisky bcomisky at pobox.com
Mon Jan 9 19:31:26 CST 2006


On Sun, 8 Jan 2006, David Young wrote:

> On Mon, Dec 19, 2005 at 07:17:36PM -0600, David Young wrote:
>> Sascha and I were talking about how futile it is to distribute multiple
>> CompactFlash geometries, when there are so many brands and sizes for
>> sale, each with a different geometry.
>
> Stephane stepped up and wrote a CGI.  All the parts are checked
> into cuw/trunk/localsrc/web-builder/ and cuw/trunk/src/boot-image/.
> Will someone review & deploy this for the 0.6.0 release?

I have it running with the 0.6.0 branch and 26-Dec-2005 netBSD snapshot 
here:

http://flatiron.cntwireless.org/cuwin/buildflash

It seems to be working fine, but I haven't actually installed a built 
image for the final test. I made a few changes (see attached patch), let 
me know if they look ok & you want me to commit them.  The changes include 
the following:

cuwin.cgi
- Serve compressed (gzip) images instead of uncompressed.
- Use tempfile() instead of mkstemp() in cuwin.cgi to automatically
   clean temporary queue lockfiles.

kickbuildweb
- gzip build images.
- Fixes to collect_garbage():  cd to ${FS_BASE}/built directory to remove
   files (ls doesn't give full path), update count if files are deleted
   when count > maxcount.
- Use '-n' with head.

Bill

--
Bill Comisky
bcomisky at pobox.com
-------------- next part --------------
Index: src/boot-image/kickbuildweb
===================================================================
--- src/boot-image/kickbuildweb	(revision 3803)
+++ src/boot-image/kickbuildweb	(working copy)
@@ -44,15 +44,16 @@
 
 collect_garbage()
 {
-	count=$(ls ${FS_BASE}/built | wc -l)
+	cd ${FS_BASE}/built
+	count=$(ls | wc -l)
 
 	#
 	# Delete the oldest images so we stay at or below the maximum image
 	# count.
 	#
 	if [ $count -gt $maxcount ]; then
-		ls -t ${FS_BASE}/built | tail -n +$(($maxcount + 1)) | \
-		    xargs rm -f
+		ls -t | tail -n +$(($maxcount + 1)) | xargs rm -f
+		count=$maxcount
 	fi
 
 	#
@@ -60,17 +61,19 @@
 	# until there is just one image left, whichever comes first.
 	#
 	while [ $count -gt 1 ]; do
-		set -- $(du -ks ${FS_BASE}/built)
+		set -- $(du -ks)
 		size=$1
 		path=$2
 		if [ $size -le $maxsize ]; then
 			break
 		fi
-		if ! ls -rt ${FS_BASE}/built | head -n 1 | xargs rm ; then
+		if ! ls -rt | head -n 1 | xargs rm ; then
 			break
 		fi
 		count=$(($count - 1))
 	done
+
+	cd -
 }
 
 trap cleanup EXIT HUP INT TERM 
@@ -100,7 +103,7 @@
 fi
 
 while lockqueue; do
-	queue_file=$(ls -rt ${FS_BASE}/queue/*.img 2>/dev/null | head -1)
+	queue_file=$(ls -rt ${FS_BASE}/queue/*.img 2>/dev/null | head -n 1)
 	if [ x$queue_file = x ]; then
                 # [race] When this thread quits the build loop, it
                 # has to release the locks in this order so that
@@ -115,7 +118,7 @@
 	fi
 	image=$(basename $queue_file)
 	building_file=${FS_BASE}/building/$image
-	built_file=${FS_BASE}/built/$image
+	built_file=${FS_BASE}/built/$image.gz
 	if ! mv $queue_file $building_file ; then
 		# Must release locks in this order.  See [race].
 		rm -f $FS_BASE/buildlock
@@ -144,8 +147,10 @@
 	fi
 	rm -f $disktab
 
+	gzip -9 -c $building_file > $building_file.gz
 	if lockqueue; then
-		mv $building_file $built_file
+		mv $building_file.gz $built_file
+		rm -f $building_file
 		collect_garbage
 		rm -f $FS_BASE/qlock
 	else
Index: localsrc/web-builder/cuwin.cgi
===================================================================
--- localsrc/web-builder/cuwin.cgi	(revision 3803)
+++ localsrc/web-builder/cuwin.cgi	(working copy)
@@ -7,7 +7,7 @@
 use strict;
 use warnings;
 
-use File::Temp ':mktemp';
+use File::Temp qw(tempfile);
 # For troubleshooting
 use CGI::Carp qw(fatalsToBrowser);
 #
@@ -106,7 +106,7 @@
 		<h1>Build a CUWiN image file</h1>
 EO1
 	$cgi->start_form,
-	"<br />Columns (C): ",	$cgi->textfield('c'),
+	"<br />Cylinders (C): ",	$cgi->textfield('c'),
 	"<br />Heads (H): ",	$cgi->textfield('h'),
 	"<br />Sectors (S): ",	$cgi->textfield('s'),
 	$cgi->submit,
@@ -124,8 +124,13 @@
 {
 	my ($c,$h,$s) = @_;
 	my $name = "${target_arch}-$c-$h-$s.img";
-	for my $s (qw(built building queue)) {
-		return [$s, "$url_base/$s/$name"] if -e "$fs_base/$s/$name";
+	my %names = (
+		built => "$name.gz",
+		building => $name,
+		queue => $name
+	);
+	for my $s (keys %names) {
+		return [$s, "$url_base/$s/$names{$s}"] if -e "$fs_base/$s/$names{$s}";
 	}
 	return ['new', ''];
 }
@@ -150,7 +155,7 @@
 {
 	my $tries = 0;
 
-	my ($fh, $filename) = mkstemp("$fs_base/qlock.XXXXXX");
+	my ($fh, $filename) = tempfile("qlock.XXXXXX", DIR => $fs_base, UNLINK => 1);
 
 	close($fh);
 	do  {
@@ -190,8 +195,11 @@
 		<title>Image is available for download</title>
 	</head>
 	<body>
-		Your file is available for download at
-		<a href="$location">$location</a>.
+		Your gzip compressed image file is available for download at:
+		<br />
+		<a href="$location">$location</a>
+		<br />
+		<br />Remember to gunzip the image before writing to your flash device.
 	</body>
 </html>
 EOT
@@ -205,8 +213,8 @@
 		<title>Image is being built</title>
 	</head>
 	<body>
-		Your file is currently being built.  <a href="$back">Come
-		back later to download it.</a>
+		Your file is currently being built.
+		<br /><a href="$back">Come back later to download it.</a>
 	</body>
 </html>
 EOT
@@ -218,7 +226,7 @@
 <html><head><title>Image is in queue</title></head>
 <body>
 Your file is currently in queue and will be built as soon as possible.
-<a href="$back">Come back later to download it.</a>
+<br /><a href="$back">Come back later to download it.</a>
 </body></html>
 EOT
 		return;
@@ -231,7 +239,7 @@
 <html><head><title>Image requested</title></head>
 <body>
 Your file has been requested and will be built as soon as possible.
-<a href="$back">Come back later to download it.</a>
+<br /><a href="$back">Come back later to download it.</a>
 </body></html>
 EOT
 		return;


More information about the CU-Wireless-Dev mailing list