slitaz-pizza diff web/pizza.cgi @ rev 7

Add the web interface
author Christophe Lincoln <pankso@slitaz.org>
date Sat Mar 24 23:12:44 2012 +0100 (2012-03-24)
parents
children a5164f0bb461
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/web/pizza.cgi	Sat Mar 24 23:12:44 2012 +0100
     1.3 @@ -0,0 +1,369 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# SliTaz Pizza CGI/web interface - Let's me have a pizza :-) 
     1.7 +# Please KISS, it is important and keep speed in mind. Thanks, Pankso.
     1.8 +#
     1.9 +
    1.10 +# Output a RSS feed of latest build isos.
    1.11 +if [ "$QUERY_STRING" == "rss" ]; then
    1.12 +	. /etc/slitaz/pizza.conf
    1.13 +	pubdate=$(date "+%a, %d %b %Y %X")
    1.14 +	cat << EOT
    1.15 +Content-Type: text/xml
    1.16 +
    1.17 +<?xml version="1.0" encoding="utf-8" ?>
    1.18 +<rss version="2.0">
    1.19 +<channel>
    1.20 +	<title>SliTaz Pizza</title>
    1.21 +	<description>The SliTaz Pizza cooker feed</description>
    1.22 +	<link>$PIZZA_URL</link>
    1.23 +	<lastBuildDate>$pubdate GMT</lastBuildDate>
    1.24 +	<pubDate>$pubdate GMT</pubDate>
    1.25 +EOT
    1.26 +	for rss in $(ls -1t $PIZZA/chroot${SLITAZ}/xml/*.xml | head -n 12)
    1.27 +	do
    1.28 +		cat $rss
    1.29 +	done
    1.30 +	cat << EOT
    1.31 +</channel>
    1.32 +</rss>
    1.33 +EOT
    1.34 +	exit 0
    1.35 +fi
    1.36 +
    1.37 +# Content negotiation for Gettext
    1.38 +IFS=","
    1.39 +for lang in $HTTP_ACCEPT_LANGUAGE
    1.40 +do
    1.41 +	lang=${lang%;*} lang=${lang# } lang=${lang%-*}
    1.42 +	[ -d "$lang" ] &&  break
    1.43 +	case "$lang" in
    1.44 +		en) lang="C" ;;
    1.45 +		fr) lang="fr_FR" ;;
    1.46 +	esac
    1.47 +done
    1.48 +unset IFS
    1.49 +export LANG=$lang LC_ALL=$lang
    1.50 +
    1.51 +# Internationalization: $(gettext "")
    1.52 +. /usr/bin/gettext.sh
    1.53 +TEXTDOMAIN='pizza'
    1.54 +export TEXTDOMAIN
    1.55 +
    1.56 +. lib/libpizza
    1.57 +
    1.58 +#
    1.59 +# Commands
    1.60 +#
    1.61 +
    1.62 +case " $(GET) " in
    1.63 +	*\ start\ *)
    1.64 +		#
    1.65 +		# First step
    1.66 +		#
    1.67 +		date=$(date "+%Y%m%d")
    1.68 +		id=$date-$$
    1.69 +		cat << EOT
    1.70 +<h2>$(gettext "First step")</h2>
    1.71 +<p>
    1.72 +	$(gettext "Chosse your distribution name and the one you want to use as
    1.73 +	base. We need our mail to notify you when your SliTaz Flavor is built 
    1.74 +	and if any things goes wrong.")
    1.75 +</p>
    1.76 +<form method="get" action="pkgs.cgi" name="pizza" onsubmit="return checkForm();">
    1.77 +<table>
    1.78 +	<tbody>
    1.79 +		<tr>
    1.80 +			<td>$(gettext "Flavor name")</td>
    1.81 +			<td><input type="text" name="flavor" size="40" /></td>
    1.82 +		</tr>
    1.83 +		<tr>
    1.84 +			<td>$(gettext "Short description")</td>
    1.85 +			<td><input type="text" name="desc" size="40" /></td>
    1.86 +		</tr>
    1.87 +		<tr>
    1.88 +			<td>$(gettext "Email")</td>
    1.89 +			<td><input type="text" name="mail" size="40" /></td>
    1.90 +		</tr>
    1.91 +		<tr>
    1.92 +			<td>$(gettext "Based on")</td>
    1.93 +			<td>
    1.94 +				<select name="skel">
    1.95 +					<option value="base">
    1.96 +						Base - $(gettext "Text mode system")</option>
    1.97 +					<option value="justx">
    1.98 +						Justx - $(gettext "X without GTK or QT")</option>
    1.99 +					<option value="gtkonly">
   1.100 +						Gtkonly - $(gettext "Clean GTK desktop")</option>
   1.101 +					<option value="core">
   1.102 +						Core - $(gettext "Default SliTaz desktop")</option>
   1.103 +				</select>
   1.104 +			</td>
   1.105 +		</tr>
   1.106 +	</tbody>
   1.107 +</table>
   1.108 +<pre>
   1.109 +Uniq ID : $id
   1.110 +</pre>
   1.111 +<div class="next">
   1.112 +	<input type="hidden" name="id" value="$id" />
   1.113 +	<input type="submit" value="$(gettext "Continue")">
   1.114 +</div>
   1.115 +</form>
   1.116 +EOT
   1.117 +		;;
   1.118 +	*\ gen\ *)
   1.119 +		#
   1.120 +		# Generate step
   1.121 +		#
   1.122 +		id="$(GET id)"
   1.123 +		. $tmpdir/slitaz-$id/receipt
   1.124 +		addfiles=$(find $tmpdir/slitaz-$id/addfiles -type f | wc -l)
   1.125 +		[ "$addfiles" ] || addfiles=0
   1.126 +		packages=$(cat $tmpdir/slitaz-$id/packages.list | wc -l)
   1.127 +		cat << EOT
   1.128 +<h2>$(gettext "Generate")</h2>
   1.129 +<p>
   1.130 +	Last chance to stop process or start over. Next step will pack your
   1.131 +	flavor and add it to the build queue. Here you can also add note to
   1.132 +	your receipt flavor, this will be displayed on your flavor ID page
   1.133 +	and can be used to give more infos to other users and SliTaz developers.
   1.134 +</p>
   1.135 +<pre>
   1.136 +Uniq ID    : $id
   1.137 +Flavor     : $FLAVOR
   1.138 +Short desc : $SHORT_DESC
   1.139 +Maintainer : $MAINTAINER
   1.140 +Packages   : $packages
   1.141 +Addfiles   : $addfiles
   1.142 +</pre>
   1.143 +<form method="get" action="./">
   1.144 +<div class="box">
   1.145 +	Note:
   1.146 +	<input type="text" name="note" style="width: 720px;" />
   1.147 +</div>
   1.148 +	<div class="next">
   1.149 +		<input type="submit" name="cancel" value="$(gettext "Cancel")">
   1.150 +		<input type="hidden" name="addfiles" value="$addfiles" />
   1.151 +		<input type="hidden" name="id" value="$id" />
   1.152 +		<input type="submit" name="pack" value="$(gettext "Build flavor")">
   1.153 +	</div>
   1.154 +</form>
   1.155 +EOT
   1.156 +		;;
   1.157 +	*\ cancel\ *)
   1.158 +		id="$(GET id)"
   1.159 +		echo "<p>Removing temporary files for: $id</p>" 
   1.160 +		[ -d "$tmpdir/slitaz-$id" ] && rm -rf $tmpdir/slitaz-$id/
   1.161 +		cat << EOT
   1.162 +<form method="get" action="./">
   1.163 +	<input type="submit" name="start" value="$(gettext "Start over")">
   1.164 +</form>
   1.165 +EOT
   1.166 +		;;
   1.167 +	*\ pack\ *)
   1.168 +		#
   1.169 +		# Pack distro step
   1.170 +		#
   1.171 +		id="$(GET id)"
   1.172 +		receipt="$tmpdir/slitaz-$id/receipt"
   1.173 +		addfiles="$(GET addfiles)"
   1.174 +		log="$tmpdir/slitaz-$id/distro.log"
   1.175 +		note="$(GET note)"
   1.176 +		inqueue=$(ls $queue | wc -l)
   1.177 +		. $receipt
   1.178 +		cat << EOT
   1.179 +<h2>$(gettext "Packing:") $FLAVOR</h2>
   1.180 +<pre>
   1.181 +EOT
   1.182 +		if ! fgrep ADDFILES $receipt; then
   1.183 +			echo "ADDFILES=\"$addfiles\"" >> $receipt
   1.184 +		fi
   1.185 +		if ! fgrep NOTE $receipt; then
   1.186 +			echo "NOTE=\"$note\"" >> $receipt
   1.187 +		fi
   1.188 +		
   1.189 +		# The rootcd README
   1.190 +		echo -n "Creating SliTaz cdrom README..."
   1.191 +		date=$(date '+%Y-%m-%d %H:%M')
   1.192 +		mkdir -p $tmpdir/slitaz-$id/rootcd
   1.193 +		cp $DATA/README.distro $tmpdir/slitaz-$id/rootcd/README
   1.194 +		sed -i s"/_DATE_/$date/" $tmpdir/slitaz-$id/rootcd/README
   1.195 +		status
   1.196 +		
   1.197 +		echo -n "Creating flavor tarball..."
   1.198 +		cd $tmpdir && tar cjf $FLAVOR.tar.bz2 slitaz-$id
   1.199 +		mkdir -p $public/slitaz-$id
   1.200 +		mv $FLAVOR.tar.bz2 $public/slitaz-$id
   1.201 +		status
   1.202 +		
   1.203 +		# Keep a public receipt copy and move everything from tmp to queue.
   1.204 +		echo "Flavor packed   : $(date '+%Y-%m-%d %H:%M')" | tee -a $log
   1.205 +		echo -n "Moving $id to Pizza build queue..."
   1.206 +		mv -f $tmpdir/slitaz-$id/distro.log $public/slitaz-$id
   1.207 +		cp -f $tmpdir/slitaz-$id/receipt $public/slitaz-$id
   1.208 +		mv $tmpdir/slitaz-$id $queue
   1.209 +		status
   1.210 +		
   1.211 +		if [ "$inqueue" == "1" ]; then
   1.212 +			gettext "Your ISO will be built on next Pizza Bot run"
   1.213 +		else
   1.214 +			eval_gettext "Ther is \$inqueue flavors in queue"
   1.215 +		fi
   1.216 +		echo ""
   1.217 +		echo "New flavor added to queue: <a href='?id=$id'>$id</a>" | log
   1.218 +		cat << EOT
   1.219 +</pre>
   1.220 +<div>
   1.221 +	<img src="images/archive.png" alt="[ tarball ]" />
   1.222 +	$(gettext "Download tarball: ")
   1.223 +	<a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
   1.224 +	- Browse <a href="public/slitaz-$id/">the flavor</a>
   1.225 +</div>
   1.226 +<div class="next">
   1.227 +	<form method="get" action="./">
   1.228 +		<input type="hidden" name="id" value="$id" />
   1.229 +		<input type="submit" value="$(gettext "Status")">
   1.230 +	</form>
   1.231 +</div>
   1.232 +EOT
   1.233 +		;;
   1.234 +	*\ id\ *)
   1.235 +		#
   1.236 +		# ID Status page
   1.237 +		#
   1.238 +		id="$(GET id)"
   1.239 +		[ -f "$queue/slitaz-$id/receipt" ] && . $queue/slitaz-$id/receipt
   1.240 +		[ -f "public/slitaz-$id/receipt" ] && . public/slitaz-$id/receipt
   1.241 +		log="$public/slitaz-$id/distro.log"
   1.242 +		if [ ! -d "public/slitaz-$id" ]; then
   1.243 +			echo "Sorry, can't found flavor ID: $id"
   1.244 +			cat lib/footer.html && exit 0
   1.245 +		fi
   1.246 +		if [ -f "$public/slitaz-$id/$FLAVOR.iso" ]; then
   1.247 +			dir="public/slitaz-$id"
   1.248 +			list="$dir/packages.list"
   1.249 +			iso="$dir/$FLAVOR.iso"
   1.250 +			msg="$(gettext "Download ISO:") <a href='$dir/$FLAVOR.iso'>$FLAVOR.iso</a>
   1.251 +				[ <a href='$dir/$FLAVOR.md5'>md5</a> ]"
   1.252 +		else
   1.253 +			list="$queue/slitaz-$id/packages.list"
   1.254 +			msg="$(gettext "Flavor is building or still in the build queue")"
   1.255 +		fi
   1.256 +		pkgslist=$(cat $list | wc -l)
   1.257 +		pkgsinst=$(cat $installed | wc -l)
   1.258 +		[ "$pkgsinst" ] || pkgsinst=0
   1.259 +		[ "$ISO_SIZE" ] || ISO_SIZE="N/A"
   1.260 +		[ "$ROOTFS_SIZE" ] || ROOTFS_SIZE="N/A"
   1.261 +		cat << EOT
   1.262 +<h2>$(gettext "Status for:") $FLAVOR</h2>
   1.263 +<p>
   1.264 +	$(gettext "Flavor description:") $SHORT_DESC
   1.265 +</p>
   1.266 +<pre>
   1.267 +Uniq ID     : $id
   1.268 +Flavor      : $FLAVOR
   1.269 +Packages    : $pkgslist in list - $pkgsinst installed
   1.270 +Rootfs size : $ROOTFS_SIZE
   1.271 +ISO size    : $ISO_SIZE
   1.272 +</pre>
   1.273 +
   1.274 +<div>
   1.275 +	<img src="images/iso.png" alt="[ iso ]" /> $(echo $msg)
   1.276 +</div>
   1.277 +<div>
   1.278 +	<img src="images/archive.png" alt="[ tarball ]" />
   1.279 +	$(gettext "Download tarball:")
   1.280 +	<a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
   1.281 +EOT
   1.282 +		if [ -f "$public/slitaz-$id/$FLAVOR.flavor" ]; then
   1.283 +			cat << EOT
   1.284 +	- Flavor file: <a href="public/slitaz-$id/$FLAVOR.flavor">$FLAVOR.flavor</a>
   1.285 +EOT
   1.286 +		fi
   1.287 +		cat << EOT
   1.288 +	- Browse <a href="public/slitaz-$id/">the flavor</a>
   1.289 +</div>
   1.290 +EOT
   1.291 +		if [ "$NOTE" ]; then
   1.292 +			echo "<div class="note">$NOTE</div>"
   1.293 +		fi
   1.294 +		if [ -f "$log" ]; then
   1.295 +			echo '<h2>Distro log</h2>'
   1.296 +			echo '<pre>'
   1.297 +			fgrep 'Build time' $log
   1.298 +			cat $log | highlighter log
   1.299 +			echo '</pre>'
   1.300 +		fi ;;
   1.301 +	*\ help\ *)
   1.302 +		echo "<h2>$(gettext "Help")</h2>"
   1.303 +		echo "<b>TODO: HTML faq/doc</b>"
   1.304 +		echo '<pre>'
   1.305 +		cat /usr/share/doc/pizza/README
   1.306 +		echo '</pre>' ;;
   1.307 +	*\ info\ *)
   1.308 +		# English only :-)
   1.309 +		if mount | fgrep -q slitaz/public; then
   1.310 +			mounted="Public is mounted"
   1.311 +		else
   1.312 +			mounted="WARRNING: Public is not mounted"
   1.313 +		fi
   1.314 +		echo '<h2><img src="images/monitor.png" alt="" />Pizza Info</h2>'
   1.315 +		echo '<pre>'
   1.316 +		[ "$mounted" ] && echo "$mounted"
   1.317 +		echo -n "Public flavors : " && ls -1 public | wc -l
   1.318 +		echo -n "Public size    : " && du -sh public | awk '{print $1}'
   1.319 +		echo -n "Tmp size       : " && du -sh $tmpdir | awk '{print $1}'
   1.320 +		echo '</pre>' ;;
   1.321 +	*)
   1.322 +		#
   1.323 +		# Main page
   1.324 +		#
   1.325 +		inqueue=$(ls $queue | wc -l)
   1.326 +		builds=$(cat $builds)
   1.327 +		pubiso=$(ls -1 public | wc -l)
   1.328 +		[ "$builds" ] || builds=0
   1.329 +		cat << EOT
   1.330 +<h2>$(gettext "Welcome")</h2>
   1.331 +<p>
   1.332 +	SliTaz Pizza let you create your own SliTaz ISO flavor online. The
   1.333 +	ISO image can be burnt on a cdrom or installed on an USB media. 
   1.334 +	Please read the SliTaz Pizza 
   1.335 +	<a href="?help">Help</a> before starting a new flavor.
   1.336 +</p>
   1.337 +<pre>
   1.338 +Flavors: $inqueue in queue - $builds builds - $pubiso public
   1.339 +</pre>
   1.340 +
   1.341 +<div class="start">
   1.342 +	<form method="get" action="./">
   1.343 +		<input type="hidden" name="start" value="flavor" />
   1.344 +		<input type="submit" value="$(gettext "Create a new flavor")">
   1.345 +	</form>
   1.346 +</div>
   1.347 +
   1.348 +<h2>Activity</h2>
   1.349 +<pre>
   1.350 +$(tac $activity | head -n 12 | highlighter activity)
   1.351 +</pre>
   1.352 +
   1.353 +EOT
   1.354 +		echo "<h2>$(gettext "Latest builds")</h2>"
   1.355 +		echo '<pre>'
   1.356 +		for flavor in $(ls -1t public | head -n 12)
   1.357 +		do
   1.358 +			if [ -f "public/$flavor/receipt" ]; then
   1.359 +				. ./public/$flavor/receipt
   1.360 +				[ -f "public/$flavor/$FLAVOR.iso" ] && \
   1.361 +					cat << EOT
   1.362 +$VERSION : <a href="public/$flavor/$FLAVOR.iso">$FLAVOR.iso</a> ($ISO_SIZE)
   1.363 +EOT
   1.364 +			fi
   1.365 +		done 
   1.366 +		echo '</pre>' ;;
   1.367 +esac
   1.368 +
   1.369 +# HTML footer.
   1.370 +cat lib/footer.html
   1.371 +
   1.372 +exit 0