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

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