tazpanel view installer.cgi @ rev 234
bug fix in Installer dropdown menu
author | Dominique Corbex <domcox@slitaz.org> |
---|---|
date | Sat Feb 25 12:20:28 2012 +0100 (2012-02-25) |
parents | f85527dffa0c |
children | c025287a4253 |
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for Tazinst, the SliTaz installer.
4 #
5 # Copyright (C) 2011 SliTaz GNU/Linux - BSD License
6 #
7 # Authors : Dominique Corbex <domcox@slitaz.org>
8 #
10 VERSION=0.21
12 # Common functions from libtazpanel
13 . lib/libtazpanel
14 header
15 get_config
17 # Include gettext helper script.
18 . /usr/bin/gettext.sh
20 # Export package name for gettext.
21 TEXTDOMAIN='installer'
22 export TEXTDOMAIN
24 TITLE="- Installer"
26 # Tazinst required version
27 TAZINST_REQUIRED_VERSION="3.3"
29 # Tazinst setup file
30 INSTFILE=/var/lib/tazinst.conf
32 read_setup()
33 {
34 [ -e "$INSTFILE" ] && . $INSTFILE || gettext "Tazinst setup file not found!"
35 }
37 write_setup()
38 {
39 if [ -e "$INSTFILE" ]; then
40 # Install type
41 INST_TYPE=$(GET INST_TYPE)
42 # Source File
43 case "$INST_TYPE" in
44 usb)
45 SRC_FILE=$(GET SRC_USB) ;;
46 iso)
47 SRC_FILE=$(GET SRC_ISO) ;;
48 web)
49 SRC_FILE=$(GET SRC_WEB) ;;
50 esac
51 SRC_FILE=$(echo "$SRC_FILE" | sed 's/\//\\\//'g)
52 [ -n $(GET URL) ] && SRC_WEB=$(GET URL)
53 # Main Partition
54 TGT_PARTITION=$(echo "$(GET TGT_PARTITION)" | sed 's/\//\\\//'g)
55 [ -n "$(GET MAIN_FMT)" ] && TGT_FS=$(GET MAIN_FS) || TGT_FS=""
56 # Home Partition
57 if [ -n "$(GET HOME_SPLIT)" ] ; then
58 TGT_HOME=$(echo "$(GET HOME_PART)" | sed 's/\//\\\//'g)
59 [ -n "$(GET HOME_FMT)" ] && TGT_HOME_FS=$(GET HOME_FS)
60 else
61 TGT_HOME=""
62 TGT_HOME_FS=""
63 fi
64 # Hostname
65 TGT_HOSTNAME=$(GET TGT_HOSTNAME)
66 # Root pwd
67 TGT_ROOT_PWD=$(GET TGT_ROOT_PWD)
68 # User Login
69 TGT_USER=$(GET TGT_USER)
70 # User Pwd
71 TGT_USER_PWD=$(GET TGT_USER_PWD)
72 # Grub
73 TGT_GRUB=$(GET TGT_GRUB)
74 [ "$TGT_GRUB" == "yes" ] || TGT_GRUB=no
75 # Win Dual-Boot
76 TGT_WINBOOT=$(GET TGT_WINBOOT)
78 # Save changes to INSTFILE
79 sed -i s/"^INST_TYPE=.*"/"INST_TYPE=\"$INST_TYPE\"/" $INSTFILE
80 sed -i s/"^SRC_FILE=.*"/"SRC_FILE=\"$SRC_FILE\"/" $INSTFILE
81 sed -i s/"^TGT_PARTITION=.*"/"TGT_PARTITION=\"$TGT_PARTITION\"/" $INSTFILE
82 sed -i s/"^TGT_FS=.*"/"TGT_FS=\"$TGT_FS\"/" $INSTFILE
83 sed -i s/"^TGT_HOME=.*"/"TGT_HOME=\"$TGT_HOME\"/" $INSTFILE
84 sed -i s/"^TGT_HOME_FS=.*"/"TGT_HOME_FS=\"$TGT_HOME_FS\"/" $INSTFILE
85 sed -i s/"^TGT_HOSTNAME=.*"/"TGT_HOSTNAME=\"$TGT_HOSTNAME\"/" $INSTFILE
86 sed -i s/"^TGT_ROOT_PWD=.*"/"TGT_ROOT_PWD=\"$TGT_ROOT_PWD\"/" $INSTFILE
87 sed -i s/"^TGT_USER=.*"/"TGT_USER=\"$TGT_USER\"/" $INSTFILE
88 sed -i s/"^TGT_USER_PWD=.*"/"TGT_USER_PWD=\"$TGT_USER_PWD\"/" $INSTFILE
89 sed -i s/"^TGT_GRUB=.*"/"TGT_GRUB=\"$TGT_GRUB\"/" $INSTFILE
90 sed -i s/"^TGT_WINBOOT=.*"/"TGT_WINBOOT=\"$TGT_WINBOOT\"/" $INSTFILE
91 fi
92 }
94 check_setup()
95 {
96 local ret
97 IFS=$'\n'
98 for line in $(tazinst check $INSTFILE; ret=$?)
99 do
100 line=$(echo $line | sed 's/\[1m//g')
101 line=$(echo $line | sed 's/\[0m//g')
102 line=$(echo $line | sed 's/\s/\ /g')
103 line=$(echo $line | sed 's/</\</g')
104 line=$(echo $line | sed 's/>/\>/g')
105 echo "<font color=\"red\">$line<br /></font>"
106 done
107 unset IFS
108 return $ret
109 }
111 select_action()
112 {
113 cat <<EOT
114 <div id="wrapper">
115 <h2>$(gettext "SliTaz Installer")</h2>
116 <p>$(gettext "The SliTaz Installer installs or upgrades SliTaz to a hard disk
117 drive from a device like a Live-CD or LiveUSB key, from a SliTaz ISO file, or
118 from the web by downloading an ISO file.")<p>
119 </div>
120 EOT
121 }
123 select_gparted()
124 {
125 cat <<EOT
126 <table>
127 <tr>
128 <td><h4>$(gettext "About")</h4></td>
129 </tr>
130 <tr>
131 <td>$(gettext "Before installation, you may need to resize partitions
132 on your hard disk drive in order to make space for SliTaz GNU/Linux.")</td>
133 </tr>
134 </table>
135 EOT
136 }
138 select_install()
139 {
140 cat <<EOT
141 </table>
142 <form method="get" action="$SCRIPT_NAME">
143 <table>
144 <tr>
145 <td><h4>$(gettext "Install")</h4></td>
146 </tr>
147 <tr>
148 <td>$(gettext "Install SliTaz on a partition of your hard disk drive. If
149 you decide to format your HDD, all data will be lost. If you do not
150 format, all data except for any existing /home directory will be removed,
151 the home directory will be kept as is.")</td>
152 </tr>
153 <tr>
154 <td><a class="button" href="$SCRIPT_NAME?page=install">$(gettext "Install SliTaz")</a></td>
155 </tr>
156 </table>
157 EOT
158 }
160 select_upgrade()
161 {
162 cat <<EOT
163 <table>
164 <tr>
165 <td><h4>$(gettext "Upgrade")</h4></td>
166 </tr>
167 <tr>
168 <td>$(gettext "Upgrade an already installed SliTaz system on your hard disk
169 drive. Your /home /etc /var/www directories will be kept, all other directories
170 will be removed. Any additional packages added to your old Slitaz system
171 will be updated as long you have an active internet connection.")</td>
172 </tr>
173 <tr>
174 <td><a class="button" href="$SCRIPT_NAME?page=upgrade">$(gettext "Upgrade SliTaz")</a></td>
175 </tr>
176 </table>
177 </form>
178 EOT
179 }
181 display_action()
182 {
183 case $1 in
184 install)
185 cat << EOT
186 <div id="wrapper">
187 <h3>$(gettext "Install SliTaz")</h3>
188 <p>$(gettext "You're going to install SliTaz on a partition of your hard disk drive. If
189 you decide to format your HDD, all data will be lost. If you do not
190 format, all data except for any existing /home directory will be removed,
191 the home directory will be kept as is.")<p>
192 </div>
193 <input type="hidden" name="INST_ACTION" value="$1">
194 EOT
195 ;;
196 upgrade)
197 cat << EOT
198 <div id="wrapper">
199 <h2>$(gettext "Upgrade SliTaz")</h2>
200 <p>$(gettext "You're going to upgrade an already installed SliTaz system on your hard disk
201 drive. Your /home /etc /var/www directories will be kept, all other directories
202 will be removed. Any additional packages added to your old Slitaz system
203 will be updated as long you have an active internet connection.")<p>
204 </div>
205 <input type="hidden" name="INST_ACTION" value="$1">
206 EOT
207 ;;
208 esac
209 }
211 select_source()
212 {
213 cat <<EOT
214 <a name="source"></a>
215 <h4>$(gettext "Source")</h4>
216 <table>
217 <tr>
218 <td><input type="radio" name="INST_TYPE" value="cdrom" $([ "$INST_TYPE" == "cdrom" ] && echo "checked") id="cdrom" />
219 <label for="cdrom">$(gettext "LiveCD")</td></label>
220 </tr>
221 <tr>
222 <td><input type="radio" name="INST_TYPE" value="usb" $([ "$INST_TYPE" == "usb" ] && echo "checked") id="usb" />
223 <label for="usb">$(gettext "LiveUSB"):</label>
224 <select name="SRC_USB">
225 EOT
226 # List disks if plugged USB device
227 usb=0
228 if [ -d /proc/scsi/usb-storage ]; then
229 for DEV in /sys/block/sd* ; do
230 if readlink $DEV | grep -q usb; then
231 DEV=$(basename $DEV)
232 if [ -d /sys/block/${DEV}/${DEV}1 ]; then
233 for i in $(fdisk -l /dev/$DEV | awk '/^\/dev/ {printf "%s ", $1}') ; do
234 echo "<option value='$i' $([ "$i" == "$SRC_FILE" ] && echo "selected") >$i</option>"
235 usb=$usb+1
236 done
237 fi
238 fi
239 done
240 fi
241 if [ $usb -lt 1 ]; then
242 echo "<option value="">$(gettext "Not found")</option>"
243 fi
244 cat << EOT
245 </select>
246 </td>
247 </tr>
248 <tr>
249 <td><input type="radio" name="INST_TYPE" value="iso" $([ "$INST_TYPE" == "iso" ] && echo "checked") id="iso" />
250 <label for="iso">$(gettext "ISO file"):</label>
251 <input type="url" size="50" name="SRC_ISO" $([ "$INST_TYPE" == "iso" ] && echo -e "value=\"$SRC_FILE\"") placeholder="$(gettext "Full path to the ISO image file")" />
252 </td>
253 </tr>
254 <tr>
255 <td><input type="radio" name="INST_TYPE" value="web" $([ "$INST_TYPE" == "web" ] && echo "checked" id="web") />
256 <label for="web">$(gettext "Web"):
257 <a class="button" href="$SCRIPT_NAME?page=$(GET page)&SRC_WEB=stable">$(gettext "Stable")</a>
258 <a class="button" href="$SCRIPT_NAME?page=$(GET page)&SRC_WEB=cooking">$(gettext "Cooking")</a>
259 $(gettext "URL:")</label>
260 EOT
261 case $(GET SRC_WEB) in
262 stable|cooking)
263 get_SRC_WEB=$(tazinst showurl $(GET SRC_WEB)) ;;
264 *)
265 [ "$INST_TYPE" == "web" ] && get_SRC_WEB=$SRC_FILE ;;
266 esac
267 cat <<EOT
268 <input type="url" size="55" name="SRC_WEB" value="$get_SRC_WEB" placeholder="$(gettext "Full url to an ISO image file")" /></td>
269 </tr>
270 </table>
271 EOT
272 }
274 select_partition()
275 {
276 cat <<EOT
277 <a name="partition"></a>
278 <h4></span>$(gettext "Main Partition")</h4>
279 <table>
280 <tr><td>
281 $(gettext "Partition to use:")
282 <select name="TGT_PARTITION">
283 EOT
284 # List partitions
285 if fdisk -l | grep -q ^/dev/ ; then
286 for i in $(fdisk -l | awk '/^\/dev/ {printf "%s " $1}'); do
287 echo "<option value='$i' $([ "$i" == "$TGT_PARTITION" ] && echo "selected")>$i</option>"
288 done
289 else
290 echo "<option value="">$(gettext "Not found")</option>"
291 fi
292 cat << EOT
293 </select>
294 <br />
295 <input type="checkbox" name="MAIN_FMT" value="yes" $([ -n "$TGT_FS" ] && echo "checked") id="mainfs" />
296 <label for="mainfs">$(gettext "Format partition as"):</label>
297 <select name="MAIN_FS">
298 EOT
299 scan_mkfs
300 for i in $FS
301 do
302 echo "<option value='$i' $([ "$i" == "$TGT_FS" ] && echo "selected")>$i</option>"
303 done
304 cat <<EOT
305 </select>
306 </td></tr>
307 </table>
308 EOT
309 }
311 select_old_slitaz()
312 {
313 cat <<EOT
314 <a name="partition"></a>
315 <h4></span>$(gettext "Existing SliTaz Partition")</h4>
316 <table>
317 <tr><td>
318 $(gettext "Partition in use:")
319 <select name="TGT_PARTITION">
320 EOT
321 # List partitions
322 if fdisk -l | grep -q ^/dev/ ; then
323 for i in `blkid | cut -d ":" -f 1`; do
324 echo "<option value='$i' $([ "$i" == "$TGT_PARTITION" ] && echo "selected")>$i</option>"
325 done
326 else
327 echo "<option value="">$(gettext "Not found")</option>"
328 fi
329 cat <<EOT
330 </select>
331 </td></tr>
332 </table>
333 EOT
334 }
336 select_home()
337 {
338 cat <<EOT
339 <a name="home"></a>
340 <h4>$(gettext "Home partition")</h4>
341 <input type="checkbox" name="HOME_SPLIT" value="yes" $([ -n "$TGT_HOME" ] && echo "checked") id="homepart" />
342 <label for="homepart">$(gettext "Use a separate partition for /home:")</label>
343 <select name="HOME_PART">
344 EOT
345 # List disk if plugged USB device
346 if fdisk -l | grep -q ^/dev/ ; then
347 for i in $(fdisk -l | awk '/^\/dev/ {printf "%s " $1}'); do
348 echo "<option value='$i' $([ "$i" == "$TGT_HOME" ] && echo "selected")>$i</option>"
349 done
350 else
351 echo "<option value="">$(gettext "Not found")</option>"
352 fi
353 cat <<EOT
354 </select>
356 <input type="checkbox" name="HOME_FMT" value="yes" $([ -n "$TGT_HOME_FS" ] && echo "checked") id="homefs" />
357 <label for="homefs">$(gettext "Format partition as:")</label>
358 <select name="HOME_FS">"
359 EOT
360 for i in $FS
361 do
362 echo "<option value='$i' $([ "$i" == "$TGT_HOME_FS" ] && echo "selected")>$i</option>"
363 done
364 echo "</select>"
365 }
367 select_hostname()
368 {
369 cat << EOT
370 <a name="hostname"></a>
371 <h4>$(gettext "Host")</h4>
372 $(gettext "Hostname:")
373 <input type="text" name="TGT_HOSTNAME" value="$TGT_HOSTNAME" placeholder="$(gettext "Name of your system")" />
374 EOT
375 }
377 select_root()
378 {
379 cat << EOT
380 <a name="root"></a>
381 <h4>$(gettext "Root")</h4>
382 $(gettext "Root passwd:")
383 <input type="text" name="TGT_ROOT_PWD" value="$TGT_ROOT_PWD" placeholder="$(gettext "Password of root")" />
384 EOT
385 }
387 select_user()
388 {
389 cat << EOT
390 <a name="user"></a>
391 <h4>$(gettext "User")</h4>
392 $(gettext "User login:")
393 <input type="text" name="TGT_USER" value="$TGT_USER" placeholder="$(gettext "Name of the first user")" />
394 $(gettext "User passwd:")
395 <input type="text" name="TGT_USER_PWD" value="$TGT_USER_PWD" placeholder="$(gettext "Password of the first user")" />
396 EOT
397 }
399 select_grub()
400 {
401 cat << EOT
402 <a name="grub"></a>
403 <h4>$(gettext "Grub")</h4>
404 <input type="checkbox" name="TGT_GRUB" value="yes" $([ "$TGT_GRUB" == "yes" ] && echo "checked") id="grub" />
405 <label for="grub">$(gettext "Install Grub bootloader")<br /></label>
406 <input type="checkbox" name="TGT_WINBOOT" value="auto" $([ -n "$TGT_WINBOOT" ] && echo "checked") id="dualboot" />
407 <label for="dualboot">$(gettext "Enable Windows Dual-Boot")</label>
408 EOT
409 }
411 moveto_page()
412 {
413 case $1 in
414 *)
415 page=home
416 title1=$(gettext "Back to Installer Start Page") ;;
417 esac
418 case $2 in
419 write|run)
420 title2=$(gettext "Proceed to SliTaz installation") ;;
421 reboot)
422 title2=$(gettext "Installation complete. You can now restart (reboot)") ;;
423 failed)
424 title2=$(gettext "Installation failed. See log") ;;
425 *)
426 page=home
427 title2=$(gettext "Back to Installer Start Page") ;;
428 esac
429 cat <<EOT
430 <script type="text/javascript">
431 function SubmitForm() {
432 var r=confirm("$(gettext "Do you really want to continue?")");
433 if (r==true)
434 {
435 document.ConfigForm.submit();
436 }
437 }
438 </script>
439 <hr />
440 <input type="hidden" name="page" value="$2" />
441 <a class="button" value="$1" href="$SCRIPT_NAME?page=$1" >$title1</a>
442 <a class="button" value="$2" onclick="SubmitForm()">$title2</a>
443 EOT
444 }
446 page_redirection()
447 {
448 cat <<EOT
449 <html>
450 <head>
451 <title>$(gettext "A web page that points a browser to a different page after 2 seconds")</title>
452 <meta http-equiv="refresh" content="0; URL=$SCRIPT_NAME?page=$1">
453 <meta name="keywords" content="automatic redirection">
454 </head>
455 <body>
456 $(gettext "If your browser doesn't automatically redirect within a few seconds,
457 you may want to go there manually")
458 <a href="$SCRIPT_NAME?page=$1">$1</a>
459 </body>
460 </html>
461 EOT
462 }
464 check_ressources()
465 {
466 local code
467 code=0
468 # Check tazinst
469 if ! tazinst usage | grep -q Usage: ; then
470 cat <<EOT
471 <h3>$(gettext "Tazinst Error")</h3>
472 <p><strong>tazinst</strong>, $(gettext "the lightweight SliTaz HDD installer
473 is missing. Any installation can not be done without tazinst.")</p>
474 <p>$(gettext "Check tazinst' permissions, or reinstall the slitaz-tools package:")</p>
475 <code># tazpkg get-install slitaz-tools --forced</code>
476 EOT
477 code=1
478 else
479 # Check tazinst required version
480 v=$(tazinst version | tr -d '[:alpha:]')
481 r=$TAZINST_REQUIRED_VERSION
482 if ! (echo "$v" | awk -v r=$r '{v=$v+0}{ if (v < r) exit 1}') ; then
483 cat <<EOT
484 <h3>$(gettext "Tazinst Error")</h3>
485 <p><strong>tazinst</strong> ($v) $(gettext "is not at the required version ($r),
486 use tazinst in a xterm or reinstall the slitaz-tools package:")</p>
487 <code># tazpkg get-install slitaz-tools --forced</code>
488 EOT
489 code=1
490 fi
491 # Check setup file
492 if [ ! -e "$INSTFILE" ]; then
493 gettext "Creating setup file $INSTFILE."
494 tazinst new $INSTFILE
495 fi
496 if [ ! -e "$INSTFILE" ]; then
497 cat <<EOT
498 <h3>$(gettext "Setup File Error")</h3>
499 <p>$(gettext "The setup file <strong>$INSTFILE</strong> doesn't exist.")</p>
500 EOT
501 code=1
502 else
503 if [ ! -r $INSTFILE ]; then
504 cat <<EOT
505 <h3>$(gettext "Setup File Error")</h3>
506 <p>$(gettext "The setup file <strong>$INSTFILE</strong> is not readable.
507 Check permissions and ownership.")</p>
508 EOT
509 code=1
510 fi
511 fi
512 fi
513 return $code
514 }
516 run_tazinst()
517 {
518 echo "<h4>$(gettext "Proceeding: ()")</h4>"
519 gettext "Please wait until processing is complete"
520 table_start
521 tazinst $(GET INST_ACTION) $INSTFILE | \
522 awk '{print "<tr><td><tt>" $0 "</tt></td></tr>"}'
523 table_end
524 return $(grep -c "cancelled on error" $INSTFILE)
525 }
527 tazinst_log()
528 {
529 echo "<pre>"
530 tazinst log
531 echo "</pre>"
532 }
534 scan_mkfs()
535 {
536 for path in /bin /sbin /usr/bin /usr/sbin
537 do
538 [ -e $path/mkfs.btrfs ] && FS=btrfs
539 [ -e $path/mkfs.cramfs ] && FS="$FS cramfs"
540 [ -e $path/mkfs.ext2 ] && FS="$FS ext2"
541 [ -e $path/mkfs.ext3 ] && FS="$FS ext3"
542 [ -e $path/mkfs.ext4 ] && FS="$FS ext4"
543 [ -e $path/mkfs.vfat ] && FS="$FS fat32"
544 [ -e $path/mkfs.jfs ] && FS="$FS jfs"
545 [ -e $path/mkfs.minix ] && FS="$FS minix"
546 [ -e $path/mkfs.ntfs ] && FS="$FS ntfs"
547 [ -e $path/mkfs.reiserfs ] && FS="$FS reiserfs"
548 [ -e $path/mkfs.xfs ] && FS="$FS xfs"
549 done
550 }
552 form_start()
553 {
554 cat <<EOT
555 <form name="ConfigForm" method="get" action="$SCRIPT_NAME">
556 EOT
557 }
559 form_end()
560 {
561 echo "</form>"
562 }
564 #
565 # Main
566 #
568 case "$(GET page)" in
569 gparted)
570 /usr/sbin/gparted
571 xhtml_header
572 page_redirection home
573 ;;
574 install)
575 read_setup
576 xhtml_header
577 form_start
578 display_action install
579 check_setup
580 select_source
581 select_partition
582 select_home
583 select_hostname
584 select_root
585 select_user
586 select_grub
587 moveto_page home write
588 form_end
589 ;;
590 upgrade)
591 read_setup
592 xhtml_header
593 form_start
594 display_action upgrade
595 check_setup
596 select_source
597 select_old_slitaz
598 select_grub
599 moveto_page home write
600 form_end
601 ;;
602 write)
603 write_setup
604 xhtml_header
605 if ! (tazinst check $INSTFILE); then
606 page_redirection $(GET INST_ACTION)
607 else
608 read_setup
609 form_start
610 display_action $(GET INST_ACTION)
611 if run_tazinst; then
612 moveto_page home reboot
613 else
614 moveto_page home failed
615 fi
616 form_end
617 fi
618 ;;
619 reboot)
620 reboot ;;
621 home)
622 xhtml_header
623 select_action
624 select_gparted
625 select_install
626 select_upgrade
627 ;;
628 failed)
629 xhtml_header
630 display_log
631 ;;
632 menu_install)
633 xhtml_header
634 if check_ressources; then
635 select_action
636 select_gparted
637 select_install
638 fi
639 ;;
640 menu_upgrade)
641 xhtml_header
642 if check_ressources; then
643 select_action
644 select_upgrade
645 fi
646 ;;
647 *)
648 xhtml_header
649 if check_ressources; then
650 page_redirection home
651 fi
652 ;;
653 esac
655 xhtml_footer
657 exit 0