slitaz-modular view initramfs/usr/bin/slitaz-installer @ rev 178

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