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

Tiny edits, improve translations...
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri May 02 17:40:45 2014 +0000 (2014-05-02)
parents 57a95ac66802
children
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 eval_gettext 'File name: $tarball'
19 eval_gettext 'File size: $size Bytes'
20 eval_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 # Don't 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 *) eval_gettext 'Bad FSH path for: $i'; rm -rf $upload ;;
46 esac
47 done && status
48 # Don't 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 cp -a $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 "$(eval_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 [ "$(POST fastboot)" != "" ]; then
115 echo "Fast boot conversion" >> $log
116 notify "$(gettext 'Fast boot conversion')"
117 mkdir -p $tmpdir/slitaz-$id/rootfs/etc/tazlito 2> /dev/null
118 # lzo decompression crash with 2.6.37...
119 false && cat > $tmpdir/slitaz-$id/rootfs/etc/tazlito/fastboot.iso <<EOT
120 [ -x /usr/bin/lzop ] || tazpkg get-install lzop
121 find * | cpio -o -H newc | lzop -9 > \$1/boot/rootfs.gz
122 EOT
123 cat > $tmpdir/slitaz-$id/rootfs/etc/tazlito/fastboot.iso <<EOT
124 find * | cpio -o -H newc | gzip -9 > \$1/boot/rootfs.gz
125 [ -x /usr/bin/advdef ] || tazpkg get-install advancecomp
126 [ -x /usr/bin/advdef ] && advdef -z4 \$1/boot/rootfs.gz
127 EOT
128 cat > $tmpdir/slitaz-$id/rootfs/etc/tazlito/fastboot.rootfs <<EOT
129 sed -i 's/FAST_BOOT_X="no"/FAST_BOOT_X="yes"/' etc/rcS.conf
130 EOT
131 fi
133 if [ "$(POST loram)" != "none" ] && [ "$(POST loram)" != "" ]; then
134 echo "Low RAM conversion: $(POST loram)" >> $log
135 notify "$(gettext 'Low RAM conversion:') $(POST loram)"
136 mkdir -p $tmpdir/slitaz-$id/rootfs/etc/tazlito 2> /dev/null
137 rm -f $tmpdir/slitaz-$id/rootfs/etc/tazlito/fastboot.iso 2> /dev/null
138 cat > $tmpdir/slitaz-$id/rootfs/etc/tazlito/loram.final <<EOT
139 cd \$1/..
140 iso=\$(ls *.iso)
141 if [ -s "\$iso" ]; then
142 echo "Converting \$iso to low ram iso..."
143 yes y | tazlito build-loram \$iso \$iso.\$\$ $(POST loram)
144 mv -f \$iso.\$\$ \$iso
145 md5sum \$iso > \${iso%.iso}.md5
146 echo "================================================================================"
147 fi
148 cd - > /dev/null
149 EOT
150 fi
152 #
153 # Source receipt and display page with additional rootfs or file upload.
154 #
155 . $tmpdir/slitaz-$id/receipt
156 cat << EOT
157 <h2>RootFS</h2>
158 <form method="post" action="rootfs.cgi" enctype="multipart/form-data">
160 <p>
161 $(gettext "SliTaz root filesystem modification can be done via an easy to use form, \
162 a single tarball or by uploading files one by one in the wanted directory.")
163 </p>
165 <h3>$(gettext "Easy customization")</h3>
167 <p>
168 $(gettext "Desktop Wallpaper in JPG format"):
169 <p>
171 <div class="inputfile">
172 <div class="inputhide">
173 <input type="file" name="wallpaper" size="48" />
174 </div>
175 </div>
176 <input type="submit" value="$(gettext 'Upload Image')" style="margin-left: 6px;" />
178 <p>
179 $(gettext "Files on user desktop such as README, desktop files or documentation. \
180 The files will be copied in the Home directory of each new user. SliTaz creates \
181 the default Live user at boot. Allowed files and extensions are:") README
182 .desktop .html .png .jpg:
183 <p>
185 <div class="inputfile">
186 <div class="inputhide">
187 <input type="file" name="desktop" size="48" />
188 </div>
189 </div>
190 <input type="submit" value="$(gettext 'Upload File')" style="margin-left: 6px;" />
193 <h3>$(gettext "RootFS tarball")</h3>
194 <p>
195 $(gettext "The files in the rootfs archive must have the same directory structure \
196 as any standard SliTaz or Linux system. For example if you wish to \
197 have a custom boot configuration file, you will have: rootfs/etc/rcS.conf. \
198 Accepted tarball formats are: <strong>tar.gz tar.bz2 tar.lzma</strong> \
199 and the archived directory must be named rootfs with a valid file system \
200 hierachy such as: /usr/bin /etc /var/www")
201 </p>
203 <div class="inputfile">
204 <div class="inputhide">
205 <input type="file" name="tarball" size="48" />
206 </div>
207 </div>
208 <input type="submit" value="$(gettext 'Upload rootFS')" style="margin-left: 6px;" />
210 <h3>$(gettext "ISO image conversion")</h3>
212 <input type="checkbox" name="fastboot" />
213 $(gettext "Fast boot") -
214 $(gettext "Low RAM support"):
215 <select name="loram">
216 <option value="none">$(gettext "No")</option>
217 <option value="ram">$(gettext "In RAM only")</option>
218 <option value="smallcdrom">$(gettext "Small CD-ROM or RAM")</option>
219 <option value="cdrom">$(gettext "Large CD-ROM or RAM")</option>
220 </select>
221 <input type="submit" value="$(gettext 'Convert')" />
223 <input type="hidden" name="id" value="$id" />
224 </form>
226 $([ "$tarball" ] && tarball_handler)
228 <pre>
229 $(gettext 'Uniq ID :') $id
230 $(gettext 'Flavor :') $FLAVOR
231 $(gettext 'Short desc :') $SHORT_DESC
232 </pre>
233 <div class="next">
234 <form method="get" action="./">
235 <input type="hidden" name="id" value="$id" />
236 <input type="submit" name="gen" value="$(gettext 'Continue')">
237 </form>
238 </div>
239 EOT
241 # HTML footer.
242 cat lib/footer.html
244 exit 0