tazinst view installer.cgi @ rev 110

Tazinst: fix iso already mounted error (thanks ben, again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jan 17 17:18:42 2021 +0000 (2021-01-17)
parents ea2154c4b6d5
children 34985ea0d32f
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for Tazinst, the SliTaz installer.
4 #
5 # Copyright (C) 2012-2017 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=$(_ '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 # menu
36 #------
38 case "$1" in
39 menu)
40 cat <<EOT
41 <li tabindex="0">
42 <span>$(_ 'Installation')</span>
43 <menu>
44 <li><a data-icon="install"
45 href="installer.cgi" data-root>$(_ 'Installation')</a></li>
46 <li><a data-icon="slitaz"
47 href="installer.cgi?page=install" data-root>$(_ 'Install SliTaz')</a></li>
48 <li><a data-icon="upgrade"
49 href="installer.cgi?page=upgrade" data-root>$(_ 'Upgrade system')</a></li>
50 <li><a data-icon="slitaz"
51 href="installer.cgi?page=evaluate" data-root>$(_ 'Evaluate SliTaz')</a></li>
52 </menu>
53 </li>
54 EOT
55 exit
56 esac
59 #-----------
60 # home page
61 #-----------
63 select_action() {
64 cat <<EOT
65 <!-- Welcome message -->
67 <h2>$(_ 'Welcome to the SliTaz Installer!')</h2>
69 <p>$(_ "The SliTaz Installer installs or upgrades SliTaz to a \
70 hard disk drive from a device like a Live-CD or LiveUSB key, from a SliTaz \
71 ISO file, or from the web by downloading an ISO file.")</p>
73 <p>$(_ "Windows&trade; users can evaluate SliTaz in the directory \
74 \\slitaz on their hard disk.")</p>
76 <p>$(_ "Which type of installation do you want to start?")</p>
77 EOT
78 }
81 select_install() {
82 cat <<EOT
83 <!-- Install message -->
85 <section>
86 <header>$(_ 'Install')</header>
88 <div>
89 <p>$(_ "Install SliTaz on a partition of your hard disk drive. If \
90 you decide to format your partition, all data will be lost. If you do not \
91 format, all data except for any existing /home directory will be removed \
92 (the home directory will be kept as is).")</p>
93 <p>$(_ "Before installation, you may need to create or resize \
94 partitions on your hard disk drive in order to make space for SliTaz \
95 GNU/Linux. You can graphically manage your partitions with Gparted")</p>
96 </div>
98 <footer>
99 <form>
100 <button type="submit" name="page" value="install" data-icon="slitaz"
101 title="$(_ 'Proceed to a new SliTaz installation')"
102 >$(_ 'Install SliTaz')</button>
103 </form>
104 </footer>
105 </section>
106 EOT
107 }
110 select_upgrade() {
111 cat <<EOT
112 <!-- Upgrade message -->
114 <section>
115 <header>$(_ 'Upgrade')</header>
117 <div>
118 <p>$(_ "Upgrade an already installed SliTaz system on your hard disk \
119 drive. Your /home /etc /var/www directories will be kept, all other \
120 directories will be removed. Any additional packages added to your old \
121 SliTaz system will be updated as long you have an active internet connection.")</p>
122 </div>
124 <footer>
125 <form>
126 <button type="submit" name="page" value="upgrade" data-icon="upgrade"
127 title="$(_ 'Upgrade an existing SliTaz system')"
128 >$(_ 'Upgrade SliTaz')</button>
129 </form>
130 </footer>
131 </section>
132 EOT
133 }
136 select_evaluate() {
137 cat <<EOT
138 <!-- Evaluate message -->
140 <section>
141 <header>$(_ 'Evaluate: Without Partitioning / Formating')</header>
143 <div>
144 <p>$(_ 'SliTaz and Windows&trade; can coexist in the same partition.')</p>
145 <p>$(_ "SliTaz will be in the %s directory like UMSDOS used to do \
146 in the previous century..." '\slitaz')</p>
147 </div>
149 <form action="boot.cgi">
150 <input type="hidden" name="iso"/>
151 <input type="hidden" name="action" value="install"/>
152 <table>
153 <tr><td>$(_ 'ISO image file full path')
154 </td>
155 <td>$(file_chooser "iso" "/dev/cdrom")</td></tr>
156 <tr><td>$(_ 'Target partition')</td>
157 <td><select name="instdev">
158 <option value="/dev/null">$(_ 'Choose a partition')</option>
159 EOT
160 blkid | grep -iE "(msdos|vfat|ntfs|ext[234]|xfs|btrfs)" | \
161 sed -e 's|[A-Z]*ID="[^"]*"||g;s| SEC[^ ]*||;s|LABEL=||;s|:||' \
162 -e 's|TYPE="\([^"]*\)"|\1|;s|/dev/||' | \
163 while read dev label type; do
164 echo -n "<option value=\"/dev/$dev\">/dev/$dev $label $type "
165 echo "$(blk2h < /sys/block/${dev:0:3}/$dev/size)</option>"
166 done
167 cat <<EOT
168 </select></td></tr>
169 </table>
170 <button type="submit" data-icon="install">$(_ 'Install')</button>
171 </form>
172 </section>
173 EOT
174 }
177 #--------------------
178 # partitioning page
179 #--------------------
181 exec_gparted() {
182 /bin/su - -c \
183 "exec env DISPLAY=':0.0' XAUTHORITY='/var/run/slim.auth' gparted" >/dev/null 2>&1
184 }
187 select_gparted() {
188 cat <<EOT
189 <!-- GParted message -->
191 <section>
192 <header>$(_ 'Partitioning')</header>
194 <div>
195 <p>$(_ "On most used systems, the hard drive is already dedicated to \
196 partitions for Windows&trade;, or Linux, or another operating \
197 system. You'll need to resize these partitions in order to make space for \
198 SliTaz GNU/Linux. SliTaz will co-exist with other operating systems already \
199 installed on your hard drive.")</p>
200 <p>$(_ "The amount of space needed depends on how much software you \
201 plan to install and how much space you require for users. It's conceivable \
202 that you could run a minimal SliTaz system in 300 megs or less, but 2 gigs \
203 is indeed more comfy.")</p>
204 <p>$(_ "A separate home partition and a partition that will be used \
205 as Linux swap space may be created if needed. SliTaz detects and uses swap \
206 partitions automatically.")</p>
207 <hr/>
208 <p>$(_ "You can graphically manage your partitions with GParted. \
209 GParted is a partition editor for graphically managing your disk partitions. \
210 GParted allows you to create, destroy, resize and copy partitions without \
211 data loss.")</p>
212 <p>$(_ "GParted supports ext2, ext3, ext4, linux swap, ntfs and \
213 fat32 filesystems right out of the box. Support for xjs, jfs, hfs and other \
214 filesystems is available as well but you first need to add drivers for these \
215 filesystems by installing the related packages xfsprogs, jfsutils, linux-hfs \
216 and so on.")</p>
217 </div>
219 <footer>
220 <!-- Launch GParted -->
221 <form>
222 <button type="submit" name="page" value="gparted" data-icon="hdd"
223 title="$(_ 'Launch GParted, the partition editor tool')"
224 >$(_ 'Execute GParted')</button>
225 </form>
226 </footer>
227 </section>
229 <h5>$(_ 'Continue installation')</h5>
231 <p>$(_ "Once you've made room for SliTaz on your drive, you should \
232 be able to continue installation.")</p>
233 EOT
234 }
237 #------------
238 # input page
239 #------------
241 select_source() {
242 local media="$(/usr/sbin/tazinst get media "$INSTFILE")"
243 local source="$(/usr/sbin/tazinst get source "$INSTFILE")"
244 local list_media="$(/usr/sbin/tazinst list media)"
245 local error
247 # set default media
248 [ -n "$media" ] || media="$(tazinst list media | cut -d ' ' -f1)"
250 comment "Source selection"
251 # cdrom
252 if printf '%s' "$list_media" | grep -q "cdrom"; then
253 input_media "cdrom" \
254 "$media"
255 label_media "cdrom" \
256 "$(_ 'LiveCD')" \
257 "$media" \
258 "$(_ 'Use the SliTaz LiveCD')"
259 br
260 fi
261 # usb
262 if printf '%s' "$list_media" | grep -q "usb"; then
263 input_media "usb" \
264 "$media"
265 label_media "usb" \
266 "$(_ 'LiveUSB:')" \
267 "$media" \
268 "$(_ 'Enter the partition where SliTaz Live is located on your USB Key')"
270 error="$?"
271 select "$(/usr/sbin/tazinst list usb "$INSTFILE" | cut -d' ' -f2)" \
272 "$source" \
273 "SRC_USB"
274 error_msg "$error" \
275 "source" \
276 2
277 br
278 fi
279 # iso
280 input_media "iso" \
281 "$media"
282 label_media "iso" \
283 "$(_ 'ISO file:')" \
284 "$media" \
285 "$(_ 'Select a SliTaz ISO file located on a local disk')"
286 error="$?"
287 if [ "$media" = "iso" ]; then
288 input "text" \
289 "src_iso" \
290 "$source" "" \
291 "$(_ 'Select an ISO or enter the full path to the ISO file')"\
292 "iso"
293 else
294 input "text" \
295 "src_iso" \
296 "" \
297 "none" \
298 "$(_ 'Select an ISO or enter the full path to the ISO file')"\
299 "iso"
300 fi
301 datalist "$(/usr/sbin/tazinst list iso "$INSTFILE")" \
302 "src_iso"
303 error_msg "$error" \
304 "source"
305 br
306 # web
307 input_media "web" \
308 "$media"
309 label_media "web" \
310 "$(_ 'Web:')" \
311 "$media" \
312 "$(_ 'Select a SliTaz version on the Web')"
313 error="$?"
315 if [ "$media" = "web" ]; then
316 input "text" \
317 "src_web" \
318 "$source" "" \
319 "$(_ 'Select a version or enter the full URL to an ISO file')"\
320 "web"
321 else
322 input "text" \
323 "src_web" \
324 "" \
325 "none" \
326 "$(_ 'Select a version or enter the full URL to an ISO file')"\
327 "web"
328 fi
329 datalist "$(/usr/sbin/tazinst help web "$INSTFILE")" \
330 "src_web"
331 error_msg "$error" \
332 "source"
333 }
335 select_root_uuid()
336 {
337 local root_uuid="$(/usr/sbin/tazinst get root_uuid "$INSTFILE")"
338 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
339 comment "root_uuid selection"
340 if [ "$mode" = "upgrade" ]; then
341 label "root_uuid" \
342 "$(_ 'Existing SliTaz partition to upgrade:')" \
343 "$(_ 'Specify the partition containing the system to upgrade')"
344 error="$?"
345 else
346 label "root_uuid" \
347 "$(_ 'Install SliTaz to partition:')" \
348 "$(_ 'Specify the partition where to install SliTaz')"
349 error="$?"
350 fi
351 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
352 "$root_uuid" \
353 "ROOT_UUID" \
354 0
355 error_msg "$error" \
356 "root_uuid" \
357 0
358 br
359 }
361 select_root_format()
362 {
363 local root_format="$(/usr/sbin/tazinst get root_format "$INSTFILE")"
364 comment "root_format selection"
365 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
366 "$root_format" \
367 "ROOT_FORMAT"
368 }
370 select_home_uuid() {
371 local home_uuid="$(/usr/sbin/tazinst get home_uuid "$INSTFILE")"
373 cat <<EOT
374 <!-- home_uuid selection -->
376 <fieldset>
377 <legend>$(_ 'home partition')</legend>
379 $(
380 label "home_uuid" \
381 "$(_ 'Separate partition for %s:' '/home')" \
382 "$(_ 'Specify the partition containing %s' '/home')"
383 select "$(/usr/sbin/tazinst list uuid "$INSTFILE")" \
384 "$home_uuid" \
385 "HOME_UUID" \
386 0
387 )
388 <br/>
389 EOT
390 }
392 select_home_format()
393 {
394 local home_format="$(/usr/sbin/tazinst get home_format "$INSTFILE")"
396 comment "home_format selection"
397 format "$(/usr/sbin/tazinst list format "$INSTFILE")" \
398 "$home_format" \
399 "HOME_FORMAT"
400 cat <<EOT
401 </fieldset>
402 EOT
403 }
406 select_hostname() {
407 local hostname="$(/usr/sbin/tazinst get hostname "$INSTFILE")" error
409 cat <<EOT
410 <!-- hostname selection -->
412 <fieldset>
413 <legend>$(_ 'Hostname')</legend>
414 $(
415 label "hostname" \
416 "$(_ 'Set Hostname to:')" \
417 "$(_ 'Hostname configuration allows you to specify the machine name')"
418 error=$?
419 input "text" \
420 "HOSTNAME" \
421 "$hostname" \
422 "" \
423 "$(_ 'Name of your system')"
424 error_msg "$error" \
425 "hostname" \
426 2
427 )
428 </fieldset>
429 EOT
430 }
433 select_root_pwd() {
434 local root_pwd="$(/usr/sbin/tazinst get root_pwd "$INSTFILE")" error
436 cat <<EOT
437 <!-- root_pwd selection -->
439 <fieldset>
440 <legend>$(_ 'Root superuser')</legend>
441 $(
442 label "root_pwd" \
443 "$(_ 'Root password:')" \
444 "$(_ 'Enter the password for root')"
445 error="$?"
446 input "text" \
447 "ROOT_PWD" \
448 "$root_pwd" \
449 "" \
450 "$(_ 'Password of root')"
451 error_msg "$error" \
452 "root_pwd"
453 )
454 </fieldset>
455 EOT
456 }
459 select_user_login() {
460 local user_login="$(/usr/sbin/tazinst get user_login "$INSTFILE")" error
462 cat <<EOT
463 <!-- user_login selection -->
465 <fieldset>
466 <legend>$(_ 'User')</legend>
467 $(
468 label "user_login" \
469 "$(_ 'User login:')" \
470 "$(_ 'Enter the name of the first user')"
471 error="$?"
472 input "text" \
473 "USER_LOGIN" \
474 "$user_login" \
475 "" \
476 "$(_ 'Name of the first user')"
477 error_msg "$error" \
478 "user_login" \
479 2
480 )
481 <br/>
482 EOT
483 }
486 select_user_pwd()
487 {
488 local user_pwd="$(/usr/sbin/tazinst get user_pwd "$INSTFILE")" error
490 label "user_pwd" \
491 "$(_ 'User password:')" \
492 "$(_ 'The password for default user')"
493 error="$?"
494 input "text" \
495 "USER_PWD" \
496 "$user_pwd" \
497 "" \
498 "$(_ 'Password of the first user')"
499 error_msg "$error" \
500 "user_pwd"
501 cat <<EOT
502 </fieldset>
503 EOT
504 }
507 select_bootloader()
508 {
509 local bootloader="$(/usr/sbin/tazinst get bootloader "$INSTFILE")" error
511 cat <<EOT
512 <!-- bootloader selection -->
514 <fieldset>
515 <legend>$(_ 'Bootloader')</legend>
517 $(
518 input "checkbox" \
519 "bootloader" \
520 "auto" \
521 "$bootloader"
522 label "bootloader" \
523 "$(_ 'Install a bootloader.')" \
524 "$(_ "Usually you should answer yes, unless you want to install \
525 a bootloader by hand yourself.")"
526 error="$?"
527 error_msg "$error" \
528 "bootloader"
529 )
530 <br/>
531 EOT
532 }
535 select_winboot()
536 {
537 local winboot="$(/usr/sbin/tazinst get winboot "$INSTFILE")" error
539 comment "winboot selection"
540 input "checkbox" \
541 "winboot" \
542 "auto" \
543 "$winboot"
544 label "winboot" \
545 "$(_ 'Enable Windows Dual-Boot.')" \
546 "$(_ "At start-up, you will be asked whether you want to boot \
547 into Windows&trade; or SliTaz GNU/Linux.")"
548 error="$?"
549 error_msg "$error" \
550 "winboot"
551 cat <<EOT
552 </fieldset>
553 EOT
554 }
557 errors_msg()
558 {
559 if [ "$CHECK" ]; then
560 echo '<span class="alert">'
561 p "$(_ "Errors found. Please check your settings.")"
562 echo '</span>'
563 fi
564 }
567 select_settings() {
568 local settings="$(/usr/sbin/tazinst get settings "$INSTFILE")"
569 CHECK=$(GET CHECK)
570 errors_msg
572 cat<<EOT
573 <fieldset>
574 <legend>$(_ 'Select source media:')</legend>
576 <div class="media">$(select_source)</div>
577 </fieldset>
580 <fieldset>
581 <legend>$(_ 'Select destination')</legend>
583 <div>$(
584 select_root_uuid
585 printf '%s' "$settings" | grep -q "root_format" && select_root_format
586 )</div>
587 </fieldset>
590 <fieldset id="options">
591 <legend>$(_ 'Options')</legend>
593 <div class="options">$(
594 printf '%s' "$settings" | grep -q "home_uuid" && select_home_uuid
595 printf '%s' "$settings" | grep -q "home_format" && select_home_format
596 printf '%s' "$settings" | grep -q "hostname" && select_hostname
597 printf '%s' "$settings" | grep -q "root_pwd" && select_root_pwd
598 printf '%s' "$settings" | grep -q "user_login" && select_user_login
599 printf '%s' "$settings" | grep -q "user_pwd" && select_user_pwd
600 )</div>
602 <div class="bootloader">$(
603 printf '%s' "$settings" | grep -q "bootloader" && select_bootloader
604 printf '%s' "$settings" | grep -q "winboot" && select_winboot
605 )</div>
606 </fieldset>
608 <br/>
609 EOT
610 }
613 #--------------
614 # execute page
615 #--------------
617 save_settings()
618 {
619 h5 "$(_ 'Checking settings...')"
621 # install type
622 /usr/sbin/tazinst set media "$(GET MEDIA)" "$INSTFILE"
624 # source File
625 case "$(/usr/sbin/tazinst get media "$INSTFILE")" in
626 usb)
627 /usr/sbin/tazinst set source "$(GET SRC_USB)" "$INSTFILE" ;;
628 iso)
629 /usr/sbin/tazinst set source "$(GET SRC_ISO)" "$INSTFILE" ;;
630 web)
631 /usr/sbin/tazinst set source "$(GET SRC_WEB)" "$INSTFILE" ;;
632 esac
634 # set defined url
635 [ $(GET URL) ] && SRC_WEB=$(GET URL)
637 # root Partition
638 /usr/sbin/tazinst set root_uuid "$(GET ROOT_UUID)" "$INSTFILE"
640 # format root partition
641 [ "$(GET ROOT_FORMAT)" ] \
642 && /usr/sbin/tazinst set root_format "$(GET ROOT_FORMAT)" "$INSTFILE" \
643 || /usr/sbin/tazinst unset root_format "$INSTFILE"
645 # home Partition
646 if [ "$(GET HOME_UUID)" ] ; then
647 /usr/sbin/tazinst set home_uuid "$(GET HOME_UUID)" "$INSTFILE"
648 [ "$(GET HOME_FORMAT)" ] \
649 && /usr/sbin/tazinst set home_format "$(GET HOME_FORMAT)" \
650 "$INSTFILE" \
651 || /usr/sbin/tazinst unset home_format "$INSTFILE"
652 else
653 /usr/sbin/tazinst unset home_uuid "$INSTFILE"
654 /usr/sbin/tazinst unset home_format "$INSTFILE"
655 fi
657 # hostname
658 /usr/sbin/tazinst set hostname "$(GET HOSTNAME)" "$INSTFILE"
660 # root pwd
661 /usr/sbin/tazinst set root_pwd "$(GET ROOT_PWD)" "$INSTFILE"
663 # user Login
664 /usr/sbin/tazinst set user_login "$(GET USER_LOGIN)" "$INSTFILE"
666 # user Pwd
667 /usr/sbin/tazinst set user_pwd "$(GET USER_PWD)" "$INSTFILE"
669 # win Dual-Boot
670 /usr/sbin/tazinst set winboot "$(GET WINBOOT)" "$INSTFILE"
672 # bootloader
673 if [ "$(GET BOOTLOADER)" = "auto" ]; then
674 /usr/sbin/tazinst set bootloader "auto" "$INSTFILE"
675 else
676 /usr/sbin/tazinst unset bootloader "$INSTFILE"
677 /usr/sbin/tazinst unset winboot "$INSTFILE"
678 fi
679 input_hidden "CHECK" "yes"
680 }
683 tazinst_run()
684 {
685 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")" error
686 h4 "$(_ 'Proceeding to: %s' "$(gettext "$mode")")"
687 /usr/sbin/tazinst execute "$INSTFILE" | /bin/busybox awk '{
688 num=$1+0
689 if (num>0 && num<=100){
690 print "<script type=\"text/javascript\">"
691 printf "document.write(\047<div id=\"progress\">"
692 printf "<img src=\"/styles/default/images/loader.gif\" />"
693 printf $1 "&#37; " substr($0, length($1)+2, 40)
694 print "</div>\047)"
695 print "</script>"
696 }
697 }'
698 # end_of_install
699 if /usr/sbin/tazinst log | grep -q "x-x-" ; then
700 error=1
701 echo "<script type=\"text/javascript\">"
702 printf "document.write(\047<div id=\"progress\">"
703 printf "<img src=\"/styles/default/images/stop.png\" />"
704 _n 'Errors encountered.'
705 printf "</div>\047)\n"
706 echo "</script>"
707 br
708 br
709 /usr/sbin/tazinst log | \
710 /bin/busybox awk '$1 == "-x-x-",$1 == "x-x-x"' | sed 's/-x-x-/ /' \
711 | grep -v "x-x-x"
712 else
713 error=0
714 echo "<script type=\"text/javascript\">"
715 printf "document.write(\047<div id=\"progress\">"
716 printf "<img src=\"/styles/default/images/tux.png\" />"
717 _n 'Process completed!'
718 printf "</div>\047)\n"
719 echo "</script>"
720 br
721 br
722 p "$(_ "Installation is now finished, you can exit the installer \
723 or reboot on your new SliTaz GNU/Linux operating system.")"
724 fi
725 return "$error"
727 }
730 tazinst_log()
731 {
732 h4 "$(_ "Tazinst log")"
733 printf '<pre>%s</pre>' "$(/usr/sbin/tazinst log | sed 's/\%/ percent/g')"
734 }
737 #-----------------
738 # page navigation
739 #-----------------
741 display_mode() {
742 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
743 case $mode in
744 install)
745 cat <<EOT
746 <h2>$(_ 'Install SliTaz')</h2>
748 <p>$(_ "You're going to install SliTaz on a partition of \
749 your hard disk drive. If you decide to format your HDD, all data will be \
750 lost. If you do not format, all data except for any existing /home \
751 directory will be removed (the home directory will be kept as is).")</p>
752 EOT
753 ;;
754 upgrade)
755 cat <<EOT
756 <h2>$(_ 'Upgrade SliTaz')</h2>
758 <p>$(_ "You're going to upgrade an already installed SliTaz \
759 system on your hard disk drive. Your /home /etc /var/www directories \
760 will be kept, all other directories will be removed. Any additional \
761 packages added to your old SliTaz system will be updated as long you \
762 have an active internet connection.")</p>
763 EOT
764 ;;
765 esac
766 }
769 moveto_page()
770 {
771 local back_page="$1" next_page="$2" back_msg next_msg
773 case "$back_page" in
774 partitioning)
775 back_msg=$(_ 'Back to partitioning') ;;
776 input)
777 back_msg=$(_ 'Back to entering settings') ;;
778 *)
779 back_msg=$(_ 'Back to Installer Start Page') ;;
780 esac
782 case "$next_page" in
783 execute|run)
784 next_msg=$(_ 'Proceed to SliTaz installation') ;;
785 reboot)
786 next_msg=$(_ 'Installation complete. You can now restart') ;;
787 failed)
788 next_msg=$(_ 'Installation failed. See log') ;;
789 input)
790 next_msg=$(_ 'Continue installation.') ;;
791 *)
792 next_msg=$(_ 'Back to Installer Start Page') ;;
793 esac
795 cat <<EOT
796 <hr/>
797 <form>
798 <button type="submit" name="page" value="$back_page" data-icon="back" >$back_msg</button>
799 <button type="submit" name="page" value="$next_page" data-icon="start">$next_msg</button>
800 </form>
801 EOT
802 }
805 moveto_home() {
806 cat <<EOT
807 <form>
808 <button type="submit" name="page" value="home" data-icon="back"
809 >$(_ 'Back to Installer Start Page')</button>
810 </form>
811 EOT
812 }
815 page_redirection() {
816 local page="$1"
817 cat <<EOT
818 HTTP/1.1 301 Moved Permanently
819 Location: $SCRIPT_NAME?page=$1
821 EOT
823 true || cat <<EOT
824 <!DOCTYPE html>
825 <html>
826 <head>
827 <meta charset="UTF-8">
828 <title>$(_ "A web page that points a browser to a different page after \
829 2 seconds")</title>
830 <meta http-equiv="refresh" content="0; URL=$SCRIPT_NAME?page=$1">
831 <meta name="keywords" content="automatic redirection">
832 </head>
833 <body>
834 <p>$(_ "If your browser doesn't automatically redirect within a few \
835 seconds, you may want to go there manually [here]" | \
836 sed "s|\[|<a href=\"?page=$page\">|; s|\]|</a>|")</p>
837 </body>
838 </html>
839 EOT
840 }
843 #----------
844 # checking
845 #----------
847 check_ressources() {
848 local errorcode=0 buffer=$(mktemp)
849 {
850 header; xhtml_header; comment "check_ressources"
851 } > $buffer
852 if ! [ -x /usr/sbin/tazinst ]; then
853 {
854 h4 $(_ 'Tazinst Error')
855 p "$(_ '%s, the backend to %s is missing.' '<strong>tazinst</strong>' 'slitaz-installer';
856 _ 'Any installation can not be done without %s.' 'tazinst')"
857 p "$(_ "Check %s permissions, or reinstall the %s package." \
858 'tazinst' 'slitaz-installer')"
859 } >> $buffer
860 errorcode=1
861 else
862 # check tazinst minimum version
863 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
864 r=$TAZINST_MINIMUM_VERSION
865 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
866 '{v=$v+0}{ if (v < r) exit 1}') ; then
867 {
868 h4 $(_ 'Tazinst Error')
869 p "$(_ '%s, the %s backend, is not at the minimum required version.' \
870 '<strong>tazinst</strong>' 'slitaz-installer';
871 _ 'Any installation can not be done without %s.' 'tazinst')"
872 p "$(_ 'Reinstall the %s package, or use %s in CLI mode.' \
873 'slitaz-installer' 'tazinst')"
874 } >> $buffer
875 errorcode=1
876 fi
877 # check tazinst maximum version
878 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
879 r=$TAZINST_MAXIMUM_VERSION
880 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
881 '{v=$v+0}{ if (v > r) exit 1}') ; then
882 {
883 h4 $(_ 'Tazinst Error')
884 p "$(_ "%s, the %s backend, is at a higher version than the maximum authorized \
885 by the %s." '<strong>tazinst</strong>' 'slitaz-installer' 'slitaz-installer';
886 _ 'Any installation cannot be done.')"
887 p "$(_ 'Reinstall the %s package, or use %s in CLI mode.' \
888 'slitaz-installer' 'tazinst')"
889 } >> $buffer
890 errorcode=1
891 fi
892 fi
893 [ "$errorcode" -eq 1 ] && cat $buffer
894 rm $buffer
895 return $errorcode
896 }
899 #---------------
900 # html snippets
901 #---------------
903 br() {
904 echo '<br />'
905 }
907 hr() {
908 echo '<hr />'
909 }
911 comment() {
912 printf '<!-- %s -->\n' "$@"
913 }
915 a() {
916 local page="$1" text="$2"
917 printf '<a class="button" value="%s" href="?page=%s">%s</a>\n' \
918 "$page" "$page" "$text"
919 }
921 button() {
922 local action="$1" msg="$2" title="$3"
923 printf '<a class="button" href="%s?page=%s" title="%s">%s</a>\n' \
924 "$SCRIPT_NAME" "$action" "$title" "$msg"
925 }
927 open_div() {
928 [ "$1" ] && printf '<div %s>\n' "$1" || echo '<div>'
929 }
931 close_div() {
932 echo '</div>'
933 }
935 p() {
936 printf '<p>%s</p>\n' "$@"
937 }
939 h4() {
940 printf '<h4>%s</h4>\n' "$@"
941 }
943 h5() {
944 printf '<h5>%s</h5>\n' "$@"
945 }
947 label() {
948 local setting="$1" label="$2" title="$3" name="$4" error=0
949 [ -z "$name" ] && name="$setting"
950 printf '<label for="%s"' "$name"
951 [ "$title" ] && printf ' title="%s">' "$title" || printf '%s' '>'
952 # display label in red in case of error
953 if [ "$CHECK" ]; then
954 /usr/sbin/tazinst check "$setting" "$INSTFILE"
955 error="$?"
956 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
957 printf '%s' '<span class="alert">'
958 printf '%s' "$label"
959 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
960 printf '%s' "<sup>*</sup></span>"
961 else
962 printf '%s' "$label"
963 fi
964 echo '</label>'
965 return "$error"
966 }
969 label_media() {
970 local id="$1" label="$2" media="$3" title="$4" retcode=0
971 if [ "$media" = "$id" ]; then
972 label "source" \
973 "$label" \
974 "$title" \
975 "$media"
976 retcode="$?"
977 else
978 printf '<label for="%s"' "$id"
979 [ "$title" ] && printf ' title="%s">' "$title" || echo '>'
980 echo "$label</label>"
981 fi
982 return "$retcode"
983 }
986 error_msg() {
987 local error="$1" setting="$2" line="$3"
988 if [ "$CHECK" ]; then
989 if [ "$error" -gt "0" ]; then
990 [ "$error" -lt "128" ] && printf '%s' '<span class="alert">' \
991 || printf '%s' '<span class="warning">'
992 if [ "$line" ]; then
993 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1 | \
994 /bin/busybox awk -v LINE="$line" '{if (NR==LINE){print}}'
995 else
996 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1
997 fi
998 echo '</span>'
999 fi
1000 fi
1004 select() {
1005 local list="$1" selected="$2" name="$3" type="$4"
1006 printf '%s' "$list" | \
1007 /bin/busybox awk -v SELECTED="$selected" -v NONE="$(_ 'None')" \
1008 -v NAME="$name" -v TYPE="$type" 'BEGIN{
1009 TYPE=TYPE+0
1010 print "<select name=\"" NAME "\">"
1011 print "<option value=>&lt; " NONE " &gt;</option>"
1014 printf "<option value=\"" $1 "\""
1015 if ($1 == SELECTED) printf " selected"
1016 if (TYPE == 0)
1017 print ">" $0 "</option>"
1018 if (TYPE == 1)
1019 print ">" substr($0,12) "</option>"
1020 if (TYPE == 2)
1021 print ">" $2 "</option>"
1023 END{
1024 print "</select>"
1025 }'
1028 input()
1030 local type="$1" name="$2" value="$3" selected="$4" help="$5" action="$6"
1031 printf '<input type="%s" id="%s" list="list_%s" ' "$type" "$name" "$name"
1032 printf 'name="%s" class="%s" ' "$(printf $name | tr [a-z] [A-Z])" "$type"
1033 [ "$value" ] && printf 'value="%s" ' "$value"
1034 [ "$value" = "$selected" ] && printf '%s' "checked "
1035 [ "$action" ] && printf \
1036 'onInput="document.getElementById(%s).checked = true;" ' "'$action'"
1037 [ "$help" ] && printf 'placeholder="%s" />\n' "$help" || echo "/>"
1040 input_media()
1042 local id="$1" media="$2"
1043 printf '<input type="radio" name="MEDIA" value="%s" id="%s" ' "$id" "$id"
1044 [ "$media" = "$id" ] && echo 'checked />' || echo '/>'
1047 input_hidden()
1049 local name="$1" value="$2"
1050 printf '<input type="hidden" name="%s" value="%s" />\n' "$name" "$value"
1053 datalist()
1055 local list="$1" name="$2"
1056 printf '<datalist id="list_%s">\n' "$name"
1057 # workaround for browsers that don’t support the datalist element..
1058 local script="displaySelValue(\"select_$name\",\"$name\")"
1059 printf '<select class="workaround" id="select_%s" ' "$name"
1060 printf "onChange='%s' onBlur='%s'>\n" "$script" "$script"
1062 # workaround ..end
1063 printf '%s' "$list" | \
1064 /bin/busybox awk -v NONE="$(_ 'None')" 'BEGIN{
1065 line=0
1068 TEXT=$1
1069 sub(".*/","",TEXT)
1070 printf "<option value=\"%s\">%s</option>\n", $1, TEXT
1071 line++
1073 END{
1074 if (line < 1)
1075 printf "<option value=>&lt; %s &gt;</option>\n", NONE
1076 }'
1077 echo "</select>"
1078 echo "</datalist>"
1081 format()
1083 list_fs="$1" selected="$2" name="$3" none="$(_ 'Do not format')"
1084 printf '<label for="%s" ' "$name"
1085 printf 'title="%s">' "$(_ "To format this partition, select a \
1086 filesystem, usually it's safe to use ext4")"
1087 printf '%s</label>\n' "$(_ 'Formatting option:')"
1088 printf '%s' "$list_fs" | \
1089 /bin/busybox awk -v SELECTED=$selected -v NONE="$none" -v NAME="$name" '
1090 BEGIN{
1091 RS=" "
1092 print "<select name=\"" NAME "\">"
1093 print "<option value=\"\">" NONE "</option>"
1094 line=0
1097 printf "<option value=\"" $1 "\""
1098 if ($1 == SELECTED) printf " selected"
1099 print ">" $0 "</option>"
1100 line++
1102 END{
1103 if (line < 1)
1104 print "<option value=>< " NONE " ></option>"
1105 print "</select>"
1106 }'
1109 form_start()
1111 printf '<form name="%s" method="get" ' "Form"
1112 printf 'onsubmit="return true" action="%s">\n' "$SCRIPT_NAME"
1115 form_end()
1117 echo '</form>'
1120 add_style()
1122 printf '<!-- add specific styles -->
1123 <style type="text/css">
1124 section label {
1125 display:inline-block;
1126 vertical-align:middle;
1127 width: 130px;
1129 .media label {
1130 display:inline-block;
1131 vertical-align:middle;
1132 width: 110px;
1134 .options label {
1135 display:inline-block;
1136 vertical-align:middle;
1137 width: 140px;
1139 .text {
1140 width: 350px;
1142 input {margin-bottom:3px;}
1143 span.alert {color: red}
1144 span.warning { color: darkgray}
1145 #progress {
1146 background-color: #f8f8f8;
1147 border: 1px solid #ddd;
1148 color: #666;
1149 cursor: progress;
1150 position: absolute;
1151 width: 348px;
1152 padding: 4px 4px 2px;
1154 </style>
1155 <!-- workaround for browsers that do not support the datalist element -->
1156 <style type="text/css">
1157 .workaround {width: 110px;}
1158 </style>
1159 <script>
1160 function displaySelValue(selectId,inputId)
1162 var slct = document.getElementById(selectId);
1163 var input = document.getElementById(inputId);
1164 document.getElementById("src_iso").value="";
1165 document.getElementById("src_web").value="";
1166 if (inputId =="src_iso"){
1167 document.getElementById("iso").checked = true;
1169 if (inputId =="src_web"){
1170 document.getElementById("web").checked = true;
1172 input.value = slct.options[slct.selectedIndex].value;
1174 </script>
1175 <!-- datalist workaround end -->
1176 \n'
1181 # main
1184 case "$(GET page)" in
1185 home)
1186 header; xhtml_header
1187 select_action
1188 select_install
1189 select_upgrade
1190 select_evaluate
1191 ;;
1192 evaluate)
1193 header; xhtml_header
1194 select_evaluate
1195 ;;
1196 install)
1197 /usr/sbin/tazinst set mode install "$INSTFILE"
1198 page_redirection partitioning
1199 ;;
1200 partitioning)
1201 header; xhtml_header
1202 form_start
1203 display_mode
1204 select_gparted
1205 moveto_page home input
1206 form_end
1207 ;;
1208 gparted)
1209 exec_gparted
1210 page_redirection partitioning
1211 ;;
1212 upgrade)
1213 /usr/sbin/tazinst set mode upgrade "$INSTFILE"
1214 page_redirection input
1215 ;;
1216 input)
1217 header; xhtml_header
1218 add_style
1219 form_start
1220 display_mode
1221 select_settings
1222 moveto_page home execute
1223 form_end
1224 ;;
1225 execute)
1226 buffer=$(mktemp)
1228 header; xhtml_header
1229 form_start
1230 display_mode
1231 save_settings
1232 } > $buffer
1233 if ! (/usr/sbin/tazinst check all $INSTFILE > /dev/null); then
1234 rm $buffer
1235 page_redirection "input&CHECK=yes"
1236 else
1237 cat $buffer; rm $buffer
1238 if tazinst_run; then
1239 moveto_page home reboot
1240 else
1241 moveto_page input failed
1242 fi
1243 fi
1244 form_end
1245 ;;
1246 reboot)
1247 /usr/sbin/tazinst clean "$INSTFILE"
1248 reboot ;;
1249 failed)
1250 header; xhtml_header
1251 form_start
1252 tazinst_log
1253 moveto_home
1254 form_end
1255 ;;
1256 *)
1257 if check_ressources; then
1258 /usr/sbin/tazinst new "$INSTFILE"
1259 page_redirection home
1260 fi
1261 ;;
1262 esac
1264 xhtml_footer
1266 exit 0