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

tazpkg-web: Clean-up and small fixes
author Christophe Lincoln <pankso@slitaz.org>
date Sun Jan 17 21:59:56 2010 +0100 (2010-01-17)
parents 50e078001b44
children 2be1a2b6a241
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 }
110 # Packages <h3> and infos in <pre>. Some packages use EXTRAVERSION in
111 # the receipt so keep the value or set it to the kernel version.
112 pkgs_pages_content()
113 {
114 for pkg in $WOK/*
115 do
116 DEPENDS=""
117 DEPENDS_LINKS=""
118 EXTRAVERSION=""
119 . $pkg/receipt
120 packages=$(($packages+1))
121 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
123 <a name="$PACKAGE"></a>
124 <h3>
125 <a href="tazpkg://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg">
126 <img src="/pics/tazpkg.png"
127 title="install" alt="install"
128 style="vertical-align: middle; width: 24px; height: 24px;" /></a>
129 $PACKAGE</h3>
130 <pre class="package">
131 Version : $VERSION
132 Short desc : $SHORT_DESC
133 Web site : <a href="$WEB_SITE">$WEB_SITE</a>
134 _EOT_
135 [ -z "$EXTRAVERSION" ] && EXTRAVERSION="_$KERNEL"
136 # Extraversion string or not
137 if [ -f "$PACKAGES_REPOSITORY/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg" ]; then
138 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
139 Download : <a href="http://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg">$PACKAGE-${VERSION}$EXTRAVERSION.tazpkg</a>
140 _EOT_
141 echo '</pre>' >> $PAGES_DIR/$CATEGORY.html
142 else
143 # Check if package exists, could be virtual?
144 [ -f "$PACKAGES_REPOSITORY/$PACKAGE-$VERSION.tazpkg" ] &&
145 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
146 Download : <a href="http://mirror.slitaz.org/packages/$RELEASE/$PACKAGE-$VERSION.tazpkg">$PACKAGE-$VERSION.tazpkg</a>
147 _EOT_
148 echo '</pre>' >> $PAGES_DIR/$CATEGORY.html
149 fi
150 # Dependencies with link to the package information using
151 # category.html#anchor
152 if [ -n "$DEPENDS" ]; then
153 for dep in $DEPENDS
154 do
155 receipt=$WOK/$dep/receipt
156 if [ -f "$receipt" ]; then
157 cat=`grep CATEGORY $receipt | sed s/CATEGORY=\"// | sed s/\"//`
158 DEPENDS_LINKS=${DEPENDS_LINKS}"<a href=\"$cat.html#$dep\">$dep</a> "
159 fi
160 done
161 cat >> $PAGES_DIR/$CATEGORY.html << _EOT_
162 <p>Depends : $DEPENDS_LINKS</p>
163 _EOT_
164 fi
165 done
166 }
168 # Pages footer
169 pages_footer()
170 {
171 for page in $CATEGORIES
172 do
173 # Gen categories menu/links
174 echo '' >> $PAGES_DIR/$page.html
175 echo '<p class="pkg_nav">' >> $PAGES_DIR/$page.html
176 echo 'Categories' >> $PAGES_DIR/$page.html
177 for i in $CATEGORIES
178 do
179 cat >> $PAGES_DIR/$page.html << _EOF_
180 | <a href="$i.html">$i</a>
181 _EOF_
182 done
183 echo '</p>' >> $PAGES_DIR/$page.html
184 xhtml_footer
185 done
186 }
188 # Home page with search form and tag cloud.
189 home_page()
190 {
191 PAGES_DIR=$WEB_INTERFACE
192 page="index"
193 h2="Web interface"
194 RELEASE=""
195 xhtml_header
196 content_top
197 cat $LIB_DIR/html/home.html >> $PAGES_DIR/$page.html
198 xhtml_footer
199 }
201 # Generate all categories pages and release index.
202 gen_all_pages()
203 {
204 # Clean previews files.
205 rm -rf $PAGES_DIR
206 mkdir -p $PAGES_DIR
207 echo -e "\nStarting to build the $RELEASE Web interface... "
208 echo "================================================================================"
209 # Packages pages header, menu and content top at first.
210 echo -n "Generating all page headers..."
211 for page in $CATEGORIES
212 do
213 h2=$page
214 xhtml_header
215 cat $LIB_DIR/html/menu.html >> $PAGES_DIR/$page.html
216 content_top
217 done
218 status
219 # Scan the wok and classify packages by category.
220 echo -n "Scanning the wok and generating page contents..."
221 pkgs_pages_content
222 status
223 # Gen all packages pages footer.
224 echo -n "Generating all page footers..."
225 pages_footer
226 status
227 # Stable or Cooking index with categories and home page.
228 echo -n "Generating the main index..."
229 page="index"
230 h2="Categories"
231 xhtml_header
232 cat $LIB_DIR/html/menu.html >> $PAGES_DIR/$page.html
233 content_top
234 gen_index_content
235 xhtml_footer
236 home_page
237 status
238 echo "================================================================================"
239 echo -e "Pages generated: $WEB_INTERFACE\n"
240 }
242 # Prefer the Hg wok in the chroot. On host running Tazbb the wok's
243 # are updated and copied automatically and so more up-to-date.
245 case "$1" in
246 stats)
247 size=`du -sh $WEB_INTERFACE | awk '{ print $1 }'`
248 pages=`find $WEB_INTERFACE -name *.html | wc -l`
249 stable=`find $WEB_INTERFACE/stable -name *.html | wc -l`
250 cooking=`find $WEB_INTERFACE/cooking -name *.html | wc -l`
251 cat << _EOT_
253 Tazpkg-web statistics
254 ================================================================================
255 Web interface : $WEB_INTERFACE ($size)
256 xHTML pages : $pages (Stable $stable - Cooking $cooking)
257 Library path : $LIB_DIR
258 Stable path : $STABLE
259 Cooking path : $COOKING
260 ================================================================================
262 _EOT_
263 ;;
264 check)
265 RELEASE=$2
266 [ -z "$RELEASE" ] && RELEASE=cooking
267 echo -e "\nChecking: $WEB_INTERFACE/$RELEASE\n"
268 for page in `cd $WEB_INTERFACE/$RELEASE && ls *.html`
269 do
270 if ! echo "$CATEGORIES index" | grep -qw ${page%.html}; then
271 echo "Wrong category: ${page%.html}"
272 fi
273 done && echo "" ;;
274 stable)
275 PACKAGES_REPOSITORY=$STABLE/packages
276 if [ -d $STABLE/chroot/home/slitaz/hg/wok ]; then
277 WOK=$STABLE/chroot/home/slitaz/hg/wok
278 else
279 WOK=$STABLE/wok
280 fi
281 KERNEL=`cat $WOK/linux/receipt | grep ^VERSION= | cut -d '"' -f 2`
282 gen_all_pages ;;
283 cooking)
284 PACKAGES_REPOSITORY=$COOKING/packages
285 if [ -d $COOKING/chroot/home/slitaz/hg/wok ]; then
286 WOK=$COOKING/chroot/home/slitaz/hg/wok
287 else
288 WOK=$COOKING/wok
289 fi
290 KERNEL=`cat $WOK/linux/receipt | grep ^VERSION= | cut -d '"' -f 2`
291 gen_all_pages ;;
292 *|usage)
293 cat << _EOT_
295 Tazpkg-web - SliTaz Packages Web interface generator.
296 Usage: `basename $0` [slitaz-release|stats|check]
298 _EOT_
299 ;;
300 esac
302 exit 0