tazpanel view installer.cgi @ rev 260

installer.cgi: hide and check passwords
author Dominique Corbex <domcox@slitaz.org>
date Sat Mar 03 12:14:00 2012 +0100 (2012-03-03)
parents a254da4c8c28
children 9bcc77055db5
line source
1 #!/bin/sh
2 #
3 # Main CGI interface for Tazinst, the SliTaz installer.
4 #
5 # Copyright (C) 2012 SliTaz GNU/Linux - BSD License
6 #
7 # Authors : Dominique Corbex <domcox@slitaz.org>
8 #
10 VERSION=0.25
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
33 write_setup()
34 {
35 if [ -e "$INSTFILE" ]; then
36 # Install type
37 INST_TYPE=$(GET INST_TYPE)
38 # Source File
39 case "$INST_TYPE" in
40 usb)
41 SRC_FILE=$(GET SRC_USB) ;;
42 iso)
43 SRC_FILE=$(GET SRC_ISO) ;;
44 web)
45 SRC_FILE=$(GET SRC_WEB) ;;
46 esac
47 SRC_FILE=$(echo "$SRC_FILE" | sed 's/\//\\\//'g)
48 [ -n $(GET URL) ] && SRC_WEB=$(GET URL)
49 # Main Partition
50 TGT_PARTITION=$(echo "$(GET TGT_PARTITION)" | sed 's/\//\\\//'g)
51 [ -n "$(GET MAIN_FMT)" ] && TGT_FS=$(GET MAIN_FS) || TGT_FS=""
52 # Home Partition
53 if [ -n "$(GET HOME_SELECT)" ] ; then
54 TGT_HOME=$(echo "$(GET TGT_HOME)" | sed 's/\//\\\//'g)
55 [ -n "$(GET HOME_FS)" ] && TGT_HOME_FS=$(GET HOME_FS)
56 else
57 TGT_HOME=""
58 TGT_HOME_FS=""
59 fi
60 # Hostname
61 TGT_HOSTNAME=$(GET TGT_HOSTNAME)
62 # Root pwd
63 TGT_ROOT_PWD=$(GET TGT_ROOT_PWD)
64 # User Login
65 TGT_USER=$(GET TGT_USER)
66 # User Pwd
67 TGT_USER_PWD=$(GET TGT_USER_PWD)
68 # Grub
69 TGT_GRUB=$(GET TGT_GRUB)
70 [ "$TGT_GRUB" == "yes" ] || TGT_GRUB=no
71 # Win Dual-Boot
72 TGT_WINBOOT=$(GET TGT_WINBOOT)
74 # Save changes to INSTFILE
75 sed -i s/"^INST_TYPE=.*"/"INST_TYPE=\"$INST_TYPE\"/" $INSTFILE
76 sed -i s/"^SRC_FILE=.*"/"SRC_FILE=\"$SRC_FILE\"/" $INSTFILE
77 sed -i s/"^TGT_PARTITION=.*"/"TGT_PARTITION=\"$TGT_PARTITION\"/" $INSTFILE
78 sed -i s/"^TGT_FS=.*"/"TGT_FS=\"$TGT_FS\"/" $INSTFILE
79 sed -i s/"^TGT_HOME=.*"/"TGT_HOME=\"$TGT_HOME\"/" $INSTFILE
80 sed -i s/"^TGT_HOME_FS=.*"/"TGT_HOME_FS=\"$TGT_HOME_FS\"/" $INSTFILE
81 sed -i s/"^TGT_HOSTNAME=.*"/"TGT_HOSTNAME=\"$TGT_HOSTNAME\"/" $INSTFILE
82 sed -i s/"^TGT_ROOT_PWD=.*"/"TGT_ROOT_PWD=\"$TGT_ROOT_PWD\"/" $INSTFILE
83 sed -i s/"^TGT_USER=.*"/"TGT_USER=\"$TGT_USER\"/" $INSTFILE
84 sed -i s/"^TGT_USER_PWD=.*"/"TGT_USER_PWD=\"$TGT_USER_PWD\"/" $INSTFILE
85 sed -i s/"^TGT_GRUB=.*"/"TGT_GRUB=\"$TGT_GRUB\"/" $INSTFILE
86 sed -i s/"^TGT_WINBOOT=.*"/"TGT_WINBOOT=\"$TGT_WINBOOT\"/" $INSTFILE
87 fi
88 }
90 read_setup()
91 {
92 # various checks on setup file
93 if [ -e "$INSTFILE" ]; then
94 # validity check + reformat output
95 IFS=$'\n'
96 for line in $(tazinst check $INSTFILE)
97 do
98 line=$(echo $line | sed 's/\[1m//g')
99 line=$(echo $line | sed 's/\[0m//g')
100 line=$(echo $line | sed 's/\s/\&nbsp;/g')
101 line=$(echo $line | sed 's/</\&lt;/g')
102 line=$(echo $line | sed 's/>/\&gt;/g')
103 echo "<font color=\"red\">$line<br /></font>"
104 done
105 unset IFS
106 else
107 # no setup file found: creating
108 gettext "Creating setup file $INSTFILE."
109 tazinst new $INSTFILE
110 if [ ! -e "$INSTFILE" ]; then
111 cat <<EOT
112 <font color="red">$(gettext "Setup File Error")<br />
113 $(gettext "The setup file <strong>$INSTFILE</strong> doesn't exist.")</font><br />
114 EOT
115 else
116 if [ ! -r $INSTFILE ]; then
117 cat <<EOT
118 <font color="red">$(gettext "Setup File Error")<br />
119 $(gettext "The setup file <strong>$INSTFILE</strong> is not readable.
120 Check permissions and ownership.")</font><br />
121 EOT
122 fi
123 fi
124 fi
125 # read setup file
126 . $INSTFILE
127 }
129 select_action()
130 {
131 cat <<EOT
132 <div id="wrapper">
133 <h2>$(gettext "SliTaz Installer")</h2>
134 <p>$(gettext "The SliTaz Installer installs or upgrades SliTaz to a hard disk
135 drive from a device like a Live-CD or LiveUSB key, from a SliTaz ISO file, or
136 from the web by downloading an ISO file.")<p>
137 </div>
138 EOT
139 }
141 select_gparted()
142 {
143 cat <<EOT
144 <div class="box">
145 <h4>$(gettext "About")</h4>
146 <p>
147 $(gettext "Before installation, you may need to resize partitions
148 on your hard disk drive in order to make space for SliTaz GNU/Linux.
149 You can graphically manage your partitions with Gparted")
150 </p>
151 </div>
152 <a class="button" href="$SCRIPT_NAME?page=gparted">$(gettext "Execute Gparted")</a>
153 EOT
154 }
156 select_install()
157 {
158 cat <<EOT
159 <div class="box">
160 <h4>$(gettext "Install")</h4>
161 <p>
162 $(gettext "Install SliTaz on a partition of your hard disk drive. If
163 you decide to format your HDD, all data will be lost. If you do not
164 format, all data except for any existing /home directory will be removed,
165 the home directory will be kept as is.")
166 </p>
167 </div>
168 <p>
169 <a class="button" href="$SCRIPT_NAME?page=install">$(gettext "Install SliTaz")</a>
170 EOT
171 }
173 select_upgrade()
174 {
175 cat <<EOT
176 <div class="box">
177 <h4>$(gettext "Upgrade")</h4>
178 <p>
179 $(gettext "Upgrade an already installed SliTaz system on your hard disk
180 drive. Your /home /etc /var/www directories will be kept, all other directories
181 will be removed. Any additional packages added to your old Slitaz system
182 will be updated as long you have an active internet connection.")
183 </p>
184 </div>
185 <p>
186 <a class="button" href="$SCRIPT_NAME?page=upgrade">$(gettext "Upgrade SliTaz")</a>
187 </p>
188 EOT
189 }
191 display_action()
192 {
193 case $1 in
194 install)
195 cat << EOT
196 <div id="wrapper">
197 <h3>$(gettext "Install SliTaz")</h3>
198 <p>$(gettext "You're going to install SliTaz on a partition of your hard disk drive. If
199 you decide to format your HDD, all data will be lost. If you do not
200 format, all data except for any existing /home directory will be removed,
201 the home directory will be kept as is.")<p>
202 </div>
203 <input type="hidden" name="INST_ACTION" value="$1">
204 EOT
205 ;;
206 upgrade)
207 cat << EOT
208 <div id="wrapper">
209 <h2>$(gettext "Upgrade SliTaz")</h2>
210 <p>$(gettext "You're going to upgrade an already installed SliTaz system on your hard disk
211 drive. Your /home /etc /var/www directories will be kept, all other directories
212 will be removed. Any additional packages added to your old Slitaz system
213 will be updated as long you have an active internet connection.")<p>
214 </div>
215 <input type="hidden" name="INST_ACTION" value="$1">
216 EOT
217 ;;
218 esac
219 }
221 select_source()
222 {
223 cat <<EOT
224 <a name="source"></a>
225 <h4>$(gettext "Source")</h4>
226 <div class="box">
227 <input type="radio" name="INST_TYPE" value="cdrom" $([ "$INST_TYPE" == "cdrom" ] && echo "checked") id="cdrom" />
228 <label for="cdrom">$(gettext "LiveCD")</td></label>
229 <br />
230 <input type="radio" name="INST_TYPE" value="usb" $([ "$INST_TYPE" == "usb" ] && echo "checked") id="usb" />
231 <label for="usb">$(gettext "LiveUSB"):
232 <select name="SRC_USB">
233 EOT
234 # List disks if plugged USB device
235 usb=0
236 if [ -d /proc/scsi/usb-storage ]; then
237 for DEV in /sys/block/sd* ; do
238 if readlink $DEV | grep -q usb; then
239 DEV=$(basename $DEV)
240 if [ -d /sys/block/${DEV}/${DEV}1 ]; then
241 for i in $(fdisk -l /dev/$DEV | awk '/^\/dev/ {printf "%s ", $1}') ; do
242 echo "<option value='$i' $([ "$i" == "$SRC_FILE" ] && echo "selected") >$i</option>"
243 usb=$usb+1
244 done
245 fi
246 fi
247 done
248 fi
249 if [ $usb -lt 1 ]; then
250 echo "<option value="">$(gettext "Not found")</option>"
251 fi
252 cat << EOT
253 </select>
254 </label>
255 <br />
256 <input type="radio" name="INST_TYPE" value="iso" $([ "$INST_TYPE" == "iso" ] && echo "checked") id="iso" />
257 <label for="iso">$(gettext "ISO file"):</label>
258 <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")" />
259 <br />
260 <input type="radio" name="INST_TYPE" value="web" $([ "$INST_TYPE" == "web" ] && echo "checked") id="web" />
261 <label for="web">$(gettext "Web"):
262 <a class="button" onclick="document.forms['ConfigForm'].url.value = '$(tazinst showurl stable)'; return true;">$(gettext "Stable")</a>
263 <a class="button" onclick="document.forms['ConfigForm'].url.value = '$(tazinst showurl cooking)'; return true;">$(gettext "Cooking")</a>
264 $(gettext "URL:")
265 <input id="url" type="url" size="55" name="SRC_WEB" value="$get_SRC_WEB" placeholder="$(gettext "Full url to an ISO image file")" />
266 </label>
267 </div>
268 EOT
269 }
271 select_partition()
272 {
273 cat <<EOT
274 <a name="partition"></a>
275 <h4></span>$(gettext "Main Partition")</h4>
276 <div class="box">
277 $(gettext "Partition to use:")
278 <select name="TGT_PARTITION">
279 EOT
280 # List partitions
281 if fdisk -l | grep -q ^/dev/ ; then
282 echo "<option value="">$(gettext "None")</option>"
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 </div>
304 EOT
305 }
307 select_old_slitaz()
308 {
309 cat <<EOT
310 <a name="partition"></a>
311 <h4></span>$(gettext "Existing SliTaz Partition")</h4>
312 <div class="box">
313 $(gettext "Partition in use:")
314 <select name="TGT_PARTITION">
315 EOT
316 # List partitions
317 if fdisk -l | grep -q ^/dev/ ; then
318 echo "<option value="">$(gettext "None")</option>"
319 for i in `blkid | cut -d ":" -f 1`; do
320 echo "<option value='$i' $([ "$i" == "$TGT_PARTITION" ] && echo "selected")>$i</option>"
321 done
322 else
323 echo "<option value="">$(gettext "Not found")</option>"
324 fi
325 cat <<EOT
326 </select>
327 </div>
328 EOT
329 }
331 select_home()
332 {
333 cat <<EOT
334 <a name="home"></a>
335 <h4>$(gettext "Home partition")</h4>
336 <input type="checkbox" name="HOME_SELECT" value="yes" $([ -n "$TGT_HOME" ] && echo "checked") id="homepart" />
337 <label for="homepart">$(gettext "Use a separate partition for /home:")</label>
338 <select name="TGT_HOME">
339 EOT
340 # List disk if plugged USB device
341 if fdisk -l | grep -q ^/dev/ ; then
342 echo "<option value="">$(gettext "None")</option>"
343 for i in $(fdisk -l | awk '/^\/dev/ {printf "%s " $1}'); do
344 echo "<option value='$i' $([ "$i" == "$TGT_HOME" ] && echo "selected")>$i</option>"
345 done
346 else
347 echo "<option value="">$(gettext "Not found")</option>"
348 fi
349 cat <<EOT
350 </select>
352 <input type="checkbox" name="HOME_FMT" value="yes" $([ -n "$TGT_HOME_FS" ] && echo "checked") id="homefs" />
353 <label for="homefs">$(gettext "Format partition as:")</label>
354 <select name="HOME_FS">"
355 EOT
356 for i in $FS
357 do
358 echo "<option value='$i' $([ "$i" == "$TGT_HOME_FS" ] && echo "selected")>$i</option>"
359 done
360 echo "</select>"
361 }
363 select_hostname()
364 {
365 cat << EOT
366 <script type="text/javascript">
367 function checkHostname(){
368 var host = document.getElementById('h1');
369 var msg = document.getElementById('hostAlert');
370 var enoughRegex = new RegExp("(?=.{3,}).*", "g");
371 var incharRegex = new RegExp("^[A-Za-z0-9_]{3,20}$");
372 if (false == enoughRegex.test(host.value)) {
373 msg.style.color = "tomato";
374 msg.innerHTML ="&#x2716; Too short";
375 return false;
376 } else if (false == incharRegex.test(host.value)) {
377 msg.style.color = "tomato";
378 msg.innerHTML ="&#x2716; Invalid chars";
379 return false;
380 } else {
381 msg.style.color = "limegreen";
382 msg.innerHTML = "&#x2714;";
383 }
384 }
385 </script>
386 <a name="hostname"></a>
387 <h4>$(gettext "Host")</h4>
388 $(gettext "Hostname:")
389 <input type="text" id="h1" name="TGT_HOSTNAME" value="$TGT_HOSTNAME" placeholder="$(gettext "Name of your system")" onkeyup="checkHostname(); return false;" />
390 <span id="hostAlert"></span>
391 EOT
392 }
394 select_root()
395 {
396 cat << EOT
397 <script type="text/javascript">
398 function checkRootPwd(){
399 var pwd1 = document.getElementById('p1');
400 var pwd2 = document.getElementById('p2');
401 var msg = document.getElementById('rootPwdAlert');
402 if(pwd1.value == pwd2.value){
403 // passwords match.
404 pwd2.style.backgroundColor = "white";
405 // various checks
406 var enoughRegex = new RegExp("(?=.{4,}).*", "g");
407 var incharRegex = new RegExp("^[A-Za-z0-9!@#$%^&*()_]{4,20}$");
408 var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
409 var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
410 if (pwd1.value.length==0) {
411 msg.style.color = "tomato";
412 msg.innerHTML = "&#x2716; Missing Password";
413 return false;
414 } else if (false == enoughRegex.test(pwd1.value)) {
415 msg.style.color = "tomato";
416 msg.innerHTML ="&#x2716; Too short";
417 return false;
418 } else if (false == incharRegex.test(pwd1.value)) {
419 msg.style.color = "tomato";
420 msg.innerHTML ="&#x2716; Invalid chars";
421 return false;
422 } else if (strongRegex.test(pwd1.value)) {
423 msg.style.color = "limegreen";
424 msg.innerHTML = "&#x2714; Strong!";
425 } else if (mediumRegex.test(pwd1.value)) {
426 msg.style.color = "limegreen";
427 msg.innerHTML = "&#x2714; Medium!";
428 } else {
429 msg.style.color = "orange";
430 msg.innerHTML = "&#x2714; Weak";
431 }
432 }else{
433 // passwords do not match.
434 pwd2.style.backgroundColor = "lightsalmon";
435 msg.style.color = "tomato";
436 msg.innerHTML = "&#x2716; Do Not Match!"
437 return false;
438 }
439 }
440 </script>
442 <a name="root"></a>
443 <h4>$(gettext "Root")</h4>
444 $(gettext "Root passwd:")
445 <input type="password" id="p1" name="TGT_ROOT_PWD" value="$TGT_ROOT_PWD" placeholder="$(gettext "Password of root")" onkeyup="checkRootPwd(); return false;" />
446 $(gettext "Confirm password:")
447 <input type="password" id="p2" value="$TGT_ROOT_PWD" placeholder="$(gettext "Password of root")" onkeyup="checkRootPwd(); return false;" />
448 <span id="rootPwdAlert"></span>
449 EOT
450 }
452 select_user()
453 {
454 cat << EOT
455 <script type="text/javascript">
456 function checkUserLogin(){
457 var user = document.getElementById('u1');
458 var msg = document.getElementById('userLoginAlert');
459 var enoughRegex = new RegExp("(?=.{3,}).*", "g");
460 var incharRegex = new RegExp("^[A-Za-z0-9_]{3,20}$");
461 if (false == enoughRegex.test(user.value)) {
462 msg.style.color = "tomato";
463 msg.innerHTML ="&#x2716; Too short";
464 return false;
465 } else if (false == incharRegex.test(user.value)) {
466 msg.style.color = "tomato";
467 msg.innerHTML ="&#x2716; Invalid chars";
468 return false;
469 } else {
470 msg.style.color = "limegreen";
471 msg.innerHTML = "&#x2714;";
472 }
473 }
474 function checkUserPwd(){
475 var pwd1 = document.getElementById('p3');
476 var pwd2 = document.getElementById('p4');
477 var msg = document.getElementById('userPwdAlert');
478 if(pwd1.value == pwd2.value){
479 // passwords match.
480 pwd2.style.backgroundColor = "white";
481 // various checks
482 var enoughRegex = new RegExp("(?=.{3,}).*", "g");
483 var incharRegex = new RegExp("^[A-Za-z0-9!@#$%^&*()_]{3,20}$");
484 var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
485 var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
486 if (pwd1.value.length==0) {
487 msg.style.color = "orange";
488 msg.innerHTML = "&#x2714; No Password";
489 } else if (false == enoughRegex.test(pwd1.value)) {
490 msg.style.color = "tomato";
491 msg.innerHTML ="&#x2716; Too short";
492 return false;
493 } else if (false == incharRegex.test(pwd1.value)) {
494 msg.style.color = "tomato";
495 msg.innerHTML ="&#x2716; Invalid chars";
496 return false;
497 } else if (strongRegex.test(pwd1.value)) {
498 msg.style.color = "limegreen";
499 msg.innerHTML = "&#x2714; Strong!";
500 } else if (mediumRegex.test(pwd1.value)) {
501 msg.style.color = "limegreen";
502 msg.innerHTML = "&#x2714; Medium!";
503 } else {
504 msg.style.color = "orange";
505 msg.innerHTML = "&#x2714; Weak";
506 }
507 }else{
508 // passwords do not match.
509 pwd2.style.backgroundColor = "lightsalmon";
510 msg.style.color = "tomato";
511 msg.innerHTML = "&#x2716; Do Not Match!"
512 return false;
513 }
514 }
515 </script>
516 <a name="user"></a>
517 <h4>$(gettext "User")</h4>
518 $(gettext "User login:")
519 <input type="text" id="u1" name="TGT_USER" value="$TGT_USER" placeholder="$(gettext "Name of the first user")" onkeyup="checkUserLogin(); return false;" />
520 <span id="userLoginAlert"></span>
521 <br /><br />
522 $(gettext "User passwd:")
523 <input type="password" id="p3" name="TGT_USER_PWD" value="$TGT_USER_PWD" placeholder="$(gettext "Password of the first user")" onkeyup="checkUserPwd(); return false;" />
524 $(gettext "Confirm password:")
525 <input type="password" id="p4" value="$TGT_USER_PWD" placeholder="$(gettext "Password of the first user")" onkeyup="checkUserPwd(); return false;" />
526 <span id="userPwdAlert"></span>
527 EOT
528 }
530 select_grub()
531 {
532 cat << EOT
533 <a name="grub"></a>
534 <h4>$(gettext "Grub")</h4>
535 <input type="checkbox" name="TGT_GRUB" value="yes" $([ "$TGT_GRUB" == "yes" ] && echo "checked") id="grub" />
536 <label for="grub">$(gettext "Install Grub bootloader")<br /></label>
537 <input type="checkbox" name="TGT_WINBOOT" value="auto" $([ -n "$TGT_WINBOOT" ] && echo "checked") id="dualboot" />
538 <label for="dualboot">$(gettext "Enable Windows Dual-Boot")</label>
539 EOT
540 }
542 moveto_page()
543 {
544 case $1 in
545 *)
546 page=home
547 title1=$(gettext "Back to Installer Start Page") ;;
548 esac
549 case $2 in
550 write|run)
551 title2=$(gettext "Proceed to SliTaz installation") ;;
552 reboot)
553 title2=$(gettext "Installation complete. You can now restart (reboot)") ;;
554 failed)
555 title2=$(gettext "Installation failed. See log") ;;
556 *)
557 page=home
558 title2=$(gettext "Back to Installer Start Page") ;;
559 esac
560 cat <<EOT
561 <script type="text/javascript">
562 function SubmitForm() {
563 if (false == checkHostname()) {
564 alert("Hostname error");
565 } else if (false == checkRootPwd()) {
566 alert("Root password error");
567 } else if (false == checkUserLogin()) {
568 alert("User login error");
569 } else if (false == checkUserPwd()) {
570 alert("User password error");
571 } else {
572 var r=confirm("$(gettext "Do you really want to continue?")");
573 if (r==true)
574 {
575 document.ConfigForm.submit();
576 }
577 }
578 }
579 </script>
580 <hr />
581 <input type="hidden" name="page" value="$2" />
582 <a class="button" value="$1" href="$SCRIPT_NAME?page=$1" >$title1</a>
583 <a class="button" value="$2" onclick="SubmitForm()">$title2</a>
584 EOT
585 }
587 page_redirection()
588 {
589 cat <<EOT
590 <html>
591 <head>
592 <title>$(gettext "A web page that points a browser to a different page after 2 seconds")</title>
593 <meta http-equiv="refresh" content="0; URL=$SCRIPT_NAME?page=$1">
594 <meta name="keywords" content="automatic redirection">
595 </head>
596 <body>
597 $(gettext "If your browser doesn't automatically redirect within a few seconds,
598 you may want to go there manually")
599 <a href="$SCRIPT_NAME?page=$1">$1</a>
600 </body>
601 </html>
602 EOT
603 }
605 check_ressources()
606 {
607 local code
608 code=0
609 # Check tazinst
610 if ! tazinst usage | grep -q Usage: ; then
611 cat <<EOT
612 <h3>$(gettext "Tazinst Error")</h3>
613 <p><strong>tazinst</strong>, $(gettext "the lightweight SliTaz HDD installer
614 is missing. Any installation can not be done without tazinst.")</p>
615 <p>$(gettext "Check tazinst' permissions, or reinstall the slitaz-tools package:")</p>
616 <code># tazpkg get-install slitaz-tools --forced</code>
617 EOT
618 code=1
619 else
620 # Check tazinst required version
621 v=$(tazinst version | tr -d '[:alpha:]')
622 r=$TAZINST_REQUIRED_VERSION
623 if ! (echo "$v" | awk -v r=$r '{v=$v+0}{ if (v < r) exit 1}') ; then
624 cat <<EOT
625 <h3>$(gettext "Tazinst Error")</h3>
626 <p><strong>tazinst</strong> ($v) $(gettext "is not at the required version ($r),
627 use tazinst in a xterm or reinstall the slitaz-tools package:")</p>
628 <code># tazpkg get-install slitaz-tools --forced</code>
629 EOT
630 code=1
631 fi
632 fi
633 return $code
634 }
636 run_tazinst()
637 {
638 echo "<h4>$(gettext "Proceeding: ()")</h4>"
639 gettext "Please wait until processing is complete"
640 table_start
641 tazinst $(GET INST_ACTION) $INSTFILE | \
642 awk '{print "<tr><td><tt>" $0 "</tt></td></tr>"}'
643 table_end
644 return $(grep -c "cancelled on error" $INSTFILE)
645 }
647 tazinst_log()
648 {
649 echo "<pre>"
650 tazinst log
651 echo "</pre>"
652 }
654 scan_mkfs()
655 {
656 for path in /bin /sbin /usr/bin /usr/sbin
657 do
658 [ -e $path/mkfs.btrfs ] && FS=btrfs
659 [ -e $path/mkfs.cramfs ] && FS="$FS cramfs"
660 [ -e $path/mkfs.ext2 ] && FS="$FS ext2"
661 [ -e $path/mkfs.ext3 ] && FS="$FS ext3"
662 [ -e $path/mkfs.ext4 ] && FS="$FS ext4"
663 [ -e $path/mkfs.jfs ] && FS="$FS jfs"
664 [ -e $path/mkfs.minix ] && FS="$FS minix"
665 [ -e $path/mkfs.reiserfs ] && FS="$FS reiserfs"
666 [ -e $path/mkfs.xfs ] && FS="$FS xfs"
667 done
668 }
670 form_start()
671 {
672 cat <<EOT
673 <form name="ConfigForm" method="get" action="$SCRIPT_NAME">
674 EOT
675 }
677 form_end()
678 {
679 echo "</form>"
680 }
682 #
683 # Main
684 #
686 case "$(GET page)" in
687 gparted)
688 /usr/sbin/gparted
689 xhtml_header
690 page_redirection home
691 ;;
692 install)
693 xhtml_header
694 form_start
695 display_action install
696 read_setup
697 select_source
698 select_partition
699 select_home
700 select_hostname
701 select_root
702 select_user
703 select_grub
704 moveto_page home write
705 form_end
706 ;;
707 upgrade)
708 xhtml_header
709 form_start
710 display_action upgrade
711 read_setup
712 select_source
713 select_old_slitaz
714 select_grub
715 moveto_page home write
716 form_end
717 ;;
718 write)
719 write_setup
720 xhtml_header
721 if ! (tazinst check $INSTFILE); then
722 page_redirection $(GET INST_ACTION)
723 else
724 read_setup
725 form_start
726 display_action $(GET INST_ACTION)
727 if run_tazinst; then
728 moveto_page home reboot
729 else
730 moveto_page home failed
731 fi
732 form_end
733 fi
734 ;;
735 reboot)
736 reboot ;;
737 home)
738 xhtml_header
739 select_action
740 select_gparted
741 select_install
742 select_upgrade
743 ;;
744 failed)
745 xhtml_header
746 display_log
747 ;;
748 menu_install)
749 xhtml_header
750 if check_ressources; then
751 page_redirection install
752 fi
753 ;;
754 menu_upgrade)
755 xhtml_header
756 if check_ressources; then
757 page_redirection upgrade
758 fi
759 ;;
760 *)
761 xhtml_header
762 if check_ressources; then
763 page_redirection home
764 fi
765 ;;
766 esac
768 xhtml_footer
770 exit 0