slitaz-tools view installer/slitaz-installer @ rev 649
bootfloppybox: add installer in slitaz boot floppies
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Jul 10 21:42:10 2011 +0200 (2011-07-10) |
parents | 2127ee92746b |
children |
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 (zcat $1 || unlzma -c $1) | cpio -i extractfs.cpio 2> /dev/null &&
502 ( cd / ; cpio -id ) < extractfs.cpio && rm -f extractfs.cpio
503 ofs=$(awk '/07070100/ { o+=index($0,"07070100"); printf "%d\n",o/4 ; exit } { o+=1+length() }' < $1)
504 dd if=$1 skip=$(($ofs / 1024)) bs=4k count=1 2> /dev/null | \
505 ( dd skip=$(($ofs % 1024)) bs=4 2> /dev/null ; \
506 dd if=$1 skip=$((1 + ($ofs / 1024) )) bs=4k ) | extract_loramfs
507 }
509 # Extract lzma'ed or gziped rootfs.
510 extract_rootfs()
511 {
512 local isloramfs
513 isloramfs=
514 cd $TARGET_ROOT
515 if [ -d $1/../fs/etc ]; then
516 # This is a tazlitobox loram (cdrom)
517 cp -a $1/../fs/. .
518 else
519 for i in $(ls $1/rootfs* | sort -r); do
520 if [ ! -d etc ]; then
521 if [ $( (zcat $i 2>/dev/null || lzma d $i -so) | wc -c) \
522 -lt $(stat -c %s $i) ]; then
523 # This is a tazlitobox loram (ram)
524 isloramfs=$i
525 extract_first_loramfs $i
526 continue
527 fi
528 fi
529 if [ -n "$isloramfs" ]; then
530 extract_loramfs < $i
531 continue
532 fi
533 ( zcat $i 2>/dev/null || lzma d $i -so || \
534 cat $i ) 2>>$LOG | cpio -idu
535 done 2>>$LOG > /dev/null
536 fi
537 cp /etc/keymap.conf etc
538 # unpack /usr (double check...)
539 if ls etc/tazlito | grep -q ".extract"; then
540 for i in etc/tazlito/*.extract; do
541 [ -f "$i" ] && . $i /media/cdrom
542 done
543 fi
544 }
546 # Pre configure freshly installed system (60 - 80%).
547 pre_config_system()
548 {
549 cd $TARGET_ROOT
550 # Restore backup of existing /home if exists.
551 # (created by prepare_target_dev)
552 if [ -d home.bak ]; then
553 echo "XXX" && echo 65
554 echo -e "\nRestoring directory: /home..."
555 echo "XXX"
556 rm -rf home
557 mv home.bak home
558 sleep 1
559 fi
560 # Add root device to CHECK_FS in rcS.conf to check filesystem
561 # on each boot.
562 echo "XXX" && echo 70
563 echo -e "\nAdding $TARGET_DEV and CHECK_FS to file /etc/rcS.conf..."
564 echo "XXX"
565 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TARGET_DEV\""# etc/rcS.conf
566 sleep 2
567 # Set hostname.
568 echo "XXX" && echo 80
569 echo -e "\nConfiguring host name: $HOSTNAME"
570 echo "XXX"
571 echo $HOSTNAME > etc/hostname
572 }
574 # Set root passwd and create user after rootfs extraction.
575 users_settings()
576 {
577 cat > $TARGET_ROOT/users.sh << _EOF_
578 #!/bin/sh
579 echo "root:$ROOT_PASSWD" | chpasswd
580 adduser -D -H $USER
582 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
583 if ! grep \$grp /etc/group | grep -q $USER ; then
584 addgroup $USER \$grp
585 fi
586 done
588 echo "$USER:$USER_PASSWD" | chpasswd
589 if [ ! -d /home/$USER ]; then
590 cp -a /etc/skel /home/$USER
591 cp /root/.xinitrc /home/$USER
592 mkdir -p /home/$USER/.config/slitaz
593 cp -a /etc/slitaz/applications.conf /home/$USER/.config/slitaz
594 chown -R $USER.users /home/$USER
595 # Path for user desktop files.
596 for i in /home/$USER/.local/share/applications/*.desktop
597 do
598 sed -i s/"user_name"/"$USER"/g \$i
599 done
600 fi
601 # Slim default user.
602 if [ -f /etc/slim.conf ]; then
603 sed -i s/"default_user .*"/"default_user $USER"/ \
604 /etc/slim.conf
605 fi
606 _EOF_
607 chmod +x $TARGET_ROOT/users.sh
608 chroot $TARGET_ROOT ./users.sh
609 rm $TARGET_ROOT/users.sh
610 }
612 # /home can be on a separate partition. If default user exist in /home
613 # we remove default file crated by users_settings().
614 home_config()
615 {
616 echo "home_config: $HOME_DEV" >> $LOG
617 cd $TARGET_ROOT
618 mv home/$USER tmp
619 mount $HOME_DEV home
620 if [ -d $TARGET_ROOT/home/$USER ]; then
621 rm -rf tmp/$USER
622 else
623 mv tmp/$USER home
624 fi
625 echo "$HOME_DEV /home ext3 defaults 0 2" \
626 >> etc/fstab
627 umount home
628 }
630 # Determine GRUB partition number and GRUB disk number.
631 grub_config()
632 {
633 DISK_LETTER=${TARGET_DEV#/dev/[h-s]d}
634 DISK_LETTER=${DISK_LETTER%[0-9]}
635 GRUB_PARTITION=$((${TARGET_DEV#/dev/[h-s]d[a-z]}-1))
636 for disk in a b c d e f g h
637 do
638 nb=$(($nb+1))
639 if [ "$disk" = "$DISK_LETTER" ]; then
640 GRUB_DISK=$(($nb-1))
641 break
642 fi
643 done
644 GRUB_ROOT="(hd${GRUB_DISK},${GRUB_PARTITION})"
645 # Create the target GRUB configuration.
646 mkdir -p $TARGET_ROOT/boot/grub
647 . /etc/locale.conf
648 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
649 # /boot/grub/menu.lst: GRUB boot loader configuration.
650 #
652 # By default, boot the first entry.
653 default 0
655 # Boot automatically after 8 secs.
656 timeout 8
658 # Graphical splash image.
659 splashimage=/boot/grub/splash.xpm.gz
661 # Change the colors.
662 #color yellow/brown light-green/black
664 # For booting SliTaz from : $TARGET_DEV
665 #
666 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
667 root $GRUB_ROOT
668 kernel /boot/$KERNEL root=$TARGET_DEV lang=$LANG
670 _EOF_
671 # log
672 echo "grub_config: $TARGET_ROOT/boot/grub/menu.lst" >>$LOG
673 sleep 2
674 }
676 # Files install with gauge, calling for functions or with cmds.
677 install_files()
678 {
679 (
681 echo "XXX" && echo 10
682 echo -e "\nCleaning the root partition if necessary..."
683 echo "XXX"
684 clean_target
686 echo "XXX" && echo 20
687 echo -e "\nInstalling the kernel ($KERNEL)..."
688 echo "XXX"
689 install_kernel
691 echo "XXX" && echo 30
692 echo -e "\nCopying the bootloader syslinux/isolinux..."
693 echo "XXX"
694 copy_bootloaders
696 echo "XXX" && echo 50
697 echo -e "\nExtracting the root system..."
698 echo "XXX"
699 extract_rootfs /media/cdrom/boot
701 echo "XXX" && echo 60
702 echo -e "\nPreconfiguring the system..."
703 echo "XXX"
704 pre_config_system
706 echo "XXX" && echo 70
707 echo -e "\nConfiguring root and default $USER account..."
708 echo "XXX"
709 users_settings
710 sleep 2
712 if [ "$HOME_DEV" != "" ]; then
713 echo "XXX" && echo 80
714 echo -e "\nConfiguring $HOME_DEV to be used as /home..."
715 echo "XXX"
716 home_config
717 sleep 2
718 fi
720 echo "XXX" && echo 90
721 echo -e "\nCreating the configuration file for GRUB (menu.lst)..."
722 echo "XXX"
723 grub_config
725 echo "XXX" && echo 100
726 echo -e "\nFinishing the files installation..."
727 echo "XXX"
728 echo "install_files: OK" >>$LOG
729 sleep 2
731 ) |
732 $DIALOG --title " Install files " \
733 --backtitle "$BACKLIST" \
734 --gauge "Starting to install files..." 18 70 0
735 }
737 # GRUB info with disk name used for grub-install.
738 grub_install()
739 {
740 TARGET_DISK=`echo $TARGET_DEV | sed s/"[0-9]"/''/`
741 set_messages
742 $DIALOG --title " GRUB install " \
743 --backtitle "$BACKLIST" \
744 --clear --colors --yesno "$GRUB_INSTALL_MSG" 18 70
745 retval=$?
746 case $retval in
747 0)
748 (
749 echo "XXX" && echo 50
750 echo -e "\nRunning grub-install on : $TARGET_DISK"
751 echo "XXX"
752 grub-install --no-floppy \
753 --root-directory=$TARGET_ROOT $TARGET_DISK 2>>$LOG
754 echo "XXX" && echo 100
755 echo -e "\nFinished installation..."
756 echo "XXX"
757 sleep 2
758 ) |
759 $DIALOG --title " GRUB install " \
760 --backtitle "$BACKLIST" \
761 --gauge "Installing GRUB..." 18 70 0 ;;
762 1)
763 echo "grub_install: NO" >>$LOG ;;
764 255)
765 echo -e "ESC pressed.\n" && exit 0 ;;
766 esac
767 }
769 # Copy log file, umount target and eject cdrom.
770 umount_devices()
771 {
772 (
773 echo "XXX" && echo 25
774 echo -e "\nCopying the log files ($LOG)..."
775 echo "XXX"
776 cp -a $LOG $TARGET_ROOT/var/log
777 sleep 2
778 echo "XXX" && echo 50
779 echo -e "\nUnmounting the target ($TARGET_DEV)..."
780 echo "XXX"
781 if mount | grep -q $TARGET_ROOT; then
782 umount $TARGET_ROOT 2>/dev/null
783 fi
784 echo "XXX" && echo 75
785 echo -e "\nUnmounting and ejecting the cdrom..."
786 echo "XXX"
787 if mount | grep -q /media/cdrom; then
788 umount /media/cdrom
789 grep -q slitaz-loram-cdrom /etc/init.d/rcS || eject
790 fi
791 sleep 2
792 echo "XXX" && echo 100
793 echo -e "\n$TITLE..."
794 echo "XXX"
795 sleep 2
796 ) |
797 $DIALOG --title " $TITLE " \
798 --backtitle "$BACKLIST" \
799 --gauge "$TITLE starting..." 18 70 0
800 }
802 # End of installation.
803 end_of_install()
804 {
805 echo "end_of_install: `date`" >>$LOG
806 $DIALOG --title " Installation complete " \
807 --backtitle "$BACKLIST" \
808 --yes-label "Exit" \
809 --no-label "Reboot" \
810 --clear --colors --yesno "$END_OF_INSTALL_MSG" 18 70
811 retval=$?
812 case $retval in
813 0)
814 TITLE="Exiting"
815 umount_devices ;;
816 1)
817 TITLE="Rebooting"
818 umount_devices
819 reboot || reboot -f ;;
820 255)
821 echo -e "ESC pressed.\n" && exit 0 ;;
822 esac
823 }
825 #####################
826 # Upgrade functions #
827 #####################
829 # We need a partition to upgrade SliTaz.
830 ask_for_upgrade_dev()
831 {
832 exec 3>&1
833 UPGRADE_DEV=`$DIALOG --title " Target to upgrade " \
834 --backtitle "$BACKLIST" --clear \
835 --extra-label "List" --extra-button \
836 --colors --inputbox "\n
837 The installer will upgrade the target by saving all configuration files and \
838 the list of installed packages. Then, it will clean the partition and install the \
839 version of SliTaz contained on the cdrom, restore the configuration files and \
840 reinstall any packages which are not present on the cdrom. You will need an active \
841 internet connection before upgrading.\n\n
842 \Z2Partition containing the system upgrade:\Zn" 18 70 2>&1 1>&3`
843 retval=$?
844 exec 3>&-
845 check_retval
846 # Display list and come back.
847 if [ "$retval" = "3" ]; then
848 fdisk_list
849 ask_for_upgrade_dev
850 fi
851 # Empty value.
852 if [ -z $UPGRADE_DEV ]; then
853 ask_for_upgrade_dev
854 fi
855 # Check if specified device exists in /proc/partitions.
856 DEV_NAME=${UPGRADE_DEV#/dev/}
857 if cat /proc/partitions | grep -q $DEV_NAME; then
858 echo "ask_for_target_dev: $TARGET_DEV" >>$LOG
859 else
860 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't seem to exist."
861 error_message
862 ask_for_upgrade_dev
863 fi
864 echo "partition to upgrade: $UPGRADE_DEV" >>$LOG
865 }
867 # Prepare the partition to upgrade, backup, install, restore configs
868 # and reinstall pkgs.
869 upgrade_process()
870 {
871 (
872 echo "XXX" && echo 5
873 echo -e "\nPreparing the target partition..."
874 echo "XXX"
875 # Mount point can be already used.
876 if mount | grep -q $TARGET_ROOT; then
877 umount $TARGET_ROOT 2>$LOG
878 fi
879 mkdir -p $TARGET_ROOT && sleep 2
880 # Mount target.
881 mount $UPGRADE_DEV $TARGET_ROOT >>$LOG 2>>$LOG
882 cd $TARGET_ROOT
883 TARGET_DEV=$UPGRADE_DEV
884 set_messages
886 echo "XXX" && echo 10
887 echo -e "\nSearching for /etc/slitaz-release"
888 echo "XXX"
889 if [ -f etc/slitaz-release ]; then
890 release=`cat etc/slitaz-release`
891 echo "XXX" && echo 15
892 echo -e "\nSliTaz release: $release"
893 echo "XXX"
894 else
895 ERROR_MSG="The partition \Z2$UPGRADE_DEV\Zn doesn't appear to contain \
896 a SliTaz system, the file: /etc/slitaz-release doesn't exist."
897 error_message
898 exit 0
899 fi && sleep 2
901 echo "XXX" && echo 20
902 echo -e "\nBackup /etc, /home and the packages list..."
903 echo "XXX"
904 # Backup target packages list.
905 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
906 for dir in *
907 do
908 case "$dir" in
909 boot)
910 # Upgrade doesn't prompt for grub install, so backup and
911 # create a new grub menu.lst.
912 rm -rf $TARGET_ROOT/boot/vmlinuz-*
913 mv $TARGET_ROOT/boot/grub/menu.lst \
914 $TARGET_ROOT/boot/grub/menu.lst.bak 2>/dev/null
915 grub_config ;;
916 home)
917 mv $TARGET_ROOT/home $TARGET_ROOT/home.bak
918 echo "keeping /home found on: $UPGRADE_DEV" >>$LOG ;;
919 etc)
920 tar czf $TARGET_ROOT/etc.tar.gz etc
921 mv $TARGET_ROOT/etc $TARGET_ROOT/etc.bak
922 echo "keeping /etc found on: $UPGRADE_DEV" >>$LOG ;;
923 var)
924 if [ -d $TARGET_ROOT/var/www ]; then
925 mv $TARGET_ROOT/var/www $TARGET_ROOT/www.bak
926 fi
927 rm -rf $TARGET_ROOT/var ;;
928 lost+found)
929 continue ;;
930 *)
931 echo "removing target: $dir" >>$LOG
932 rm -rf $TARGET_ROOT/$dir 2>>$LOG ;;
933 esac
934 done
935 if [ -d $TARGET_ROOT/mklost+found ]; then
936 mklost+found 2>>$LOG
937 fi
938 sleep 2
940 echo "XXX" && echo 25
941 echo -e "\nInstalling the kernel ($KERNEL)..."
942 echo "XXX"
943 install_kernel
945 echo "XXX" && echo 30
946 echo -e "\nCopying the bootloader syslinux/isolinux..."
947 echo "XXX"
948 copy_bootloaders
950 echo "XXX" && echo 40
951 echo -e "\nExtracting the root system..."
952 echo "XXX"
953 extract_rootfs /media/cdrom/boot
955 # Restore backups.
956 echo "XXX" && echo 42
957 echo -e "\nRestoring configuration files..."
958 echo "XXX"
959 rm -rf $TARGET_ROOT/home
960 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
961 rm -rf $TARGET_ROOT/etc
962 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
963 if [ -d $TARGET_ROOT/www.bak ]; then
964 rm -rf $TARGET_ROOT/var/www
965 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
966 fi
967 echo "backups restored: `date`" >> $LOG
969 # /var/lib/slitaz-installer
970 mkdir $TARGET_ROOT/var/lib/slitaz-installer
971 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/slitaz-installer
972 mv $TARGET_ROOT/home/packages-selection.list $TARGET_ROOT/var/lib/slitaz-installer
973 cd $TARGET_ROOT/var/lib/slitaz-installer
975 # LiveCD packages list.
976 echo "XXX" && echo 46
977 echo -e "\nCreating package lists..."
978 echo "XXX"
979 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-cdrom.list || exit 1
980 echo "packages-cdrom.list: done" >> $LOG
981 # Diff
982 diff packages-cdrom.list packages-selection.list | \
983 grep ^+[a-z] | sed s/^+// > packages-selection.diff
984 echo "packages-selection.diff: done" >> $LOG
985 # Get mirror list.
986 tazpkg recharge >>$LOG 2>>$LOG
987 if [ ! -f /var/lib/tazpkg/packages.list ]; then
988 ERROR_MSG="The list of available packages on the mirror could not be \
989 downloaded. No missing packages will be reinstalled now, but \
990 you can do so later by looking at the following list: \n\n
992 /var/lib/slitaz-installer/packages-selection.diff"
993 error_message
994 fi
995 sleep 2
997 # Check if the pkg is on the mirror.
998 echo "XXX" && echo 48
999 echo -e "\nChecking the availability of packages..."
1000 echo "XXX"
1001 touch packages-to-install.list
1002 packages=0
1003 diff=`cat packages-selection.diff | sort`
1004 for pkg in $diff
1005 do
1006 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
1007 packages=$(($packages+1))
1008 echo "$pkg" >> packages-to-install.list
1009 fi
1010 done
1012 # Calculate the percent for one package and install.
1013 echo "XXX" && echo 50
1014 echo -e "\nInstalling any packages..."
1015 echo "XXX"
1016 sleep 2
1017 if [ "$packages" == "0" ]; then
1018 echo "packages to install: 0" >> $LOG
1019 else
1020 onepkg=$((48/$packages))
1021 pct=50
1022 # Get-install all missing pkgs.
1023 for pkg in `cat packages-to-install.list`
1024 do
1025 pct=$(($pct+$onepkg))
1026 echo "XXX" && echo $pct
1027 echo -e "\nInstalling: $pkg..."
1028 echo "XXX"
1029 # Log please.
1030 echo "get-install: $pkg" >>$LOG
1031 # Get install package and answer yes in case of dependencies.
1032 pkgname=`grep ^$pkg /var/lib/tazpkg/packages.list`
1033 tazpkg get $pkg >/dev/null 2>/dev/null
1034 yes "" | tazpkg install $pkgname.tazpkg --root=$TARGET_ROOT >/dev/null 2>/dev/null
1035 rm -f $pkgname.tazpkg
1036 done
1037 fi
1038 echo "XXX" && echo 100
1039 echo -e "\nInstallation of packages complete..."
1040 echo "XXX"
1041 sleep 2
1042 ) |
1043 $DIALOG --title " Processing system upgrade " \
1044 --backtitle "$BACKLIST" \
1045 --gauge "Target in preparation..." 18 70 0
1046 }
1048 # End of system upgrade.
1049 end_of_upgrade()
1050 {
1051 TARGET_DEV=$UPGRADE_DEV
1052 set_messages
1053 pkgscd=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-cdrom.list | wc -l`
1054 pkginst=`cat $TARGET_ROOT/var/lib/slitaz-installer/packages-to-install.list | wc -l`
1055 echo "end_of_upgrade: `date`" >>$LOG
1056 $DIALOG --title " Upgrade completed " \
1057 --backtitle "$BACKLIST" \
1058 --yes-label "Exit" \
1059 --no-label "Reboot" \
1060 --clear --colors --yesno "\n
1061 Upgrade finished. You can now restart (reboot) \
1062 from your SliTaz GNU/Linux system.\n\n
1063 Packages on the cdrom : $pkgscd\n
1064 Packages installed from the mirror : $pkginst\n" 18 70
1065 retval=$?
1066 case $retval in
1067 0)
1068 TITLE="Exiting"
1069 umount_devices ;;
1070 1)
1071 TITLE="Rebooting"
1072 umount_devices
1073 reboot || reboot -f ;;
1074 255)
1075 echo -e "ESC pressed.\n" && exit 0 ;;
1076 esac
1077 }
1079 ######################
1080 # Installer sequence #
1081 ######################
1083 set_messages
1084 check_root
1085 start_installer
1087 case $ACTION in
1088 upgrade)
1089 BACKLIST="$BACKLIST (Upgrade)"
1090 mount_cdrom
1091 ask_for_upgrade_dev
1092 upgrade_process
1093 end_of_upgrade ;;
1094 install|*)
1095 mount_cdrom
1096 ask_for_target_dev
1097 ask_for_mkfs_target_dev
1098 ask_for_home
1099 if [ -n "$HOME_DEV" ]; then
1100 ask_for_mkfs_home
1101 fi
1102 ask_for_hostname
1103 ask_for_users_settings
1104 summary
1105 prepare_partitions
1106 install_files
1107 grub_install
1108 end_of_install ;;
1109 esac
1111 exit 0