tazlito annotate live.cgi @ rev 524

tazlito/loram: root may not be set
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Apr 19 12:30:49 2020 +0000 (2020-04-19)
parents 392ce00aa117
children
rev   line source
pascal@320 1 #!/bin/sh
pascal@320 2 #
pascal@320 3 # CGI interface for SliTaz Live systems using Tazlito and TazUSB.
pascal@320 4 #
al@399 5 # Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
pascal@320 6 #
pascal@320 7
pascal@514 8 if [ "$1" = 'call' ]; then
pascal@320 9 case "$2" in
al@399 10 merge_cleanup)
al@399 11 mv -f $3.merged $3
al@399 12 for i in $4/*; do
al@399 13 umount -d $i
al@399 14 done
al@399 15 rm -rf $4
al@399 16 exit ;;
pascal@320 17 esac
pascal@320 18 fi
pascal@320 19
al@399 20
pascal@320 21 # Common functions from libtazpanel
al@399 22
pascal@320 23 . lib/libtazpanel
pascal@320 24 get_config
pascal@320 25
al@399 26
pascal@382 27 #------
pascal@382 28 # menu
pascal@382 29 #------
pascal@382 30
pascal@382 31 case "$1" in
pascal@382 32 menu)
al@399 33 TEXTDOMAIN_original="$TEXTDOMAIN"
pascal@382 34 export TEXTDOMAIN='tazlito'
pascal@382 35 cat <<EOT
pascal@401 36 <li><a data-icon="cd" href="live.cgi">$(_ 'Live')</a>
pascal@382 37 <menu>
al@399 38 <li><a data-icon="" href="live.cgi?liveusb" data-root>$(_ 'Create a live USB key')</a></li>
al@399 39 <li><a data-icon="" href="live.cgi#liveiso" data-root>$(_ 'Create a live CD-ROM')</a></li>
pascal@440 40 <li><a data-icon="" href="live.cgi#hybrid" data-root>$(_ 'Create a hybrid ISO')</a></li>
al@399 41 <li><a data-icon="" href="live.cgi#loram" data-root>$(_ 'Convert ISO to loram')</a></li>
al@399 42 <li><a data-icon="" href="live.cgi#meta" data-root>$(_ 'Build a meta ISO')</a></li>
pascal@382 43 </menu>
pascal@382 44 </li>
pascal@382 45 EOT
al@399 46 export TEXTDOMAIN="$TEXTDOMAIN_original"
pascal@382 47 exit
pascal@382 48 esac
pascal@382 49
pascal@382 50
al@399 51 TEXTDOMAIN='tazlito'
al@399 52 TITLE=$(_ 'Live')
pascal@384 53 header
pascal@320 54
al@399 55
pascal@320 56 # Build arguments to create a meta iso using 'tazlito merge' command
al@399 57
al@399 58 merge_args() {
al@399 59 tmp="$1"
pascal@320 60 first=true
pascal@320 61 i=1
pascal@320 62 while [ -n "$(GET input$i)" ]; do
pascal@320 63 echo "$(stat -c "%s" $(GET input$i)) $(GET input$i) $(GET ram$i)"
pascal@320 64 $((i++))
al@399 65 done | sort -nr | \
al@399 66 while read size file ram; do
pascal@320 67 if $first; then
pascal@320 68 cp $file $(GET metaoutput)
pascal@320 69 echo -n "$ram $(GET metaoutput) "
pascal@320 70 first=false
pascal@320 71 continue
pascal@320 72 fi
al@399 73 dir="$tmp/$(basename $file)"
al@399 74 mkdir "$dir"
al@399 75 mount -o loop,ro "$file" "$dir"
pascal@320 76 echo -n "$ram $dir/boot/rootfs.gz "
pascal@320 77 done
pascal@320 78 }
pascal@320 79
al@399 80
pascal@320 81 #
pascal@320 82 # Commands executed in Xterm first
pascal@320 83 #
pascal@320 84
pascal@320 85 case " $(GET) " in
pascal@320 86 *\ loramoutput\ *)
al@399 87 export output='raw'
al@399 88 DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' \
pascal@320 89 $TERMINAL $TERM_OPTS \
al@399 90 -T "$(_ 'Convert ISO to loram')" \
al@399 91 -e "tazlito build-loram $(GET input) $(GET loramoutput) $(GET type)" &
al@399 92 ;;
al@399 93
pascal@320 94 *\ meta\ *)
pascal@320 95 tmp=/tmp/$(basename $0).$$
pascal@320 96 cleanup="sh $0 call merge_cleanup $(GET output) $tmp"
al@399 97 export output='raw'
al@399 98 DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' \
pascal@320 99 $TERMINAL $TERM_OPTS \
al@399 100 -T "$(_ 'Build a meta ISO')" \
pascal@320 101 -e "tazlito merge $(merge_args $tmp); \
al@399 102 _ 'ENTER to quit'; read i; \
al@399 103 $cleanup" &
al@399 104 ;;
al@399 105
pascal@320 106 *\ hybrid\ *)
pascal@440 107 custom=""
pascal@440 108 [ -n "$(GET extracmdline)" ] &&
pascal@440 109 custom="$custom -a \\\"$(GET extracmdline)\\\" "
pascal@440 110 [ -n "$(GET extrainitrd)" ] &&
pascal@440 111 custom="$custom -i \\\"$(GET extrainitrd)\\\" "
al@399 112 export output='raw'
al@399 113 DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' \
pascal@320 114 $TERMINAL $TERM_OPTS \
al@399 115 -T "$(_ 'Create a hybrid ISO')" \
pascal@440 116 -e iso2exe $custom$(GET input) -f &
al@399 117 ;;
pascal@320 118 esac
pascal@320 119
al@399 120
pascal@320 121 #
pascal@320 122 # Commands
pascal@320 123 #
pascal@320 124
pascal@320 125 case " $(GET) " in
al@399 126
pascal@320 127 *\ create\ *)
pascal@320 128 #
pascal@320 129 # Create a flavor file and ISO in options with all settings
pascal@320 130 # Step by step interface and store files in cache.
pascal@320 131 #
al@399 132 xhtml_header
al@399 133 _ 'TODO'
al@399 134 ;;
al@399 135
pascal@320 136 *\ liveusb\ *)
al@399 137 TITLE="$(_ 'SliTaz LiveUSB')"
al@399 138 xhtml_header "$(_ 'Create Live USB SliTaz systems')"
al@399 139 cat <<EOT
al@399 140 <section>
al@399 141 <header>$(_ 'SliTaz LiveUSB')</header>
pascal@320 142
al@399 143 <form method="get" action="$SCRIPT_NAME" class="wide">
al@399 144 <div>
al@399 145 $(_ "Generate SliTaz LiveUSB media and boot in RAM! Insert a Live CD \
al@399 146 into the CD-ROM drive, select the correct device and press Generate.")
al@399 147 </div>
pascal@320 148
al@399 149 <input type="hidden" name="liveusb" />
al@399 150 <footer>
al@399 151 $(_ 'USB Media to use:')
al@399 152 <select name="gen" id="gen">
pascal@320 153 EOT
pascal@320 154 # List disk if there is a plugged USB device
pascal@320 155 if [ -d /proc/scsi/usb-storage ]; then
al@399 156 for dev in /sys/block/sd*; do
al@399 157 # removable writable sd* device:
pascal@514 158 if [ "$(cat $dev/removable)" = '1' -a "$(cat $dev/ro)" = '0' ]; then
al@399 159 echo "<optgroup label='$(cat $dev/device/vendor) $(cat $dev/device/model):'>"
al@399 160 for part in $dev/sd*; do
al@399 161 [ ! -d "$part" ] && break
al@399 162 linuxdev=$(readlink -f /dev/block/$(cat $part/dev))
al@399 163 cat <<EOT
al@399 164 <option value='$linuxdev'>$(basename $linuxdev) [$(blkid -o value -s TYPE "$linuxdev")]
al@399 165 $(blkid -o value -s LABEL "$linuxdev") ($(cat $part/size | blk2h))</option>
al@399 166 EOT
al@399 167 done
al@399 168 echo '</optgroup>'
al@399 169 fi
pascal@320 170 done
pascal@320 171 else
al@399 172 echo "<option value=''>$(_ 'Not found')</option>"
pascal@320 173 fi
al@399 174
al@399 175 cat <<EOT
al@399 176 </select>
al@399 177 <button type="submit" data-icon="removable">$(_ 'Generate')</button>
al@399 178 </footer>
al@399 179 </form>
al@399 180 </section>
pascal@320 181 EOT
al@399 182
al@399 183 gen="$(GET gen)"
al@399 184 if [ -n "$gen" ]; then
al@399 185 cat <<EOT
al@399 186 <script>document.getElementById("gen").value = "$gen";</script>
al@399 187
al@399 188 <section>
al@399 189 <header>tazusb gen-liveusb $gen</header>
al@399 190 <pre>
pascal@320 191 EOT
pascal@320 192 # No pipe here so output is displayed in realtime
al@399 193 yes | tazusb gen-liveusb $gen
al@399 194 cat <<EOT
al@399 195 </pre>
al@399 196 </section>
al@399 197 EOT
al@399 198 fi
al@399 199
al@399 200 ;;
al@399 201
psychomaniak@383 202 *\ write_iso\ *)
psychomaniak@383 203 xhtml_header
psychomaniak@383 204
psychomaniak@383 205 LaunchedByTazpanel="y" \
psychomaniak@383 206 tazlito writeiso $(GET write_iso) > /tmp/tazlitowriteiso 2>&1 &
psychomaniak@383 207
psychomaniak@383 208 until [ -f /rootfs.gz ]; do
psychomaniak@383 209 sleep 1
psychomaniak@383 210 done
al@399 211 cat <<EOT
psychomaniak@383 212 <fieldset>
psychomaniak@383 213 $(head /tmp/tazlitowriteiso | sed "s|$|<p></p>|g" | sed '/.gvfs/d')
psychomaniak@383 214 <li id="fssize"> </li>
psychomaniak@383 215 EOT
psychomaniak@383 216 until [ ! -f /rootfs.gz ]; do
psychomaniak@383 217 sleep 1
al@399 218 cat <<EOT
psychomaniak@383 219 <script type="text/javascript">
psychomaniak@383 220 document.getElementById('fssize').innerHTML = "<h4>$(boldify $(du -mh /rootfs.gz | cut -f1))</h4>";
psychomaniak@383 221 </script>
psychomaniak@383 222 EOT
psychomaniak@383 223 done
psychomaniak@383 224 if [ -f /rootfs.gz ]; then
psychomaniak@383 225 until [ ! -f /rootfs.gz ]; do
psychomaniak@383 226 sleep 1
psychomaniak@383 227 done
psychomaniak@383 228 fi
psychomaniak@383 229 cat <<EOT
psychomaniak@383 230 <script type="text/javascript">
psychomaniak@383 231 document.getElementById('fssize').innerHTML = "$(boldify $(du -mh /home/slitaz/distro/rootcd/boot/rootfs.gz | cut -f1))";
psychomaniak@383 232 </script>
psychomaniak@383 233 /home/slitaz/distro/rootcd/boot/rootfs.gz
psychomaniak@383 234 </fieldset>
psychomaniak@383 235 EOT
psychomaniak@388 236 ls -l /home/slitaz/distro/rootcd/boot/rootfs.gz
psychomaniak@383 237 until [ -f /tmp/.write-iso* ]; do
psychomaniak@383 238 sleep 1
psychomaniak@383 239 done
psychomaniak@383 240 echo "<fieldset>"
psychomaniak@383 241 if [ -f /tmp/.write-iso ]; then
psychomaniak@383 242 newline
psychomaniak@383 243 tail /tmp/tazlitowriteiso | grep ISO
psychomaniak@383 244 while [ -f /tmp/.write-iso ]; do sleep 1 ; done
psychomaniak@383 245 elif [ -f /tmp/.write-iso-error ]; then
psychomaniak@383 246 tail -n8 /tmp/tazlitowriteiso | grep -vE 'ENTER|----'
psychomaniak@383 247 fi
psychomaniak@383 248 tail -n5 /tmp/tazlitowriteiso | sed "s|$|<p></p>|g"
psychomaniak@388 249 ls -l /home/slitaz/distro
psychomaniak@383 250 echo "</fieldset>"
al@399 251 echo "Use ' <code>tazlito emu-iso</code> ' to check it"
al@399 252 ;;
al@399 253
pascal@320 254 *)
pascal@320 255 #
pascal@320 256 # Default xHTML content
pascal@320 257 #
al@399 258 TITLE="$(_ 'SliTaz Live Systems')"
al@399 259 xhtml_header "$(_ 'Create and manage Live CD or USB SliTaz systems')"
pascal@320 260
pascal@400 261 [ $(id -u) -eq 0 ] && cat <<EOT
pascal@320 262
al@399 263 <section id="liveiso">
al@399 264 <header>$(_ 'Write a Live CD')</header>
pascal@320 265
al@399 266 <form method="get" action="$SCRIPT_NAME" class="wide">
al@399 267 <div>
al@399 268 $(_ "The command writeiso will generate an ISO image of the current \
pascal@320 269 filesystem as is, including all files in the /home directory. It is an easy \
pascal@320 270 way to remaster a SliTaz Live system, you just have to: boot, modify, \
al@399 271 writeiso.")
al@399 272 </div>
pascal@320 273
al@399 274 <table>
al@399 275 <tr><td>
al@399 276 $(_ 'Compression type:')
al@399 277 <select name="write_iso">
al@399 278 <option value="lzma">lzma</option>
pascal@402 279 <option value="gzip">gzip</option>
al@399 280 <option value="none">$(_ 'none')</option>
al@399 281 </select>
al@399 282 </td></tr>
al@399 283 </table>
al@399 284 EOT
pascal@320 285
psychomaniak@428 286 if [ $(id -u) -eq 0 -a ! -d /media/cdrom/boot/isolinux ]; then
al@399 287 msg warn "$(_ 'Cannot find SliTaz ISO/CD mounted in /media/cdrom (You will get only rootfs.gz)')"
al@399 288 fi
pascal@320 289
al@399 290 inputiso="$(GET input)"; inputiso="${inputiso:-/root/}"
al@399 291 loramoutput="$(GET loramoutput)"; loramoutput="${loramoutput:-/root/loram.iso}"
pascal@320 292
pascal@400 293 [ $(id -u) -eq 0 ] && cat <<EOT
al@399 294 <footer>
al@399 295 <button type="submit" data-icon="cd">$(_ 'Write ISO')</button>
al@399 296 </footer>
al@399 297 </form>
al@399 298 </section>
psychomaniak@383 299
pascal@320 300
al@399 301 <section><header>$(_ 'Live CD tools')</header>
pascal@320 302
pascal@320 303
al@399 304 <section id="loram">
al@399 305 <header>$(_ 'Convert ISO to loram')</header>
pascal@320 306
al@399 307 <form method="get" action="$SCRIPT_NAME#loram" class="wide">
al@399 308 <div>
al@399 309 $(_ "This command will convert an ISO image of a SliTaz Live CD to a \
pascal@400 310 new ISO image requiring less RAM to run.") (-30%)
al@399 311 </div>
pascal@320 312
al@399 313 <table>
al@399 314 <tr><td>
al@399 315 $(_ 'ISO to convert')
al@409 316 $(file_chooser 'input' "$inputiso" 'cd' 'application/x-cd-image')
al@399 317 </td></tr>
al@399 318 <tr><td>
al@399 319 <input type="radio" name="type" value="ram" id="type1" checked />
al@399 320 <label for="type1">$(_ 'The filesystem is always in RAM')</label>
al@399 321 </td></tr>
al@399 322 <tr><td>
al@399 323 <input type="radio" name="type" value="smallcdrom" id="type2" />
al@399 324 <label for="type2">$(_ 'The filesystem may be on a small CD-ROM')</label>
al@399 325 </td></tr>
al@399 326 <tr><td>
al@399 327 <input type="radio" name="type" value="cdrom" id="type3" />
al@399 328 <label for="type3">$(_ 'The filesystem may be on a large CD-ROM')</label>
al@399 329 </td></tr>
al@399 330 <tr><td>
al@399 331 $(_ 'ISO to create')
al@399 332 <input type="text" accept=".iso" name="loramoutput" value="$loramoutput" />
al@399 333 </td></tr>
al@399 334 </table>
pascal@320 335
al@399 336 <script>
al@399 337 EOT
al@399 338 case "$(GET type)" in
al@399 339 smallcdrom) sel='type2';;
al@399 340 cdrom) sel='type3';;
al@399 341 *) sel='type1';;
al@399 342 esac
pascal@400 343 [ $(id -u) -eq 0 ] echo "document.getElementById('$sel').checked = true;"
pascal@400 344 [ $(id -u) -eq 0 ] && cat <<EOT
al@399 345 </script>
pascal@320 346
al@399 347 <footer>
al@399 348 <button type="submit" data-icon="cd">$(_ 'Convert ISO to loram')</button>
al@399 349 </footer>
al@399 350 </form>
al@399 351 </section>
pascal@320 352
pascal@400 353 EOT
pascal@400 354 cat <<EOT
al@399 355
al@399 356 <section id="hybrid">
al@399 357 <header>$(_ 'Build a hybrid ISO')</header>
al@399 358
al@399 359 <form method="get" action="$SCRIPT_NAME#hybrid" class="wide">
al@399 360 <div>
al@399 361 $(_ "Add a master boot sector and an EXE header to the ISO image.")
pascal@400 362 <ul>
pascal@401 363 <li>$(_ "Create a bootable image for a USB key, a memory card, a harddisk or a SSD.")</li>
pascal@400 364 <li>$(_ "With the .EXE suffix, it will run under DOS (16 bits) or Windows (32 bits).")</li>
pascal@401 365 <li>$(_ "Add the ISO filesystem md5 digest and the boot CRC in the ISO boot area.")</li>
pascal@401 366 <li>$(_ "Does not alter the ISO filesystem or the ISO image size.")</li>
pascal@400 367 </ul>
al@399 368 </div>
al@399 369
al@399 370 <table>
al@399 371 <tr><td>
al@399 372 $(_ 'ISO to convert')
al@409 373 $(file_chooser 'input' '' 'cd' 'application/x-cd-image')
al@399 374 </td></tr>
al@399 375 </table>
pascal@440 376 <div>
pascal@440 377 $(_ "By the way, you can customize the ISO image to your needs.")
pascal@440 378 <ul>
pascal@440 379 <li>$(_ "Append the kernel command line.")<span data-img="info"
pascal@440 380 title="$(_ "Examples: add your locales")
pascal@440 381 (lang=fr_FR kmap=fr-latin1 tz=Europe/Paris) $(_ "or modify the init script")
pascal@440 382 (rdinit=/myowninit.sh)"></span><input type="text" name="extracmdline" /></li>
pascal@440 383 <li>$(_ "Load an extra initrd with your settings.")<span data-img="info"
pascal@440 384 title="$(_ "Examples: add your wifi/ssh/vpn keys or your applications")">
pascal@440 385 </span>$(file_chooser extrainitrd)</li>
pascal@440 386 </ul>
pascal@440 387 </div>
al@399 388
al@399 389 <footer>
al@399 390 <button type="submit" name="hybrid" data-icon="cd">$(_ 'Build a hybrid ISO')</button>
al@399 391 </footer>
al@399 392 </form>
al@399 393 </section>
al@399 394
pascal@400 395 EOT
pascal@400 396 [ $(id -u) -eq 0 ] && cat <<EOT
al@399 397
al@399 398 <section id="meta">
al@399 399 <header>$(_ 'Build a meta ISO')</header>
al@399 400
al@399 401 <form method="get" action="$SCRIPT_NAME#meta">
al@399 402 <div>
al@399 403 $(_ "Combines several ISO flavors like nested Russian dolls. The \
al@399 404 amount of RAM available at startup will be used to select the utmost one.")
al@399 405 </div>
al@399 406
al@399 407 <table class="wide">
pascal@320 408 EOT
al@399 409 i=''
pascal@320 410 while [ -n "$(GET addmeta)" ]; do
pascal@320 411 [ -n "$(GET input$i)" ] || break
pascal@320 412 j=$(($i + 1))
pascal@400 413 [ $(id -u) -eq 0 ] && cat <<EOT
al@399 414 <tr>
al@399 415 <td>
al@399 416 $(_ 'ISO number %s:' "$j") $(GET input$i)
al@399 417 <input type="hidden" name="input$j" value="$(GET input$i)" />
al@399 418 </td>
al@399 419 <td>
al@399 420 $(_ 'Minimum RAM:') $(GET ram$i)
al@399 421 <input type="hidden" name="ram$j" value="$(GET ram$i)" />
al@399 422 </td>
al@399 423 </tr>
pascal@320 424 EOT
pascal@320 425 i=$j
pascal@320 426 done
pascal@320 427 metaoutput="$(GET metaoutput)"
pascal@320 428 [ -n "$metaoutput" ] || metaoutput="/root/meta.iso"
pascal@320 429
pascal@400 430 [ $(id -u) -eq 0 ] && cat <<EOT
al@399 431 <tr>
al@399 432 <td>
al@399 433 $(_ 'ISO to add')
al@409 434 $(file_chooser 'input' '' 'cd' 'application/x-cd-image')
al@399 435 </td>
al@399 436 <td>
al@399 437 $(_ 'Minimum RAM:')
al@399 438 <input type="text" name="ram" value="128M" />
al@399 439 <button type="submit" name="addmeta" value="addmeta" data-icon="add">$(_ 'Add to the list')</button>
al@399 440 </td>
al@399 441 </tr>
al@399 442 <tr>
al@399 443 <td>
al@399 444 $(_ 'ISO to create')
al@399 445 <input type="text" name="metaoutput" value="$metaoutput" />
al@399 446 </td>
al@399 447 <td>
al@399 448 </td>
al@399 449 </tr>
al@399 450 </table>
pascal@320 451
al@399 452 <footer>
al@399 453 <button type="submit" name="meta" value="meta" data-icon="cd">$(_ 'Build a meta ISO')</button>
al@399 454 </footer>
al@399 455 </form>
al@399 456 </section>
al@399 457
al@399 458 </section>
pascal@320 459 EOT
pascal@320 460 ;;
pascal@320 461 esac
pascal@320 462
pascal@320 463 xhtml_footer
pascal@320 464 exit 0