tazlito view live.cgi @ rev 392
tazlito: mergefs(): try to process filenames with spaces
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Nov 16 02:45:04 2015 +0200 (2015-11-16) |
parents | 847a1a024cd0 |
children | d7aa98b45a0f |
line source
1 #!/bin/sh
2 #
3 # CGI interface for SliTaz Live systems using Tazlito and TazUSB.
4 #
5 # Copyright (C) 2011 SliTaz GNU/Linux - BSD License
6 #
8 if [ "$1" == "call" ]; then
9 case "$2" in
10 merge_cleanup)
11 mv -f $3.merged $3
12 for i in $4/*; do
13 umount -d $i
14 done
15 rm -rf $4
16 exit ;;
17 esac
18 fi
20 # Common functions from libtazpanel
21 . lib/libtazpanel
22 get_config
24 #------
25 # menu
26 #------
28 case "$1" in
29 menu)
30 TEXTDOMAIN_original=$TEXTDOMAIN
31 export TEXTDOMAIN='tazlito'
32 cat <<EOT
33 <li><a data-icon="cd" href="live.cgi" data-root>$(gettext 'Live')</a>
34 <menu>
35 <li><a data-icon="" href="live.cgi?liveusb" data-root>$(gettext 'Create a live USB key')</a></li>
36 <li><a data-icon="" href="live.cgi#liveiso" data-root>$(gettext 'Create a live CD-ROM')</a></li>
37 <li><a data-icon="" href="live.cgi#hybrid" data-root>$(gettext 'Create a hybrid ISO')</a></li>
38 <li><a data-icon="" href="live.cgi#loram" data-root>$(gettext 'Convert ISO to loram')</a></li>
39 <li><a data-icon="" href="live.cgi#meta" data-root>$(gettext 'Build a meta ISO')</a></li>
40 </menu>
41 </li>
42 EOT
43 export TEXTDOMAIN=$TEXTDOMAIN_original
44 exit
45 esac
48 TITLE=$(gettext 'TazPanel - Live')
49 header
51 # Build arguments to create a meta iso using 'tazlito merge' command
52 merge_args()
53 {
54 tmp=$1
55 first=true
56 i=1
57 while [ -n "$(GET input$i)" ]; do
58 echo "$(stat -c "%s" $(GET input$i)) $(GET input$i) $(GET ram$i)"
59 $((i++))
60 done | sort -nr | while read size file ram; do
61 if $first; then
62 cp $file $(GET metaoutput)
63 echo -n "$ram $(GET metaoutput) "
64 first=false
65 continue
66 fi
67 dir=$tmp/$(basename $file)
68 mkdir $dir
69 mount -o loop,ro $file $dir
70 echo -n "$ram $dir/boot/rootfs.gz "
71 done
72 }
74 #
75 # Commands executed in Xterm first
76 #
78 case " $(GET) " in
79 *\ loramoutput\ *)
80 $TERMINAL $TERM_OPTS \
81 -T "build loram iso" \
82 -e "tazlito build-loram $(GET input) $(GET loramoutput) $(GET type)" & ;;
83 *\ meta\ *)
84 tmp=/tmp/$(basename $0).$$
85 cleanup="sh $0 call merge_cleanup $(GET output) $tmp"
86 $TERMINAL $TERM_OPTS \
87 -T "build meta iso" \
88 -e "tazlito merge $(merge_args $tmp); \
89 gettext 'ENTER to quit'; read i; \
90 $cleanup" & ;;
91 *\ hybrid\ *)
92 $TERMINAL $TERM_OPTS \
93 -T "build hybrid iso" \
94 -e "iso2exe $(GET input)" & ;;
95 esac
97 #
98 # Commands
99 #
101 case " $(GET) " in
102 *\ create\ *)
103 #
104 # Create a flavor file and ISO in options with all settings
105 # Step by step interface and store files in cache.
106 #
107 gettext 'TODO' ;;
108 *\ liveusb\ *)
109 xhtml_header
110 cat << EOT
111 <div id="wrapper">
112 <h2>$(gettext 'SliTaz LiveUSB')</h2>
113 <p>$(gettext 'Create Live USB SliTaz systems')<p>
114 </div>
116 <p>$(gettext "Generate SliTaz LiveUSB media and boot in RAM! Insert a LiveCD \
117 into the cdrom drive, select the correct device and press Generate.")</p>
119 <form method="get" action="$SCRIPT_NAME">
120 <input type="hidden" name="liveusb" />
121 $(gettext 'USB Media to use:')
122 <select name="gen">
123 EOT
124 # List disk if there is a plugged USB device
125 if [ -d /proc/scsi/usb-storage ]; then
126 for i in `blkid | cut -d ":" -f 1`; do
127 echo "<option value='$i'>$i</option>"
128 done
129 else
130 echo "<option value="">$(gettext 'Not found')</option>"
131 fi
132 cat << EOT
133 </select>
134 <input type="submit" value="$(gettext 'Generate')" />
135 </form>
136 EOT
137 if [ "$(GET gen)" ]; then
138 cat << EOT
139 <h3>tazusb gen-liveusb $(GET gen)</h3>
140 <pre>
141 EOT
142 # No pipe here so output is displayed in realtime
143 yes | tazusb gen-liveusb $(GET gen)
144 echo '</pre>'
145 fi ;;
146 *\ write_iso\ *)
147 xhtml_header
149 LaunchedByTazpanel="y" \
150 tazlito writeiso $(GET write_iso) > /tmp/tazlitowriteiso 2>&1 &
152 until [ -f /rootfs.gz ]; do
153 sleep 1
154 done
155 cat << EOT
156 <fieldset>
157 $(head /tmp/tazlitowriteiso | sed "s|$|<p></p>|g" | sed '/.gvfs/d')
158 <li id="fssize"> </li>
159 EOT
160 until [ ! -f /rootfs.gz ]; do
161 sleep 1
162 cat << EOT
163 <script type="text/javascript">
164 document.getElementById('fssize').innerHTML = "<h4>$(boldify $(du -mh /rootfs.gz | cut -f1))</h4>";
165 </script>
166 EOT
167 done
168 if [ -f /rootfs.gz ]; then
169 until [ ! -f /rootfs.gz ]; do
170 sleep 1
171 done
172 fi
173 cat <<EOT
174 <script type="text/javascript">
175 document.getElementById('fssize').innerHTML = "$(boldify $(du -mh /home/slitaz/distro/rootcd/boot/rootfs.gz | cut -f1))";
176 </script>
177 /home/slitaz/distro/rootcd/boot/rootfs.gz
178 </fieldset>
179 EOT
180 ls -l /home/slitaz/distro/rootcd/boot/rootfs.gz
181 until [ -f /tmp/.write-iso* ]; do
182 sleep 1
183 done
184 echo "<fieldset>"
185 if [ -f /tmp/.write-iso ]; then
186 newline
187 tail /tmp/tazlitowriteiso | grep ISO
188 while [ -f /tmp/.write-iso ]; do sleep 1 ; done
189 elif [ -f /tmp/.write-iso-error ]; then
190 tail -n8 /tmp/tazlitowriteiso | grep -vE 'ENTER|----'
191 fi
192 tail -n5 /tmp/tazlitowriteiso | sed "s|$|<p></p>|g"
193 ls -l /home/slitaz/distro
194 echo "</fieldset>"
195 echo "Use ' <code>tazlito emu-iso</code> ' to check it" ;;
196 *)
197 #
198 # Default xHTML content
199 #
200 xhtml_header
201 cat << EOT
202 <header id="liveiso"> <header>
203 <div id="wrapper">
204 <h2>$(gettext 'SliTaz Live Systems')</h2>
205 <p>$(gettext 'Create and manage Live CD or USB SliTaz systems')<p>
206 </div>
208 <div id="actions">
209 <a class="button" href="$SCRIPT_NAME?liveusb">
210 <img src="$IMAGES/harddisk.png" />$(gettext 'Create LiveUSB')</a>
211 </div>
213 <fieldset >
214 <h3 id="loram">$(gettext 'Write a Live CD')</h3>
216 <!-- id="livecd" -->
218 <div>
219 <p>$(gettext "The command writeiso will generate an ISO image of the current \
220 filesystem as is, including all files in the /home directory. It is an easy \
221 way to remaster a SliTaz Live system, you just have to: boot, modify, \
222 writeiso.")</p>
224 <form method="get" action="$SCRIPT_NAME">
225 $(gettext 'Compression type:')
226 <select name="write_iso">
227 <!--
228 <option value="gzip">gzip</option>
229 -->
230 <option value="lzma">lzma</option>
231 <option value="none">$(gettext 'none')</option>
232 </select>
233 <input type="submit" value="$(gettext 'Write ISO')" />
234 </form>
235 $([ ! -d /media/cdrom/boot/isolinux -a ! -f /boot/*slitaz* ] && \
236 echo '<p> Cannot find Slitaz ISO/cd mounted in /media/cdrom (You will get only rootfs.gz)</p>')
237 </div>
238 </fieldset>
240 <p></p>
241 <fieldset>
243 <h3>$(gettext 'Live CD tools')</h3>
245 <fieldset>
246 <h4>$(gettext 'Convert ISO to loram')</h4>
248 <!-- id="loram" -->
250 <p>$(gettext "This command will convert an ISO image of a SliTaz Live CD to a \
251 new ISO image requiring less RAM to run.")</p>
253 <form method="get" action="$SCRIPT_NAME#loram">
254 <table>
255 <tr>
256 <td>$(gettext 'ISO to convert')
257 <input type="text" accept=".iso" name="input" value="/root/" /></td>
258 </tr>
259 <tr>
260 <td><input type="radio" name="type" value="ram" id="type1" checked />
261 <label for="type1">$(gettext 'The filesystem is always in RAM')</label>
262 </td>
263 </tr>
264 <tr>
265 <td><input type="radio" name="type" value="smallcdrom" id="type2" />
266 <label for="type2">$(gettext 'The filesystem may be on a small CDROM')</label>
267 </td>
268 </tr>
269 <tr>
270 <td><input type="radio" name="type" value="cdrom" id="type3" />
271 <label for="type3">$(gettext 'The filesystem may be on a large CDROM')</label>
272 </td>
273 </tr>
274 <tr>
275 <td>$(gettext 'ISO to create')
276 <input type="text" accept=".iso" name="loramoutput" value="/root/loram.iso" />
277 </td>
278 </tr>
279 </table>
280 <input type="submit" value="$(gettext 'Convert ISO to loram')" />
281 </form>
282 </fieldset>
284 <fieldset>
285 <h4 id="hybrid">$(gettext 'Build a hybrid ISO')</h4>
287 <p>$(gettext "Add a master boot sector and an EXE header to the ISO image. \
288 ")</p>
290 <form method="get" action="$SCRIPT_NAME#hybrid">
291 <table>
292 <tr>
293 <td>
294 $(gettext 'ISO to convert')
295 <input type="text" name="input" value="/root/" />
296 </td>
297 </tr>
298 </table>
299 <input type="submit" name="hybrid" value="$(gettext 'Build a hybrid ISO')" />
300 </form>
301 </fieldset>
303 <fieldset>
304 <h4 id="meta">$(gettext 'Build a meta ISO')</h4>
306 <p>$(gettext "Combines several ISO flavors like nested Russian dolls. The \
307 amount of RAM available at startup will be used to select the utmost one.")</p>
309 <form method="get" action="$SCRIPT_NAME#meta">
310 <table>
311 EOT
312 i=""
313 while [ -n "$(GET addmeta)" ]; do
314 [ -n "$(GET input$i)" ] || break
315 j=$(($i + 1))
316 cat << EOT
317 <tr>
318 <td>$(gettext 'ISO number') $j: $(GET input$i)
319 <input type="hidden" name="input$j" value="$(GET input$i)" />
320 </td>
321 <td>$(gettext 'Minimum RAM'): $(GET ram$i)
322 <input type="hidden" name="ram$j" value="$(GET ram$i)" />
323 </td>
324 </tr>
325 EOT
326 i=$j
327 done
328 metaoutput="$(GET metaoutput)"
329 [ -n "$metaoutput" ] || metaoutput="/root/meta.iso"
331 cat << EOT
332 <tr>
333 <td>$(gettext 'ISO to add')
334 <input type="text" name="input" value="/root/" />
335 </td>
336 <td>$(gettext 'Minimum RAM')
337 <input type="text" name="ram" value="128M" />
338 <input type="submit" name="addmeta" value="$(gettext 'Add to the list')" />
339 </td>
340 </tr>
341 <tr>
342 <td>$(gettext 'ISO to create')
343 <input type="text" name="metaoutput" value="$metaoutput" />
344 </td>
345 </tr>
346 </table>
347 <input type="submit" name="meta" value="$(gettext 'Build a meta ISO')" />
348 </form>
349 </fieldset>
350 </fieldset>
352 EOT
353 ;;
354 esac
356 xhtml_footer
357 exit 0