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