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

slitaz-installer: fix loram
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 27 10:50:24 2011 +0200 (2011-04-27)
parents 0f8c0385c52a
children ebe49a6e58f9
line source
1 #!/bin/sh
2 # slitaz-installer - SliTaz GNU/Linux installer.
3 #
4 # So this is the 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}
15 [ "$1" = "gui" ] && DIALOG=tazdialog
17 # We need to know cdrom device and kernel version string to copy files.
18 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
19 [ -n "$DRIVE_NAME" ] || DRIVE_NAME=cdrom
20 CDROM=/dev/$DRIVE_NAME
21 KERNEL=vmlinuz-`uname -r`
22 TARGET_ROOT=/mnt/target
23 LOG=/var/log/slitaz-installer.log
24 BACKLIST="SliTaz GNU/Linux installer"
25 ACTION=$1
27 #######################
28 # Installer functions #
29 #######################
31 # Messages language setting.
32 set_messages()
33 {
34 if [ -s /usr/share/slitaz/messages/${LANG:0:2}/installer.msg ]; then
35 . /usr/share/slitaz/messages/${LANG:0:2}/installer.msg
36 else
37 . /usr/share/slitaz/messages/en/installer.msg
38 fi
39 }
41 # Display error message.
42 error_message()
43 {
44 $DIALOG --title " Error " \
45 --colors --backtitle "$BACKLIST" \
46 --clear --msgbox "\n$ERROR_MSG" 18 70
47 }
49 # Exit install if user is not root.
50 check_root()
51 {
52 if test $(id -u) != 0 ; then
53 ERROR_MSG="\
54 [\Z6en\Zn] You must be root administrator to start SliTaz installer, please \
55 use 'su' to get a root SHell and restart installation.\n\n
56 [\Z6fr\Zn] Vous devez ĂȘtre root pour installer SLiTaz GNU/Linux. Vous pouvez \
57 utiliser 'su' suivi du mot de passe administrateur pour devenir root \
58 et relancer l'installation."
59 error_message
60 exit 0
61 fi
62 }
64 # This function is used after each screen to contine or abort install.
65 check_retval()
66 {
67 case $retval in
68 0)
69 continue ;;
70 1)
71 echo -e "\nVoluntary exit.\n" && exit 0 ;;
72 3)
73 continue ;;
74 255)
75 echo -e "ESC pressed.\n" && exit 0 ;;
76 esac
77 }
79 # Start install with basic information.
80 start_installer()
81 {
82 $DIALOG --title " Install or Upgrade " \
83 --backtitle "$BACKLIST" \
84 --extra-button --extra-label "Upgrade" \
85 --ok-label "Install" \
86 --clear --colors --yesno "$START_INSTALL_MSG" 18 70
87 retval=$?
88 case $retval in
89 0)
90 ACTION=install ;;
91 1)
92 echo -e "\nVoluntary exit.\n" && exit 0 ;;
93 3)
94 ACTION=upgrade ;;
95 255)
96 echo -e "ESC pressed.\n" && exit 0 ;;
97 esac
98 echo "start_installer: `date`" > $LOG
99 }
101 # Mount cdrom and verify if it's really SliTaz CD.
102 mount_cdrom()
103 {
104 ERROR_MSG=""
105 (
106 echo "XXX" && echo 30
107 echo -e "\nCreating mount point (/media/cdrom)..."
108 echo "XXX"
109 mkdir -p /media/cdrom
110 sleep 1
111 # First try to mount a cdrom
112 if mount -t iso9660 $CDROM /media/cdrom 2>>$LOG; then
113 echo "XXX" && echo 60
114 echo -e "\nUsing files from cdrom ($CDROM)..."
115 echo "XXX"
116 sleep 2
117 # We may be in LiveUSB mode
118 elif [ -d /home/boot ]; then
119 echo "XXX" && echo 60
120 echo -e "\nUsing files from USB device..."
121 echo "XXX"
122 rm /media/cdrom/boot 2>/dev/null
123 ln -s /home/boot /media/cdrom/boot
124 sleep 2
125 # We may be in Tiny Web boot mode
126 elif [ -d /cdrom/boot ]; then
127 echo "XXX" && echo 60
128 echo -e "\nUsing files from HTTP device..."
129 echo "XXX"
130 rm /media/cdrom/boot 2>/dev/null
131 ln -s /cdrom/boot /media/cdrom/boot
132 sleep 2
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 your /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"); printf "%d\n",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 cp /etc/keymap.conf etc
536 # unpack /usr (double check...)
537 if ls etc/tazlito | grep -q ".extract"; then
538 for i in etc/tazlito/*.extract; do
539 [ -f "$i" ] && . $i /media/cdrom
540 done
541 fi
542 }
544 # Pre configure freshly installed system (60 - 80%).
545 pre_config_system()
546 {
547 cd $TARGET_ROOT
548 # Restore backup of existing /home if exists.
549 # (created by prepare_target_dev)
550 if [ -d home.bak ]; then
551 echo "XXX" && echo 65
552 echo -e "\nRestoring directory: /home..."
553 echo "XXX"
554 rm -rf home
555 mv home.bak home
556 sleep 1
557 fi
558 # Add root device to CHECK_FS in rcS.conf to check filesystem
559 # on each boot.
560 echo "XXX" && echo 70
561 echo -e "\nAdding $TARGET_DEV and CHECK_FS to file /etc/rcS.conf..."
562 echo "XXX"
563 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TARGET_DEV\""# etc/rcS.conf
564 sleep 2
565 # Set hostname.
566 echo "XXX" && echo 80
567 echo -e "\nConfiguring host name: $HOSTNAME"
568 echo "XXX"
569 echo $HOSTNAME > etc/hostname
570 }
572 # Set root passwd and create user after rootfs extraction.
573 users_settings()
574 {
575 cat > $TARGET_ROOT/users.sh << _EOF_
576 #!/bin/sh
577 echo "root:$ROOT_PASSWD" | chpasswd
578 adduser -D -H $USER
580 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
581 if ! grep \$grp /etc/group | grep -q $USER ; then
582 addgroup $USER \$grp
583 fi
584 done
586 echo "$USER:$USER_PASSWD" | chpasswd
587 if [ ! -d /home/$USER ]; then
588 cp -a /etc/skel /home/$USER
589 cp /root/.xinitrc /home/$USER
590 mkdir -p /home/$USER/.config/slitaz
591 cp -a /etc/slitaz/applications.conf /home/$USER/.config/slitaz
592 chown -R $USER.users /home/$USER
593 # Path for user desktop files.
594 for i in /home/$USER/.local/share/applications/*.desktop
595 do
596 sed -i s/"user_name"/"$USER"/g \$i
597 done
598 fi
599 # Slim default user.
600 if [ -f /etc/slim.conf ]; then
601 sed -i s/"default_user .*"/"default_user $USER"/ \
602 /etc/slim.conf
603 fi
604 _EOF_
605 chmod +x $TARGET_ROOT/users.sh
606 chroot $TARGET_ROOT ./users.sh
607 rm $TARGET_ROOT/users.sh
608 }
610 # /home can be on a separate partition. If default user exist in /home
611 # we remove default file crated by users_settings().
612 home_config()
613 {
614 echo "home_config: $HOME_DEV" >> $LOG
615 cd $TARGET_ROOT
616 mv home/$USER tmp
617 mount $HOME_DEV home
618 if [ -d $TARGET_ROOT/home/$USER ]; then
619 rm -rf tmp/$USER
620 else
621 mv tmp/$USER home
622 fi
623 echo "$HOME_DEV /home ext3 defaults 0 2" \
624 >> etc/fstab
625 umount home
626 }
628 # Determine GRUB partition number and GRUB disk number.
629 grub_config()
630 {
631 DISK_LETTER=${TARGET_DEV#/dev/[h-s]d}
632 DISK_LETTER=${DISK_LETTER%[0-9]}
633 GRUB_PARTITION=$((${TARGET_DEV#/dev/[h-s]d[a-z]}-1))
634 for disk in a b c d e f g h
635 do
636 nb=$(($nb+1))
637 if [ "$disk" = "$DISK_LETTER" ]; then
638 GRUB_DISK=$(($nb-1))
639 break
640 fi
641 done
642 GRUB_ROOT="(hd${GRUB_DISK},${GRUB_PARTITION})"
643 # Create the target GRUB configuration.
644 mkdir -p $TARGET_ROOT/boot/grub
645 . /etc/locale.conf
646 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
647 # /boot/grub/menu.lst: GRUB boot loader configuration.
648 #
650 # By default, boot the first entry.
651 default 0
653 # Boot automatically after 8 secs.
654 timeout 8
656 # Graphical splash image.
657 splashimage=/boot/grub/splash.xpm.gz
659 # Change the colors.
660 #color yellow/brown light-green/black
662 # For booting SliTaz from : $TARGET_DEV
663 #
664 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
665 root $GRUB_ROOT
666 kernel /boot/$KERNEL root=$TARGET_DEV lang=$LANG
668 _EOF_
669 # log
670 echo "grub_config: $TARGET_ROOT/boot/grub/menu.lst" >>$LOG
671 sleep 2
672 }
674 # Files install with gauge, calling for functions or with cmds.
675 install_files()
676 {
677 (
679 echo "XXX" && echo 10
680 echo -e "\nCleaning the root partition if necessary..."
681 echo "XXX"
682 clean_target
684 echo "XXX" && echo 20
685 echo -e "\nInstalling the kernel ($KERNEL)..."
686 echo "XXX"
687 install_kernel
689 echo "XXX" && echo 30
690 echo -e "\nCopying the bootloader syslinux/isolinux..."
691 echo "XXX"
692 copy_bootloaders
694 echo "XXX" && echo 50
695 echo -e "\nExtracting the root system..."
696 echo "XXX"
697 extract_rootfs /media/cdrom/boot
699 echo "XXX" && echo 60
700 echo -e "\nPreconfiguring the system..."
701 echo "XXX"
702 pre_config_system
704 echo "XXX" && echo 70
705 echo -e "\nConfiguring root and default $USER account..."
706 echo "XXX"
707 users_settings
708 sleep 2
710 if [ "$HOME_DEV" != "" ]; then
711 echo "XXX" && echo 80
712 echo -e "\nConfiguring $HOME_DEV to be used as /home..."
713 echo "XXX"
714 home_config
715 sleep 2
716 fi
718 echo "XXX" && echo 90
719 echo -e "\nCreating the configuration file for GRUB (menu.lst)..."
720 echo "XXX"
721 grub_config
723 echo "XXX" && echo 100
724 echo -e "\nFinishing the files installation..."
725 echo "XXX"
726 echo "install_files: OK" >>$LOG
727 sleep 2
729 ) |
730 $DIALOG --title " Install files " \
731 --backtitle "$BACKLIST" \
732 --gauge "Starting to install files..." 18 70 0
733 }
735 # GRUB info with disk name used for grub-install.
736 grub_install()
737 {
738 TARGET_DISK=`echo $TARGET_DEV | sed s/"[0-9]"/''/`
739 set_messages
740 $DIALOG --title " GRUB install " \
741 --backtitle "$BACKLIST" \
742 --clear --colors --yesno "$GRUB_INSTALL_MSG" 18 70
743 retval=$?
744 case $retval in
745 0)
746 (
747 echo "XXX" && echo 50
748 echo -e "\nRunning grub-install on : $TARGET_DISK"
749 echo "XXX"
750 grub-install --no-floppy \
751 --root-directory=$TARGET_ROOT $TARGET_DISK 2>>$LOG
752 echo "XXX" && echo 100
753 echo -e "\nFinished installation..."
754 echo "XXX"
755 sleep 2
756 ) |
757 $DIALOG --title " GRUB install " \
758 --backtitle "$BACKLIST" \
759 --gauge "Installing GRUB..." 18 70 0 ;;
760 1)
761 echo "grub_install: NO" >>$LOG ;;
762 255)
763 echo -e "ESC pressed.\n" && exit 0 ;;
764 esac
765 }
767 # Copy log file, umount target and eject cdrom.
768 umount_devices()
769 {
770 (
771 echo "XXX" && echo 25
772 echo -e "\nCopying the log files ($LOG)..."
773 echo "XXX"
774 cp -a $LOG $TARGET_ROOT/var/log
775 sleep 2
776 echo "XXX" && echo 50
777 echo -e "\nUnmounting the target ($TARGET_DEV)..."
778 echo "XXX"
779 if mount | grep -q $TARGET_ROOT; then
780 umount $TARGET_ROOT 2>/dev/null
781 fi
782 echo "XXX" && echo 75
783 echo -e "\nUnmounting and ejecting the cdrom..."
784 echo "XXX"
785 if mount | grep -q /media/cdrom; then
786 umount /media/cdrom
787 grep -q slitaz-loram-cdrom /etc/init.d/rcS || eject
788 fi
789 sleep 2
790 echo "XXX" && echo 100
791 echo -e "\n$TITLE..."
792 echo "XXX"
793 sleep 2
794 ) |
795 $DIALOG --title " $TITLE " \
796 --backtitle "$BACKLIST" \
797 --gauge "$TITLE starting..." 18 70 0
798 }
800 # End of installation.
801 end_of_install()
802 {
803 echo "end_of_install: `date`" >>$LOG
804 $DIALOG --title " Installation complete " \
805 --backtitle "$BACKLIST" \
806 --yes-label "Exit" \
807 --no-label "Reboot" \
808 --clear --colors --yesno "$END_OF_INSTALL_MSG" 18 70
809 retval=$?
810 case $retval in
811 0)
812 TITLE="Exiting"
813 umount_devices ;;
814 1)
815 TITLE="Rebooting"
816 umount_devices
817 reboot || reboot -f ;;
818 255)
819 echo -e "ESC pressed.\n" && exit 0 ;;
820 esac
821 }
823 #####################
824 # Upgrade functions #
825 #####################
827 # We need a partition to upgrade SliTaz.
828 ask_for_upgrade_dev()
829 {
830 exec 3>&1
831 UPGRADE_DEV=`$DIALOG --title " Target to upgrade " \
832 --backtitle "$BACKLIST" --clear \
833 --extra-label "List" --extra-button \
834 --colors --inputbox "\n
835 The installer will upgrade the target by saving all configuration files and \
836 the list of installed packages. Then, it will clean the partition and install the \
837 version of SliTaz contained on the cdrom, restore the configuration files and \
838 reinstall any packages which are not present on the cdrom. You will need an active \
839 internet connection before upgrading.\n\n
840 \Z2Partition containing the system upgrade:\Zn" 18 70 2>&1 1>&3`
841 retval=$?
842 exec 3>&-
843 check_retval
844 # Display list and come back.
845 if [ "$retval" = "3" ]; then
846 fdisk_list
847 ask_for_upgrade_dev
848 fi
849 # Empty value.
850 if [ -z $UPGRADE_DEV ]; then
851 ask_for_upgrade_dev
852 fi
853 # Check if specified device exists in /proc/partitions.
854 DEV_NAME=${UPGRADE_DEV#/dev/}
855 if cat /proc/partitions | grep -q $DEV_NAME; then
856 echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
857 else
858 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't seem to exist."
859 error_message
860 ask_for_upgrade_dev
861 fi
862 echo "partition to upgrade: $UPGRADE_DEV" >>$LOG
863 }
865 # Prepare the partition to upgrade, backup, install, restore configs
866 # and reinstall pkgs.
867 upgrade_process()
868 {
869 (
870 echo "XXX" && echo 5
871 echo -e "\nPreparing the target partition..."
872 echo "XXX"
873 # Mount point can be already used.
874 if mount | grep -q $TARGET_ROOT; then
875 umount $TARGET_ROOT 2>$LOG
876 fi
877 mkdir -p $TARGET_ROOT && sleep 2
878 # Mount target.
879 mount $UPGRADE_DEV $TARGET_ROOT >>$LOG 2>>$LOG
880 cd $TARGET_ROOT
881 TARGET_DEV=$UPGRADE_DEV
882 set_messages
884 echo "XXX" && echo 10
885 echo -e "\nSearching for /etc/slitaz-release"
886 echo "XXX"
887 if [ -f etc/slitaz-release ]; then
888 release=`cat etc/slitaz-release`
889 echo "XXX" && echo 15
890 echo -e "\nSliTaz release: $release"
891 echo "XXX"
892 else
893 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't appear to contain \
894 a SliTaz system, the file: /etc/slitaz-release doesn't exist."
895 error_message
896 exit 0
897 fi && sleep 2
899 echo "XXX" && echo 20
900 echo -e "\nBackup /etc, /home and the packages list..."
901 echo "XXX"
902 # Backup target packages list.
903 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
904 for dir in *
905 do
906 case "$dir" in
907 boot)
908 # Upgrade doesn't prompt for grub install, so backup and
909 # create a new grub menu.lst.
910 rm -rf $TARGET_ROOT/boot/vmlinuz-*
911 mv $TARGET_ROOT/boot/grub/menu.lst \
912 $TARGET_ROOT/boot/grub/menu.lst.bak 2>/dev/null
913 grub_config ;;
914 home)
915 mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
916 echo "keeping /home found on: $UPGRADE_DEV" >>$LOG ;;
917 etc)
918 tar czf $TARGET_ROOT/etc.tar.gz etc
919 mv $TARGET_ROOT/etc $TARGET_ROOT/etc.bak
920 echo "keeping /etc found on: $UPGRADE_DEV" >>$LOG ;;
921 var)
922 if [ -d $TARGET_ROOT/var/www ]; then
923 mv $TARGET_ROOT/var/www $TARGET_ROOT/www.bak
924 fi
925 rm -rf $TARGET_ROOT/var ;;
926 lost+found)
927 continue ;;
928 *)
929 echo "removing target: $dir" >>$LOG
930 rm -rf $TARGET_ROOT/$dir 2>>$LOG ;;
931 esac
932 done
933 if [ -d $TARGET_ROOT/mklost+found ]; then
934 mklost+found 2>>$LOG
935 fi
936 sleep 2
938 echo "XXX" && echo 25
939 echo -e "\nInstalling the kernel ($KERNEL)..."
940 echo "XXX"
941 install_kernel
943 echo "XXX" && echo 30
944 echo -e "\nCopying the bootloader syslinux/isolinux..."
945 echo "XXX"
946 copy_bootloaders
948 echo "XXX" && echo 40
949 echo -e "\nExtracting the root system..."
950 echo "XXX"
951 extract_rootfs /media/cdrom/boot
953 # Restore backups.
954 echo "XXX" && echo 42
955 echo -e "\nRestoring configuration files..."
956 echo "XXX"
957 rm -rf $TARGET_ROOT/home
958 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
959 rm -rf $TARGET_ROOT/etc
960 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
961 if [ -d $TARGET_ROOT/www.bak ]; then
962 rm -rf $TARGET_ROOT/var/www
963 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
964 fi
965 echo "backups restored: `date`" >> $LOG
967 # /var/lib/slitaz-installer
968 mkdir $TARGET_ROOT/var/lib/slitaz-installer
969 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/slitaz-installer
970 mv $TARGET_ROOT/home/packages-selection.list $TARGET_ROOT/var/lib/slitaz-installer
971 cd $TARGET_ROOT/var/lib/slitaz-installer
973 # LiveCD packages list.
974 echo "XXX" && echo 46
975 echo -e "\nCreating package lists..."
976 echo "XXX"
977 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-cdrom.list || exit 1
978 echo "packages-cdrom.list: done" >> $LOG
979 # Diff
980 diff packages-cdrom.list packages-selection.list | \
981 grep ^+[a-z] | sed s/^+// > packages-selection.diff
982 echo "packages-selection.diff: done" >> $LOG
983 # Get mirror list.
984 tazpkg recharge >>$LOG 2>>$LOG
985 if [ ! -f /var/lib/tazpkg/packages.list ]; then
986 ERROR_MSG="The list of available packages on the mirror could not be \
987 downloaded. No missing packages will be reinstalled now, but \
988 you can do so later by looking at the following list: \n\n
990 /var/lib/slitaz-installer/packages-selection.diff"
991 error_message
992 fi
993 sleep 2
995 # Check if the pkg is on the mirror.
996 echo "XXX" && echo 48
997 echo -e "\nChecking the availability of packages..."
998 echo "XXX"
999 touch packages-to-install.list
1000 packages=0
1001 diff=`cat packages-selection.diff | sort`
1002 for pkg in $diff
1003 do
1004 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
1005 packages=$(($packages+1))
1006 echo "$pkg" >> packages-to-install.list
1007 fi
1008 done
1010 # Calculate the percent for one package and install.
1011 echo "XXX" && echo 50
1012 echo -e "\nInstalling any packages..."
1013 echo "XXX"
1014 sleep 2
1015 if [ "$packages" == "0" ]; then
1016 echo "packages to install: 0" >> $LOG
1017 else
1018 onepkg=$((48/$packages))
1019 pct=50
1020 # Get-install all missing pkgs.
1021 for pkg in `cat packages-to-install.list`
1022 do
1023 pct=$(($pct+$onepkg))
1024 echo "XXX" && echo $pct
1025 echo -e "\nInstalling: $pkg..."
1026 echo "XXX"
1027 # Log please.
1028 echo "get-install: $pkg" >>$LOG
1029 # Get install package and answer yes in case of dependencies.
1030 pkgname=`grep ^$pkg /var/lib/tazpkg/packages.list`
1031 tazpkg get $pkg >/dev/null 2>/dev/null
1032 yes "" | tazpkg install $pkgname.tazpkg --root=$TARGET_ROOT >/dev/null 2>/dev/null
1033 rm -f $pkgname.tazpkg
1034 done
1035 fi
1036 echo "XXX" && echo 100
1037 echo -e "\nInstallation of packages complete..."
1038 echo "XXX"
1039 sleep 2
1040 ) |
1041 $DIALOG --title " Processing system upgrade " \
1042 --backtitle "$BACKLIST" \
1043 --gauge "Target in preparation..." 18 70 0
1046 # End of system upgrade.
1047 end_of_upgrade()
1049 TARGET_DEV=$UPGRADE_DEV
1050 set_messages
1051 pkgscd=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-cdrom.list | wc -l`
1052 pkginst=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-to-install.list | wc -l`
1053 echo "end_of_upgrade: `date`" >>$LOG
1054 $DIALOG --title " Upgrade completed " \
1055 --backtitle "$BACKLIST" \
1056 --yes-label "Exit" \
1057 --no-label "Reboot" \
1058 --clear --colors --yesno "\n
1059 Upgrade finished. You can now restart (reboot) \
1060 from your SliTaz GNU/Linux system.\n\n
1061 Packages on the cdrom : $pkgscd\n
1062 Packages installed from the mirror : $pkginst\n" 18 70
1063 retval=$?
1064 case $retval in
1065 0)
1066 TITLE="Exiting"
1067 umount_devices ;;
1068 1)
1069 TITLE="Rebooting"
1070 umount_devices
1071 reboot || reboot -f ;;
1072 255)
1073 echo -e "ESC pressed.\n" && exit 0 ;;
1074 esac
1077 ######################
1078 # Installer sequence #
1079 ######################
1081 set_messages
1082 check_root
1083 start_installer
1085 case $ACTION in
1086 upgrade)
1087 BACKLIST="$BACKLIST (Upgrade)"
1088 mount_cdrom
1089 ask_for_upgrade_dev
1090 upgrade_process
1091 end_of_upgrade ;;
1092 install|*)
1093 mount_cdrom
1094 ask_for_target_dev
1095 ask_for_mkfs_target_dev
1096 ask_for_home
1097 if [ -n "$HOME_DEV" ]; then
1098 ask_for_mkfs_home
1099 fi
1100 ask_for_hostname
1101 ask_for_users_settings
1102 summary
1103 prepare_partitions
1104 install_files
1105 grub_install
1106 end_of_install ;;
1107 esac
1109 exit 0