slitaz-pizza view web/rootfs.cgi @ rev 37

rootfs.cgi: Add support for file on user Desktop
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 27 10:50:17 2012 +0200 (2012-03-27)
parents b870dbff832c
children 15d286d476f4
line source
1 #!/bin/sh
2 #
3 # SliTaz Pizza CGI/web interface - Let's have a pizza :-)
4 # SliTaz rootfs step
5 #
7 . lib/libpizza
8 log="$tmpdir/slitaz-$id/distro.log"
10 # Internationalization: $(gettext "")
11 . /usr/bin/gettext.sh
12 TEXTDOMAIN='pizza'
13 export TEXTDOMAIN
15 # Handle rootfs.* file upload.
16 tarball_handler() {
17 echo "<pre>"
18 echo "File name : $tarball"
19 echo "File size : $size Bytes"
20 gettext "Moving rootfs tarball to slitaz-$id"
21 upload=$tmpdir/slitaz-$id/upload-$$
22 mkdir -p $upload && cd $upload
23 mv $tmpname "$upload/$tarball" && rm -rf $(dirname $tmpname)
24 chmod a+r $upload/$tarball
25 status
27 # Extract into the tmp upload dir.
28 gettext "Extracting archive for sanity checks..."
29 case "$tarball" in
30 *.tar.gz) tar xzf $tarball && status ;;
31 *.tar.bz2) tar xjf $tarball && status ;;
32 *.tar.lzma) tar xaf $tarball && status ;;
33 *) echo && error "Unsupported tarball format" && rm -rf $upload
34 esac
36 # Upload dir is removed if bad tarball so we stop here. Now be a bit
37 # restrictive using only rootfs as archive name and check FSH in root.
38 # Dont allow files in /dev /proc /sys /tmp /mnt
39 if [ -d "$upload/rootfs" ]; then
40 gettext "Checking Filesystem Standard..."
41 for i in $(ls $upload/rootfs)
42 do
43 case "$i" in
44 bin|boot|etc|home|init|lib|root|sbin|usr|var) continue ;;
45 *) echo "Bad FSH path for: $i" && rm -rf $upload ;;
46 esac
47 done && status
48 # Dont allow too big rootfs content.
49 size=$(du -s $upload/rootfs | awk '{print $1}')
50 gettext "Checking uploaded rootfs size..."
51 if [ "$size" -lt "$MAX_UPLOAD" ]; then
52 status
53 else
54 echo && error "Tarball is too big"
55 rm -rf $upload
56 fi
57 fi
59 # So now it time to move the addfile to flavor files.
60 if [ -d "$upload/rootfs" ]; then
61 echo "Additional rootfs: accepted" | tee -a $log
62 mkdir -p $tmpdir/slitaz-$id/rootfs
63 mv $upload/rootfs/* $tmpdir/slitaz-$id/rootfs
64 rm -rf $tmpdir/slitaz-$id/upload-* $upload/rootfs
65 fi
66 echo "</pre>"
67 rm -rf $upload
68 }
70 #
71 # Actions
72 #
74 case " $(FILE) " in
75 *\ wallpaper\ *)
76 tmpname="$(FILE wallpaper tmpname)"
77 wallpaper="$(FILE wallpaper name)"
78 size="$(FILE wallpaper size)"
79 if echo $wallpaper | fgrep -q .jpg; then
80 images=$tmpdir/slitaz-$id/rootfs/usr/share/images
81 mkdir -p $images
82 mv $tmpname $images/slitaz-background.jpg
83 chmod a+r $images/*.jpg
84 notify "$(gettext "Added image:") $wallpaper ($size Bytes)"
85 else
86 notify "$(gettext "Unsupported image format")" "error"
87 fi ;;
88 *\ desktop\ *)
89 id="$(POST id)"
90 tmpname="$(FILE desktop tmpname)"
91 file="$(FILE desktop name)"
92 size="$(FILE desktop size)"
93 path="$tmpdir/slitaz-$id/rootfs/etc/skel/Desktop"
94 mkdir -p $path
95 case "$file" in
96 *README*|*.desktop|*.html|*.png|*.jpg)
97 mv $tmpname $path/$file
98 chmod a+r $path/$file
99 notify "$(gettext "Added file:") $file ($size Bytes)" ;;
100 *)
101 notify "$(gettext "Unsupported file type")" "error" ;;
102 esac
103 ;;
104 *\ tarball\ *)
105 tmpname="$(FILE tarball tmpname)"
106 tarball="$(FILE tarball name)"
107 size="$(FILE tarball size)" ;;
108 *)
109 id="$(GET id)" ;;
110 esac
112 [ -n "$id" ] || id="$(POST id)"
114 if [ "$(GET loram)" != "none" ] && [ "$(GET loram)" != "" ]; then
115 echo "Low RAM convertion: $(GET loram)" >> $log
116 notify "$(gettext "Low RAM convertion:") $(GET loram)"
117 mkdir -p $tmpdir/slitaz-$id/rootfs/etc/tazlito 2> /dev/null
118 cat > $tmpdir/slitaz-$id/rootfs/etc/tazlito/loram.final <<EOT
119 cd \$1/..
120 iso=\$(ls *.iso)
121 if [ -s "\$iso" ]; then
122 echo "Converting \$iso to low ram iso..."
123 yes y | tazlito build-loram \$iso $iso.\$\$ $(GET loram)
124 mv -f \$iso.\$\$ \$iso
125 md5sum \$iso > \${iso%.iso}.md5
126 echo "================================================================================"
127 fi
128 cd - > /dev/null
129 EOT
130 fi
132 #
133 # Source receipt and display page with additional rootfs or file upload.
134 #
135 . $tmpdir/slitaz-$id/receipt
136 cat << EOT
137 <h2>Rootfs</h2>
138 <form method="post" action="rootfs.cgi" enctype="multipart/form-data">
140 <p>
141 SliTaz root filesystem modification can be done via an easy to use form,
142 a single tarball or by uploading files one by one in the wanted directory.
143 </p>
145 <h3>$(gettext "Easy customization")</h3>
147 <p>
148 $(gettext "Desktop Wallpaper in JPG format"):
149 <p>
151 <div class="inputfile">
152 <div class="inputhide">
153 <input type="file" name="wallpaper" size="48" />
154 </div>
155 </div>
156 <input type="submit" value="Upload Image" style="margin-left: 6px;" />
158 <p>
159 $(gettext "Files on user desktop such as README, desktop file or documenatation.
160 The file will be copied in the Home directory of each new user. SliTaz create
161 the default Live user at boot. Allowed file and extentions are:") README
162 .desktop .html .png .jpg:
163 <p>
165 <div class="inputfile">
166 <div class="inputhide">
167 <input type="file" name="desktop" size="48" />
168 </div>
169 </div>
170 <input type="submit" value="Upload File" style="margin-left: 6px;" />
173 <h3>$(gettext "Rootfs tarball")</h3>
174 <p>
175 The files in the rootfs archive must have the same directory structure
176 as any standard SliTaz or Linux system. For example if you wish to
177 have a custom boot configuration file, you will have: rootfs/etc/rcS.conf.
178 Accepted tarball formats are: <strong>tar.gz tar.bz2 tar.lzma</strong>
179 and the archived directory must be named rootfs with a valid file system
180 hierachy such as: /usr/bin /etc /var/www
181 </p>
183 <div class="inputfile">
184 <div class="inputhide">
185 <input type="file" name="tarball" size="48" />
186 </div>
187 </div>
188 <input type="submit" value="Upload rootfs" style="margin-left: 6px;" />
190 <h3>$(gettext "ISO image convertion")</h3>
192 $(gettext "Low RAM support"):
193 <select name="loram">
194 <option value="none">$(gettext "No")</option>
195 <option value="ram">$(gettext "In RAM only")</option>
196 <option value="smallcdrom">$(gettext "Small CDROM or RAM")</option>
197 <option value="cdrom">$(gettext "Large CDROM or RAM")</option>
198 </select>
199 <input type="submit" value="Convert" />
201 <input type="hidden" name="id" value="$id" />
202 </form>
204 $([ "$tarball" ] && tarball_handler)
206 <pre>
207 Uniq ID : $id
208 Flavor : $FLAVOR
209 Short desc : $SHORT_DESC
210 </pre>
211 <div class="next">
212 <form method="get" action="./">
213 <input type="hidden" name="id" value="$id" />
214 <input type="submit" name="gen" value="$(gettext "Continue")">
215 </form>
216 </div>
217 EOT
219 # HTML footer.
220 cat lib/footer.html
222 exit 0