flavors view core/rootfs/usr/bin/slitaz-installer @ rev 15

Keep 4 flavors + loram + 3in1 and add tmp addfiles for core
author Christophe Lincoln <pankso@slitaz.org>
date Tue Feb 02 22:26:52 2010 +0100 (2010-02-02)
parents
children
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 # First try to mount a cdrom
117 if mount -t iso9660 $CDROM /media/cdrom 2>>$LOG; then
118 echo "XXX" && echo 60
119 echo -e "\nUsing file from cdrom ($CDROM)..."
120 echo "XXX"
121 sleep 2
122 else
123 # We may be in LiveUSB mode
124 if [ -d /home/boot ]; then
125 echo "XXX" && echo 60
126 echo -e "\nUsing file from USB device..."
127 echo "XXX"
128 rm /media/cdrom/boot 2>/dev/null
129 ln -s /home/boot /media/cdrom/boot
130 sleep 2
131 fi
132 fi
134 echo "XXX" && echo 90
135 echo -e "\nChecking installation media..."
136 echo "XXX"
137 sleep 2
138 ) |
139 $DIALOG --title " Mounting cdrom " \
140 --backtitle "$BACKLIST" \
141 --gauge "Preparing the installation media..." 18 70 0
142 # Exit with error msg if no rootfs.gz found.
143 if [ ! -f /media/cdrom/boot/rootfs.gz ]; then
144 ERROR_MSG="$MOUNT_CDROM_ERROR_MSG"
145 error_message
146 echo "missing: /media/cdrom/boot/rootfs.gz" >>$LOG
147 exit 1
148 fi
149 }
151 # Display a list of available partitions.
152 fdisk_list()
153 {
154 LIST_PARTITIONS=`fdisk -l | grep ^/dev | sed s/'e Win95'/'e'/g`
155 $DIALOG --title " Partition tables " \
156 --backtitle "$BACKLIST" \
157 --clear --msgbox "\n
158 Available partitions :\n\n
159 $LIST_PARTITIONS" 18 70
160 }
162 # We need a partition to install to (inputbox).
163 ask_for_target_dev()
164 {
165 exec 3>&1
166 TARGET_DEV=`$DIALOG --title " Root Partition " \
167 --backtitle "$BACKLIST" --clear \
168 --extra-label "List" --extra-button \
169 --colors --inputbox "$ASK_FOR_TARGET_DEV_MSG" 18 70 2>&1 1>&3`
170 retval=$?
171 exec 3>&-
172 check_retval
173 # Display list and come back.
174 if [ "$retval" = "3" ]; then
175 fdisk_list
176 ask_for_target_dev
177 fi
178 # Empty value.
179 if [ -z $TARGET_DEV ]; then
180 ask_for_target_dev
181 fi
182 set_messages
183 # Check if specified device exists in /proc/partitions.
184 DEV_NAME=${TARGET_DEV#/dev/}
185 if cat /proc/partitions | grep -q $DEV_NAME; then
186 if [ "$DEV_NAME" = "$TARGET_DEV" ]; then
187 TARGET_DEV="/dev/$DEV_NAME"
188 fi
189 echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
190 else
191 ERROR_MSG="Partition \Z2$TARGET_DEV\Zn doesn't exist."
192 error_message
193 ask_for_target_dev
194 fi
195 }
197 # Mkfs if needed/wanted on /.
198 ask_for_mkfs_target_dev()
199 {
200 $DIALOG --title " Format " \
201 --backtitle "$BACKLIST" \
202 --clear --colors --yesno "$ASK_FOR_MKFS_TARGET_DEV_MSG" 18 70
203 retval=$?
204 case $retval in
205 0)
206 MKFS_TARGET_DEV="ext3"
207 echo "mkfs_target_dev: ext3" >>$LOG ;;
208 1)
209 CLEAN="clean"
210 echo "mkfs_target_dev: clean" >>$LOG ;;
211 255)
212 echo -e "ESC pressed.\n" && exit 0 ;;
213 esac
215 }
217 # We can have a separate partition for /home.
218 ask_for_home()
219 {
220 exec 3>&1
221 HOME_DEV=`$DIALOG --title " Home Partition " \
222 --backtitle "$BACKLIST" --clear \
223 --extra-label "List" --extra-button \
224 --colors --inputbox "
225 On most GNU/Linux systems users personal files are stored in the directory \
226 /home. Home can be on a separate partition or another hard disk.
228 \Z2Home partition to use (Optional):\Zn" 18 70 2>&1 1>&3`
229 retval=$?
230 exec 3>&-
231 check_retval
232 # Display list and come back.
233 if [ "$retval" = "3" ]; then
234 fdisk_list
235 ask_for_home
236 fi
237 if [ -n "$HOME_DEV" ]; then
238 # Check if specified device exists in /proc/partitions.
239 DEV_NAME=${HOME_DEV#/dev/}
240 if cat /proc/partitions | grep -q $DEV_NAME; then
241 if [ "$DEV_NAME" = "$HOME_DEV" ]; then
242 HOME_DEV="/dev/$DEV_NAME"
243 fi
244 echo "ask_for_home: $HOME_DEV" >>$LOG
245 else
246 ERROR_MSG="Partition \Z2$HOME_DEV\Zn doesn't exist."
247 error_message
248 ask_for_home
249 fi
250 fi
251 }
253 # Mkfs if needed/wanted on /.
254 ask_for_mkfs_home()
255 {
256 $DIALOG --title " Format " \
257 --backtitle "$BACKLIST" \
258 --clear --colors --yesno "
259 Here you can format the /home partition: $HOME_DEV
261 SliTaz uses ext3 by default but another filesystem can be used if wanted, \
262 for this please adjust /etc/fstab after installation.
264 \Z2Do you want to format (Option): $HOME_DEV\Zn" 18 70
265 retval=$?
266 case $retval in
267 0)
268 MKFS_HOME="ext3"
269 echo "mkfs_home: ext3" >>$LOG ;;
270 1)
271 MKFS_HOME=""
272 echo "mkfs_home: no" >>$LOG ;;
273 255)
274 echo -e "ESC pressed.\n" && exit 0 ;;
275 esac
277 }
279 # Ask for hostname before installing files.
280 ask_for_hostname()
281 {
282 exec 3>&1
283 HOSTNAME=`$DIALOG --title " Hostname " \
284 --backtitle "$BACKLIST" --clear \
285 --colors --inputbox "$ASK_FOR_HOSTNAME_MSG" 18 70 "slitaz" 2>&1 1>&3`
286 retval=$?
287 exec 3>&-
288 check_retval
289 # Empty value.
290 if [ -z $HOSTNAME ]; then
291 HOSTNAME="slitaz"
292 fi
293 }
295 # Ask for root password and default user settings.
296 ask_for_users_settings()
297 {
298 # Root passwd
299 exec 3>&1
300 ROOT_PASSWD=`$DIALOG --title " Root password " \
301 --backtitle "$BACKLIST" --clear \
302 --colors --nocancel --inputbox "
303 The root administrator privilege lets you manage and configure the full \
304 system. A root user can damage your system so you should always setup a \
305 strong password with special characters and/or numbers.
307 \Z2Please specify the Root password for your new system:\Zn" 18 70 "root" 2>&1 1>&3`
308 retval=$?
309 exec 3>&-
310 check_retval
311 # Prevent empty value.
312 if [ -z $ROOT_PASSWD ]; then
313 ROOT_PASSWD="root"
314 fi
315 # Default user
316 exec 3>&1
317 USER=`$DIALOG --title " User name " \
318 --backtitle "$BACKLIST" --clear \
319 --colors --nocancel --inputbox "
320 The default user for the system will have their personal files stored \
321 in /home/*user* (and will be automatically added to the audio group).
323 \Z2Default user name login:\Zn" 18 70 "tux" 2>&1 1>&3`
324 retval=$?
325 exec 3>&-
326 check_retval
327 # Prevent empty value.
328 if [ -z $USER ]; then
329 USER="tux"
330 fi
331 # User passwd
332 exec 3>&1
333 USER_PASSWD=`$DIALOG --title " User password " \
334 --backtitle "$BACKLIST" --clear \
335 --colors --nocancel --inputbox "
336 The password for default user $USER. It may be a security risk if too \
337 weak and should always be strong if you use a SSH connection through the web.
339 \Z2Please specify $USER password:\Zn" 18 70 "tux" 2>&1 1>&3`
340 retval=$?
341 exec 3>&-
342 check_retval
343 # Prevent empty value.
344 if [ -z $USER_PASSWD ]; then
345 USER_PASSWD="tux"
346 fi
347 }
349 # Tiny summary and last chance to cancel or restart for user.
350 summary()
351 {
352 $DIALOG --title " Summary " \
353 --backtitle "$BACKLIST" \
354 --clear --colors --yesno "
355 Installation settings summary and last chance to cancel or restart all \
356 installation steps.
358 Root partition: $TARGET_DEV
359 Home partition: $HOME_DEV
360 Hostname: $HOSTNAME
361 Default user: $USER
363 \Z2Go and install SliTaz or cancel?\Zn" 18 70
364 retval=$?
365 check_retval
366 }
368 # Mount and mkfs with progress.
369 prepare_partitions()
370 {
371 (
372 echo "XXX" && echo 30
373 echo -e "\nPreparing target partition..."
374 echo "XXX"
375 # Mount point can be already used.
376 if mount | grep -q $TARGET_ROOT; then
377 umount $TARGET_ROOT 2>$LOG
378 fi
379 sleep 2
381 if [ "$MKFS_TARGET_DEV" == "ext3" ]; then
382 echo "XXX" && echo 50
383 echo -e "\nExecuting mkfs.ext3 on $TARGET_DEV"
384 echo "XXX"
385 mkfs.ext3 $TARGET_DEV >>$LOG 2>>$LOG
386 else
387 echo "XXX" && echo 50
388 echo -e "\nThe partition ($TARGET_DEV) will be cleaned..."
389 echo "XXX"
390 sleep 2
391 fi
393 if [ "$MKFS_HOME" == "ext3" ]; then
394 echo "XXX" && echo 70
395 echo -e "\nExecuting mkfs.ext3 on $HOME_DEV"
396 echo "XXX"
397 mkfs.ext3 -L "Home" $HOME_DEV >>$LOG 2>>$LOG
398 else
399 echo "XXX" && echo 70
400 echo -e "\nThe partition ($HOME_DEV) will be kept..."
401 echo "XXX"
402 sleep 2
403 fi
405 echo "XXX" && echo 90
406 echo -e "\nCreating mount point: $TARGET_ROOT"
407 echo "XXX"
408 mkdir -p $TARGET_ROOT
409 sleep 2
411 ) |
412 $DIALOG --title " Prepare the target " \
413 --backtitle "$BACKLIST" \
414 --gauge "Target in preparation..." 18 70 0
415 # Mount target.
416 mount $TARGET_DEV $TARGET_ROOT >>$LOG 2>>$LOG
417 }
419 # Get a clean target device (15%).
420 clean_target()
421 {
422 if [ "$CLEAN" == "clean" ]; then
423 echo "XXX" && echo 15
424 echo -e "\nCleaning the root partition ($TARGET_DEV)"
425 echo "XXX"
426 # Keep /home in case of reinstall.
427 cd $TARGET_ROOT
428 for dir in *
429 do
430 case "$dir" in
431 home)
432 mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
433 echo "keeping /home found on: $TARGET_DEV" >>$LOG ;;
434 lost+found)
435 continue ;;
436 *)
437 echo "removing target: $dir" >>$LOG
438 rm -rf $dir 2>>$LOG ;;
439 esac
440 done
441 if [ -d $TARGET_ROOT/mklost+found ]; then
442 mklost+found 2>>$LOG
443 fi
444 fi
445 sleep 2
446 }
448 # Kernel is renamed to standard vmlinuz-$VERSION.
449 install_kernel()
450 {
451 mkdir -p $TARGET_ROOT/boot
452 cp /media/cdrom/boot/bzImage $TARGET_ROOT/boot/$KERNEL
453 echo "install_kernel: $KERNEL" >> $LOG
454 sleep 2
455 }
457 # Copy isolinux r/w files (not syslinux, some files are read only).
458 copy_bootloaders()
459 {
460 if [ -d "/media/cdrom/boot/isolinux" ]; then
461 mkdir -p $TARGET_ROOT/boot/isolinux
462 cp -a /media/cdrom/boot/isolinux/*.cfg $TARGET_ROOT/boot/isolinux
463 cp -a /media/cdrom/boot/isolinux/*.kbd $TARGET_ROOT/boot/isolinux
464 cp -a /media/cdrom/boot/isolinux/*.txt $TARGET_ROOT/boot/isolinux
465 cp -a /media/cdrom/boot/isolinux/*.bin $TARGET_ROOT/boot/isolinux
466 cp -a /media/cdrom/boot/isolinux/*.msg $TARGET_ROOT/boot/isolinux
467 cp -a /media/cdrom/boot/isolinux/*.lss $TARGET_ROOT/boot/isolinux
468 cp -a /media/cdrom/boot/isolinux/*.c32 $TARGET_ROOT/boot/isolinux
469 fi
470 }
472 # Extract lzma'ed or gziped rootfs.
473 extract_rootfs()
474 {
475 cd $TARGET_ROOT
476 (zcat rootfs.gz 2>/dev/null || lzma d rootfs.gz -so || \
477 cat rootfs.gz) 2>>$LOG | cpio -id 2>>$LOG > /dev/null
478 rm -f rootfs.gz
479 # unpack /usr (double check...)
480 if ls etc/tazlito | grep -q ".extract"; then
481 for i in etc/tazlito/*.extract; do
482 [ -f "$i" ] && . $i /media/cdrom
483 done
484 fi
485 }
487 # Pre configure freshly installed system (60 - 80%).
488 pre_config_system()
489 {
490 cd $TARGET_ROOT
491 # Restore backup of existing /home if exists.
492 # (created by prepare_target_dev)
493 if [ -d home.bak ]; then
494 echo "XXX" && echo 65
495 echo -e "\nRestoring directory: /home..."
496 echo "XXX"
497 rm -rf home
498 mv home.bak home
499 sleep 1
500 fi
501 # Add root device to CHECK_FS in rcS.conf to check filesystem
502 # on each boot.
503 echo "XXX" && echo 70
504 echo -e "\nAdding $TARGET_DEV and CHECK_FS to file /etc/rcS.conf..."
505 echo "XXX"
506 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TARGET_DEV\""# etc/rcS.conf
507 sleep 2
508 # Set hostname.
509 echo "XXX" && echo 80
510 echo -e "\nConfiguring host name: $HOSTNAME"
511 echo "XXX"
512 echo $HOSTNAME > etc/hostname
513 }
515 # Set root passwd and create user after rootfs extraction.
516 users_settings()
517 {
518 cat > $TARGET_ROOT/users.sh << _EOF_
519 #!/bin/sh
520 echo "root:$ROOT_PASSWD" | chpasswd
521 adduser -D -H $USER
522 addgroup $USER audio
523 echo "$USER:$USER_PASSWD" | chpasswd
524 if [ ! -d /home/$USER ]; then
525 cp -a /etc/skel /home/$USER
526 chown -R $USER.$USER /home/$USER
527 # Path for user desktop files.
528 for i in /home/$USER/.local/share/applications/*.desktop
529 do
530 sed -i s/"user_name"/"$USER"/g \$i
531 done
532 fi
533 # Slim default user.
534 if [ -f /etc/slim.conf ]; then
535 sed -i s/"default_user .*"/"default_user $USER"/ \
536 /etc/slim.conf
537 fi
538 _EOF_
539 chmod +x $TARGET_ROOT/users.sh
540 chroot $TARGET_ROOT ./users.sh
541 rm $TARGET_ROOT/users.sh
542 }
544 # /home can be on a separate partition. If default user exist in /home
545 # we remove default file crated by users_settings().
546 home_config()
547 {
548 echo "home_config: $HOME_DEV" >> $LOG
549 cd $TARGET_ROOT
550 mv home/$USER tmp
551 mount $HOME_DEV home
552 if [ -d $TARGET_ROOT/home/$USER ]; then
553 rm -rf tmp/$USER
554 else
555 mv tmp/$USER home
556 fi
557 echo "$HOME_DEV /home ext3 defaults 0 2" \
558 >> etc/fstab
559 umount home
560 }
562 # Determine GRUB partition number and GRUB disk number.
563 grub_config()
564 {
565 DISK_LETTER=${TARGET_DEV#/dev/[h-s]d}
566 DISK_LETTER=${DISK_LETTER%[0-9]}
567 GRUB_PARTITION=$((${TARGET_DEV#/dev/[h-s]d[a-z]}-1))
568 for disk in a b c d e f g h
569 do
570 nb=$(($nb+1))
571 if [ "$disk" = "$DISK_LETTER" ]; then
572 GRUB_DISK=$(($nb-1))
573 break
574 fi
575 done
576 GRUB_ROOT="(hd${GRUB_DISK},${GRUB_PARTITION})"
577 # Create the target GRUB configuration.
578 mkdir -p $TARGET_ROOT/boot/grub
579 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
580 # /boot/grub/menu.lst: GRUB boot loader configuration.
581 #
583 # By default, boot the first entry.
584 default 0
586 # Boot automatically after 8 secs.
587 timeout 8
589 # Change the colors.
590 color yellow/brown light-green/black
592 # For booting SliTaz from : $TARGET_DEV
593 #
594 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
595 root $GRUB_ROOT
596 kernel /boot/$KERNEL root=$TARGET_DEV
598 _EOF_
599 # log
600 echo "grub_config: $TARGET_ROOT/boot/grub/menu.lst" >>$LOG
601 sleep 2
602 }
604 # Files install with gauge, calling for functions or with cmds.
605 install_files()
606 {
607 (
609 echo "XXX" && echo 10
610 echo -e "\nCleaning the root partition if necessary..."
611 echo "XXX"
612 clean_target
614 echo "XXX" && echo 20
615 echo -e "\nInstalling the kernel ($KERNEL)"
616 echo "XXX"
617 install_kernel
619 echo "XXX" && echo 30
620 echo -e "\nCopying the bootloader syslinux/isolinux..."
621 echo "XXX"
622 copy_bootloaders
624 echo "XXX" && echo 40
625 echo -e "\nCopying the compressed system (rootfs.gz)..."
626 echo "XXX"
627 cp /media/cdrom/boot/rootfs.gz $TARGET_ROOT
628 sleep 2
630 echo "XXX" && echo 50
631 echo -e "\nExtracting the root system..."
632 echo "XXX"
633 extract_rootfs
635 echo "XXX" && echo 60
636 echo -e "\nPreconfiguring the system..."
637 echo "XXX"
638 pre_config_system
640 echo "XXX" && echo 70
641 echo -e "\nConfiguring root and default $USER account..."
642 echo "XXX"
643 users_settings
644 sleep 2
646 if [ "$HOME_DEV" != "" ]; then
647 echo "XXX" && echo 80
648 echo -e "\nConfiguring $HOME_DEV to be used as /home..."
649 echo "XXX"
650 home_config
651 sleep 2
652 fi
654 echo "XXX" && echo 90
655 echo -e "\nCreating the configuration file for GRUB (menu.lst)..."
656 echo "XXX"
657 grub_config
659 echo "XXX" && echo 100
660 echo -e "\nFinishing the files installation..."
661 echo "XXX"
662 echo "install_files: OK" >>$LOG
663 sleep 2
665 ) |
666 $DIALOG --title " Install files " \
667 --backtitle "$BACKLIST" \
668 --gauge "Starting to install files..." 18 70 0
669 }
671 # GRUB info with disk name used for grub-install.
672 grub_install()
673 {
674 TARGET_DISK=`echo $TARGET_DEV | sed s/"[0-9]"/''/`
675 set_messages
676 $DIALOG --title " GRUB install " \
677 --backtitle "$BACKLIST" \
678 --clear --colors --yesno "$GRUB_INSTALL_MSG" 18 70
679 retval=$?
680 case $retval in
681 0)
682 (
683 echo "XXX" && echo 50
684 echo -e "\nRunning grub-install on : $TARGET_DISK"
685 echo "XXX"
686 grub-install --no-floppy \
687 --root-directory=$TARGET_ROOT $TARGET_DISK 2>>$LOG
688 echo "XXX" && echo 100
689 echo -e "\nFinished installation..."
690 echo "XXX"
691 sleep 2
692 ) |
693 $DIALOG --title " GRUB install " \
694 --backtitle "$BACKLIST" \
695 --gauge "Installing GRUB..." 18 70 0 ;;
696 1)
697 echo "grub_install: NO" >>$LOG ;;
698 255)
699 echo -e "ESC pressed.\n" && exit 0 ;;
700 esac
701 }
703 # Copy log file, umount target and eject cdrom.
704 umount_devices()
705 {
706 (
707 echo "XXX" && echo 25
708 echo -e "\nCopying the log files ($LOG)"
709 echo "XXX"
710 cp -a $LOG $TARGET_ROOT/var/log
711 sleep 2
712 echo "XXX" && echo 50
713 echo -e "\nUnmounting the target ($TARGET_DEV)"
714 echo "XXX"
715 if mount | grep -q $TARGET_ROOT; then
716 umount $TARGET_ROOT 2>/dev/null
717 fi
718 echo "XXX" && echo 75
719 echo -e "\nUnmounting and ejecting the cdrom..."
720 echo "XXX"
721 if mount | grep -q /media/cdrom; then
722 umount /media/cdrom
723 grep -q slitaz-loram-cdrom /etc/init.d/rcS || eject
724 fi
725 sleep 2
726 echo "XXX" && echo 100
727 echo -e "\n$TITLE..."
728 echo "XXX"
729 sleep 2
730 ) |
731 $DIALOG --title " $TITLE " \
732 --backtitle "$BACKLIST" \
733 --gauge "$TITLE starting..." 18 70 0
734 }
736 # End of installation.
737 end_of_install()
738 {
739 echo "end_of_install: `date`" >>$LOG
740 $DIALOG --title " Installation complete " \
741 --backtitle "$BACKLIST" \
742 --yes-label "Exit" \
743 --no-label "Reboot" \
744 --clear --colors --yesno "$END_OF_INSTALL_MSG" 18 70
745 retval=$?
746 case $retval in
747 0)
748 TITLE="Exiting"
749 umount_devices ;;
750 1)
751 TITLE="Rebooting"
752 umount_devices
753 reboot || reboot -f ;;
754 255)
755 echo -e "ESC pressed.\n" && exit 0 ;;
756 esac
757 }
759 #####################
760 # Upgrade functions #
761 #####################
763 # We need a partition to upgrade SliTaz.
764 ask_for_upgrade_dev()
765 {
766 exec 3>&1
767 UPGRADE_DEV=`$DIALOG --title " Target to upgrade " \
768 --backtitle "$BACKLIST" --clear \
769 --extra-label "List" --extra-button \
770 --colors --inputbox "\n
771 The installer will upgrade the target by saving all configuration files and \
772 the list of installed packages. Then, it will clean the partition and install the \
773 version of SliTaz contained on the cdrom, restore the configuration files and \
774 reinstall any packages which are not present on the cdrom. You will need an active \
775 internet connection before upgrading.\n\n
776 \Z2Partition containing the system upgrade:\Zn" 18 70 2>&1 1>&3`
777 retval=$?
778 exec 3>&-
779 check_retval
780 # Display list and come back.
781 if [ "$retval" = "3" ]; then
782 fdisk_list
783 ask_for_upgrade_dev
784 fi
785 # Empty value.
786 if [ -z $UPGRADE_DEV ]; then
787 ask_for_upgrade_dev
788 fi
789 # Check if specified device exists in /proc/partitions.
790 DEV_NAME=${UPGRADE_DEV#/dev/}
791 if cat /proc/partitions | grep -q $DEV_NAME; then
792 echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
793 else
794 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't seem to exist."
795 error_message
796 ask_for_upgrade_dev
797 fi
798 echo "partition to upgrade: $UPGRADE_DEV" >>$LOG
799 }
801 # Prepare the partition to upgrade, backup, install, restore configs
802 # and reinstall pkgs.
803 upgrade_process()
804 {
805 (
806 echo "XXX" && echo 5
807 echo -e "\nPreparing the target partition..."
808 echo "XXX"
809 # Mount point can be already used.
810 if mount | grep -q $TARGET_ROOT; then
811 umount $TARGET_ROOT 2>$LOG
812 fi
813 mkdir -p $TARGET_ROOT && sleep 2
814 # Mount target.
815 mount $UPGRADE_DEV $TARGET_ROOT >>$LOG 2>>$LOG
816 cd $TARGET_ROOT
817 TARGET_DEV=$UPGRADE_DEV
818 set_messages
820 echo "XXX" && echo 10
821 echo -e "\nSearch for /etc/slitaz-release"
822 echo "XXX"
823 if [ -f etc/slitaz-release ]; then
824 release=`cat etc/slitaz-release`
825 echo "XXX" && echo 15
826 echo -e "\nSliTaz release: $release"
827 echo "XXX"
828 else
829 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't appear to contain \
830 a SliTaz system, the file: /etc/slitaz-release doesn't exist."
831 error_message
832 exit 0
833 fi && sleep 2
835 echo "XXX" && echo 20
836 echo -e "\nBackup /etc, /home and the packages list..."
837 echo "XXX"
838 # Backup target packages list.
839 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
840 for dir in *
841 do
842 case "$dir" in
843 boot)
844 # Upgrade doesn't prompt for grub install, so backup and
845 # create a new grub menu.lst.
846 rm -rf $TARGET_ROOT/boot/vmlinuz-*
847 mv $TARGET_ROOT/boot/grub/menu.lst \
848 $TARGET_ROOT/boot/grub/menu.lst.bak 2>/dev/null
849 grub_config ;;
850 home)
851 mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
852 echo "keeping /home found on: $UPGRADE_DEV" >>$LOG ;;
853 etc)
854 tar czf $TARGET_ROOT/etc.tar.gz etc
855 mv $TARGET_ROOT/etc $TARGET_ROOT/etc.bak
856 echo "keeping /etc found on: $UPGRADE_DEV" >>$LOG ;;
857 var)
858 if [ -d $TARGET_ROOT/var/www ]; then
859 mv $TARGET_ROOT/var/www $TARGET_ROOT/www.bak
860 fi
861 rm -rf $TARGET_ROOT/var ;;
862 lost+found)
863 continue ;;
864 *)
865 echo "removing target: $dir" >>$LOG
866 rm -rf $TARGET_ROOT/$dir 2>>$LOG ;;
867 esac
868 done
869 if [ -d $TARGET_ROOT/mklost+found ]; then
870 mklost+found 2>>$LOG
871 fi
872 sleep 2
874 echo "XXX" && echo 25
875 echo -e "\nInstalling the kernel ($KERNEL)"
876 echo "XXX"
877 install_kernel
879 echo "XXX" && echo 30
880 echo -e "\nCopying the bootloader syslinux/isolinux..."
881 echo "XXX"
882 copy_bootloaders
884 echo "XXX" && echo 35
885 echo -e "\nCopying the compressed system (rootfs.gz)..."
886 echo "XXX"
887 cp /media/cdrom/boot/rootfs.gz $TARGET_ROOT
888 sleep 2
890 echo "XXX" && echo 40
891 echo -e "\nExtracting the root system..."
892 echo "XXX"
893 extract_rootfs
895 # Restore backups.
896 echo "XXX" && echo 42
897 echo -e "\nRestoring configuration files..."
898 echo "XXX"
899 rm -rf $TARGET_ROOT/home
900 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
901 rm -rf $TARGET_ROOT/etc
902 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
903 if [ -d $TARGET_ROOT/www.bak ]; then
904 rm -rf $TARGET_ROOT/var/www
905 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
906 fi
907 echo "backups restored: `date`" >> $LOG
909 # /var/lib/slitaz-installer
910 mkdir $TARGET_ROOT/var/lib/slitaz-installer
911 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/slitaz-installer
912 mv $TARGET_ROOT/home/packages-selection.list $TARGET_ROOT/var/lib/slitaz-installer
913 cd $TARGET_ROOT/var/lib/slitaz-installer
915 # LiveCD packages list.
916 echo "XXX" && echo 46
917 echo -e "\nCreating package lists..."
918 echo "XXX"
919 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-cdrom.list || exit 1
920 echo "packages-cdrom.list: done" >> $LOG
921 # Diff
922 diff packages-cdrom.list packages-selection.list | \
923 grep ^+[a-z] | sed s/^+// > packages-selection.diff
924 echo "packages-selection.diff: done" >> $LOG
925 # Get mirror list.
926 tazpkg recharge >>$LOG 2>>$LOG
927 if [ ! -f /var/lib/tazpkg/packages.list ]; then
928 ERROR_MSG="The list of available packages on the mirror could not be \
929 downloaded. No missing packages will be reinstalled now, but \
930 you can do so later by looking at the following list: \n\n
932 /var/lib/slitaz-installer/packages-selection.diff"
933 error_message
934 fi
935 sleep 2
937 # Check if the pkg is on the mirror.
938 echo "XXX" && echo 48
939 echo -e "\nChecking the availability of packages..."
940 echo "XXX"
941 touch packages-to-install.list
942 packages=0
943 diff=`cat packages-selection.diff | sort`
944 for pkg in $diff
945 do
946 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
947 packages=$(($packages+1))
948 echo "$pkg" >> packages-to-install.list
949 fi
950 done
952 # Calculate the percent for one package and install.
953 echo "XXX" && echo 50
954 echo -e "\nInstalling any packages..."
955 echo "XXX"
956 sleep 2
957 if [ "$packages" == "0" ]; then
958 echo "packages to install: 0" >> $LOG
959 else
960 onepkg=$((48/$packages))
961 pct=50
962 # Get-install all missing pkgs.
963 for pkg in `cat packages-to-install.list`
964 do
965 pct=$(($pct+$onepkg))
966 echo "XXX" && echo $pct
967 echo -e "\nInstallation of: $pkg..."
968 echo "XXX"
969 # Log please.
970 echo "get-install: $pkg" >>$LOG
971 # Get install package and answer yes in case of dependencies.
972 pkgname=`grep ^$pkg /var/lib/tazpkg/packages.list`
973 tazpkg get $pkg >/dev/null 2>/dev/null
974 yes "" | tazpkg install $pkgname.tazpkg --root=$TARGET_ROOT >/dev/null 2>/dev/null
975 rm -f $pkgname.tazpkg
976 done
977 fi
978 echo "XXX" && echo 100
979 echo -e "\nInstallation of packages complete..."
980 echo "XXX"
981 sleep 2
982 ) |
983 $DIALOG --title " Processing system upgrade " \
984 --backtitle "$BACKLIST" \
985 --gauge "Target in preparation..." 18 70 0
986 }
988 # End of system upgrade.
989 end_of_upgrade()
990 {
991 TARGET_DEV=$UPGRADE_DEV
992 set_messages
993 pkgscd=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-cdrom.list | wc -l`
994 pkginst=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-to-install.list | wc -l`
995 echo "end_of_upgrade: `date`" >>$LOG
996 $DIALOG --title " Upgrade completed " \
997 --backtitle "$BACKLIST" \
998 --yes-label "Exit" \
999 --no-label "Reboot" \
1000 --clear --colors --yesno "\n
1001 Upgrade finished. You can now restart (reboot) \
1002 from your SliTaz GNU/Linux system.\n\n
1003 Packages on the cdrom : $pkgscd\n
1004 Packages installed from the mirror : $pkginst\n" 18 70
1005 retval=$?
1006 case $retval in
1007 0)
1008 TITLE="Exiting"
1009 umount_devices ;;
1010 1)
1011 TITLE="Rebooting"
1012 umount_devices
1013 reboot || reboot -f ;;
1014 255)
1015 echo -e "ESC pressed.\n" && exit 0 ;;
1016 esac
1019 ######################
1020 # Installer sequence #
1021 ######################
1023 set_messages
1024 check_root
1025 start_installer
1027 case $ACTION in
1028 upgrade)
1029 BACKLIST="$BACKLIST (Upgrade)"
1030 mount_cdrom
1031 ask_for_upgrade_dev
1032 upgrade_process
1033 end_of_upgrade ;;
1034 install|*)
1035 mount_cdrom
1036 ask_for_target_dev
1037 ask_for_mkfs_target_dev
1038 ask_for_home
1039 if [ -n "$HOME_DEV" ]; then
1040 ask_for_mkfs_home
1041 fi
1042 ask_for_hostname
1043 ask_for_users_settings
1044 summary
1045 prepare_partitions
1046 install_files
1047 grub_install
1048 end_of_install ;;
1049 esac
1051 exit 0