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