slitaz-pizza annotate web/pizza.cgi @ rev 91

pizza.cgi: notes should not be executable
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 28 09:30:48 2013 +0100 (2013-01-28)
parents b40b5c7e5955
children e4bf1581a71b
rev   line source
pankso@7 1 #!/bin/sh
pankso@7 2 #
paul@9 3 # SliTaz Pizza CGI/web interface - Let's have a pizza :-)
pankso@7 4 # Please KISS, it is important and keep speed in mind. Thanks, Pankso.
pankso@7 5 #
pankso@7 6
pankso@7 7 # Output a RSS feed of latest build isos.
pankso@7 8 if [ "$QUERY_STRING" == "rss" ]; then
pankso@7 9 . /etc/slitaz/pizza.conf
pankso@7 10 pubdate=$(date "+%a, %d %b %Y %X")
pankso@7 11 cat << EOT
pankso@7 12 Content-Type: text/xml
pankso@7 13
pankso@7 14 <?xml version="1.0" encoding="utf-8" ?>
pankso@7 15 <rss version="2.0">
pankso@7 16 <channel>
pankso@7 17 <title>SliTaz Pizza</title>
pankso@7 18 <description>The SliTaz Pizza cooker feed</description>
pankso@7 19 <link>$PIZZA_URL</link>
pankso@7 20 <lastBuildDate>$pubdate GMT</lastBuildDate>
pankso@7 21 <pubDate>$pubdate GMT</pubDate>
pankso@7 22 EOT
pankso@7 23 for rss in $(ls -1t $PIZZA/chroot${SLITAZ}/xml/*.xml | head -n 12)
pankso@7 24 do
pankso@7 25 cat $rss
pankso@7 26 done
pankso@7 27 cat << EOT
pankso@7 28 </channel>
pankso@7 29 </rss>
pankso@7 30 EOT
pankso@7 31 exit 0
pankso@7 32 fi
pankso@7 33
pankso@7 34 # Content negotiation for Gettext
pankso@7 35 IFS=","
pankso@7 36 for lang in $HTTP_ACCEPT_LANGUAGE
pankso@7 37 do
pankso@7 38 lang=${lang%;*} lang=${lang# } lang=${lang%-*}
pankso@7 39 [ -d "$lang" ] && break
pankso@7 40 case "$lang" in
pankso@7 41 en) lang="C" ;;
pankso@7 42 fr) lang="fr_FR" ;;
pankso@7 43 esac
pankso@7 44 done
pankso@7 45 unset IFS
pankso@7 46 export LANG=$lang LC_ALL=$lang
pankso@7 47
pankso@7 48 # Internationalization: $(gettext "")
pankso@7 49 . /usr/bin/gettext.sh
pankso@7 50 TEXTDOMAIN='pizza'
pankso@7 51 export TEXTDOMAIN
pankso@7 52
pankso@7 53 . lib/libpizza
pankso@7 54
pankso@7 55 #
pankso@7 56 # Commands
pankso@7 57 #
pankso@7 58
pankso@7 59 case " $(GET) " in
pankso@7 60 *\ start\ *)
pankso@7 61 #
pankso@7 62 # First step
pankso@7 63 #
pankso@7 64 date=$(date "+%Y%m%d")
pankso@7 65 id=$date-$$
pankso@7 66 cat << EOT
pankso@7 67 <h2>$(gettext "First step")</h2>
pankso@7 68 <p>
paul@9 69 $(gettext "Choose your distribution name and the one you want to use as
paul@9 70 base. We need your mail to notify you when your SliTaz Flavor is built
paul@9 71 and if anything goes wrong.")
pankso@7 72 </p>
pankso@7 73 <form method="get" action="pkgs.cgi" name="pizza" onsubmit="return checkForm();">
pankso@7 74 <table>
pankso@7 75 <tbody>
pankso@7 76 <tr>
pankso@7 77 <td>$(gettext "Flavor name")</td>
erjo@77 78 <td><input type="text" name="flavor" size="40" maxlength="25" /></td>
pankso@7 79 </tr>
pankso@7 80 <tr>
pankso@7 81 <td>$(gettext "Short description")</td>
erjo@66 82 <td><input type="text" name="desc" size="40" maxlength="60" /></td>
pankso@7 83 </tr>
pankso@7 84 <tr>
pankso@7 85 <td>$(gettext "Email")</td>
pankso@7 86 <td><input type="text" name="mail" size="40" /></td>
pankso@7 87 </tr>
pankso@7 88 <tr>
pankso@7 89 <td>$(gettext "Based on")</td>
pankso@7 90 <td>
pankso@7 91 <select name="skel">
pankso@7 92 <option value="base">
pankso@7 93 Base - $(gettext "Text mode system")</option>
pankso@7 94 <option value="justx">
pankso@7 95 Justx - $(gettext "X without GTK or QT")</option>
pankso@7 96 <option value="gtkonly">
pankso@7 97 Gtkonly - $(gettext "Clean GTK desktop")</option>
pankso@7 98 <option value="core">
pankso@7 99 Core - $(gettext "Default SliTaz desktop")</option>
pankso@7 100 </select>
pankso@7 101 </td>
pankso@7 102 </tr>
pankso@7 103 </tbody>
pankso@7 104 </table>
pankso@7 105 <pre>
pankso@7 106 Uniq ID : $id
pankso@7 107 </pre>
pankso@7 108 <div class="next">
pankso@7 109 <input type="hidden" name="id" value="$id" />
pankso@7 110 <input type="submit" value="$(gettext "Continue")">
pankso@7 111 </div>
pankso@7 112 </form>
pankso@7 113 EOT
pankso@7 114 ;;
pankso@7 115 *\ gen\ *)
pankso@7 116 #
pankso@7 117 # Generate step
pankso@7 118 #
pankso@7 119 id="$(GET id)"
pankso@7 120 . $tmpdir/slitaz-$id/receipt
pankso@7 121 addfiles=$(find $tmpdir/slitaz-$id/addfiles -type f | wc -l)
pankso@7 122 [ "$addfiles" ] || addfiles=0
pankso@7 123 packages=$(cat $tmpdir/slitaz-$id/packages.list | wc -l)
pankso@7 124 cat << EOT
pankso@7 125 <h2>$(gettext "Generate")</h2>
pankso@7 126 <p>
pankso@23 127 $(gettext "Last chance to stop process or start over. Next step will pack
pankso@23 128 your flavor and add it to the build queue. Here you can also add a note to
pankso@23 129 your receipt flavor, this will be displayed on your flavor ID page and
pankso@23 130 can be used to give more info to other users and SliTaz developers.")
pankso@7 131 </p>
pankso@23 132
pankso@7 133 <pre>
pankso@7 134 Uniq ID : $id
pankso@7 135 Flavor : $FLAVOR
pankso@7 136 Short desc : $SHORT_DESC
pankso@7 137 Maintainer : $MAINTAINER
pankso@7 138 Packages : $packages
pankso@7 139 Addfiles : $addfiles
pankso@7 140 </pre>
pankso@7 141 <form method="get" action="./">
pankso@7 142 <div class="box">
pankso@7 143 Note:
pankso@7 144 <input type="text" name="note" style="width: 720px;" />
pankso@7 145 </div>
pankso@7 146 <div class="next">
pankso@7 147 <input type="submit" name="cancel" value="$(gettext "Cancel")">
pankso@7 148 <input type="hidden" name="addfiles" value="$addfiles" />
pankso@7 149 <input type="hidden" name="id" value="$id" />
pankso@7 150 <input type="submit" name="pack" value="$(gettext "Build flavor")">
pankso@7 151 </div>
pankso@7 152 </form>
pankso@7 153 EOT
pankso@7 154 ;;
pankso@7 155 *\ cancel\ *)
pankso@7 156 id="$(GET id)"
pankso@23 157 echo "<p>$(gettext "Removing temporary files for:") $id</p>"
pankso@7 158 [ -d "$tmpdir/slitaz-$id" ] && rm -rf $tmpdir/slitaz-$id/
pankso@7 159 cat << EOT
pankso@7 160 <form method="get" action="./">
pankso@7 161 <input type="submit" name="start" value="$(gettext "Start over")">
pankso@7 162 </form>
pankso@7 163 EOT
pankso@7 164 ;;
pankso@7 165 *\ pack\ *)
pankso@7 166 #
pankso@7 167 # Pack distro step
pankso@7 168 #
pankso@7 169 id="$(GET id)"
pankso@7 170 receipt="$tmpdir/slitaz-$id/receipt"
pankso@7 171 addfiles="$(GET addfiles)"
pankso@7 172 log="$tmpdir/slitaz-$id/distro.log"
pankso@7 173 note="$(GET note)"
pankso@7 174 inqueue=$(ls $queue | wc -l)
pankso@7 175 . $receipt
pankso@7 176 cat << EOT
pankso@7 177 <h2>$(gettext "Packing:") $FLAVOR</h2>
pankso@7 178 <pre>
pankso@7 179 EOT
pankso@7 180 if ! fgrep ADDFILES $receipt; then
pankso@7 181 echo "ADDFILES=\"$addfiles\"" >> $receipt
pankso@7 182 fi
pankso@7 183 if ! fgrep NOTE $receipt; then
pascal@91 184 echo "NOTE=\"$note\"" | \
pascal@91 185 sed 's/\$/\\$/g;s/`/\\`/g;s/\\/\\\\/g' >> $receipt
pankso@7 186 fi
pankso@7 187
pankso@7 188 # The rootcd README
pankso@7 189 echo -n "Creating SliTaz cdrom README..."
pankso@7 190 date=$(date '+%Y-%m-%d %H:%M')
pankso@7 191 mkdir -p $tmpdir/slitaz-$id/rootcd
pankso@7 192 cp $DATA/README.distro $tmpdir/slitaz-$id/rootcd/README
pankso@7 193 sed -i s"/_DATE_/$date/" $tmpdir/slitaz-$id/rootcd/README
pankso@7 194 status
pankso@7 195
pankso@7 196 echo -n "Creating flavor tarball..."
pankso@7 197 cd $tmpdir && tar cjf $FLAVOR.tar.bz2 slitaz-$id
pankso@7 198 mkdir -p $public/slitaz-$id
pankso@7 199 mv $FLAVOR.tar.bz2 $public/slitaz-$id
pankso@7 200 status
pankso@7 201
pankso@7 202 # Keep a public receipt copy and move everything from tmp to queue.
pankso@7 203 echo "Flavor packed : $(date '+%Y-%m-%d %H:%M')" | tee -a $log
pankso@7 204 echo -n "Moving $id to Pizza build queue..."
pankso@7 205 mv -f $tmpdir/slitaz-$id/distro.log $public/slitaz-$id
pankso@7 206 cp -f $tmpdir/slitaz-$id/receipt $public/slitaz-$id
pankso@7 207 mv $tmpdir/slitaz-$id $queue
pankso@7 208 status
pankso@7 209
pankso@7 210 if [ "$inqueue" == "1" ]; then
pankso@7 211 gettext "Your ISO will be built on next Pizza Bot run"
pankso@7 212 else
paul@63 213 eval_gettext "There are \$inqueue flavors in queue"
pankso@7 214 fi
pankso@7 215 echo ""
pankso@10 216 echo "New flavor added to queue: <a href='?id=$id'>$id</a> ($FLAVOR)" | log
pankso@7 217 cat << EOT
pankso@7 218 </pre>
pankso@7 219 <div>
pankso@7 220 <img src="images/archive.png" alt="[ tarball ]" />
pankso@7 221 $(gettext "Download tarball: ")
pankso@7 222 <a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
pankso@7 223 - Browse <a href="public/slitaz-$id/">the flavor</a>
pankso@7 224 </div>
pankso@7 225 <div class="next">
pankso@7 226 <form method="get" action="./">
pankso@7 227 <input type="hidden" name="id" value="$id" />
pankso@7 228 <input type="submit" value="$(gettext "Status")">
pankso@7 229 </form>
pankso@7 230 </div>
pankso@7 231 EOT
pankso@7 232 ;;
pankso@7 233 *\ id\ *)
pankso@7 234 #
pankso@7 235 # ID Status page
pankso@7 236 #
pankso@7 237 id="$(GET id)"
pankso@7 238 [ -f "$queue/slitaz-$id/receipt" ] && . $queue/slitaz-$id/receipt
pankso@7 239 [ -f "public/slitaz-$id/receipt" ] && . public/slitaz-$id/receipt
pankso@7 240 log="$public/slitaz-$id/distro.log"
pankso@7 241 if [ ! -d "public/slitaz-$id" ]; then
paul@9 242 echo "Sorry, can't find flavor ID: $id"
pankso@7 243 cat lib/footer.html && exit 0
pankso@7 244 fi
pankso@7 245 if [ -f "$public/slitaz-$id/$FLAVOR.iso" ]; then
pankso@7 246 dir="public/slitaz-$id"
pankso@7 247 list="$dir/packages.list"
pankso@7 248 iso="$dir/$FLAVOR.iso"
pankso@7 249 msg="$(gettext "Download ISO:") <a href='$dir/$FLAVOR.iso'>$FLAVOR.iso</a>
pankso@7 250 [ <a href='$dir/$FLAVOR.md5'>md5</a> ]"
pankso@7 251 else
pankso@7 252 list="$queue/slitaz-$id/packages.list"
pankso@7 253 msg="$(gettext "Flavor is building or still in the build queue")"
pankso@7 254 fi
pankso@7 255 pkgslist=$(cat $list | wc -l)
pankso@7 256 pkgsinst=$(cat $installed | wc -l)
pankso@7 257 [ "$pkgsinst" ] || pkgsinst=0
pankso@7 258 [ "$ISO_SIZE" ] || ISO_SIZE="N/A"
pankso@7 259 [ "$ROOTFS_SIZE" ] || ROOTFS_SIZE="N/A"
pankso@7 260 cat << EOT
pankso@7 261 <h2>$(gettext "Status for:") $FLAVOR</h2>
pankso@14 262 <div>
pankso@14 263 $(get_gravatar $MAINTAINER) $(gettext "Flavor description:") $SHORT_DESC
pankso@14 264 </div>
pankso@7 265 <pre>
pankso@7 266 Uniq ID : $id
pankso@7 267 Flavor : $FLAVOR
pankso@7 268 Packages : $pkgslist in list - $pkgsinst installed
pankso@7 269 Rootfs size : $ROOTFS_SIZE
pankso@7 270 ISO size : $ISO_SIZE
pankso@7 271 </pre>
pankso@7 272
pankso@7 273 <div>
pankso@7 274 <img src="images/iso.png" alt="[ iso ]" /> $(echo $msg)
pankso@7 275 </div>
pankso@7 276 <div>
pankso@7 277 <img src="images/archive.png" alt="[ tarball ]" />
pankso@7 278 $(gettext "Download tarball:")
pankso@7 279 <a href="public/slitaz-$id/$FLAVOR.tar.bz2">$FLAVOR.tar.bz2</a>
pankso@7 280 EOT
pankso@7 281 if [ -f "$public/slitaz-$id/$FLAVOR.flavor" ]; then
pankso@7 282 cat << EOT
pankso@7 283 - Flavor file: <a href="public/slitaz-$id/$FLAVOR.flavor">$FLAVOR.flavor</a>
pankso@7 284 EOT
pankso@7 285 fi
pankso@7 286 cat << EOT
pankso@7 287 - Browse <a href="public/slitaz-$id/">the flavor</a>
pankso@7 288 </div>
pankso@7 289 EOT
pankso@7 290 if [ "$NOTE" ]; then
pankso@7 291 echo "<div class="note">$NOTE</div>"
pankso@7 292 fi
pankso@7 293 if [ -f "$log" ]; then
pankso@7 294 echo '<h2>Distro log</h2>'
pankso@7 295 echo '<pre>'
pankso@7 296 fgrep 'Build time' $log
pankso@7 297 cat $log | highlighter log
pankso@7 298 echo '</pre>'
pankso@7 299 fi ;;
pankso@7 300 *\ help\ *)
pankso@7 301 echo "<h2>$(gettext "Help")</h2>"
pankso@42 302 cat /usr/share/doc/pizza/help.en.html
pankso@40 303 cat /usr/share/doc/pizza/faq.en.html
pankso@43 304 echo '<h3>README</h3>'
pankso@7 305 echo '<pre>'
pankso@7 306 cat /usr/share/doc/pizza/README
pankso@7 307 echo '</pre>' ;;
pankso@7 308 *\ info\ *)
pankso@7 309 # English only :-)
pankso@7 310 if mount | fgrep -q slitaz/public; then
pankso@7 311 mounted="Public is mounted"
pankso@7 312 else
pankso@7 313 mounted="WARRNING: Public is not mounted"
pankso@7 314 fi
pankso@7 315 echo '<h2><img src="images/monitor.png" alt="" />Pizza Info</h2>'
pankso@7 316 echo '<pre>'
pankso@7 317 [ "$mounted" ] && echo "$mounted"
pankso@7 318 echo -n "Public flavors : " && ls -1 public | wc -l
pankso@7 319 echo -n "Public size : " && du -sh public | awk '{print $1}'
pankso@7 320 echo -n "Tmp size : " && du -sh $tmpdir | awk '{print $1}'
pankso@7 321 echo '</pre>' ;;
pankso@16 322 *\ activity\ *)
pankso@16 323 cat << EOT
pankso@16 324 <h2><img src="images/monitor.png" alt="" />$(gettext "Activity")</h2>
pankso@16 325
pankso@16 326 <pre>
pankso@16 327 $(tac $activity | highlighter activity)
pankso@16 328 </pre>
pankso@16 329
pankso@16 330 EOT
pankso@16 331 ;;
pankso@7 332 *)
pankso@7 333 #
pankso@7 334 # Main page
pankso@7 335 #
pankso@7 336 inqueue=$(ls $queue | wc -l)
pankso@7 337 builds=$(cat $builds)
pankso@7 338 pubiso=$(ls -1 public | wc -l)
pankso@7 339 [ "$builds" ] || builds=0
pankso@7 340 cat << EOT
pankso@7 341 <h2>$(gettext "Welcome")</h2>
pankso@16 342 <form method="get" action="./">
pankso@7 343 <p>
pankso@23 344 $(gettext "SliTaz Pizza lets you create your own SliTaz ISO flavor
pankso@23 345 online. The ISO image can be burnt on a cdrom or installed on USB media.
pankso@23 346 Please read the SliTaz Pizza <a href="?help">Help</a> before starting
pankso@23 347 a new flavor.")
pankso@7 348 </p>
pankso@7 349 <pre>
erjo@71 350 Flavors: $inqueue in queue - $builds builds - $pubiso <a href="/public">public</a>
pankso@7 351 </pre>
pankso@7 352
pankso@7 353 <div class="start">
pankso@16 354 <input type="submit" name="start" value="$(gettext "Create a new flavor")">
pankso@7 355 </div>
pankso@7 356
pankso@7 357 EOT
pankso@7 358 echo "<h2>$(gettext "Latest builds")</h2>"
pankso@7 359 echo '<pre>'
pankso@19 360 for flavor in $(ls -1t public | head -n 5)
pankso@7 361 do
pankso@7 362 if [ -f "public/$flavor/receipt" ]; then
pankso@7 363 . ./public/$flavor/receipt
pankso@7 364 [ -f "public/$flavor/$FLAVOR.iso" ] && \
pankso@7 365 cat << EOT
pankso@17 366 $(get_gravatar $MAINTAINER 24) <a href="?id=$ID">$VERSION</a> : \
pankso@16 367 <a href="public/$flavor/$FLAVOR.iso">$FLAVOR.iso</a> ($ISO_SIZE)
pankso@7 368 EOT
pankso@7 369 fi
pankso@7 370 done
pankso@16 371 echo '</pre>'
pankso@16 372 cat << EOT
pankso@16 373 <h2>$(gettext "Activity")</h2>
pankso@16 374 <pre>
pankso@16 375 $(tac $activity | head -n 12 | highlighter activity)
pankso@16 376 </pre>
pankso@16 377 <input type="submit" name="activity" value="$(gettext "More activity")">
pankso@16 378 </form>
pankso@16 379 EOT
pankso@16 380 ;;
pankso@7 381 esac
pankso@7 382
pankso@7 383 # HTML footer.
pankso@7 384 cat lib/footer.html
pankso@7 385
pankso@7 386 exit 0