tazinst view installer.cgi @ rev 114

installer.cgi: disable TAZINST_MAXIMUM_VERSION
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 23 15:06:52 2021 +0000 (2021-10-23)
parents 55a8e9fe5627
children
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="999"
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_liveboot()
536 {
537 local liveboot="$(/usr/sbin/tazinst get liveboot "$INSTFILE")" error
539 cat <<EOT
540 $(
541 input "checkbox" \
542 "liveboot" \
543 "auto" \
544 "$liveboot"
545 label "liveboot" \
546 "$(_ 'Enable the liveboot/rescue mode. (with root password)')" \
547 "$(_ "At start-up, you will be asked whether you want to boot \
548 into SliTaz GNU/Linux on disk or in RAM.")"
549 error="$?"
550 error_msg "$error" \
551 "liveboot"
552 )
553 <br/>
554 EOT
555 }
558 select_webboot()
559 {
560 local webboot="$(/usr/sbin/tazinst get webboot "$INSTFILE")" error
562 cat <<EOT
563 $(
564 input "checkbox" \
565 "webboot" \
566 "auto" \
567 "$webboot"
568 label "webboot" \
569 "$(_ 'Enable the webboot mode. (with root password)')" \
570 "$(_ "At start-up, you will be asked whether you want to boot \
571 into SliTaz GNU/Linux on disk or boot in RAM from the Web.")"
572 error="$?"
573 error_msg "$error" \
574 "webboot"
575 )
576 <br/>
577 EOT
578 }
581 select_winboot()
582 {
583 local winboot="$(/usr/sbin/tazinst get winboot "$INSTFILE")" error
585 comment "winboot selection"
586 input "checkbox" \
587 "winboot" \
588 "auto" \
589 "$winboot"
590 label "winboot" \
591 "$(_ 'Enable Windows Dual-Boot.')" \
592 "$(_ "At start-up, you will be asked whether you want to boot \
593 into Windows&trade; or SliTaz GNU/Linux.")"
594 error="$?"
595 error_msg "$error" \
596 "winboot"
597 cat <<EOT
598 </fieldset>
599 EOT
600 }
603 errors_msg()
604 {
605 if [ "$CHECK" ]; then
606 echo '<span class="alert">'
607 p "$(_ "Errors found. Please check your settings.")"
608 echo '</span>'
609 fi
610 }
613 select_settings() {
614 local settings="$(/usr/sbin/tazinst get settings "$INSTFILE")"
615 CHECK=$(GET CHECK)
616 errors_msg
618 cat<<EOT
619 <fieldset>
620 <legend>$(_ 'Select source media:')</legend>
622 <div class="media">$(select_source)</div>
623 </fieldset>
626 <fieldset>
627 <legend>$(_ 'Select destination')</legend>
629 <div>$(
630 select_root_uuid
631 printf '%s' "$settings" | grep -q "root_format" && select_root_format
632 )</div>
633 </fieldset>
636 <fieldset id="options">
637 <legend>$(_ 'Options')</legend>
639 <div class="options">$(
640 printf '%s' "$settings" | grep -q "home_uuid" && select_home_uuid
641 printf '%s' "$settings" | grep -q "home_format" && select_home_format
642 printf '%s' "$settings" | grep -q "hostname" && select_hostname
643 printf '%s' "$settings" | grep -q "root_pwd" && select_root_pwd
644 printf '%s' "$settings" | grep -q "user_login" && select_user_login
645 printf '%s' "$settings" | grep -q "user_pwd" && select_user_pwd
646 )</div>
648 <div class="bootloader">$(
649 printf '%s' "$settings" | grep -q "bootloader" && select_bootloader
650 printf '%s' "$settings" | grep -q "liveboot" && select_liveboot
651 printf '%s' "$settings" | grep -q "webboot" && select_webboot
652 printf '%s' "$settings" | grep -q "winboot" && select_winboot
653 )</div>
654 </fieldset>
656 <br/>
657 EOT
658 }
661 #--------------
662 # execute page
663 #--------------
665 save_settings()
666 {
667 h5 "$(_ 'Checking settings...')"
669 # install type
670 /usr/sbin/tazinst set media "$(GET MEDIA)" "$INSTFILE"
672 # source File
673 case "$(/usr/sbin/tazinst get media "$INSTFILE")" in
674 usb)
675 /usr/sbin/tazinst set source "$(GET SRC_USB)" "$INSTFILE" ;;
676 iso)
677 /usr/sbin/tazinst set source "$(GET SRC_ISO)" "$INSTFILE" ;;
678 web)
679 /usr/sbin/tazinst set source "$(GET SRC_WEB)" "$INSTFILE" ;;
680 esac
682 # set defined url
683 [ $(GET URL) ] && SRC_WEB=$(GET URL)
685 # root Partition
686 /usr/sbin/tazinst set root_uuid "$(GET ROOT_UUID)" "$INSTFILE"
688 # format root partition
689 [ "$(GET ROOT_FORMAT)" ] \
690 && /usr/sbin/tazinst set root_format "$(GET ROOT_FORMAT)" "$INSTFILE" \
691 || /usr/sbin/tazinst unset root_format "$INSTFILE"
693 # home Partition
694 if [ "$(GET HOME_UUID)" ] ; then
695 /usr/sbin/tazinst set home_uuid "$(GET HOME_UUID)" "$INSTFILE"
696 [ "$(GET HOME_FORMAT)" ] \
697 && /usr/sbin/tazinst set home_format "$(GET HOME_FORMAT)" \
698 "$INSTFILE" \
699 || /usr/sbin/tazinst unset home_format "$INSTFILE"
700 else
701 /usr/sbin/tazinst unset home_uuid "$INSTFILE"
702 /usr/sbin/tazinst unset home_format "$INSTFILE"
703 fi
705 # hostname
706 /usr/sbin/tazinst set hostname "$(GET HOSTNAME)" "$INSTFILE"
708 # root pwd
709 /usr/sbin/tazinst set root_pwd "$(GET ROOT_PWD)" "$INSTFILE"
711 # user Login
712 /usr/sbin/tazinst set user_login "$(GET USER_LOGIN)" "$INSTFILE"
714 # user Pwd
715 /usr/sbin/tazinst set user_pwd "$(GET USER_PWD)" "$INSTFILE"
717 # SliTaz Live Boot
718 /usr/sbin/tazinst set liveboot "$(GET LIVEBOOT)" "$INSTFILE"
720 # SliTaz Web Boot
721 /usr/sbin/tazinst set webboot "$(GET WEBBOOT)" "$INSTFILE"
723 # win Dual-Boot
724 /usr/sbin/tazinst set winboot "$(GET WINBOOT)" "$INSTFILE"
726 # bootloader
727 if [ "$(GET BOOTLOADER)" = "auto" ]; then
728 /usr/sbin/tazinst set bootloader "auto" "$INSTFILE"
729 else
730 for i in bootloader liveboot webboot winboot ; do
731 /usr/sbin/tazinst unset $i "$INSTFILE"
732 done
733 fi
734 input_hidden "CHECK" "yes"
735 }
738 tazinst_run()
739 {
740 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")" error
741 h4 "$(_ 'Proceeding to: %s' "$(gettext "$mode")")"
742 /usr/sbin/tazinst execute "$INSTFILE" | /bin/busybox awk '{
743 num=$1+0
744 if (num>0 && num<=100){
745 print "<script type=\"text/javascript\">"
746 printf "document.write(\047<div id=\"progress\">"
747 printf "<img src=\"/styles/default/images/loader.gif\" />"
748 printf $1 "&#37; " substr($0, length($1)+2)
749 print "</div>\047)"
750 print "</script>"
751 }
752 }'
753 # end_of_install
754 if /usr/sbin/tazinst log | grep -q "x-x-" ; then
755 error=1
756 echo "<script type=\"text/javascript\">"
757 printf "document.write(\047<div id=\"progress\">"
758 printf "<img src=\"/styles/default/images/stop.png\" />"
759 _n 'Errors encountered.'
760 printf "</div>\047)\n"
761 echo "</script>"
762 br
763 br
764 /usr/sbin/tazinst log | \
765 /bin/busybox awk '$1 == "-x-x-",$1 == "x-x-x"' | sed 's/-x-x-/ /' \
766 | grep -v "x-x-x"
767 else
768 error=0
769 echo "<script type=\"text/javascript\">"
770 printf "document.write(\047<div id=\"progress\">"
771 printf "<img src=\"/styles/default/images/tux.png\" />"
772 _n 'Process completed!'
773 printf "</div>\047)\n"
774 echo "</script>"
775 br
776 br
777 p "$(_ "Installation is now finished, you can exit the installer \
778 or reboot on your new SliTaz GNU/Linux operating system.")"
779 fi
780 return "$error"
782 }
785 tazinst_log()
786 {
787 h4 "$(_ "Tazinst log")"
788 printf '<pre>%s</pre>' "$(/usr/sbin/tazinst log | sed 's/\%/ percent/g')"
789 }
792 #-----------------
793 # page navigation
794 #-----------------
796 display_mode() {
797 local mode="$(/usr/sbin/tazinst get mode "$INSTFILE")"
798 case $mode in
799 install)
800 cat <<EOT
801 <h2>$(_ 'Install SliTaz')</h2>
803 <p>$(_ "You're going to install SliTaz on a partition of \
804 your hard disk drive. If you decide to format your HDD, all data will be \
805 lost. If you do not format, all data except for any existing /home \
806 directory will be removed (the home directory will be kept as is).")</p>
807 EOT
808 ;;
809 upgrade)
810 cat <<EOT
811 <h2>$(_ 'Upgrade SliTaz')</h2>
813 <p>$(_ "You're going to upgrade an already installed SliTaz \
814 system on your hard disk drive. Your /home /etc /var/www directories \
815 will be kept, all other directories will be removed. Any additional \
816 packages added to your old SliTaz system will be updated as long you \
817 have an active internet connection.")</p>
818 EOT
819 ;;
820 esac
821 }
824 moveto_page()
825 {
826 local back_page="$1" next_page="$2" back_msg next_msg
828 case "$back_page" in
829 partitioning)
830 back_msg=$(_ 'Back to partitioning') ;;
831 input)
832 back_msg=$(_ 'Back to entering settings') ;;
833 *)
834 back_msg=$(_ 'Back to Installer Start Page') ;;
835 esac
837 case "$next_page" in
838 execute|run)
839 next_msg=$(_ 'Proceed to SliTaz installation') ;;
840 reboot)
841 next_msg=$(_ 'Installation complete. You can now restart') ;;
842 failed)
843 next_msg=$(_ 'Installation failed. See log') ;;
844 input)
845 next_msg=$(_ 'Continue installation.') ;;
846 *)
847 next_msg=$(_ 'Back to Installer Start Page') ;;
848 esac
850 cat <<EOT
851 <hr/>
852 <form>
853 <button type="submit" name="page" value="$back_page" data-icon="back" >$back_msg</button>
854 <button type="submit" name="page" value="$next_page" data-icon="start">$next_msg</button>
855 </form>
856 EOT
857 }
860 moveto_home() {
861 cat <<EOT
862 <form>
863 <button type="submit" name="page" value="home" data-icon="back"
864 >$(_ 'Back to Installer Start Page')</button>
865 </form>
866 EOT
867 }
870 page_redirection() {
871 local page="$1"
872 cat <<EOT
873 HTTP/1.1 301 Moved Permanently
874 Location: $SCRIPT_NAME?page=$1
876 EOT
878 true || cat <<EOT
879 <!DOCTYPE html>
880 <html>
881 <head>
882 <meta charset="UTF-8">
883 <title>$(_ "A web page that points a browser to a different page after \
884 2 seconds")</title>
885 <meta http-equiv="refresh" content="0; URL=$SCRIPT_NAME?page=$1">
886 <meta name="keywords" content="automatic redirection">
887 </head>
888 <body>
889 <p>$(_ "If your browser doesn't automatically redirect within a few \
890 seconds, you may want to go there manually [here]" | \
891 sed "s|\[|<a href=\"?page=$page\">|; s|\]|</a>|")</p>
892 </body>
893 </html>
894 EOT
895 }
898 #----------
899 # checking
900 #----------
902 check_ressources() {
903 local errorcode=0 buffer=$(mktemp)
904 {
905 header; xhtml_header; comment "check_ressources"
906 } > $buffer
907 if ! [ -x /usr/sbin/tazinst ]; then
908 {
909 h4 $(_ 'Tazinst Error')
910 p "$(_ '%s, the backend to %s is missing.' '<strong>tazinst</strong>' 'slitaz-installer';
911 _ 'Any installation can not be done without %s.' 'tazinst')"
912 p "$(_ "Check %s permissions, or reinstall the %s package." \
913 'tazinst' 'slitaz-installer')"
914 } >> $buffer
915 errorcode=1
916 else
917 # check tazinst minimum version
918 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
919 r=$TAZINST_MINIMUM_VERSION
920 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
921 '{v=$v+0}{ if (v < r) exit 1}') ; then
922 {
923 h4 $(_ 'Tazinst Error')
924 p "$(_ '%s, the %s backend, is not at the minimum required version.' \
925 '<strong>tazinst</strong>' 'slitaz-installer';
926 _ 'Any installation can not be done without %s.' 'tazinst')"
927 p "$(_ 'Reinstall the %s package, or use %s in CLI mode.' \
928 'slitaz-installer' 'tazinst')"
929 } >> $buffer
930 errorcode=1
931 fi
932 # check tazinst maximum version
933 v=$(/usr/sbin/tazinst version | tr -d '[:alpha:]')
934 r=$TAZINST_MAXIMUM_VERSION
935 if ! (printf '%s' "$v" | /bin/busybox awk -v r=$r \
936 '{v=$v+0}{ if (v > r) exit 1}') ; then
937 {
938 h4 $(_ 'Tazinst Error')
939 p "$(_ "%s, the %s backend, is at a higher version than the maximum authorized \
940 by the %s." '<strong>tazinst</strong>' 'slitaz-installer' 'slitaz-installer';
941 _ 'Any installation cannot be done.')"
942 p "$(_ 'Reinstall the %s package, or use %s in CLI mode.' \
943 'slitaz-installer' 'tazinst')"
944 } >> $buffer
945 errorcode=1
946 fi
947 fi
948 [ "$errorcode" -eq 1 ] && cat $buffer
949 rm $buffer
950 return $errorcode
951 }
954 #---------------
955 # html snippets
956 #---------------
958 br() {
959 echo '<br />'
960 }
962 hr() {
963 echo '<hr />'
964 }
966 comment() {
967 printf '<!-- %s -->\n' "$@"
968 }
970 a() {
971 local page="$1" text="$2"
972 printf '<a class="button" value="%s" href="?page=%s">%s</a>\n' \
973 "$page" "$page" "$text"
974 }
976 button() {
977 local action="$1" msg="$2" title="$3"
978 printf '<a class="button" href="%s?page=%s" title="%s">%s</a>\n' \
979 "$SCRIPT_NAME" "$action" "$title" "$msg"
980 }
982 open_div() {
983 [ "$1" ] && printf '<div %s>\n' "$1" || echo '<div>'
984 }
986 close_div() {
987 echo '</div>'
988 }
990 p() {
991 printf '<p>%s</p>\n' "$@"
992 }
994 h4() {
995 printf '<h4>%s</h4>\n' "$@"
996 }
998 h5() {
999 printf '<h5>%s</h5>\n' "$@"
1002 label() {
1003 local setting="$1" label="$2" title="$3" name="$4" error=0
1004 [ -z "$name" ] && name="$setting"
1005 printf '<label for="%s"' "$name"
1006 [ "$title" ] && printf ' title="%s">' "$title" || printf '%s' '>'
1007 # display label in red in case of error
1008 if [ "$CHECK" ]; then
1009 /usr/sbin/tazinst check "$setting" "$INSTFILE"
1010 error="$?"
1011 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
1012 printf '%s' '<span class="alert">'
1013 printf '%s' "$label"
1014 [ "$error" -gt "0" ] && [ "$error" -lt "127" ] && \
1015 printf '%s' "<sup>*</sup></span>"
1016 else
1017 printf '%s' "$label"
1018 fi
1019 echo '</label>'
1020 return "$error"
1024 label_media() {
1025 local id="$1" label="$2" media="$3" title="$4" retcode=0
1026 if [ "$media" = "$id" ]; then
1027 label "source" \
1028 "$label" \
1029 "$title" \
1030 "$media"
1031 retcode="$?"
1032 else
1033 printf '<label for="%s"' "$id"
1034 [ "$title" ] && printf ' title="%s">' "$title" || echo '>'
1035 echo "$label</label>"
1036 fi
1037 return "$retcode"
1041 error_msg() {
1042 local error="$1" setting="$2" line="$3"
1043 if [ "$CHECK" ]; then
1044 if [ "$error" -gt "0" ]; then
1045 [ "$error" -lt "128" ] && printf '%s' '<span class="alert">' \
1046 || printf '%s' '<span class="warning">'
1047 if [ "$line" ]; then
1048 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1 | \
1049 /bin/busybox awk -v LINE="$line" '{if (NR==LINE){print}}'
1050 else
1051 /usr/sbin/tazinst check "$setting" "$INSTFILE" 2>&1
1052 fi
1053 echo '</span>'
1054 fi
1055 fi
1059 select() {
1060 local list="$1" selected="$2" name="$3" type="$4"
1061 printf '%s' "$list" | \
1062 /bin/busybox awk -v SELECTED="$selected" -v NONE="$(_ 'None')" \
1063 -v NAME="$name" -v TYPE="$type" 'BEGIN{
1064 TYPE=TYPE+0
1065 print "<select name=\"" NAME "\">"
1066 print "<option value=>&lt; " NONE " &gt;</option>"
1069 printf "<option value=\"" $1 "\""
1070 if ($1 == SELECTED) printf " selected"
1071 if (TYPE == 0)
1072 print ">" $0 "</option>"
1073 if (TYPE == 1)
1074 print ">" substr($0,12) "</option>"
1075 if (TYPE == 2)
1076 print ">" $2 "</option>"
1078 END{
1079 print "</select>"
1080 }'
1083 input()
1085 local type="$1" name="$2" value="$3" selected="$4" help="$5" action="$6"
1086 printf '<input type="%s" id="%s" list="list_%s" ' "$type" "$name" "$name"
1087 printf 'name="%s" class="%s" ' "$(printf $name | tr [a-z] [A-Z])" "$type"
1088 [ "$value" ] && printf 'value="%s" ' "$value"
1089 [ "$value" = "$selected" ] && printf '%s' "checked "
1090 [ "$action" ] && printf \
1091 'onInput="document.getElementById(%s).checked = true;" ' "'$action'"
1092 [ "$help" ] && printf 'placeholder="%s" />\n' "$help" || echo "/>"
1095 input_media()
1097 local id="$1" media="$2"
1098 printf '<input type="radio" name="MEDIA" value="%s" id="%s" ' "$id" "$id"
1099 [ "$media" = "$id" ] && echo 'checked />' || echo '/>'
1102 input_hidden()
1104 local name="$1" value="$2"
1105 printf '<input type="hidden" name="%s" value="%s" />\n' "$name" "$value"
1108 datalist()
1110 local list="$1" name="$2"
1111 printf '<datalist id="list_%s">\n' "$name"
1112 # workaround for browsers that don’t support the datalist element..
1113 local script="displaySelValue(\"select_$name\",\"$name\")"
1114 printf '<select class="workaround" id="select_%s" ' "$name"
1115 printf "onChange='%s' onBlur='%s'>\n" "$script" "$script"
1117 # workaround ..end
1118 printf '%s' "$list" | \
1119 /bin/busybox awk -v NONE="$(_ 'None')" 'BEGIN{
1120 line=0
1123 TEXT=$1
1124 sub(".*/","",TEXT)
1125 printf "<option value=\"%s\">%s</option>\n", $1, TEXT
1126 line++
1128 END{
1129 if (line < 1)
1130 printf "<option value=>&lt; %s &gt;</option>\n", NONE
1131 }'
1132 echo "</select>"
1133 echo "</datalist>"
1136 format()
1138 list_fs="$1" selected="$2" name="$3" none="$(_ 'Do not format')"
1139 printf '<label for="%s" ' "$name"
1140 printf 'title="%s">' "$(_ "To format this partition, select a \
1141 filesystem, usually it's safe to use ext4")"
1142 printf '%s</label>\n' "$(_ 'Formatting option:')"
1143 printf '%s' "$list_fs" | \
1144 /bin/busybox awk -v SELECTED=$selected -v NONE="$none" -v NAME="$name" '
1145 BEGIN{
1146 RS=" "
1147 print "<select name=\"" NAME "\">"
1148 print "<option value=\"\">" NONE "</option>"
1149 line=0
1152 printf "<option value=\"" $1 "\""
1153 if ($1 == SELECTED) printf " selected"
1154 print ">" $0 "</option>"
1155 line++
1157 END{
1158 if (line < 1)
1159 print "<option value=>< " NONE " ></option>"
1160 print "</select>"
1161 }'
1164 form_start()
1166 printf '<form name="%s" method="get" ' "Form"
1167 printf 'onsubmit="return true" action="%s">\n' "$SCRIPT_NAME"
1170 form_end()
1172 echo '</form>'
1175 add_style()
1177 printf '<!-- add specific styles -->
1178 <style type="text/css">
1179 section label {
1180 display:inline-block;
1181 vertical-align:middle;
1182 width: 130px;
1184 .media label {
1185 display:inline-block;
1186 vertical-align:middle;
1187 width: 110px;
1189 .options label {
1190 display:inline-block;
1191 vertical-align:middle;
1192 width: 140px;
1194 .text {
1195 width: 350px;
1197 input {margin-bottom:3px;}
1198 span.alert {color: red}
1199 span.warning { color: darkgray}
1200 #progress {
1201 background-color: #f8f8f8;
1202 border: 1px solid #ddd;
1203 color: #666;
1204 cursor: progress;
1205 position: absolute;
1206 width: 348px;
1207 padding: 4px 4px 2px;
1209 </style>
1210 <!-- workaround for browsers that do not support the datalist element -->
1211 <style type="text/css">
1212 .workaround {width: 110px;}
1213 </style>
1214 <script>
1215 function displaySelValue(selectId,inputId)
1217 var slct = document.getElementById(selectId);
1218 var input = document.getElementById(inputId);
1219 document.getElementById("src_iso").value="";
1220 document.getElementById("src_web").value="";
1221 if (inputId =="src_iso"){
1222 document.getElementById("iso").checked = true;
1224 if (inputId =="src_web"){
1225 document.getElementById("web").checked = true;
1227 input.value = slct.options[slct.selectedIndex].value;
1229 </script>
1230 <!-- datalist workaround end -->
1231 \n'
1236 # main
1239 case "$(GET page)" in
1240 home)
1241 header; xhtml_header
1242 select_action
1243 select_install
1244 select_upgrade
1245 select_evaluate
1246 ;;
1247 evaluate)
1248 header; xhtml_header
1249 select_evaluate
1250 ;;
1251 install)
1252 /usr/sbin/tazinst set mode install "$INSTFILE"
1253 page_redirection partitioning
1254 ;;
1255 partitioning)
1256 header; xhtml_header
1257 form_start
1258 display_mode
1259 select_gparted
1260 moveto_page home input
1261 form_end
1262 ;;
1263 gparted)
1264 exec_gparted
1265 page_redirection partitioning
1266 ;;
1267 upgrade)
1268 /usr/sbin/tazinst set mode upgrade "$INSTFILE"
1269 page_redirection input
1270 ;;
1271 input)
1272 header; xhtml_header
1273 add_style
1274 form_start
1275 display_mode
1276 select_settings
1277 moveto_page home execute
1278 form_end
1279 ;;
1280 execute)
1281 buffer=$(mktemp)
1283 header; xhtml_header
1284 form_start
1285 display_mode
1286 save_settings
1287 } > $buffer
1288 if ! (/usr/sbin/tazinst check all $INSTFILE > /dev/null); then
1289 rm $buffer
1290 page_redirection "input&CHECK=yes"
1291 else
1292 cat $buffer; rm $buffer
1293 if tazinst_run; then
1294 moveto_page home reboot
1295 else
1296 moveto_page input failed
1297 fi
1298 fi
1299 form_end
1300 ;;
1301 reboot)
1302 /usr/sbin/tazinst clean "$INSTFILE"
1303 reboot ;;
1304 failed)
1305 header; xhtml_header
1306 form_start
1307 tazinst_log
1308 moveto_home
1309 form_end
1310 ;;
1311 *)
1312 if check_ressources; then
1313 /usr/sbin/tazinst new "$INSTFILE"
1314 page_redirection home
1315 fi
1316 ;;
1317 esac
1319 xhtml_footer
1321 exit 0