tazinst annotate tazinst @ rev 0

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