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

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sat Feb 18 17:56:39 2017 +0000 (2017-02-18)
parents c83842a21724
children
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 a receipt for new flavor.
42 gen_receipt() {
43 cat > $tmpdir/slitaz-$id/receipt << EOT
44 # SliTaz flavor receipt.
46 FLAVOR="slitaz-$flavor"
47 SHORT_DESC="$desc"
48 VERSION="$(date "+%Y%m%d")"
49 MAINTAINER="$mail"
51 ID="$id"
52 SKEL="$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 yet 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 description" && 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 gen_receipt
117 echo "Receipt created : $(date '+%Y-%m-%d %H:%M')" > $log ;;
118 esac
120 #
121 # Source the receipt and display page.
122 #
123 . $tmpdir/slitaz-$id/receipt
125 nb=$(cat $list | wc -l)
126 cat << EOT
127 <h2>Packages ($nb)</h2>
129 <form method="get" action="pkgs.cgi">
130 <div id="packages">
131 <table>
132 <tbody>
133 $(list_pkgs)
134 </tbody>
135 </table>
136 </div>
137 <input type="hidden" name="id" value="$id" />
138 <input type="submit" name="rm" value="$(gettext 'Remove package(s)')" />
139 </form>
141 <form method="get" action="pkgs.cgi">
142 <div style="float: right;">
143 <input type="text" name="add" style="width: 400px;" />
144 <input type="hidden" name="id" value="$id" />
145 <input type="submit" name="pkgs" value="$(gettext 'Add package(s)')" />
146 </div>
147 </form>
149 <form method="get" action="pkgs.cgi">
150 <p>
152 $(gettext "Here you can add or remove some packages to your flavor. You \
153 can also search for a package name and description to find a package name")
155 </p>
156 <input type="text" name="search" style="width: 300px;" />
157 <input type="hidden" name="id" value="$id" />
158 <input type="submit" value="$(gettext 'Search')" />
159 <div id="pkgs-search">
160 $([ "$search" ] && search_pkgs)
161 </div>
162 </form>
164 <pre>
165 Uniq ID : $id
166 Flavor : $FLAVOR
167 Short desc : $SHORT_DESC
168 </pre>
170 <div class="next">
171 <form method="get" action="rootfs.cgi">
172 <input type="hidden" name="id" value="$id" />
173 <input type="submit" value="$(gettext 'Continue')">
174 </form>
175 </div>
177 EOT
179 # HTML footer.
180 cat lib/footer.html
182 exit 0