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

Add HTML FAQ
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 27 11:32:23 2012 +0200 (2012-03-27)
parents ce872f64c4a7
children 96974e330b86
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 log="$tmpdir/slitaz-$id/distro.log"
15 # Flavor pkgs desc list format: pkgname version " short desc "
16 allpkgs="$SLITAZ/$SLITAZ_VERSION/packages/packages.desc"
17 list="$tmpdir/slitaz-$id/packages.list"
18 pkgsdesc="$tmpdir/slitaz-$id/packages.desc"
20 #
21 # Functions
22 #
24 # Pizza uses local packages synced with mirror each night.
25 list_pkgs() {
26 [ ! -f "$list" ] && echo "Missing: $pkgsdesc"
27 cat $pkgsdesc | while read PACKAGE VERSION SHORT_DESC
28 do
29 cat << EOT
31 <tr>
32 <td><input type="checkbox" name="pkg" value="$PACKAGE" /></td>
33 <td>$PACKAGE</td>
34 <td>$VERSION</td>
35 <td>$SHORT_DESC</td>
36 </tr>
37 EOT
38 done
39 }
41 # Gen an empty receipt for new flavor.
42 empty_receipt() {
43 cat > $tmpdir/slitaz-$id/receipt << EOT
44 # SliTaz flavor receipt.
46 FLAVOR=""
47 SHORT_DESC=""
48 VERSION="$(date "+%Y%m%d")"
49 MAINTAINER=""
51 ID=""
52 SKEL=""
54 EOT
55 }
57 # Search packages or desc in the local packages.desc
58 # TODO: Html table with selection
59 search_pkgs() {
60 echo '<pre>'
61 for pkg in $search
62 do
63 fgrep $pkg $allpkgs | cut -d "|" -f 1,2,3
64 done
65 echo '</pre>'
66 }
68 #
69 # Actions
70 #
72 case " $(GET) " in
73 *\ search\ *)
74 search="$(GET search)"
75 notify "Searching for: $search" ;;
76 *\ add\ *)
77 add="$(GET add)"
78 notify "Adding packages: $add"
79 for pkg in $add
80 do
81 # Add pkg only if not yep in Pizza flavor pkgs list
82 if ! grep -Eq "^($pkg|get-$pkg) " $list; then
83 pkginfo=$(grep -E "^($pkg|get-$pkg) " $allpkgs | cut -f 1,2,3 -d "|")
84 name=$(echo $pkginfo | cut -d "|" -f 1)
85 vers=$(echo $pkginfo | cut -d "|" -f 2)
86 desc=$(echo $pkginfo | cut -d "|" -f 3)
87 echo "$pkg $vers \" $desc \"" >> $pkgsdesc
88 echo "$pkg" >> $list
89 fi
90 done ;;
91 *\ rm\ *)
92 cmdline=$(echo ${QUERY_STRING#pkg=} | sed s'/&/ /g')
93 cmdline=${cmdline%id=*}
94 pkgs=$(echo $cmdline | sed -e s'/+/ /g' -e s'/pkg=//g' -e s/$cmd//)
95 notify "Removing packages: $pkgs"
96 for pkg in $pkgs
97 do
98 sed -i "/^${pkg} /"d $pkgsdesc
99 sed -i "/^${pkg} /"d $list
100 done ;;
101 *)
102 # No space in flavor name please.
103 flavor=$(echo $flavor | sed s'/ //'g)
104 # Javascript can be disable in browser.
105 [ ! "$flavor" ] && echo "Missing flavor name" && exit 0
106 [ ! "$mail" ] && echo "Missing email address" && exit 0
107 [ ! "$skel" ] && echo "Missing SliTaz skeleton" && exit 0
108 [ ! "$desc" ] && echo "Missing short desciption" && exit 0
109 notify "$(gettext "Creating receipt and packages list")"
110 mkdir -p $tmpdir/slitaz-$id
111 # Use a pkg desc for the web interface and a simple one tazlito.
112 cp -f $hgflavors/$skel/packages.desc $pkgsdesc
113 cp -f $hgflavors/$skel/packages.list $list
114 [ -d "$hgflavors/$skel/rootfs" ] && \
115 cp -a $hgflavors/$skel/rootfs $tmpdir/slitaz-$id
116 empty_receipt
117 sed -i \
118 -e s"/FLAVOR=.*/FLAVOR=\"slitaz-$flavor\"/" \
119 -e s"/MAINTAINER=.*/MAINTAINER=\"$mail\"/" \
120 -e s"/SKEL=.*/SKEL=\"$skel\"/" \
121 -e s"/SHORT_DESC=.*/SHORT_DESC=\"$desc\"/" \
122 -e s"/ID=.*/ID=\"$id\"/" $tmpdir/slitaz-$id/receipt
123 echo "Receipt created : $(date '+%Y-%m-%d %H:%M')" > $log ;;
124 esac
126 #
127 # Source the receipt and display page.
128 #
129 . $tmpdir/slitaz-$id/receipt
131 nb=$(cat $list | wc -l)
132 cat << EOT
133 <h2>Packages ($nb)</h2>
135 <form method="get" action="pkgs.cgi">
136 <div id="packages">
137 <table>
138 <tbody>
139 $(list_pkgs)
140 </tbody>
141 </table>
142 </div>
143 <input type="hidden" name="id" value="$id" />
144 <input type="submit" name="rm" value="$(gettext "Remove package(s)")" />
145 </form>
147 <form method="get" action="pkgs.cgi">
148 <div style="float: right;">
149 <input type="text" name="add" style="width: 400px;" />
150 <input type="hidden" name="id" value="$id" />
151 <input type="submit" name="pkgs" value="$(gettext "Add package(s)")" />
152 </div>
153 </form>
155 <form method="get" action="pkgs.cgi">
156 <p>
158 $(gettext "Here you can add or remove some packages from your flavor. You
159 can also search for packages name and description to find a package name")
161 </p>
162 <input type="text" name="search" style="width: 300px;" />
163 <input type="hidden" name="id" value="$id" />
164 <input type="submit" value="$(gettext "Search")" />
165 <div id="pkgs-search">
166 $([ "$search" ] && search_pkgs)
167 </div>
168 </form>
170 <pre>
171 Uniq ID : $id
172 Flavor : $FLAVOR
173 Short desc : $SHORT_DESC
174 </pre>
176 <div class="next">
177 <form method="get" action="rootfs.cgi">
178 <input type="hidden" name="id" value="$id" />
179 <input type="submit" value="$(gettext "Continue")">
180 </form>
181 </div>
183 EOT
185 # HTML footer.
186 cat lib/footer.html
188 exit 0