tazpanel view installer.cgi @ rev 208

Add Install tab (thanks Dominique)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Sep 02 13:46:24 2011 +0200 (2011-09-02)
parents
children f85527dffa0c
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/\&nbsp;/g')
103 line=$(echo $line | sed 's/</\&lt;/g')
104 line=$(echo $line | sed 's/>/\&gt;/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 upgrade 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>$(gettext "Before installation, you'll may need to resize partitions
129 on your hard disk drive in order to make space for SlItaz GNU/Linux.")</td>
130 </tr>
131 </table>
132 EOT
133 }
135 select_install()
136 {
137 cat <<EOT
138 </table>
139 <form method="get" action="$SCRIPT_NAME">
140 <table>
141 <tr>
142 <td><h4>$(gettext "Install")</h4></td>
143 </tr>
144 <tr>
145 <td>$(gettext "Install SliTaz on a partition of your hard disk drive. If
146 you decide to format your HDD, all data will be lost. If you do not
147 format, all data except for any existing /home directory will be removed,
148 the home directory will be kept as is.")</td>
149 </tr>
150 <tr>
151 <td><a class="button" href="$SCRIPT_NAME?page=install">$(gettext "Install SliTaz")</a></td>
152 </tr>
153 </table>
154 EOT
155 }
157 select_upgrade()
158 {
159 cat <<EOT
160 <table>
161 <tr>
162 <td><h4>$(gettext "Upgrade")</h4></td>
163 </tr>
164 <tr>
165 <td>$(gettext "Upgrade an already installed SliTaz system on your hard disk
166 drive. Your /home /etc /var/www directories will be kept, all other directories
167 will be removed. Any additional package added to your old Slitaz system
168 will be updated as long you have an active internet connection.")</td>
169 </tr>
170 <tr>
171 <td><a class="button" href="$SCRIPT_NAME?page=upgrade">$(gettext "Upgrade SliTaz")</a></td>
172 </tr>
173 </table>
174 </form>
175 EOT
176 }
178 display_action()
179 {
180 case $1 in
181 install)
182 cat << EOT
183 <div id="wrapper">
184 <h3>$(gettext "Install SliTaz")</h3>
185 <p>$(gettext "You're going to install SliTaz on a partition of your hard disk drive. If
186 you decide to format your HDD, all data will be lost. If you do not
187 format, all data except for any existing /home directory will be removed,
188 the home directory will be kept as is.")<p>
189 </div>
190 <input type="hidden" name="INST_ACTION" value="$1">
191 EOT
192 ;;
193 upgrade)
194 cat << EOT
195 <div id="wrapper">
196 <h2>$(gettext "Upgrade SliTaz")</h2>
197 <p>$(gettext "You're going to upgrade an already installed SliTaz system on your hard disk
198 drive. Your /home /etc /var/www directories will be kept, all other directories
199 will be removed. Any additional package added to your old Slitaz system
200 will be updated as long you have an active internet connection.")<p>
201 </div>
202 <input type="hidden" name="INST_ACTION" value="$1">
203 EOT
204 ;;
205 esac
206 }
208 select_source()
209 {
210 cat <<EOT
211 <a name="source"></a>
212 <h4>$(gettext "Source")</h4>
213 <table>
214 <tr>
215 <td><input type="radio" name="INST_TYPE" value="cdrom" $([ "$INST_TYPE" == "cdrom" ] && echo "checked") id="cdrom" />
216 <label for="cdrom">$(gettext "LiveCD")</td></label>
217 </tr>
218 <tr>
219 <td><input type="radio" name="INST_TYPE" value="usb" $([ "$INST_TYPE" == "usb" ] && echo "checked") id="usb" />
220 <label for="usb">$(gettext "LiveUSB"):</label>
221 <select name="SRC_USB">
222 EOT
223 # List disks if plugged USB device
224 usb=0
225 if [ -d /proc/scsi/usb-storage ]; then
226 for DEV in /sys/block/sd* ; do
227 if readlink $DEV | grep -q usb; then
228 DEV=$(basename $DEV)
229 if [ -d /sys/block/${DEV}/${DEV}1 ]; then
230 for i in $(fdisk -l /dev/$DEV | awk '/^\/dev/ {printf "%s ", $1}') ; do
231 echo "<option value='$i' $([ "$i" == "$SRC_FILE" ] && echo "selected") >$i</option>"
232 usb=$usb+1
233 done
234 fi
235 fi
236 done
237 fi
238 if [ $usb -lt 1 ]; then
239 echo "<option value="">$(gettext "Not found")</option>"
240 fi
241 cat << EOT
242 </select>
243 </td>
244 </tr>
245 <tr>
246 <td><input type="radio" name="INST_TYPE" value="iso" $([ "$INST_TYPE" == "iso" ] && echo "checked") id="iso" />
247 <label for="iso">$(gettext "ISO file"):</label>
248 <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")" />
249 </td>
250 </tr>
251 <tr>
252 <td><input type="radio" name="INST_TYPE" value="web" $([ "$INST_TYPE" == "web" ] && echo "checked" id="web") />
253 <label for="web">$(gettext "Web"):
254 <a class="button" href="$SCRIPT_NAME?page=$(GET page)&SRC_WEB=stable">$(gettext "Stable")</a>
255 <a class="button" href="$SCRIPT_NAME?page=$(GET page)&SRC_WEB=cooking">$(gettext "Cooking")</a>
256 $(gettext "URL:")</label>
257 EOT
258 case $(GET SRC_WEB) in
259 stable|cooking)
260 get_SRC_WEB=$(tazinst showurl $(GET SRC_WEB)) ;;
261 *)
262 [ "$INST_TYPE" == "web" ] && get_SRC_WEB=$SRC_FILE ;;
263 esac
264 cat <<EOT
265 <input type="url" size="55" name="SRC_WEB" value="$get_SRC_WEB" placeholder="$(gettext "Full url to an ISO image file")" /></td>
266 </tr>
267 </table>
268 EOT
269 }
271 select_partition()
272 {
273 cat <<EOT
274 <a name="partition"></a>
275 <h4></span>$(gettext "Main Partition")</h4>
276 <table>
277 <tr><td>
278 $(gettext "Partition to use:")
279 <select name="TGT_PARTITION">
280 EOT
281 # List partitions
282 if fdisk -l | grep -q ^/dev/ ; then
283 for i in $(fdisk -l | awk '/^\/dev/ {printf "%s " $1}'); do
284 echo "<option value='$i' $([ "$i" == "$TGT_PARTITION" ] && echo "selected")>$i</option>"
285 done
286 else
287 echo "<option value="">$(gettext "Not found")</option>"
288 fi
289 cat << EOT
290 </select>
291 <br />
292 <input type="checkbox" name="MAIN_FMT" value="yes" $([ -n "$TGT_FS" ] && echo "checked") id="mainfs" />
293 <label for="mainfs">$(gettext "Format partition as"):</label>
294 <select name="MAIN_FS">
295 EOT
296 scan_mkfs
297 for i in $FS
298 do
299 echo "<option value='$i' $([ "$i" == "$TGT_FS" ] && echo "selected")>$i</option>"
300 done
301 cat <<EOT
302 </select>
303 </td></tr>
304 </table>
305 EOT
306 }
308 select_old_slitaz()
309 {
310 cat <<EOT
311 <a name="partition"></a>
312 <h4></span>$(gettext "Existing SliTaz Partition")</h4>
313 <table>
314 <tr><td>
315 $(gettext "Partition in use:")
316 <select name="TGT_PARTITION">
317 EOT
318 # List partitions
319 if fdisk -l | grep -q ^/dev/ ; then
320 for i in `blkid | cut -d ":" -f 1`; do
321 echo "<option value='$i' $([ "$i" == "$TGT_PARTITION" ] && echo "selected")>$i</option>"
322 done
323 else
324 echo "<option value="">$(gettext "Not found")</option>"
325 fi
326 cat <<EOT
327 </select>
328 </td></tr>
329 </table>
330 EOT
331 }
333 select_home()
334 {
335 cat <<EOT
336 <a name="home"></a>
337 <h4>$(gettext "Home partition")</h4>
338 <input type="checkbox" name="HOME_SPLIT" value="yes" $([ -n "$TGT_HOME" ] && echo "checked") id="homepart" />
339 <label for="homepart">$(gettext "Use a separate partition for /home:")</label>
340 <select name="HOME_PART">
341 EOT
342 # List disk if plugged USB device
343 if fdisk -l | grep -q ^/dev/ ; then
344 for i in $(fdisk -l | awk '/^\/dev/ {printf "%s " $1}'); do
345 echo "<option value='$i' $([ "$i" == "$TGT_HOME" ] && echo "selected")>$i</option>"
346 done
347 else
348 echo "<option value="">$(gettext "Not found")</option>"
349 fi
350 cat <<EOT
351 </select>
353 <input type="checkbox" name="HOME_FMT" value="yes" $([ -n "$TGT_HOME_FS" ] && echo "checked") id="homefs" />
354 <label for="homefs">$(gettext "Format partition as:")</label>
355 <select name="HOME_FS">"
356 EOT
357 for i in $FS
358 do
359 echo "<option value='$i' $([ "$i" == "$TGT_HOME_FS" ] && echo "selected")>$i</option>"
360 done
361 echo "</select>"
362 }
364 select_hostname()
365 {
366 cat << EOT
367 <a name="hostname"></a>
368 <h4>$(gettext "Host")</h4>
369 $(gettext "Hostname:")
370 <input type="text" name="TGT_HOSTNAME" value="$TGT_HOSTNAME" placeholder="$(gettext "Name of your system")" />
371 EOT
372 }
374 select_root()
375 {
376 cat << EOT
377 <a name="root"></a>
378 <h4>$(gettext "Root")</h4>
379 $(gettext "Root passwd:")
380 <input type="text" name="TGT_ROOT_PWD" value="$TGT_ROOT_PWD" placeholder="$(gettext "Password of root")" />
381 EOT
382 }
384 select_user()
385 {
386 cat << EOT
387 <a name="user"></a>
388 <h4>$(gettext "User")</h4>
389 $(gettext "User login:")
390 <input type="text" name="TGT_USER" value="$TGT_USER" placeholder="$(gettext "Name of the first user")" />
391 $(gettext "User passwd:")
392 <input type="text" name="TGT_USER_PWD" value="$TGT_USER_PWD" placeholder="$(gettext "Password of the first user")" />
393 EOT
394 }
396 select_grub()
397 {
398 cat << EOT
399 <a name="grub"></a>
400 <h4>$(gettext "Grub")</h4>
401 <input type="checkbox" name="TGT_GRUB" value="yes" $([ "$TGT_GRUB" == "yes" ] && echo "checked") id="grub" />
402 <label for="grub">$(gettext "Install Grub bootloader")<br /></label>
403 <input type="checkbox" name="TGT_WINBOOT" value="auto" $([ -n "$TGT_WINBOOT" ] && echo "checked") id="dualboot" />
404 <label for="dualboot">$(gettext "Enable Windows Dual-Boot")</label>
405 EOT
406 }
408 moveto_page()
409 {
410 case $1 in
411 *)
412 page=home
413 title1=$(gettext "Back to Installer Start Page") ;;
414 esac
415 case $2 in
416 write|run)
417 title2=$(gettext "Proceed to SliTaz installation") ;;
418 reboot)
419 title2=$(gettext "Installation complete. You can now restart (reboot)") ;;
420 failed)
421 title2=$(gettext "Installation failed. See log") ;;
422 *)
423 page=home
424 title2=$(gettext "Back to Installer Start Page") ;;
425 esac
426 cat <<EOT
427 <script type="text/javascript">
428 function SubmitForm() {
429 var r=confirm("$(gettext "Do you really want to continue?")");
430 if (r==true)
431 {
432 document.ConfigForm.submit();
433 }
434 }
435 </script>
436 <hr />
437 <input type="hidden" name="page" value="$2" />
438 <a class="button" value="$1" href="$SCRIPT_NAME?page=$1" >$title1</a>
439 <a class="button" value="$2" onclick="SubmitForm()">$title2</a>
440 EOT
441 }
443 page_redirection()
444 {
445 cat <<EOT
446 <html>
447 <head>
448 <title>$(gettext "A web page that points a browser to a different page after 2 seconds")</title>
449 <meta http-equiv="refresh" content="0; URL=$SCRIPT_NAME?page=$1">
450 <meta name="keywords" content="automatic redirection">
451 </head>
452 <body>
453 $(gettext "If your browser doesn't automatically go there within a few seconds,
454 you may want to go manually to ")
455 <a href="$SCRIPT_NAME?page=$1">$1</a>
456 </body>
457 </html>
458 EOT
459 }
461 check_ressources()
462 {
463 local code
464 code=0
465 # Check tazinst
466 if ! tazinst usage | grep -q Usage: ; then
467 cat <<EOT
468 <h3>$(gettext "Tazinst Error")</h3>
469 <p><strong>tazinst</strong>, $(gettext "the lightweight SliTaz HDD installer
470 is missing. Any installation can't be done without tazinst.")</p>
471 <p>$(gettext "Check tazinst' permissions, or reinstall the slitaz-tools package:")</p>
472 <code># tazpkg get-install slitaz-tools --forced</code>
473 EOT
474 code=1
475 else
476 # Check tazinst required version
477 v=$(tazinst version | tr -d '[:alpha:]')
478 r=$TAZINST_REQUIRED_VERSION
479 if ! (echo "$v" | awk -v r=$r '{v=$v+0}{ if (v < r) exit 1}') ; then
480 cat <<EOT
481 <h3>$(gettext "Tazinst Error")</h3>
482 <p><strong>tazinst</strong> ($v) $(gettext "is not at the required version ($r),
483 use tazinst in a xterm or reinstall the slitaz-tools package:")</p>
484 <code># tazpkg get-install slitaz-tools --forced</code>
485 EOT
486 code=1
487 fi
488 # Check setup file
489 if [ ! -e "$INSTFILE" ]; then
490 gettext "Creating setup file $INSTFILE."
491 tazinst new $INSTFILE
492 fi
493 if [ ! -e "$INSTFILE" ]; then
494 cat <<EOT
495 <h3>$(gettext "Setup File Error")</h3>
496 <p>$(gettext "The setup file <strong>$INSTFILE</strong> doesn't exists.")</p>
497 EOT
498 code=1
499 else
500 if [ ! -r $INSTFILE ]; then
501 cat <<EOT
502 <h3>$(gettext "Setup File Error")</h3>
503 <p>$(gettext "The setup file <strong>$INSTFILE</strong> is not readable.
504 Check permissions and ownership.")</p>
505 EOT
506 code=1
507 fi
508 fi
509 fi
510 return $code
511 }
513 run_tazinst()
514 {
515 echo "<h4>$(gettext "Proceeding: ()")</h4>"
516 gettext "Please wait until processing is complete"
517 table_start
518 tazinst $(GET INST_ACTION) $INSTFILE | \
519 awk '{print "<tr><td><tt>" $0 "</tt></td></tr>"}'
520 table_end
521 return $(grep -c "cancelled on error" $INSTFILE)
522 }
524 tazinst_log()
525 {
526 echo "<pre>"
527 tazinst log
528 echo "</pre>"
529 }
531 scan_mkfs()
532 {
533 for path in /bin /sbin /usr/bin /usr/sbin
534 do
535 [ -e $path/mkfs.btrfs ] && FS=btrfs
536 [ -e $path/mkfs.cramfs ] && FS="$FS cramfs"
537 [ -e $path/mkfs.ext2 ] && FS="$FS ext2"
538 [ -e $path/mkfs.ext3 ] && FS="$FS ext3"
539 [ -e $path/mkfs.ext4 ] && FS="$FS ext4"
540 [ -e $path/mkfs.vfat ] && FS="$FS fat32"
541 [ -e $path/mkfs.jfs ] && FS="$FS jfs"
542 [ -e $path/mkfs.minix ] && FS="$FS minix"
543 [ -e $path/mkfs.ntfs ] && FS="$FS ntfs"
544 [ -e $path/mkfs.reiserfs ] && FS="$FS reiserfs"
545 [ -e $path/mkfs.xfs ] && FS="$FS xfs"
546 done
547 }
549 form_start()
550 {
551 cat <<EOT
552 <form name="ConfigForm" method="get" action="$SCRIPT_NAME">
553 EOT
554 }
556 form_end()
557 {
558 echo "</form>"
559 }
561 #
562 # Main
563 #
565 case "$(GET page)" in
566 gparted)
567 /usr/sbin/gparted
568 xhtml_header
569 page_redirection home
570 ;;
571 install)
572 read_setup
573 xhtml_header
574 form_start
575 display_action install
576 check_setup
577 select_source
578 select_partition
579 select_home
580 select_hostname
581 select_root
582 select_user
583 select_grub
584 moveto_page home write
585 form_end
586 ;;
587 upgrade)
588 read_setup
589 xhtml_header
590 form_start
591 display_action upgrade
592 check_setup
593 select_source
594 select_old_slitaz
595 select_grub
596 moveto_page home write
597 form_end
598 ;;
599 write)
600 write_setup
601 xhtml_header
602 if ! (tazinst check $INSTFILE); then
603 page_redirection $(GET INST_ACTION)
604 else
605 read_setup
606 form_start
607 display_action $(GET INST_ACTION)
608 if run_tazinst; then
609 moveto_page home reboot
610 else
611 moveto_page home failed
612 fi
613 form_end
614 fi
615 ;;
616 reboot)
617 reboot ;;
618 home)
619 xhtml_header
620 select_action
621 select_gparted
622 select_install
623 select_upgrade
624 ;;
625 failed)
626 xhtml_header
627 display_log
628 ;;
629 *)
630 xhtml_header
631 if check_ressources; then
632 page_redirection home
633 fi
634 ;;
635 esac
637 xhtml_footer
639 exit 0