tazinst view installer.cgi @ rev 2

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