slitaz-tools annotate installer/tazinst @ rev 618

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