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

tazpkg-web: Minor edits
author Paul Issott <paul@slitaz.org>
date Sun Jun 21 22:21:53 2009 +0000 (2009-06-21)
parents 9cf36f931f36
children 50e078001b44
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>1.0</option>
35 _EOT_
36 else
37 cat << _EOT_
38 <option>cooking</option>
39 <option>stable</option>
40 <option>1.0</option>
41 _EOT_
42 fi
43 }
45 content_top()
46 {
47 cat >> $PAGES_DIR/$page.html << _EOF_
49 <!-- Content top. -->
50 <div id="content_top">
51 <div class="top_left"></div>
52 <div class="top_right"></div>
53 </div>
55 <!-- Content -->
56 <div id="content">
57 <a name="content"></a>
59 <h1><font color="#3E1220">Packages $RELEASE</font></h1>
60 <h2><font color="#DF8F06">$h2</font></h2>
61 _EOF_
62 }
64 # xHTML Header.
65 xhtml_header()
66 {
67 cat $LIB_DIR/html/header.html > $PAGES_DIR/$page.html
68 sed -i s/"_RELEASE_"/"$RELEASE"/ $PAGES_DIR/$page.html
69 sed -i s/"_PAGE_"/"$page"/ $PAGES_DIR/$page.html
70 sed -i s/"_DATE_"/"$DATE"/ $PAGES_DIR/$page.html
71 }
73 # xHTML Footer.
74 xhtml_footer()
75 {
76 cat $LIB_DIR/html/footer.html >> $PAGES_DIR/$page.html
77 sed -i s/"_DATE_"/"$DATE"/ $PAGES_DIR/$page.html
78 }
80 # Index pages with categories and search form.
81 gen_index_content()
82 {
83 cat >> $PAGES_DIR/$page.html << _EOT_
85 <div style="text-align: center; padding: 20px;">
86 <form method="post" action="http://pkgs.slitaz.org/search.cgi">
87 <select name="object">
88 <option>Package</option>
89 <option>Desc</option>
90 <option>Tags</option>
91 <option>Receipt</option>
92 <option>Depends</option>
93 <option>File</option>
94 <option>File_list</option>
95 </select>
96 <strong>:</strong>
97 <input type="text" name="query" size="32" />
98 <select name="version">
99 `search_form_option`
100 </select>
101 <input type="submit" name="search" value="Search" />
102 </form>
103 <p>
104 $packages packages - Database generated on: $DATE
105 </p>
106 </div>
107 _EOT_
108 cat $LIB_DIR/html/catlist.html >> $PAGES_DIR/$page.html
109 }
111 # Packages <h3> and infos in <pre>. Some packages use EXTRAVERSION in
112 # the receipt so keep the value or set it to the kernel version.
113 pkgs_pages_content()
114 {
115 for pkg in $WOK/*
116 do
117 DEPENDS=""
118 DEPENDS_LINKS=""
119 EXTRAVERSION=""
120 . $pkg/receipt
121 [ -z "$EXTRAVERSION" ] && EXTRAVERSION="_$KERNEL"
122 packages=$(($packages+1))
123 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
125 <a name="$PACKAGE"></a>
126 <h3>$PACKAGE</h3>
127 <pre class="package">
128 Version : $VERSION
129 Short desc : $SHORT_DESC
130 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
131 _EOT_
132 # Extraversion string or not
133 if [ -f "$PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" ]; then
134 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
135 Download : <a href="http://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg">$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg</a>
136 _EOT_
137 echo '</pre>' >> $PAGES_DIR/$CATEGORY.html
138 else
139 # Check if package exists, could be virtual?
140 [ -f "$PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg" ] &&
141 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
142 Download : <a href="http://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-$VERSION.tazpkg">$PACKAGE-$VERSION.tazpkg</a>
143 _EOT_
144 echo '</pre>' >> $PAGES_DIR/$CATEGORY.html
145 # Dependencies with link to the package information using
146 # category.html#anchor
147 if [ -n "$DEPENDS" ]; then
148 for dep in $DEPENDS
149 do
150 receipt=$WOK/$dep/receipt
151 if [ -f "$receipt" ]; then
152 cat=`grep CATEGORY $receipt | sed s/CATEGORY=\"// | sed s/\"//`
153 DEPENDS_LINKS=${DEPENDS_LINKS}"<a href=\"$cat.html#$dep\">$dep</a> "
154 fi
155 done
156 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
157 <p>Depends : $DEPENDS_LINKS</p>
158 _EOT_
159 fi
160 fi
161 done
162 }
164 # Pages footer
165 pages_footer()
166 {
167 for page in $CATEGORIES
168 do
169 # Gen categories menu/links
170 echo '' >> $PAGES_DIR/$page.html
171 echo '<p class="pkg_nav">' >> $PAGES_DIR/$page.html
172 echo 'Categories' >> $PAGES_DIR/$page.html
173 for i in $CATEGORIES
174 do
175 cat >> $PAGES_DIR/$page.html << _EOF_
176 | <a href="$i.html">$i</a>
177 _EOF_
178 done
179 echo '</p>' >> $PAGES_DIR/$page.html
180 xhtml_footer
181 done
182 }
184 # Home page with search form and tag cloud.
185 home_page()
186 {
187 PAGES_DIR=$WEB_INTERFACE
188 page="index"
189 h2="Web interface"
190 RELEASE=""
191 xhtml_header
192 content_top
193 cat $LIB_DIR/html/home.html >> $PAGES_DIR/$page.html
194 xhtml_footer
195 }
197 # Generate all categories pages and release index.
198 gen_all_pages()
199 {
200 # Clean previews files.
201 rm -rf $PAGES_DIR
202 mkdir -p $PAGES_DIR
203 echo -e "\nStarting to build the $RELEASE Web interface... "
204 echo "================================================================================"
205 # Packages pages header, menu and content top at first.
206 echo -n "Generating all page headers..."
207 for page in $CATEGORIES
208 do
209 h2=$page
210 xhtml_header
211 cat $LIB_DIR/html/menu.html >> $PAGES_DIR/$page.html
212 content_top
213 done
214 status
215 # Scan the wok and classify packages by category.
216 echo -n "Scanning the wok and generating page contents..."
217 pkgs_pages_content
218 status
219 # Gen all packages pages footer.
220 echo -n "Generating all page footers..."
221 pages_footer
222 status
223 # Stable or Cooking index with categories and home page.
224 echo -n "Generating the main index..."
225 page="index"
226 h2="Categories"
227 xhtml_header
228 cat $LIB_DIR/html/menu.html >> $PAGES_DIR/$page.html
229 content_top
230 gen_index_content
231 xhtml_footer
232 home_page
233 status
234 echo "================================================================================"
235 echo -e "Pages generated: $WEB_INTERFACE\n"
236 }
238 # Prefer the Hg wok in the chroot. On host running Tazbb the wok's
239 # are updated and copied automatically and so more up-to-date.
241 case "$1" in
242 stats)
243 size=`du -sh $WEB_INTERFACE | awk '{ print $1 }'`
244 pages=`find $WEB_INTERFACE -name *.html | wc -l`
245 stable=`find $WEB_INTERFACE/stable -name *.html | wc -l`
246 cooking=`find $WEB_INTERFACE/cooking -name *.html | wc -l`
247 cat << _EOT_
249 Tazpkg-web statistics
250 ================================================================================
251 Web interface : $WEB_INTERFACE ($size)
252 xHTML pages : $pages (Stable $stable - Cooking $cooking)
253 Library path : $LIB_DIR
254 Stable path : $STABLE
255 Cooking path : $COOKING
256 ================================================================================
258 _EOT_
259 ;;
260 check)
261 RELEASE=$2
262 [ -z "$RELEASE" ] && RELEASE=cooking
263 echo -e "\nChecking: $WEB_INTERFACE/$RELEASE\n"
264 for page in `cd $WEB_INTERFACE/$RELEASE && ls *.html`
265 do
266 if ! echo "$CATEGORIES index" | grep -qw ${page%.html}; then
267 echo "Wrong category: ${page%.html}"
268 fi
269 done && echo "" ;;
270 stable)
271 PACKAGES_REPOSITORY=$STABLE/packages
272 if [ -d $STABLE/chroot/home/slitaz/hg/wok ]; then
273 WOK=$STABLE/chroot/home/slitaz/hg/wok
274 else
275 WOK=$STABLE/wok
276 fi
277 KERNEL=`cat $WOK/linux/receipt | grep ^VERSION= | cut -d '"' -f 2`
278 gen_all_pages ;;
279 cooking)
280 PACKAGES_REPOSITORY=$COOKING/packages
281 if [ -d $COOKING/chroot/home/slitaz/hg/wok ]; then
282 WOK=$COOKING/chroot/home/slitaz/hg/wok
283 else
284 WOK=$COOKING/wok
285 fi
286 KERNEL=`cat $WOK/linux/receipt | grep ^VERSION= | cut -d '"' -f 2`
287 gen_all_pages ;;
288 *|usage)
289 cat << _EOT_
291 Tazpkg-web - SliTaz Packages Web interface generator.
292 Usage: `basename $0` [slitaz-release|stats|check]
294 _EOT_
295 ;;
296 esac
298 exit 0