tazinst view installer.cgi @ rev 50

installer.cgi: enhance install wizard appearance to comply with current TazPanel style, so decode some pseudo-code into the plain html.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Apr 07 03:30:19 2015 +0300 (2015-04-07)
parents 6a623c8ee24c
children a6cb7280e39a
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for Tazinst, the SliTaz installer.
4 #
5 # Copyright (C) 2012-2015 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 [ "$REMOTE_USER" == "root" ] && cat << EOT
41 <li tabindex="0">
42 <span>$(gettext 'Install')</span>
43 <menu>
44 <li><a data-icon="install"
45 href="/installer.cgi">$(gettext 'Install')</a></li>
46 <li><a data-icon="slitaz"
47 href="/installer.cgi?page=install">$(gettext 'Install SliTaz')</a></li>
48 <li><a data-icon="upgrade"
49 href="/installer.cgi?page=upgrade">$(gettext 'Upgrade system')</a></li>
50 </menu>
51 </li>
52 EOT
53 exit
54 esac
57 #-----------
58 # home page
59 #-----------
61 select_action() {
62 cat <<EOT
63 <!-- Welcome message -->
65 <h2>$(gettext "Welcome to the Slitaz Installer!")</h2>
67 <p>$(gettext "The SliTaz Installer installs or upgrades SliTaz to a \
68 hard disk drive from a device like a Live-CD or LiveUSB key, from a SliTaz \
69 ISO file, or from the web by downloading an ISO file.")</p>
71 <p>$(gettext "Which type of installation do you want to start?")</p>
72 EOT
73 }
76 select_install() {
77 cat <<EOT
78 <!-- Install message -->
80 <section>
81 <header>$(gettext 'Install')</header>
83 <div>
84 <p>$(gettext "Install SliTaz on a partition of your hard disk drive. If \
85 you decide to format your partition, all data will be lost. If you do not \
86 format, all data except for any existing /home directory will be removed \
87 (the home directory will be kept as is).")</p>
88 <p>$(gettext "Before installation, you may need to create or resize \
89 partitions on your hard disk drive in order to make space for SliTaz \
90 GNU/Linux. You can graphically manage your partitions with Gparted")</p>
91 </div>
93 <footer>
94 <form>
95 <button name="page" value="install" data-icon="slitaz"
96 title="$(gettext 'Proceed to a new SliTaz installation')"
97 >$(gettext 'Install SliTaz')</button>
98 </form>
99 </footer>
100 </section>
101 EOT
102 }
105 select_upgrade() {
106 cat <<EOT
107 <!-- Upgrade message -->
109 <section>
110 <header>$(gettext 'Upgrade')</header>
112 <div>
113 <p>$(gettext "Upgrade an already installed SliTaz system on your hard disk \
114 drive. Your /home /etc /var/www directories will be kept, all other \
115 directories will be removed. Any additional packages added to your old \
116 Slitaz system will be updated as long you have an active internet connection.")</p>
117 </div>
119 <footer>
120 <form>
121 <button name="page" value="upgrade" data-icon="upgrade"
122 title="$(gettext 'Upgrade an existing SliTaz system')"
123 >$(gettext 'Upgrade SliTaz')</button>
124 </form>
125 </footer>
126 </section>
127 EOT
128 }
131 #--------------------
132 # partitioning page
133 #--------------------
135 exec_gparted() {
136 /bin/su - -c \
137 "exec env DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' /usr/sbin/gparted"
138 }
141 select_gparted() {
142 cat <<EOT
143 <!-- GParted message -->
145 <section>
146 <header>$(gettext "Partitioning")</header>
148 <div>
149 <p>$(gettext "On most used systems, the hard drive is already dedicated to \
150 partitions for Windows™, or Linux, or another operating \
151 system. You'll need to resize these partitions in order to make space for \
152 SliTaz GNU/Linux. SliTaz will co-exist with other operating systems already \
153 installed on your hard drive.")</p>
154 <p>$(gettext "The amount of space needed depends on how much software you \
155 plan to install and how much space you require for users. It's conceivable \
156 that you could run a minimal SliTaz system in 300 megs or less, but 2 gigs \
157 is indeed more comfy.")</p>
158 <p>$(gettext "A separate home partition and a partition that will be used \
159 as Linux swap space may be created if needed. Slitaz detects and uses swap \
160 partitions automatically.")</p>
161 <hr/>
162 <p>$(gettext "You can graphically manage your partitions with GParted. \
163 GParted is a partition editor for graphically managing your disk partitions. \
164 GParted allows you to create, destroy, resize and copy partitions without \
165 data loss.")</p>
166 <p>$(gettext "GParted supports ext2, ext3, ext4, linux swap, ntfs and \
167 fat32 filesystems right out of the box. Support for xjs, jfs, hfs and other \
168 filesystems is available as well but you first need to add drivers for these \
169 filesystems by installing the related packages xfsprogs, jfsutils, linux-hfs \
170 and so on.")</p>
171 </div>
173 <footer>
174 <!-- Launch GParted -->
175 <form>
176 <button name="page" value="gparted" data-icon="hdd"
177 title="$(gettext 'Launch GParted, the partition editor tool')"
178 >$(gettext 'Execute GParted')</button>
179 </form>
180 </footer>
181 </section>
184 <h5>$(gettext "Continue installation")</h5>
186 <p>$(gettext "Once you've made room for SliTaz on your drive, you should \
187 be able to continue installation.")</p>
188 EOT
189 }
192 #------------
193 # input page
194 #------------
196 select_source() {
197 local media="$(/usr/sbin/tazinst get media "$INSTFILE")"
198 local source="$(/usr/sbin/tazinst get source "$INSTFILE")"
199 local list_media="$(/usr/sbin/tazinst list media)"
200 local error
202 # set default media
203 [ "$media" ] || media="$(tazinst list media | cut -d ' ' -f1)"
205 comment "Source selection"
206 # cdrom
207 if printf '%s' "$list_media" | grep -q "cdrom"; then
208 input_media "cdrom" \
209 "$media"
210 label_media "cdrom" \
211 "$(gettext 'LiveCD')" \
212 "$media" \
213 "$(gettext 'Use the SliTaz LiveCD')"
214 br
215 fi
216 # usb
217 if printf '%s' "$list_media" | grep -q "usb"; then
218 input_media "usb" \
219 "$media"
220 label_media "usb" \
221 "$(gettext 'LiveUSB:')" \
222 "$media" \
223 "$(gettext 'Enter the partition where SliTaz Live is located on
224 your USB Key')"
225 error="$?"
226 select "$(/usr/sbin/tazinst list usb "$INSTFILE" | cut -d' ' -f2)" \
227 "$source" \
228 "SRC_USB"
229 error_msg "$error" \
230 "source" \
231 2
232 br
233 fi
234 # iso
235 input_media "iso" \
236 "$media"
237 label_media "iso" \
238 "$(gettext 'ISO file:')" \
239 "$media" \
240 "$(gettext 'Select a SliTaz ISO file located on a local disk')"
241 error="$?"
242 if [ "$media" == "iso" ]; then
243 input "text" \
244 "src_iso" \
245 "$source" "" \
246 "$(gettext 'Select an ISO or enter the full path to the ISO file')"\
247 "iso"
248 else
249 input "text" \
250 "src_iso" \
251 "" \
252 "none" \
253 "$(gettext 'Select an ISO or enter the full path to the ISO file')"\
254 "iso"
255 fi
256 datalist "$(/usr/sbin/tazinst list iso "$INSTFILE")" \
257 "src_iso"
258 error_msg "$error" \
259 "source"
260 br
261 # web
262 input_media "web" \
263 "$media"
264 label_media "web" \
265 "$(gettext 'Web:')" \
266 "$media" \
267 "$(gettext 'Select a SliTaz version on the Web')"
268 error="$?"
270 if [ "$media" == "web" ]; then
271 input "text" \
272 "src_web" \
273 "$source" "" \
274 "$(gettext 'Select a version or enter the full url to an ISO file')"\
275 "web"
276 else
277 input "text" \
278 "src_web" \
279 "" \
280 "none" \
281 "$(gettext 'Select a version or enter the full url to an ISO file')"\
282 "web"
283 fi
284 datalist "$(/usr/sbin/tazinst help web "$INSTFILE")" \
285 "src_web"
286 error_msg "$error" \
287 "source"
288 }
290 select_root_uuid()
291 {
292 local root_uuid="$(/usr/sbin/tazinst get root_uuid "$INSTFILE")"
293 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
294 comment "root_uuid selection"
295 if [ "$mode" == "upgrade" ]; then
296 label "root_uuid" \
297 "$(gettext 'Existing SliTaz partition to upgrade:')" \
298 "$(gettext 'Specify the partition containing the system to upgrade')"
299 error="$?"
300 else
301 label "root_uuid" \
302 "$(gettext 'Install Slitaz to partition:')" \
303 "$(gettext 'Specify the partition where to install SliTaz')"
304 error="$?"
305 fi
306 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
307 "$root_uuid" \
308 "ROOT_UUID" \
309 0
310 error_msg "$error" \
311 "root_uuid" \
312 0
313 br
314 }
316 select_root_format()
317 {
318 local root_format="$(/usr/sbin/tazinst get root_format "$INSTFILE")"
319 comment "root_format selection"
320 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
321 "$root_format" \
322 "ROOT_FORMAT"
323 }
325 select_home_uuid() {
326 local home_uuid="$(/usr/sbin/tazinst get home_uuid "$INSTFILE")"
328 cat <<EOT
329 <!-- home_uuid selection -->
331 <fieldset>
332 <legend>$(gettext "home partition")</legend>
334 $(
335 label "home_uuid" \
336 "$(gettext 'Separate partition for /home:')" \
337 "$(gettext 'Specify the partition containing /home')"
338 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
339 "$home_uuid" \
340 "HOME_UUID" \
341 0
342 )
343 <br/>
344 EOT
345 }
347 select_home_format()
348 {
349 local home_format="$(/usr/sbin/tazinst get home_format "$INSTFILE")"
351 comment "home_format selection"
352 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
353 "$home_format" \
354 "HOME_FORMAT"
355 cat <<EOT
356 </fieldset>
357 EOT
358 }
361 select_hostname() {
362 local hostname="$(/usr/sbin/tazinst get hostname "$INSTFILE")" error
364 cat <<EOT
365 <!-- hostname selection -->
367 <fieldset>
368 <legend>$(gettext "Hostname")</legend>
369 $(
370 label "hostname" \
371 "$(gettext 'Set Hostname to:')" \
372 "$(gettext 'Hostname configuration allows you to specify the machine name')"
373 error=$?
374 input "text" \
375 "HOSTNAME" \
376 "$hostname" \
377 "" \
378 "$(gettext 'Name of your system')"
379 error_msg "$error" \
380 "hostname" \
381 2
382 )
383 </fieldset>
384 EOT
385 }
388 select_root_pwd() {
389 local root_pwd="$(/usr/sbin/tazinst get root_pwd "$INSTFILE")" error
391 cat <<EOT
392 <!-- root_pwd selection -->
394 <fieldset>
395 <legend>$(gettext "Root superuser")</legend>
396 $(
397 label "root_pwd" \
398 "$(gettext 'Root passwd:')" \
399 "$(gettext 'Enter the password for root')"
400 error="$?"
401 input "text" \
402 "ROOT_PWD" \
403 "$root_pwd" \
404 "" \
405 "$(gettext 'Password of root')"
406 error_msg "$error" \
407 "root_pwd"
408 )
409 </fieldset>
410 EOT
411 }
414 select_user_login() {
415 local user_login="$(/usr/sbin/tazinst get user_login "$INSTFILE")" error
417 cat <<EOT
418 <!-- user_login selection -->
420 <fieldset>
421 <legend>$(gettext "User")</legend>
422 $(
423 label "user_login" \
424 "$(gettext 'User login:')" \
425 "$(gettext 'Enter the name of the first user')"
426 error="$?"
427 input "text" \
428 "USER_LOGIN" \
429 "$user_login" \
430 "" \
431 "$(gettext 'Name of the first user')"
432 error_msg "$error" \
433 "user_login" \
434 2
435 )
436 <br/>
437 EOT
438 }
441 select_user_pwd()
442 {
443 local user_pwd="$(/usr/sbin/tazinst get user_pwd "$INSTFILE")" error
445 label "user_pwd" \
446 "$(gettext 'User passwd:')" \
447 "$(gettext 'The password for default user')"
448 error="$?"
449 input "text" \
450 "USER_PWD" \
451 "$user_pwd" \
452 "" \
453 "$(gettext 'Password of the first user')"
454 error_msg "$error" \
455 "user_pwd"
456 cat <<EOT
457 </fieldset>
458 EOT
459 }
462 select_bootloader()
463 {
464 local bootloader="$(/usr/sbin/tazinst get bootloader "$INSTFILE")" error
466 cat <<EOT
467 <!-- bootloader selection -->
469 <fieldset>
470 <legend>$(gettext "Bootloader")</legend>
472 $(
473 input "checkbox" \
474 "bootloader" \
475 "auto" \
476 "$bootloader"
477 label "bootloader" \
478 "$(gettext 'Install a bootloader.')" \
479 "$(gettext "Usually you should answer yes, unless you want to install \
480 a bootloader by hand yourself.")"
481 error="$?"
482 error_msg "$error" \
483 "bootloader"
484 )
485 <br/>
486 EOT
487 }
490 select_winboot()
491 {
492 local winboot="$(/usr/sbin/tazinst get winboot "$INSTFILE")" error
494 comment "winboot selection"
495 input "checkbox" \
496 "winboot" \
497 "auto" \
498 "$winboot"
499 label "winboot" \
500 "$(gettext 'Enable Windows Dual-Boot.')" \
501 "$(gettext "At start-up, you will be asked whether you want to boot \
502 into Windows™ or SliTaz GNU/Linux.")"
503 error="$?"
504 error_msg "$error" \
505 "winboot"
506 cat <<EOT
507 </fieldset>
508 EOT
509 }
512 errors_msg()
513 {
514 if [ "$CHECK" ]; then
515 echo '<span class="alert">'
516 p "$(gettext "Errors found. Please check your settings.")"
517 echo '</span>'
518 fi
519 }
522 select_settings() {
523 local settings="$(/usr/sbin/tazinst get settings "$INSTFILE")"
524 CHECK=$(GET CHECK)
525 errors_msg
527 cat<<EOT
528 <fieldset>
529 <legend>$(gettext "Select source media:")</legend>
531 <div class="media">$(select_source)</div>
532 </fieldset>
535 <fieldset>
536 <legend>$(gettext "Select destination")</legend>
538 <div>$(
539 select_root_uuid
540 printf '%s' "$settings" | grep -q "root_format" && select_root_format
541 )</div>
542 </fieldset>
545 <fieldset id="options">
546 <legend>$(gettext 'Options')</legend>
548 <div class="options">$(
549 printf '%s' "$settings" | grep -q "home_uuid" && select_home_uuid
550 printf '%s' "$settings" | grep -q "home_format" && select_home_format
551 printf '%s' "$settings" | grep -q "hostname" && select_hostname
552 printf '%s' "$settings" | grep -q "root_pwd" && select_root_pwd
553 printf '%s' "$settings" | grep -q "user_login" && select_user_login
554 printf '%s' "$settings" | grep -q "user_pwd" && select_user_pwd
555 )</div>
557 <div class="bootloader">$(
558 printf '%s' "$settings" | grep -q "bootloader" && select_bootloader
559 printf '%s' "$settings" | grep -q "winboot" && select_winboot
560 )</div>
561 </fieldset>
563 <br/>
564 EOT
565 }
568 #--------------
569 # execute page
570 #--------------
572 save_settings()
573 {
574 h5 "$(gettext "Checking settings...")"
576 # install type
577 /usr/sbin/tazinst set media "$(GET MEDIA)" "$INSTFILE"
579 # source File
580 case "$(/usr/sbin/tazinst get media "$INSTFILE")" in
581 usb)
582 /usr/sbin/tazinst set source "$(GET SRC_USB)" "$INSTFILE" ;;
583 iso)
584 /usr/sbin/tazinst set source "$(GET SRC_ISO)" "$INSTFILE" ;;
585 web)
586 /usr/sbin/tazinst set source "$(GET SRC_WEB)" "$INSTFILE" ;;
587 esac
589 # set defined url
590 [ $(GET URL) ] && SRC_WEB=$(GET URL)
592 # root Partition
593 /usr/sbin/tazinst set root_uuid "$(GET ROOT_UUID)" "$INSTFILE"
595 # format root partition
596 [ "$(GET ROOT_FORMAT)" ] \
597 && /usr/sbin/tazinst set root_format "$(GET ROOT_FORMAT)" "$INSTFILE" \
598 || /usr/sbin/tazinst unset root_format "$INSTFILE"
600 # home Partition
601 if [ "$(GET HOME_UUID)" ] ; then
602 /usr/sbin/tazinst set home_uuid "$(GET HOME_UUID)" "$INSTFILE"
603 [ "$(GET HOME_FORMAT)" ] \
604 && /usr/sbin/tazinst set home_format "$(GET HOME_FORMAT)" \
605 "$INSTFILE" \
606 || /usr/sbin/tazinst unset home_format "$INSTFILE"
607 else
608 /usr/sbin/tazinst unset home_uuid "$INSTFILE"
609 /usr/sbin/tazinst unset home_format "$INSTFILE"
610 fi
612 # hostname
613 /usr/sbin/tazinst set hostname "$(GET HOSTNAME)" "$INSTFILE"
615 # root pwd
616 /usr/sbin/tazinst set root_pwd "$(GET ROOT_PWD)" "$INSTFILE"
618 # user Login
619 /usr/sbin/tazinst set user_login "$(GET USER_LOGIN)" "$INSTFILE"
621 # user Pwd
622 /usr/sbin/tazinst set user_pwd "$(GET USER_PWD)" "$INSTFILE"
624 # win Dual-Boot
625 /usr/sbin/tazinst set winboot "$(GET WINBOOT)" "$INSTFILE"
627 # bootloader
628 if [ "$(GET BOOTLOADER)" == "auto" ]; then
629 /usr/sbin/tazinst set bootloader "auto" "$INSTFILE"
630 else
631 /usr/sbin/tazinst unset bootloader "$INSTFILE"
632 /usr/sbin/tazinst unset winboot "$INSTFILE"
633 fi
634 input_hidden "CHECK" "yes"
635 }
638 tazinst_run()
639 {
640 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")" error
641 h4 "Proceeding to: $mode"
642 /usr/sbin/tazinst execute "$INSTFILE" | /bin/busybox awk '{
643 num=$1+0
644 if (num>0 && num<=100){
645 print "<script type=\"text/javascript\">"
646 printf "document.write(\047<div id=\"progress\">"
647 printf "<img src=\"/styles/default/images/loader.gif\" />"
648 printf $1 "&#37; " substr($0, length($1)+2, 40)
649 print "</div>\047)"
650 print "</script>"
651 }
652 }'
653 # end_of_install
654 if /usr/sbin/tazinst log | grep -q "x-x-" ; then
655 error=1
656 echo "<script type=\"text/javascript\">"
657 printf "document.write(\047<div id=\"progress\">"
658 printf "<img src=\"/styles/default/images/stop.png\" />"
659 printf "$(gettext 'Errors encountered.')"
660 printf "</div>\047)\n"
661 echo "</script>"
662 br
663 br
664 /usr/sbin/tazinst log | \
665 /bin/busybox awk '$1 == "-x-x-",$1 == "x-x-x"' | sed 's/-x-x-/ /' \
666 | grep -v "x-x-x"
667 else
668 error=0
669 echo "<script type=\"text/javascript\">"
670 printf "document.write(\047<div id=\"progress\">"
671 printf "<img src=\"/styles/default/images/tux.png\" />"
672 printf "$(gettext 'Process completed!')"
673 printf "</div>\047)\n"
674 echo "</script>"
675 br
676 br
677 br
678 p $(gettext "Installation is now finished, you can exit the installer \
679 or reboot on your new SliTaz GNU/Linux operating system.")
680 fi
681 return "$error"
683 }
686 tazinst_log()
687 {
688 h4 "$(gettext "Tazinst log")"
689 printf '<pre>%s</pre>' "$(/usr/sbin/tazinst log | sed 's/\%/ percent/g')"
690 }
693 #-----------------
694 # page navigation
695 #-----------------
697 display_mode() {
698 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
699 case $mode in
700 install)
701 cat <<EOT
702 <h2>$(gettext "Install SliTaz")</h2>
704 <p>$(gettext "You're going to install SliTaz on a partition of \
705 your hard disk drive. If you decide to format your HDD, all data will be \
706 lost. If you do not format, all data except for any existing /home \
707 directory will be removed (the home directory will be kept as is).")</p>
708 EOT
709 ;;
710 upgrade)
711 cat <<EOT
712 <h2>$(gettext "Upgrade SliTaz")</h2>
714 <p>$(gettext "You're going to upgrade an already installed SliTaz \
715 system on your hard disk drive. Your /home /etc /var/www directories \
716 will be kept, all other directories will be removed. Any additional \
717 packages added to your old Slitaz system will be updated as long you \
718 have an active internet connection.")</p>
719 EOT
720 ;;
721 esac
722 }
725 moveto_page()
726 {
727 local back_page="$1" next_page="$2" back_msg next_msg
729 case "$back_page" in
730 partitioning)
731 back_msg=$(gettext 'Back to partitioning') ;;
732 input)
733 back_msg=$(gettext 'Back to entering settings') ;;
734 *)
735 back_msg=$(gettext 'Back to Installer Start Page') ;;
736 esac
738 case "$next_page" in
739 execute|run)
740 next_msg=$(gettext 'Proceed to SliTaz installation') ;;
741 reboot)
742 next_msg=$(gettext 'Installation complete. You can now restart') ;;
743 failed)
744 next_msg=$(gettext 'Installation failed. See log') ;;
745 input)
746 next_msg=$(gettext 'Continue installation.') ;;
747 *)
748 next_msg=$(gettext 'Back to Installer Start Page') ;;
749 esac
751 cat <<EOT
752 <hr/>
753 <form>
754 <button name="page" value="$back_page" data-icon="back" >$back_msg</button>
755 <button name="page" value="$next_page" data-icon="start">$next_msg</button>
756 </form>
757 EOT
758 }
761 moveto_home() {
762 cat <<EOT
763 <form>
764 <button name="page" value="home" data-icon="back"
765 >$(gettext 'Back to Installer Start Page')</button>
766 </form>
767 EOT
768 }
771 page_redirection() {
772 local page="$1"
773 cat <<EOT
774 <!DOCTYPE html>
775 <html>
776 <head>
777 <meta charset="UTF-8">
778 <title>$(gettext "A web page that points a browser to a different page after \
779 2 seconds")</title>
780 <meta http-equiv="refresh" content="0; URL=$SCRIPT_NAME?page=$1">
781 <meta name="keywords" content="automatic redirection">
782 </head>
783 <body>
784 <p>$(gettext "If your browser doesn't automatically redirect within a few \
785 seconds, you may want to go there manually")
786 <a href="$SCRIPT_NAME?page=$page">$(gettext "here")</a></p>
787 </body>
788 </html>
789 EOT
790 }
793 #----------
794 # checking
795 #----------
797 check_ressources() {
798 local errorcode=0
799 comment "check_ressources"
800 if ! [ -x /usr/sbin/tazinst ] ; then
801 h4 $(gettext "Tazinst Error")
802 p $(gettext "<strong>tazinst</strong>, the backend to slitaz-installer \
803 is missing. Any installation can not be done without tazinst.")
804 p $(gettext "Check tazinst permissions, or reinstall the \
805 slitaz-installer package.")
806 errorcode=1
807 else
808 # check tazinst minimum version
809 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
810 r=$TAZINST_MINIMUM_VERSION
811 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
812 '{v=$v+0}{ if (v < r) exit 1}') ; then
813 h4 $(gettext "Tazinst Error")
814 p $(gettext "<strong>tazinst</strong>, the slitaz-installer \
815 backend, is not at the minimum required version. Any installation \
816 cannot be done without tazinst.")
817 p $(gettext "Reinstall the slitaz-installer package, or use \
818 tazinst in CLI mode.")
819 errorcode=1
820 fi
821 # check tazinst maximum version
822 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
823 r=$TAZINST_MAXIMUM_VERSION
824 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
825 '{v=$v+0}{ if (v > r) exit 1}') ; then
826 h4 $(gettext "Tazinst Error")
827 p $(gettext "<strong>tazinst</strong>, the slitaz-installer \
828 backend, is at a higher version than the maximum authorized \
829 by the slitaz-installer. Any installation cannot be done.")
830 p $(gettext "Reinstall the slitaz-installer package, or use \
831 tazinst in CLI mode.")
832 errorcode=1
833 fi
834 fi
835 return $errorcode
836 }
839 #---------------
840 # html snippets
841 #---------------
843 br() {
844 echo '<br />'
845 }
847 hr() {
848 echo '<hr />'
849 }
851 comment() {
852 printf '<!-- %s -->\n' "$@"
853 }
855 a() {
856 local page="$1" text="$2"
857 printf '<a class="button" value="%s" href="%s?page=%s">%s</a>\n' \
858 "$page" "$SCRIPT_NAME" "$page" "$text"
859 }
861 button() {
862 local action="$1" msg="$2" title="$3"
863 printf '<a class="button" href="%s?page=%s" title="%s">%s</a>\n' \
864 "$SCRIPT_NAME" "$action" "$title" "$msg"
865 }
867 open_div() {
868 [ "$1" ] && printf '<div %s>\n' "$1" || echo '<div>'
869 }
871 close_div() {
872 echo '</div>'
873 }
875 p() {
876 printf '<p>%s</p>\n' "$@"
877 }
879 h4() {
880 printf '<h4>%s</h4>\n' "$@"
881 }
883 h5() {
884 printf '<h5>%s</h5>\n' "$@"
885 }
887 label() {
888 local setting="$1" label="$2" title="$3" name="$4" error=0
889 [ -z "$name" ] && name="$setting"
890 printf '<label for="%s"' "$name"
891 [ "$title" ] && printf ' title="%s">' "$title" || printf '%s' '>'
892 # display label in red in case of error
893 if [ "$CHECK" ]; then
894 /usr/sbin/tazinst check "$setting" "$INSTFILE"
895 error="$?"
896 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
897 printf '%s' '<span class="alert">'
898 printf '%s' "$label"
899 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
900 printf '%s' "<sup>*</sup></span>"
901 else
902 printf '%s' "$label"
903 fi
904 echo '</label>'
905 return "$error"
906 }
909 label_media() {
910 local id="$1" label="$2" media="$3" title="$4" retcode=0
911 if [ "$media" == "$id" ]; then
912 label "source" \
913 "$label" \
914 "$title" \
915 "$media"
916 retcode="$?"
917 else
918 printf '<label for="%s"' "$id"
919 [ "$title" ] && printf ' title="%s">' "$title" || echo '>'
920 echo "$label</label>"
921 fi
922 return "$retcode"
923 }
926 error_msg() {
927 local error="$1" setting="$2" line="$3"
928 if [ "$CHECK" ]; then
929 if [ "$error" -gt "0" ]; then
930 [ "$error" -lt "128" ] && printf '%s' '<span class="alert">' \
931 || printf '%s' '<span class="warning">'
932 if [ "$line" ]; then
933 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1 | \
934 /bin/busybox awk -v LINE="$line" '{if (NR==LINE){print}}'
935 else
936 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1
937 fi
938 echo '</span>'
939 fi
940 fi
941 }
944 select() {
945 local list="$1" selected="$2" name="$3" type="$4"
946 printf '%s' "$list" | \
947 /bin/busybox awk -v SELECTED="$selected" -v NONE="$(gettext "None")" \
948 -v NAME="$name" -v TYPE="$type" 'BEGIN{
949 TYPE=TYPE+0
950 print "<select name=\"" NAME "\">"
951 print "<option value=>< " NONE " ></option>"
952 }
953 {
954 printf "<option value=\"" $1 "\""
955 if ($1 == SELECTED) printf " selected"
956 if (TYPE == 0)
957 print ">" $0 "</option>"
958 if (TYPE == 1)
959 print ">" substr($0,12) "</option>"
960 if (TYPE == 2)
961 print ">" $2 "</option>"
962 }
963 END{
964 print "</select>"
965 }'
966 }
968 input()
969 {
970 local type="$1" name="$2" value="$3" selected="$4" help="$5" action="$6"
971 printf '<input type="%s" id="%s" list="list_%s" ' "$type" "$name" "$name"
972 printf 'name="%s" class="%s" ' "$(printf $name | tr [a-z] [A-Z])" "$type"
973 [ "$value" ] && printf 'value="%s" ' "$value"
974 [ "$value" == "$selected" ] && printf '%s' "checked "
975 [ "$action" ] && printf \
976 'onInput="document.getElementById(%s).checked = true;" ' "'$action'"
977 [ "$help" ] && printf 'placeholder="%s" />\n' "$help" || echo "/>"
978 }
980 input_media()
981 {
982 local id="$1" media="$2"
983 printf '<input type="radio" name="MEDIA" value="%s" id="%s" ' "$id" "$id"
984 [ "$media" == "$id" ] && echo 'checked />' || echo '/>'
985 }
987 input_hidden()
988 {
989 local name="$1" value="$2"
990 printf '<input type="hidden" name="%s" value="%s" />\n' "$name" "$value"
991 }
993 datalist()
994 {
995 local list="$1" name="$2"
996 printf '<datalist id="list_%s">\n' "$name"
997 # workaround for browsers that don’t support the datalist element..
998 local script="displaySelValue(\"select_$name\",\"$name\")"
999 printf '<select class="workaround" id="select_%s" ' "$name"
1000 printf "onChange='%s' onBlur='%s'>\n" "$script" "$script"
1002 # workaround ..end
1003 printf '%s' "$list" | \
1004 /bin/busybox awk -v NONE="$(gettext "None")" 'BEGIN{
1005 line=0
1008 TEXT=$1
1009 sub(".*/","",TEXT)
1010 printf "<option value=\"%s\">%s</option>\n", $1, TEXT
1011 line++
1013 END{
1014 if (line < 1)
1015 printf "<option value=>< %s ></option>\n", NONE
1016 }'
1017 echo "</select>"
1018 echo "</datalist>"
1021 format()
1023 list_fs="$1" selected="$2" name="$3" none="$(gettext 'Do not format')"
1024 printf '<label for="%s" ' "$name"
1025 printf 'title="%s">' "$(gettext "To format this partition, select a \
1026 filesystem, usually it's safe to use ext4")"
1027 printf '%s</label>\n' "$(gettext "Formatting option:")"
1028 printf '%s' "$list_fs" | \
1029 /bin/busybox awk -v SELECTED=$selected -v NONE="$none" -v NAME="$name" '
1030 BEGIN{
1031 RS=" "
1032 print "<select name=\"" NAME "\">"
1033 print "<option value=\"\">" NONE "</option>"
1034 line=0
1037 printf "<option value=\"" $1 "\""
1038 if ($1 == SELECTED) printf " selected"
1039 print ">" $0 "</option>"
1040 line++
1042 END{
1043 if (line < 1)
1044 print "<option value=>< " NONE " ></option>"
1045 print "</select>"
1046 }'
1049 form_start()
1051 printf '<form name="%s" method="get" ' "Form"
1052 printf 'onsubmit="return true" action="%s">\n' "$SCRIPT_NAME"
1055 form_end()
1057 echo '</form>'
1060 add_style()
1062 printf '<!-- add specific styles -->
1063 <style type="text/css">
1064 section label {
1065 display:inline-block;
1066 vertical-align:middle;
1067 width: 130px;
1069 .media label {
1070 display:inline-block;
1071 vertical-align:middle;
1072 width: 110px;
1074 .options label {
1075 display:inline-block;
1076 vertical-align:middle;
1077 width: 140px;
1079 .text {
1080 width: 350px;
1082 input {margin-bottom:3px;}
1083 span.alert {color: red}
1084 span.warning { color: darkgray}
1085 #progress {
1086 background-color: #f8f8f8;
1087 border: 1px solid #ddd;
1088 color: #666;
1089 cursor: progress;
1090 position: absolute;
1091 width: 348px;
1092 padding: 4px 4px 2px;
1094 </style>
1095 <!-- workaround for browsers that do not support the datalist element -->
1096 <style type="text/css">
1097 .workaround {width: 110px;}
1098 </style>
1099 <script>
1100 function displaySelValue(selectId,inputId)
1102 var slct = document.getElementById(selectId);
1103 var input = document.getElementById(inputId);
1104 document.getElementById("src_iso").value="";
1105 document.getElementById("src_web").value="";
1106 if (inputId =="src_iso"){
1107 document.getElementById("iso").checked = true;
1109 if (inputId =="src_web"){
1110 document.getElementById("web").checked = true;
1112 input.value = slct.options[slct.selectedIndex].value;
1114 </script>
1115 <!-- datalist workaround end -->
1116 \n'
1121 # main
1124 header
1126 case "$(GET page)" in
1127 home)
1128 xhtml_header
1129 select_action
1130 select_install
1131 select_upgrade
1132 ;;
1133 install)
1134 xhtml_header
1135 /usr/sbin/tazinst set mode install "$INSTFILE"
1136 page_redirection partitioning
1137 ;;
1138 partitioning)
1139 xhtml_header
1140 form_start
1141 display_mode
1142 select_gparted
1143 moveto_page home input
1144 form_end
1145 ;;
1146 gparted)
1147 exec_gparted
1148 xhtml_header
1149 page_redirection partitioning
1150 ;;
1151 upgrade)
1152 xhtml_header
1153 /usr/sbin/tazinst set mode upgrade "$INSTFILE"
1154 page_redirection input
1155 ;;
1156 input)
1157 xhtml_header
1158 add_style
1159 form_start
1160 display_mode
1161 select_settings
1162 moveto_page home execute
1163 form_end
1164 ;;
1165 execute)
1166 xhtml_header
1167 form_start
1168 display_mode
1169 save_settings
1170 if ! (/usr/sbin/tazinst check all $INSTFILE > /dev/null); then
1171 page_redirection "input&CHECK=yes"
1172 else
1173 tazinst_run && moveto_page home reboot \
1174 || moveto_page input failed
1175 fi
1176 form_end
1177 ;;
1178 reboot)
1179 /usr/sbin/tazinst clean "$INSTFILE"
1180 reboot ;;
1181 failed)
1182 xhtml_header
1183 form_start
1184 tazinst_log
1185 moveto_home
1186 form_end
1187 ;;
1188 *)
1189 xhtml_header
1190 if check_ressources; then
1191 /usr/sbin/tazinst new "$INSTFILE"
1192 page_redirection home
1193 fi
1194 ;;
1195 esac
1197 xhtml_footer
1199 exit 0