slitaz-tools view installer/slitaz-installer @ rev 393
Added tag 3.3 for changeset b27d8925b831
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Oct 01 21:57:15 2009 +0200 (2009-10-01) |
parents | cf43c3752733 |
children | 14683938d8d4 |
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-2008 SliTaz - GNU General Public License v3.
9 #
10 # Author : Christophe Lincoln <pankso@slitaz.org>
11 #
12 VERSION=1.0
14 if [ "$1" = "gui" ]; then
15 : ${DIALOG=tazdialog}
16 else
17 : ${DIALOG=dialog}
18 fi
20 # Installer actions can be specified on cmdline (install or upgrade).
21 if [ "$1" = "upgrade" ]; then
22 ACTION=$1
23 else
24 ACTION=install
25 fi
27 # We need to know cdrom device and kernel version string to copy files.
28 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
29 CDROM=/dev/$DRIVE_NAME
30 KERNEL=vmlinuz-`uname -r`
31 TARGET_ROOT=/mnt/target
32 LOG=/var/log/slitaz-installer.log
33 BACKLIST="SliTaz GNU/Linux installer"
35 #######################
36 # Installer functions #
37 #######################
39 # Messages language setting.
40 set_messages()
41 {
42 case $LANG in
43 de*)
44 . /usr/share/slitaz/messages/de/installer.msg ;;
45 fr*)
46 . /usr/share/slitaz/messages/fr/installer.msg ;;
47 hu*)
48 . /usr/share/slitaz/messages/hu/installer.msg ;;
49 pt*)
50 . /usr/share/slitaz/messages/pt/installer.msg ;;
51 *)
52 . /usr/share/slitaz/messages/en/installer.msg ;;
53 esac
54 }
56 # Display error message.
57 error_message()
58 {
59 $DIALOG --title " Error " \
60 --colors --backtitle "$BACKLIST" \
61 --clear --msgbox "\n$ERROR_MSG" 18 70
62 }
64 # Exit install if user is not root.
65 check_root()
66 {
67 if test $(id -u) != 0 ; then
68 ERROR_MSG="\
69 [\Z6en\Zn] You must be root administrator to start SliTaz installer, please \
70 use 'su' to get a root SHell and restart installation.\n\n
71 [\Z6fr\Zn] Vous devez être root pour installer SLiTaz GNU/Linux. Vous pouvez \
72 utiliser 'su' suivi du mot de passe administrateur pour devenir root \
73 et relancer l'installation."
74 error_message
75 exit 0
76 fi
77 }
79 # This function is used after each screen to contine or abort install.
80 check_retval()
81 {
82 case $retval in
83 0)
84 continue ;;
85 1)
86 echo -e "\nVoluntary exit.\n" && exit 0 ;;
87 3)
88 continue ;;
89 255)
90 echo -e "ESC pressed.\n" && exit 0 ;;
91 esac
92 }
94 # Start install with basic information.
95 start_installer()
96 {
97 $DIALOG --title " Install or Upgrade " \
98 --backtitle "$BACKLIST" \
99 --extra-button --extra-label "Upgrade" \
100 --yes-label "Install" \
101 --no-label "Quit" \
102 --clear --colors --yesno "$START_INSTALL_MSG" 18 70
103 retval=$?
104 case $retval in
105 0)
106 ACTION=install ;;
107 1)
108 echo -e "\nVoluntary exit.\n" && exit 0 ;;
109 3)
110 ACTION=upgrade ;;
111 255)
112 echo -e "ESC pressed.\n" && exit 0 ;;
113 esac
114 echo "start_installer: `date`" > $LOG
115 }
117 # Mount cdrom and verify if it's really SliTaz CD.
118 mount_cdrom()
119 {
120 ERROR_MSG=""
121 (
122 echo "XXX" && echo 30
123 echo -e "\nCreating mount point (/media/cdrom)..."
124 echo "XXX"
125 mkdir -p /media/cdrom
126 sleep 1
127 echo "XXX" && echo 60
128 echo -e "\nMounting cdrom ($CDROM)..."
129 echo "XXX"
130 mount -t iso9660 $CDROM /media/cdrom 2>>$LOG
131 echo "XXX" && echo 90
132 echo -e "\nChecking installation media..."
133 echo "XXX"
134 sleep 2
135 ) |
136 $DIALOG --title " Mounting cdrom " \
137 --backtitle "$BACKLIST" \
138 --gauge "Preparing the installation media..." 18 70 0
139 # Exit with error msg if no rootfs.gz found.
140 if [ ! -f /media/cdrom/boot/rootfs.gz ]; then
141 ERROR_MSG="$MOUNT_CDROM_ERROR_MSG"
142 error_message
143 echo "missing: /media/cdrom/boot/rootfs.gz" >>$LOG
144 exit 1
145 fi
146 }
148 # Display a list of available partitions.
149 fdisk_list()
150 {
151 LIST_PARTITIONS=`fdisk -l | grep ^/dev | sed s/'e Win95'/'e'/g`
152 $DIALOG --title " Partition tables " \
153 --backtitle "$BACKLIST" \
154 --clear --msgbox "\n
155 Available partitions :\n\n
156 $LIST_PARTITIONS" 18 70
157 }
159 # We need a partition to install to (inputbox).
160 ask_for_target_dev()
161 {
162 exec 3>&1
163 TARGET_DEV=`$DIALOG --title " Root Partition " \
164 --backtitle "$BACKLIST" --clear \
165 --extra-label "List" --extra-button \
166 --colors --inputbox "$ASK_FOR_TARGET_DEV_MSG" 18 70 2>&1 1>&3`
167 retval=$?
168 exec 3>&-
169 check_retval
170 # Display list and come back.
171 if [ "$retval" = "3" ]; then
172 fdisk_list
173 ask_for_target_dev
174 fi
175 # Empty value.
176 if [ -z $TARGET_DEV ]; then
177 ask_for_target_dev
178 fi
179 set_messages
180 # Check if specified device exists in /proc/partitions.
181 DEV_NAME=${TARGET_DEV#/dev/}
182 if cat /proc/partitions | grep -q $DEV_NAME; then
183 if [ "$DEV_NAME" = "$TARGET_DEV" ]; then
184 TARGET_DEV="/dev/$DEV_NAME"
185 fi
186 echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
187 else
188 ERROR_MSG="Partition \Z2$TARGET_DEV\Zn doesn't exist."
189 error_message
190 ask_for_target_dev
191 fi
192 }
194 # Mkfs if needed/wanted.
195 ask_for_mkfs_target_dev()
196 {
197 $DIALOG --title " Format " \
198 --backtitle "$BACKLIST" \
199 --clear --colors --yesno "$ASK_FOR_MKFS_TARGET_DEV_MSG" 18 70
200 retval=$?
201 case $retval in
202 0)
203 MKFS_TARGET_DEV="ext3"
204 echo "mkfs_target_dev: ext3" >>$LOG ;;
205 1)
206 CLEAN="clean"
207 echo "mkfs_target_dev: clean" >>$LOG ;;
208 255)
209 echo -e "ESC pressed.\n" && exit 0 ;;
210 esac
212 }
214 # Mount and mkfs with progress.
215 prepare_target_dev()
216 {
217 (
218 echo "XXX" && echo 30
219 echo -e "\nPreparing target partition..."
220 echo "XXX"
221 # Mount point can be already used.
222 if mount | grep -q $TARGET_ROOT; then
223 umount $TARGET_ROOT 2>$LOG
224 fi
225 sleep 2
227 if [ "$MKFS_TARGET_DEV" == "ext3" ]; then
228 echo "XXX" && echo 60
229 echo -e "\nExecuting mkfs.ext3 on $TARGET_DEV"
230 echo "XXX"
231 mkfs.ext3 $TARGET_DEV >>$LOG 2>>$LOG
232 else
233 echo "XXX" && echo 60
234 echo -e "\nThe partition ($TARGET_DEV) will be cleaned..."
235 echo "XXX"
236 sleep 2
237 fi
239 echo "XXX" && echo 90
240 echo -e "\nCreating mount point: $TARGET_ROOT"
241 echo "XXX"
242 mkdir -p $TARGET_ROOT
243 sleep 2
245 ) |
246 $DIALOG --title " Prepare the target " \
247 --backtitle "$BACKLIST" \
248 --gauge "Target in preparation..." 18 70 0
249 # Mount target.
250 mount $TARGET_DEV $TARGET_ROOT >>$LOG 2>>$LOG
251 }
253 # Ask for hostname before installing files.
254 ask_for_hostname()
255 {
256 exec 3>&1
257 HOSTNAME=`$DIALOG --title " Hostname " \
258 --backtitle "$BACKLIST" --clear \
259 --colors --inputbox "$ASK_FOR_HOSTNAME_MSG" 18 70 "slitaz" 2>&1 1>&3`
260 retval=$?
261 exec 3>&-
262 check_retval
263 # Empty value.
264 if [ -z $HOSTNAME ]; then
265 HOSTNAME="slitaz"
266 fi
267 }
269 # Get a clean target device (15%).
270 clean_target()
271 {
272 if [ "$CLEAN" == "clean" ]; then
273 echo "XXX" && echo 15
274 echo -e "\nCleaning the root partition ($TARGET_DEV)..."
275 echo "XXX"
276 # Keep /home in case of reinstall.
277 cd $TARGET_ROOT
278 for dir in *
279 do
280 case "$dir" in
281 home)
282 mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
283 echo "keeping /home found on: $TARGET_DEV" >>$LOG ;;
284 lost+found)
285 continue ;;
286 *)
287 echo "removing target: $dir" >>$LOG
288 rm -rf $dir 2>>$LOG ;;
289 esac
290 done
291 if [ -d $TARGET_ROOT/mklost+found ]; then
292 mklost+found 2>>$LOG
293 fi
294 fi
295 sleep 2
296 }
298 # Kernel is renamed to standard vmlinuz-$VERSION.
299 install_kernel()
300 {
301 mkdir -p $TARGET_ROOT/boot
302 cp /media/cdrom/boot/bzImage $TARGET_ROOT/boot/$KERNEL
303 echo "install_kernel: $KERNEL" >> $LOG
304 sleep 2
305 }
307 # Copy isolinux r/w files (not syslinux, some files are read only).
308 copy_bootloaders()
309 {
310 if [ -d "/media/cdrom/boot/isolinux" ]; then
311 mkdir -p $TARGET_ROOT/boot/isolinux
312 cp -a /media/cdrom/boot/isolinux/*.cfg $TARGET_ROOT/boot/isolinux
313 cp -a /media/cdrom/boot/isolinux/*.kbd $TARGET_ROOT/boot/isolinux
314 cp -a /media/cdrom/boot/isolinux/*.txt $TARGET_ROOT/boot/isolinux
315 cp -a /media/cdrom/boot/isolinux/*.bin $TARGET_ROOT/boot/isolinux
316 cp -a /media/cdrom/boot/isolinux/*.msg $TARGET_ROOT/boot/isolinux
317 cp -a /media/cdrom/boot/isolinux/*.lss $TARGET_ROOT/boot/isolinux
318 cp -a /media/cdrom/boot/isolinux/*.c32 $TARGET_ROOT/boot/isolinux
319 fi
320 }
322 # Extract lzma'ed or gziped rootfs.
323 extract_rootfs()
324 {
325 cd $TARGET_ROOT
326 (zcat rootfs.gz 2>/dev/null || lzma d rootfs.gz -so || \
327 cat rootfs.gz) 2>>$LOG | cpio -id 2>>$LOG > /dev/null
328 rm -f rootfs.gz
329 # unpack /usr (double check...)
330 if ls etc/tazlito | grep -q ".extract"; then
331 for i in etc/tazlito/*.extract; do
332 [ -f "$i" ] && . $i /media/cdrom
333 done
334 fi
335 }
337 # /etc/skel (60%)
338 gen_etc_skel()
339 {
340 # Maybe we don't have /home/hacker directory.
341 if [ -d $TARGET_ROOT/home/hacker ]; then
342 echo "XXX" && echo 60
343 echo -e "\nCopying default user files (/etc/skel)..."
344 echo "XXX"
345 cp -a $TARGET_ROOT/home/hacker $TARGET_ROOT/etc/skel
346 else
347 echo "XXX" && echo 60
348 echo -e "\nCreating directory (/etc/skel)..."
349 echo "XXX"
350 mkdir -p $TARGET_ROOT/etc/skel \
351 $TARGET_ROOT/etc/Documents \
352 $TARGET_ROOT/etc/skel/Images \
353 $TARGET_ROOT/etc/skel/.local/bin \
354 $TARGET_ROOT/etc/skel/.local/share
355 fi
356 sleep 2
357 }
359 # Pre configure freshly installed system (70 - 90%).
360 pre_config_system()
361 {
362 cd $TARGET_ROOT
363 # Restore backup of existing /home if exists.
364 # (created by prepare_target_dev)
365 if [ -d home.bak ]; then
366 echo "XXX" && echo 75
367 echo -e "\nThe restore directory: /home..."
368 echo "XXX"
369 rm -rf home
370 mv home.bak home
371 sleep 2
372 fi
373 # Add root device to CHECK_FS in rcS.conf to check filesystem
374 # on each boot.
375 echo "XXX" && echo 80
376 echo -e "\nAdding $TARGET_DEV and CHECK_FS to file /etc/rcS.conf..."
377 echo "XXX"
378 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TARGET_DEV\""# etc/rcS.conf
379 sleep 2
380 # Set hostname.
381 echo "XXX" && echo 85
382 echo -e "\nConfiguring host name: $HOSTNAME"
383 echo "XXX"
384 echo $HOSTNAME > etc/hostname
385 sleep 2
386 }
388 # Determine GRUB partition number and GRUB disk number.
389 grub_config()
390 {
391 DISK_LETTER=${TARGET_DEV#/dev/[h-s]d}
392 DISK_LETTER=${DISK_LETTER%[0-9]}
393 GRUB_PARTITION=$((${TARGET_DEV#/dev/[h-s]d[a-z]}-1))
394 for disk in a b c d e f g h
395 do
396 nb=$(($nb+1))
397 if [ "$disk" = "$DISK_LETTER" ]; then
398 GRUB_DISK=$(($nb-1))
399 break
400 fi
401 done
402 GRUB_ROOT="(hd${GRUB_DISK},${GRUB_PARTITION})"
403 # Create the target GRUB configuration.
404 mkdir -p $TARGET_ROOT/boot/grub
405 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
406 # /boot/grub/menu.lst: GRUB boot loader configuration.
407 #
409 # By default, boot the first entry.
410 default 0
412 # Boot automatically after 8 secs.
413 timeout 8
415 # Change the colors.
416 color yellow/brown light-green/black
418 # For booting SliTaz from : $TARGET_DEV
419 #
420 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
421 root $GRUB_ROOT
422 kernel /boot/$KERNEL root=$TARGET_DEV
424 _EOF_
425 # log
426 echo "grub_config: $TARGET_ROOT/boot/grub/menu.lst" >>$LOG
427 sleep 2
428 }
430 # Files install with gauge, calling for functions or with cmds.
431 install_files()
432 {
433 (
435 echo "XXX" && echo 10
436 echo -e "\nCleaning the root partition if necessary..."
437 echo "XXX"
438 clean_target
440 echo "XXX" && echo 20
441 echo -e "\nInstalling the kernel ($KERNEL)..."
442 echo "XXX"
443 install_kernel
445 echo "XXX" && echo 30
446 echo -e "\nCopying the bootloader syslinux/isolinux..."
447 echo "XXX"
448 copy_bootloaders
450 echo "XXX" && echo 40
451 echo -e "\nCopying the compressed system (rootfs.gz)..."
452 echo "XXX"
453 cp /media/cdrom/boot/rootfs.gz $TARGET_ROOT
454 sleep 2
456 echo "XXX" && echo 50
457 echo -e "\nExtracting the root system..."
458 echo "XXX"
459 extract_rootfs
461 echo "XXX" && echo 60
462 echo -e "\nCopying the default user files (/etc/skel)..."
463 echo "XXX"
464 gen_etc_skel
465 sleep 2
467 echo "XXX" && echo 70
468 echo -e "\nPreconfiguring the system..."
469 echo "XXX"
470 pre_config_system
472 echo "XXX" && echo 90
473 echo -e "\nCreating the configuration file for GRUB (menu.lst)..."
474 echo "XXX"
475 grub_config
477 echo "XXX" && echo 100
478 echo -e "\nFinishing the files installation..."
479 echo "XXX"
480 echo "install_files: OK" >>$LOG
481 sleep 4
483 ) |
484 $DIALOG --title " Install files " \
485 --backtitle "$BACKLIST" \
486 --gauge "Starting to install files..." 18 70 0
487 }
489 # GRUB info with disk name used for grub-install.
490 grub_install()
491 {
492 TARGET_DISK=`echo $TARGET_DEV | sed s/"[0-9]"/''/`
493 set_messages
494 $DIALOG --title " GRUB install " \
495 --backtitle "$BACKLIST" \
496 --clear --colors --yesno "$GRUB_INSTALL_MSG" 18 70
497 retval=$?
498 case $retval in
499 0)
500 (
501 echo "XXX" && echo 50
502 echo -e "\nRunning grub-install on : $TARGET_DISK..."
503 echo "XXX"
504 grub-install --no-floppy \
505 --root-directory=$TARGET_ROOT $TARGET_DISK 2>>$LOG
506 echo "XXX" && echo 100
507 echo -e "\nFinished installation..."
508 echo "XXX"
509 sleep 2
510 ) |
511 $DIALOG --title " GRUB install " \
512 --backtitle "$BACKLIST" \
513 --gauge "Installating GRUB..." 18 70 0 ;;
514 1)
515 echo "grub_install: NO" >>$LOG ;;
516 255)
517 echo -e "ESC pressed.\n" && exit 0 ;;
518 esac
519 }
521 # Copy log file, umount target and eject cdrom.
522 umount_devices()
523 {
524 (
525 echo "XXX" && echo 25
526 echo -e "\nCopying the log files ($LOG)..."
527 echo "XXX"
528 cp -a $LOG $TARGET_ROOT/var/log
529 sleep 2
530 echo "XXX" && echo 50
531 echo -e "\nUnmounting the target ($TARGET_DEV)..."
532 echo "XXX"
533 if mount | grep -q $TARGET_ROOT; then
534 umount $TARGET_ROOT 2>/dev/null
535 fi
536 echo "XXX" && echo 75
537 echo -e "\nUnmounting and ejecting the cdrom..."
538 echo "XXX"
539 if mount | grep -q /media/cdrom; then
540 umount /media/cdrom
541 grep -q slitaz-loram-cdrom /etc/init.d/rcS || eject
542 fi
543 sleep 2
544 echo "XXX" && echo 100
545 echo -e "\n$TITLE..."
546 echo "XXX"
547 sleep 2
548 ) |
549 $DIALOG --title " $TITLE " \
550 --backtitle "$BACKLIST" \
551 --gauge "$TITLE starting..." 18 70 0
552 }
554 # End of installation.
555 end_of_install()
556 {
557 echo "end_of_install: `date`" >>$LOG
558 $DIALOG --title " Installation complete " \
559 --backtitle "$BACKLIST" \
560 --yes-label "Exit" \
561 --no-label "Reboot" \
562 --clear --colors --yesno "$END_OF_INSTALL_MSG" 18 70
563 retval=$?
564 case $retval in
565 0)
566 TITLE="Exiting"
567 umount_devices ;;
568 1)
569 TITLE="Rebooting"
570 umount_devices
571 reboot || reboot -f ;;
572 255)
573 echo -e "ESC pressed.\n" && exit 0 ;;
574 esac
575 }
577 #####################
578 # Upgrade functions #
579 #####################
581 # We need a partition to upgrade SliTaz.
582 ask_for_upgrade_dev()
583 {
584 exec 3>&1
585 UPGRADE_DEV=`$DIALOG --title " Target to upgrade " \
586 --backtitle "$BACKLIST" --clear \
587 --extra-label "List" --extra-button \
588 --colors --inputbox "\n
589 The installer will upgrade the target by saving all configuration files and \
590 the list of installed packages. Then, it will clean the partition and install the \
591 version of SliTaz contained on the cdrom, restore the configuration files and \
592 reinstall all packages which are not present on the cdrom. You will need an active \
593 internet connection before upgrading.\n\n
594 \Z2Partition containing the system upgrade:\Zn" 18 70 2>&1 1>&3`
595 retval=$?
596 exec 3>&-
597 check_retval
598 # Display list and come back.
599 if [ "$retval" = "3" ]; then
600 fdisk_list
601 ask_for_upgrade_dev
602 fi
603 # Empty value.
604 if [ -z $UPGRADE_DEV ]; then
605 ask_for_upgrade_dev
606 fi
607 # Check if specified device exists in /proc/partitions.
608 DEV_NAME=${UPGRADE_DEV#/dev/}
609 if cat /proc/partitions | grep -q $DEV_NAME; then
610 echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
611 else
612 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't seem to exist."
613 error_message
614 ask_for_upgrade_dev
615 fi
616 echo "partition to upgrade: $UPGRADE_DEV" >>$LOG
617 }
619 # Prepare the partition to upgrade, backup, install, restore configs
620 # and reinstall pkgs.
621 upgrade_process()
622 {
623 (
624 echo "XXX" && echo 5
625 echo -e "\nPreparing the target partition..."
626 echo "XXX"
627 # Mount point can be already used.
628 if mount | grep -q $TARGET_ROOT; then
629 umount $TARGET_ROOT 2>$LOG
630 fi
631 mkdir -p $TARGET_ROOT && sleep 2
632 # Mount target.
633 mount $UPGRADE_DEV $TARGET_ROOT >>$LOG 2>>$LOG
634 cd $TARGET_ROOT
635 TARGET_DEV=$UPGRADE_DEV
636 set_messages
638 echo "XXX" && echo 10
639 echo -e "\nSearch for /etc/slitaz-release"
640 echo "XXX"
641 if [ -f etc/slitaz-release ]; then
642 release=`cat etc/slitaz-release`
643 echo "XXX" && echo 15
644 echo -e "\nSliTaz release: $release"
645 echo "XXX"
646 else
647 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't appear to contain \
648 a SliTaz system, the file: /etc/slitaz-release doesn't exist."
649 error_message
650 exit 0
651 fi && sleep 2
653 echo "XXX" && echo 20
654 echo -e "\nBackup /etc, /home and the packages list..."
655 echo "XXX"
656 # Backup target packages list.
657 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
658 for dir in *
659 do
660 case "$dir" in
661 boot)
662 # Upgrade doesn't prompt for grub install, so backup and
663 # create a new grub menu.lst.
664 rm -rf $TARGET_ROOT/boot/vmlinuz-*
665 mv $TARGET_ROOT/boot/grub/menu.lst \
666 $TARGET_ROOT/boot/grub/menu.lst.bak 2>/dev/null
667 grub_config ;;
668 home)
669 mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
670 echo "keeping /home found on: $UPGRADE_DEV" >>$LOG ;;
671 etc)
672 tar czf $TARGET_ROOT/etc.tar.gz etc
673 mv $TARGET_ROOT/etc $TARGET_ROOT/etc.bak
674 echo "keeping /etc found on: $UPGRADE_DEV" >>$LOG ;;
675 var)
676 if [ -d $TARGET_ROOT/var/www ]; then
677 mv $TARGET_ROOT/var/www $TARGET_ROOT/www.bak
678 fi
679 rm -rf $TARGET_ROOT/var ;;
680 lost+found)
681 continue ;;
682 *)
683 echo "removing target: $dir" >>$LOG
684 rm -rf $TARGET_ROOT/$dir 2>>$LOG ;;
685 esac
686 done
687 if [ -d $TARGET_ROOT/mklost+found ]; then
688 mklost+found 2>>$LOG
689 fi
690 sleep 2
692 echo "XXX" && echo 25
693 echo -e "\nInstalling the kernel ($KERNEL)..."
694 echo "XXX"
695 install_kernel
697 echo "XXX" && echo 30
698 echo -e "\nCopying the bootloader syslinux/isolinux..."
699 echo "XXX"
700 copy_bootloaders
702 echo "XXX" && echo 35
703 echo -e "\nCopying the compressed system (rootfs.gz)..."
704 echo "XXX"
705 cp /media/cdrom/boot/rootfs.gz $TARGET_ROOT
706 sleep 2
708 echo "XXX" && echo 40
709 echo -e "\nExtracting the root system..."
710 echo "XXX"
711 extract_rootfs
713 # Restore backups.
714 echo "XXX" && echo 42
715 echo -e "\nRestoring configuration files..."
716 echo "XXX"
717 rm -rf $TARGET_ROOT/home
718 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
719 rm -rf $TARGET_ROOT/etc
720 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
721 if [ -d $TARGET_ROOT/www.bak ]; then
722 rm -rf $TARGET_ROOT/var/www
723 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
724 fi
725 echo "backups restored: `date`" >> $LOG
727 # /var/lib/slitaz-installer
728 mkdir $TARGET_ROOT/var/lib/slitaz-installer
729 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/slitaz-installer
730 mv $TARGET_ROOT/home/packages-selection.list $TARGET_ROOT/var/lib/slitaz-installer
731 cd $TARGET_ROOT/var/lib/slitaz-installer
733 # LiveCD packages list.
734 echo "XXX" && echo 46
735 echo -e "\nCreating package lists..."
736 echo "XXX"
737 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-cdrom.list || exit 1
738 echo "packages-cdrom.list: done" >> $LOG
739 # Diff
740 diff packages-cdrom.list packages-selection.list | \
741 grep ^+[a-z] | sed s/^+// > packages-selection.diff
742 echo "packages-selection.diff: done" >> $LOG
743 # Get mirror list.
744 tazpkg recharge >>$LOG 2>>$LOG
745 if [ ! -f /var/lib/tazpkg/packages.list ]; then
746 ERROR_MSG="The list of available packages on the mirror could not be \
747 downloaded. No missing packages will be reinstalled now, but \
748 you can do so later by looking at the following list: \n\n
750 /var/lib/slitaz-installer/packages-selection.diff"
751 error_message
752 fi
753 sleep 2
755 # Check if the pkg is on the mirror.
756 echo "XXX" && echo 48
757 echo -e "\nChecking the availability of packages..."
758 echo "XXX"
759 touch packages-to-install.list
760 packages=0
761 diff=`cat packages-selection.diff | sort`
762 for pkg in $diff
763 do
764 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
765 packages=$(($packages+1))
766 echo "$pkg" >> packages-to-install.list
767 fi
768 done
770 # Calculate the percent for one package and install.
771 echo "XXX" && echo 50
772 echo -e "\nInstalling any packages..."
773 echo "XXX"
774 sleep 2
775 if [ "$packages" == "0" ]; then
776 echo "packages to install: 0" >> $LOG
777 else
778 onepkg=$((48/$packages))
779 pct=50
780 # Get-install all missing pkgs.
781 for pkg in `cat packages-to-install.list`
782 do
783 pct=$(($pct+$onepkg))
784 echo "XXX" && echo $pct
785 echo -e "\nInstallation of: $pkg..."
786 echo "XXX"
787 # Log please.
788 echo "get-install: $pkg" >>$LOG
789 # Get install package and answer yes in case of dependencies.
790 pkgname=`grep ^$pkg /var/lib/tazpkg/packages.list`
791 tazpkg get $pkg >/dev/null 2>/dev/null
792 yes "" | tazpkg install $pkgname.tazpkg --root=$TARGET_ROOT >/dev/null 2>/dev/null
793 rm -f $pkgname.tazpkg
794 done
795 fi
796 echo "XXX" && echo 100
797 echo -e "\nInstallation of packages complete..."
798 echo "XXX"
799 sleep 2
800 ) |
801 $DIALOG --title " Processing system upgrade " \
802 --backtitle "$BACKLIST" \
803 --gauge "Target in preparation..." 18 70 0
804 }
806 # End of system upgrade.
807 end_of_upgrade()
808 {
809 TARGET_DEV=$UPGRADE_DEV
810 set_messages
811 pkgscd=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-cdrom.list | wc -l`
812 pkginst=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-to-install.list | wc -l`
813 echo "end_of_upgrade: `date`" >>$LOG
814 $DIALOG --title " Upgrade completed " \
815 --backtitle "$BACKLIST" \
816 --yes-label "Exit" \
817 --no-label "Reboot" \
818 --clear --colors --yesno "\n
819 Upgrade finished. You can know restart (reboot) \
820 from your SliTaz GNU/Linux system.\n\n
821 Packages on the cdrom : $pkgscd\n
822 Packages installed from the mirror : $pkginst\n" 18 70
823 retval=$?
824 case $retval in
825 0)
826 TITLE="Exiting"
827 umount_devices ;;
828 1)
829 TITLE="Rebooting"
830 umount_devices
831 reboot || reboot -f ;;
832 255)
833 echo -e "ESC pressed.\n" && exit 0 ;;
834 esac
835 }
837 ######################
838 # Installer sequence #
839 ######################
841 set_messages
842 check_root
843 start_installer
845 case $ACTION in
846 upgrade)
847 BACKLIST="$BACKLIST (Upgrade)"
848 mount_cdrom
849 ask_for_upgrade_dev
850 upgrade_process
851 end_of_upgrade
852 ;;
853 install|*)
854 mount_cdrom
855 ask_for_target_dev
856 ask_for_mkfs_target_dev
857 prepare_target_dev
858 ask_for_hostname
859 install_files
860 grub_install
861 end_of_install
862 ;;
863 esac
865 exit 0