slitaz-pizza view web/pkgs.cgi @ rev 14

Add Gravatar support to flavor status page
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 26 13:05:04 2012 +0200 (2012-03-26)
parents 8b324cb2c5e2
children 05bb87925527
line source
1 #!/bin/sh
2 #
3 # SliTaz Pizza CGI/web interface - Let's have a pizza :-)
4 # Packages step
5 #
7 . lib/libpizza
9 id="$(GET id)"
10 flavor="$(GET flavor)"
11 skel="$(GET skel)"
12 desc="$(GET desc)"
13 mail="$(GET mail)"
14 add="$(GET add)"
15 log="$tmpdir/slitaz-$id/distro.log"
16 list="$tmpdir/slitaz-$id/packages.list"
18 #
19 # Functions
20 #
22 list_pkgs() {
23 # Pizza uses local packages synced with mirror each night.
24 pkgsdesc="$SLITAZ/$SLITAZ_VERSION/packages/packages.desc"
25 [ ! -f "$pkgsdesc" ] && echo "Missing: $pkgsdesc"
26 for pkg in $(cat $list)
27 do
28 IFS="|"
29 grep "^$pkg |" $pkgsdesc | cut -f 1,2,3 -d "|" | \
30 while read PACKAGE VERSION SHORT_DESC
31 do
32 cat << EOT
33 <tr>
34 <td><input type="checkbox" name="pkg" value="$PACKAGE" /></td>
35 <td>$PACKAGE</td>
36 <td>$VERSION</td>
37 <td>$SHORT_DESC</td>
38 </tr>
39 EOT
40 done
41 done
42 }
44 # Gen an empty receipt for new flavor.
45 empty_receipt() {
46 cat > $tmpdir/slitaz-$id/receipt << EOT
47 # SliTaz flavor receipt.
49 FLAVOR=""
50 SHORT_DESC=""
51 VERSION="$(date "+%Y%m%d")"
52 MAINTAINER=""
54 ID=""
55 SKEL=""
57 EOT
58 }
60 #
61 # Actions
62 #
64 case " $(GET) " in
65 *\ add\ *)
66 for pkg in $add
67 do
68 if ! grep -q ^${pkg}$ $list; then
69 echo "$pkg" >> $list
70 fi
71 done ;;
72 *\ rm\ *)
73 cmdline=$(echo ${QUERY_STRING#pkg=} | sed s'/&/ /g')
74 cmdline=${cmdline%id=*}
75 pkgs=$(echo $cmdline | sed -e s'/+/ /g' -e s'/pkg=//g' -e s/$cmd//)
76 for pkg in $pkgs
77 do
78 sed -i "/^${pkg}$/"d $list
79 done ;;
80 *)
81 # No space in flavor name please.
82 flavor=$(echo $flavor | sed s'/ //'g)
83 # Javascript can be disable in browser.
84 [ ! "$flavor" ] && echo "Missing flavor name" && exit 0
85 [ ! "$mail" ] && echo "Missing email address" && exit 0
86 [ ! "$skel" ] && echo "Missing SliTaz skeleton" && exit 0
87 [ ! "$desc" ] && echo "Missing short desciption" && exit 0
88 mkdir -p $tmpdir/slitaz-$id
89 cp -f $cache/packages.$skel $list
90 echo "Receipt created : $(date '+%Y-%m-%d %H:%M')" > $log
91 empty_receipt
92 sed -i \
93 -e s"/FLAVOR=.*/FLAVOR=\"slitaz-$flavor\"/" \
94 -e s"/MAINTAINER=.*/MAINTAINER=\"$mail\"/" \
95 -e s"/SKEL=.*/SKEL=\"$skel\"/" \
96 -e s"/SHORT_DESC=.*/SHORT_DESC=\"$desc\"/" \
97 -e s"/ID=.*/ID=\"$id\"/" $tmpdir/slitaz-$id/receipt ;;
98 esac
100 #
101 # Source the receipt and display page.
102 #
103 . $tmpdir/slitaz-$id/receipt
105 nb=$(cat $list | wc -l)
106 cat << EOT
107 <h2>Packages ($nb)</h2>
109 <form method="get" action="pkgs.cgi">
110 <table>
111 <tbody>
112 $(list_pkgs)
113 </tbody>
114 </table>
115 <div>
116 <input type="hidden" name="id" value="$id" />
117 <input type="submit" name="rm" value="$(gettext "Remove package(s)")">
118 </form>
120 <form method="get" action="pkgs.cgi" style="float: right;">
121 <input type="text" name="add" />
122 <input type="hidden" name="id" value="$id" />
123 <input type="submit" name="pkgs" value="$(gettext "Add package(s)")">
124 </form>
126 <pre>
127 Uniq ID : $id
128 Flavor : $FLAVOR
129 Short desc : $SHORT_DESC
130 </pre>
131 <div class="next">
132 <form method="get" action="rootfs.cgi">
133 <input type="hidden" name="id" value="$id" />
134 <input type="submit" value="$(gettext "Continue")">
135 </form>
136 </div>
137 EOT
139 # HTML footer.
140 cat lib/footer.html
142 exit 0