slitaz-dev-tools view tazpkg-web/tazpkg-web @ rev 309

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