tazinst view installer.cgi @ rev 10

Merge installer.menu and installer.cgi (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Mar 23 08:44:40 2013 +0100 (2013-03-23)
parents ee47159f98fb
children 7e0be1e36271
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for Tazinst, the SliTaz installer.
4 #
5 # Copyright (C) 2012-2013 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.90
16 # panel location and theme
17 PANEL="/var/www/tazpanel"
18 STYLE="default"
20 # absolute paths to images
21 IMAGES="/styles/$STYLE/images"
23 # tazpanel config
24 [ -r /etc/slitaz/tazpanel.conf ] && . /etc/slitaz/tazpanel.conf
26 # include gettext helper script.
27 . /usr/bin/gettext.sh
29 # get parameters with GET, POST and FILE functions
30 . /usr/bin/httpd_helper.sh
32 # export package name for gettext.
33 TEXTDOMAIN='installer'
34 export TEXTDOMAIN
36 # tazinst required version
37 TAZINST_MINIMUM_VERSION="3.8"
38 TAZINST_MAXIMUM_VERSION="4.99"
40 # tazinst setup file
41 INSTFILE=/root/tazinst.conf
43 #------
44 # menu
45 #------
46 case "$1" in
47 menu) cat << EOT
48 <li><a href="/installer.cgi">$(gettext 'Install')</a>
49 <ul>
50 <li><a href="/installer.cgi?page=menu_install">$(gettext 'Install SliTaz')</a></li>
51 <li><a href="/installer.cgi?page=menu_upgrade">$(gettext 'Upgrade system')</a></li>
52 </ul>
53 </li>
54 EOT
55 exit
56 esac
58 #-----------
59 # home page
60 #-----------
62 select_action()
63 {
64 comment "welcome message"
65 open_div_id "wrapper"
66 h4 $(gettext "Welcome to the Slitaz Installer!")
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.")
70 h5 $(gettext "Which type of installation do you want to start?")
71 close_div
72 }
74 select_install()
75 {
76 comment "install message"
77 open_div_class "box"
78 h4 $(gettext "Install")
79 p $(gettext "Install SliTaz on a partition of your hard disk drive. If you \
80 decide to format your partition, all data will be lost. If you do not \
81 format, all data except for any existing /home directory will be removed, \
82 the home directory will be kept as is.")
83 p $(gettext "Before installation, you may need to create or resize \
84 partitions on your hard disk drive in order to make space for SliTaz \
85 GNU/Linux. You can graphically manage your partitions with Gparted")
86 close_div
87 button "install" \
88 "$(gettext 'Install SliTaz')" \
89 "$(gettext 'Proceed to a new SliTaz installation')"
90 }
92 select_upgrade()
93 {
94 comment "upgrade message"
95 open_div_class "box"
96 h4 $(gettext "Upgrade")
97 p $(gettext "Upgrade an already installed SliTaz system on your hard disk \
98 drive. Your /home /etc /var/www directories will be kept, all other \
99 directories will be removed. Any additional packages added to your old \
100 Slitaz system will be updated as long you have an active internet connection.")
101 close_div
102 button "upgrade" \
103 "$(gettext 'Upgrade SliTaz')" \
104 "$(gettext 'Upgrade an existing SliTaz system')"
105 }
107 #--------------------
108 # partitionning page
109 #--------------------
111 exec_gparted()
112 {
113 /bin/su - -c "exec env DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' \
114 /usr/sbin/gparted"
115 }
117 select_gparted()
118 {
119 comment "gparted message"
120 h5 $(gettext "Partitioning")
121 open_div_class "box"
122 p $(gettext "On most used systems, the hard drive is already dedicated to \
123 partitions for Windows<sup>&trade;</sup>, or Linux, or another operating \
124 system. You'll need to resize these partitions in order to make space for \
125 SliTaz GNU/Linux. SliTaz will co-exist with other operating systems already \
126 installed on your hard drive.")
127 p $(gettext "The amount of space needed depends on how much software you \
128 plan to install and how much space you require for users. It's conceivable \
129 that you could run a minimal SliTaz system in 300 megs or less, but 2 gigs \
130 is indeed more comfy.")
131 p $(gettext "A separate home partition, and a partition that will be used \
132 as Linux swap space may be created if needed. Slitaz detects and uses swap \
133 partitions automatically.")
134 close_div
135 open_div_class "box"
136 p $(gettext "You can graphically manage your partitions with GParted. \
137 GParted is a partition editor for graphically managing your disk partitions. \
138 GParted allows you to create, destroy, resize and copy partitions without \
139 data loss.")
140 p $(gettext "GParted supports ext2, ext3, ext4, linux swap, ntfs and fat32 \
141 filesystems right out of the box. Support for xjs, jfs, hfs and other \
142 filesystems is available as well but you first need to add drivers for these \
143 filesystems by installing the related packages xfsprogs, jfsutils, linux-hfs \
144 and so on.")
145 close_div
146 comment "launch GParted"
147 button "gparted" \
148 "$(gettext 'Execute GParted')" \
149 "$(gettext 'Launch GParted, the partition editor tool')"
150 h5 $(gettext "Continue installation")
151 p $(gettext "Once you've made room for SliTaz on your drive, you should be \
152 able to continue installation.")
153 }
155 #------------
156 # input page
157 #------------
160 select_source()
161 {
162 local media="$(/usr/sbin/tazinst get media "$INSTFILE")"
163 local source="$(/usr/sbin/tazinst get source "$INSTFILE")"
164 local list_media="$(/usr/sbin/tazinst list media)"
166 # default media
167 [ "$media" ] || media="$(tazinst list media | cut -d ' ' -f1)"
168 local error
169 comment "source selection"
170 # cdrom
171 if printf "$list_media" | grep -q "cdrom"; then
172 input_media "cdrom" \
173 "$media"
174 label_media "cdrom" \
175 "$(gettext 'LiveCD')" \
176 "$media" \
177 "$(gettext 'Use the SliTaz LiveCD')"
178 br
179 fi
180 # usb
181 if printf "$list_media" | grep -q "usb"; then
182 input_media "usb" \
183 "$media"
184 label_media "usb" \
185 "$(gettext 'LiveUSB:')" \
186 "$media" \
187 "$(gettext 'Enter the partition where SliTaz Live is located on your USB Key')"
188 error="$?"
189 select "$(/usr/sbin/tazinst list usb "$INSTFILE")" \
190 "$source" \
191 "SRC_USB"
192 error_msg "$error" \
193 "source" \
194 2
195 br
196 fi
197 # iso
198 input_media "iso" \
199 "$media"
200 label_media "iso" \
201 "$(gettext 'ISO file:')" \
202 "$media" \
203 "$(gettext 'Select a SliTaz ISO file located on a local disk')"
204 error="$?"
205 if [ "$media" == "iso" ]; then
206 input "text" \
207 "src_iso" \
208 "$source" "" \
209 "$(gettext 'Select an ISO or enter the full path to the ISO file')" \
210 "iso"
211 else
212 input "text" \
213 "src_iso" \
214 "" \
215 "none" \
216 "$(gettext 'Select an ISO or enter the full path to the ISO file')" \
217 "iso"
218 fi
219 datalist "$(/usr/sbin/tazinst list iso "$INSTFILE")" \
220 "src_iso"
221 error_msg "$error" \
222 "source"
223 br
224 # web
225 input_media "web" \
226 "$media"
227 label_media "web" \
228 "$(gettext 'Web:')" \
229 "$media" \
230 "$(gettext 'Select a SliTaz version on the Web')"
231 error="$?"
233 if [ "$media" == "web" ]; then
234 input "text" \
235 "src_web" \
236 "$source" "" \
237 "$(gettext 'Select a version or enter the full url to an ISO file')" \
238 "web"
239 else
240 input "text" \
241 "src_web" \
242 "" \
243 "none" \
244 "$(gettext 'Select a version or enter the full url to an ISO file')" \
245 "web"
246 fi
247 datalist "$(/usr/sbin/tazinst help web "$INSTFILE")" \
248 "src_web"
249 error_msg "$error" \
250 "source"
251 }
253 select_root_uuid()
254 {
255 local root_uuid="$(/usr/sbin/tazinst get root_uuid "$INSTFILE")"
256 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
257 comment "root_uuid selection"
258 if [ "$mode" == "upgrade" ]; then
259 label "root_uuid" \
260 "$(gettext 'Existing SliTaz partition to upgrade:')" \
261 "$(gettext 'Specify the partition containing the system to upgrade')"
262 error="$?"
263 else
264 label "root_uuid" \
265 "$(gettext 'Install Slitaz to partition:')" \
266 "$(gettext 'Specify the partition where to install SliTaz')"
267 error="$?"
268 fi
269 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
270 "$root_uuid" \
271 "ROOT_UUID" \
272 2
273 error_msg "$error" \
274 "root_uuid" \
275 2
276 br
277 }
279 select_root_format()
280 {
281 local root_format="$(/usr/sbin/tazinst get root_format "$INSTFILE")"
282 comment "root_format selection"
283 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
284 "$root_format" \
285 "ROOT_FORMAT"
286 }
288 select_options()
289 {
290 printf "<h4 id=\"options\">$(gettext 'Options')</h4>"
291 }
293 select_home_uuid()
294 {
295 local home_uuid="$(/usr/sbin/tazinst get home_uuid "$INSTFILE")"
296 comment "home_uuid selection"
297 h5 $(gettext "home partition")
298 label "home_uuid" \
299 "$(gettext 'Separate partition for /home:')" \
300 "$(gettext 'Specify the partition containing /home')"
301 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
302 "$home_uuid" \
303 "HOME_UUID" \
304 2
305 br
306 }
308 select_home_format()
309 {
310 local home_format="$(/usr/sbin/tazinst get home_format "$INSTFILE")"
311 comment "home_format selection"
312 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
313 "$home_format" \
314 "HOME_FORMAT"
315 }
317 select_hostname()
318 {
319 local hostname="$(/usr/sbin/tazinst get hostname "$INSTFILE")" error
320 comment "hostname selection"
321 h5 $(gettext "Hostname")
322 label "hostname" \
323 "$(gettext 'Set Hostname to:')" \
324 "$(gettext 'Hostname configuration allows you to specify the machine name')"
325 error=$?
326 input "text" \
327 "HOSTNAME" \
328 "$hostname" \
329 "" \
330 "$(gettext 'Name of your system')"
331 error_msg "$error" \
332 "hostname" \
333 2
334 }
336 select_root_pwd()
337 {
338 local root_pwd="$(/usr/sbin/tazinst get root_pwd "$INSTFILE")" error
339 comment "root_pwd selection"
340 h5 $(gettext "Root superuser")
341 label "root_pwd" \
342 "$(gettext 'Root passwd:')" \
343 "$(gettext 'Enter the password for root')"
344 error="$?"
345 input "text" \
346 "ROOT_PWD" \
347 "$root_pwd" \
348 "" \
349 "$(gettext 'Password of root')"
350 error_msg "$error" \
351 "root_pwd"
352 }
354 select_user_login()
355 {
356 local user_login="$(/usr/sbin/tazinst get user_login "$INSTFILE")" error
357 comment "user_login selection"
358 h5 $(gettext "User")
359 label "user_login" \
360 "$(gettext 'User login:')" \
361 "$(gettext 'Enter the name of the first user')"
362 error="$?"
363 input "text" \
364 "USER_LOGIN" \
365 "$user_login" \
366 "" \
367 "$(gettext 'Name of the first user')"
368 error_msg "$error" \
369 "user_login" \
370 2
371 br
372 }
374 select_user_pwd()
375 {
376 local user_pwd="$(/usr/sbin/tazinst get user_pwd "$INSTFILE")" error
377 label "user_pwd" \
378 "$(gettext 'User passwd:')" \
379 "$(gettext 'The password for default user')"
380 error="$?"
381 input "text" \
382 "USER_PWD" \
383 "$user_pwd" \
384 "" \
385 "$(gettext 'Password of the first user')"
386 error_msg "$error" \
387 "user_pwd"
388 }
390 select_bootloader()
391 {
392 local bootloader="$(/usr/sbin/tazinst get bootloader "$INSTFILE")" error
393 comment "bootloader selection"
394 h5 $(gettext "Bootloader")
395 input "checkbox" \
396 "bootloader" \
397 "auto" \
398 "$bootloader"
399 label "bootloader" \
400 "$(gettext 'Install a bootloader.')" \
401 "$(gettext "Usually you should answer yes, unless you want to install a \
402 bootloader by hand yourself.")"
403 error="$?"
404 error_msg "$error" \
405 "bootloader"
406 br
407 }
409 select_winboot()
410 {
411 local winboot="$(/usr/sbin/tazinst get winboot "$INSTFILE")" error
412 comment "winboot selection"
413 input "checkbox" \
414 "winboot" \
415 "auto" \
416 "$winboot"
417 label "winboot" \
418 "$(gettext 'Enable Windows Dual-Boot.')" \
419 "$(gettext "At start-up, you will be asked whether you want to boot into \
420 Windows&trade; or SliTaz GNU/Linux.")"
421 error="$?"
422 error_msg "$error" \
423 "winboot"
424 }
426 errors_msg()
427 {
428 if [ "$CHECK" ]; then
429 echo "<span class=\"alert\">"
430 p $(gettext "Errors found. Please check your settings.")
431 echo "</span>"
432 fi
433 }
435 select_settings()
436 {
437 local settings="$(/usr/sbin/tazinst get settings "$INSTFILE")"
438 CHECK=$(GET CHECK)
439 errors_msg
440 h4 $(gettext "Select source media:")
441 open_div_class "box"
442 open_div_class "media"
443 select_source
444 close_div
445 close_div
446 h4 $(gettext "Select destination")
447 open_div_class "box"
448 select_root_uuid
449 printf "$settings" | grep -q "root_format" \
450 && select_root_format
451 close_div
452 select_options
453 open_div_class "options"
454 printf "$settings" | grep -q "home_uuid" && select_home_uuid
455 printf "$settings" | grep -q "home_format" \
456 && select_home_format
457 printf "$settings" | grep -q "hostname" && select_hostname
458 printf "$settings" | grep -q "root_pwd" && select_root_pwd
459 printf "$settings" | grep -q "user_login" && select_user_login
460 printf "$settings" | grep -q "user_pwd" && select_user_pwd
461 close_div
462 open_div_class "bootloader"
463 printf "$settings" | grep -q "bootloader" && select_bootloader
464 printf "$settings" | grep -q "winboot" && select_winboot
465 close_div
466 br
467 }
469 #--------------
470 # execute page
471 #--------------
473 save_settings()
474 {
475 h5 $(gettext "Checking settings...")
476 # install type
477 /usr/sbin/tazinst set media "$(GET MEDIA)" "$INSTFILE"
478 # source File
479 case "$(/usr/sbin/tazinst get media "$INSTFILE")" in
480 usb)
481 /usr/sbin/tazinst set source "$(GET SRC_USB)" "$INSTFILE" ;;
482 iso)
483 /usr/sbin/tazinst set source "$(GET SRC_ISO)" "$INSTFILE" ;;
484 web)
485 /usr/sbin/tazinst set source "$(GET SRC_WEB)" "$INSTFILE" ;;
486 esac
487 # set defined url
488 [ $(GET URL) ] && SRC_WEB=$(GET URL)
489 # root Partition
490 /usr/sbin/tazinst set root_uuid "$(GET ROOT_UUID)" "$INSTFILE"
491 # format root partition
492 [ "$(GET ROOT_FORMAT)" ] \
493 && /usr/sbin/tazinst set root_format "$(GET ROOT_FORMAT)" "$INSTFILE" \
494 || /usr/sbin/tazinst unset root_format "$INSTFILE"
495 # home Partition
496 if [ "$(GET HOME_UUID)" ] ; then
497 /usr/sbin/tazinst set home_uuid "$(GET HOME_UUID)" "$INSTFILE"
498 [ "$(GET HOME_FORMAT)" ] \
499 && /usr/sbin/tazinst set home_format "$(GET HOME_FORMAT)" \
500 "$INSTFILE" \
501 || /usr/sbin/tazinst unset home_format "$INSTFILE"
502 else
503 /usr/sbin/tazinst unset home_uuid "$INSTFILE"
504 /usr/sbin/tazinst unset home_format "$INSTFILE"
505 fi
506 # hostname
507 /usr/sbin/tazinst set hostname "$(GET HOSTNAME)" "$INSTFILE"
508 # root pwd
509 /usr/sbin/tazinst set root_pwd "$(GET ROOT_PWD)" "$INSTFILE"
510 # user Login
511 /usr/sbin/tazinst set user_login "$(GET USER_LOGIN)" "$INSTFILE"
512 # user Pwd
513 /usr/sbin/tazinst set user_pwd "$(GET USER_PWD)" "$INSTFILE"
514 # win Dual-Boot
515 /usr/sbin/tazinst set winboot "$(GET WINBOOT)" "$INSTFILE"
516 # bootloader
517 if [ "$(GET BOOTLOADER)" == "auto" ]; then
518 /usr/sbin/tazinst set bootloader "auto" "$INSTFILE"
519 else
520 /usr/sbin/tazinst unset bootloader "$INSTFILE"
521 /usr/sbin/tazinst unset winboot "$INSTFILE"
522 fi
523 input_hidden "CHECK" "yes"
524 }
526 tazinst_run()
527 {
528 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")" error
529 h4 "Proceeding to: $mode"
530 /usr/sbin/tazinst execute "$INSTFILE" | /bin/busybox awk '{
531 num=$1+0
532 if (num>0 && num<=100){
533 print "<script type=\"text/javascript\">"
534 printf "document.write(\047<div id=\"progress\">"
535 printf "<img src=\"/styles/default/images/loader.gif\" />"
536 printf $1 "&#37; " substr($0, length($1)+2, 40)
537 print "</div>\047)"
538 print "</script>"
539 }
540 }'
541 # end_of_install
542 if /usr/sbin/tazinst log | grep -q "x-x-" ; then
543 error=1
544 echo "<script type=\"text/javascript\">"
545 printf "document.write(\047<div id=\"progress\">"
546 printf "<img src=\"/styles/default/images/stop.png\" />"
547 printf "$(gettext 'Errors encountered.')"
548 printf "</div>\047)\n"
549 echo "</script>"
550 br
551 br
552 /usr/sbin/tazinst log | \
553 /bin/busybox awk '$1 == "-x-x-",$1 == "x-x-x"' | sed 's/-x-x-/ /' \
554 | grep -v "x-x-x"
555 else
556 error=0
557 echo "<script type=\"text/javascript\">"
558 printf "document.write(\047<div id=\"progress\">"
559 printf "<img src=\"/styles/default/images/tux.png\" />"
560 printf "$(gettext 'Process completed!')"
561 printf "</div>\047)\n"
562 echo "</script>"
563 br
564 br
565 br
566 p $(gettext "Installation is now finished, you can exit the installer \
567 or reboot on your new SliTaz GNU/Linux operating system.")
568 fi
569 return "$error"
571 }
573 tazinst_log()
574 {
575 h4 $(gettext "Tazinst log")
576 printf "<pre>$(/usr/sbin/tazinst log | sed 's/\%/ percent/g')</pre>"
577 }
580 #-----------------
581 # page navigation
582 #-----------------
584 display_mode()
585 {
586 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
587 case $mode in
588 install)
589 open_div_id "wrapper"
590 h4 $(gettext "Install SliTaz")
591 p $(gettext "You're going to install SliTaz on a partition of your \
592 hard disk drive. If you decide to format your HDD, all data will be \
593 lost. If you do not format, all data except for any existing /home \
594 directory will be removed, the home directory will be kept as is.")
595 close_div
596 ;;
597 upgrade)
598 open_div_id "wrapper"
599 h4 $(gettext "Upgrade SliTaz")
600 p $(gettext "You're going to upgrade an already installed SliTaz \
601 system on your hard disk drive. Your /home /etc /var/www directories \
602 will be kept, all other directories will be removed. Any additional \
603 packages added to your old Slitaz system will be updated as long you \
604 have an active internet connection.")
605 close_div
606 ;;
607 esac
608 }
610 moveto_page()
611 {
612 local back="$1" next="$2" back_msg next_msg
613 case "$back" in
614 partitioning)
615 back_msg=$(gettext 'Back to partitioning') ;;
616 input)
617 back_msg=$(gettext 'Back to entering settings') ;;
618 *)
619 back_msg=$(gettext 'Back to Installer Start Page') ;;
620 esac
621 case "$next" in
622 execute|run)
623 next_msg=$(gettext 'Proceed to SliTaz installation') ;;
624 reboot)
625 next_msg=$(gettext 'Installation complete. You can now restart') ;;
626 failed)
627 next_msg=$(gettext 'Installation failed. See log') ;;
628 input)
629 next_msg=$(gettext 'Continue installation.') ;;
630 *)
631 next_msg=$(gettext 'Back to Installer Start Page') ;;
632 esac
633 hr
634 input_hidden "page" \
635 "$next"
636 a "$back" \
637 "$SCRIPT_NAME?page=$back" \
638 "$back_msg"
639 input "submit" \
640 "" \
641 "$next_msg"
642 }
644 moveto_home()
645 {
646 local msg=$(gettext 'Back to Installer Start Page')
647 a "home" \
648 "$SCRIPT_NAME?page=home" \
649 "$msg"
650 }
652 page_redirection()
653 {
654 local page="$1"
655 cat <<EOT
656 <!DOCTYPE html>
657 <html>
658 <head>
659 <meta charset="utf-8">
660 <title>$(gettext "A web page that points a browser to a different page after \
661 2 seconds")</title>
662 <meta http-equiv="refresh" content="0; URL=$SCRIPT_NAME?page=$1">
663 <meta name="keywords" content="automatic redirection">
664 </head>
665 <body>
666 <p>$(gettext "If your browser doesn't automatically redirect within a few \
667 seconds, you may want to go there manually")
668 <a href="$SCRIPT_NAME?page=$page">$(gettext "here")</a></p>
669 </body>
670 </html>
671 EOT
672 }
674 #----------
675 # checking
676 #----------
678 check_ressources()
679 {
680 local errorcode=0
681 comment "check_ressources"
682 if ! [ -x /usr/sbin/tazinst ] ; then
683 h4 $(gettext "Tazinst Error")
684 p $(gettext "<strong>tazinst</strong>, the backend to slitaz-installer \
685 is missing. Any installation can not be done without tazinst.")
686 p $(gettext "Check tazinst permissions, or reinstall the \
687 slitaz-installer package.")
688 errorcode=1
689 else
690 # check tazinst minimum version
691 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
692 r=$TAZINST_MINIMUM_VERSION
693 if ! (echo "$v" | /bin/busybox awk -v r=$r \
694 '{v=$v+0}{ if (v < r) exit 1}') ; then
695 h4 $(gettext "Tazinst Error")
696 p $(gettext "<strong>tazinst</strong>, the slitaz-installer \
697 backend, is not at the minimum required version. Any installation \
698 cannot be done without tazinst.")
699 p $(gettext "Reinstall the slitaz-installer package, or use \
700 tazinst in CLI mode.")
701 errorcode=1
702 fi
703 # check tazinst maximum version
704 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
705 r=$TAZINST_MAXIMUM_VERSION
706 if ! (echo "$v" | /bin/busybox awk -v r=$r \
707 '{v=$v+0}{ if (v > r) exit 1}') ; then
708 h4 $(gettext "Tazinst Error")
709 p $(gettext "<strong>tazinst</strong>, the slitaz-installer \
710 backend, is at a higher version than the maximum authorized \
711 by the slitaz-installer. Any installation cannot be done.")
712 p $(gettext "Reinstall the slitaz-installer package, or use \
713 tazinst in CLI mode.")
714 errorcode=1
715 fi
716 fi
717 return $errorcode
718 }
721 #---------------
722 # html snippets
723 #---------------
725 br()
726 {
727 echo "<br />"
728 }
730 hr()
731 {
732 echo "<hr />"
733 }
735 comment()
736 {
737 echo "<!-- $@ -->"
738 }
740 a()
741 {
742 echo "<a class=\"button\" value=\"$1\" href=\"$2\">$3</a>"
743 }
745 open_div()
746 {
747 echo "<div>"
748 }
750 open_div_id()
751 {
752 echo "<div id=\"$1\">"
753 }
755 open_div_class()
756 {
757 echo "<div class=\"$1\">"
758 }
760 close_div()
761 {
762 echo "</div>"
763 }
765 p()
766 {
767 echo "<p>$@</p>"
768 }
770 h4()
771 {
772 echo "<h4>$@</h4>"
773 }
775 h5()
776 {
777 echo "<h5>$@</h5>"
778 }
780 label()
781 {
782 local setting="$1" label="$2" title="$3" name="$4" error=0
783 [ -z "$name" ] && name="$setting"
784 printf "<label for=\"$name\""
785 [ "$title" ] && echo " title=\"$title\">" || echo ">"
786 # display label in red in case of error
787 if [ "$CHECK" ]; then
788 /usr/sbin/tazinst check "$setting" "$INSTFILE"
789 error="$?"
790 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
791 printf "<span class=\"alert\">"
792 printf "$label"
793 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
794 printf "<sup>*</sup></span>"
795 else
796 printf "$label"
797 fi
798 echo "</label>"
799 return "$error"
800 }
802 label_media()
803 {
804 local id="$1" label="$2" media="$3" title="$4" retcode=0
805 if [ "$media" == "$id" ]; then
806 label "source" \
807 "$label" \
808 "$title" \
809 "$media"
810 retcode="$?"
811 else
812 printf "<label for=\"$id\""
813 [ "$title" ] && echo " title=\"$title\">" || echo ">"
814 echo "$label</label>"
815 fi
816 return "$retcode"
817 }
819 error_msg()
820 {
821 local error="$1" setting="$2" line="$3"
822 if [ "$CHECK" ]; then
823 if [ "$error" -gt "0" ]; then
824 [ "$error" -lt "128" ] && printf "<span class=\"alert\">" \
825 || printf "<span class=\"warning\">"
826 if [ "$line" ]; then
827 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1 | \
828 /bin/busybox awk -v LINE="$line" '{if (NR==LINE){print}}'
829 else
830 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1
831 fi
832 echo "</span>"
833 fi
834 fi
835 }
837 select()
838 {
839 local list="$1" selected="$2" name="$3" type="$4" none="$(gettext 'None')"
840 printf "$list" | /bin/busybox awk -v SELECTED="$selected" -v NONE="$none" \
841 -v NAME="$name" -v TYPE="$type" 'BEGIN{
842 TYPE=TYPE+0
843 print "<select name=\"" NAME "\">"
844 print "<option value=>< " NONE " ></option>"
845 }
846 {
847 printf "<option value=\"" $1 "\""
848 if ($1 == SELECTED) printf " selected"
849 if (TYPE == 0)
850 print ">" $0 "</option>"
851 if (TYPE == 1)
852 print ">" substr($0,12) "</option>"
853 if (TYPE == 2)
854 print ">" $2 "</option>"
855 }
856 END{
857 print "</select>"
858 }'
859 }
861 input()
862 {
863 local type="$1" name="$2" value="$3" selected="$4" help="$5" action="$6"
864 printf "<input type=\"$type\" id=\"$name\" list=\"list_$name\" "
865 printf "name=\"$(printf $name | tr [a-z] [A-Z])\" class=\"$type\" "
866 [ "$value" ] && printf "value=\"$value\" "
867 [ "$value" == "$selected" ] && printf "checked "
868 [ "$action" ] && printf \
869 "onInput=\"document.getElementById('$action').checked = true;\" "
870 [ "$help" ] && echo "placeholder=\"$help\" />" || echo "/>"
871 }
873 input_media()
874 {
875 local id="$1" media="$2"
876 echo -n "<input type=\"radio\" name=\"MEDIA\" value=\"$id\" id=\"$id\" "
877 echo "$([ "$media" == "$id" ] && echo 'checked') />"
878 }
880 input_hidden()
881 {
882 echo "<input type=\"hidden\" name=\"$1\" value=\"$2\" />"
883 }
885 datalist()
886 {
887 local list="$1" name="$2" none="$(gettext 'None')"
888 echo "<datalist id=\"list_$name\">"
889 # workaround for browsers that don’t support the datalist element..
890 echo "<select class=\"workaround\" id=\"sel_$name\" \
891 onChange='displaySelValue(\"sel_$name\",\"$name\")' \
892 onBlur='displaySelValue(\"sel_$name\",\"$name\")'>"
893 # workaround ..end
894 printf "$list" | /bin/busybox awk -v NONE="$none" 'BEGIN{
895 line=0
896 }
897 {
898 TEXT=$1
899 sub(".*/","",TEXT)
900 print "<option value=\"" $1 "\">" TEXT "</option>"
901 line++
902 }
903 END{
904 if (line < 1)
905 print "<option value=>< " NONE " ></option>"
906 }'
907 echo "</select>"
908 echo "</datalist>"
909 }
911 format()
912 {
913 list_fs="$1" selected="$2" name="$3" none="$(gettext 'Do not format')"
914 cat << EOT
915 <label for="$name" title="$(gettext "To format this partition, \
916 select a filesystem, usually it's safe to use ext4")">
917 $(gettext "Formatting option:")</label>
918 EOT
919 printf "$list_fs" | /bin/busybox awk -v SELECTED=$selected -v NONE="$none" \
920 -v NAME="$name" 'BEGIN{
921 RS=" "
922 print "<select name=\"" NAME "\">"
923 print "<option value=\"\">" NONE "</option>"
924 line=0
925 }
926 {
927 printf "<option value=\"" $1 "\""
928 if ($1 == SELECTED) printf " selected"
929 print ">" $0 "</option>"
930 line++
931 }
932 END{
933 if (line < 1)
934 print "<option value=>< " NONE " ></option>"
935 print "</select>"
936 }'
937 }
939 button()
940 {
941 local action="$1" msg="$2" title="$3"
942 echo "<a class=\"button\" href=\"$SCRIPT_NAME?page=$action\" \
943 title=\"$title\">$msg</a>"
944 }
946 form_start()
947 {
948 local name="$1"
949 cat <<EOT
950 <form name="Form_$name" method="get" onsubmit="return true" \
951 action="$SCRIPT_NAME">
952 EOT
953 }
955 form_end()
956 {
957 echo "</form>"
958 }
960 xhtml_header()
961 {
962 cat << EOT
963 <!DOCTYPE html>
964 <html xmlns="http://www.w3.org/1999/xhtml" lang="$(echo $LANG | cut -f1 -d_)">
965 <head>
966 <title>$(gettext "SliTaz Installer")</title>
967 <meta charset="utf-8" />
968 <link rel="shortcut icon" href="/styles/$STYLE/favicon.ico" />
969 <style type="text/css">
970 .box label {
971 display:inline-block;
972 vertical-align:middle;
973 width: 130px;
974 }
975 .media label {
976 display:inline-block;
977 vertical-align:middle;
978 width: 110px;
979 }
980 .options label {
981 display:inline-block;
982 vertical-align:middle;
983 width: 140px;
984 }
985 .box .text {
986 width: 350px;
987 }
988 input {margin-bottom:3px;}
989 span.alert {color: red}
990 span.warning { color: darkgray}
991 #progress {
992 background-color: #f8f8f8;
993 border: 1px solid #ddd;
994 color: #666;
995 cursor: progress;
996 position: absolute;
997 width: 348px;
998 padding: 4px 4px 2px;
999 }
1000 </style>
1001 <link rel="stylesheet" type="text/css" href="/styles/$STYLE/style.css" />
1002 <!-- Function to hide the loading message when page is generated. -->
1003 <script type="text/javascript">
1004 function showProgress(){
1005 document.getElementById("progress").style.display='none';
1007 </script>
1008 <!-- workaround for browsers that don’t support the datalist element -->
1009 <style type="text/css">
1010 .workaround {width: 110px;}
1011 </style>
1012 <script>
1013 function displaySelValue(selectId,inputId)
1015 var slct = document.getElementById(selectId);
1016 var input = document.getElementById(inputId);
1017 document.getElementById("src_iso").value="";
1018 document.getElementById("src_web").value="";
1019 if (inputId =="src_iso"){
1020 document.getElementById("iso").checked = true;
1022 if (inputId =="src_web"){
1023 document.getElementById("web").checked = true;
1025 input.value = slct.options[slct.selectedIndex].value;
1028 </script>
1029 <!-- workaround end -->
1030 </head>
1031 <body onload="showProgress()">
1032 </head>
1033 <body>
1035 <!--
1036 <div id="header">
1037 <h1>$(gettext "SliTaz Installer")</h1>
1038 </div>
1039 -->
1041 <!-- Page content -->
1042 <div id="content">
1043 EOT
1046 xhtml_footer()
1048 cat << EOT
1049 <!-- End of content-->
1050 </div>
1052 <div id="footer">
1053 $(gettext "Copyright") &copy; 2012–2013
1054 <a href="http://www.slitaz.org/">SliTaz GNU/Linux</a>
1055 — <a href="/index.cgi?file=/usr/share/licenses/bsd.txt">
1056 $(gettext "BSD License")</a>
1057 </div>
1059 </body>
1060 </html>
1061 EOT
1066 # main
1069 header
1071 case "$(GET page)" in
1072 home)
1073 xhtml_header
1074 select_action
1075 select_install
1076 select_upgrade
1077 ;;
1078 install)
1079 xhtml_header
1080 /usr/sbin/tazinst set mode install "$INSTFILE"
1081 page_redirection partitioning
1082 ;;
1083 partitioning)
1084 xhtml_header
1085 form_start
1086 display_mode
1087 select_gparted
1088 moveto_page home input
1089 form_end
1090 ;;
1091 gparted)
1092 exec_gparted
1093 xhtml_header
1094 page_redirection partitioning
1095 ;;
1096 upgrade)
1097 xhtml_header
1098 /usr/sbin/tazinst set mode upgrade "$INSTFILE"
1099 page_redirection input
1100 ;;
1101 input)
1102 xhtml_header
1103 form_start
1104 display_mode
1105 select_settings
1106 moveto_page partitioning execute
1107 form_end
1108 ;;
1109 execute)
1110 xhtml_header
1111 form_start
1112 display_mode
1113 save_settings
1114 if ! (/usr/sbin/tazinst check all $INSTFILE > /dev/null); then
1115 page_redirection "input&CHECK=yes"
1116 else
1117 tazinst_run && moveto_page home reboot \
1118 || moveto_page input failed
1119 fi
1120 form_end
1121 ;;
1122 reboot)
1123 /usr/sbin/tazinst clean "$INSTFILE"
1124 reboot ;;
1125 failed)
1126 xhtml_header
1127 form_start
1128 tazinst_log
1129 moveto_home
1130 form_end
1131 ;;
1132 *)
1133 xhtml_header
1134 if check_ressources; then
1135 /usr/sbin/tazinst new "$INSTFILE"
1136 page_redirection home
1137 fi
1138 ;;
1139 esac
1141 xhtml_footer
1143 exit 0