slitaz-tools view installer/tazinst @ rev 763

Tiny edits
author Paul Issott <paul@slitaz.org>
date Sun May 13 13:44:10 2012 +0100 (2012-05-13)
parents e570520a6e4c
children 64cc5c3b9d6c
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-2012 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: Setup 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 # 7: Another instance is running
21 # 8: Internal error
23 VERSION=3.34
25 # Internationalization
26 . /usr/bin/gettext.sh
27 TEXTDOMAIN='tazinst'
28 export TEXTDOMAIN
30 SOURCE_ROOT=/media/source
31 TARGET_ROOT=/mnt/target
32 LOG=/var/log/tazinst.log
33 LOCK=/run/tazinst.pid
34 BACKLIST="SliTaz GNU/Linux installer"
36 # DEBUG=1: Enable debug msgs
37 DEBUG=0
39 # Predefined urls
40 URL_STABLE="http://mirror.slitaz.org/iso/stable/slitaz-4.0.iso"
41 URL_COOKING="http://mirror.slitaz.org/iso/cooking/slitaz-cooking.iso"
42 URL_ROLLING="http://mirror.slitaz.org/iso/rolling/slitaz-core.iso"
44 # Tazinst conf
45 [ -r /etc/slitaz/tazinst.conf ] && . /etc/slitaz/tazinst.conf
47 # Print a short help
48 usage()
49 {
50 cat <<EOT
51 $(echo -e "\n$(gettext "Tazinst - SliTaz installer - Version"): $VERSION")
53 $(echo -e "\033[1m$(gettext "Usage"):\033[0m $(gettext "tazinst [command] [setup-file|url-shortcut]")")
55 $(echo -e "\033[1m$(gettext "Commands"): \033[0m")
56 usage|help $(gettext "Print this short usage.")
57 install <file> $(gettext "Install SliTaz on HDD using setup file contents.")
58 upgrade <file> $(gettext "Upgrade SliTaz on HDD using setup file contents.")
59 new <file> $(gettext "Create a new setup file.")
60 check <file> $(gettext "Check validity of settings in a setup file.")
61 showurl <shortcut> $(gettext "Show full URL of a predefined shortcut (stable|cooking|rolling).")
62 log $(gettext "Display log file contents and exit.")
63 version $(gettext "Print version and exit.")
64 EOT
65 exit 1
66 }
68 # Print an error msg & exit
69 # $1: exit code
70 # $@: err msg
71 abort()
72 {
73 # unmouting source & target
74 if mount | grep -q $SOURCE_ROOT; then
75 umount $SOURCE_ROOT 2>>$LOG
76 fi
77 if mount | grep -q $TARGET_ROOT; then
78 umount $TARGET_ROOT 2>>$LOG
79 fi
80 # rm lock
81 rm -f $LOCK
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 [ $DEBUG -gt 0 ] && echo "DEBUG: $1" >>$LOG
99 }
101 # Print a simple msg
102 msg()
103 {
104 STEP=$(($STEP+1))
105 echo "$STEP. $@" | tee -a $LOG
106 sleep 1
107 }
109 #######################
110 # New setup functions #
111 #######################
113 # Generate a setup file
114 # $1: Setup file
115 gen_setup()
116 {
117 SETUP=$1
118 [ -z "$1" ] && abort 1 "Missing <file> parameter for install configuration"
119 touch $SETUP || abort 2 $(gettext "Can't write setup file")
120 if [ -r "$SETUP" ]; then
121 cat > $SETUP << _EOF_
122 # SliTaz Installer setup file.
123 #
125 # Install type : [cdrom|usb|iso|web|weboot]
126 INST_TYPE="cdrom"
128 # Install source
129 # usb:/dev/xxx, ex: SRC_FILE=/dev/sdb1
130 # iso:file.iso, ex: SRC_FILE=~/slitaz.3.0.iso
131 # web: url, ex: SRC_FILE=http://mirror.slitaz.org/iso/cooking/slitaz-cooking.iso
132 # web: predefined mirrors (stable|cooking|rolling), ex: SRC_FILE=cooking
133 SRC_FILE=""
135 # Install Target (Root Partition, ex /dev/hda5).
136 TGT_PARTITION=""
138 # Target File system.
139 # SliTaz uses ext3 by default but another filesystem can be used if wanted,
140 # for this please adjust your /etc/fstab after installation. Valid options are:
141 # (btrfs|ext2|ext3|ext4|fat16|fat32|hfs|hfs+|jfs|ntfs|reiser4|reiserfs|ufs|xfs)
142 TGT_FS="ext3"
144 # Home partition.
145 # On most GNU/Linux systems users personal files are stored in the directory
146 # /home. Home can be on another hard disk or on a separate partition.
147 TGT_HOME=""
148 # Home File system (if /home is on a separate partition)
149 TGT_HOME_FS=""
151 # Hostname
152 TGT_HOSTNAME="slitaz"
154 # root password
155 # The root administrator privilege lets you manage and configure the full
156 # system. A root user can damage your system so you should always setup a
157 # strong password with special characters and/or numbers.
158 TGT_ROOT_PWD="root"
160 # The default user for the system will have his personal files stored
161 # in /home/*user* (and will be automatically added to the audio group).
162 TGT_USER="tux"
163 TGT_USER_PWD=""
165 # Grub bootloader
166 # install grub [yes|no]
167 TGT_GRUB="no"
169 # Windows dual-boot
170 # Dual boot is disabled if WINBOOT is empty: TGT_WINBOOT=""
171 # You may let tazinst find your win partition, mode=auto: TGT_WINBOOT="auto"
172 # or use manual setting: "hd[disk],[partition]" ex:TGT_WINBOOT=hd0,0
173 TGT_WINBOOT=""
175 _EOF_
176 echo "$(ls $1)" $(gettext "created.")
177 else
178 abort 2 $(gettext "Setup file not found")
179 fi
180 }
182 ######################
183 # Checking functions #
184 ######################
186 # def values and start log
187 # $@ :
188 init()
189 {
190 # Check if another instance of tazinst is running
191 if [ -e "$LOCK" ]; then
192 echo $(gettext "Another instance of tazinst is running.")
193 exit 7
194 else
195 echo $$ > $LOCK
196 fi
198 echo "=== Tazinst: start at `date` ===" >$LOG
199 echo "Command: $0 $@" >>$LOG
200 debug $(fdisk -l | grep \/dev)
202 # Default Type
203 INST_TYPE=cdrom
204 # Default Hostname.
205 TGT_HOSTNAME=slitaz
206 # Default root passwd
207 TGT_ROOT_PWD=root
208 # Default user
209 TGT_USER=tux
210 # Default Grub Install
211 TGT_GRUB=no
212 }
214 # Read setup
215 # $1: setup file
216 read_setup_file()
217 {
218 SETUP=$1
219 if [ -n "$SETUP" ]; then
220 if [ -r "$SETUP" ]; then
221 debug "Using setup-file=$SETUP"
222 # source doesn't like file without a path
223 [ $(echo "$SETUP" | grep -c "/") == "0" ] && SETUP="./$SETUP"
224 source $SETUP || abort 2 $(gettext "Unable to read setup file")
225 else
226 abort 2 $(gettext "Setup file not found")
227 fi
228 else
229 abort 2 $(gettext "No setup file provided")
230 fi
231 }
233 # check main vars
234 check_vars()
235 {
236 # error handling
237 local error=no
238 local found=no
239 local partition=""
241 debug "--- Tazinst main options ---"
242 debug "action=$INST_ACTION"
243 debug "type=$INST_TYPE"
244 debug "source=$SRC_FILE"
245 debug "/ partition=$TGT_PARTITION"
246 debug "/ filesystem=$TGT_FS"
247 debug "/home partition=$TGT_HOME"
248 debug "/home filesystem=$TGT_HOME_FS"
249 debug "hostname=$TGT_HOSTNAME"
250 debug "root-pwd=$TGT_ROOT_PWD"
251 debug "user=$TGT_USER"
252 debug "user-pwd=$TGT_USER_PWD"
253 debug "grub=$TGT_GRUB"
254 debug "winboot=$TGT_WINBOOT"
255 debug "--------------------------------------"
257 # Check Action
258 case $INST_ACTION in
259 install|upgrade|check) ;;
260 *) msg "$INST_ACTION: $(gettext "Unknown install mode")"; error=yes ;;
261 esac
263 # Check Type
264 case $INST_TYPE in
265 cdrom|weboot) ;;
266 usb|iso|web)
267 # We need a valid source
268 if [ -z "$SRC_FILE" ]; then
269 msg "$INST_TYPE: $(gettext "No source file provided")"; error=yes
270 fi ;;
271 *) msg "$INST_TYPE: $(gettext "Unknown source type")"; error=yes ;;
272 esac
274 # Check Source file
275 # 1. assign predefs
276 if [ "$INST_TYPE" == "web" ]; then
277 [ "$SRC_FILE" == "stable" ] && SRC_FILE=$URL_STABLE
278 [ "$SRC_FILE" == "cooking" ] && SRC_FILE=$URL_COOKING
279 [ "$SRC_FILE" == "rolling" ] && SRC_FILE=$URL_ROLLING
280 fi
281 # 2. check avail.
282 case $INST_TYPE in
283 iso)
284 if [ ! -r "$SRC_FILE" ]; then
285 msg "$SRC_FILE: $(gettext "Source file not found")"; error=yes
286 fi ;;
287 web)
288 if ! wget -sq "$SRC_FILE" 2> /dev/null ; then
289 msg "$SRC_FILE: $(gettext "URL not found")"; error=yes
290 fi ;;
291 esac
293 # Check Target Partition
294 found=no
295 LIST_PARTITION=$(fdisk -l | awk '/^\/dev/{printf "%s ",$1}')
296 for partition in $LIST_PARTITION; do
297 [ "$partition" == "$TGT_PARTITION" ] && found="yes"
298 done
299 if [ "$found" != "yes" ]; then
300 msg "$TGT_PARTITION: $(gettext "Partition for / not found")"; error=yes
301 fi
302 if [ "$TGT_PARTITION" == "$SRC_FILE" ]; then
303 msg $(gettext "Target and source partitions should be different"); error=yes
304 fi
306 # Check Filesystem
307 case $TGT_FS in
308 "") ;;
309 btrfs|ext2|ext3|ext4|fat16|fat32|hfs|hfs+|jfs|ntfs|reiser4|reiserfs|ufs|xfs)
310 found=no
311 for xdir in /sbin /usr/sbin /usr/bin; do
312 [ -x "$xdir/mkfs.$TGT_FS" ] && found=yes
313 done
314 if [ "$found" == "no" ]; then
315 msg "$TGT_FS: mkfs.$TGT_FS $(gettext "is not installed")"; error=yes
316 fi ;;
317 *) msg "$TGT_FS: $(gettext "Unknown filesystem (/)")"; error=yes ;;
318 esac
320 # Check Home partition
321 if [ -n "$TGT_HOME" ]; then
322 found=no
323 for partition in $LIST_PARTITION; do
324 [ "$partition" == "$TGT_HOME" ] && found=yes
325 done
326 if [ "$found" != "yes" ]; then
327 msg "$TGT_HOME: $(gettext "Partition for /home not found")"; error=yes
328 fi
329 if [ "$TGT_HOME" == "$SRC_FILE" ]; then
330 msg $(gettext "/home and source partitions should be different"); error=yes
331 fi
332 if [ "$TGT_HOME" == "$TGT_PARTITION" ]; then
333 msg $(gettext "/ and /home partitions should be different"); error=yes
334 fi
335 fi
337 # Check Home Filesystem
338 case $TGT_HOME_FS in
339 "") ;;
340 btrfs|ext2|ext3|ext4|fat16|fat32|hfs|hfs+|jfs|ntfs|reiser4|reiserfs|ufs|xfs)
341 found=no
342 for xdir in /sbin /usr/sbin /usr/bin; do
343 [ -x "$xdir/mkfs.$TGT_HOME_FS" ] && found=yes
344 done
345 if [ "$found" == "no" ]; then
346 msg "$TGT_FS: mkfs.$TGT_HOME_FS $(gettext "is not installed")"; error=yes
347 fi ;;
348 *) msg "$TGT_HOME_FS: $(gettext "Unknown filesystem (/home)")"; error=yes ;;
349 esac
351 # Check Grub
352 case $TGT_GRUB in
353 yes|no) ;;
354 *) msg $(gettext "Bootloader (grub): Invalid settings"); error=yes ;;
355 esac
357 # Check Winboot
358 case $TGT_WINBOOT in
359 "") ;;
360 auto) ;;
361 hd[[:digit:]],[[:digit:]]) ;;
362 *) msg $(gettext "Windows Dual-Boot: Invalid settings"); error=yes ;;
363 esac
365 # Stop on error
366 [ "$error" == "yes" ] && abort 1
367 }
369 # Exit install if user is not root.
370 check_root()
371 {
372 if test $(id -u) != 0 ; then
373 gettext "You must be the root user (system administrator) to install SliTaz, \
374 please use 'su' to get a root SHell and restart installation."
375 exit 0
376 fi
377 }
379 # Mount cdrom
380 check_cdrom()
381 {
382 # Set device name
383 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3` [ -n "$DRIVE_NAME" ] || DRIVE_NAME=cdrom
384 CDROM=/dev/$DRIVE_NAME
385 # Try to mount a cdrom
386 if mount -t iso9660 $CDROM $SOURCE_ROOT 2>>$LOG; then
387 debug "Using files from cdrom ($CDROM)..."
388 sleep 2
389 else
390 warning "$CDROM: $(gettext "Mount failed")"
391 fi
392 }
394 # Link LiveUSB
395 check_usb()
396 {
397 # /home is on USB dev
398 if [ -d /home/boot ]; then
399 debug "Using files from USB device..."
400 ln -s /home/boot $SOURCE_ROOT/boot
401 SOURCE_STATUS="link"
402 sleep 2
403 else
404 # Try to mount LiveUSB
405 if mount $SRC_FILE $SOURCE_ROOT 2>>$LOG; then
406 debug "Using files from USB device ($SRC_FILE)..."
407 SOURCE_STATUS="mount"
408 else
409 warning "$SRC_FILE: $(gettext "Failed to mount USB device")"
410 fi
411 fi
412 }
414 # Mount ISO file
415 check_iso()
416 {
417 local src_md5
418 # Integrity check
419 src_md5=$(echo $SRC_FILE | sed 's/.iso$/.md5/')
420 if [ -r "$src_md5" ]; then
421 [ $(md5sum $SRC_FILE | cut -d' ' -f1) == $(cat "$src_md5" | cut -d' ' -f1) ] || \
422 abort 3 "$SRC-FILE: $(gettext "md5sum mismatch, file corrupted")"
423 else
424 warning "$SRC_FILE: $(gettext "md5 file not found, unable to check integrity.")"
425 fi
426 # Try to mount ISO
427 if mount -o loop -t iso9660 $SRC_FILE $SOURCE_ROOT 2>>$LOG; then
428 debug "Using files from ISO ($SRC_FILE)..."
429 sleep 2
430 else
431 warning "$SRC_FILE: $(gettext "Failed to mount ISO.")"
432 fi
433 }
435 # Source is on the web
436 check_web()
437 {
438 local src_md5
439 debug "Downloading $SRC_FILE"
440 if wget $SRC_FILE -P /tmp; then
441 debug "Download completed."
442 else
443 warning "$SRC_FILE: $(gettext "File download failed.")"
444 fi
445 src_md5=$(echo $SRC_FILE | sed 's/.iso$/.md5/')
446 debug "Downloading $src_md5"
447 wget $src_md5 -P /tmp || warning "$src_md5: $(gettext "File download failed.")"
448 tmpfile=$(echo $SRC_FILE | awk 'BEGIN{RS="/"}{out=$1}END{printf"%s",out}')
449 SRC_FILE="/tmp/$tmpfile"
450 check_iso
451 }
453 # We may be in Tiny Web boot mode
454 check_weboot()
455 {
456 if [ -d $SRC_FILE/boot ]; then
457 debug "Using files from HTTP device..."
458 ln -s $SRC_FILE/boot $SOURCE_ROOT/boot
459 sleep 2
460 else
461 abort 3 $(gettext "Web boot files not found")
462 fi
463 }
465 # set up source and check Slitaz' content
466 check_source()
467 {
468 debug "Creating mount point ($SOURCE_ROOT)..."
469 mkdir -p $SOURCE_ROOT
470 sleep 1
471 case $INST_TYPE in
472 cdrom)
473 check_cdrom ;;
474 usb)
475 check_usb ;;
476 iso)
477 check_iso ;;
478 web)
479 check_web ;;
480 weboot)
481 check_cdrom
482 check_web ;;
483 *)
484 abort 8 $(gettext "Internal") ;;
485 esac
487 # Exit with error msg if no rootfs.gz found.
488 debug "Checking installation media..."
489 if [ ! -f $SOURCE_ROOT/boot/rootfs.gz -a \
490 ! -f $SOURCE_ROOT/boot/rootfs1.gz ]; then
491 abort 3 $(gettext "Invalid source")
492 else
493 debug "Installation media checked ok"
494 fi
495 }
497 #######################
498 # Installer functions #
499 #######################
501 # Mount and mkfs with progress.
502 prepare_install()
503 {
504 debug "Preparing target partition..."
505 # Target may be used
506 mount | grep -q $TGT_PARTITION && \
507 abort 5 "$TGT_PARTITION: $(gettext "Partition in use")"
508 # Mount point can be already used.
509 if mount | grep -q $TARGET_ROOT; then
510 umount $TARGET_ROOT 2>>$LOG
511 fi
512 sleep 2
514 # Formatting root partition
515 case $TGT_FS in
516 "")
517 debug "The partition ($TGT_PARTITION) will be cleaned..."
518 # ROOT_FS=$(parted /dev/hda5 print -m | grep "^1:" | cut -d':' -f5) ;;
519 ROOT_FS=auto ;;
520 *)
521 msg "$(gettext "Formatting / partition:") $TGT_PARTITION ($TGT_FS)"
522 mkfs.$TGT_FS $TGT_PARTITION >>$LOG 2>>$LOG
523 ROOT_FS=$TGT_FS ;;
524 esac
525 sleep 2
527 # Formatting /home
528 if [ -n "$TGT_HOME" ]; then
529 case $TGT_HOME_FS in
530 "")
531 debug "The partition ($TGT_HOME) will be kept..." ;;
532 *)
533 msg "$(gettext "Formatting /home partition:") $TGT_HOME ($TGT_HOME_FS)"
534 mkfs.$TGT_HOME_FS -L "Home" $TGT_HOME >>$LOG 2>>$LOG ;;
535 esac
536 sleep 2
537 fi
539 # Mount target.
540 debug "Creating mount point: $TARGET_ROOT"
541 mkdir -p $TARGET_ROOT >>$LOG
542 sleep 2
544 mount -t $ROOT_FS $TGT_PARTITION $TARGET_ROOT >>$LOG 2>>$LOG
545 if [ $(mount | grep -c "mnt/target") == "0" ]; then
546 abort 5 "$TGT_PARTITION: $(gettext "Unable to mount partition")"
547 fi
548 }
550 # Get a clean target device (15%).
551 clean_target()
552 {
553 if [ -z "$TGT_FS" ]; then
554 # partition was not formatted
555 debug "Cleaning the root partition ($TGT_PARTITION)..."
556 # Keep /home in case of reinstall.
557 cd $TARGET_ROOT || abort 8 $(gettext "Internal")
558 for dir in *
559 do
560 case "$dir" in
561 home)
562 debug "keeping /home found on: $TGT_PARTITION"
563 mv home home.bak ;;
564 lost+found)
565 continue ;;
566 *)
567 debug "removing target: $dir"
568 rm -rf $dir 2>>$LOG ;;
569 esac
570 done
571 if [ -d mklost+found ]; then
572 mklost+found 2>>$LOG
573 fi
574 fi
575 sleep 2
576 }
578 # Kernel is renamed to standard vmlinuz-$VERSION.
579 install_kernel()
580 {
581 if [ -d /$TARGET_ROOT/lib/modules ]; then
582 KERNEL=$(ls /$TARGET_ROOT/lib/modules | tail -1)
583 KERNEL="vmlinuz-$KERNEL"
584 else
585 KERNEL=vmlinuz-`uname -r`
586 warning "$(gettext "Kernel name not found, falling back to:") $(uname -r)"
587 fi
588 mkdir -p $TARGET_ROOT/boot
589 cp $SOURCE_ROOT/boot/bzImage $TARGET_ROOT/boot/$KERNEL
590 debug "install_kernel: $KERNEL"
591 sleep 2
592 }
594 # Copy isolinux r/w files (not syslinux, some files are read only).
595 copy_bootloaders()
596 {
597 if [ -d "$SOURCE/ROOT/boot/isolinux" ]; then
598 debug "Copy isolinux r/w files"
599 mkdir -p $TARGET_ROOT/boot/isolinux
600 cp -a $SOURCE_ROOT/boot/isolinux/*.cfg $TARGET_ROOT/boot/isolinux
601 cp -a $SOURCE_ROOT/boot/isolinux/*.kbd $TARGET_ROOT/boot/isolinux
602 cp -a $SOURCE_ROOT/boot/isolinux/*.txt $TARGET_ROOT/boot/isolinux
603 cp -a $SOURCE_ROOT/boot/isolinux/*.bin $TARGET_ROOT/boot/isolinux
604 cp -a $SOURCE_ROOT/boot/isolinux/*.msg $TARGET_ROOT/boot/isolinux
605 cp -a $SOURCE_ROOT/boot/isolinux/*.lss $TARGET_ROOT/boot/isolinux
606 cp -a $SOURCE_ROOT/boot/isolinux/*.c32 $TARGET_ROOT/boot/isolinux
607 fi
608 # GRUB splash image
609 if [ -f "$SOURCE_ROOT/boot/grub/splash.xpm.gz" ]; then
610 debug "Copy GRUB splash image"
611 mkdir -p $TARGET_ROOT/boot/grub
612 $SOURCE_ROOT/boot/grub/splash.xpm.gz $TARGET_ROOT/boot/grub
613 fi
614 }
616 need_package()
617 {
618 [ -d /var/lib/tazpkg/installed/$1 ] || tazpkg get-install $1
619 }
621 # extract packed rootfs: squashfs or cromfs
622 extract_loramfs()
623 {
624 local i
625 for i in $(cpio -idvum 2> /dev/null); do
626 case "$i" in
627 rootfs*)
628 need_package squashfs
629 if ! unsquashfs $i ; then
630 need_package cromfs
631 unmkcromfs $i squashfs-root
632 fi
633 mv -f squashfs-root/* .
634 rmdir squashfs-root
635 rm -f $i
636 esac
637 done
638 }
640 # This is a loram rootfs.gz, skip loram bootstrap and extract
641 extract_first_loramfs()
642 {
643 (zcat $1 || unlzma -c $1) | cpio -i extractfs.cpio 2> /dev/null &&
644 ( cd / ; cpio -id ) < extractfs.cpio && rm -f extractfs.cpio
645 ofs=$(awk '/07070100/ { o+=index($0,"07070100"); printf "%d\n",o/4 ; exit } { o+=1+length() }' < $1)
646 dd if=$1 skip=$(($ofs / 1024)) bs=4k count=1 2> /dev/null | \
647 ( dd skip=$(($ofs % 1024)) bs=4 2> /dev/null ; \
648 dd if=$1 skip=$((1 + ($ofs / 1024) )) bs=4k ) | extract_loramfs
649 }
651 # Extract lzma'ed or gziped rootfs.
652 extract_rootfs()
653 {
654 local isloramfs
655 isloramfs=
656 cd $TARGET_ROOT || abort 8 $(gettext "Internal")
657 if [ -d $1/../fs/etc ]; then
658 # This is a tazlitobox loram (cdrom)
659 cp -a $1/../fs/. .
660 else
661 for i in $(ls $1/rootfs* | sort -r); do
662 if [ ! -d etc ]; then
663 if [ $( (zcat $i 2>/dev/null || lzma d $i -so) | wc -c) \
664 -lt $(stat -c %s $i) ]; then
665 # This is a tazlitobox loram (ram)
666 isloramfs=$i
667 extract_first_loramfs $i
668 continue
669 fi
670 fi
671 if [ -n "$isloramfs" ]; then
672 extract_loramfs < $i
673 continue
674 fi
675 ( zcat $i 2>/dev/null || lzma d $i -so || \
676 cat $i ) 2>>$LOG | cpio -idu
677 done 2>>$LOG > /dev/null
678 fi
679 cp /etc/keymap.conf etc
680 # unpack /usr (double check...)
681 if ls etc/tazlito | grep -q ".extract"; then
682 for i in etc/tazlito/*.extract; do
683 [ -f "$i" ] && . $i /media/cdrom
684 done
685 fi
686 }
688 # Pre configure freshly installed system (60 - 80%).
689 pre_config_system()
690 {
691 cd $TARGET_ROOT || abort 8 $(gettext "Internal")
692 # Restore backup of existing /home if exists.
693 # (created by prepare_target_dev)
694 if [ -d home.bak ]; then
695 debug "Restoring directory: /home..."
696 rm -rf home
697 mv home.bak home
698 sleep 1
699 fi
700 # Add root device to CHECK_FS in rcS.conf to check filesystem
701 # on each boot.
702 debug "Adding $TGT_PARTITION and CHECK_FS to file /etc/rcS.conf..."
703 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$TGT_PARTITION\""# etc/rcS.conf
704 sleep 2
705 # Set hostname.
706 msg "$(gettext "Configuring host name:") $TGT_HOSTNAME"
707 echo $TGT_HOSTNAME > etc/hostname
708 }
710 # Set root passwd and create user after rootfs extraction.
711 users_settings()
712 {
713 cat > $TARGET_ROOT/users.sh << _EOF_
714 #!/bin/sh
715 echo "root:$TGT_ROOT_PWD" | chpasswd -m
716 adduser -D -H $TGT_USER
718 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
719 if ! grep \$grp /etc/group | grep -q $TGT_USER ; then
720 grep -q \$grp /etc/group && addgroup $TGT_USER \$grp
721 fi
722 done
724 echo "$TGT_USER:$TGT_USER_PWD" | chpasswd -m
725 if [ ! -d /home/$TGT_USER ]; then
726 cp -a /etc/skel /home/$TGT_USER
727 [ -e /root/.xinitrc ] && cp /root/.xinitrc /home/$TGT_USER
728 mkdir -p /home/$TGT_USER/.config/slitaz
729 cp -a /etc/slitaz/applications.conf /home/$TGT_USER/.config/slitaz
730 # Set ownership
731 if grep -q ^users: /etc/group; then
732 chown -R $TGT_USER:users /home/$TGT_USER
733 else
734 chown -R $TGT_USER:$TGT_USER /home/$TGT_USER
735 fi
736 # Path for user desktop files.
737 for i in /home/$TGT_USER/.local/share/applications/*.desktop
738 do
739 [ -e "$i" ] && sed -i s/"user_name"/"$TGT_USER"/g \$i
740 done
741 fi
742 # Slim default user.
743 if [ -f /etc/slim.conf ]; then
744 sed -i s/"default_user .*"/"default_user $TGT_USER"/ \
745 /etc/slim.conf
746 fi
747 _EOF_
748 chmod +x $TARGET_ROOT/users.sh
749 chroot $TARGET_ROOT ./users.sh
750 rm $TARGET_ROOT/users.sh
751 sleep 2
752 }
754 # /home can be on a separate partition. If default user exists in /home
755 # we remove default file created by users_settings().
756 home_config()
757 {
758 debug "home_config: $TGT_HOME"
759 cd $TARGET_ROOT || abort 8 $(gettext "Internal")
760 mv home/$TGT_USER tmp
761 mount $TGT_HOME home
762 if [ -d $TARGET_ROOT/home/$TGT_USER ]; then
763 rm -rf tmp/$TGT_USER
764 else
765 mv tmp/$TGT_USER home
766 fi
767 echo "$TGT_HOME /home ext3 defaults 0 2" \
768 >> etc/fstab
769 umount home
770 }
772 # Search for a Windows partition
773 win_partition()
774 {
775 debug "Searching for Windows"
776 if [ "$TGT_WINBOOT" == "auto" ];then
777 WINBOOT=$(fdisk -l | awk '
778 BEGIN{
779 disk=-1
780 found=0
781 winboot=""}
782 {
783 # Count disks
784 if ($1=="Disk"){
785 disk++
786 part=-1
787 dev=substr($2,6,3)
788 # get removable status
789 file="/sys/block/"dev"/removable"
790 "cat " file | getline removable
791 close("cat ")
792 }
793 # Count partitions
794 if (substr($1,1,4)=="/dev"){
795 # List fixed drives only
796 if (removable==0){
797 part++
798 # Read partition Id
799 if ($2=="*"){Id=$6} else {Id=""}
800 # Detect Windows Partition Type: 7,b,c,e,f
801 WPT="[7bcef]"
802 if (Id ~ WPT){
803 found++
804 # record 1st Windows partition found
805 if (found==1){
806 winboot=sprintf("hd%d,%d",disk,part)
807 }
808 }
809 }
810 }
811 }
812 END{printf "%s", winboot}')
813 if [ -z "$WINBOOT" ]; then
814 warning $(gettext "No windows partition found. Dual-boot disabled")
815 TGT_WINBOOT=""
816 fi
817 fi
818 }
820 # Determine GRUB partition number and GRUB disk number.
821 grub_partition()
822 {
823 DISK_LETTER=${TGT_PARTITION#/dev/[h-s]d}
824 DISK_LETTER=${DISK_LETTER%[0-9]}
825 GRUB_PARTITION=$((${TGT_PARTITION#/dev/[h-s]d[a-z]}-1))
826 for disk in a b c d e f g h
827 do
828 nb=$(($nb+1))
829 if [ "$disk" = "$DISK_LETTER" ]; then
830 GRUB_DISK=$(($nb-1))
831 break
832 fi
833 done
834 GRUB_ROOT="(hd${GRUB_DISK},${GRUB_PARTITION})"
835 }
837 # Create grub conf
838 grub_config()
839 {
840 grub_partition
841 if [ "$TGT_GRUB" == "yes" ]; then
842 win_partition
843 fi
844 # Create the target GRUB configuration.
845 mkdir -p $TARGET_ROOT/boot/grub
846 cat > $TARGET_ROOT/boot/grub/menu.lst << _EOF_
847 # /boot/grub/menu.lst: GRUB boot loader configuration.
848 #
850 # By default, boot the first entry.
851 default 0
853 # Boot automatically after 8 secs.
854 timeout 8
856 # Graphical splash image.
857 splashimage=/boot/grub/splash.xpm.gz
859 # Change the colors.
860 #color yellow/brown light-green/black
862 # For booting SliTaz from : $TGT_PARTITION
863 #
864 title SliTaz GNU/Linux (cooking) (Kernel $KERNEL)
865 root $GRUB_ROOT
866 kernel /boot/$KERNEL root=$TGT_PARTITION quiet
868 _EOF_
869 if [ -n "$TGT_WINBOOT" ]; then
870 msg $(gettext "Enabling Windows dual-boot")
871 cat >> $TARGET_ROOT/boot/grub/menu.lst << _EOF_
872 # For booting Windows :
873 #
874 title Microsoft Windows
875 rootnoverify ($WINBOOT)
876 chainloader +1
878 _EOF_
879 fi
880 # log
881 debug "grub_config: $TARGET_ROOT/boot/grub/menu.lst"
882 echo "--- menu.lst -------------" >>$LOG
883 cat $TARGET_ROOT/boot/grub/menu.lst >>$LOG
884 echo "--- menu.lst -------------" >>$LOG
885 sleep 2
886 }
888 # Files install, calling for functions or with cmds.
889 install_files()
890 {
891 msg "$(gettext "Installing SliTaz on:") $TGT_PARTITION"
892 # saving pwd
893 local save_pwd=$(pwd)
895 debug "Cleaning the root partition if necessary..."
896 clean_target
898 debug "Extracting the root system..."
899 extract_rootfs $SOURCE_ROOT/boot
901 debug "Installing the kernel..."
902 install_kernel
904 debug "Copying the bootloader syslinux/isolinux..."
905 copy_bootloaders
907 debug "Preconfiguring the system..."
908 pre_config_system
910 msg "$(gettext "Configuring root and default user account:") $TGT_USER"
911 users_settings
913 if [ "$TGT_HOME" != "" ]; then
914 msg "$(gettext "Configuring partition to be used as /home:") $TGT_HOME"
915 home_config
916 sleep 2
917 fi
919 debug "Creating configuration file for GRUB (menu.lst)..."
920 grub_config
922 debug "Files installation completed"
923 sleep 2
924 # restoring pwd
925 cd $save_pwd
926 }
928 # GRUB info with disk name used for grub-install.
929 grub_install()
930 {
931 if [ "$TGT_GRUB" == "yes" ]; then
932 TARGET_DISK=`echo $TGT_PARTITION | sed s/"[0-9]"/''/`
933 msg "$(gettext "Running grub-install on:") $TARGET_DISK"
934 grub-install --no-floppy \
935 --root-directory=$TARGET_ROOT $TARGET_DISK 2>>$LOG
936 debug "Grub installation done..."
937 else
938 debug "Grub not installed"
939 fi
940 }
942 # Copy log file, umount target and eject cdrom.
943 umount_devices()
944 {
945 # Umount target
946 if mount | grep -q $TARGET_ROOT; then
947 echo "$(gettext "Unmounting target partition:") $TGT_PARTITION"
948 umount $TARGET_ROOT 2>>$LOG
949 fi
951 # Umount source
952 if mount | grep -q $SOURCE_ROOT; then
953 echo "$(gettext "Unmounting:") $SOURCE_ROOT"
954 umount $SOURCE_ROOT
955 fi
957 # Eject cd
958 if [ "$INST_TYPE" == "cdrom" ]; then
959 gettext "Ejecting cdrom..."
960 eject
961 fi
962 # Remove lock file
963 rm -f $LOCK
964 sleep 2
965 }
967 # End of installation.
968 end_of_install()
969 {
970 msg $(gettext "Installation complete. You can now restart (reboot)")
971 echo " $(gettext "from your SliTaz GNU/Linux system.")"
972 echo "=== Tazinst end at `date` ===" >>$LOG
973 # Log files
974 echo "$(gettext "Copying log files") ($LOG)..."
975 cp -a $LOG $TARGET_ROOT/var/log
976 sleep 2
977 # umount
978 umount_devices
979 }
981 #####################
982 # Upgrade functions #
983 #####################
985 # Mount.
986 prepare_upgrade()
987 {
988 debug "Preparing the target partition..."
989 # Target may be used
990 mount | grep -q $TGT_PARTITION && \
991 abort 5 "$TGT_PARTITION: $(gettext "Partition in use")"
992 # Mount point can be already used.
993 if mount | grep -q $TARGET_ROOT; then
994 umount $TARGET_ROOT 2>>$LOG
995 fi
996 mkdir -p $TARGET_ROOT && sleep 2
997 # Mount target.
998 mount $TGT_PARTITION $TARGET_ROOT >>$LOG 2>>$LOG
999 if [ $(mount | grep -c "mnt/target") == "0" ]; then
1000 abort 5 "$TGT_PARTITION $(gettext "Unable to mount partition")"
1001 fi
1004 # Check for a valid SliTaz
1005 check_release()
1007 if [ -f $TARGET_ROOT/etc/slitaz-release ]; then
1008 release=`cat $TARGET_ROOT/etc/slitaz-release`
1009 msg "$(gettext "Preparing upgrade of SliTaz release:") $release"
1010 else
1011 abort 6 "$TGT_PARTITION: $(gettext "This partition doesn't appear to contain \
1012 a valid SliTaz system, the file: /etc/slitaz-release doesn't exist.")"
1013 fi && sleep 2
1016 # Backup target packages list.
1017 backup_files()
1019 cd $TARGET_ROOT || abort 8 $(gettext "Internal")
1020 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
1021 for dir in *
1022 do
1023 case "$dir" in
1024 boot)
1025 rm -rf boot/vmlinuz-* ;;
1026 home)
1027 mv home home.bak
1028 debug "keeping /home found on: $TGT_PARTITION" ;;
1029 etc)
1030 tar czf etc.tar.gz etc
1031 mv etc etc.bak
1032 debug "keeping /etc found on: $TGT_PARTITION" ;;
1033 var)
1034 if [ -d var/www ]; then
1035 mv var/www www.bak
1036 debug "keeping /var/www found on: $TGT_PARTITION"
1037 fi
1038 rm -rf var 2>>$LOG ;;
1039 lost+found)
1040 continue ;;
1041 *)
1042 debug "removing target: $dir"
1043 rm -rf $dir 2>>$LOG ;;
1044 esac
1045 done
1046 if [ -d mklost+found ]; then
1047 mklost+found 2>>$LOG
1048 fi
1049 sleep 2
1052 # Restore backups.
1053 restore_files()
1055 rm -rf $TARGET_ROOT/home
1056 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
1057 rm -rf $TARGET_ROOT/etc
1058 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
1059 if [ -d $TARGET_ROOT/www.bak ]; then
1060 rm -rf $TARGET_ROOT/var/www
1061 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
1062 fi
1063 debug "backups restored: `date`"
1065 # /var/lib/slitaz-installer
1066 mkdir -p $TARGET_ROOT/var/lib/tazinst
1067 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/tazinst
1068 mv $TARGET_ROOT/home/packages-selection.list $TARGET_ROOT/var/lib/tazinst
1071 # Added pkgs
1072 install_pkgs()
1074 # Check if the pkg is on the mirror.
1075 debug "Checking the availability of packages..."
1076 touch packages-to-install.list
1077 packages=0
1078 diff=`cat packages-selection.diff | sort`
1079 for pkg in $diff
1080 do
1081 if grep -q ^$pkg-[0-9] /var/lib/tazpkg/packages.list; then
1082 packages=$(($packages+1))
1083 echo "$pkg" >> packages-to-install.list
1084 fi
1085 done
1087 # Install packages.
1088 debug "Installing any packages..."
1089 sleep 2
1090 if [ "$packages" == "0" ]; then
1091 debug "packages to install: 0"
1092 else
1093 # Get-install all missing pkgs.
1094 for pkg in `cat packages-to-install.list`
1095 do
1096 debug "Installing: $pkg..."
1097 # Get install package and answer yes in case of dependencies.
1098 pkgname=`grep ^$pkg /var/lib/tazpkg/packages.list`
1099 tazpkg get $pkg >/dev/null 2>/dev/null
1100 yes "" | tazpkg install $pkgname.tazpkg --root=$TARGET_ROOT >/dev/null 2>/dev/null
1101 rm -f $pkgname.tazpkg
1102 done
1103 fi
1104 debug "Installation of packages complete..."
1105 sleep 2
1108 # Search for added pkgs
1109 update_pkgs()
1111 cd $TARGET_ROOT/var/lib/tazinst || abort 8 $(gettext "Internal")
1112 # LiveCD packages list.
1113 debug "Creating package lists..."
1114 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-source.list || exit 1
1115 debug "packages-source.list: done"
1116 # Diff
1117 diff packages-source.list packages-selection.list | \
1118 grep ^+[a-z] | sed s/^+// > packages-selection.diff
1119 debug "packages-selection.diff: done"
1120 # Get mirror list.
1121 tazpkg recharge >>$LOG 2>>$LOG
1122 if [ -f /var/lib/tazpkg/packages.list ]; then
1123 install_pkgs
1124 else
1125 touch packages-to-install.list
1126 warning $(gettext "The list of available packages on the mirror could not be \
1127 downloaded. No missing packages will be reinstalled now, but \
1128 you can do so later by looking at the following list: \
1129 /var/lib/tazinst/packages-selection.diff")
1130 fi
1131 sleep 2
1134 # Update grub conf
1135 grub_update()
1137 # Backup and create a new grub menu.lst.
1138 if [ "$TGT_GRUB" == "yes" ]; then
1139 msg $(gettext "Grub update")
1140 mv $TARGET_ROOT/boot/grub/menu.lst \
1141 $TARGET_ROOT/boot/grub/menu.lst.bak 2>/dev/null
1142 grub_config
1143 fi
1146 # Prepare the partition to upgrade, backup, install, restore configs
1147 # and reinstall pkgs.
1148 upgrade_files()
1150 # saving pwd
1151 local save_pwd=$(pwd)
1152 cd $TARGET_ROOT || abort 8 $(gettext "Internal")
1154 debug "Searching for /etc/slitaz-release"
1155 check_release
1157 msg $(gettext "Backup /etc, /home and the packages list...")
1158 backup_files
1160 msg "$(gettext "Upgrading SliTaz on:") $TGT_PARTITION"
1162 debug "Copying the bootloader syslinux/isolinux..."
1163 copy_bootloaders
1165 debug "Extracting the root system..."
1166 extract_rootfs $SOURCE_ROOT/boot
1168 msg $(gettext "Restoring configuration files...")
1169 restore_files
1171 debug "Installing the kernel..."
1172 install_kernel
1174 msg $(gettext "Upgrading added packages...")
1175 update_pkgs
1177 # restoring pwd
1178 cd $save_pwd
1181 # End of system upgrade.
1182 end_of_upgrade()
1184 pkgscd=`cat $TARGET_ROOT/var/lib/tazinst/packages-source.list | wc -l`
1185 pkginst=`cat $TARGET_ROOT/var/lib/tazinst/packages-to-install.list | wc -l`
1186 msg $(gettext "Upgrade finished. You can now restart (reboot)")
1187 echo $(gettext "from your SliTaz GNU/Linux system.")
1188 echo "$(gettext "Packages on the cdrom :") $pkgscd"
1189 echo "$(gettext "Packages installed from the mirror :") $pkginst"
1190 echo "=== Tazinst end at `date` ===" >>$LOG
1191 umount_devices
1194 ######################
1195 # Installer sequence #
1196 ######################
1198 case $1 in
1199 install)
1200 INST_ACTION=install
1201 check_root
1202 init $@
1203 read_setup_file $2
1204 check_vars
1205 check_source
1206 prepare_install
1207 install_files
1208 grub_install
1209 end_of_install ;;
1210 upgrade)
1211 INST_ACTION=upgrade
1212 check_root
1213 init $@
1214 read_setup_file $2
1215 check_vars
1216 check_source
1217 prepare_upgrade
1218 upgrade_files
1219 grub_update
1220 end_of_upgrade ;;
1221 new)
1222 gen_setup $2 ;;
1223 showurl)
1224 LOG="/dev/null"
1225 case $2 in
1226 stable)
1227 echo $URL_STABLE ;;
1228 cooking)
1229 echo $URL_COOKING ;;
1230 rolling)
1231 echo $URL_ROLLING ;;
1232 *)
1233 abort 1 $(gettext "Unknown url shortcut")
1234 esac ;;
1235 check)
1236 LOG="/dev/null"
1237 INST_ACTION=check
1238 check_root
1239 init $@
1240 read_setup_file $2
1241 check_vars
1242 rm -f $LOCK ;;
1243 log)
1244 [ -r "$LOG" ] && cat $LOG ;;
1245 version)
1246 echo $VERSION ;;
1247 usage|*)
1248 usage ;;
1249 esac
1251 exit 0