slitaz-tools view installer/tazinst @ rev 655

tazinst: French locale added
author Dominique Corbex <domcox@slitaz.org>
date Wed Jul 20 15:29:22 2011 +0200 (2011-07-20)
parents 15546925dd96
children a339d3240495
line source
1 #!/bin/sh
2 # slitaz-installer - SliTaz GNU/Linux installer.
3 #
4 # So this is the SliTaz installer. The script starts with a
5 # few main variables, then all the functions and then the
6 # full sequence of functions.
7 #
8 # (C) 2007-2011 SliTaz - GNU General Public License v3.
9 #
10 # Authors : Christophe Lincoln <pankso@slitaz.org>
11 # Dominique Corbex <domcox@slitaz.org>
12 #
13 # Exit codes
14 # 1: Parameters error
15 # 2: Configuration file error
16 # 3: Source error
17 # 4: Cancelled by user
18 # 5: Target partition error
19 # 6: No SliTaz system to upgrade found
20 # 8: Internal error
22 VERSION=3.01
24 # Internationalization
25 . /usr/bin/gettext.sh
26 TEXTDOMAIN='tazinst'
27 export TEXTDOMAIN
29 SOURCE_ROOT=/media/source
30 TARGET_ROOT=/mnt/target
31 LOG=/var/log/tazinst.log
32 BACKLIST="SliTaz GNU/Linux installer"
34 # DEBUG=1: Enable debug msgs
35 DEBUG=0
37 # Predefined urls
38 URL_STABLE="http://mirror.slitaz.org/iso/stable/slitaz-4.0.iso"
39 URL_COOKING="http://mirror.slitaz.org/iso/cooking/slitaz-cooking.iso"
40 URL_ROLLING="http://mirror.slitaz.org/iso/rolling/slitaz-core.iso"
42 # Print a short help
43 usage()
44 {
45 echo -e "\n`gettext \"Tazinst - SliTaz installer - Version\"`: $VERSION\n"
46 echo -e "\033[1m`gettext \"Usage\"`:"
47 echo -e "\033[0m `gettext \"tazinst [command] [config-file]\"`\n"
48 echo -e "\033[1m`gettext \"Commands\"`: \033[0m"
49 echo -e "usage `gettext \"Print this short usage.\"`"
50 echo -e "install `gettext \"Install SliTaz on HDD using a configuration file.\"`"
51 echo -e "upgrade `gettext \"Upgrade SliTaz on HDD using a configuration file.\"`"
52 echo -e "config `gettext \"Generate a configuration file.\"`"
53 echo -e "cli `gettext \"Install or upgrade using command line options:\"`"
54 echo -e " -i `gettext \"Full Install (not upgrading, all present data will be lost).\"`"
55 echo -e " -u `gettext \"Upgrade (Needs an active internet connection).\"`"
56 echo -e " -t <type> `gettext \"Install type (cdrom|usb|iso|web|weboot).\"`"
57 echo -e " -s <source> `gettext \"Source media (ex: file.iso|usb partition|web url).\"`"
58 echo -e " -p <partition> `gettext \"Partition where SliTaz will be installed (ex:/dev/hda3).\"`"
59 echo -e " -f <fs> `gettext \"Partition to be formatted (fs=ext2|ext3|ext4|etc..).\"`"
60 echo -e " -g `gettext \"Install Grub.\"`"
61 echo -e " -w `gettext \"Dual-boot a Windows partition (auto|hd<disk>,<part> ex:hd0,0).\"`"
62 echo -e " -d `gettext \"Debug mode.\"`"
63 exit 0
64 }
66 # Print an error msg & exit
67 # $1: exit code
68 # $@: err msg
69 abort()
70 {
71 # unmouting source & target
72 if mount | grep -q $SOURCE_ROOT; then
73 umount $SOURCE_ROOT 2>>$LOG
74 fi
75 if mount | grep -q $TARGET_ROOT; then
76 umount $TARGET_ROOT 2>>$LOG
77 fi
78 echo -e "`gettext \"Error\"` $@"
79 echo -e "`gettext \"Installation cancelled\"`"
80 test $(id -u) = 0 && echo "Installation cancelled on error $@" >> $LOG
81 exit $1
82 }
84 # Print a warning msg
85 warning()
86 {
87 echo -e "`gettext \"Warning:\"` $@" | tee -a $LOG
88 }
90 # Print a debug msg
91 debug()
92 {
93 [ $DEBUG -gt 0 ] && echo -e "\033[1mDEBUG: \033[0m$1"
94 echo "DEBUG: $1" >>$LOG
95 }
97 # print a msg
98 msg()
99 {
100 STEP=$(($STEP+1))
101 echo "$STEP. $@" | tee -a $LOG
102 }
104 ########################
105 # Gen-config functions #
106 ########################
108 # Generate a config file
109 # $1: Configuration file
110 gen_config()
111 {
112 CONFILE=$1
113 touch $CONFILE || abort 2 `gettext "Unable to write to $CONFILE"`
114 if [ -r "$CONFILE" ]; then
115 cat > $CONFILE << _EOF_
116 # tazinst.conf: SliTaz Installer configuration file.
117 #
119 # Install type : [cdrom|usb|iso|web|weboot]
120 INST_TYPE="cdrom"
122 # Install source
123 # usb:/dev/xxx, ex: SRC_FILE=/dev/sdb1
124 # iso:file.iso, ex: SRC_FILE=~/slitaz.3.0.iso
125 # web: url, ex: SRC_FILE=http://mirror.slitaz.org/iso/cooking/slitaz-cooking.iso
126 # web: predefined mirrors (stable|cooking|rolling), ex: SRC_FILE=cooking
127 SRC_FILE=""
129 # Install Target (Root Partition).
130 TGT_PARTITION="/dev/hda5"
132 # Target File system.
133 # SliTaz uses ext3 by default but another filesystem can be used if wanted,
134 # for this please adjust your /etc/fstab after installation. Valid options are:
135 # (btrfs|ext2|ext3|ext4|fat16|fat32|hfs|hfs+|jfs|ntfs|reiser4|reiserfs|ufs|xfs)
136 TGT_FS="ext3"
138 # Home partition.
139 # On most GNU/Linux systems users personal files are stored in the directory
140 # /home. Home can be on another hard disk or on a separate partition.
141 TGT_HOME=""
142 # Home File system (if /home is on a separate partition)
143 TGT_HOME_FS=""
145 # Hostname
146 TGT_HOSTNAME="slitaz"
148 # root password
149 # The root administrator privilege lets you manage and configure the full
150 # system. A root user can damage your system so you should always setup a
151 # strong password with special characters and/or numbers.
152 TGT_ROOT_PWD="root"
154 # The default user for the system will have his personal files stored
155 # in /home/*user* (and will be automatically added to the audio group).
156 TGT_USER="tux"
157 TGT_USER_PWD=""
159 # Grub bootloader
160 # install grub [yes|no]
161 TGT_GRUB="no"
163 # Windows dual-boot
164 # Dual boot is disabled if WINBOOT is empty: TGT_WINBOOT=""
165 # You may let tazinst find your win partition, mode=auto: TGT_WINBOOT="auto"
166 # or use manual setting: "hd[disk],[partition]" ex:TGT_WINBOOT=hd0,0
167 TGT_WINBOOT=""
169 _EOF_
171 else
172 abort 2 `gettext "Configuration file $CONFILE not found"`
173 fi
174 }
176 ######################
177 # Checking functions #
178 ######################
180 # def values and start log
181 # $@ :
182 init()
183 {
184 echo "=== Tazinst start at `date` ===" >$LOG
185 echo "Command: $0 $@" >>$LOG
187 # Default Type
188 INST_TYPE=cdrom
189 # Default Hostname.
190 TGT_HOSTNAME=slitaz
191 # Default root passwd
192 TGT_ROOT_PWD=root
193 # Default user
194 TGT_USER=tux
195 # Default Grub Install
196 TGT_GRUB=no
197 }
199 # Read Conf
200 # $1: conf file
201 read_configuration_file()
202 {
203 CONFILE=$1
204 if [ -n "$CONFILE" ]; then
205 if [ -r "$CONFILE" ]; then
206 debug "Using config-file=$CONFILE"
207 # source doesn't like file without a path
208 [ $(echo "$CONFILE" | grep -c "/") == "0" ] && CONFILE="./$CONFILE"
209 source $CONFILE || abort 2 `gettext "Unable to read $CONFILE"`
210 else
211 abort 2 `gettext "Configuration file not found"`
212 fi
213 else
214 abort 2 `gettext "No configuration file provided"`
215 fi
216 }
218 # Cli options
219 # $@: tazinst parms
220 check_cli_options()
221 {
222 shift
223 while getopts "c:df:ghip:s:t:uw:" opt ; do
224 case $opt in
225 d) DEBUG=1 ;;
226 f) TGT_FS=$OPTARG ;;
227 g) TGT_GRUB="yes" ;;
228 h) usage ;;
229 i) INSTALL="install" ;;
230 p) TGT_PARTITION=$OPTARG ;;
231 s) SRC_FILE=$OPTARG ;;
232 t) INST_TYPE=$OPTARG ;;
233 u) UPGRADE="upgrade" ;;
234 w) TGT_WINBOOT=$OPTARG ;;
235 [?]) abort 1 ;;
236 esac
237 done
239 # Duplicate install modes are forbidden
240 [ -n "$INSTALL" ] && [ -n "$UPGRADE" ] && abort 1 `gettext "Mismatched parameters"`
241 INST_ACTION="$INSTALL$UPGRADE"
242 # Don't allow formatting on upgrades
243 [ "$INST_ACTION" == "upgrade" ] && [ -n "$TGT_FS" ] && \
244 warning `gettext "Partition $TGT_PARTITION will not be formatted during upgrade"`
245 }
247 # check main vars
248 check_vars()
249 {
250 # error handling
251 local error=no
252 local found=no
253 local partition=""
255 debug "--- Tazinst main options ---"
256 debug "action=$INST_ACTION"
257 debug "type=$INST_TYPE"
258 debug "source=$SRC_FILE"
259 debug "/ partition=$TGT_PARTITION"
260 debug "/ filesystem=$TGT_FS"
261 debug "/home partition=$TGT_HOME"
262 debug "/home filesystem=$TGT_HOME_FS"
263 debug "hostname=$TGT_HOSTNAME"
264 debug "root-pwd=$TGT_ROOT_PWD"
265 debug "user=$TGT_USER"
266 debug "user-pwd=$TGT_USER_PWD"
267 debug "grub=$TGT_GRUB"
268 debug "winboot=$TGT_WINBOOT"
269 debug "--------------------------------------"
271 # Check Action
272 case $INST_ACTION in
273 install|upgrade) ;;
274 *) msg `gettext "INST_ACTION=$INST_ACTION: Invalid setting"`; error=yes ;;
275 esac
277 # Check Type
278 case $INST_TYPE in
279 cdrom|weboot) ;;
280 usb|iso|web)
281 # We need a valid source
282 if [ -z "$SRC_FILE" ]; then
283 msg `gettext "Type is $INST_TYPE, but INST_SOURCE is not set"`; error=yes
284 fi ;;
285 *) msg `gettext "INST_TYPE=$INST_TYPE: Invalid setting"`; error=yes ;;
286 esac
288 # Check Source file
289 # 1. assign predefs
290 if [ "$INST_TYPE" == "web" ]; then
291 [ "$SRC_FILE" == "stable" ] && SRC_FILE=$URL_STABLE
292 [ "$SRC_FILE" == "cooking" ] && SRC_FILE=$URL_COOKING
293 [ "$SRC_FILE" == "rolling" ] && SRC_FILE=$URL_ROLLING
294 fi
295 # 2. check avail.
296 case $INST_TYPE in
297 iso)
298 if [ ! -r "$SRC_FILE" ]; then
299 msg `gettext "SRC_FILE=$SRC_FILE: file not found"`; error=yes
300 fi ;;
301 web)
302 if [ $(wget -sq "$SRC_FILE") ]; then
303 msg `gettext "SRC_FILE=$SRC_FILE: file not found on the web"`; error=yes
304 fi ;;
305 esac
307 # Check Target Partition
308 found=no
309 LIST_PARTITION=$(fdisk -l | awk '/^\/dev/{printf "%s ",$1}')
310 for partition in $LIST_PARTITION; do
311 [ "$partition" == "$TGT_PARTITION" ] && found="yes"
312 done
313 if [ "$found" != "yes" ]; then
314 msg `gettext "TGT_PARTITION=$TGT_PARTITION Partition not found"`; error=yes
315 fi
317 # Check Filesystem
318 case $TGT_FS in
319 "") ;;
320 btrfs|ext2|ext3|ext4|fat16|fat32|hfs|hfs+|jfs|ntfs|reiser4|reiserfs|ufs|xfs)
321 found=no
322 for xdir in /sbin /usr/sbin /usr/bin; do
323 [ -x "$xdir/mkfs.$TGT_FS" ] && found=yes
324 done
325 if [ "$found" == "no" ]; then
326 msg `gettext "$TGT_FS: mkfs.$TGT_FS is not installed."`; error=yes
327 fi ;;
328 *) msg `gettext "TGT_FS=$TGT_FS: Unknown filesystem"`; error=yes ;;
329 esac
331 # Check Home partition
332 if [ -n "$TGT_HOME" ]; then
333 found=no
334 for partition in $LIST_PARTITION; do
335 [ "$partition" == "$TGT_HOME" ] && found=yes
336 done
337 if [ "$found" != "yes" ]; then
338 msg `gettext "TGT_HOME=$TGT_HOME: Partition not found"`; error=yes
339 fi
340 fi
342 # Check Home Filesystem
343 case $TGT_HOME_FS in
344 "") ;;
345 btrfs|ext2|ext3|ext4|fat16|fat32|hfs|hfs+|jfs|ntfs|reiser4|reiserfs|ufs|xfs)
346 found=no
347 for xdir in /sbin /usr/sbin /usr/bin; do
348 [ -x "$xdir/mkfs.$TGT_FS" ] && found=yes
349 done
350 if [ "$found" == "no" ]; then
351 msg `gettext "$TGT_FS: mkfs.$TGT_FS is not installed."`; error=yes
352 fi ;;
353 *) msg `gettext "TGT_HOME_FS=$TGT_HOME_FS: unknown filesystem"`; error=yes ;;
354 esac
356 # Check Grub
357 case $TGT_GRUB in
358 yes|no) ;;
359 *) msg `gettext "TGT_GRUB=$TGT_GRUB: Invalid setting"`; error=yes ;;
360 esac
362 # Check Winboot
363 case $TGT_WINBOOT in
364 "") ;;
365 auto) ;;
366 hd[[:digit:]],[[:digit:]]) ;;
367 *) msg `gettext "TGT_WINBOOT=$TGT_WINBOOT: Invalid format"`; error=yes ;;
368 esac
370 # Stop on error
371 [ "$error" == "yes" ] && abort 1
372 }
374 # Exit install if user is not root.
375 check_root()
376 {
377 if test $(id -u) != 0 ; then
378 echo -e "`gettext \"You must be the root user (system administrator) to install SliTaz, \
379 please use 'su' to get a root SHell and restart installation.\"`"
380 exit 0
381 fi
382 }
384 # Mount cdrom
385 check_cdrom()
386 {
387 # Set device name
388 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3` [ -n "$DRIVE_NAME" ] || DRIVE_NAME=cdrom
389 CDROM=/dev/$DRIVE_NAME
390 # Try to mount a cdrom
391 if mount -t iso9660 $CDROM $SOURCE_ROOT 2>>$LOG; then
392 debug "Using files from cdrom ($CDROM)..."
393 sleep 2
394 else
395 warning `gettext "Failed to mount $CDROM"`
396 fi
397 }
399 # Link LiveUSB
400 check_usb()
401 {
402 # /home is on USB dev
403 if [ -d /home/boot ]; then
404 debug "Using files from USB device..."
405 ln -s /home/boot $SOURCE_ROOT/boot
406 SOURCE_STATUS="link"
407 sleep 2
408 else
409 # Try to mount LiveUSB
410 if mount $SRC_FILE $SOURCE_ROOT 2>>$LOG; then
411 debug "Using files from USB device ($SRC_FILE)..."
412 SOURCE_STATUS="mount"
413 else
414 warning `gettext "Failed to mount USB device $SRC_FILE"`
415 fi
416 fi
417 }
419 # Mount ISO file
420 check_iso()
421 {
422 local src_md5
423 # Integrity check
424 src_md5=$(echo $SRC_FILE | sed 's/.iso$/.md5/')
425 if [ -r "$src_md5" ]; then
426 [ $(md5sum $SRC_FILE | cut -d' ' -f1) == $(cat "$src_md5" | cut -d' ' -f1) ] || \
427 abort 3 `gettext "$SRC-FILE corrupted"`
428 else
429 warning `gettext "$src_md5 not found, unable to check integrity of $SRC_FILE"`
430 fi
431 # Try to mount ISO
432 if mount -o loop -t iso9660 $SRC_FILE $SOURCE_ROOT 2>>$LOG; then
433 debug "Using files from ISO ($SRC_FILE)..."
434 sleep 2
435 else
436 warning `gettext "Failed to mount ISO '$SRC_FILE'"`
437 fi
438 }
440 # Source is on the web
441 check_web()
442 {
443 local src_md5
444 debug "Downloading $SRC_FILE"
445 if wget $SRC_FILE -P /tmp; then
446 debug "Download completed."
447 else
448 warning `gettext "Failed to download '$SRC_FILE'"`
449 fi
450 src_md5=$(echo $SRC_FILE | sed 's/.iso$/.md5/')
451 debug "Downloading $src_md5"
452 wget $src_md5 -P /tmp || warning `gettext "Failed to download '$src_md5'"`
453 tmpfile=$(echo $SRC_FILE | awk 'BEGIN{RS="/"}{out=$1}END{printf"%s",out}')
454 SRC_FILE="/tmp/$tmpfile"
455 check_iso
456 }
458 # We may be in Tiny Web boot mode
459 check_weboot()
460 {
461 if [ -d $SRC_FILE/boot ]; then
462 debug "Using files from HTTP device..."
463 ln -s $SRC_FILE/boot $SOURCE_ROOT/boot
464 sleep 2
465 else
466 abort 3 `gettext "Web boot files not found"`
467 fi
468 }
470 # set up source and check Slitaz' content
471 check_source()
472 {
473 debug "Creating mount point ($SOURCE_ROOT)..."
474 mkdir -p $SOURCE_ROOT
475 sleep 1
476 case $INST_TYPE in
477 cdrom)
478 check_cdrom ;;
479 usb)
480 check_usb ;;
481 iso)
482 check_iso ;;
483 web)
484 check_web ;;
485 weboot)
486 check_cdrom
487 check_web ;;
488 *)
489 abort 8 `gettext "Internal"` ;;
490 esac
492 # Exit with error msg if no rootfs.gz found.
493 debug "Checking installation media..."
494 if [ ! -f $SOURCE_ROOT/boot/rootfs.gz -a \
495 ! -f $SOURCE_ROOT/boot/rootfs1.gz ]; then
496 abort 3 `gettext "Invalid source"`
497 else
498 debug "Installation media checked ok"
499 fi
500 }
502 # Tiny summary
503 summary()
504 {
505 echo -e "`gettext \"Installation settings summary:\"`"
506 STEP=0
508 if [ "$INST_ACTION" == "install" ]; then
509 if [ -n "$TGT_FS" ]; then
510 msg `gettext "Format root partition '$TGT_PARTITION' ($TGT_FS)"`
511 fi
512 if [ -n "$TGT_HOME_FS" ]; then
513 msg `gettext "Format /home partition '$TGT_HOME' ($TGT_HOME_FS)"`
514 fi
515 msg `gettext "Install SliTaz on '$TGT_PARTITION' from $INST_TYPE"`
516 [ -n "$TGT_HOME" ] && msg `gettext "Set Home partition to '$TGT_HOME'"`
517 msg `gettext "Set Hostname as '$TGT_HOSTNAME'"`
518 msg `gettext "Set Default user as '$TGT_USER'"`
519 else
520 msg `gettext "Check '$TGT_PARTITION'"`
521 msg `gettext "Backup /etc, /home and the packages list"`
522 msg `gettext "Upgrade SliTaz on '$TGT_PARTITION' from $INST_TYPE"`
523 msg `gettext "Restore /etc, /home"`
524 msg `gettext "Upgrade additional packages."`
525 fi
526 if [ -n "$TGT_WINBOOT" ]; then
527 msg `gettext "Enable Windows dual-boot ($TGT_WINBOOT)"`
528 fi
529 if [ "$TGT_GRUB" == "yes" ]; then
530 msg `gettext "Install Grub"`
531 fi
533 echo -ne "`gettext \"Continue:(y/n)\"`"
534 read answer
535 case $answer in
536 [oOyY]) echo -e "`gettext \"Running $BACKLIST..\"`" ;;
537 *) abort 4 `gettext "Cancelled by user"` ;;
538 esac
539 STEP=0
540 }
542 #######################
543 # Installer functions #
544 #######################
546 # Mount and mkfs with progress.
547 prepare_install()
548 {
549 debug "Preparing target partition..."
550 # Target may be used
551 mount | grep -q $TGT_PARTITION && \
552 abort 5 `gettext $TGT_PARTITION": Partition in use"`
553 # Mount point can be already used.
554 if mount | grep -q $TARGET_ROOT; then
555 umount $TARGET_ROOT 2>>$LOG
556 fi
557 sleep 2
559 # Formatting root partition
560 case $TGT_FS in
561 "")
562 debug "The partition ($TGT_PARTITION) will be cleaned..."
563 # ROOT_FS=$(parted /dev/hda5 print -m | grep "^1:" | cut -d':' -f5) ;;
564 ROOT_FS=auto ;;
565 *)
566 msg `gettext "Formatting $TGT_PARTITION ($TGT_FS)"`
567 mkfs.$TGT_FS $TGT_PARTITION >>$LOG 2>>$LOG
568 ROOT_FS=$TGT_FS ;;
569 esac
570 sleep 2
572 # Formatting /home
573 if [ -n "$TGT_HOME" ]; then
574 case $TGT_HOME_FS in
575 "")
576 debug "The partition ($TGT_HOME) will be kept..." ;;
577 *)
578 msg `gettext "Formatting /home on $TGT_HOME ($TGT_HOME_FS)"`
579 mkfs.$TGT_HOME_FS -L "Home" $TGT_HOME >>$LOG 2>>$LOG ;;
580 esac
581 sleep 2
582 fi
584 # Mount target.
585 debug "Creating mount point: $TARGET_ROOT"
586 mkdir -p $TARGET_ROOT >>$LOG
587 sleep 2
589 mount -t $ROOT_FS $TGT_PARTITION $TARGET_ROOT >>$LOG 2>>$LOG
590 if [ $(mount | grep -c "mnt/target") == "0" ]; then
591 abort 5 `gettext "Can't mount $TGT_PARTITION"`
592 fi
593 }
595 # Get a clean target device (15%).
596 clean_target()
597 {
598 if [ -z "$TGT_FS" ]; then
599 # partition was not formatted
600 debug "Cleaning the root partition ($TGT_PARTITION)..."
601 # Keep /home in case of reinstall.
602 cd $TARGET_ROOT || abort 8 `gettext "Internal"`
603 for dir in *
604 do
605 case "$dir" in
606 home)
607 debug "keeping /home found on: $TGT_PARTITION"
608 mv home home.bak ;;
609 lost+found)
610 continue ;;
611 *)
612 debug "removing target: $dir"
613 rm -rf $dir 2>>$LOG ;;
614 esac
615 done
616 if [ -d mklost+found ]; then
617 mklost+found 2>>$LOG
618 fi
619 fi
620 sleep 2
621 }
623 # Kernel is renamed to standard vmlinuz-$VERSION.
624 install_kernel()
625 {
626 if [ -d /$TARGET_ROOT/lib/modules ]; then
627 KERNEL=$(ls /$TARGET_ROOT/lib/modules | tail -1)
628 KERNEL="vmlinuz-$KERNEL"
629 else
630 warning `gettext "Falling back to running kernel name.."`
631 KERNEL=vmlinuz-`uname -r`
632 fi
633 mkdir -p $TARGET_ROOT/boot
634 cp $SOURCE_ROOT/boot/bzImage $TARGET_ROOT/boot/$KERNEL
635 debug "install_kernel: $KERNEL"
636 sleep 2
637 }
639 # Copy isolinux r/w files (not syslinux, some files are read only).
640 copy_bootloaders()
641 {
642 if [ -d "$SOURCE/ROOT/boot/isolinux" ]; then
643 debug "Copy isolinux r/w files"
644 mkdir -p $TARGET_ROOT/boot/isolinux
645 cp -a $SOURCE_ROOT/boot/isolinux/*.cfg $TARGET_ROOT/boot/isolinux
646 cp -a $SOURCE_ROOT/boot/isolinux/*.kbd $TARGET_ROOT/boot/isolinux
647 cp -a $SOURCE_ROOT/boot/isolinux/*.txt $TARGET_ROOT/boot/isolinux
648 cp -a $SOURCE_ROOT/boot/isolinux/*.bin $TARGET_ROOT/boot/isolinux
649 cp -a $SOURCE_ROOT/boot/isolinux/*.msg $TARGET_ROOT/boot/isolinux
650 cp -a $SOURCE_ROOT/boot/isolinux/*.lss $TARGET_ROOT/boot/isolinux
651 cp -a $SOURCE_ROOT/boot/isolinux/*.c32 $TARGET_ROOT/boot/isolinux
652 fi
653 }
655 need_package()
656 {
657 [ -d /var/lib/tazpkg/installed/$1 ] || tazpkg get-install $1
658 }
660 # extract packed rootfs: squashfs or cromfs
661 extract_loramfs()
662 {
663 local i
664 for i in $(cpio -idvum 2> /dev/null); do
665 case "$i" in
666 rootfs*)
667 need_package squashfs
668 if ! unsquashfs $i ; then
669 need_package cromfs
670 unmkcromfs $i squashfs-root
671 fi
672 mv -f squashfs-root/* .
673 rmdir squashfs-root
674 rm -f $i
675 esac
676 done
677 }
679 # This is a loram rootfs.gz, skip loram bootstrap and extract
680 extract_first_loramfs()
681 {
682 (zcat $1 || unlzma -c $1) | cpio -i extractfs.cpio 2> /dev/null &&
683 ( cd / ; cpio -id ) < extractfs.cpio && rm -f extractfs.cpio
684 ofs=$(awk '/07070100/ { o+=index($0,"07070100"); printf "%d\n",o/4 ; exit } { o+=1+length() }' < $1)
685 dd if=$1 skip=$(($ofs / 1024)) bs=4k count=1 2> /dev/null | \
686 ( dd skip=$(($ofs % 1024)) bs=4 2> /dev/null ; \
687 dd if=$1 skip=$((1 + ($ofs / 1024) )) bs=4k ) | extract_loramfs
688 }
690 # Extract lzma'ed or gziped rootfs.
691 extract_rootfs()
692 {
693 local isloramfs
694 isloramfs=
695 cd $TARGET_ROOT || abort 8 `gettext "Internal"`
696 if [ -d $1/../fs/etc ]; then
697 # This is a tazlitobox loram (cdrom)
698 cp -a $1/../fs/. .
699 else
700 for i in $(ls $1/rootfs* | sort -r); do
701 if [ ! -d etc ]; then
702 if [ $( (zcat $i 2>/dev/null || lzma d $i -so) | wc -c) \
703 -lt $(stat -c %s $i) ]; then
704 # This is a tazlitobox loram (ram)
705 isloramfs=$i
706 extract_first_loramfs $i
707 continue
708 fi
709 fi
710 if [ -n "$isloramfs" ]; then
711 extract_loramfs < $i
712 continue
713 fi
714 ( zcat $i 2>/dev/null || lzma d $i -so || \
715 cat $i ) 2>>$LOG | cpio -idu
716 done 2>>$LOG > /dev/null
717 fi
718 cp /etc/keymap.conf etc
719 # unpack /usr (double check...)
720 if ls etc/tazlito | grep -q ".extract"; then
721 for i in etc/tazlito/*.extract; do
722 [ -f "$i" ] && . $i /media/cdrom
723 done
724 fi
725 }
727 # Pre configure freshly installed system (60 - 80%).
728 pre_config_system()
729 {
730 cd $TARGET_ROOT || abort 8 `gettext "Internal"`
731 # Restore backup of existing /home if exists.
732 # (created by prepare_target_dev)
733 if [ -d home.bak ]; then
734 debug "Restoring directory: /home..."
735 rm -rf home
736 mv home.bak home
737 sleep 1
738 fi
739 # Add root device to CHECK_FS in rcS.conf to check filesystem
740 # on each boot.
741 debug "Adding $TGT_PARTITION and CHECK_FS to file /etc/rcS.conf..."
742 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TGT_PARTITION\""# etc/rcS.conf
743 sleep 2
744 # Set hostname.
745 msg `gettext "Configuring host name: $TGT_HOSTNAME"`
746 echo $TGT_HOSTNAME > etc/hostname
747 }
749 # Set root passwd and create user after rootfs extraction.
750 users_settings()
751 {
752 cat > $TARGET_ROOT/users.sh << _EOF_
753 #!/bin/sh
754 echo "root:$TGT_ROOT_PWD" | chpasswd > /etc/null
755 adduser -D -H $TGT_USER
757 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
758 if ! grep \$grp /etc/group | grep -q $TGT_USER ; then
759 grep -q \$grp /etc/group && addgroup $TGT_USER \$grp
760 fi
761 done
763 echo "$TGT_USER:$TGT_USER_PWD" | chpasswd > /etc/null
764 if [ ! -d /home/$TGT_USER ]; then
765 cp -a /etc/skel /home/$TGT_USER
766 [ -e /root/.xinitrc ] && cp /root/.xinitrc /home/$TGT_USER
767 mkdir -p /home/$TGT_USER/.config/slitaz
768 cp -a /etc/slitaz/applications.conf /home/$TGT_USER/.config/slitaz
769 # chmod $TGT_USER:user doesn't work with most ISO
770 if grep -q ^users: /etc/group; then
771 chown -R $TGT_USER:users /home/$TGT_USER
772 else
773 chown -R $TGT_USER:$TGT_USER /home/$TGT_USER
774 fi
775 # Path for user desktop files.
776 for i in /home/$TGT_USER/.local/share/applications/*.desktop
777 do
778 [ -e "$i" ] && sed -i s/"user_name"/"$TGT_USER"/g \$i
779 done
780 fi
781 # Slim default user.
782 if [ -f /etc/slim.conf ]; then
783 sed -i s/"default_user .*"/"default_user $TGT_USER"/ \
784 /etc/slim.conf
785 fi
786 _EOF_
787 chmod +x $TARGET_ROOT/users.sh
788 chroot $TARGET_ROOT ./users.sh
789 rm $TARGET_ROOT/users.sh
790 sleep 2
791 }
793 # /home can be on a separate partition. If default user exists in /home
794 # we remove default file created by users_settings().
795 home_config()
796 {
797 debug "home_config: $TGT_HOME"
798 cd $TARGET_ROOT || abort 8 `gettext "Internal"`
799 mv home/$TGT_USER tmp
800 mount $TGT_HOME home
801 if [ -d $TARGET_ROOT/home/$TGTUSER ]; then
802 rm -rf tmp/$TGT_USER
803 else
804 mv tmp/$TGT_USER home
805 fi
806 echo "$TGT_HOME /home ext3 defaults 0 2" \
807 >> etc/fstab
808 umount home
809 }
811 # Search for a Windows partition
812 win_partition()
813 {
814 # msg `gettext "Searching for Windows"`
815 if [ "$TGT_WINBOOT" == "auto" ];then
816 WINBOOT=$(fdisk -l | awk '
817 BEGIN{disk=-1, found=-1, winboot=""}
818 {
819 # Counting disk
820 if ($1=="Disk"){disk++, part=-1}
821 # Counting partition
822 if (substr($1,1,4)=="/dev"){part++}
823 # Read partition Id
824 if ($2=="*"){Id=$6} else {Id=$5}
825 # Detect Windows type
826 if (Id=="7" || Id=="b"){
827 if (found){
828 # record 1st Windows partition found
829 winboot=sprintf("hd%d,%d",disk,part),found++}
830 }
831 }
832 END{printf "%s", winboot}')
833 if [ -z "$WINBOOT" ]; then
834 warning `gettext "No windows partition found. Dual-boot disabled"`
835 TGT_WINBOOT=""
836 fi
837 fi
838 }
840 # Determine GRUB partition number and GRUB disk number.
841 grub_partition()
842 {
843 DISK_LETTER=${TGT_PARTITION#/dev/[h-s]d}
844 DISK_LETTER=${DISK_LETTER%[0-9]}
845 GRUB_PARTITION=$((${TGT_PARTITION#/dev/[h-s]d[a-z]}-1))
846 for disk in a b c d e f g h
847 do
848 nb=$(($nb+1))
849 if [ "$disk" = "$DISK_LETTER" ]; then
850 GRUB_DISK=$(($nb-1))
851 break
852 fi
853 done
854 GRUB_ROOT="(hd${GRUB_DISK},${GRUB_PARTITION})"
855 }
857 # Create grub conf
858 grub_config()
859 {
860 grub_partition
861 if [ "$TGT_GRUB" == "yes" ]; then
862 win_partition
863 fi
864 # Create the target GRUB configuration.
865 mkdir -p $TARGET_ROOT/boot/grub
866 . /etc/locale.conf
867 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
868 # /boot/grub/menu.lst: GRUB boot loader configuration.
869 #
871 # By default, boot the first entry.
872 default 0
874 # Boot automatically after 8 secs.
875 timeout 8
877 # Graphical splash image.
878 splashimage=/boot/grub/splash.xpm.gz
880 # Change the colors.
881 #color yellow/brown light-green/black
883 # For booting SliTaz from : $TGT_PARTITION
884 #
885 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
886 root $GRUB_ROOT
887 kernel /boot/$KERNEL root=$TGT_PARTITION lang=$LANG
889 _EOF_
890 if [ -n "$TGT_WINBOOT" ]; then
891 msg `gettext "Enabling Windows dual-boot"`
892 cat >> $TARGET_ROOT/boot/grub/menu.lst << _EOF_
893 # For booting Windows :
894 #
895 title Microsoft Windows
896 rootnoverify ($WINBOOT)
897 chainloader +1
899 _EOF_
900 fi
901 # log
902 debug "grub_config: $TARGET_ROOT/boot/grub/menu.lst"
903 echo "--- menu.lst -------------" >>$LOG
904 cat $TARGET_ROOT/boot/grub/menu.lst >>$LOG
905 echo "--- menu.lst -------------" >>$LOG
906 sleep 2
907 }
909 # Files install, calling for functions or with cmds.
910 install_files()
911 {
912 msg `gettext "Installing SliTaz on $TGT_PARTITION"`
913 # saving pwd
914 local save_pwd=$(pwd)
916 debug "Cleaning the root partition if necessary..."
917 clean_target
919 debug "Extracting the root system..."
920 extract_rootfs $SOURCE_ROOT/boot
922 debug "Installing the kernel..."
923 install_kernel
925 debug "Copying the bootloader syslinux/isolinux..."
926 copy_bootloaders
928 debug "Preconfiguring the system..."
929 pre_config_system
931 msg `gettext "Configuring root and default $TGT_USER account..."`
932 users_settings
934 if [ "$TGT_HOME" != "" ]; then
935 msg `gettext "Configuring $TGT_HOME to be used as /home..."`
936 home_config
937 sleep 2
938 fi
940 debug "Creating configuration file for GRUB (menu.lst)..."
941 grub_config
943 debug "Files installation completed"
944 sleep 2
945 # restoring pwd
946 cd $save_pwd
947 }
949 # GRUB info with disk name used for grub-install.
950 grub_install()
951 {
952 if [ "$TGT_GRUB" == "yes" ]; then
953 TARGET_DISK=`echo $TGT_PARTITION | sed s/"[0-9]"/''/`
954 msg `gettext "Running grub-install on : $TARGET_DISK"`
955 grub-install --no-floppy \
956 --root-directory=$TARGET_ROOT $TARGET_DISK 2>>$LOG
957 debug "Grub installation done..."
958 else
959 debug "Grub not installed"
960 fi
961 }
963 # Copy log file, umount target and eject cdrom.
964 umount_devices()
965 {
966 # Umount target
967 if mount | grep -q $TARGET_ROOT; then
968 echo -e "`gettext \"Unmounting target ($TGT_PARTITION)...\"`"
969 umount $TARGET_ROOT 2>>$LOG
970 fi
972 # Umount source
973 if mount | grep -q $SOURCE_ROOT; then
974 echo -e "`gettext \"Unmounting $SOURCE_ROOT\"`"
975 umount $SOURCE_ROOT
976 fi
978 # Eject cd
979 if [ "$INST_TYPE" == "cdrom" ]; then
980 echo -e "`gettext \"Ejecting cdrom...\"`"
981 eject
982 fi
983 sleep 2
984 }
986 # End of installation.
987 end_of_install()
988 {
989 echo -e "`gettext \"Installation complete. You can now restart (reboot) \"`"
990 echo -e "`gettext \"from your SliTaz GNU/Linux system.\"`"
991 echo "=== Tazinst end at `date` ===" >>$LOG
992 # Log files
993 echo -e "`gettext \"Copying log files ($LOG)...\"`"
994 cp -a $LOG $TARGET_ROOT/var/log
995 sleep 2
996 # umount
997 umount_devices
998 }
1000 #####################
1001 # Upgrade functions #
1002 #####################
1004 # Mount.
1005 prepare_upgrade()
1007 debug "Preparing the target partition..."
1008 # Target may be used
1009 mount | grep -q $TGT_PARTITION && \
1010 abort 5 `gettext "$TGT_PARTITION": Partition in use"`
1011 # Mount point can be already used.
1012 if mount | grep -q $TARGET_ROOT; then
1013 umount $TARGET_ROOT 2>>$LOG
1014 fi
1015 mkdir -p $TARGET_ROOT && sleep 2
1016 # Mount target.
1017 mount $TGT_PARTITION $TARGET_ROOT >>$LOG 2>>$LOG
1018 if [ $(mount | grep -c "mnt/target") == "0" ]; then
1019 abort 5 `gettext "Can't mount $TGT_PARTITION"`
1020 fi
1023 # Check for a valid SliTaz
1024 check_release()
1026 if [ -f $TARGET_ROOT/etc/slitaz-release ]; then
1027 release=`cat $TARGET_ROOT/etc/slitaz-release`
1028 msg `gettext "Preparing upgrade of SliTaz release: $release"`
1029 else
1030 abort 6 `gettext "The partition '$TGT_PARTITION' doesn't appear to contain \
1031 a SliTaz system, the file: /etc/slitaz-release doesn't exist."`
1032 fi && sleep 2
1035 # Backup target packages list.
1036 backup_files()
1038 cd $TARGET_ROOT || abort 8 `gettext "Internal"`
1039 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
1040 for dir in *
1041 do
1042 case "$dir" in
1043 boot)
1044 rm -rf boot/vmlinuz-* ;;
1045 home)
1046 mv home home.bak
1047 debug "keeping /home found on: $TGT_PARTITION" ;;
1048 etc)
1049 tar czf etc.tar.gz etc
1050 mv etc etc.bak
1051 debug "keeping /etc found on: $TGT_PARTITION" ;;
1052 var)
1053 if [ -d var/www ]; then
1054 mv var/www www.bak
1055 debug "keeping /var/www found on: $TGT_PARTITION"
1056 fi
1057 rm -rf var 2>>$LOG ;;
1058 lost+found)
1059 continue ;;
1060 *)
1061 debug "removing target: $dir"
1062 rm -rf $dir 2>>$LOG ;;
1063 esac
1064 done
1065 if [ -d mklost+found ]; then
1066 mklost+found 2>>$LOG
1067 fi
1068 sleep 2
1071 # Restore backups.
1072 restore_files()
1074 rm -rf $TARGET_ROOT/home
1075 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
1076 rm -rf $TARGET_ROOT/etc
1077 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
1078 if [ -d $TARGET_ROOT/www.bak ]; then
1079 rm -rf $TARGET_ROOT/var/www
1080 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
1081 fi
1082 debug "backups restored: `date`"
1084 # /var/lib/slitaz-installer
1085 mkdir -p $TARGET_ROOT/var/lib/tazinst
1086 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/tazinst
1087 mv $TARGET_ROOT/home/packages-selection.list $TARGET_ROOT/var/lib/tazinst
1090 # Added pkgs
1091 install_pkgs()
1093 # Check if the pkg is on the mirror.
1094 debug "Checking the availability of packages..."
1095 touch packages-to-install.list
1096 packages=0
1097 diff=`cat packages-selection.diff | sort`
1098 for pkg in $diff
1099 do
1100 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
1101 packages=$(($packages+1))
1102 echo "$pkg" >> packages-to-install.list
1103 fi
1104 done
1106 # Calculate the percent for one package and install.
1107 debug "Installing any packages..."
1108 sleep 2
1109 if [ "$packages" == "0" ]; then
1110 debug "packages to install: 0"
1111 else
1112 onepkg=$((48/$packages))
1113 pct=50
1114 # Get-install all missing pkgs.
1115 for pkg in `cat packages-to-install.list`
1116 do
1117 pct=$(($pct+$onepkg))
1118 echo $pct
1119 debug "Installing: $pkg..."
1120 # Get install package and answer yes in case of dependencies.
1121 pkgname=`grep ^$pkg /var/lib/tazpkg/packages.list`
1122 tazpkg get $pkg >/dev/null 2>/dev/null
1123 yes "" | tazpkg install $pkgname.tazpkg --root=$TARGET_ROOT >/dev/null 2>/dev/null
1124 rm -f $pkgname.tazpkg
1125 done
1126 fi
1127 echo 100
1128 debug "Installation of packages complete..."
1129 sleep 2
1132 # Search for added pkgs
1133 update_pkgs()
1135 cd $TARGET_ROOT/var/lib/tazinst || abort 8 `gettext "Internal"`
1136 # LiveCD packages list.
1137 debug "Creating package lists..."
1138 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-source.list || exit 1
1139 debug "packages-source.list: done"
1140 # Diff
1141 diff packages-source.list packages-selection.list | \
1142 grep ^+[a-z] | sed s/^+// > packages-selection.diff
1143 debug "packages-selection.diff: done"
1144 # Get mirror list.
1145 tazpkg recharge >>$LOG 2>>$LOG
1146 if [ -f /var/lib/tazpkg/packages.list ]; then
1147 install_pkgs
1148 else
1149 touch packages-to-install.list
1150 warning `gettext "The list of available packages on the mirror could not be \
1151 downloaded. No missing packages will be reinstalled now, but \
1152 you can do so later by looking at the following list: \
1153 /var/lib/tazinst/packages-selection.diff"`
1154 fi
1155 sleep 2
1158 # Update grub conf
1159 grub_update()
1161 # Backup and create a new grub menu.lst.
1162 if [ "$TGT_GRUB" == "yes" ]; then
1163 msg `gettext "Grub update"`
1164 mv $TARGET_ROOT/boot/grub/menu.lst \
1165 $TARGET_ROOT/boot/grub/menu.lst.bak 2>/dev/null
1166 grub_config
1167 fi
1170 # Prepare the partition to upgrade, backup, install, restore configs
1171 # and reinstall pkgs.
1172 upgrade_files()
1174 # saving pwd
1175 local save_pwd=$(pwd)
1176 cd $TARGET_ROOT || abort 8 `gettext "Internal"`
1178 debug "Searching for /etc/slitaz-release"
1179 check_release
1181 msg `gettext "Backup /etc, /home and the packages list..."`
1182 backup_files
1184 msg `gettext "Upgrading SliTaz on $TGT_PARTITION"`
1186 debug "Copying the bootloader syslinux/isolinux..."
1187 copy_bootloaders
1189 debug "Extracting the root system..."
1190 extract_rootfs $SOURCE_ROOT/boot
1192 msg `gettext "Restoring configuration files..."`
1193 restore_files
1195 debug "Installing the kernel..."
1196 install_kernel
1198 msg `gettext "Upgrading added packages..."`
1199 update_pkgs
1201 # restoring pwd
1202 cd $save_pwd
1205 # End of system upgrade.
1206 end_of_upgrade()
1208 pkgscd=`cat $TARGET_ROOT/var/lib/tazinst/packages-source.list | wc -l`
1209 pkginst=`cat $TARGET_ROOT/var/lib/tazinst/packages-to-install.list | wc -l`
1210 echo -e "`gettext \"Upgrade finished. You can now restart (reboot) from your SliTaz GNU/Linux system.\"`"
1211 echo -e "`gettext \"Packages on the cdrom :\"`" $pkgscd
1212 echo -e "`gettext \"Packages installed from the mirror :\"`" $pkginst
1213 echo "=== Tazinst end at `date` ===" >>$LOG
1214 umount_devices
1217 ######################
1218 # Installer sequence #
1219 ######################
1221 case $1 in
1222 install)
1223 INST_ACTION=install
1224 check_root
1225 init $@
1226 read_configuration_file $2
1227 check_vars
1228 check_source
1229 prepare_install
1230 install_files
1231 grub_install
1232 end_of_install ;;
1233 upgrade)
1234 INST_ACTION=upgrade
1235 check_root
1236 init $@
1237 read_configuration_file $2
1238 check_vars
1239 check_source
1240 prepare_upgrade
1241 upgrade_files
1242 grub_update
1243 end_of_upgrade ;;
1244 config)
1245 gen_config $2 ;;
1246 cli)
1247 check_root
1248 init $@
1249 check_cli_options $@
1250 check_vars
1251 check_source
1252 summary
1253 case $INST_ACTION in
1254 upgrade)
1255 prepare_upgrade
1256 upgrade_files
1257 grub_update
1258 end_of_upgrade ;;
1259 install)
1260 prepare_install
1261 install_files
1262 grub_install
1263 end_of_install ;;
1264 esac ;;
1265 usage|*)
1266 usage ;;
1267 esac
1269 exit 0