tazinst view installer.cgi @ rev 19

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