slitaz-tools view installer/slitaz-installer @ rev 416

tazx: fix /etc/X11/xorg.conf keyboard patches
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Dec 28 15:38:59 2009 +0100 (2009-12-28)
parents 9111553d3e51
children 68ee70163abc
line source
1 #!/bin/sh
2 # slitaz-installer - SliTaz GNU/Linux installer.
3 #
4 # So this is SliTaz installer using dialog boxes. All the comments are in
5 # English but displayed messages are in French. The script starts with a
6 # few main variables, then all the functions and then a sequence of functions.
7 #
8 # (C) 2007-2009 SliTaz - GNU General Public License v3.
9 #
10 # Author : Christophe Lincoln <pankso@slitaz.org>
11 #
12 VERSION=2.0
14 : ${DIALOG=dialog}
16 # We need to know cdrom device and kernel version string to copy files.
17 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
18 CDROM=/dev/$DRIVE_NAME
19 KERNEL=vmlinuz-`uname -r`
20 TARGET_ROOT=/mnt/target
21 LOG=/var/log/slitaz-installer.log
22 BACKLIST="SliTaz GNU/Linux installer"
23 ACTION=$1
25 #######################
26 # Installer functions #
27 #######################
29 # Messages language setting.
30 set_messages()
31 {
32 case $LANG in
33 de*)
34 . /usr/share/slitaz/messages/de/installer.msg ;;
35 fr*)
36 . /usr/share/slitaz/messages/fr/installer.msg ;;
37 hu*)
38 . /usr/share/slitaz/messages/hu/installer.msg ;;
39 pt*)
40 . /usr/share/slitaz/messages/pt/installer.msg ;;
41 *)
42 . /usr/share/slitaz/messages/en/installer.msg ;;
43 esac
44 }
46 # Display error message.
47 error_message()
48 {
49 $DIALOG --title " Error " \
50 --colors --backtitle "$BACKLIST" \
51 --clear --msgbox "\n$ERROR_MSG" 18 70
52 }
54 # Exit install if user is not root.
55 check_root()
56 {
57 if test $(id -u) != 0 ; then
58 ERROR_MSG="\
59 [\Z6en\Zn] You must be root administrator to start SliTaz installer, please \
60 use 'su' to get a root SHell and restart installation.\n\n
61 [\Z6fr\Zn] Vous devez être root pour installer SLiTaz GNU/Linux. Vous pouvez \
62 utiliser 'su' suivi du mot de passe administrateur pour devenir root \
63 et relancer l'installation."
64 error_message
65 exit 0
66 fi
67 }
69 # This function is used after each screen to contine or abort install.
70 check_retval()
71 {
72 case $retval in
73 0)
74 continue ;;
75 1)
76 echo -e "\nVoluntary exit.\n" && exit 0 ;;
77 3)
78 continue ;;
79 255)
80 echo -e "ESC pressed.\n" && exit 0 ;;
81 esac
82 }
84 # Start install with basic information.
85 start_installer()
86 {
87 $DIALOG --title " Install or Upgrade " \
88 --backtitle "$BACKLIST" \
89 --extra-button --extra-label "Upgrade" \
90 --ok-label "Install" \
91 --clear --colors --yesno "$START_INSTALL_MSG" 18 70
92 retval=$?
93 case $retval in
94 0)
95 ACTION=install ;;
96 1)
97 echo -e "\nVoluntary exit.\n" && exit 0 ;;
98 3)
99 ACTION=upgrade ;;
100 255)
101 echo -e "ESC pressed.\n" && exit 0 ;;
102 esac
103 echo "start_installer: `date`" > $LOG
104 }
106 # Mount cdrom and verify if it's really SliTaz CD.
107 mount_cdrom()
108 {
109 ERROR_MSG=""
110 (
111 echo "XXX" && echo 30
112 echo -e "\nCreating mount point (/media/cdrom)..."
113 echo "XXX"
114 mkdir -p /media/cdrom
115 sleep 1
116 echo "XXX" && echo 60
117 echo -e "\nMounting cdrom ($CDROM)..."
118 echo "XXX"
119 mount -t iso9660 $CDROM /media/cdrom 2>>$LOG
120 echo "XXX" && echo 90
121 echo -e "\nChecking installation media..."
122 echo "XXX"
123 sleep 2
124 ) |
125 $DIALOG --title " Mounting cdrom " \
126 --backtitle "$BACKLIST" \
127 --gauge "Preparing the installation media..." 18 70 0
128 # Exit with error msg if no rootfs.gz found.
129 if [ ! -f /media/cdrom/boot/rootfs.gz ]; then
130 ERROR_MSG="$MOUNT_CDROM_ERROR_MSG"
131 error_message
132 echo "missing: /media/cdrom/boot/rootfs.gz" >>$LOG
133 exit 1
134 fi
135 }
137 # Display a list of available partitions.
138 fdisk_list()
139 {
140 LIST_PARTITIONS=`fdisk -l | grep ^/dev | sed s/'e Win95'/'e'/g`
141 $DIALOG --title " Partition tables " \
142 --backtitle "$BACKLIST" \
143 --clear --msgbox "\n
144 Available partitions :\n\n
145 $LIST_PARTITIONS" 18 70
146 }
148 # We need a partition to install to (inputbox).
149 ask_for_target_dev()
150 {
151 exec 3>&1
152 TARGET_DEV=`$DIALOG --title " Root Partition " \
153 --backtitle "$BACKLIST" --clear \
154 --extra-label "List" --extra-button \
155 --colors --inputbox "$ASK_FOR_TARGET_DEV_MSG" 18 70 2>&1 1>&3`
156 retval=$?
157 exec 3>&-
158 check_retval
159 # Display list and come back.
160 if [ "$retval" = "3" ]; then
161 fdisk_list
162 ask_for_target_dev
163 fi
164 # Empty value.
165 if [ -z $TARGET_DEV ]; then
166 ask_for_target_dev
167 fi
168 set_messages
169 # Check if specified device exists in /proc/partitions.
170 DEV_NAME=${TARGET_DEV#/dev/}
171 if cat /proc/partitions | grep -q $DEV_NAME; then
172 if [ "$DEV_NAME" = "$TARGET_DEV" ]; then
173 TARGET_DEV="/dev/$DEV_NAME"
174 fi
175 echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
176 else
177 ERROR_MSG="Partition \Z2$TARGET_DEV\Zn doesn't exist."
178 error_message
179 ask_for_target_dev
180 fi
181 }
183 # Mkfs if needed/wanted on /.
184 ask_for_mkfs_target_dev()
185 {
186 $DIALOG --title " Format " \
187 --backtitle "$BACKLIST" \
188 --clear --colors --yesno "$ASK_FOR_MKFS_TARGET_DEV_MSG" 18 70
189 retval=$?
190 case $retval in
191 0)
192 MKFS_TARGET_DEV="ext3"
193 echo "mkfs_target_dev: ext3" >>$LOG ;;
194 1)
195 CLEAN="clean"
196 echo "mkfs_target_dev: clean" >>$LOG ;;
197 255)
198 echo -e "ESC pressed.\n" && exit 0 ;;
199 esac
201 }
203 # We can have a separate partition for /home.
204 ask_for_home()
205 {
206 exec 3>&1
207 HOME_DEV=`$DIALOG --title " Root Partition " \
208 --backtitle "$BACKLIST" --clear \
209 --extra-label "List" --extra-button \
210 --colors --inputbox "
211 On most GNU/Linux system users personnal files are stored in the directoty \
212 /home. Home can be on a separate partition or another hard disk.
214 \Z2Home partition to use (Option):\Zn" 18 70 2>&1 1>&3`
215 retval=$?
216 exec 3>&-
217 check_retval
218 # Display list and come back.
219 if [ "$retval" = "3" ]; then
220 fdisk_list
221 ask_for_home
222 fi
223 if [ -n "$HOME_DEV" ]; then
224 # Check if specified device exists in /proc/partitions.
225 DEV_NAME=${HOME_DEV#/dev/}
226 if cat /proc/partitions | grep -q $DEV_NAME; then
227 if [ "$DEV_NAME" = "$HOME_DEV" ]; then
228 HOME_DEV="/dev/$DEV_NAME"
229 fi
230 echo "ask_for_home: $HOME_DEV" >>$LOG
231 else
232 ERROR_MSG="Partition \Z2$HOME_DEV\Zn doesn't exist."
233 error_message
234 ask_for_home
235 fi
236 fi
237 }
239 # Mkfs if needed/wanted on /.
240 ask_for_mkfs_home()
241 {
242 $DIALOG --title " Format " \
243 --backtitle "$BACKLIST" \
244 --clear --colors --yesno "
245 Here you can format the /home partition: $HOME_DEV
247 SliTaz use ext3 by default but another filesystem can be used if wanted, \
248 for this please adjust /etc/fstab afer installation.
250 \Z2Do you want to format (Option): $HOME_DEV\Zn" 18 70
251 retval=$?
252 case $retval in
253 0)
254 MKFS_HOME="ext3"
255 echo "mkfs_home: ext3" >>$LOG ;;
256 1)
257 MKFS_HOME=""
258 echo "mkfs_home: no" >>$LOG ;;
259 255)
260 echo -e "ESC pressed.\n" && exit 0 ;;
261 esac
263 }
265 # Ask for hostname before installing files.
266 ask_for_hostname()
267 {
268 exec 3>&1
269 HOSTNAME=`$DIALOG --title " Hostname " \
270 --backtitle "$BACKLIST" --clear \
271 --colors --inputbox "$ASK_FOR_HOSTNAME_MSG" 18 70 "slitaz" 2>&1 1>&3`
272 retval=$?
273 exec 3>&-
274 check_retval
275 # Empty value.
276 if [ -z $HOSTNAME ]; then
277 HOSTNAME="slitaz"
278 fi
279 }
281 # Ask for root password and default user settings.
282 ask_for_users_settings()
283 {
284 # Root passwd
285 exec 3>&1
286 ROOT_PASSWD=`$DIALOG --title " Root password " \
287 --backtitle "$BACKLIST" --clear \
288 --colors --nocancel --inputbox "
289 The root administrator privilege lets you manage and configure the full \
290 system. A root user can damage your system so you should always setup a \
291 strong password with special characters and/or numbers.
293 \Z2Please specify the Root password for your new system:\Zn" 18 70 "root" 2>&1 1>&3`
294 retval=$?
295 exec 3>&-
296 check_retval
297 # Prevent empty value.
298 if [ -z $ROOT_PASSWD ]; then
299 ROOT_PASSWD="root"
300 fi
301 # Default user
302 exec 3>&1
303 USER=`$DIALOG --title " User name " \
304 --backtitle "$BACKLIST" --clear \
305 --colors --nocancel --inputbox "
306 The default user for the system will have his personal files stored \
307 in /home/*user* (and will automatically be added to the audio group).
309 \Z2Default user name login:\Zn" 18 70 "tux" 2>&1 1>&3`
310 retval=$?
311 exec 3>&-
312 check_retval
313 # Prevent empty value.
314 if [ -z $USER ]; then
315 USER="tux"
316 fi
317 # User passwd
318 exec 3>&1
319 USER_PASSWD=`$DIALOG --title " User password " \
320 --backtitle "$BACKLIST" --clear \
321 --colors --nocancel --inputbox "
322 The password for default user $USER. It may also be a security risk if too \
323 weak and should always be strong if you use a SSH connection through the web.
325 \Z2Please specify $USER password:\Zn" 18 70 "tux" 2>&1 1>&3`
326 retval=$?
327 exec 3>&-
328 check_retval
329 # Prevent empty value.
330 if [ -z $USER_PASSWD ]; then
331 USER_PASSWD="tux"
332 fi
333 }
335 # Tiny summary and last chance to cancel or restart for user.
336 summary()
337 {
338 $DIALOG --title " Summary " \
339 --backtitle "$BACKLIST" \
340 --clear --colors --yesno "
341 Installation settings summary and last chance to cancel or restart all \
342 installator steps.
344 Root partition: $TARGET_DEV
345 Home partition: $HOME_DEV
346 Hostname: $HOSTNAME
347 Default user: $USER
349 \Z2Go and install SliTaz or cancel?\Zn" 18 70
350 retval=$?
351 check_retval
352 }
354 # Mount and mkfs with progress.
355 prepare_partitions()
356 {
357 (
358 echo "XXX" && echo 30
359 echo -e "\nPreparing target partition..."
360 echo "XXX"
361 # Mount point can be already used.
362 if mount | grep -q $TARGET_ROOT; then
363 umount $TARGET_ROOT 2>$LOG
364 fi
365 sleep 2
367 if [ "$MKFS_TARGET_DEV" == "ext3" ]; then
368 echo "XXX" && echo 50
369 echo -e "\nExecuting mkfs.ext3 on $TARGET_DEV"
370 echo "XXX"
371 mkfs.ext3 $TARGET_DEV >>$LOG 2>>$LOG
372 else
373 echo "XXX" && echo 50
374 echo -e "\nThe partition ($TARGET_DEV) will be cleaned..."
375 echo "XXX"
376 sleep 2
377 fi
379 if [ "$MKFS_HOME" == "ext3" ]; then
380 echo "XXX" && echo 70
381 echo -e "\nExecuting mkfs.ext3 on $HOME_DEV"
382 echo "XXX"
383 mkfs.ext3 -L "Home" $HOME_DEV >>$LOG 2>>$LOG
384 else
385 echo "XXX" && echo 70
386 echo -e "\nThe partition ($HOME_DEV) will be keeped..."
387 echo "XXX"
388 sleep 2
389 fi
391 echo "XXX" && echo 90
392 echo -e "\nCreating mount point: $TARGET_ROOT"
393 echo "XXX"
394 mkdir -p $TARGET_ROOT
395 sleep 2
397 ) |
398 $DIALOG --title " Prepare the target " \
399 --backtitle "$BACKLIST" \
400 --gauge "Target in preparation..." 18 70 0
401 # Mount target.
402 mount $TARGET_DEV $TARGET_ROOT >>$LOG 2>>$LOG
403 }
405 # Get a clean target device (15%).
406 clean_target()
407 {
408 if [ "$CLEAN" == "clean" ]; then
409 echo "XXX" && echo 15
410 echo -e "\nCleaning the root partition ($TARGET_DEV)..."
411 echo "XXX"
412 # Keep /home in case of reinstall.
413 cd $TARGET_ROOT
414 for dir in *
415 do
416 case "$dir" in
417 home)
418 mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
419 echo "keeping /home found on: $TARGET_DEV" >>$LOG ;;
420 lost+found)
421 continue ;;
422 *)
423 echo "removing target: $dir" >>$LOG
424 rm -rf $dir 2>>$LOG ;;
425 esac
426 done
427 if [ -d $TARGET_ROOT/mklost+found ]; then
428 mklost+found 2>>$LOG
429 fi
430 fi
431 sleep 2
432 }
434 # Kernel is renamed to standard vmlinuz-$VERSION.
435 install_kernel()
436 {
437 mkdir -p $TARGET_ROOT/boot
438 cp /media/cdrom/boot/bzImage $TARGET_ROOT/boot/$KERNEL
439 echo "install_kernel: $KERNEL" >> $LOG
440 sleep 2
441 }
443 # Copy isolinux r/w files (not syslinux, some files are read only).
444 copy_bootloaders()
445 {
446 if [ -d "/media/cdrom/boot/isolinux" ]; then
447 mkdir -p $TARGET_ROOT/boot/isolinux
448 cp -a /media/cdrom/boot/isolinux/*.cfg $TARGET_ROOT/boot/isolinux
449 cp -a /media/cdrom/boot/isolinux/*.kbd $TARGET_ROOT/boot/isolinux
450 cp -a /media/cdrom/boot/isolinux/*.txt $TARGET_ROOT/boot/isolinux
451 cp -a /media/cdrom/boot/isolinux/*.bin $TARGET_ROOT/boot/isolinux
452 cp -a /media/cdrom/boot/isolinux/*.msg $TARGET_ROOT/boot/isolinux
453 cp -a /media/cdrom/boot/isolinux/*.lss $TARGET_ROOT/boot/isolinux
454 cp -a /media/cdrom/boot/isolinux/*.c32 $TARGET_ROOT/boot/isolinux
455 fi
456 }
458 # Extract lzma'ed or gziped rootfs.
459 extract_rootfs()
460 {
461 cd $TARGET_ROOT
462 (zcat rootfs.gz 2>/dev/null || lzma d rootfs.gz -so || \
463 cat rootfs.gz) 2>>$LOG | cpio -id 2>>$LOG > /dev/null
464 rm -f rootfs.gz
465 # unpack /usr (double check...)
466 if ls etc/tazlito | grep -q ".extract"; then
467 for i in etc/tazlito/*.extract; do
468 [ -f "$i" ] && . $i /media/cdrom
469 done
470 fi
471 }
473 # Pre configure freshly installed system (60 - 80%).
474 pre_config_system()
475 {
476 cd $TARGET_ROOT
477 # Restore backup of existing /home if exists.
478 # (created by prepare_target_dev)
479 if [ -d home.bak ]; then
480 echo "XXX" && echo 65
481 echo -e "\nRestoring directory: /home..."
482 echo "XXX"
483 rm -rf home
484 mv home.bak home
485 sleep 1
486 fi
487 # Add root device to CHECK_FS in rcS.conf to check filesystem
488 # on each boot.
489 echo "XXX" && echo 70
490 echo -e "\nAdding $TARGET_DEV and CHECK_FS to file /etc/rcS.conf..."
491 echo "XXX"
492 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TARGET_DEV\""# etc/rcS.conf
493 sleep 2
494 # Set hostname.
495 echo "XXX" && echo 80
496 echo -e "\nConfiguring host name: $HOSTNAME"
497 echo "XXX"
498 echo $HOSTNAME > etc/hostname
499 }
501 # Set root passwd and create user after rootfs extraction.
502 users_settings()
503 {
504 cat > $TARGET_ROOT/users.sh << _EOF_
505 #!/bin/sh
506 echo "root:$ROOT_PASSWD" | chpasswd
507 adduser -D -H $USER
508 addgroup $USER audio
509 echo "$USER:$USER_PASSWD" | chpasswd
510 if [ ! -d /home/$USER ]; then
511 cp -a /etc/skel /home/$USER
512 chown -R $USER.$USER /home/$USER
513 # Path for user desktop files.
514 for i in /home/$USER/.local/share/applications/*.desktop
515 do
516 sed -i s/"user_name"/"$USER"/g \$i
517 done
518 fi
519 # Slim default user.
520 if [ -f /etc/slim.conf ]; then
521 sed -i s/"default_user .*"/"default_user $USER"/ \
522 /etc/slim.conf
523 fi
524 _EOF_
525 chmod +x $TARGET_ROOT/users.sh
526 chroot $TARGET_ROOT ./users.sh
527 rm $TARGET_ROOT/users.sh
528 }
530 # /home can be on a separate partition. If default user exist in /home
531 # we remove default file crated by users_settings().
532 home_config()
533 {
534 echo "home_config: $HOME_DEV" >> $LOG
535 cd $TARGET_ROOT
536 mv home/$USER tmp
537 mount $HOME_DEV home
538 if [ -d $TARGET_ROOT/home/$USER ]; then
539 rm -rf tmp/$USER
540 else
541 mv tmp/$USER home
542 fi
543 echo "$HOME_DEV /home ext3 defaults 0 2" \
544 >> etc/fstab
545 umount home
546 }
548 # Determine GRUB partition number and GRUB disk number.
549 grub_config()
550 {
551 DISK_LETTER=${TARGET_DEV#/dev/[h-s]d}
552 DISK_LETTER=${DISK_LETTER%[0-9]}
553 GRUB_PARTITION=$((${TARGET_DEV#/dev/[h-s]d[a-z]}-1))
554 for disk in a b c d e f g h
555 do
556 nb=$(($nb+1))
557 if [ "$disk" = "$DISK_LETTER" ]; then
558 GRUB_DISK=$(($nb-1))
559 break
560 fi
561 done
562 GRUB_ROOT="(hd${GRUB_DISK},${GRUB_PARTITION})"
563 # Create the target GRUB configuration.
564 mkdir -p $TARGET_ROOT/boot/grub
565 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
566 # /boot/grub/menu.lst: GRUB boot loader configuration.
567 #
569 # By default, boot the first entry.
570 default 0
572 # Boot automatically after 8 secs.
573 timeout 8
575 # Change the colors.
576 color yellow/brown light-green/black
578 # For booting SliTaz from : $TARGET_DEV
579 #
580 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
581 root $GRUB_ROOT
582 kernel /boot/$KERNEL root=$TARGET_DEV
584 _EOF_
585 # log
586 echo "grub_config: $TARGET_ROOT/boot/grub/menu.lst" >>$LOG
587 sleep 2
588 }
590 # Files install with gauge, calling for functions or with cmds.
591 install_files()
592 {
593 (
595 echo "XXX" && echo 10
596 echo -e "\nCleaning the root partition if necessary..."
597 echo "XXX"
598 clean_target
600 echo "XXX" && echo 20
601 echo -e "\nInstalling the kernel ($KERNEL)..."
602 echo "XXX"
603 install_kernel
605 echo "XXX" && echo 30
606 echo -e "\nCopying the bootloader syslinux/isolinux..."
607 echo "XXX"
608 copy_bootloaders
610 echo "XXX" && echo 40
611 echo -e "\nCopying the compressed system (rootfs.gz)..."
612 echo "XXX"
613 cp /media/cdrom/boot/rootfs.gz $TARGET_ROOT
614 sleep 2
616 echo "XXX" && echo 50
617 echo -e "\nExtracting the root system..."
618 echo "XXX"
619 extract_rootfs
621 echo "XXX" && echo 60
622 echo -e "\nPreconfiguring the system..."
623 echo "XXX"
624 pre_config_system
626 echo "XXX" && echo 70
627 echo -e "\nConfiguring root and default $USER account..."
628 echo "XXX"
629 users_settings
630 sleep 2
632 if [ "$HOME_DEV" != "" ]; then
633 echo "XXX" && echo 80
634 echo -e "\nConfiguring $HOME_DEV to be used as /home..."
635 echo "XXX"
636 home_config
637 sleep 2
638 fi
640 echo "XXX" && echo 90
641 echo -e "\nCreating the configuration file for GRUB (menu.lst)..."
642 echo "XXX"
643 grub_config
645 echo "XXX" && echo 100
646 echo -e "\nFinishing the files installation..."
647 echo "XXX"
648 echo "install_files: OK" >>$LOG
649 sleep 2
651 ) |
652 $DIALOG --title " Install files " \
653 --backtitle "$BACKLIST" \
654 --gauge "Starting to install files..." 18 70 0
655 }
657 # GRUB info with disk name used for grub-install.
658 grub_install()
659 {
660 TARGET_DISK=`echo $TARGET_DEV | sed s/"[0-9]"/''/`
661 set_messages
662 $DIALOG --title " GRUB install " \
663 --backtitle "$BACKLIST" \
664 --clear --colors --yesno "$GRUB_INSTALL_MSG" 18 70
665 retval=$?
666 case $retval in
667 0)
668 (
669 echo "XXX" && echo 50
670 echo -e "\nRunning grub-install on : $TARGET_DISK..."
671 echo "XXX"
672 grub-install --no-floppy \
673 --root-directory=$TARGET_ROOT $TARGET_DISK 2>>$LOG
674 echo "XXX" && echo 100
675 echo -e "\nFinished installation..."
676 echo "XXX"
677 sleep 2
678 ) |
679 $DIALOG --title " GRUB install " \
680 --backtitle "$BACKLIST" \
681 --gauge "Installating GRUB..." 18 70 0 ;;
682 1)
683 echo "grub_install: NO" >>$LOG ;;
684 255)
685 echo -e "ESC pressed.\n" && exit 0 ;;
686 esac
687 }
689 # Copy log file, umount target and eject cdrom.
690 umount_devices()
691 {
692 (
693 echo "XXX" && echo 25
694 echo -e "\nCopying the log files ($LOG)..."
695 echo "XXX"
696 cp -a $LOG $TARGET_ROOT/var/log
697 sleep 2
698 echo "XXX" && echo 50
699 echo -e "\nUnmounting the target ($TARGET_DEV)..."
700 echo "XXX"
701 if mount | grep -q $TARGET_ROOT; then
702 umount $TARGET_ROOT 2>/dev/null
703 fi
704 echo "XXX" && echo 75
705 echo -e "\nUnmounting and ejecting the cdrom..."
706 echo "XXX"
707 if mount | grep -q /media/cdrom; then
708 umount /media/cdrom
709 grep -q slitaz-loram-cdrom /etc/init.d/rcS || eject
710 fi
711 sleep 2
712 echo "XXX" && echo 100
713 echo -e "\n$TITLE..."
714 echo "XXX"
715 sleep 2
716 ) |
717 $DIALOG --title " $TITLE " \
718 --backtitle "$BACKLIST" \
719 --gauge "$TITLE starting..." 18 70 0
720 }
722 # End of installation.
723 end_of_install()
724 {
725 echo "end_of_install: `date`" >>$LOG
726 $DIALOG --title " Installation complete " \
727 --backtitle "$BACKLIST" \
728 --yes-label "Exit" \
729 --no-label "Reboot" \
730 --clear --colors --yesno "$END_OF_INSTALL_MSG" 18 70
731 retval=$?
732 case $retval in
733 0)
734 TITLE="Exiting"
735 umount_devices ;;
736 1)
737 TITLE="Rebooting"
738 umount_devices
739 reboot || reboot -f ;;
740 255)
741 echo -e "ESC pressed.\n" && exit 0 ;;
742 esac
743 }
745 #####################
746 # Upgrade functions #
747 #####################
749 # We need a partition to upgrade SliTaz.
750 ask_for_upgrade_dev()
751 {
752 exec 3>&1
753 UPGRADE_DEV=`$DIALOG --title " Target to upgrade " \
754 --backtitle "$BACKLIST" --clear \
755 --extra-label "List" --extra-button \
756 --colors --inputbox "\n
757 The installer will upgrade the target by saving all configuration files and \
758 the list of installed packages. Then, it will clean the partition and install the \
759 version of SliTaz contained on the cdrom, restore the configuration files and \
760 reinstall any packages which are not present on the cdrom. You will need an active \
761 internet connection before upgrading.\n\n
762 \Z2Partition containing the system upgrade:\Zn" 18 70 2>&1 1>&3`
763 retval=$?
764 exec 3>&-
765 check_retval
766 # Display list and come back.
767 if [ "$retval" = "3" ]; then
768 fdisk_list
769 ask_for_upgrade_dev
770 fi
771 # Empty value.
772 if [ -z $UPGRADE_DEV ]; then
773 ask_for_upgrade_dev
774 fi
775 # Check if specified device exists in /proc/partitions.
776 DEV_NAME=${UPGRADE_DEV#/dev/}
777 if cat /proc/partitions | grep -q $DEV_NAME; then
778 echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
779 else
780 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't seem to exist."
781 error_message
782 ask_for_upgrade_dev
783 fi
784 echo "partition to upgrade: $UPGRADE_DEV" >>$LOG
785 }
787 # Prepare the partition to upgrade, backup, install, restore configs
788 # and reinstall pkgs.
789 upgrade_process()
790 {
791 (
792 echo "XXX" && echo 5
793 echo -e "\nPreparing the target partition..."
794 echo "XXX"
795 # Mount point can be already used.
796 if mount | grep -q $TARGET_ROOT; then
797 umount $TARGET_ROOT 2>$LOG
798 fi
799 mkdir -p $TARGET_ROOT && sleep 2
800 # Mount target.
801 mount $UPGRADE_DEV $TARGET_ROOT >>$LOG 2>>$LOG
802 cd $TARGET_ROOT
803 TARGET_DEV=$UPGRADE_DEV
804 set_messages
806 echo "XXX" && echo 10
807 echo -e "\nSearch for /etc/slitaz-release"
808 echo "XXX"
809 if [ -f etc/slitaz-release ]; then
810 release=`cat etc/slitaz-release`
811 echo "XXX" && echo 15
812 echo -e "\nSliTaz release: $release"
813 echo "XXX"
814 else
815 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't appear to contain \
816 a SliTaz system, the file: /etc/slitaz-release doesn't exist."
817 error_message
818 exit 0
819 fi && sleep 2
821 echo "XXX" && echo 20
822 echo -e "\nBackup /etc, /home and the packages list..."
823 echo "XXX"
824 # Backup target packages list.
825 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
826 for dir in *
827 do
828 case "$dir" in
829 boot)
830 # Upgrade doesn't prompt for grub install, so backup and
831 # create a new grub menu.lst.
832 rm -rf $TARGET_ROOT/boot/vmlinuz-*
833 mv $TARGET_ROOT/boot/grub/menu.lst \
834 $TARGET_ROOT/boot/grub/menu.lst.bak 2>/dev/null
835 grub_config ;;
836 home)
837 mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
838 echo "keeping /home found on: $UPGRADE_DEV" >>$LOG ;;
839 etc)
840 tar czf $TARGET_ROOT/etc.tar.gz etc
841 mv $TARGET_ROOT/etc $TARGET_ROOT/etc.bak
842 echo "keeping /etc found on: $UPGRADE_DEV" >>$LOG ;;
843 var)
844 if [ -d $TARGET_ROOT/var/www ]; then
845 mv $TARGET_ROOT/var/www $TARGET_ROOT/www.bak
846 fi
847 rm -rf $TARGET_ROOT/var ;;
848 lost+found)
849 continue ;;
850 *)
851 echo "removing target: $dir" >>$LOG
852 rm -rf $TARGET_ROOT/$dir 2>>$LOG ;;
853 esac
854 done
855 if [ -d $TARGET_ROOT/mklost+found ]; then
856 mklost+found 2>>$LOG
857 fi
858 sleep 2
860 echo "XXX" && echo 25
861 echo -e "\nInstalling the kernel ($KERNEL)..."
862 echo "XXX"
863 install_kernel
865 echo "XXX" && echo 30
866 echo -e "\nCopying the bootloader syslinux/isolinux..."
867 echo "XXX"
868 copy_bootloaders
870 echo "XXX" && echo 35
871 echo -e "\nCopying the compressed system (rootfs.gz)..."
872 echo "XXX"
873 cp /media/cdrom/boot/rootfs.gz $TARGET_ROOT
874 sleep 2
876 echo "XXX" && echo 40
877 echo -e "\nExtracting the root system..."
878 echo "XXX"
879 extract_rootfs
881 # Restore backups.
882 echo "XXX" && echo 42
883 echo -e "\nRestoring configuration files..."
884 echo "XXX"
885 rm -rf $TARGET_ROOT/home
886 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
887 rm -rf $TARGET_ROOT/etc
888 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
889 if [ -d $TARGET_ROOT/www.bak ]; then
890 rm -rf $TARGET_ROOT/var/www
891 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
892 fi
893 echo "backups restored: `date`" >> $LOG
895 # /var/lib/slitaz-installer
896 mkdir $TARGET_ROOT/var/lib/slitaz-installer
897 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/slitaz-installer
898 mv $TARGET_ROOT/home/packages-selection.list $TARGET_ROOT/var/lib/slitaz-installer
899 cd $TARGET_ROOT/var/lib/slitaz-installer
901 # LiveCD packages list.
902 echo "XXX" && echo 46
903 echo -e "\nCreating package lists..."
904 echo "XXX"
905 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-cdrom.list || exit 1
906 echo "packages-cdrom.list: done" >> $LOG
907 # Diff
908 diff packages-cdrom.list packages-selection.list | \
909 grep ^+[a-z] | sed s/^+// > packages-selection.diff
910 echo "packages-selection.diff: done" >> $LOG
911 # Get mirror list.
912 tazpkg recharge >>$LOG 2>>$LOG
913 if [ ! -f /var/lib/tazpkg/packages.list ]; then
914 ERROR_MSG="The list of available packages on the mirror could not be \
915 downloaded. No missing packages will be reinstalled now, but \
916 you can do so later by looking at the following list: \n\n
918 /var/lib/slitaz-installer/packages-selection.diff"
919 error_message
920 fi
921 sleep 2
923 # Check if the pkg is on the mirror.
924 echo "XXX" && echo 48
925 echo -e "\nChecking the availability of packages..."
926 echo "XXX"
927 touch packages-to-install.list
928 packages=0
929 diff=`cat packages-selection.diff | sort`
930 for pkg in $diff
931 do
932 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
933 packages=$(($packages+1))
934 echo "$pkg" >> packages-to-install.list
935 fi
936 done
938 # Calculate the percent for one package and install.
939 echo "XXX" && echo 50
940 echo -e "\nInstalling any packages..."
941 echo "XXX"
942 sleep 2
943 if [ "$packages" == "0" ]; then
944 echo "packages to install: 0" >> $LOG
945 else
946 onepkg=$((48/$packages))
947 pct=50
948 # Get-install all missing pkgs.
949 for pkg in `cat packages-to-install.list`
950 do
951 pct=$(($pct+$onepkg))
952 echo "XXX" && echo $pct
953 echo -e "\nInstallation of: $pkg..."
954 echo "XXX"
955 # Log please.
956 echo "get-install: $pkg" >>$LOG
957 # Get install package and answer yes in case of dependencies.
958 pkgname=`grep ^$pkg /var/lib/tazpkg/packages.list`
959 tazpkg get $pkg >/dev/null 2>/dev/null
960 yes "" | tazpkg install $pkgname.tazpkg --root=$TARGET_ROOT >/dev/null 2>/dev/null
961 rm -f $pkgname.tazpkg
962 done
963 fi
964 echo "XXX" && echo 100
965 echo -e "\nInstallation of packages complete..."
966 echo "XXX"
967 sleep 2
968 ) |
969 $DIALOG --title " Processing system upgrade " \
970 --backtitle "$BACKLIST" \
971 --gauge "Target in preparation..." 18 70 0
972 }
974 # End of system upgrade.
975 end_of_upgrade()
976 {
977 TARGET_DEV=$UPGRADE_DEV
978 set_messages
979 pkgscd=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-cdrom.list | wc -l`
980 pkginst=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-to-install.list | wc -l`
981 echo "end_of_upgrade: `date`" >>$LOG
982 $DIALOG --title " Upgrade completed " \
983 --backtitle "$BACKLIST" \
984 --yes-label "Exit" \
985 --no-label "Reboot" \
986 --clear --colors --yesno "\n
987 Upgrade finished. You can now restart (reboot) \
988 from your SliTaz GNU/Linux system.\n\n
989 Packages on the cdrom : $pkgscd\n
990 Packages installed from the mirror : $pkginst\n" 18 70
991 retval=$?
992 case $retval in
993 0)
994 TITLE="Exiting"
995 umount_devices ;;
996 1)
997 TITLE="Rebooting"
998 umount_devices
999 reboot || reboot -f ;;
1000 255)
1001 echo -e "ESC pressed.\n" && exit 0 ;;
1002 esac
1005 ######################
1006 # Installer sequence #
1007 ######################
1009 set_messages
1010 check_root
1011 start_installer
1013 case $ACTION in
1014 upgrade)
1015 BACKLIST="$BACKLIST (Upgrade)"
1016 mount_cdrom
1017 ask_for_upgrade_dev
1018 upgrade_process
1019 end_of_upgrade ;;
1020 install|*)
1021 mount_cdrom
1022 ask_for_target_dev
1023 ask_for_mkfs_target_dev
1024 ask_for_home
1025 if [ -n "$HOME_DEV" ]; then
1026 ask_for_mkfs_home
1027 fi
1028 ask_for_hostname
1029 ask_for_users_settings
1030 summary
1031 prepare_partitions
1032 install_files
1033 grub_install
1034 end_of_install ;;
1035 esac
1037 exit 0