tazinst view installer.cgi @ rev 46

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