tazinst view installer.cgi @ rev 71

Rollback edit
author Paul Issott <paul@slitaz.org>
date Tue Apr 05 19:04:43 2016 +0100 (2016-04-05)
parents 5a132e85bdd6
children 7877ddbcbdbe
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for Tazinst, the SliTaz installer.
4 #
5 # Copyright (C) 2012-2016 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=$(gettext '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>$(gettext 'Installation')</span>
43 <menu>
44 <li><a data-icon="install"
45 href="installer.cgi" data-root>$(gettext 'Installation')</a></li>
46 <li><a data-icon="slitaz"
47 href="installer.cgi?page=install" data-root>$(gettext 'Install SliTaz')</a></li>
48 <li><a data-icon="upgrade"
49 href="installer.cgi?page=upgrade" data-root>$(gettext 'Upgrade system')</a></li>
50 <li><a data-icon="slitaz"
51 href="installer.cgi?page=evaluate" data-root>$(gettext '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>$(gettext "Welcome to the SliTaz Installer!")</h2>
69 <p>$(gettext "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>$(gettext "Windows&trade; users can evaluate SliTaz in the directory \
74 \\slitaz on their hard disk.")</p>
76 <p>$(gettext "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>$(gettext 'Install')</header>
88 <div>
89 <p>$(gettext "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>$(gettext "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 name="page" value="install" data-icon="slitaz"
101 title="$(gettext 'Proceed to a new SliTaz installation')"
102 >$(gettext '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>$(gettext 'Upgrade')</header>
117 <div>
118 <p>$(gettext "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 name="page" value="upgrade" data-icon="upgrade"
127 title="$(gettext 'Upgrade an existing SliTaz system')"
128 >$(gettext '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>$(gettext "Evaluate:") $(gettext "Without Partitioning / Formating")</header>
143 <div>
144 <p>$(gettext "SliTaz and Windows&trade; can coexist in the same partition.")</p>
145 <p>$(gettext "SliTaz will be in the \slitaz directory like UMSDOS did \
146 in the previous century...")</p>
147 </div>
149 <footer>
150 <form action="boot.cgi">
151 <input type="hidden" name="iso"/>
152 <input type="hidden" name="action" value="install"/>
153 <table>
154 <tr><td>$(gettext 'ISO image file full path')
155 <span data-img="info" title="$(gettext 'set /dev/cdrom for a physical CD-ROM')"></span>
156 </td>
157 <td>$(file_chooser "iso" "")</td></tr>
158 <tr><td>$(gettext 'Target partition')</td>
159 <td><select name="instdev">
160 <option value="/dev/null">$(gettext 'Choose a partition')</option>
161 EOT
162 blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | \
163 sed -e 's|[A-Z]*ID="[^"]*"||g;s| SEC[^ ]*||;s|LABEL=||;s|:||' \
164 -e 's|TYPE="\([^"]*\)"|\1|;s|/dev/||' | \
165 while read dev label type; do
166 echo -n "<option value=\"/dev/$dev\">/dev/$dev $label $type "
167 echo "$(blk2h < /sys/block/${dev:0:3}/$dev/size)</option>"
168 done
169 cat <<EOT
170 </select></td></tr>
171 </table>
172 <button data-icon="install">$(gettext 'Install')</button>
173 </form>
174 </footer>
175 </section>
176 EOT
177 }
180 #--------------------
181 # partitioning page
182 #--------------------
184 exec_gparted() {
185 /bin/su - -c \
186 "exec env DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' /usr/sbin/gparted"
187 }
190 select_gparted() {
191 cat <<EOT
192 <!-- GParted message -->
194 <section>
195 <header>$(gettext "Partitioning")</header>
197 <div>
198 <p>$(gettext "On most used systems, the hard drive is already dedicated to \
199 partitions for Windows&trade;, or Linux, or another operating \
200 system. You'll need to resize these partitions in order to make space for \
201 SliTaz GNU/Linux. SliTaz will co-exist with other operating systems already \
202 installed on your hard drive.")</p>
203 <p>$(gettext "The amount of space needed depends on how much software you \
204 plan to install and how much space you require for users. It's conceivable \
205 that you could run a minimal SliTaz system in 300 megs or less, but 2 gigs \
206 is indeed more comfy.")</p>
207 <p>$(gettext "A separate home partition and a partition that will be used \
208 as Linux swap space may be created if needed. SliTaz detects and uses swap \
209 partitions automatically.")</p>
210 <hr/>
211 <p>$(gettext "You can graphically manage your partitions with GParted. \
212 GParted is a partition editor for graphically managing your disk partitions. \
213 GParted allows you to create, destroy, resize and copy partitions without \
214 data loss.")</p>
215 <p>$(gettext "GParted supports ext2, ext3, ext4, linux swap, ntfs and \
216 fat32 filesystems right out of the box. Support for xjs, jfs, hfs and other \
217 filesystems is available as well but you first need to add drivers for these \
218 filesystems by installing the related packages xfsprogs, jfsutils, linux-hfs \
219 and so on.")</p>
220 </div>
222 <footer>
223 <!-- Launch GParted -->
224 <form>
225 <button name="page" value="gparted" data-icon="hdd"
226 title="$(gettext 'Launch GParted, the partition editor tool')"
227 >$(gettext 'Execute GParted')</button>
228 </form>
229 </footer>
230 </section>
232 <h5>$(gettext "Continue installation")</h5>
234 <p>$(gettext "Once you've made room for SliTaz on your drive, you should \
235 be able to continue installation.")</p>
236 EOT
237 }
240 #------------
241 # input page
242 #------------
244 select_source() {
245 local media="$(/usr/sbin/tazinst get media "$INSTFILE")"
246 local source="$(/usr/sbin/tazinst get source "$INSTFILE")"
247 local list_media="$(/usr/sbin/tazinst list media)"
248 local error
250 # set default media
251 [ "$media" ] || media="$(tazinst list media | cut -d ' ' -f1)"
253 comment "Source selection"
254 # cdrom
255 if printf '%s' "$list_media" | grep -q "cdrom"; then
256 input_media "cdrom" \
257 "$media"
258 label_media "cdrom" \
259 "$(gettext 'LiveCD')" \
260 "$media" \
261 "$(gettext 'Use the SliTaz LiveCD')"
262 br
263 fi
264 # usb
265 if printf '%s' "$list_media" | grep -q "usb"; then
266 input_media "usb" \
267 "$media"
268 label_media "usb" \
269 "$(gettext 'LiveUSB:')" \
270 "$media" \
271 "$(gettext 'Enter the partition where SliTaz Live is located on
272 your USB Key')"
273 error="$?"
274 select "$(/usr/sbin/tazinst list usb "$INSTFILE" | cut -d' ' -f2)" \
275 "$source" \
276 "SRC_USB"
277 error_msg "$error" \
278 "source" \
279 2
280 br
281 fi
282 # iso
283 input_media "iso" \
284 "$media"
285 label_media "iso" \
286 "$(gettext 'ISO file:')" \
287 "$media" \
288 "$(gettext 'Select a SliTaz ISO file located on a local disk')"
289 error="$?"
290 if [ "$media" == "iso" ]; then
291 input "text" \
292 "src_iso" \
293 "$source" "" \
294 "$(gettext 'Select an ISO or enter the full path to the ISO file')"\
295 "iso"
296 else
297 input "text" \
298 "src_iso" \
299 "" \
300 "none" \
301 "$(gettext 'Select an ISO or enter the full path to the ISO file')"\
302 "iso"
303 fi
304 datalist "$(/usr/sbin/tazinst list iso "$INSTFILE")" \
305 "src_iso"
306 error_msg "$error" \
307 "source"
308 br
309 # web
310 input_media "web" \
311 "$media"
312 label_media "web" \
313 "$(gettext 'Web:')" \
314 "$media" \
315 "$(gettext 'Select a SliTaz version on the Web')"
316 error="$?"
318 if [ "$media" == "web" ]; then
319 input "text" \
320 "src_web" \
321 "$source" "" \
322 "$(gettext 'Select a version or enter the full url to an ISO file')"\
323 "web"
324 else
325 input "text" \
326 "src_web" \
327 "" \
328 "none" \
329 "$(gettext 'Select a version or enter the full url to an ISO file')"\
330 "web"
331 fi
332 datalist "$(/usr/sbin/tazinst help web "$INSTFILE")" \
333 "src_web"
334 error_msg "$error" \
335 "source"
336 }
338 select_root_uuid()
339 {
340 local root_uuid="$(/usr/sbin/tazinst get root_uuid "$INSTFILE")"
341 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
342 comment "root_uuid selection"
343 if [ "$mode" == "upgrade" ]; then
344 label "root_uuid" \
345 "$(gettext 'Existing SliTaz partition to upgrade:')" \
346 "$(gettext 'Specify the partition containing the system to upgrade')"
347 error="$?"
348 else
349 label "root_uuid" \
350 "$(gettext 'Install SliTaz to partition:')" \
351 "$(gettext 'Specify the partition where to install SliTaz')"
352 error="$?"
353 fi
354 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
355 "$root_uuid" \
356 "ROOT_UUID" \
357 0
358 error_msg "$error" \
359 "root_uuid" \
360 0
361 br
362 }
364 select_root_format()
365 {
366 local root_format="$(/usr/sbin/tazinst get root_format "$INSTFILE")"
367 comment "root_format selection"
368 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
369 "$root_format" \
370 "ROOT_FORMAT"
371 }
373 select_home_uuid() {
374 local home_uuid="$(/usr/sbin/tazinst get home_uuid "$INSTFILE")"
376 cat <<EOT
377 <!-- home_uuid selection -->
379 <fieldset>
380 <legend>$(gettext "home partition")</legend>
382 $(
383 label "home_uuid" \
384 "$(gettext 'Separate partition for /home:')" \
385 "$(gettext 'Specify the partition containing /home')"
386 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
387 "$home_uuid" \
388 "HOME_UUID" \
389 0
390 )
391 <br/>
392 EOT
393 }
395 select_home_format()
396 {
397 local home_format="$(/usr/sbin/tazinst get home_format "$INSTFILE")"
399 comment "home_format selection"
400 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
401 "$home_format" \
402 "HOME_FORMAT"
403 cat <<EOT
404 </fieldset>
405 EOT
406 }
409 select_hostname() {
410 local hostname="$(/usr/sbin/tazinst get hostname "$INSTFILE")" error
412 cat <<EOT
413 <!-- hostname selection -->
415 <fieldset>
416 <legend>$(gettext "Hostname")</legend>
417 $(
418 label "hostname" \
419 "$(gettext 'Set Hostname to:')" \
420 "$(gettext 'Hostname configuration allows you to specify the machine name')"
421 error=$?
422 input "text" \
423 "HOSTNAME" \
424 "$hostname" \
425 "" \
426 "$(gettext 'Name of your system')"
427 error_msg "$error" \
428 "hostname" \
429 2
430 )
431 </fieldset>
432 EOT
433 }
436 select_root_pwd() {
437 local root_pwd="$(/usr/sbin/tazinst get root_pwd "$INSTFILE")" error
439 cat <<EOT
440 <!-- root_pwd selection -->
442 <fieldset>
443 <legend>$(gettext "Root superuser")</legend>
444 $(
445 label "root_pwd" \
446 "$(gettext 'Root passwd:')" \
447 "$(gettext 'Enter the password for root')"
448 error="$?"
449 input "text" \
450 "ROOT_PWD" \
451 "$root_pwd" \
452 "" \
453 "$(gettext 'Password of root')"
454 error_msg "$error" \
455 "root_pwd"
456 )
457 </fieldset>
458 EOT
459 }
462 select_user_login() {
463 local user_login="$(/usr/sbin/tazinst get user_login "$INSTFILE")" error
465 cat <<EOT
466 <!-- user_login selection -->
468 <fieldset>
469 <legend>$(gettext "User")</legend>
470 $(
471 label "user_login" \
472 "$(gettext 'User login:')" \
473 "$(gettext 'Enter the name of the first user')"
474 error="$?"
475 input "text" \
476 "USER_LOGIN" \
477 "$user_login" \
478 "" \
479 "$(gettext 'Name of the first user')"
480 error_msg "$error" \
481 "user_login" \
482 2
483 )
484 <br/>
485 EOT
486 }
489 select_user_pwd()
490 {
491 local user_pwd="$(/usr/sbin/tazinst get user_pwd "$INSTFILE")" error
493 label "user_pwd" \
494 "$(gettext 'User passwd:')" \
495 "$(gettext 'The password for default user')"
496 error="$?"
497 input "text" \
498 "USER_PWD" \
499 "$user_pwd" \
500 "" \
501 "$(gettext 'Password of the first user')"
502 error_msg "$error" \
503 "user_pwd"
504 cat <<EOT
505 </fieldset>
506 EOT
507 }
510 select_bootloader()
511 {
512 local bootloader="$(/usr/sbin/tazinst get bootloader "$INSTFILE")" error
514 cat <<EOT
515 <!-- bootloader selection -->
517 <fieldset>
518 <legend>$(gettext "Bootloader")</legend>
520 $(
521 input "checkbox" \
522 "bootloader" \
523 "auto" \
524 "$bootloader"
525 label "bootloader" \
526 "$(gettext 'Install a bootloader.')" \
527 "$(gettext "Usually you should answer yes, unless you want to install \
528 a bootloader by hand yourself.")"
529 error="$?"
530 error_msg "$error" \
531 "bootloader"
532 )
533 <br/>
534 EOT
535 }
538 select_winboot()
539 {
540 local winboot="$(/usr/sbin/tazinst get winboot "$INSTFILE")" error
542 comment "winboot selection"
543 input "checkbox" \
544 "winboot" \
545 "auto" \
546 "$winboot"
547 label "winboot" \
548 "$(gettext 'Enable Windows Dual-Boot.')" \
549 "$(gettext "At start-up, you will be asked whether you want to boot \
550 into Windows&trade; or SliTaz GNU/Linux.")"
551 error="$?"
552 error_msg "$error" \
553 "winboot"
554 cat <<EOT
555 </fieldset>
556 EOT
557 }
560 errors_msg()
561 {
562 if [ "$CHECK" ]; then
563 echo '<span class="alert">'
564 p "$(gettext "Errors found. Please check your settings.")"
565 echo '</span>'
566 fi
567 }
570 select_settings() {
571 local settings="$(/usr/sbin/tazinst get settings "$INSTFILE")"
572 CHECK=$(GET CHECK)
573 errors_msg
575 cat<<EOT
576 <fieldset>
577 <legend>$(gettext "Select source media:")</legend>
579 <div class="media">$(select_source)</div>
580 </fieldset>
583 <fieldset>
584 <legend>$(gettext "Select destination")</legend>
586 <div>$(
587 select_root_uuid
588 printf '%s' "$settings" | grep -q "root_format" && select_root_format
589 )</div>
590 </fieldset>
593 <fieldset id="options">
594 <legend>$(gettext 'Options')</legend>
596 <div class="options">$(
597 printf '%s' "$settings" | grep -q "home_uuid" && select_home_uuid
598 printf '%s' "$settings" | grep -q "home_format" && select_home_format
599 printf '%s' "$settings" | grep -q "hostname" && select_hostname
600 printf '%s' "$settings" | grep -q "root_pwd" && select_root_pwd
601 printf '%s' "$settings" | grep -q "user_login" && select_user_login
602 printf '%s' "$settings" | grep -q "user_pwd" && select_user_pwd
603 )</div>
605 <div class="bootloader">$(
606 printf '%s' "$settings" | grep -q "bootloader" && select_bootloader
607 printf '%s' "$settings" | grep -q "winboot" && select_winboot
608 )</div>
609 </fieldset>
611 <br/>
612 EOT
613 }
616 #--------------
617 # execute page
618 #--------------
620 save_settings()
621 {
622 h5 "$(gettext "Checking settings...")"
624 # install type
625 /usr/sbin/tazinst set media "$(GET MEDIA)" "$INSTFILE"
627 # source File
628 case "$(/usr/sbin/tazinst get media "$INSTFILE")" in
629 usb)
630 /usr/sbin/tazinst set source "$(GET SRC_USB)" "$INSTFILE" ;;
631 iso)
632 /usr/sbin/tazinst set source "$(GET SRC_ISO)" "$INSTFILE" ;;
633 web)
634 /usr/sbin/tazinst set source "$(GET SRC_WEB)" "$INSTFILE" ;;
635 esac
637 # set defined url
638 [ $(GET URL) ] && SRC_WEB=$(GET URL)
640 # root Partition
641 /usr/sbin/tazinst set root_uuid "$(GET ROOT_UUID)" "$INSTFILE"
643 # format root partition
644 [ "$(GET ROOT_FORMAT)" ] \
645 && /usr/sbin/tazinst set root_format "$(GET ROOT_FORMAT)" "$INSTFILE" \
646 || /usr/sbin/tazinst unset root_format "$INSTFILE"
648 # home Partition
649 if [ "$(GET HOME_UUID)" ] ; then
650 /usr/sbin/tazinst set home_uuid "$(GET HOME_UUID)" "$INSTFILE"
651 [ "$(GET HOME_FORMAT)" ] \
652 && /usr/sbin/tazinst set home_format "$(GET HOME_FORMAT)" \
653 "$INSTFILE" \
654 || /usr/sbin/tazinst unset home_format "$INSTFILE"
655 else
656 /usr/sbin/tazinst unset home_uuid "$INSTFILE"
657 /usr/sbin/tazinst unset home_format "$INSTFILE"
658 fi
660 # hostname
661 /usr/sbin/tazinst set hostname "$(GET HOSTNAME)" "$INSTFILE"
663 # root pwd
664 /usr/sbin/tazinst set root_pwd "$(GET ROOT_PWD)" "$INSTFILE"
666 # user Login
667 /usr/sbin/tazinst set user_login "$(GET USER_LOGIN)" "$INSTFILE"
669 # user Pwd
670 /usr/sbin/tazinst set user_pwd "$(GET USER_PWD)" "$INSTFILE"
672 # win Dual-Boot
673 /usr/sbin/tazinst set winboot "$(GET WINBOOT)" "$INSTFILE"
675 # bootloader
676 if [ "$(GET BOOTLOADER)" == "auto" ]; then
677 /usr/sbin/tazinst set bootloader "auto" "$INSTFILE"
678 else
679 /usr/sbin/tazinst unset bootloader "$INSTFILE"
680 /usr/sbin/tazinst unset winboot "$INSTFILE"
681 fi
682 input_hidden "CHECK" "yes"
683 }
686 tazinst_run()
687 {
688 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")" error
689 h4 "$(gettext 'Proceeding to:') $(gettext "$mode")"
690 /usr/sbin/tazinst execute "$INSTFILE" | /bin/busybox awk '{
691 num=$1+0
692 if (num>0 && num<=100){
693 print "<script type=\"text/javascript\">"
694 printf "document.write(\047<div id=\"progress\">"
695 printf "<img src=\"/styles/default/images/loader.gif\" />"
696 printf $1 "&#37; " substr($0, length($1)+2, 40)
697 print "</div>\047)"
698 print "</script>"
699 }
700 }'
701 # end_of_install
702 if /usr/sbin/tazinst log | grep -q "x-x-" ; then
703 error=1
704 echo "<script type=\"text/javascript\">"
705 printf "document.write(\047<div id=\"progress\">"
706 printf "<img src=\"/styles/default/images/stop.png\" />"
707 printf "$(gettext 'Errors encountered.')"
708 printf "</div>\047)\n"
709 echo "</script>"
710 br
711 br
712 /usr/sbin/tazinst log | \
713 /bin/busybox awk '$1 == "-x-x-",$1 == "x-x-x"' | sed 's/-x-x-/ /' \
714 | grep -v "x-x-x"
715 else
716 error=0
717 echo "<script type=\"text/javascript\">"
718 printf "document.write(\047<div id=\"progress\">"
719 printf "<img src=\"/styles/default/images/tux.png\" />"
720 printf "$(gettext 'Process completed!')"
721 printf "</div>\047)\n"
722 echo "</script>"
723 br
724 br
725 br
726 p $(gettext "Installation is now finished, you can exit the installer \
727 or reboot on your new SliTaz GNU/Linux operating system.")
728 fi
729 return "$error"
731 }
734 tazinst_log()
735 {
736 h4 "$(gettext "Tazinst log")"
737 printf '<pre>%s</pre>' "$(/usr/sbin/tazinst log | sed 's/\%/ percent/g')"
738 }
741 #-----------------
742 # page navigation
743 #-----------------
745 display_mode() {
746 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
747 case $mode in
748 install)
749 cat <<EOT
750 <h2>$(gettext "Install SliTaz")</h2>
752 <p>$(gettext "You're going to install SliTaz on a partition of \
753 your hard disk drive. If you decide to format your HDD, all data will be \
754 lost. If you do not format, all data except for any existing /home \
755 directory will be removed (the home directory will be kept as is).")</p>
756 EOT
757 ;;
758 upgrade)
759 cat <<EOT
760 <h2>$(gettext "Upgrade SliTaz")</h2>
762 <p>$(gettext "You're going to upgrade an already installed SliTaz \
763 system on your hard disk drive. Your /home /etc /var/www directories \
764 will be kept, all other directories will be removed. Any additional \
765 packages added to your old SliTaz system will be updated as long you \
766 have an active internet connection.")</p>
767 EOT
768 ;;
769 esac
770 }
773 moveto_page()
774 {
775 local back_page="$1" next_page="$2" back_msg next_msg
777 case "$back_page" in
778 partitioning)
779 back_msg=$(gettext 'Back to partitioning') ;;
780 input)
781 back_msg=$(gettext 'Back to entering settings') ;;
782 *)
783 back_msg=$(gettext 'Back to Installer Start Page') ;;
784 esac
786 case "$next_page" in
787 execute|run)
788 next_msg=$(gettext 'Proceed to SliTaz installation') ;;
789 reboot)
790 next_msg=$(gettext 'Installation complete. You can now restart') ;;
791 failed)
792 next_msg=$(gettext 'Installation failed. See log') ;;
793 input)
794 next_msg=$(gettext 'Continue installation.') ;;
795 *)
796 next_msg=$(gettext 'Back to Installer Start Page') ;;
797 esac
799 cat <<EOT
800 <hr/>
801 <form>
802 <button name="page" value="$back_page" data-icon="back" >$back_msg</button>
803 <button name="page" value="$next_page" data-icon="start">$next_msg</button>
804 </form>
805 EOT
806 }
809 moveto_home() {
810 cat <<EOT
811 <form>
812 <button name="page" value="home" data-icon="back"
813 >$(gettext 'Back to Installer Start Page')</button>
814 </form>
815 EOT
816 }
819 page_redirection() {
820 local page="$1"
821 cat <<EOT
822 <!DOCTYPE html>
823 <html>
824 <head>
825 <meta charset="UTF-8">
826 <title>$(gettext "A web page that points a browser to a different page after \
827 2 seconds")</title>
828 <meta http-equiv="refresh" content="0; URL=$SCRIPT_NAME?page=$1">
829 <meta name="keywords" content="automatic redirection">
830 </head>
831 <body>
832 <p>$(gettext "If your browser doesn't automatically redirect within a few \
833 seconds, you may want to go there manually")
834 <a href="$SCRIPT_NAME?page=$page">$(gettext "here")</a></p>
835 </body>
836 </html>
837 EOT
838 }
841 #----------
842 # checking
843 #----------
845 check_ressources() {
846 local errorcode=0
847 comment "check_ressources"
848 if ! [ -x /usr/sbin/tazinst ] ; then
849 h4 $(gettext "Tazinst Error")
850 p $(gettext "<strong>tazinst</strong>, the backend to slitaz-installer \
851 is missing. Any installation can not be done without tazinst.")
852 p $(gettext "Check tazinst permissions, or reinstall the \
853 slitaz-installer package.")
854 errorcode=1
855 else
856 # check tazinst minimum version
857 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
858 r=$TAZINST_MINIMUM_VERSION
859 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
860 '{v=$v+0}{ if (v < r) exit 1}') ; then
861 h4 $(gettext "Tazinst Error")
862 p $(gettext "<strong>tazinst</strong>, the slitaz-installer \
863 backend, is not at the minimum required version. Any installation \
864 cannot be done without tazinst.")
865 p $(gettext "Reinstall the slitaz-installer package, or use \
866 tazinst in CLI mode.")
867 errorcode=1
868 fi
869 # check tazinst maximum version
870 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
871 r=$TAZINST_MAXIMUM_VERSION
872 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
873 '{v=$v+0}{ if (v > r) exit 1}') ; then
874 h4 $(gettext "Tazinst Error")
875 p $(gettext "<strong>tazinst</strong>, the slitaz-installer \
876 backend, is at a higher version than the maximum authorized \
877 by the slitaz-installer. Any installation cannot be done.")
878 p $(gettext "Reinstall the slitaz-installer package, or use \
879 tazinst in CLI mode.")
880 errorcode=1
881 fi
882 fi
883 return $errorcode
884 }
887 #---------------
888 # html snippets
889 #---------------
891 br() {
892 echo '<br />'
893 }
895 hr() {
896 echo '<hr />'
897 }
899 comment() {
900 printf '<!-- %s -->\n' "$@"
901 }
903 a() {
904 local page="$1" text="$2"
905 printf '<a class="button" value="%s" href="%s?page=%s">%s</a>\n' \
906 "$page" "$SCRIPT_NAME" "$page" "$text"
907 }
909 button() {
910 local action="$1" msg="$2" title="$3"
911 printf '<a class="button" href="%s?page=%s" title="%s">%s</a>\n' \
912 "$SCRIPT_NAME" "$action" "$title" "$msg"
913 }
915 open_div() {
916 [ "$1" ] && printf '<div %s>\n' "$1" || echo '<div>'
917 }
919 close_div() {
920 echo '</div>'
921 }
923 p() {
924 printf '<p>%s</p>\n' "$@"
925 }
927 h4() {
928 printf '<h4>%s</h4>\n' "$@"
929 }
931 h5() {
932 printf '<h5>%s</h5>\n' "$@"
933 }
935 label() {
936 local setting="$1" label="$2" title="$3" name="$4" error=0
937 [ -z "$name" ] && name="$setting"
938 printf '<label for="%s"' "$name"
939 [ "$title" ] && printf ' title="%s">' "$title" || printf '%s' '>'
940 # display label in red in case of error
941 if [ "$CHECK" ]; then
942 /usr/sbin/tazinst check "$setting" "$INSTFILE"
943 error="$?"
944 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
945 printf '%s' '<span class="alert">'
946 printf '%s' "$label"
947 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
948 printf '%s' "<sup>*</sup></span>"
949 else
950 printf '%s' "$label"
951 fi
952 echo '</label>'
953 return "$error"
954 }
957 label_media() {
958 local id="$1" label="$2" media="$3" title="$4" retcode=0
959 if [ "$media" == "$id" ]; then
960 label "source" \
961 "$label" \
962 "$title" \
963 "$media"
964 retcode="$?"
965 else
966 printf '<label for="%s"' "$id"
967 [ "$title" ] && printf ' title="%s">' "$title" || echo '>'
968 echo "$label</label>"
969 fi
970 return "$retcode"
971 }
974 error_msg() {
975 local error="$1" setting="$2" line="$3"
976 if [ "$CHECK" ]; then
977 if [ "$error" -gt "0" ]; then
978 [ "$error" -lt "128" ] && printf '%s' '<span class="alert">' \
979 || printf '%s' '<span class="warning">'
980 if [ "$line" ]; then
981 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1 | \
982 /bin/busybox awk -v LINE="$line" '{if (NR==LINE){print}}'
983 else
984 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1
985 fi
986 echo '</span>'
987 fi
988 fi
989 }
992 select() {
993 local list="$1" selected="$2" name="$3" type="$4"
994 printf '%s' "$list" | \
995 /bin/busybox awk -v SELECTED="$selected" -v NONE="$(gettext "None")" \
996 -v NAME="$name" -v TYPE="$type" 'BEGIN{
997 TYPE=TYPE+0
998 print "<select name=\"" NAME "\">"
999 print "<option value=>< " NONE " ></option>"
1002 printf "<option value=\"" $1 "\""
1003 if ($1 == SELECTED) printf " selected"
1004 if (TYPE == 0)
1005 print ">" $0 "</option>"
1006 if (TYPE == 1)
1007 print ">" substr($0,12) "</option>"
1008 if (TYPE == 2)
1009 print ">" $2 "</option>"
1011 END{
1012 print "</select>"
1013 }'
1016 input()
1018 local type="$1" name="$2" value="$3" selected="$4" help="$5" action="$6"
1019 printf '<input type="%s" id="%s" list="list_%s" ' "$type" "$name" "$name"
1020 printf 'name="%s" class="%s" ' "$(printf $name | tr [a-z] [A-Z])" "$type"
1021 [ "$value" ] && printf 'value="%s" ' "$value"
1022 [ "$value" == "$selected" ] && printf '%s' "checked "
1023 [ "$action" ] && printf \
1024 'onInput="document.getElementById(%s).checked = true;" ' "'$action'"
1025 [ "$help" ] && printf 'placeholder="%s" />\n' "$help" || echo "/>"
1028 input_media()
1030 local id="$1" media="$2"
1031 printf '<input type="radio" name="MEDIA" value="%s" id="%s" ' "$id" "$id"
1032 [ "$media" == "$id" ] && echo 'checked />' || echo '/>'
1035 input_hidden()
1037 local name="$1" value="$2"
1038 printf '<input type="hidden" name="%s" value="%s" />\n' "$name" "$value"
1041 datalist()
1043 local list="$1" name="$2"
1044 printf '<datalist id="list_%s">\n' "$name"
1045 # workaround for browsers that don’t support the datalist element..
1046 local script="displaySelValue(\"select_$name\",\"$name\")"
1047 printf '<select class="workaround" id="select_%s" ' "$name"
1048 printf "onChange='%s' onBlur='%s'>\n" "$script" "$script"
1050 # workaround ..end
1051 printf '%s' "$list" | \
1052 /bin/busybox awk -v NONE="$(gettext "None")" 'BEGIN{
1053 line=0
1056 TEXT=$1
1057 sub(".*/","",TEXT)
1058 printf "<option value=\"%s\">%s</option>\n", $1, TEXT
1059 line++
1061 END{
1062 if (line < 1)
1063 printf "<option value=>< %s ></option>\n", NONE
1064 }'
1065 echo "</select>"
1066 echo "</datalist>"
1069 format()
1071 list_fs="$1" selected="$2" name="$3" none="$(gettext 'Do not format')"
1072 printf '<label for="%s" ' "$name"
1073 printf 'title="%s">' "$(gettext "To format this partition, select a \
1074 filesystem, usually it's safe to use ext4")"
1075 printf '%s</label>\n' "$(gettext "Formatting option:")"
1076 printf '%s' "$list_fs" | \
1077 /bin/busybox awk -v SELECTED=$selected -v NONE="$none" -v NAME="$name" '
1078 BEGIN{
1079 RS=" "
1080 print "<select name=\"" NAME "\">"
1081 print "<option value=\"\">" NONE "</option>"
1082 line=0
1085 printf "<option value=\"" $1 "\""
1086 if ($1 == SELECTED) printf " selected"
1087 print ">" $0 "</option>"
1088 line++
1090 END{
1091 if (line < 1)
1092 print "<option value=>< " NONE " ></option>"
1093 print "</select>"
1094 }'
1097 form_start()
1099 printf '<form name="%s" method="get" ' "Form"
1100 printf 'onsubmit="return true" action="%s">\n' "$SCRIPT_NAME"
1103 form_end()
1105 echo '</form>'
1108 add_style()
1110 printf '<!-- add specific styles -->
1111 <style type="text/css">
1112 section label {
1113 display:inline-block;
1114 vertical-align:middle;
1115 width: 130px;
1117 .media label {
1118 display:inline-block;
1119 vertical-align:middle;
1120 width: 110px;
1122 .options label {
1123 display:inline-block;
1124 vertical-align:middle;
1125 width: 140px;
1127 .text {
1128 width: 350px;
1130 input {margin-bottom:3px;}
1131 span.alert {color: red}
1132 span.warning { color: darkgray}
1133 #progress {
1134 background-color: #f8f8f8;
1135 border: 1px solid #ddd;
1136 color: #666;
1137 cursor: progress;
1138 position: absolute;
1139 width: 348px;
1140 padding: 4px 4px 2px;
1142 </style>
1143 <!-- workaround for browsers that do not support the datalist element -->
1144 <style type="text/css">
1145 .workaround {width: 110px;}
1146 </style>
1147 <script>
1148 function displaySelValue(selectId,inputId)
1150 var slct = document.getElementById(selectId);
1151 var input = document.getElementById(inputId);
1152 document.getElementById("src_iso").value="";
1153 document.getElementById("src_web").value="";
1154 if (inputId =="src_iso"){
1155 document.getElementById("iso").checked = true;
1157 if (inputId =="src_web"){
1158 document.getElementById("web").checked = true;
1160 input.value = slct.options[slct.selectedIndex].value;
1162 </script>
1163 <!-- datalist workaround end -->
1164 \n'
1169 # main
1172 header
1174 case "$(GET page)" in
1175 home)
1176 xhtml_header
1177 select_action
1178 select_install
1179 select_upgrade
1180 select_evaluate
1181 ;;
1182 evaluate)
1183 xhtml_header
1184 select_evaluate
1185 ;;
1186 install)
1187 xhtml_header
1188 /usr/sbin/tazinst set mode install "$INSTFILE"
1189 page_redirection partitioning
1190 ;;
1191 partitioning)
1192 xhtml_header
1193 form_start
1194 display_mode
1195 select_gparted
1196 moveto_page home input
1197 form_end
1198 ;;
1199 gparted)
1200 exec_gparted
1201 xhtml_header
1202 page_redirection partitioning
1203 ;;
1204 upgrade)
1205 xhtml_header
1206 /usr/sbin/tazinst set mode upgrade "$INSTFILE"
1207 page_redirection input
1208 ;;
1209 input)
1210 xhtml_header
1211 add_style
1212 form_start
1213 display_mode
1214 select_settings
1215 moveto_page home execute
1216 form_end
1217 ;;
1218 execute)
1219 xhtml_header
1220 form_start
1221 display_mode
1222 save_settings
1223 if ! (/usr/sbin/tazinst check all $INSTFILE > /dev/null); then
1224 page_redirection "input&CHECK=yes"
1225 else
1226 tazinst_run && moveto_page home reboot \
1227 || moveto_page input failed
1228 fi
1229 form_end
1230 ;;
1231 reboot)
1232 /usr/sbin/tazinst clean "$INSTFILE"
1233 reboot ;;
1234 failed)
1235 xhtml_header
1236 form_start
1237 tazinst_log
1238 moveto_home
1239 form_end
1240 ;;
1241 *)
1242 xhtml_header
1243 if check_ressources; then
1244 /usr/sbin/tazinst new "$INSTFILE"
1245 page_redirection home
1246 fi
1247 ;;
1248 esac
1250 xhtml_footer
1252 exit 0