wok view tazpkg-web/stuff/tazpkg-web @ rev 5235

tazpkg-web: add 2.0 version
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Apr 08 17:25:45 2010 +0200 (2010-04-08)
parents 48aebe803b83
children 0b8eeecc964e
line source
1 #!/bin/sh
2 # SliTaz Packages Web interface generator: http://pkgs.slitaz.org/
3 #
4 # (C) 2009 SliTaz project - GNU General Public License v3.
5 # Christophe Lincoln <pankso@slitaz.org>
6 #
8 . /etc/slitaz/tazpkg-web.conf
10 RELEASE="$1"
11 PAGES_DIR=$WEB_INTERFACE/$RELEASE
12 DATE=`date +%Y-%m-%d\ \%H:%M:%S`
14 status()
15 {
16 local CHECK=$?
17 echo -en "\033[70G"
18 if [ $CHECK = 0 ]; then
19 echo "Done"
20 else
21 echo "Failed"
22 fi
23 return $CHECK
24 }
26 # Search from option with current version in first so users dont have
27 # to select the correct one.
28 search_form_option()
29 {
30 if [ "$RELEASE" == "stable" ]; then
31 cat << _EOT_
32 <option>stable</option>
33 <option>cooking</option>
34 <option>2.0</option>
35 <option>1.0</option>
36 _EOT_
37 else
38 cat << _EOT_
39 <option>cooking</option>
40 <option>stable</option>
41 <option>2.0</option>
42 <option>1.0</option>
43 _EOT_
44 fi
45 }
47 content_top()
48 {
49 cat >> $PAGES_DIR/$page.html << _EOF_
51 <!-- Content top. -->
52 <div id="content_top">
53 <div class="top_left"></div>
54 <div class="top_right"></div>
55 </div>
57 <!-- Content -->
58 <div id="content">
59 <a name="content"></a>
61 <h1><font color="#3E1220">Packages $RELEASE</font></h1>
62 <h2><font color="#DF8F06">$h2</font></h2>
63 _EOF_
64 }
66 # xHTML Header.
67 xhtml_header()
68 {
69 cat $LIB_DIR/html/header.html > $PAGES_DIR/$page.html
70 sed -i s/"_RELEASE_"/"$RELEASE"/ $PAGES_DIR/$page.html
71 sed -i s/"_PAGE_"/"$page"/ $PAGES_DIR/$page.html
72 sed -i s/"_DATE_"/"$DATE"/ $PAGES_DIR/$page.html
73 }
75 # xHTML Footer.
76 xhtml_footer()
77 {
78 cat $LIB_DIR/html/footer.html >> $PAGES_DIR/$page.html
79 sed -i s/"_DATE_"/"$DATE"/ $PAGES_DIR/$page.html
80 }
82 # Index pages with categories and search form.
83 gen_index_content()
84 {
85 cat >> $PAGES_DIR/$page.html << _EOT_
87 <div style="text-align: center; padding: 20px;">
88 <form method="post" action="http://pkgs.slitaz.org/search.cgi">
89 <select name="object">
90 <option>Package</option>
91 <option>Desc</option>
92 <option>Tags</option>
93 <option>Receipt</option>
94 <option>Depends</option>
95 <option>BuildDepends</option>
96 <option>File</option>
97 <option>File_list</option>
98 <option>FileOverlap</option>
99 </select>
100 <strong>:</strong>
101 <input type="text" name="query" size="32" />
102 <select name="version">
103 `search_form_option`
104 </select>
105 <input type="submit" name="search" value="Search" />
106 </form>
107 <p>
108 $packages packages - Database generated on: $DATE
109 </p>
110 </div>
111 _EOT_
112 }
114 # Packages <h3> and infos in <pre>. Some packages use EXTRAVERSION in
115 # the receipt so keep the value or set it to the kernel version.
116 pkgs_pages_content()
117 {
118 for pkg in $WOK/*
119 do
120 DEPENDS=""
121 DEPENDS_LINKS=""
122 EXTRAVERSION=""
123 . $pkg/receipt
124 packages=$(($packages+1))
125 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
127 <a name="$PACKAGE"></a>
128 <h3>
129 <a href="tazpkg://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg">
130 <img src="/pics/tazpkg.png"
131 title="install" alt="install"
132 style="vertical-align: middle; width: 24px; height: 24px;" /></a>
133 $PACKAGE</h3>
134 <pre class="package">
135 Version : $VERSION
136 Short desc : $SHORT_DESC
137 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
138 _EOT_
139 [ -z "$EXTRAVERSION" ] && EXTRAVERSION="_$KERNEL"
140 # Extraversion string or not
141 if [ -f "$PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" ]; then
142 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
143 Download : <a href="http://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg">$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg</a>
144 _EOT_
145 echo '</pre>' >> $PAGES_DIR/$CATEGORY.html
146 else
147 # Check if package exists, could be virtual?
148 [ -f "$PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg" ] &&
149 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
150 Download : <a href="http://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-$VERSION.tazpkg">$PACKAGE-$VERSION.tazpkg</a>
151 _EOT_
152 echo '</pre>' >> $PAGES_DIR/$CATEGORY.html
153 fi
154 # Dependencies with link to the package information using
155 # category.html#anchor
156 if [ -n "$DEPENDS" ]; then
157 for dep in $DEPENDS
158 do
159 receipt=$WOK/$dep/receipt
160 if [ -f "$receipt" ]; then
161 cat=`grep CATEGORY $receipt | sed s/CATEGORY=\"// | sed s/\"//`
162 DEPENDS_LINKS=${DEPENDS_LINKS}"<a href=\"$cat.html#$dep\">$dep</a> "
163 fi
164 done
165 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
166 <p>Depends : $DEPENDS_LINKS</p>
167 _EOT_
168 fi
169 done
170 }
172 # Pages footer
173 pages_footer()
174 {
175 for page in $CATEGORIES
176 do
177 # Gen categories menu/links
178 echo '' >> $PAGES_DIR/$page.html
179 echo '<p class="pkg_nav">' >> $PAGES_DIR/$page.html
180 echo 'Categories' >> $PAGES_DIR/$page.html
181 for i in $CATEGORIES
182 do
183 cat >> $PAGES_DIR/$page.html << _EOF_
184 | <a href="$i.html">$i</a>
185 _EOF_
186 done
187 echo '</p>' >> $PAGES_DIR/$page.html
188 xhtml_footer
189 done
190 }
192 # Home page with search form and tag cloud.
193 home_page()
194 {
195 PAGES_DIR=$WEB_INTERFACE
196 page="index"
197 h2="Web interface"
198 RELEASE=""
199 xhtml_header
200 content_top
201 cat $LIB_DIR/html/home.html >> $PAGES_DIR/$page.html
202 xhtml_footer
203 }
205 # Generate all categories pages and release index.
206 gen_all_pages()
207 {
208 # Clean previews files.
209 rm -rf $PAGES_DIR
210 mkdir -p $PAGES_DIR
211 echo -e "\nStarting to build the $RELEASE Web interface... "
212 echo "================================================================================"
213 # Packages pages header, menu and content top at first.
214 echo -n "Generating all page headers..."
215 for page in $CATEGORIES
216 do
217 h2=$page
218 xhtml_header
219 cat $LIB_DIR/html/menu.html >> $PAGES_DIR/$page.html
220 content_top
221 done
222 status
223 # Scan the wok and classify packages by category.
224 echo -n "Scanning the wok and generating page contents..."
225 pkgs_pages_content
226 status
227 # Gen all packages pages footer.
228 echo -n "Generating all page footers..."
229 pages_footer
230 status
231 # Stable or Cooking index with categories and home page.
232 echo -n "Generating the main index..."
233 page="index"
234 h2="Categories"
235 xhtml_header
236 cat $LIB_DIR/html/menu.html >> $PAGES_DIR/$page.html
237 content_top
238 gen_index_content
239 xhtml_footer
240 home_page
241 status
242 echo "================================================================================"
243 echo -e "Pages generated: $WEB_INTERFACE\n"
244 }
246 # Prefer the Hg wok in the chroot. On host running Tazbb the wok's
247 # are updated and copied automatically and so more up-to-date.
249 case "$1" in
250 stats)
251 size=`du -sh $WEB_INTERFACE | awk '{ print $1 }'`
252 pages=`find $WEB_INTERFACE -name *.html | wc -l`
253 stable=`find $WEB_INTERFACE/stable -name *.html | wc -l`
254 cooking=`find $WEB_INTERFACE/cooking -name *.html | wc -l`
255 cat << _EOT_
257 Tazpkg-web statistics
258 ================================================================================
259 Web interface : $WEB_INTERFACE ($size)
260 xHTML pages : $pages (Stable $stable - Cooking $cooking)
261 Library path : $LIB_DIR
262 Stable path : $STABLE
263 Cooking path : $COOKING
264 ================================================================================
266 _EOT_
267 ;;
268 check)
269 RELEASE=$2
270 [ -z "$RELEASE" ] && RELEASE=cooking
271 echo -e "\nChecking: $WEB_INTERFACE/$RELEASE\n"
272 for page in `cd $WEB_INTERFACE/$RELEASE && ls *.html`
273 do
274 if ! echo "$CATEGORIES index" | grep -qw ${page%.html}; then
275 echo "Wrong category: ${page%.html}"
276 fi
277 done && echo "" ;;
278 stable)
279 PACKAGES_REPOSITORY=$STABLE/packages
280 if [ -d $STABLE/chroot/home/slitaz/hg/wok ]; then
281 WOK=$STABLE/chroot/home/slitaz/hg/wok
282 else
283 WOK=$STABLE/wok
284 fi
285 KERNEL=`cat $WOK/linux/receipt | grep ^VERSION= | cut -d '"' -f 2`
286 gen_all_pages ;;
287 cooking)
288 PACKAGES_REPOSITORY=$COOKING/packages
289 if [ -d $COOKING/chroot/home/slitaz/hg/wok ]; then
290 WOK=$COOKING/chroot/home/slitaz/hg/wok
291 else
292 WOK=$COOKING/wok
293 fi
294 KERNEL=`cat $WOK/linux/receipt | grep ^VERSION= | cut -d '"' -f 2`
295 gen_all_pages ;;
296 *|usage)
297 cat << _EOT_
299 Tazpkg-web - SliTaz Packages Web interface generator.
300 Usage: `basename $0` [slitaz-release|stats|check]
302 _EOT_
303 ;;
304 esac
306 exit 0