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

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sun Mar 06 19:58:55 2011 +0000 (2011-03-06)
parents f701389ed812
children 0f8c0385c52a
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"); 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 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 # Change the colors.
657 color yellow/brown light-green/black
659 # For booting SliTaz from : $TARGET_DEV
660 #
661 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
662 root $GRUB_ROOT
663 kernel /boot/$KERNEL root=$TARGET_DEV lang=$LANG
665 _EOF_
666 # log
667 echo "grub_config: $TARGET_ROOT/boot/grub/menu.lst" >>$LOG
668 sleep 2
669 }
671 # Files install with gauge, calling for functions or with cmds.
672 install_files()
673 {
674 (
676 echo "XXX" && echo 10
677 echo -e "\nCleaning the root partition if necessary..."
678 echo "XXX"
679 clean_target
681 echo "XXX" && echo 20
682 echo -e "\nInstalling the kernel ($KERNEL)..."
683 echo "XXX"
684 install_kernel
686 echo "XXX" && echo 30
687 echo -e "\nCopying the bootloader syslinux/isolinux..."
688 echo "XXX"
689 copy_bootloaders
691 echo "XXX" && echo 50
692 echo -e "\nExtracting the root system..."
693 echo "XXX"
694 extract_rootfs /media/cdrom/boot
696 echo "XXX" && echo 60
697 echo -e "\nPreconfiguring the system..."
698 echo "XXX"
699 pre_config_system
701 echo "XXX" && echo 70
702 echo -e "\nConfiguring root and default $USER account..."
703 echo "XXX"
704 users_settings
705 sleep 2
707 if [ "$HOME_DEV" != "" ]; then
708 echo "XXX" && echo 80
709 echo -e "\nConfiguring $HOME_DEV to be used as /home..."
710 echo "XXX"
711 home_config
712 sleep 2
713 fi
715 echo "XXX" && echo 90
716 echo -e "\nCreating the configuration file for GRUB (menu.lst)..."
717 echo "XXX"
718 grub_config
720 echo "XXX" && echo 100
721 echo -e "\nFinishing the files installation..."
722 echo "XXX"
723 echo "install_files: OK" >>$LOG
724 sleep 2
726 ) |
727 $DIALOG --title " Install files " \
728 --backtitle "$BACKLIST" \
729 --gauge "Starting to install files..." 18 70 0
730 }
732 # GRUB info with disk name used for grub-install.
733 grub_install()
734 {
735 TARGET_DISK=`echo $TARGET_DEV | sed s/"[0-9]"/''/`
736 set_messages
737 $DIALOG --title " GRUB install " \
738 --backtitle "$BACKLIST" \
739 --clear --colors --yesno "$GRUB_INSTALL_MSG" 18 70
740 retval=$?
741 case $retval in
742 0)
743 (
744 echo "XXX" && echo 50
745 echo -e "\nRunning grub-install on : $TARGET_DISK"
746 echo "XXX"
747 grub-install --no-floppy \
748 --root-directory=$TARGET_ROOT $TARGET_DISK 2>>$LOG
749 echo "XXX" && echo 100
750 echo -e "\nFinished installation..."
751 echo "XXX"
752 sleep 2
753 ) |
754 $DIALOG --title " GRUB install " \
755 --backtitle "$BACKLIST" \
756 --gauge "Installing GRUB..." 18 70 0 ;;
757 1)
758 echo "grub_install: NO" >>$LOG ;;
759 255)
760 echo -e "ESC pressed.\n" && exit 0 ;;
761 esac
762 }
764 # Copy log file, umount target and eject cdrom.
765 umount_devices()
766 {
767 (
768 echo "XXX" && echo 25
769 echo -e "\nCopying the log files ($LOG)..."
770 echo "XXX"
771 cp -a $LOG $TARGET_ROOT/var/log
772 sleep 2
773 echo "XXX" && echo 50
774 echo -e "\nUnmounting the target ($TARGET_DEV)..."
775 echo "XXX"
776 if mount | grep -q $TARGET_ROOT; then
777 umount $TARGET_ROOT 2>/dev/null
778 fi
779 echo "XXX" && echo 75
780 echo -e "\nUnmounting and ejecting the cdrom..."
781 echo "XXX"
782 if mount | grep -q /media/cdrom; then
783 umount /media/cdrom
784 grep -q slitaz-loram-cdrom /etc/init.d/rcS || eject
785 fi
786 sleep 2
787 echo "XXX" && echo 100
788 echo -e "\n$TITLE..."
789 echo "XXX"
790 sleep 2
791 ) |
792 $DIALOG --title " $TITLE " \
793 --backtitle "$BACKLIST" \
794 --gauge "$TITLE starting..." 18 70 0
795 }
797 # End of installation.
798 end_of_install()
799 {
800 echo "end_of_install: `date`" >>$LOG
801 $DIALOG --title " Installation complete " \
802 --backtitle "$BACKLIST" \
803 --yes-label "Exit" \
804 --no-label "Reboot" \
805 --clear --colors --yesno "$END_OF_INSTALL_MSG" 18 70
806 retval=$?
807 case $retval in
808 0)
809 TITLE="Exiting"
810 umount_devices ;;
811 1)
812 TITLE="Rebooting"
813 umount_devices
814 reboot || reboot -f ;;
815 255)
816 echo -e "ESC pressed.\n" && exit 0 ;;
817 esac
818 }
820 #####################
821 # Upgrade functions #
822 #####################
824 # We need a partition to upgrade SliTaz.
825 ask_for_upgrade_dev()
826 {
827 exec 3>&1
828 UPGRADE_DEV=`$DIALOG --title " Target to upgrade " \
829 --backtitle "$BACKLIST" --clear \
830 --extra-label "List" --extra-button \
831 --colors --inputbox "\n
832 The installer will upgrade the target by saving all configuration files and \
833 the list of installed packages. Then, it will clean the partition and install the \
834 version of SliTaz contained on the cdrom, restore the configuration files and \
835 reinstall any packages which are not present on the cdrom. You will need an active \
836 internet connection before upgrading.\n\n
837 \Z2Partition containing the system upgrade:\Zn" 18 70 2>&1 1>&3`
838 retval=$?
839 exec 3>&-
840 check_retval
841 # Display list and come back.
842 if [ "$retval" = "3" ]; then
843 fdisk_list
844 ask_for_upgrade_dev
845 fi
846 # Empty value.
847 if [ -z $UPGRADE_DEV ]; then
848 ask_for_upgrade_dev
849 fi
850 # Check if specified device exists in /proc/partitions.
851 DEV_NAME=${UPGRADE_DEV#/dev/}
852 if cat /proc/partitions | grep -q $DEV_NAME; then
853 echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
854 else
855 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't seem to exist."
856 error_message
857 ask_for_upgrade_dev
858 fi
859 echo "partition to upgrade: $UPGRADE_DEV" >>$LOG
860 }
862 # Prepare the partition to upgrade, backup, install, restore configs
863 # and reinstall pkgs.
864 upgrade_process()
865 {
866 (
867 echo "XXX" && echo 5
868 echo -e "\nPreparing the target partition..."
869 echo "XXX"
870 # Mount point can be already used.
871 if mount | grep -q $TARGET_ROOT; then
872 umount $TARGET_ROOT 2>$LOG
873 fi
874 mkdir -p $TARGET_ROOT && sleep 2
875 # Mount target.
876 mount $UPGRADE_DEV $TARGET_ROOT >>$LOG 2>>$LOG
877 cd $TARGET_ROOT
878 TARGET_DEV=$UPGRADE_DEV
879 set_messages
881 echo "XXX" && echo 10
882 echo -e "\nSearching for /etc/slitaz-release"
883 echo "XXX"
884 if [ -f etc/slitaz-release ]; then
885 release=`cat etc/slitaz-release`
886 echo "XXX" && echo 15
887 echo -e "\nSliTaz release: $release"
888 echo "XXX"
889 else
890 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't appear to contain \
891 a SliTaz system, the file: /etc/slitaz-release doesn't exist."
892 error_message
893 exit 0
894 fi && sleep 2
896 echo "XXX" && echo 20
897 echo -e "\nBackup /etc, /home and the packages list..."
898 echo "XXX"
899 # Backup target packages list.
900 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
901 for dir in *
902 do
903 case "$dir" in
904 boot)
905 # Upgrade doesn't prompt for grub install, so backup and
906 # create a new grub menu.lst.
907 rm -rf $TARGET_ROOT/boot/vmlinuz-*
908 mv $TARGET_ROOT/boot/grub/menu.lst \
909 $TARGET_ROOT/boot/grub/menu.lst.bak 2>/dev/null
910 grub_config ;;
911 home)
912 mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
913 echo "keeping /home found on: $UPGRADE_DEV" >>$LOG ;;
914 etc)
915 tar czf $TARGET_ROOT/etc.tar.gz etc
916 mv $TARGET_ROOT/etc $TARGET_ROOT/etc.bak
917 echo "keeping /etc found on: $UPGRADE_DEV" >>$LOG ;;
918 var)
919 if [ -d $TARGET_ROOT/var/www ]; then
920 mv $TARGET_ROOT/var/www $TARGET_ROOT/www.bak
921 fi
922 rm -rf $TARGET_ROOT/var ;;
923 lost+found)
924 continue ;;
925 *)
926 echo "removing target: $dir" >>$LOG
927 rm -rf $TARGET_ROOT/$dir 2>>$LOG ;;
928 esac
929 done
930 if [ -d $TARGET_ROOT/mklost+found ]; then
931 mklost+found 2>>$LOG
932 fi
933 sleep 2
935 echo "XXX" && echo 25
936 echo -e "\nInstalling the kernel ($KERNEL)..."
937 echo "XXX"
938 install_kernel
940 echo "XXX" && echo 30
941 echo -e "\nCopying the bootloader syslinux/isolinux..."
942 echo "XXX"
943 copy_bootloaders
945 echo "XXX" && echo 40
946 echo -e "\nExtracting the root system..."
947 echo "XXX"
948 extract_rootfs /media/cdrom/boot
950 # Restore backups.
951 echo "XXX" && echo 42
952 echo -e "\nRestoring configuration files..."
953 echo "XXX"
954 rm -rf $TARGET_ROOT/home
955 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
956 rm -rf $TARGET_ROOT/etc
957 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
958 if [ -d $TARGET_ROOT/www.bak ]; then
959 rm -rf $TARGET_ROOT/var/www
960 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
961 fi
962 echo "backups restored: `date`" >> $LOG
964 # /var/lib/slitaz-installer
965 mkdir $TARGET_ROOT/var/lib/slitaz-installer
966 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/slitaz-installer
967 mv $TARGET_ROOT/home/packages-selection.list $TARGET_ROOT/var/lib/slitaz-installer
968 cd $TARGET_ROOT/var/lib/slitaz-installer
970 # LiveCD packages list.
971 echo "XXX" && echo 46
972 echo -e "\nCreating package lists..."
973 echo "XXX"
974 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-cdrom.list || exit 1
975 echo "packages-cdrom.list: done" >> $LOG
976 # Diff
977 diff packages-cdrom.list packages-selection.list | \
978 grep ^+[a-z] | sed s/^+// > packages-selection.diff
979 echo "packages-selection.diff: done" >> $LOG
980 # Get mirror list.
981 tazpkg recharge >>$LOG 2>>$LOG
982 if [ ! -f /var/lib/tazpkg/packages.list ]; then
983 ERROR_MSG="The list of available packages on the mirror could not be \
984 downloaded. No missing packages will be reinstalled now, but \
985 you can do so later by looking at the following list: \n\n
987 /var/lib/slitaz-installer/packages-selection.diff"
988 error_message
989 fi
990 sleep 2
992 # Check if the pkg is on the mirror.
993 echo "XXX" && echo 48
994 echo -e "\nChecking the availability of packages..."
995 echo "XXX"
996 touch packages-to-install.list
997 packages=0
998 diff=`cat packages-selection.diff | sort`
999 for pkg in $diff
1000 do
1001 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
1002 packages=$(($packages+1))
1003 echo "$pkg" >> packages-to-install.list
1004 fi
1005 done
1007 # Calculate the percent for one package and install.
1008 echo "XXX" && echo 50
1009 echo -e "\nInstalling any packages..."
1010 echo "XXX"
1011 sleep 2
1012 if [ "$packages" == "0" ]; then
1013 echo "packages to install: 0" >> $LOG
1014 else
1015 onepkg=$((48/$packages))
1016 pct=50
1017 # Get-install all missing pkgs.
1018 for pkg in `cat packages-to-install.list`
1019 do
1020 pct=$(($pct+$onepkg))
1021 echo "XXX" && echo $pct
1022 echo -e "\nInstalling: $pkg..."
1023 echo "XXX"
1024 # Log please.
1025 echo "get-install: $pkg" >>$LOG
1026 # Get install package and answer yes in case of dependencies.
1027 pkgname=`grep ^$pkg /var/lib/tazpkg/packages.list`
1028 tazpkg get $pkg >/dev/null 2>/dev/null
1029 yes "" | tazpkg install $pkgname.tazpkg --root=$TARGET_ROOT >/dev/null 2>/dev/null
1030 rm -f $pkgname.tazpkg
1031 done
1032 fi
1033 echo "XXX" && echo 100
1034 echo -e "\nInstallation of packages complete..."
1035 echo "XXX"
1036 sleep 2
1037 ) |
1038 $DIALOG --title " Processing system upgrade " \
1039 --backtitle "$BACKLIST" \
1040 --gauge "Target in preparation..." 18 70 0
1043 # End of system upgrade.
1044 end_of_upgrade()
1046 TARGET_DEV=$UPGRADE_DEV
1047 set_messages
1048 pkgscd=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-cdrom.list | wc -l`
1049 pkginst=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-to-install.list | wc -l`
1050 echo "end_of_upgrade: `date`" >>$LOG
1051 $DIALOG --title " Upgrade completed " \
1052 --backtitle "$BACKLIST" \
1053 --yes-label "Exit" \
1054 --no-label "Reboot" \
1055 --clear --colors --yesno "\n
1056 Upgrade finished. You can now restart (reboot) \
1057 from your SliTaz GNU/Linux system.\n\n
1058 Packages on the cdrom : $pkgscd\n
1059 Packages installed from the mirror : $pkginst\n" 18 70
1060 retval=$?
1061 case $retval in
1062 0)
1063 TITLE="Exiting"
1064 umount_devices ;;
1065 1)
1066 TITLE="Rebooting"
1067 umount_devices
1068 reboot || reboot -f ;;
1069 255)
1070 echo -e "ESC pressed.\n" && exit 0 ;;
1071 esac
1074 ######################
1075 # Installer sequence #
1076 ######################
1078 set_messages
1079 check_root
1080 start_installer
1082 case $ACTION in
1083 upgrade)
1084 BACKLIST="$BACKLIST (Upgrade)"
1085 mount_cdrom
1086 ask_for_upgrade_dev
1087 upgrade_process
1088 end_of_upgrade ;;
1089 install|*)
1090 mount_cdrom
1091 ask_for_target_dev
1092 ask_for_mkfs_target_dev
1093 ask_for_home
1094 if [ -n "$HOME_DEV" ]; then
1095 ask_for_mkfs_home
1096 fi
1097 ask_for_hostname
1098 ask_for_users_settings
1099 summary
1100 prepare_partitions
1101 install_files
1102 grub_install
1103 end_of_install ;;
1104 esac
1106 exit 0