slitaz-dev-tools diff tazpkg-web/tazpkg-web @ rev 13

Add tazpkg-web.
author Christopher Rogers <slaxemulator@gmail.com>
date Thu Feb 24 04:33:56 2011 +0000 (2011-02-24)
parents
children 95e6d40038aa
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tazpkg-web/tazpkg-web	Thu Feb 24 04:33:56 2011 +0000
     1.3 @@ -0,0 +1,290 @@
     1.4 +#!/bin/sh
     1.5 +# SliTaz Packages Web interface generator: http://pkgs.slitaz.org/
     1.6 +#
     1.7 +# (C) 2011 SliTaz project - GNU General Public License v3.
     1.8 +# Christophe Lincoln <pankso@slitaz.org>
     1.9 +#
    1.10 +
    1.11 +. /etc/slitaz/tazpkg-web.conf
    1.12 +
    1.13 +RELEASE="$1"
    1.14 +PAGES_DIR=$WEB_INTERFACE/$RELEASE
    1.15 +DATE=`date +%Y-%m-%d\ \%H:%M:%S`
    1.16 +YEAR=`date +%Y`
    1.17 +
    1.18 +status()
    1.19 +{
    1.20 +	local CHECK=$?
    1.21 +	echo -en "\033[70G"
    1.22 +	if [ $CHECK = 0 ]; then
    1.23 +		echo "Done"
    1.24 +	else
    1.25 +		echo "Failed"
    1.26 +	fi
    1.27 +	return $CHECK
    1.28 +}
    1.29 +
    1.30 +# Search from option with current version in first so users dont have
    1.31 +# to select the correct one.
    1.32 +search_form_option()
    1.33 +{
    1.34 +	if [ "$RELEASE" == "stable" ]; then
    1.35 +		cat << _EOT_
    1.36 +			<option>stable</option>
    1.37 +			<option>cooking</option>
    1.38 +			<option>2.0</option>
    1.39 +			<option>1.0</option>
    1.40 +_EOT_
    1.41 +	else
    1.42 +		cat << _EOT_
    1.43 +			<option>cooking</option>
    1.44 +			<option>stable</option>
    1.45 +			<option>2.0</option>
    1.46 +			<option>1.0</option>
    1.47 +_EOT_
    1.48 +	fi
    1.49 +}
    1.50 +
    1.51 +# xHTML Header.
    1.52 +xhtml_header()
    1.53 +{
    1.54 +	cat $LIB_DIR/html/header.html > $PAGES_DIR/$page.html
    1.55 +	sed -i s/"_RELEASE_"/"$RELEASE"/ $PAGES_DIR/$page.html
    1.56 +	sed -i s/"_PAGE_"/"$page"/ $PAGES_DIR/$page.html
    1.57 +	sed -i s/"_DATE_"/"$DATE"/ $PAGES_DIR/$page.html
    1.58 +}
    1.59 +
    1.60 +# xHTML Footer.
    1.61 +xhtml_footer()
    1.62 +{
    1.63 +	cat $LIB_DIR/html/footer.html >> $PAGES_DIR/$page.html
    1.64 +	sed -i s/"_DATE_"/"$DATE"/ $PAGES_DIR/$page.html
    1.65 +	sed -i s/"_YEAR_"/"$YEAR"/ $PAGES_DIR/$page.html
    1.66 +}
    1.67 +
    1.68 +# Index pages with categories and search form.
    1.69 +gen_index_content()
    1.70 +{
    1.71 +	cat >> $PAGES_DIR/$page.html << _EOT_
    1.72 +
    1.73 +<div class="pkgs-search">
    1.74 +	<form method="post" action="http://pkgs.slitaz.org/search.cgi">
    1.75 +		<p>
    1.76 +			<input type="text" name="query" size="32" />
    1.77 +			<input type="submit" name="search" value="Search" />
    1.78 +		</p>
    1.79 +		<select name="object">
    1.80 +			<option>Package</option>
    1.81 +			<option>Desc</option>
    1.82 +			<option>Tags</option>
    1.83 +			<option>Receipt</option>
    1.84 +			<option>Depends</option>
    1.85 +			<option>BuildDepends</option>
    1.86 +			<option>File</option>
    1.87 +			<option>File_list</option>
    1.88 +			<option>FileOverlap</option>
    1.89 +		</select>
    1.90 +		<select name="version">
    1.91 +`search_form_option`
    1.92 +		</select>
    1.93 +	</form>
    1.94 +	<p>
    1.95 +		$packages packages - Database generated on: $DATE
    1.96 +	</p>
    1.97 +</div>
    1.98 +_EOT_
    1.99 +	sed -i s/"_RELEASE_"/"$RELEASE"/ $PAGES_DIR/$page.html
   1.100 +}
   1.101 +
   1.102 +# Packages <h3> and infos in <pre>. Some packages use EXTRAVERSION in
   1.103 +# the receipt so keep the value or set it to the kernel version.
   1.104 +pkgs_pages_content()
   1.105 +{
   1.106 +	for pkg in $WOK/*
   1.107 +	do
   1.108 +		DEPENDS=""
   1.109 +		DEPENDS_LINKS=""
   1.110 +		EXTRAVERSION=""
   1.111 +		. $pkg/receipt
   1.112 +		packages=$(($packages+1))
   1.113 +		cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
   1.114 +
   1.115 +<a name="$PACKAGE"></a>
   1.116 +<h3>
   1.117 +<a href="tazpkg://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg">
   1.118 +<img src="/pics/tazpkg.png" 
   1.119 +	title="install" alt="install" 
   1.120 +	style="vertical-align: middle; width: 24px; height: 24px;" /></a>
   1.121 +$PACKAGE</h3>
   1.122 +<pre class="package">
   1.123 +Version    : $VERSION
   1.124 +Short desc : $SHORT_DESC
   1.125 +Web site   : <a href="$WEB_SITE">$WEB_SITE</a>
   1.126 +_EOT_
   1.127 +		[ -z "$EXTRAVERSION" ] && EXTRAVERSION="_$KERNEL"
   1.128 +		# Extraversion string or not
   1.129 +		if [ -f "$PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" ]; then
   1.130 +			cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
   1.131 +Download   : <a href="http://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg">$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg</a>
   1.132 +_EOT_
   1.133 +			echo '</pre>' >> $PAGES_DIR/$CATEGORY.html
   1.134 +		else
   1.135 +			# Check if package exists, could be virtual?
   1.136 +			[ -f "$PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg" ] &&
   1.137 +			cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
   1.138 +Download   : <a href="http://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-$VERSION.tazpkg">$PACKAGE-$VERSION.tazpkg</a>
   1.139 +_EOT_
   1.140 +			echo '</pre>' >> $PAGES_DIR/$CATEGORY.html
   1.141 +		fi
   1.142 +		# Dependencies with link to the package information using
   1.143 +		# category.html#anchor
   1.144 +		if [ -n "$DEPENDS" ]; then
   1.145 +			for dep in $DEPENDS
   1.146 +			do
   1.147 +				receipt=$WOK/$dep/receipt
   1.148 +				if [ -f "$receipt" ]; then
   1.149 +					cat=`grep CATEGORY $receipt | sed s/CATEGORY=\"// | sed s/\"//`
   1.150 +					DEPENDS_LINKS=${DEPENDS_LINKS}"<a href=\"$cat.html#$dep\">$dep</a> "
   1.151 +				fi
   1.152 +			done
   1.153 +			cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
   1.154 +<p>Depends : $DEPENDS_LINKS</p>
   1.155 +_EOT_
   1.156 +		fi
   1.157 +	done
   1.158 +}
   1.159 +
   1.160 +# Pages footer
   1.161 +pages_footer()
   1.162 +{
   1.163 +	for page in $CATEGORIES
   1.164 +	do
   1.165 +		# Gen categories menu/links
   1.166 +		echo '' >> $PAGES_DIR/$page.html
   1.167 +		echo '<div class="infobox"><p>' >> $PAGES_DIR/$page.html
   1.168 +		echo 'Categories' >> $PAGES_DIR/$page.html
   1.169 +		for i in $CATEGORIES
   1.170 +		do
   1.171 +			cat >> $PAGES_DIR/$page.html << _EOF_
   1.172 +| <a href="$i.html">$i</a>
   1.173 +_EOF_
   1.174 +		done
   1.175 +		echo '</p></div>' >> $PAGES_DIR/$page.html
   1.176 +		xhtml_footer
   1.177 +	done
   1.178 +}
   1.179 +
   1.180 +# Home page with search form and tag cloud.
   1.181 +home_page()
   1.182 +{
   1.183 +	PAGES_DIR=$WEB_INTERFACE
   1.184 +	page="index"
   1.185 +	h2="Web interface"
   1.186 +	RELEASE=""
   1.187 +	xhtml_header
   1.188 +	cat $LIB_DIR/html/home.html >> $PAGES_DIR/$page.html
   1.189 +	xhtml_footer
   1.190 +}
   1.191 +
   1.192 +# Generate all categories pages and release index.
   1.193 +gen_all_pages()
   1.194 +{
   1.195 +	# Clean previews files.
   1.196 +	rm -rf $PAGES_DIR
   1.197 +	mkdir -p $PAGES_DIR
   1.198 +	echo -e "\nStarting to build the $RELEASE Web interface... "
   1.199 +	echo "================================================================================"
   1.200 +	# Packages pages header, menu and content top at first.
   1.201 +	echo -n "Generating all page headers..."
   1.202 +	for page in $CATEGORIES
   1.203 +	do
   1.204 +		h2=$page
   1.205 +		xhtml_header
   1.206 +		cat $LIB_DIR/html/menu.html >> $PAGES_DIR/$page.html
   1.207 +		sed -i s/"_RELEASE_"/"$RELEASE"/ $PAGES_DIR/$page.html
   1.208 +		echo "<h2>Category: $h2</h2>" >> $PAGES_DIR/$page.html
   1.209 +	done
   1.210 +	status
   1.211 +	# Scan the wok and classify packages by category.
   1.212 +	echo -n "Scanning the wok and generating page contents..."
   1.213 +	pkgs_pages_content
   1.214 +	status
   1.215 +	# Gen all packages pages footer.
   1.216 +	echo -n "Generating all page footers..."
   1.217 +	pages_footer
   1.218 +	status
   1.219 +	# Stable or Cooking index with categories and home page.
   1.220 +	echo -n "Generating the main index..."
   1.221 +	page="index"
   1.222 +	h2="Categories"
   1.223 +	xhtml_header
   1.224 +	cat $LIB_DIR/html/menu.html >> $PAGES_DIR/$page.html
   1.225 +	gen_index_content
   1.226 +	xhtml_footer
   1.227 +	home_page
   1.228 +	status
   1.229 +	echo "================================================================================"
   1.230 +	echo -e "Pages generated: $WEB_INTERFACE\n"
   1.231 +}
   1.232 +
   1.233 +# Prefer the Hg wok in the chroot. On host running Tazbb the wok's
   1.234 +# are updated and copied automatically and so more up-to-date.
   1.235 +
   1.236 +case "$1" in
   1.237 +	stats)
   1.238 +		size=`du -sh $WEB_INTERFACE | awk '{ print $1 }'`
   1.239 +		pages=`find $WEB_INTERFACE -name *.html | wc -l`
   1.240 +		stable=`find $WEB_INTERFACE/stable -name *.html | wc -l`
   1.241 +		cooking=`find $WEB_INTERFACE/cooking -name *.html | wc -l`
   1.242 +		cat << _EOT_
   1.243 +
   1.244 +Tazpkg-web statistics
   1.245 +================================================================================
   1.246 +Web interface : $WEB_INTERFACE ($size)
   1.247 +xHTML pages   : $pages (Stable $stable - Cooking $cooking)
   1.248 +Library path  : $LIB_DIR
   1.249 +Stable path   : $STABLE
   1.250 +Cooking path  : $COOKING
   1.251 +================================================================================
   1.252 +
   1.253 +_EOT_
   1.254 +		;;
   1.255 +	check)
   1.256 +		RELEASE=$2
   1.257 +		[ -z "$RELEASE" ] && RELEASE=cooking
   1.258 +		echo -e "\nChecking: $WEB_INTERFACE/$RELEASE\n"
   1.259 +		for page in `cd $WEB_INTERFACE/$RELEASE && ls *.html`
   1.260 +		do
   1.261 +			if ! echo "$CATEGORIES index" | grep -qw ${page%.html}; then
   1.262 +				echo "Wrong category: ${page%.html}"
   1.263 +			fi
   1.264 +		done && echo "" ;;
   1.265 +	stable)
   1.266 +		PACKAGES_REPOSITORY=$STABLE/packages
   1.267 +		if [ -d $STABLE/chroot/home/slitaz/hg/wok ]; then
   1.268 +			WOK=$STABLE/chroot/home/slitaz/hg/wok
   1.269 +		else
   1.270 +			WOK=$STABLE/wok
   1.271 +		fi
   1.272 +		KERNEL=`cat $WOK/linux/receipt | grep ^VERSION= | cut -d '"' -f 2`
   1.273 +		gen_all_pages ;;
   1.274 +	cooking)
   1.275 +		PACKAGES_REPOSITORY=$COOKING/packages
   1.276 +		if [ -d $COOKING/chroot/home/slitaz/hg/wok ]; then
   1.277 +			WOK=$COOKING/chroot/home/slitaz/hg/wok
   1.278 +		else
   1.279 +			WOK=$COOKING/wok
   1.280 +		fi
   1.281 +		KERNEL=`cat $WOK/linux/receipt | grep ^VERSION= | cut -d '"' -f 2`
   1.282 +		gen_all_pages ;;
   1.283 +	*|usage)
   1.284 +		cat << _EOT_
   1.285 +
   1.286 +Tazpkg-web - SliTaz Packages Web interface generator.
   1.287 +Usage: `basename $0` [slitaz-release|stats|check]
   1.288 +
   1.289 +_EOT_
   1.290 +		;;
   1.291 +esac
   1.292 +
   1.293 +exit 0