cookutils rev 354

cooker.cgi: add download link
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 18 13:45:05 2012 +0200 (2012-04-18)
parents 7e69ae6e69a5
children 0f9e30b30fb0
files web/cooker.cgi
line diff
     1.1 --- a/web/cooker.cgi	Mon Apr 16 11:26:06 2012 +0200
     1.2 +++ b/web/cooker.cgi	Wed Apr 18 13:45:05 2012 +0200
     1.3 @@ -2,8 +2,6 @@
     1.4  #
     1.5  # SliTaz Cooker CGI/web interface.
     1.6  #
     1.7 -echo "Content-Type: text/html"
     1.8 -echo ""
     1.9  
    1.10  [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
    1.11  [ -f "cook.conf" ] && . ./cook.conf
    1.12 @@ -25,9 +23,20 @@
    1.13  # We're not logged and want time zone to display correct server date.
    1.14  export TZ=$(cat /etc/TZ)
    1.15  
    1.16 -#
    1.17 -# Functions
    1.18 -#
    1.19 +if [ "${QUERY_STRING%%=*}" == "download" ]; then
    1.20 +	file=$PKGS/${QUERY_STRING#*=}
    1.21 +	cat <<EOT
    1.22 +Content-Type: application/octet-stream
    1.23 +Content-Length: $(stat -c %s $file)
    1.24 +Content-Disposition: attachment; filename=$(basename $file)
    1.25 +
    1.26 +EOT
    1.27 +	cat $file
    1.28 +	exit
    1.29 +fi
    1.30 +
    1.31 +echo "Content-Type: text/html"
    1.32 +echo ""
    1.33  
    1.34  # RSS feed generator
    1.35  if [ "$QUERY_STRING" == "rss" ]; then
    1.36 @@ -53,6 +62,10 @@
    1.37  	exit 0
    1.38  fi
    1.39  
    1.40 +#
    1.41 +# Functions
    1.42 +#
    1.43 +
    1.44  # Put some colors in log and DB files.
    1.45  syntax_highlighter() {
    1.46  	case $1 in
    1.47 @@ -137,6 +150,13 @@
    1.48  			[ -n "$WEB_SITE" ] && # busybox wget -s $WEB_SITE &&
    1.49  			echo "<a href='$WEB_SITE'>home</a>"
    1.50  			echo "<a href='cooker.cgi?files=$pkg'>files</a>"
    1.51 +			if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
    1.52 +				unset EXTRAVERSION
    1.53 +				. $wok/$pkg/taz/$PACKAGE-$VERSION/receipt
    1.54 +				if [ -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
    1.55 +					echo "<a href='cooker.cgi?download=$PACKAGE-$VERSION$EXTRAVERSION.tazpkg'>download</a>"
    1.56 +				fi
    1.57 +			fi
    1.58  		else
    1.59  			echo "No package named: $pkg"
    1.60  		fi