tazinst view installer.cgi @ rev 92

german translation completed
author Hans-G?nter Theisgen
date Fri Oct 06 15:12:26 2017 +0100 (2017-10-06)
parents d3fec3a9d379
children 5c34d77a6168
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for Tazinst, the SliTaz installer.
4 #
5 # Copyright (C) 2012-2017 SliTaz GNU/Linux - BSD License
6 #
7 # Authors : Dominique Corbex <domcox@slitaz.org>
8 #
11 # restricted path
12 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
14 VERSION=3.98
16 # Common functions from libtazpanel
17 . ./lib/libtazpanel
18 get_config
20 TITLE=$(_ 'TazPanel - Installer')
22 # export package name for gettext.
23 TEXTDOMAIN='installer'
24 export TEXTDOMAIN
26 # tazinst required version
27 TAZINST_MINIMUM_VERSION="3.8"
28 TAZINST_MAXIMUM_VERSION="4.99"
30 # tazinst setup file
31 INSTFILE=/root/tazinst.conf
34 #------
35 # menu
36 #------
38 case "$1" in
39 menu)
40 cat <<EOT
41 <li tabindex="0">
42 <span>$(_ 'Installation')</span>
43 <menu>
44 <li><a data-icon="install"
45 href="installer.cgi" data-root>$(_ 'Installation')</a></li>
46 <li><a data-icon="slitaz"
47 href="installer.cgi?page=install" data-root>$(_ 'Install SliTaz')</a></li>
48 <li><a data-icon="upgrade"
49 href="installer.cgi?page=upgrade" data-root>$(_ 'Upgrade system')</a></li>
50 <li><a data-icon="slitaz"
51 href="installer.cgi?page=evaluate" data-root>$(_ 'Evaluate SliTaz')</a></li>
52 </menu>
53 </li>
54 EOT
55 exit
56 esac
59 #-----------
60 # home page
61 #-----------
63 select_action() {
64 cat <<EOT
65 <!-- Welcome message -->
67 <h2>$(_ 'Welcome to the SliTaz Installer!')</h2>
69 <p>$(_ "The SliTaz Installer installs or upgrades SliTaz to a \
70 hard disk drive from a device like a Live-CD or LiveUSB key, from a SliTaz \
71 ISO file, or from the web by downloading an ISO file.")</p>
73 <p>$(_ "Windows&trade; users can evaluate SliTaz in the directory \
74 \\slitaz on their hard disk.")</p>
76 <p>$(_ "Which type of installation do you want to start?")</p>
77 EOT
78 }
81 select_install() {
82 cat <<EOT
83 <!-- Install message -->
85 <section>
86 <header>$(_ 'Install')</header>
88 <div>
89 <p>$(_ "Install SliTaz on a partition of your hard disk drive. If \
90 you decide to format your partition, all data will be lost. If you do not \
91 format, all data except for any existing /home directory will be removed \
92 (the home directory will be kept as is).")</p>
93 <p>$(_ "Before installation, you may need to create or resize \
94 partitions on your hard disk drive in order to make space for SliTaz \
95 GNU/Linux. You can graphically manage your partitions with Gparted")</p>
96 </div>
98 <footer>
99 <form>
100 <button type="submit" name="page" value="install" data-icon="slitaz"
101 title="$(_ 'Proceed to a new SliTaz installation')"
102 >$(_ 'Install SliTaz')</button>
103 </form>
104 </footer>
105 </section>
106 EOT
107 }
110 select_upgrade() {
111 cat <<EOT
112 <!-- Upgrade message -->
114 <section>
115 <header>$(_ 'Upgrade')</header>
117 <div>
118 <p>$(_ "Upgrade an already installed SliTaz system on your hard disk \
119 drive. Your /home /etc /var/www directories will be kept, all other \
120 directories will be removed. Any additional packages added to your old \
121 SliTaz system will be updated as long you have an active internet connection.")</p>
122 </div>
124 <footer>
125 <form>
126 <button type="submit" name="page" value="upgrade" data-icon="upgrade"
127 title="$(_ 'Upgrade an existing SliTaz system')"
128 >$(_ 'Upgrade SliTaz')</button>
129 </form>
130 </footer>
131 </section>
132 EOT
133 }
136 select_evaluate() {
137 cat <<EOT
138 <!-- Evaluate message -->
140 <section>
141 <header>$(_ 'Evaluate: Without Partitioning / Formating')</header>
143 <div>
144 <p>$(_ 'SliTaz and Windows&trade; can coexist in the same partition.')</p>
145 <p>$(_ "SliTaz will be in the %s directory like UMSDOS used to do \
146 in the previous century..." '\slitaz')</p>
147 </div>
149 <form action="boot.cgi">
150 <input type="hidden" name="iso"/>
151 <input type="hidden" name="action" value="install"/>
152 <table>
153 <tr><td>$(_ 'ISO image file full path')
154 <span data-img="info" title="$(_ 'set %s for a physical CD-ROM' '/dev/cdrom')"></span>
155 </td>
156 <td>$(file_chooser "iso" "")</td></tr>
157 <tr><td>$(_ 'Target partition')</td>
158 <td><select name="instdev">
159 <option value="/dev/null">$(_ 'Choose a partition')</option>
160 EOT
161 blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | \
162 sed -e 's|[A-Z]*ID="[^"]*"||g;s| SEC[^ ]*||;s|LABEL=||;s|:||' \
163 -e 's|TYPE="\([^"]*\)"|\1|;s|/dev/||' | \
164 while read dev label type; do
165 echo -n "<option value=\"/dev/$dev\">/dev/$dev $label $type "
166 echo "$(blk2h < /sys/block/${dev:0:3}/$dev/size)</option>"
167 done
168 cat <<EOT
169 </select></td></tr>
170 </table>
171 <button type="submit" data-icon="install">$(_ 'Install')</button>
172 </form>
173 </section>
174 EOT
175 }
178 #--------------------
179 # partitioning page
180 #--------------------
182 exec_gparted() {
183 /bin/su - -c \
184 "exec env DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' /usr/sbin/gparted" >/dev/null 2>&1
185 }
188 select_gparted() {
189 cat <<EOT
190 <!-- GParted message -->
192 <section>
193 <header>$(_ 'Partitioning')</header>
195 <div>
196 <p>$(_ "On most used systems, the hard drive is already dedicated to \
197 partitions for Windows&trade;, or Linux, or another operating \
198 system. You'll need to resize these partitions in order to make space for \
199 SliTaz GNU/Linux. SliTaz will co-exist with other operating systems already \
200 installed on your hard drive.")</p>
201 <p>$(_ "The amount of space needed depends on how much software you \
202 plan to install and how much space you require for users. It's conceivable \
203 that you could run a minimal SliTaz system in 300 megs or less, but 2 gigs \
204 is indeed more comfy.")</p>
205 <p>$(_ "A separate home partition and a partition that will be used \
206 as Linux swap space may be created if needed. SliTaz detects and uses swap \
207 partitions automatically.")</p>
208 <hr/>
209 <p>$(_ "You can graphically manage your partitions with GParted. \
210 GParted is a partition editor for graphically managing your disk partitions. \
211 GParted allows you to create, destroy, resize and copy partitions without \
212 data loss.")</p>
213 <p>$(_ "GParted supports ext2, ext3, ext4, linux swap, ntfs and \
214 fat32 filesystems right out of the box. Support for xjs, jfs, hfs and other \
215 filesystems is available as well but you first need to add drivers for these \
216 filesystems by installing the related packages xfsprogs, jfsutils, linux-hfs \
217 and so on.")</p>
218 </div>
220 <footer>
221 <!-- Launch GParted -->
222 <form>
223 <button type="submit" name="page" value="gparted" data-icon="hdd"
224 title="$(_ 'Launch GParted, the partition editor tool')"
225 >$(_ 'Execute GParted')</button>
226 </form>
227 </footer>
228 </section>
230 <h5>$(_ 'Continue installation')</h5>
232 <p>$(_ "Once you've made room for SliTaz on your drive, you should \
233 be able to continue installation.")</p>
234 EOT
235 }
238 #------------
239 # input page
240 #------------
242 select_source() {
243 local media="$(/usr/sbin/tazinst get media "$INSTFILE")"
244 local source="$(/usr/sbin/tazinst get source "$INSTFILE")"
245 local list_media="$(/usr/sbin/tazinst list media)"
246 local error
248 # set default media
249 [ -n "$media" ] || media="$(tazinst list media | cut -d ' ' -f1)"
251 comment "Source selection"
252 # cdrom
253 if printf '%s' "$list_media" | grep -q "cdrom"; then
254 input_media "cdrom" \
255 "$media"
256 label_media "cdrom" \
257 "$(_ 'LiveCD')" \
258 "$media" \
259 "$(_ 'Use the SliTaz LiveCD')"
260 br
261 fi
262 # usb
263 if printf '%s' "$list_media" | grep -q "usb"; then
264 input_media "usb" \
265 "$media"
266 label_media "usb" \
267 "$(_ 'LiveUSB:')" \
268 "$media" \
269 "$(_ 'Enter the partition where SliTaz Live is located on your USB Key')"
271 error="$?"
272 select "$(/usr/sbin/tazinst list usb "$INSTFILE" | cut -d' ' -f2)" \
273 "$source" \
274 "SRC_USB"
275 error_msg "$error" \
276 "source" \
277 2
278 br
279 fi
280 # iso
281 input_media "iso" \
282 "$media"
283 label_media "iso" \
284 "$(_ 'ISO file:')" \
285 "$media" \
286 "$(_ 'Select a SliTaz ISO file located on a local disk')"
287 error="$?"
288 if [ "$media" == "iso" ]; then
289 input "text" \
290 "src_iso" \
291 "$source" "" \
292 "$(_ 'Select an ISO or enter the full path to the ISO file')"\
293 "iso"
294 else
295 input "text" \
296 "src_iso" \
297 "" \
298 "none" \
299 "$(_ 'Select an ISO or enter the full path to the ISO file')"\
300 "iso"
301 fi
302 datalist "$(/usr/sbin/tazinst list iso "$INSTFILE")" \
303 "src_iso"
304 error_msg "$error" \
305 "source"
306 br
307 # web
308 input_media "web" \
309 "$media"
310 label_media "web" \
311 "$(_ 'Web:')" \
312 "$media" \
313 "$(_ 'Select a SliTaz version on the Web')"
314 error="$?"
316 if [ "$media" == "web" ]; then
317 input "text" \
318 "src_web" \
319 "$source" "" \
320 "$(_ 'Select a version or enter the full URL to an ISO file')"\
321 "web"
322 else
323 input "text" \
324 "src_web" \
325 "" \
326 "none" \
327 "$(_ 'Select a version or enter the full URL to an ISO file')"\
328 "web"
329 fi
330 datalist "$(/usr/sbin/tazinst help web "$INSTFILE")" \
331 "src_web"
332 error_msg "$error" \
333 "source"
334 }
336 select_root_uuid()
337 {
338 local root_uuid="$(/usr/sbin/tazinst get root_uuid "$INSTFILE")"
339 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
340 comment "root_uuid selection"
341 if [ "$mode" == "upgrade" ]; then
342 label "root_uuid" \
343 "$(_ 'Existing SliTaz partition to upgrade:')" \
344 "$(_ 'Specify the partition containing the system to upgrade')"
345 error="$?"
346 else
347 label "root_uuid" \
348 "$(_ 'Install SliTaz to partition:')" \
349 "$(_ 'Specify the partition where to install SliTaz')"
350 error="$?"
351 fi
352 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
353 "$root_uuid" \
354 "ROOT_UUID" \
355 0
356 error_msg "$error" \
357 "root_uuid" \
358 0
359 br
360 }
362 select_root_format()
363 {
364 local root_format="$(/usr/sbin/tazinst get root_format "$INSTFILE")"
365 comment "root_format selection"
366 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
367 "$root_format" \
368 "ROOT_FORMAT"
369 }
371 select_home_uuid() {
372 local home_uuid="$(/usr/sbin/tazinst get home_uuid "$INSTFILE")"
374 cat <<EOT
375 <!-- home_uuid selection -->
377 <fieldset>
378 <legend>$(_ 'home partition')</legend>
380 $(
381 label "home_uuid" \
382 "$(_ 'Separate partition for %s:' '/home')" \
383 "$(_ 'Specify the partition containing %s' '/home')"
384 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
385 "$home_uuid" \
386 "HOME_UUID" \
387 0
388 )
389 <br/>
390 EOT
391 }
393 select_home_format()
394 {
395 local home_format="$(/usr/sbin/tazinst get home_format "$INSTFILE")"
397 comment "home_format selection"
398 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
399 "$home_format" \
400 "HOME_FORMAT"
401 cat <<EOT
402 </fieldset>
403 EOT
404 }
407 select_hostname() {
408 local hostname="$(/usr/sbin/tazinst get hostname "$INSTFILE")" error
410 cat <<EOT
411 <!-- hostname selection -->
413 <fieldset>
414 <legend>$(_ 'Hostname')</legend>
415 $(
416 label "hostname" \
417 "$(_ 'Set Hostname to:')" \
418 "$(_ 'Hostname configuration allows you to specify the machine name')"
419 error=$?
420 input "text" \
421 "HOSTNAME" \
422 "$hostname" \
423 "" \
424 "$(_ 'Name of your system')"
425 error_msg "$error" \
426 "hostname" \
427 2
428 )
429 </fieldset>
430 EOT
431 }
434 select_root_pwd() {
435 local root_pwd="$(/usr/sbin/tazinst get root_pwd "$INSTFILE")" error
437 cat <<EOT
438 <!-- root_pwd selection -->
440 <fieldset>
441 <legend>$(_ 'Root superuser')</legend>
442 $(
443 label "root_pwd" \
444 "$(_ 'Root password:')" \
445 "$(_ 'Enter the password for root')"
446 error="$?"
447 input "text" \
448 "ROOT_PWD" \
449 "$root_pwd" \
450 "" \
451 "$(_ 'Password of root')"
452 error_msg "$error" \
453 "root_pwd"
454 )
455 </fieldset>
456 EOT
457 }
460 select_user_login() {
461 local user_login="$(/usr/sbin/tazinst get user_login "$INSTFILE")" error
463 cat <<EOT
464 <!-- user_login selection -->
466 <fieldset>
467 <legend>$(_ 'User')</legend>
468 $(
469 label "user_login" \
470 "$(_ 'User login:')" \
471 "$(_ 'Enter the name of the first user')"
472 error="$?"
473 input "text" \
474 "USER_LOGIN" \
475 "$user_login" \
476 "" \
477 "$(_ 'Name of the first user')"
478 error_msg "$error" \
479 "user_login" \
480 2
481 )
482 <br/>
483 EOT
484 }
487 select_user_pwd()
488 {
489 local user_pwd="$(/usr/sbin/tazinst get user_pwd "$INSTFILE")" error
491 label "user_pwd" \
492 "$(_ 'User password:')" \
493 "$(_ 'The password for default user')"
494 error="$?"
495 input "text" \
496 "USER_PWD" \
497 "$user_pwd" \
498 "" \
499 "$(_ 'Password of the first user')"
500 error_msg "$error" \
501 "user_pwd"
502 cat <<EOT
503 </fieldset>
504 EOT
505 }
508 select_bootloader()
509 {
510 local bootloader="$(/usr/sbin/tazinst get bootloader "$INSTFILE")" error
512 cat <<EOT
513 <!-- bootloader selection -->
515 <fieldset>
516 <legend>$(_ 'Bootloader')</legend>
518 $(
519 input "checkbox" \
520 "bootloader" \
521 "auto" \
522 "$bootloader"
523 label "bootloader" \
524 "$(_ 'Install a bootloader.')" \
525 "$(_ "Usually you should answer yes, unless you want to install \
526 a bootloader by hand yourself.")"
527 error="$?"
528 error_msg "$error" \
529 "bootloader"
530 )
531 <br/>
532 EOT
533 }
536 select_winboot()
537 {
538 local winboot="$(/usr/sbin/tazinst get winboot "$INSTFILE")" error
540 comment "winboot selection"
541 input "checkbox" \
542 "winboot" \
543 "auto" \
544 "$winboot"
545 label "winboot" \
546 "$(_ 'Enable Windows Dual-Boot.')" \
547 "$(_ "At start-up, you will be asked whether you want to boot \
548 into Windows&trade; or SliTaz GNU/Linux.")"
549 error="$?"
550 error_msg "$error" \
551 "winboot"
552 cat <<EOT
553 </fieldset>
554 EOT
555 }
558 errors_msg()
559 {
560 if [ "$CHECK" ]; then
561 echo '<span class="alert">'
562 p "$(_ "Errors found. Please check your settings.")"
563 echo '</span>'
564 fi
565 }
568 select_settings() {
569 local settings="$(/usr/sbin/tazinst get settings "$INSTFILE")"
570 CHECK=$(GET CHECK)
571 errors_msg
573 cat<<EOT
574 <fieldset>
575 <legend>$(_ 'Select source media:')</legend>
577 <div class="media">$(select_source)</div>
578 </fieldset>
581 <fieldset>
582 <legend>$(_ 'Select destination')</legend>
584 <div>$(
585 select_root_uuid
586 printf '%s' "$settings" | grep -q "root_format" && select_root_format
587 )</div>
588 </fieldset>
591 <fieldset id="options">
592 <legend>$(_ 'Options')</legend>
594 <div class="options">$(
595 printf '%s' "$settings" | grep -q "home_uuid" && select_home_uuid
596 printf '%s' "$settings" | grep -q "home_format" && select_home_format
597 printf '%s' "$settings" | grep -q "hostname" && select_hostname
598 printf '%s' "$settings" | grep -q "root_pwd" && select_root_pwd
599 printf '%s' "$settings" | grep -q "user_login" && select_user_login
600 printf '%s' "$settings" | grep -q "user_pwd" && select_user_pwd
601 )</div>
603 <div class="bootloader">$(
604 printf '%s' "$settings" | grep -q "bootloader" && select_bootloader
605 printf '%s' "$settings" | grep -q "winboot" && select_winboot
606 )</div>
607 </fieldset>
609 <br/>
610 EOT
611 }
614 #--------------
615 # execute page
616 #--------------
618 save_settings()
619 {
620 h5 "$(_ 'Checking settings...')"
622 # install type
623 /usr/sbin/tazinst set media "$(GET MEDIA)" "$INSTFILE"
625 # source File
626 case "$(/usr/sbin/tazinst get media "$INSTFILE")" in
627 usb)
628 /usr/sbin/tazinst set source "$(GET SRC_USB)" "$INSTFILE" ;;
629 iso)
630 /usr/sbin/tazinst set source "$(GET SRC_ISO)" "$INSTFILE" ;;
631 web)
632 /usr/sbin/tazinst set source "$(GET SRC_WEB)" "$INSTFILE" ;;
633 esac
635 # set defined url
636 [ $(GET URL) ] && SRC_WEB=$(GET URL)
638 # root Partition
639 /usr/sbin/tazinst set root_uuid "$(GET ROOT_UUID)" "$INSTFILE"
641 # format root partition
642 [ "$(GET ROOT_FORMAT)" ] \
643 && /usr/sbin/tazinst set root_format "$(GET ROOT_FORMAT)" "$INSTFILE" \
644 || /usr/sbin/tazinst unset root_format "$INSTFILE"
646 # home Partition
647 if [ "$(GET HOME_UUID)" ] ; then
648 /usr/sbin/tazinst set home_uuid "$(GET HOME_UUID)" "$INSTFILE"
649 [ "$(GET HOME_FORMAT)" ] \
650 && /usr/sbin/tazinst set home_format "$(GET HOME_FORMAT)" \
651 "$INSTFILE" \
652 || /usr/sbin/tazinst unset home_format "$INSTFILE"
653 else
654 /usr/sbin/tazinst unset home_uuid "$INSTFILE"
655 /usr/sbin/tazinst unset home_format "$INSTFILE"
656 fi
658 # hostname
659 /usr/sbin/tazinst set hostname "$(GET HOSTNAME)" "$INSTFILE"
661 # root pwd
662 /usr/sbin/tazinst set root_pwd "$(GET ROOT_PWD)" "$INSTFILE"
664 # user Login
665 /usr/sbin/tazinst set user_login "$(GET USER_LOGIN)" "$INSTFILE"
667 # user Pwd
668 /usr/sbin/tazinst set user_pwd "$(GET USER_PWD)" "$INSTFILE"
670 # win Dual-Boot
671 /usr/sbin/tazinst set winboot "$(GET WINBOOT)" "$INSTFILE"
673 # bootloader
674 if [ "$(GET BOOTLOADER)" == "auto" ]; then
675 /usr/sbin/tazinst set bootloader "auto" "$INSTFILE"
676 else
677 /usr/sbin/tazinst unset bootloader "$INSTFILE"
678 /usr/sbin/tazinst unset winboot "$INSTFILE"
679 fi
680 input_hidden "CHECK" "yes"
681 }
684 tazinst_run()
685 {
686 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")" error
687 h4 "$(_ 'Proceeding to: %s' "$(gettext "$mode")")"
688 /usr/sbin/tazinst execute "$INSTFILE" | /bin/busybox awk '{
689 num=$1+0
690 if (num>0 && num<=100){
691 print "<script type=\"text/javascript\">"
692 printf "document.write(\047<div id=\"progress\">"
693 printf "<img src=\"/styles/default/images/loader.gif\" />"
694 printf $1 "&#37; " substr($0, length($1)+2, 40)
695 print "</div>\047)"
696 print "</script>"
697 }
698 }'
699 # end_of_install
700 if /usr/sbin/tazinst log | grep -q "x-x-" ; then
701 error=1
702 echo "<script type=\"text/javascript\">"
703 printf "document.write(\047<div id=\"progress\">"
704 printf "<img src=\"/styles/default/images/stop.png\" />"
705 _n 'Errors encountered.'
706 printf "</div>\047)\n"
707 echo "</script>"
708 br
709 br
710 /usr/sbin/tazinst log | \
711 /bin/busybox awk '$1 == "-x-x-",$1 == "x-x-x"' | sed 's/-x-x-/ /' \
712 | grep -v "x-x-x"
713 else
714 error=0
715 echo "<script type=\"text/javascript\">"
716 printf "document.write(\047<div id=\"progress\">"
717 printf "<img src=\"/styles/default/images/tux.png\" />"
718 _n 'Process completed!'
719 printf "</div>\047)\n"
720 echo "</script>"
721 br
722 br
723 br
724 p $(_ "Installation is now finished, you can exit the installer \
725 or reboot on your new SliTaz GNU/Linux operating system.")
726 fi
727 return "$error"
729 }
732 tazinst_log()
733 {
734 h4 "$(_ "Tazinst log")"
735 printf '<pre>%s</pre>' "$(/usr/sbin/tazinst log | sed 's/\%/ percent/g')"
736 }
739 #-----------------
740 # page navigation
741 #-----------------
743 display_mode() {
744 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
745 case $mode in
746 install)
747 cat <<EOT
748 <h2>$(_ 'Install SliTaz')</h2>
750 <p>$(_ "You're going to install SliTaz on a partition of \
751 your hard disk drive. If you decide to format your HDD, all data will be \
752 lost. If you do not format, all data except for any existing /home \
753 directory will be removed (the home directory will be kept as is).")</p>
754 EOT
755 ;;
756 upgrade)
757 cat <<EOT
758 <h2>$(_ 'Upgrade SliTaz')</h2>
760 <p>$(_ "You're going to upgrade an already installed SliTaz \
761 system on your hard disk drive. Your /home /etc /var/www directories \
762 will be kept, all other directories will be removed. Any additional \
763 packages added to your old SliTaz system will be updated as long you \
764 have an active internet connection.")</p>
765 EOT
766 ;;
767 esac
768 }
771 moveto_page()
772 {
773 local back_page="$1" next_page="$2" back_msg next_msg
775 case "$back_page" in
776 partitioning)
777 back_msg=$(_ 'Back to partitioning') ;;
778 input)
779 back_msg=$(_ 'Back to entering settings') ;;
780 *)
781 back_msg=$(_ 'Back to Installer Start Page') ;;
782 esac
784 case "$next_page" in
785 execute|run)
786 next_msg=$(_ 'Proceed to SliTaz installation') ;;
787 reboot)
788 next_msg=$(_ 'Installation complete. You can now restart') ;;
789 failed)
790 next_msg=$(_ 'Installation failed. See log') ;;
791 input)
792 next_msg=$(_ 'Continue installation.') ;;
793 *)
794 next_msg=$(_ 'Back to Installer Start Page') ;;
795 esac
797 cat <<EOT
798 <hr/>
799 <form>
800 <button type="submit" name="page" value="$back_page" data-icon="back" >$back_msg</button>
801 <button type="submit" name="page" value="$next_page" data-icon="start">$next_msg</button>
802 </form>
803 EOT
804 }
807 moveto_home() {
808 cat <<EOT
809 <form>
810 <button type="submit" name="page" value="home" data-icon="back"
811 >$(_ 'Back to Installer Start Page')</button>
812 </form>
813 EOT
814 }
817 page_redirection() {
818 local page="$1"
819 cat <<EOT
820 HTTP/1.1 301 Moved Permanently
821 Location: $SCRIPT_NAME?page=$1
823 EOT
825 true || cat <<EOT
826 <!DOCTYPE html>
827 <html>
828 <head>
829 <meta charset="UTF-8">
830 <title>$(_ "A web page that points a browser to a different page after \
831 2 seconds")</title>
832 <meta http-equiv="refresh" content="0; URL=$SCRIPT_NAME?page=$1">
833 <meta name="keywords" content="automatic redirection">
834 </head>
835 <body>
836 <p>$(_ "If your browser doesn't automatically redirect within a few \
837 seconds, you may want to go there manually [here]" | \
838 sed "s|\[|<a href=\"?page=$page\">|; s|\]|</a>|")</p>
839 </body>
840 </html>
841 EOT
842 }
845 #----------
846 # checking
847 #----------
849 check_ressources() {
850 local errorcode=0 buffer=$(mktemp)
851 {
852 header; xhtml_header; comment "check_ressources"
853 } > $buffer
854 if ! [ -x /usr/sbin/tazinst ]; then
855 {
856 h4 $(_ 'Tazinst Error')
857 p $(_ '%s, the backend to %s is missing.' '<strong>tazinst</strong>' 'slitaz-installer';
858 _ 'Any installation can not be done without %s.' 'tazinst')
859 p $(_ "Check %s permissions, or reinstall the %s package." \
860 'tazinst' 'slitaz-installer')
861 } >> $buffer
862 errorcode=1
863 else
864 # check tazinst minimum version
865 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
866 r=$TAZINST_MINIMUM_VERSION
867 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
868 '{v=$v+0}{ if (v < r) exit 1}') ; then
869 {
870 h4 $(_ 'Tazinst Error')
871 p $(_ '%s, the %s backend, is not at the minimum required version.' \
872 '<strong>tazinst</strong>' 'slitaz-installer';
873 _ 'Any installation can not be done without %s.' 'tazinst')
874 p $(_ 'Reinstall the %s package, or use %s in CLI mode.' \
875 'slitaz-installer' 'tazinst')
876 } >> $buffer
877 errorcode=1
878 fi
879 # check tazinst maximum version
880 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
881 r=$TAZINST_MAXIMUM_VERSION
882 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
883 '{v=$v+0}{ if (v > r) exit 1}') ; then
884 {
885 h4 $(_ 'Tazinst Error')
886 p $(_ "%s, the %s backend, is at a higher version than the maximum authorized \
887 by the %s." '<strong>tazinst</strong>' 'slitaz-installer' 'slitaz-installer';
888 _ 'Any installation cannot be done.')
889 p $(_ 'Reinstall the %s package, or use %s in CLI mode.' \
890 'slitaz-installer' 'tazinst')
891 } >> $buffer
892 errorcode=1
893 fi
894 fi
895 [ "$errorcode" -eq 1 ] && cat $buffer
896 rm $buffer
897 return $errorcode
898 }
901 #---------------
902 # html snippets
903 #---------------
905 br() {
906 echo '<br />'
907 }
909 hr() {
910 echo '<hr />'
911 }
913 comment() {
914 printf '<!-- %s -->\n' "$@"
915 }
917 a() {
918 local page="$1" text="$2"
919 printf '<a class="button" value="%s" href="?page=%s">%s</a>\n' \
920 "$page" "$page" "$text"
921 }
923 button() {
924 local action="$1" msg="$2" title="$3"
925 printf '<a class="button" href="%s?page=%s" title="%s">%s</a>\n' \
926 "$SCRIPT_NAME" "$action" "$title" "$msg"
927 }
929 open_div() {
930 [ "$1" ] && printf '<div %s>\n' "$1" || echo '<div>'
931 }
933 close_div() {
934 echo '</div>'
935 }
937 p() {
938 printf '<p>%s</p>\n' "$@"
939 }
941 h4() {
942 printf '<h4>%s</h4>\n' "$@"
943 }
945 h5() {
946 printf '<h5>%s</h5>\n' "$@"
947 }
949 label() {
950 local setting="$1" label="$2" title="$3" name="$4" error=0
951 [ -z "$name" ] && name="$setting"
952 printf '<label for="%s"' "$name"
953 [ "$title" ] && printf ' title="%s">' "$title" || printf '%s' '>'
954 # display label in red in case of error
955 if [ "$CHECK" ]; then
956 /usr/sbin/tazinst check "$setting" "$INSTFILE"
957 error="$?"
958 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
959 printf '%s' '<span class="alert">'
960 printf '%s' "$label"
961 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
962 printf '%s' "<sup>*</sup></span>"
963 else
964 printf '%s' "$label"
965 fi
966 echo '</label>'
967 return "$error"
968 }
971 label_media() {
972 local id="$1" label="$2" media="$3" title="$4" retcode=0
973 if [ "$media" == "$id" ]; then
974 label "source" \
975 "$label" \
976 "$title" \
977 "$media"
978 retcode="$?"
979 else
980 printf '<label for="%s"' "$id"
981 [ "$title" ] && printf ' title="%s">' "$title" || echo '>'
982 echo "$label</label>"
983 fi
984 return "$retcode"
985 }
988 error_msg() {
989 local error="$1" setting="$2" line="$3"
990 if [ "$CHECK" ]; then
991 if [ "$error" -gt "0" ]; then
992 [ "$error" -lt "128" ] && printf '%s' '<span class="alert">' \
993 || printf '%s' '<span class="warning">'
994 if [ "$line" ]; then
995 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1 | \
996 /bin/busybox awk -v LINE="$line" '{if (NR==LINE){print}}'
997 else
998 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1
999 fi
1000 echo '</span>'
1001 fi
1002 fi
1006 select() {
1007 local list="$1" selected="$2" name="$3" type="$4"
1008 printf '%s' "$list" | \
1009 /bin/busybox awk -v SELECTED="$selected" -v NONE="$(_ 'None')" \
1010 -v NAME="$name" -v TYPE="$type" 'BEGIN{
1011 TYPE=TYPE+0
1012 print "<select name=\"" NAME "\">"
1013 print "<option value=>&lt; " NONE " &gt;</option>"
1016 printf "<option value=\"" $1 "\""
1017 if ($1 == SELECTED) printf " selected"
1018 if (TYPE == 0)
1019 print ">" $0 "</option>"
1020 if (TYPE == 1)
1021 print ">" substr($0,12) "</option>"
1022 if (TYPE == 2)
1023 print ">" $2 "</option>"
1025 END{
1026 print "</select>"
1027 }'
1030 input()
1032 local type="$1" name="$2" value="$3" selected="$4" help="$5" action="$6"
1033 printf '<input type="%s" id="%s" list="list_%s" ' "$type" "$name" "$name"
1034 printf 'name="%s" class="%s" ' "$(printf $name | tr [a-z] [A-Z])" "$type"
1035 [ "$value" ] && printf 'value="%s" ' "$value"
1036 [ "$value" == "$selected" ] && printf '%s' "checked "
1037 [ "$action" ] && printf \
1038 'onInput="document.getElementById(%s).checked = true;" ' "'$action'"
1039 [ "$help" ] && printf 'placeholder="%s" />\n' "$help" || echo "/>"
1042 input_media()
1044 local id="$1" media="$2"
1045 printf '<input type="radio" name="MEDIA" value="%s" id="%s" ' "$id" "$id"
1046 [ "$media" == "$id" ] && echo 'checked />' || echo '/>'
1049 input_hidden()
1051 local name="$1" value="$2"
1052 printf '<input type="hidden" name="%s" value="%s" />\n' "$name" "$value"
1055 datalist()
1057 local list="$1" name="$2"
1058 printf '<datalist id="list_%s">\n' "$name"
1059 # workaround for browsers that don’t support the datalist element..
1060 local script="displaySelValue(\"select_$name\",\"$name\")"
1061 printf '<select class="workaround" id="select_%s" ' "$name"
1062 printf "onChange='%s' onBlur='%s'>\n" "$script" "$script"
1064 # workaround ..end
1065 printf '%s' "$list" | \
1066 /bin/busybox awk -v NONE="$(_ 'None')" 'BEGIN{
1067 line=0
1070 TEXT=$1
1071 sub(".*/","",TEXT)
1072 printf "<option value=\"%s\">%s</option>\n", $1, TEXT
1073 line++
1075 END{
1076 if (line < 1)
1077 printf "<option value=>&lt; %s &gt;</option>\n", NONE
1078 }'
1079 echo "</select>"
1080 echo "</datalist>"
1083 format()
1085 list_fs="$1" selected="$2" name="$3" none="$(_ 'Do not format')"
1086 printf '<label for="%s" ' "$name"
1087 printf 'title="%s">' "$(_ "To format this partition, select a \
1088 filesystem, usually it's safe to use ext4")"
1089 printf '%s</label>\n' "$(_ 'Formatting option:')"
1090 printf '%s' "$list_fs" | \
1091 /bin/busybox awk -v SELECTED=$selected -v NONE="$none" -v NAME="$name" '
1092 BEGIN{
1093 RS=" "
1094 print "<select name=\"" NAME "\">"
1095 print "<option value=\"\">" NONE "</option>"
1096 line=0
1099 printf "<option value=\"" $1 "\""
1100 if ($1 == SELECTED) printf " selected"
1101 print ">" $0 "</option>"
1102 line++
1104 END{
1105 if (line < 1)
1106 print "<option value=>< " NONE " ></option>"
1107 print "</select>"
1108 }'
1111 form_start()
1113 printf '<form name="%s" method="get" ' "Form"
1114 printf 'onsubmit="return true" action="%s">\n' "$SCRIPT_NAME"
1117 form_end()
1119 echo '</form>'
1122 add_style()
1124 printf '<!-- add specific styles -->
1125 <style type="text/css">
1126 section label {
1127 display:inline-block;
1128 vertical-align:middle;
1129 width: 130px;
1131 .media label {
1132 display:inline-block;
1133 vertical-align:middle;
1134 width: 110px;
1136 .options label {
1137 display:inline-block;
1138 vertical-align:middle;
1139 width: 140px;
1141 .text {
1142 width: 350px;
1144 input {margin-bottom:3px;}
1145 span.alert {color: red}
1146 span.warning { color: darkgray}
1147 #progress {
1148 background-color: #f8f8f8;
1149 border: 1px solid #ddd;
1150 color: #666;
1151 cursor: progress;
1152 position: absolute;
1153 width: 348px;
1154 padding: 4px 4px 2px;
1156 </style>
1157 <!-- workaround for browsers that do not support the datalist element -->
1158 <style type="text/css">
1159 .workaround {width: 110px;}
1160 </style>
1161 <script>
1162 function displaySelValue(selectId,inputId)
1164 var slct = document.getElementById(selectId);
1165 var input = document.getElementById(inputId);
1166 document.getElementById("src_iso").value="";
1167 document.getElementById("src_web").value="";
1168 if (inputId =="src_iso"){
1169 document.getElementById("iso").checked = true;
1171 if (inputId =="src_web"){
1172 document.getElementById("web").checked = true;
1174 input.value = slct.options[slct.selectedIndex].value;
1176 </script>
1177 <!-- datalist workaround end -->
1178 \n'
1183 # main
1186 case "$(GET page)" in
1187 home)
1188 header; xhtml_header
1189 select_action
1190 select_install
1191 select_upgrade
1192 select_evaluate
1193 ;;
1194 evaluate)
1195 header; xhtml_header
1196 select_evaluate
1197 ;;
1198 install)
1199 /usr/sbin/tazinst set mode install "$INSTFILE"
1200 page_redirection partitioning
1201 ;;
1202 partitioning)
1203 header; xhtml_header
1204 form_start
1205 display_mode
1206 select_gparted
1207 moveto_page home input
1208 form_end
1209 ;;
1210 gparted)
1211 exec_gparted
1212 page_redirection partitioning
1213 ;;
1214 upgrade)
1215 /usr/sbin/tazinst set mode upgrade "$INSTFILE"
1216 page_redirection input
1217 ;;
1218 input)
1219 header; xhtml_header
1220 add_style
1221 form_start
1222 display_mode
1223 select_settings
1224 moveto_page home execute
1225 form_end
1226 ;;
1227 execute)
1228 buffer=$(mktemp)
1230 header; xhtml_header
1231 form_start
1232 display_mode
1233 save_settings
1234 } > $buffer
1235 if ! (/usr/sbin/tazinst check all $INSTFILE > /dev/null); then
1236 rm $buffer
1237 page_redirection "input&CHECK=yes"
1238 else
1239 cat $buffer; rm $buffer
1240 if tazinst_run; then
1241 moveto_page home reboot
1242 else
1243 moveto_page input failed
1244 fi
1245 fi
1246 form_end
1247 ;;
1248 reboot)
1249 /usr/sbin/tazinst clean "$INSTFILE"
1250 reboot ;;
1251 failed)
1252 header; xhtml_header
1253 form_start
1254 tazinst_log
1255 moveto_home
1256 form_end
1257 ;;
1258 *)
1259 if check_ressources; then
1260 /usr/sbin/tazinst new "$INSTFILE"
1261 page_redirection home
1262 fi
1263 ;;
1264 esac
1266 xhtml_footer
1268 exit 0