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

Some smal CSS improvments
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 27 10:33:41 2012 +0200 (2012-03-27)
parents e457bafd41fc
children 2d78c44e8ad5
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-file\ *)
89 id="$(POST id)"
90 tmpname="$(FILE desktop-file tmpname)"
91 file="$(FILE desktop-file name)"
92 size="$(FILE desktop-file 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 notify "$(gettext "Added file:") $file ($size Bytes)" ;;
99 *)
100 notify "$(gettext "Unsupported file type")" "error" ;;
101 esac
102 ;;
103 *\ tarball\ *)
104 tmpname="$(FILE tarball tmpname)"
105 tarball="$(FILE tarball name)"
106 size="$(FILE tarball size)" ;;
107 *)
108 id="$(GET id)" ;;
109 esac
111 [ -n "$id" ] || id="$(POST id)"
113 if [ "$(GET loram)" != "none" ] && [ "$(GET loram)" != "" ]; then
114 echo "Low RAM convertion: $(GET loram)" >> $log
115 notify "$(gettext "Low RAM convertion:") $(GET loram)"
116 mkdir -p $tmpdir/slitaz-$id/rootfs/etc/tazlito 2> /dev/null
117 cat > $tmpdir/slitaz-$id/rootfs/etc/tazlito/loram.final <<EOT
118 cd \$1/..
119 iso=\$(ls *.iso)
120 if [ -s "\$iso" ]; then
121 echo "Converting \$iso to low ram iso..."
122 yes y | tazlito build-loram \$iso $iso.\$\$ $(GET loram)
123 mv -f \$iso.\$\$ \$iso
124 md5sum \$iso > \${iso%.iso}.md5
125 echo "================================================================================"
126 fi
127 cd - > /dev/null
128 EOT
129 fi
131 #
132 # Source receipt and display page with additional rootfs or file upload.
133 #
134 . $tmpdir/slitaz-$id/receipt
135 cat << EOT
136 <h2>Rootfs</h2>
137 <form method="post" action="rootfs.cgi" enctype="multipart/form-data">
139 <p>
140 SliTaz root filesystem modification can be done via an easy to use form,
141 a single tarball or by uploading files one by one in the wanted directory.
142 </p>
144 <h3>$(gettext "Easy customization")</h3>
146 <p>
147 $(gettext "Desktop Wallpaper in JPG format"):
148 <p>
150 <div class="inputfile">
151 <div class="inputhide">
152 <input type="file" name="wallpaper" size="48" />
153 </div>
154 </div>
155 <input type="submit" value="Upload Image" style="margin-left: 6px;" />
157 <!-- Buggy case action
159 <p>
160 $(gettext "Files on user desktop such as README, desktop file or documenatation.
161 Allowed file and extentions are:") README .desktop .html .png .jpg:
162 /etc/skel/Desktop:
163 <p>
165 <div class="inputfile">
166 <div class="inputhide">
167 <input type="file" name="desktop-file" size="48" />
168 </div>
169 </div>
170 <input type="submit" value="Upload File" style="margin-left: 6px;" />
172 -->
174 <h3>$(gettext "Rootfs tarball")</h3>
175 <p>
176 The files in the rootfs archive must have the same directory structure
177 as any standard SliTaz or Linux system. For example if you wish to
178 have a custom boot configuration file, you will have: rootfs/etc/rcS.conf.
179 Accepted tarball formats are: <strong>tar.gz tar.bz2 tar.lzma</strong>
180 and the archived directory must be named rootfs with a valid file system
181 hierachy such as: /usr/bin /etc /var/www
182 </p>
184 <div class="inputfile">
185 <div class="inputhide">
186 <input type="file" name="tarball" size="48" />
187 </div>
188 </div>
189 <input type="submit" value="Upload rootfs" style="margin-left: 6px;" />
191 <h3>$(gettext "ISO image convertion")</h3>
193 $(gettext "Low RAM support"):
194 <select name="loram">
195 <option value="none">$(gettext "No")</option>
196 <option value="ram">$(gettext "In RAM only")</option>
197 <option value="smallcdrom">$(gettext "Small CDROM or RAM")</option>
198 <option value="cdrom">$(gettext "Large CDROM or RAM")</option>
199 </select>
200 <input type="submit" value="Convert" />
202 <input type="hidden" name="id" value="$id" />
203 </form>
205 $([ "$tarball" ] && tarball_handler)
207 <pre>
208 Uniq ID : $id
209 Flavor : $FLAVOR
210 Short desc : $SHORT_DESC
211 </pre>
212 <div class="next">
213 <form method="get" action="./">
214 <input type="hidden" name="id" value="$id" />
215 <input type="submit" name="gen" value="$(gettext "Continue")">
216 </form>
217 </div>
218 EOT
220 # HTML footer.
221 cat lib/footer.html
223 exit 0