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