slitaz-tools view installer/tazinst @ rev 658

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