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

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