tazinst annotate tazinst @ rev 116

tazinst: typo
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 09 15:11:39 2021 +0000 (2021-11-09)
parents 6b79681fa9ec
children
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@2 5 # few main variables, then all the functions and then the
domcox@0 6 # full sequence of functions.
domcox@0 7 #
al@68 8 # (C) 2007-2016 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@2 12
domcox@0 13 # Exit codes:
domcox@2 14 # 1: Parameters error
domcox@2 15 # 2: Install file error
domcox@0 16 # 3: Source error
domcox@2 17 # 4: Target error
paul@5 18 # 5: Missing resource
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@2 22 # 9: User cancellation
domcox@0 23
domcox@0 24
domcox@2 25 # path
domcox@2 26 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
domcox@2 27 umask 0177
domcox@2 28
al@68 29 # read SliTaz conf
domcox@2 30 [ -r /etc/slitaz/slitaz.conf ] && . /etc/slitaz/slitaz.conf
domcox@2 31
domcox@2 32 # read Tazinst conf
domcox@2 33 [ -r /etc/slitaz/tazinst.conf ] && . /etc/slitaz/tazinst.conf
domcox@2 34
domcox@2 35 # version
domcox@28 36 readonly VERSION=3.95
domcox@2 37
domcox@2 38 # i18n
al@73 39 . /lib/libtaz.sh
al@73 40 export TEXTDOMAIN='tazinst'
al@73 41
domcox@0 42
pascal@106 43 # common kernels arguments
pascal@106 44 readonly KERNEL_ARGS="video=-32 quiet"
pascal@106 45
domcox@2 46 # files
domcox@2 47 readonly DEFAULT_INSTALL_FILE=./tazinst.rc
domcox@2 48 readonly SOURCE_ROOT=/media/source
domcox@2 49 readonly TARGET_ROOT=/mnt/target
domcox@2 50 readonly LOG=/var/log/tazinst.log
domcox@2 51 readonly LOCK=/run/tazinst.pid
domcox@2 52 MIRRORS="${MIRRORS:-$LOCALSTATE/mirrors}"
domcox@0 53
domcox@2 54 # settings
domcox@2 55 readonly SETTINGS="mode media source \
domcox@2 56 root_uuid root_format home_uuid home_format \
domcox@2 57 hostname root_pwd user_login user_pwd \
pascal@112 58 bootloader liveboot webboot winboot"
domcox@0 59
domcox@2 60 # modes (key:help)
domcox@2 61 readonly LST_MODE="
al@73 62 install:$(_ 'Fresh install on a HDD')
al@73 63 upgrade:$(_ 'Upgrade an existing system')"
domcox@0 64
paul@5 65 # media (key:help)
domcox@2 66 readonly LST_MEDIA="
al@73 67 cdrom:$(_ 'LiveCD')
al@73 68 usb:$(_ 'LiveUSB')
al@73 69 iso:$(_ 'ISO image on a local drive')
al@73 70 web:$(_ 'ISO image on the Internet')"
domcox@0 71
domcox@2 72 # formats (key:help)
domcox@2 73 readonly LST_FORMAT="
al@73 74 btrfs:$(_ 'B-tree file system (Oracle)')
al@73 75 ext2:$(_ 'Second extended filesystem (Linux)')
al@73 76 ext3:$(_ 'Third extended filesystem (Linux)')
al@73 77 ext4:$(_ 'Fourth extended file system (Linux)')
al@73 78 jfs:$(_ 'Journaled File System (IBM)')
al@73 79 minix:$(_ 'File system of the MINIX operating system')
al@73 80 reiser4:$(_ 'Journaled computer file system (Namesys)')
al@73 81 xfs:$(_ 'Journaling file system (Silicon Graphics, Inc.)')"
domcox@2 82
domcox@2 83 # bootloaders (key:help)
domcox@2 84 readonly LST_BOOTLOADER="
al@73 85 auto:$(_ 'Automatic selection')
al@73 86 grub:$(_ 'GRUB legacy bootloader')
al@73 87 syslinux:$(_ 'Lightweight bootloader')"
domcox@2 88
domcox@2 89 # predefined iso (key:url:help)
domcox@2 90 SLITAZ_VERSION="${SLITAZ_VERSION:-cooking}"
pascal@98 91 [ "$SLITAZ_VERSION" = 'cooking' ] && SLITAZ_VERSION="$(($(date "+%y")-8)).0"
domcox@2 92 [ -n "$URL_ISO" ] && readonly LST_WEB="$URL_ISO" || readonly LST_WEB="
domcox@2 93 stable:iso/stable/slitaz-$SLITAZ_VERSION.iso \
al@73 94 :$(_ 'Stable release') $SLITAZ_VERSION
domcox@2 95 core:iso/stable/flavors/slitaz-$SLITAZ_VERSION-core.iso \
al@73 96 :$(_ 'Stable version without nested subsets')
domcox@2 97 base:iso/stable/flavors/slitaz-$SLITAZ_VERSION-base.iso \
al@73 98 :$(_ 'Stable text-only version (8.1MB)')
domcox@2 99 justx:iso/stable/flavors/slitaz-$SLITAZ_VERSION-justx.iso \
al@73 100 :$(_ 'Stable basic graphic version without graphic apps')
domcox@2 101 gtkonly:iso/stable/flavors/slitaz-$SLITAZ_VERSION-gtkonly.iso \
al@73 102 :$(_ 'Stable basic graphic version with only GTK')
domcox@2 103 cooking:iso/cooking/slitaz-cooking.iso \
al@73 104 :$(_ 'Development version for testing latest features')
domcox@2 105 rolling:iso/rolling/slitaz-rolling.iso \
al@73 106 :$(_ 'Bleeding edge development version updated every day')
domcox@2 107 "
domcox@2 108
domcox@2 109
domcox@2 110 #-------
domcox@2 111 # usage
domcox@2 112 #-------
domcox@2 113
domcox@2 114 # print a short help
domcox@0 115 usage()
domcox@0 116 {
al@73 117 _ 'SliTaz GNU/Linux Installer - Version: %s' "$VERSION"
al@73 118 newline; boldify "$(_ 'Usage:')"
al@73 119 echo -n ' '; _ '%s [command] <setting> <value> <file>' 'tazinst'
al@73 120 newline; boldify "$(_ 'Commands:')"
al@73 121 optlist "\
al@73 122 new $(_ 'Create a new install file.')
al@73 123 set $(_ 'Change value of a setting.')
al@73 124 unset $(_ 'Clear a setting.')
al@73 125 get $(_ 'Get the value of a setting.')
al@73 126 check $(_ 'Check settings.')
al@73 127 help $(_ 'Print a short help on settings')
al@73 128 list $(_ 'List system resources.')
al@73 129 execute $(_ 'Execute a SliTaz installation.')
al@73 130 log $(_ 'Display log file contents.')
al@73 131 clean $(_ 'Clean install and log files.')
al@73 132 version $(_ 'Print version and exit.')
al@73 133 usage $(_ 'Print this short usage.')
al@73 134 "
domcox@2 135 exit 0
domcox@0 136 }
domcox@0 137
domcox@2 138 usage_error()
domcox@0 139 {
domcox@12 140 local cmd="$1" script="$(basename $0)"
al@73 141 _ 'SliTaz GNU/Linux Installer - Version: %s' "$VERSION"
al@73 142 newline
al@73 143 _ "'%s': Unknown command!" "$cmd"
al@73 144
al@73 145 _ "Run: '%s' to get a list of available commands." "$script help"
domcox@12 146 exit 1
domcox@0 147 }
domcox@0 148
al@73 149
domcox@2 150 option_error()
domcox@0 151 {
domcox@2 152 local option="$1" list="$2"
al@73 153 _ 'SliTaz GNU/Linux Installer - Version: %s' "$VERSION"
al@73 154 newline
al@73 155 _ "'%s': Unknown option!" "$option"
al@73 156
al@73 157 _ 'Please select one of these options:'
al@73 158 printf " %s\n\n" "$list"
domcox@12 159 exit 1
domcox@0 160 }
domcox@0 161
domcox@2 162 #---------------------
domcox@2 163 # 1. settings section
domcox@2 164 #---------------------
domcox@2 165
domcox@2 166 #----------
domcox@2 167 # 1.1 file
domcox@2 168 #----------
domcox@2 169
domcox@2 170 # create a new install file
domcox@2 171 new_file()
domcox@0 172 {
domcox@2 173 local install_file=$1
domcox@2 174 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
domcox@2 175 if [ -e "$install_file" ]; then
al@73 176 _ 'Warning: file already exists.' 1>&2
domcox@2 177 exit 0
domcox@2 178 fi
domcox@2 179 [ -n "$install_file" ] && touch "$install_file"
domcox@2 180 if [ -w "$install_file" ]; then
domcox@2 181 write_file "$install_file"
domcox@2 182 else
al@73 183 _ 'Error: Cannot create file.' 1>&2
domcox@2 184 exit 2
domcox@2 185 fi
domcox@0 186 }
domcox@0 187
domcox@2 188 # fill up the install file
domcox@2 189 write_file()
domcox@0 190 {
domcox@2 191 local install_file="$1"
al@73 192 cat > "$install_file" <<EOT
domcox@12 193 # SliTaz GNU/Linux Installer - Version: $VERSION
domcox@2 194 #
domcox@12 195 # Install file.
domcox@0 196 #
domcox@0 197
domcox@2 198 # Mode of installation:
domcox@2 199 # install: Full install of SliTaz on a disk, all previous info will be erased
domcox@2 200 # upgrade: Upgrade an existing SliTaz installation to a new version
domcox@2 201 # run 'tazinst list mode' to have a full list.
domcox@2 202 MODE="$MODE"
domcox@0 203
domcox@2 204 # Media to install from:
domcox@2 205 # Options are cdrom usb iso web.
domcox@2 206 # run 'tazinst list media' to see available options on your system.
domcox@2 207 MEDIA="$MEDIA"
domcox@0 208
domcox@2 209 # Install source:
domcox@2 210 # it depends on the media used:
domcox@2 211 # usb: partition, run 'tazinst list uuid' to list your partitions
domcox@2 212 # iso: file.iso, ex: SOURCE=~/slitaz.5.0.iso
domcox@2 213 # web: url, ex: SOURCE=http://mirror.slitaz.org/../slitaz-cooking.iso
domcox@2 214 # web: iso names, ex: SOURCE=cooking
domcox@2 215 # run 'tazinst list <MEDIA>' to list source values. ex: tazinst list iso.
domcox@2 216 SOURCE="$SOURCE"
domcox@0 217
domcox@2 218 # root partition that SliTaz will be Installed on:
domcox@2 219 # Enter the UUID of the partition.
domcox@2 220 # run 'tazinst list uuid' to list your partitions
domcox@2 221 ROOT_UUID="$ROOT_UUID"
domcox@0 222
domcox@2 223 # Formatting the root partition:
domcox@2 224 # Let ROOT_FORMAT empty if you do not want to format the root partition.
domcox@2 225 # SliTaz uses ext2 ext3 ext4 by default but another filesystem can be
domcox@2 226 # installed if wanted, for this please adjust your /etc/fstab after
domcox@2 227 # installation.
domcox@2 228 # run 'tazinst list format' to list installed filesystems on your system.
domcox@2 229 ROOT_FORMAT="$ROOT_FORMAT"
domcox@2 230
domcox@2 231 # Home partition:
domcox@0 232 # On most GNU/Linux systems users personal files are stored in the directory
domcox@2 233 # /home. /home can be on another hard disk or on a separate partition.
paul@5 234 # Leave HOME_UUID empty if you do not intend to use a specific partition for /home
domcox@2 235 # or enter the UUID of the partition to be used.
domcox@2 236 # run 'tazinst list uuid' to list your partitions.
domcox@2 237 HOME_UUID="$HOME_UUID"
domcox@0 238
domcox@2 239 # Formatting the /home partition (if /home is on a separate partition):
paul@5 240 # Leave HOME_FORMAT empty if you do not want to format the /home partition.
domcox@2 241 # For options, see comments on 'Formatting the root partition' above.
domcox@2 242 HOME_FORMAT="$HOME_FORMAT"
domcox@0 243
domcox@2 244 # Hostname of the new system:
domcox@2 245 HOSTNAME="$HOSTNAME"
domcox@2 246
domcox@2 247 # root password:
domcox@0 248 # The root administrator privilege lets you manage and configure the full
domcox@0 249 # system. A root user can damage your system so you should always setup a
domcox@0 250 # strong password with special characters and/or numbers.
domcox@2 251 ROOT_PWD="$ROOT_PWD"
domcox@0 252
domcox@2 253 # Default user:
domcox@0 254 # The default user for the system will have his personal files stored
domcox@2 255 # in /home/<USER_LOGIN> (and will be automatically added to the audio group).
domcox@2 256 USER_LOGIN="$USER_LOGIN"
domcox@2 257 USER_PWD="$USER_PWD"
domcox@0 258
domcox@2 259 # Install bootloader:
paul@5 260 # If you do not want to install a bootloader, leave this field empty.
domcox@2 261 # It's generally safe to set it up as 'auto'.
domcox@2 262 # Run 'tazinst list bootloader' to list all options.
domcox@2 263 BOOTLOADER="$BOOTLOADER"
domcox@0 264
pascal@112 265 # SliTaz live/rescue boot:
pascal@112 266 # If you do not want enable live boot, leave LIVEBOOT empty (LIVEBOOT="").
pascal@112 267 # You may let tazinst automatically find your rootfs file(s) by specifying auto
pascal@112 268 # (LIVEBOOT="auto").
pascal@112 269 LIVEBOOT="$LIVEBOOT"
pascal@112 270
pascal@112 271 # SliTaz Web boot:
pascal@112 272 # If you do not want enable Web boot, leave WEBBOOT empty (WEBBOOT="").
pascal@112 273 # You may let tazinst automatically find your pxe client by specifying auto
pascal@112 274 # (WEBBOOT="auto").
pascal@112 275 WEBBOOT="$WEBBOOT"
pascal@112 276
domcox@2 277 # Windows dual boot:
paul@5 278 # If you do not want enable Dual boot, leave WINBOOT empty (WINBOOT="").
domcox@2 279 # You may let tazinst automatically find your win partition by specifying auto
domcox@2 280 # (WINBOOT="auto"), otherwise enter the UUID of the partition to be used.
domcox@2 281 # Run 'tazinst list winboot' to see the Windows partitions found by tazinst.
domcox@2 282 WINBOOT="$WINBOOT"
domcox@0 283
domcox@2 284 EOT
domcox@2 285 return "$?"
domcox@2 286 }
domcox@2 287
domcox@2 288 read_file()
domcox@2 289 {
domcox@2 290 local install_file="$1"
domcox@2 291 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
domcox@2 292 if ! [ -r "$install_file" ]; then
al@73 293 _ 'Error: Unable to read install file.' 1>&2
domcox@2 294 exit 2
domcox@2 295 fi
domcox@2 296 #
domcox@2 297 if ! CONTENTS="$(cat "$install_file")"; then
al@73 298 _ 'Error: Unable to read install file.' 1>&2
domcox@2 299 exit 2
domcox@0 300 fi
domcox@0 301 }
domcox@0 302
domcox@2 303 # read value of a setting
domcox@2 304 get_value()
domcox@0 305 {
domcox@2 306 local setting="$1"
domcox@2 307 printf "%s" "$CONTENTS" | /bin/busybox awk -v setting="$setting" 'BEGIN{
domcox@2 308 setting="^" toupper(setting) "="
domcox@2 309 }
domcox@2 310 {
domcox@2 311 if (match($0,setting)){
domcox@2 312 n=index($0,"=")
domcox@2 313 value=substr($0,n+1)
domcox@2 314 gsub(/[\t\s]*$/,"",value)
domcox@2 315 sub(/^"/,"",value)
domcox@2 316 sub(/"$/,"",value)
domcox@2 317 }
domcox@2 318 }
domcox@2 319 END{
domcox@2 320 print value
domcox@2 321 }'
domcox@0 322 }
domcox@0 323
domcox@2 324 # list of settings
domcox@2 325 get_settings()
domcox@0 326 {
domcox@2 327 local "mode=$(get_value mode)"
domcox@2 328 case "$mode" in
domcox@2 329 upgrade)
pascal@112 330 echo "mode media source root_uuid bootloader liveboot webboot winboot" ;;
domcox@2 331 *)
domcox@12 332 printf "%s\n" "$SETTINGS" ;;
domcox@2 333 esac
domcox@0 334 }
domcox@0 335
domcox@2 336 # get command
domcox@2 337 get()
domcox@0 338 {
domcox@2 339 local setting="$1"
domcox@2 340 [ -z "$setting" ] && setting="all"
domcox@2 341 # setting is valid: display value
domcox@2 342 if printf "%s" "$setting" | \
domcox@2 343 egrep -q "$(regex "$SETTINGS")"; then
domcox@2 344 get_value "$setting"
domcox@0 345 else
al@73 346 case "$setting" in
al@73 347 all)
al@73 348 for i in mode media source root_uuid root_format home_uuid home_format \
pascal@112 349 hostname root_pwd user_login user_pwd bootloader liveboot webboot winboot; do
al@73 350 printf "%-15s: %s\n" "$i" "$(get_value $i)"
al@73 351 done
al@73 352 ;;
al@73 353 settings)
al@73 354 get_settings
al@73 355 ;;
al@73 356 *)
al@73 357 option_error "$1" "$SETTINGS"
al@73 358 ;;
al@73 359 esac
domcox@0 360 fi
domcox@0 361 }
domcox@0 362
domcox@2 363 # set command
domcox@2 364 change()
domcox@0 365 {
domcox@2 366 local setting="$1" value="$2" install_file="$3"
domcox@2 367 # validate setting
domcox@2 368 if ! printf "%s" "$setting" | \
domcox@2 369 egrep -q "$(regex "$SETTINGS")"; then
al@73 370 _ "Error: '%s' unknown setting." "$setting" 1>&2
domcox@2 371 exit 1
domcox@2 372 fi
domcox@2 373 # and file
domcox@2 374 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
domcox@2 375 # write changes to file
domcox@2 376 if [ -w "$install_file" ]; then
domcox@2 377 printf "%s" "$CONTENTS" | \
domcox@2 378 /bin/busybox awk -v setting="$setting" -v value="$value" '
domcox@2 379 BEGIN{
domcox@2 380 set=0
domcox@2 381 }
domcox@2 382 {
domcox@2 383 if (match($0,"^" toupper(setting) "=")){
domcox@2 384 printf toupper(setting) "=\"" value "\"\n"
domcox@2 385 set++
domcox@2 386 }
domcox@2 387 else
domcox@2 388 printf $0 "\n"
domcox@2 389 }
domcox@2 390 END{
domcox@2 391 if (! set)
domcox@2 392 printf toupper(setting) "=\"" value "\"\n"
domcox@2 393 }' > "$install_file"
domcox@2 394 # check new value
domcox@2 395 read_file "$install_file"
domcox@2 396 check "$setting"
domcox@0 397 else
al@73 398 _ 'Error: Unable to write to install file.' 1>&2
domcox@2 399 exit 2
domcox@0 400 fi
domcox@0 401 }
domcox@0 402
domcox@2 403 #
domcox@2 404 load_settings()
domcox@0 405 {
domcox@2 406 MODE="$(get mode)"
domcox@2 407 local settings="$(get settings)"
domcox@2 408 MEDIA="$(get media)"
domcox@12 409 echo "source" | egrep -q "$(regex "$settings")" \
domcox@2 410 && SOURCE="$(get source)" \
domcox@2 411 || unset SOURCE
domcox@2 412 ROOT_UUID="$(get root_uuid)"
domcox@12 413 echo "root_format" | egrep -q "$(regex "$settings")" \
domcox@2 414 && ROOT_FORMAT="$(get root_format)" \
domcox@2 415 || unset ROOT_FORMAT
domcox@12 416 echo "home_uuid" | egrep -q "$(regex "$settings")" \
domcox@2 417 && HOME_UUID="$(get home_uuid)" \
domcox@2 418 || unset HOME_UUID
domcox@12 419 echo "home_format" | egrep -q "$(regex "$settings")" \
domcox@2 420 && HOME_FORMAT="$(get home_format)" \
domcox@2 421 || unset HOME_FORMAT
domcox@12 422 echo "hostname" | egrep -q "$(regex "$settings")" \
domcox@2 423 && HOSTNAME="$(get hostname)" \
domcox@2 424 || unset HOSTNAME
domcox@12 425 echo "root_pwd" | egrep -q "$(regex "$settings")" \
domcox@2 426 && ROOT_PWD="$(get root_pwd)" \
domcox@2 427 || unset ROOT_PWD
domcox@12 428 echo "user_login" | egrep -q "$(regex "$settings")" \
domcox@2 429 && USER_LOGIN="$(get user_login)" \
domcox@2 430 || unset USER_LOGIN
domcox@12 431 echo "user_pwd" | egrep -q "$(regex "$settings")" \
domcox@2 432 && USER_PWD="$(get user_pwd)" \
domcox@2 433 || unset USER_PWD
domcox@12 434 echo "bootloader" | egrep -q "$(regex "$settings")" \
domcox@2 435 && BOOTLOADER="$(get bootloader)" \
domcox@2 436 || unset BOOTLOADER
pascal@112 437 echo "liveboot" | egrep -q "$(regex "$settings")" \
pascal@112 438 && LIVEBOOT="$(get liveboot)" \
pascal@112 439 || unset LIVEBOOT
pascal@112 440 echo "webboot" | egrep -q "$(regex "$settings")" \
pascal@112 441 && WEBBOOT="$(get webboot)" \
pascal@112 442 || unset WEBBOOT
domcox@12 443 echo "winboot" | egrep -q "$(regex "$settings")" \
domcox@2 444 && WINBOOT="$(get winboot)" \
domcox@2 445 || unset WINBOOT
domcox@0 446 }
domcox@0 447
al@73 448
al@73 449
al@73 450
al@73 451
al@73 452
al@73 453
domcox@2 454 # clean command
domcox@2 455 clean()
domcox@0 456 {
domcox@2 457 # rm LOG
domcox@2 458 [ -r "$LOG" ] && rm -f "$LOG"
domcox@2 459 # rm temp files
domcox@2 460 rm -rf /tmp/tazinst
domcox@2 461 # rm install file
domcox@2 462 local install_file="$1"
domcox@2 463 [ -z "$install_file" ] && install_file="$DEFAULT_INSTALL_FILE"
al@73 464 _ 'Deleting install file: %s' "$install_file"
domcox@2 465 if ! [ -w "$install_file" ]; then
al@73 466 _ 'Error: Unable to delete install file.' 1>&2
domcox@2 467 exit 2
domcox@0 468 else
domcox@2 469 rm -f "$install_file"
domcox@0 470 fi
domcox@0 471 }
domcox@0 472
domcox@2 473 #-----------
domcox@2 474 # 1.2 check
domcox@2 475 #-----------
domcox@2 476
domcox@2 477 # exit if user is not root.
domcox@2 478 check_root()
domcox@0 479 {
al@73 480 if [ $(id -u) -ne 0 ]; then
al@73 481 _ "You must be the root user (system administrator) \
domcox@2 482 to install SliTaz, please use 'su' to get a root SHell and restart \
al@73 483 installation." 1>&2
domcox@2 484 exit 1
domcox@0 485 fi
domcox@0 486 }
domcox@0 487
domcox@2 488 # exit if another instance of tazinst is running
domcox@2 489 check_instance()
domcox@0 490 {
domcox@2 491 if [ -e "$LOCK" ]; then
al@73 492 _ 'Another instance of tazinst is running.' 1>&2
domcox@2 493 exit 7
domcox@2 494 else
domcox@12 495 printf "%s" "$$" > $LOCK
domcox@0 496 fi
domcox@0 497 }
domcox@0 498
domcox@2 499 # exit if the setting is not in a list of keywords
domcox@2 500 check_key()
domcox@0 501 {
domcox@12 502 local setting="$1" keylist="$2" keyword="$(get $1)" msg
domcox@2 503 if ! printf "%s" "$keyword" | \
domcox@2 504 egrep -q "$(regex "$keylist")"; then
domcox@12 505 msg="$setting=$keyword
al@73 506 $(_ "Error: '%s' Invalid keyword." "$keyword")
al@73 507 $(_ 'Select one of these options: %s.' "$keylist")
al@73 508 $(_ 'For more information, see tazinst Manual.')"
domcox@12 509 printf "%s\n" "$msg" 1>&2
domcox@2 510 exit 1
domcox@0 511 fi
domcox@0 512 }
domcox@0 513
paul@5 514 # exit if the partition does not exist
domcox@2 515 check_uuid()
domcox@0 516 {
domcox@12 517 local setting="$1" value="$(get $1)" found=0 partition msg
domcox@2 518 for partition in $(list_uuid); do
pascal@98 519 [ "$partition" = "$value" ] && found="$(($found + 1))"
domcox@2 520 done
domcox@2 521 if [ "$found" != "1" ]; then
domcox@12 522 msg="$(gettext "$setting")=$value
al@73 523 $(_ 'Error: Partition not found.')
al@73 524 $(_ "To see available partitions, run '%s'." 'tazinst list uuid')"
domcox@12 525 printf "%s\n" "$msg" 1>&2
domcox@2 526 exit 1
domcox@2 527 fi
domcox@0 528 }
domcox@0 529
paul@5 530 # exit if the source does not exist
domcox@2 531 check_source()
domcox@0 532 {
domcox@2 533 local media="$(get media)" source="$(get source)"
domcox@2 534 case $media in
domcox@2 535 usb)
domcox@2 536 check_uuid source ;;
domcox@2 537 iso)
domcox@2 538 if [ ! -r "$source" ]; then
al@73 539 _ 'Error: Source file not found.' 1>&2
domcox@2 540 exit 1
domcox@2 541 fi ;;
domcox@2 542 web)
domcox@2 543 local valid=0
domcox@2 544 # check full url (http://...)
domcox@2 545 local regexp="^(https?|ftp):\/\/([a-z0-9\-]+\.)?[a-z0-9\-]+\.\
domcox@2 546 [a-z0-9]{2,4}(\.[a-z0-9]{2,4})?(\/.*)?iso$"
domcox@2 547 printf "%s" "$source" | \
domcox@2 548 egrep -q "$regexp" && valid=$(($valid+1))
domcox@2 549 # check iso names (stable cooking...)
domcox@2 550 regexp="$(regex "$(list web)")"
domcox@2 551 printf "%s" "$source" | \
domcox@2 552 egrep -q "$regexp" && valid=$(($valid+1))
domcox@2 553 if [ "$valid" -le "0" ]; then
al@73 554 _ 'Error: invalid URL.' 1>&2
domcox@2 555 exit 1
domcox@0 556 fi
domcox@2 557 esac
domcox@2 558 }
domcox@2 559
domcox@2 560 # exit if a partition is selected more than once
domcox@2 561 check_uuid_mix()
domcox@2 562 {
domcox@2 563 local list all nodup
domcox@2 564 list="$(get root_uuid) $(get source) $(get home_uuid) $(get winboot)"
domcox@12 565 all="$(printf "%s" "$list" | wc -w)"
domcox@12 566 nodup="$(printf "%s" "$list" | /bin/busybox awk 'BEGIN{RS=" "}{print $0}' \
domcox@12 567 | sort | uniq | wc -w)"
domcox@2 568 if [ "$all" != "$nodup" ]; then
al@73 569 _ 'Error: multiple assignations for a disk.' 1>&2
domcox@2 570 exit 1
domcox@2 571 fi
domcox@2 572 }
domcox@2 573
al@73 574
domcox@2 575 # exit if a password is invalid
domcox@2 576 check_password()
domcox@2 577 {
domcox@2 578 local pass="$(get "$1")"
domcox@2 579 local invalid="^[A-Za-z0-9!@#$%^&*()_]{0,40}$"
domcox@2 580 local errcode=0
domcox@2 581 # too long
domcox@2 582 if [ "${#pass}" -ge 40 ]; then
al@73 583 _ 'Error: password too long.' 1>&2
domcox@2 584 exit 1
domcox@2 585 fi
domcox@2 586 # bad chars
domcox@12 587 if ! (printf "%s" "$pass" | egrep -q "$invalid"); then
al@73 588 _ 'Error: Unallowed characters in password.' 1>&2
al@73 589
domcox@2 590 exit 1
domcox@2 591 fi
domcox@2 592 # short pwd
domcox@2 593 [ "${#pass}" -le 4 ] && errcode=128
domcox@2 594 # empty pwd
domcox@2 595 [ -z "$pass" ] && errcode=129
domcox@2 596 case "$errcode" in
domcox@2 597 128)
al@73 598 _ 'Warning: short password!' 1>&2 ;;
domcox@2 599 129)
al@73 600 _ 'Warning: no password!' 1>&2 ;;
domcox@2 601 esac
domcox@2 602 return "$errcode"
domcox@2 603 }
domcox@2 604
domcox@2 605 # exit if a name is invalid
domcox@2 606 check_name()
domcox@2 607 {
domcox@12 608 local name="$1" value="$(get "$1")" msg
domcox@12 609 msg="$name=$value"
al@73 610 if [ "${#value}" -lt 2 ]; then
al@73 611 _ '%s Error: Too short.' "$msg" 1>&2
domcox@2 612 exit 1
domcox@2 613 fi
domcox@2 614 if [ "${#value}" -gt 32 ]; then
al@73 615 _ '%s Error: Too long.' "$msg" 1>&2
domcox@2 616 exit 1
domcox@2 617 fi
domcox@12 618 if printf "%s" "$value" | \
domcox@2 619 grep -q "[[:space:]\&\"\'\(\)\|\*\\#\`\+\:/;<>]"; then
al@73 620 _ '%s Error: Invalid chars.' "$msg" 1>&2
domcox@2 621 exit 1
domcox@2 622 fi
domcox@2 623 }
domcox@2 624
domcox@2 625 # check bootloader + winboot
domcox@2 626 check_boot_mix()
domcox@2 627 {
domcox@2 628 local bootloader=$(get bootloader)
pascal@112 629 local var name
pascal@112 630 [ -z "$bootloader" ] && while read var name; do
pascal@112 631 local value
pascal@112 632 eval value=\$$var
pascal@112 633 [ -z "$value" ] && continue
pascal@112 634 _ 'Error: %s set with no bootloader.' "$name" 1>&2
domcox@2 635 exit 1
pascal@112 636 done <<EOT
pascal@112 637 liveboot Rescue/live boot
pascal@112 638 webbot Web boot
pascal@112 639 winboot Dualboot
pascal@112 640 EOT
domcox@2 641 }
domcox@2 642
domcox@2 643 # exit if partition table is not in list
domcox@2 644 check_table()
domcox@2 645 {
domcox@2 646 local pt_list="gpt msdos"
domcox@2 647 # get root uuid
domcox@2 648 local uuid="$(get root_uuid)"
pascal@106 649 if [ "$(blkid | grep -c "$uuid")" = "1" ]; then
domcox@12 650 if ! printf "%s" "$(p_table $uuid)" | \
domcox@2 651 egrep -q "$(regex "$pt_list")"; then
al@73 652 _ 'Error: Unsupported Partition Table.' 1>&2
domcox@2 653 exit 1
domcox@2 654 fi
domcox@2 655 else
al@73 656
al@73 657 _ 'Error: No disk selected, cannot install any bootloader.' 1>&2
domcox@2 658 exit 1
domcox@2 659 fi
domcox@2 660 }
domcox@2 661
domcox@2 662
domcox@2 663 # check all settings()
domcox@2 664 check_all()
domcox@2 665 {
domcox@2 666 # check only settings we need
domcox@2 667 for key in $(get settings); do
domcox@2 668 case "$key" in
domcox@2 669 mode)
pascal@112 670 printf "%-15s: " "$key"
pascal@112 671 check_key $key "$(key "$LST_MODE")" && echo "ok" ;;
domcox@2 672 media)
pascal@112 673 printf "%-15s: " "$key"
pascal@112 674 check_key $key "$(key "$LST_MEDIA")" && echo "ok" ;;
domcox@2 675 source)
pascal@112 676 printf "%-15s: " "$key"
domcox@2 677 check_source && echo "ok" ;;
domcox@2 678 root_uuid)
pascal@112 679 printf "%-15s: " "$key"
pascal@112 680 check_uuid $key && echo "ok" ;;
pascal@112 681 root_format|home_format)
pascal@112 682 printf "%-15s: " "$key"
pascal@112 683 [ -n "$(get $key)" ] && \
pascal@112 684 { check_key $key "$(key "$LST_FORMAT")" && echo "ok"; } \
domcox@2 685 || echo "ok" ;;
domcox@2 686 home_uuid)
pascal@112 687 printf "%-15s: " "$key"
pascal@112 688 [ -n "$(get $key)" ] && \
pascal@112 689 { check_uuid $key && check_uuid_mix && echo "ok"; } \
domcox@2 690 || echo "ok" ;;
pascal@112 691 hostname|user_login)
pascal@112 692 printf "%-15s: " "$key"
pascal@112 693 check_name $key && echo "ok" ;;
pascal@112 694 root_pwd|user_pwd)
pascal@112 695 printf "%-15s: " "${key/pwd/password}"
pascal@112 696 check_password $key && echo "ok" ;;
domcox@2 697 bootloader)
pascal@112 698 printf "%-15s: " "$key"
pascal@112 699 [ -n "$(get $key)" ] \
pascal@112 700 && { check_key $key "$(list_bootloader)" \
domcox@2 701 && check_table && echo "ok" ; } \
domcox@2 702 || echo "ok" ;;
pascal@112 703 liveboot|webboot)
pascal@112 704 printf "%-15s: " "$key"
pascal@116 705 [ -n "$(get $key)" ] && [ "$(get $key)" == "auto" ] \
pascal@116 706 && { check_boot_mix && echo "ok"; } \
pascal@112 707 || echo "ok" ;;
domcox@2 708 winboot)
pascal@112 709 printf "%-15s: " "$key"
pascal@112 710 [ -n "$(get $key)" ] && [ "$(get $key)" != "auto" ] \
pascal@112 711 && { check_uuid $key && check_boot_mix && echo "ok"; } \
domcox@2 712 || echo "ok" ;;
domcox@2 713 esac
domcox@0 714 done
domcox@0 715 }
domcox@0 716
domcox@2 717 # check command
domcox@2 718 check()
domcox@0 719 {
domcox@2 720 local setting="$1"
domcox@2 721 case "$setting" in
domcox@2 722 mode)
pascal@112 723 check_key $setting "$(key "$LST_MODE")" ;;
domcox@2 724 media)
pascal@112 725 check_key $setting "$(key "$LST_MEDIA")" ;;
domcox@2 726 source)
domcox@2 727 check_source ;;
domcox@2 728 root_uuid)
pascal@112 729 check_uuid $setting
domcox@2 730 check_uuid_mix ;;
domcox@2 731 home_uuid)
pascal@112 732 [ -z "$(get $setting)" ] || check_uuid $setting
domcox@2 733 check_uuid_mix ;;
domcox@2 734 root_format)
pascal@112 735 [ -z "$(get $setting)" ] \
pascal@112 736 || check_key $setting "$(key "$LST_FORMAT")" ;;
domcox@2 737 home_format)
pascal@112 738 [ -z "$(get $setting)" ] \
pascal@112 739 || check_key $setting "$(key "$LST_FORMAT")" ;;
pascal@112 740 hostname|user_login)
pascal@112 741 check_name $setting ;;
pascal@112 742 root_pwd|user_pwd)
pascal@112 743 check_password $setting ;;
domcox@2 744 bootloader)
pascal@112 745 [ -z "$(get $setting)" ] \
pascal@112 746 || (check_key $setting "$(list_bootloader)" \
domcox@2 747 && check_table ; ) ;;
pascal@112 748 liveboot|webboot)
pascal@116 749 { [ -z "$(get $setting)" ] || [ "$(get $setting)" = "auto" ]; } \
pascal@112 750 && check_boot_mix ;;
domcox@2 751 winboot)
pascal@116 752 { [ -z "$(get $setting)" ] || [ "$(get $setting)" = "auto" ]; } \
pascal@112 753 || check_uuid $setting && check_boot_mix ;;
domcox@2 754 ""|all)
domcox@2 755 check_all ;;
domcox@2 756 *)
domcox@2 757 option_error "$setting" "$SETTINGS" ;;
domcox@2 758 esac
domcox@0 759 }
domcox@0 760
domcox@2 761 #----------
domcox@2 762 # 1.3 help
domcox@2 763 #----------
domcox@2 764
domcox@2 765 help_source()
domcox@0 766 {
al@73 767
al@73 768 _ 'The Source setting depends on the type of media:'
domcox@2 769 printf "%-12s%s\n" "cdrom" "$(help cdrom)"
domcox@2 770 printf "%-12s%s\n" "usb" "$(help usb)"
domcox@2 771 printf "%-12s%s\n" "iso" "$(help iso)"
al@73 772 printf "%-12s%s" "web" "$(_ 'Name or URL of the image on the web.')"
al@73 773 printf "%s\n" "$(_ 'Type: %s' 'tazinst help web')"
domcox@2 774 }
domcox@2 775
domcox@2 776 help_all()
domcox@2 777 {
al@73 778 _ 'List of settings:'
al@73 779 optlist "\
al@73 780 mode $(_ 'Mode of install')
al@73 781 media $(_ 'Media containing the SliTaz source files')
al@73 782 source $(_ 'Source file containing SliTaz')
al@73 783 root_uuid $(_ 'The name of the target partition')
al@73 784 root_format $(_ 'Format of the target partition')
al@73 785 home_uuid $(_ 'Separate home partition')
al@73 786 home_format $(_ 'Format of the root partition')
al@73 787 hostname $(_ 'Name of the system')
al@73 788 root_pwd $(_ 'Superuser password')
al@73 789 user_login $(_ 'First user name')
al@73 790 user_pwd $(_ 'First user password')
al@73 791 bootloader $(_ 'Install a bootloader')
pascal@113 792 liveboot $(_ 'Install a live/rescue boot (with root password)')
pascal@113 793 webboot $(_ 'Install a web boot (with root password)')
al@73 794 winboot $(_ 'Partition to dualboot Windows from')
al@73 795 "
domcox@2 796 }
domcox@2 797
domcox@2 798 # help command
domcox@2 799 help()
domcox@2 800 {
domcox@2 801 local setting="$1"
domcox@2 802 case "$setting" in
domcox@2 803 mode)
domcox@12 804 printf "%s" "$LST_MODE" | \
domcox@2 805 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
domcox@2 806 media)
domcox@12 807 printf "%s" "$LST_MEDIA" | \
domcox@2 808 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
domcox@2 809 source)
domcox@2 810 help_source ;;
domcox@2 811 cdrom)
al@73 812 _ 'CD. Automatically set' ;;
domcox@2 813 usb)
al@73 814
al@73 815 _ 'USB partition. For a list, type: %s' 'tazinst list usb' ;;
domcox@2 816 iso)
al@73 817
al@73 818 _ 'ISO file name. For a list, type: %s' 'tazinst list iso' ;;
domcox@2 819 web)
domcox@12 820 printf "%s" "$LST_WEB" | \
domcox@2 821 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $3}' ;;
domcox@2 822 root_format)
domcox@12 823 printf "%s" "$LST_FORMAT" | \
domcox@2 824 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
pascal@106 825 home_uuid|root_uuid)
domcox@2 826 /sbin/blkid -s TYPE -s LABEL | sort ;;
domcox@2 827 home_format)
domcox@12 828 printf "%s" "$LST_FORMAT" | \
domcox@2 829 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
domcox@2 830 hostname)
al@73 831 _ 'Name of the system' ;;
domcox@2 832 root_pwd)
al@73 833 _ 'Superuser password' ;;
domcox@2 834 user_login)
al@73 835 _ 'First user name' ;;
domcox@2 836 user_pwd)
al@73 837 _ 'First user password' ;;
domcox@2 838 bootloader)
domcox@12 839 printf "%s" "$LST_BOOTLOADER" | \
domcox@2 840 /bin/busybox awk -F: '/..*/{printf "%-12s%s\n",$1,$2}' ;;
pascal@112 841 liveboot|webboot)
pascal@112 842 _ "Empty string, or 'auto'" ;;
domcox@2 843 winboot)
al@73 844 _ "Partition containing Windows, or 'auto'" ;;
domcox@2 845 ""|all)
al@73 846 help_all ;;
domcox@2 847 *)
domcox@2 848 option_error "$setting" "$SETTINGS" ;;
domcox@2 849 esac
domcox@2 850 }
domcox@2 851
domcox@2 852 #---------
domcox@2 853 # 2. list
domcox@2 854 #---------
domcox@2 855
domcox@2 856 list_media()
domcox@2 857 {
domcox@2 858 local key media
domcox@2 859 for key in $(key "$LST_MEDIA") ; do
domcox@2 860 case "$key" in
domcox@2 861 cdrom)
domcox@2 862 [ -e "/dev/cdrom" ] && media="cdrom" ;;
domcox@2 863 usb)
domcox@2 864 [ -e "/sys/bus/usb" ] && media="$media usb" ;;
domcox@2 865 web)
domcox@2 866 [ "$(ifconfig -a | grep -c Link)" -gt 2 ] \
domcox@2 867 && media="$media web" ;;
domcox@2 868 *)
domcox@2 869 media="$media $key"
domcox@2 870 esac
domcox@2 871 done
domcox@19 872 printf "%s\n" "$media" | sed 's/^\s//'
domcox@2 873 }
domcox@2 874
domcox@2 875 list_usb()
domcox@2 876 {
domcox@2 877 # List plugged USB disks
domcox@2 878 if [ -d /proc/scsi/usb-storage ]; then
domcox@2 879 for DEV in /sys/block/sd* ; do
domcox@2 880 if readlink $DEV | grep -q usb; then
domcox@2 881 DEV=$(basename $DEV)
domcox@2 882 if [ -d /sys/block/${DEV}/${DEV}1 ]; then
pascal@106 883 blkid /dev/$DEV* | tr ' ' '\n' | /bin/busybox awk '
domcox@2 884 /^\/dev\// {
domcox@2 885 DEV=$1
domcox@2 886 gsub(/:/,"",DEV)
domcox@2 887 }
domcox@19 888 /^UUID/ {
domcox@2 889 UUID=$1
domcox@2 890 gsub(/"/,"",UUID)
domcox@2 891 printf "%s %s\n",UUID,DEV}'
domcox@2 892 fi
domcox@0 893 fi
domcox@0 894 done
domcox@0 895 fi
domcox@0 896 }
domcox@0 897
domcox@2 898 list_iso()
domcox@0 899 {
domcox@2 900 for i in /root/*.iso /home/*/*.iso /home/*/*/*.iso ; do
domcox@12 901 printf "%s" $i | grep -v "*"
domcox@2 902 done
domcox@0 903 }
domcox@0 904
domcox@2 905 list_format()
domcox@0 906 {
domcox@2 907 local fs
al@73 908 type mkfs.btrfs > /dev/null && fs="btrfs"
al@73 909 type mkfs.ext2 > /dev/null && fs="$fs ext2"
al@73 910 type mkfs.ext3 > /dev/null && fs="$fs ext3"
al@73 911 type mkfs.ext4 > /dev/null && fs="$fs ext4"
al@73 912 type mkfs.jfs > /dev/null && fs="$fs jfs"
al@73 913 type mkfs.minix > /dev/null && fs="$fs minix"
domcox@2 914 type mkfs.reiser4 > /dev/null && fs="$fs reiser4"
al@73 915 type mkfs.xfs > /dev/null && fs="$fs xfs"
domcox@12 916 printf "%s" "$fs" | sed 's/^\s//'
domcox@0 917 }
domcox@0 918
domcox@2 919 # list partitions
domcox@2 920 list_uuid()
domcox@0 921 {
domcox@28 922 # list all drives but cdroms
domcox@28 923 /sbin/blkid -o export| /bin/busybox awk '
domcox@28 924 BEGIN{FS="="}
domcox@28 925 /DEVNAME/{dev=$2, type="unknown", label=""}
domcox@28 926 /LABEL/{label=$2" "}
domcox@28 927 /TYPE/{type=$2}
domcox@28 928 /PARTUUID/{if (type != "iso9660"){
domcox@28 929 printf "%s %s(%s)\n", dev, label, type}}' | sort -k 2
domcox@0 930 }
domcox@0 931
domcox@2 932 list_partition_table()
domcox@0 933 {
domcox@28 934 /usr/sbin/parted -lms 2>&1 | \
domcox@2 935 /bin/busybox awk -F: '/^\/dev\//{printf "%s: %s\n", $1,$6}'
domcox@2 936 }
domcox@2 937
domcox@2 938 list_web()
domcox@0 939 {
domcox@2 940 local key="$1"
domcox@2 941 # print url of a given iso
domcox@12 942 if printf "%s" "$LST_WEB" | egrep -q "^$key:"; then
domcox@12 943 printf "%s" "$LST_WEB" | egrep "^$key:" | \
domcox@2 944 /bin/busybox awk -F: '{print $2}'
domcox@2 945 fi
domcox@2 946 # print all key
domcox@2 947 if [ -z "$key" ]; then
domcox@2 948 key "$LST_WEB"
domcox@2 949 fi
domcox@0 950 }
domcox@2 951
domcox@2 952 list_bootloader()
domcox@2 953 {
domcox@2 954 local btlr
domcox@2 955 type grub-install > /dev/null && btlr=" grub"
domcox@2 956 type syslinux > /dev/null && btlr="$btlr syslinux"
domcox@12 957 [ -n "$btlr" ] && printf "%s\n" "auto$btlr"
domcox@2 958 }
domcox@2 959
domcox@2 960 # list Windows partitions
domcox@2 961 list_winboot()
domcox@2 962 {
pascal@103 963 /usr/sbin/parted -lms 2>&1 | sed '/zram/,$d' | /bin/busybox awk '
domcox@2 964 BEGIN{
domcox@2 965 FS=":"
domcox@2 966 disknum=-1
domcox@2 967 found=0
domcox@2 968 winboot=""
domcox@2 969 printf "auto"
domcox@2 970 }
domcox@2 971 {
domcox@2 972 # Count disks
domcox@2 973 if (match($1,"^/dev")){
domcox@2 974 disknum++
domcox@2 975 part=0
pascal@106 976 disk=$1
pascal@106 977 dev=substr($1,6)
domcox@2 978 # get removable status
domcox@2 979 file="/sys/block/"dev"/removable"
domcox@2 980 "cat " file | getline removable
domcox@2 981 close("cat ")
pascal@106 982 }
domcox@2 983 # Count partitions
domcox@2 984 if (match($1,"[0-9][0-9]?")){
domcox@2 985 # List fixed drives only
domcox@2 986 if (removable==0){
domcox@2 987 part++
domcox@2 988 # Read partition Id
domcox@2 989 if (match($7,"boot")){
domcox@2 990 fs=$5
domcox@2 991 # Detect Windows Partition Type: ntfs vfat
domcox@2 992 WPT="ntfs|vfat"
domcox@2 993 if (fs ~ WPT){
domcox@2 994 found++
domcox@2 995 # record 1st Windows partition found
domcox@2 996 if (found==1){
domcox@2 997 printf(" %s%d",disk,part)
domcox@2 998 }
domcox@2 999 }
domcox@0 1000 }
domcox@0 1001 }
domcox@0 1002 }
domcox@0 1003 }
domcox@2 1004 END{printf "\n"}'
domcox@0 1005 }
domcox@2 1006
paul@31 1007 # list command
domcox@2 1008 list()
domcox@2 1009 {
domcox@2 1010 local ressource="$1"
domcox@2 1011 case "$ressource" in
domcox@2 1012 mode)
domcox@12 1013 printf "%s\n" "$(key "$LST_MODE")" ;;
domcox@2 1014 media)
domcox@2 1015 list_media ;;
domcox@2 1016 iso)
domcox@2 1017 list_iso ;;
domcox@2 1018 usb)
domcox@2 1019 list_usb ;;
domcox@2 1020 web)
domcox@2 1021 list_web "$2" ;;
domcox@2 1022 uuid)
domcox@2 1023 list_uuid ;;
domcox@2 1024 format)
domcox@2 1025 list_format ;;
domcox@2 1026 bootloader)
domcox@2 1027 list_bootloader ;;
domcox@2 1028 winboot)
domcox@2 1029 list_winboot ;;
domcox@2 1030 partition_table)
domcox@2 1031 list_partition_table ;;
domcox@2 1032 ""|all)
domcox@12 1033 printf "* mode:\n%s\n\n" "$(key "$LST_MODE")"
domcox@12 1034 printf "* media:\n%s\n\n" "$(list_media)"
domcox@12 1035 printf "* usb:\n%s\n\n" "$(list usb)"
domcox@12 1036 printf "* iso:\n%s\n\n" "$(list_iso)"
domcox@12 1037 printf "* web:\n%s\n\n" "$(list_web)"
domcox@17 1038 printf "* uuid:\n%s\n\n" "$(list_uuid)"
domcox@12 1039 printf "* format:\n%s\n\n" "$(list_format)"
domcox@12 1040 printf "* bootloader:\n%s\n\n" "$(list_bootloader)"
domcox@12 1041 printf "* partition_table:\n%s\n\n" "$(list_partition_table)"
domcox@12 1042 printf "* winboot:\n%s\n" "$(list_winboot)"
domcox@2 1043 ;;
domcox@2 1044 *)
domcox@2 1045 local options="mode media usb iso web uuid format bootloader \
domcox@2 1046 partition_table winboot"
domcox@2 1047 option_error "$1" "$options" ;;
domcox@2 1048 esac
domcox@2 1049 }
domcox@2 1050
domcox@2 1051 #----------
domcox@2 1052 # 3. tools
domcox@2 1053 #----------
domcox@2 1054
domcox@2 1055 # list indexes from a list
domcox@2 1056 key()
domcox@2 1057 {
domcox@12 1058 printf "%s" "$1" | /bin/busybox awk -F: 'BEGIN{
domcox@2 1059 other=-1
domcox@2 1060 }
domcox@2 1061 !/^#|^$/{
domcox@2 1062 if(other){
domcox@2 1063 printf "%s", $1
domcox@2 1064 other++}
domcox@2 1065 else
domcox@2 1066 printf " %s", $1
domcox@2 1067 }
domcox@2 1068 END{printf "\n"}'
domcox@2 1069 }
domcox@2 1070
domcox@2 1071 # convert a list of words to a regex
domcox@2 1072 regex()
domcox@2 1073 {
domcox@12 1074 printf "%s" "^$1$" | sed s'/ /$|^/g'
domcox@2 1075 }
domcox@2 1076
domcox@2 1077 # print dev from uuid
domcox@2 1078 uuid2dev()
domcox@2 1079 {
pascal@106 1080 local uuid="$1"
pascal@106 1081 if [ "${uuid%=*}" = "UUID" ]; then
pascal@106 1082 uuid="$(blkid | sed '/ UUID="'${uuid#*=}'"/!d;s|:.*||')"
domcox@2 1083 fi
pascal@106 1084 printf "%s" "$uuid"
domcox@2 1085 }
domcox@2 1086
domcox@2 1087 # print disk from uuid
domcox@2 1088 uuid2disk()
domcox@2 1089 {
pascal@106 1090 printf "%s" "$(uuid2dev $1 | /bin/busybox sed 's|p*[0-9]*$||')"
domcox@2 1091 }
domcox@2 1092
domcox@2 1093 dev2uuid()
domcox@2 1094 {
domcox@2 1095 local uuid="$1"
domcox@12 1096 if printf "%s" "$uuid" | grep -q dev; then
domcox@12 1097 printf "UUID=%s" "$(/sbin/blkid -p -i -o udev "$uuid" \
domcox@2 1098 | grep ID_FS_UUID= | cut -d '=' -f2)"
domcox@2 1099 else
domcox@12 1100 printf "%s" "$uuid"
domcox@2 1101 fi
domcox@2 1102 }
domcox@2 1103
domcox@2 1104 # print partition scheme from uuid
domcox@2 1105 p_table()
domcox@2 1106 {
domcox@2 1107 local uuid="$1" device
domcox@2 1108 device="$(uuid2disk $uuid)"
domcox@28 1109 printf "%s" "$(/usr/sbin/parted -lms 2>&1 | grep "$device" | \
domcox@2 1110 cut -d':' -f6)"
domcox@2 1111 }
domcox@2 1112
domcox@2 1113 # print filesystem from uuid
domcox@2 1114 filesys()
domcox@2 1115 {
domcox@2 1116 local uuid="$1"
domcox@2 1117 local fs="$(/sbin/blkid -s UUID -s TYPE | \
domcox@2 1118 grep "$(uuid2dev $uuid)" | cut -d' ' -f3)"
domcox@2 1119 fs="${fs#TYPE=\"}"
domcox@2 1120 fs="${fs%\"}"
domcox@12 1121 printf "%s" "$fs"
domcox@2 1122 }
domcox@2 1123
domcox@2 1124 # return removable status from uuid
domcox@2 1125 is_removable()
domcox@2 1126 {
pascal@106 1127 local removable=1
pascal@106 1128 local disk="$(uuid2disk $1 | sed 's|/dev/||')"
pascal@106 1129 if [ "$disk" ]; then
pascal@103 1130 [ "$(cat /sys/block/"$disk"/removable 2> /dev/null)" -gt "0" ] \
domcox@2 1131 && removable=0
domcox@2 1132 fi
domcox@2 1133 return "$removable"
domcox@2 1134 }
domcox@2 1135
domcox@2 1136 randomize_mirrors()
domcox@2 1137 {
domcox@2 1138 local list_mirrors
domcox@2 1139 if [ -r "$MIRRORS" ]; then
domcox@2 1140 # randomize list of mirrors
pascal@116 1141 list_mirrors="$(busybox awk 'BEGIN {srand()}{
domcox@2 1142 printf "%05.0f %s \n",rand()*99999, $0;
pascal@116 1143 }' < $MIRRORS | sort -n | sed 's/^[0-9]* //' )"
domcox@2 1144 else
al@73 1145 log "$(_ 'No mirror list found, run %s.' 'tazpkg recharge')"
domcox@2 1146 list_mirrors="http://mirror.slitaz.org/"
domcox@2 1147 fi
domcox@2 1148 MIRRORS="$list_mirrors"
domcox@2 1149 }
domcox@2 1150
domcox@2 1151 # download a file
domcox@2 1152 dnl()
domcox@2 1153 {
domcox@2 1154 local file="$1" mirror transfer=0 oldfile
domcox@2 1155 mkdir -p /tmp/tazinst
domcox@2 1156 for mirror in $MIRRORS; do
al@73 1157 log "$(_ 'Downloading: %s' "$mirror$file")"
domcox@12 1158 oldfile="$(printf "%s" $file | \
domcox@2 1159 /bin/busybox awk 'BEGIN{RS="/"}{text=$1}END{print text}')"
domcox@2 1160 [ -e "/tmp/tazinst/$oldfile" ] && rm -f "/tmp/tazinst/$oldfile"
domcox@2 1161 /bin/busybox wget $mirror$file -P /tmp/tazinst && transfer=1 && break
domcox@2 1162 done
domcox@2 1163 if [ "$transfer" -gt "0" ];then
al@73 1164 log "$(_ 'Download completed.')"
domcox@2 1165 else
pascal@116 1166 error 5 "$(_ '%s: Download failed.' "$file")"
domcox@2 1167 fi
domcox@2 1168 }
domcox@2 1169
domcox@2 1170 # install pkg in current system
domcox@2 1171 need_package()
domcox@2 1172 {
domcox@2 1173 local pkg="$1"
domcox@2 1174 if [ ! -d /var/lib/tazpkg/installed/$pkg ]; then
al@73 1175 log "$(_ 'Installing package %s to the current system.' "$pkg")"
domcox@2 1176 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
al@73 1177 /usr/bin/tazpkg get-install "$pkg" || error 5 "$(_ 'Cannot install %s.' "$pkg")"
domcox@2 1178 fi
domcox@2 1179 }
domcox@2 1180
domcox@2 1181 # install pkg in target system
domcox@2 1182 add_pkg()
domcox@2 1183 {
domcox@2 1184 local pkg="$1"
al@73 1185 log "$(_ 'Adding package %s to the target system...' "$pkg")"
domcox@2 1186 [ -z "$RECHARGE" ] && RECHARGE=true && /usr/bin/tazpkg recharge
domcox@2 1187 /usr/bin/tazpkg get "$pkg" >> "$LOG" 2>> "$LOG"
domcox@2 1188 yes "" | /usr/bin/tazpkg install $pkg.tazpkg \
domcox@2 1189 --root=$TARGET_ROOT >> "$LOG" 2>> "$LOG"
domcox@2 1190 rm -f $pkg.tazpkg
domcox@2 1191 }
domcox@2 1192
domcox@2 1193 #---------
domcox@2 1194 # 3.1 log
domcox@2 1195 #---------
domcox@2 1196
domcox@2 1197 # start log
domcox@2 1198 log_open()
domcox@2 1199 {
al@73 1200 _ '=== Tazinst: started on %s ===' "$(date "+%x %X")" > "$LOG"
domcox@2 1201 LOGGING="true"
domcox@2 1202 }
domcox@2 1203
domcox@2 1204 # print and log a comment
domcox@2 1205 log(){
domcox@2 1206 # for front-ends, sleep 1 if $1 is num
domcox@12 1207 printf "%s" "$1" | awk '{
domcox@2 1208 num=$1+0
domcox@2 1209 if(num>0 && num<=100)
domcox@2 1210 exit 0
domcox@2 1211 else
domcox@2 1212 exit 1
domcox@2 1213 }' && sleep 1
domcox@2 1214 # log
domcox@12 1215 printf "%s\n" "$1"
domcox@12 1216 [ -n "$LOGGING" ] && printf "%s\n" "$1" >> $LOG
domcox@2 1217 }
domcox@2 1218
domcox@2 1219 #--------------------
domcox@2 1220 # 3.2 error handling
domcox@2 1221 #--------------------
domcox@2 1222
domcox@2 1223 # print an error msg & exit
domcox@2 1224 error()
domcox@2 1225 {
al@73 1226 local error="$1" msg="$2" cancel="$(_ 'Process not completed')"
al@73 1227 _ 'Error: %s' "$msg" >&2; echo "$cancel" >&2
domcox@2 1228 if [ -n "$LOGGING" ]; then
domcox@2 1229 # 1st pattern
domcox@12 1230 echo "-x-x- " >> "$LOG"
al@73 1231 _ 'Error: %s' "$msg" >> "$LOG"; echo "$cancel" >> "$LOG"
domcox@2 1232 # 2nd pattern
domcox@12 1233 echo "x-x-x " >> "$LOG"
al@73 1234 _ '=== Tazinst error on %s ===' "$(date "+%x %X")" >> "$LOG"
domcox@2 1235 fi
domcox@2 1236 unset LOGGING
domcox@2 1237 umount_devices
domcox@2 1238 exit "$error"
domcox@2 1239 }
domcox@2 1240
domcox@2 1241 error8()
domcox@2 1242 {
al@73 1243 error 8 "$(_ 'Internal error')"
domcox@2 1244 }
domcox@2 1245
domcox@2 1246 error9()
domcox@2 1247 {
al@73 1248 error 9 "$(_ 'Cancelled by user')"
domcox@2 1249 }
domcox@2 1250
domcox@2 1251 #------------------
domcox@2 1252 # 4. disks section
domcox@2 1253 #------------------
domcox@2 1254
domcox@2 1255 #------------
domcox@2 1256 # 4.1 source
domcox@2 1257 #------------
domcox@2 1258
domcox@2 1259 # liveCD
domcox@2 1260 mount_cdrom()
domcox@2 1261 {
domcox@2 1262 # set device name
pascal@100 1263 local drive="$(grep "drive name" < \
pascal@100 1264 /proc/sys/dev/cdrom/info | cut -f 3)"
domcox@2 1265 [ -n "$drive" ] || drive=cdrom
domcox@2 1266 local cdrom=/dev/$drive
domcox@2 1267 # mount cdrom
domcox@2 1268 if mount -t iso9660 "$cdrom" "$SOURCE_ROOT" 2>>"$LOG"; then
al@73 1269 log "$(_ 'Using files from %s.' "$cdrom")"
domcox@2 1270 else
al@73 1271 error 3 "$(_ '%s: Mount failed.' "$cdrom")"
domcox@2 1272 fi
domcox@2 1273 }
domcox@2 1274
domcox@2 1275 # liveUSB
domcox@2 1276 mount_usb()
domcox@2 1277 {
domcox@2 1278 # /home is on LiveUSB
domcox@2 1279 if [ -d /home/boot ]; then
al@73 1280 log "$(_ 'Using files from USB device...')"
domcox@2 1281 ln -s /home/boot $SOURCE_ROOT/boot
domcox@2 1282 else
domcox@2 1283 # mount LiveUSB
domcox@2 1284 if mount "$SOURCE" "$SOURCE_ROOT" 2>>"$LOG"; then
al@73 1285 log "$(_ 'Using files from USB device %s.' "$SOURCE")"
domcox@2 1286 else
al@73 1287 error 3 "$(_ '%s: Failed to mount USB device.' "$SOURCE")"
domcox@0 1288 fi
domcox@0 1289 fi
domcox@0 1290 }
domcox@0 1291
domcox@2 1292 # ISO file on HDD
domcox@2 1293 mount_iso()
domcox@0 1294 {
domcox@2 1295 # check integrity
domcox@12 1296 local md5file=$(printf "%s" $SOURCE | sed 's/.iso$/.md5/')
domcox@2 1297 if [ -r "$md5file" ]; then
pascal@100 1298 local md5ref="$(cut -d' ' -f1 < "$md5file")"
domcox@2 1299 local md5calc="$(md5sum $SOURCE | cut -d' ' -f1)"
domcox@2 1300 if [ ! "$md5calc" = "$md5ref" ]; then
domcox@2 1301 log "md5sum iso=$md5ref md5sum tazinst=$md5calc"
al@73 1302 error 3 "$(_ 'md5sum error, file corrupted.')"
domcox@0 1303 fi
domcox@2 1304 else
al@73 1305 log "$(_ '%s: md5 file not found, cannot check integrity.' "$SOURCE")"
domcox@2 1306 fi
domcox@2 1307 # mount ISO
domcox@2 1308 if mount -o loop -t iso9660 "$SOURCE" \
domcox@2 1309 "$SOURCE_ROOT" 2>>"$LOG"; then
al@73 1310 log "$(_ 'Using files from ISO %s.' "$SOURCE")"
domcox@2 1311 else
al@73 1312 error 3 "$(_ '%s: Failed to mount ISO.' "$SOURCE")"
domcox@2 1313 fi
domcox@0 1314 }
domcox@0 1315
domcox@2 1316 # ISO file on the web
domcox@2 1317 mount_web()
domcox@2 1318 {
domcox@12 1319 if (printf "%s" "$SOURCE" | egrep -q "$(regex "$(list web)")"); then
domcox@2 1320 SOURCE="$(list web $SOURCE)"
domcox@2 1321 fi
domcox@2 1322 dnl "$SOURCE"
domcox@12 1323 local md5file="$(printf "%s" $SOURCE | sed 's/.iso$/.md5/')"
domcox@2 1324 dnl "$md5file"
domcox@12 1325 local webiso="$(printf "%s" $SOURCE | \
domcox@12 1326 /bin/busybox awk 'BEGIN{RS="/"}{out=$1} END{printf "%s",out}')"
domcox@2 1327 SOURCE="/tmp/tazinst/$webiso"
domcox@2 1328 mount_iso
domcox@2 1329 }
domcox@2 1330
al@68 1331 # set up source and check SliTaz' content
domcox@2 1332 mount_source()
domcox@2 1333 {
al@73 1334 log "$(_ 'Creating mount point: %s...' "$SOURCE_ROOT")"
domcox@2 1335 mkdir -p "$SOURCE_ROOT"
domcox@2 1336 case "$MEDIA" in
domcox@2 1337 cdrom)
domcox@2 1338 mount_cdrom ;;
domcox@2 1339 usb)
domcox@2 1340 mount_usb ;;
domcox@2 1341 iso)
domcox@2 1342 mount_iso ;;
domcox@2 1343 web)
domcox@2 1344 mount_web ;;
domcox@2 1345 *)
domcox@2 1346 error8 ;;
domcox@2 1347 esac
domcox@2 1348
domcox@2 1349 # exit if no rootfs.gz found.
al@73 1350 log "$(_ 'Checking installation media...')"
pascal@116 1351 if [ ! -f $SOURCE_ROOT/boot/rootfs.gz ] &&
pascal@116 1352 [ ! -f $SOURCE_ROOT/boot/rootfs1.gz ]; then
al@73 1353 error 3 "$(_ 'Invalid source')"
domcox@2 1354 else
al@73 1355 log "$(_ 'Installation media checked ok')"
domcox@2 1356 fi
domcox@2 1357 }
domcox@2 1358
domcox@2 1359 #------------
domcox@2 1360 # 4.2 target
domcox@2 1361 #------------
domcox@2 1362
domcox@2 1363 # format a partition
domcox@2 1364 format()
domcox@2 1365 {
domcox@2 1366 local uuid="$1" fmt="$2" dest="$3" dev format
al@73 1367 log "$(_ 'Format %s (%s)' "$uuid" "$fmt")"
domcox@2 1368 format="mkfs.$fmt"
domcox@12 1369 if (printf "%s" "$uuid" | grep -q "UUID="); then
domcox@2 1370 # case UUID=
domcox@2 1371 dev="$(uuid2dev $uuid)"
al@73 1372 "$format" "$dev" >>"$LOG" 2>>"$LOG" || error 4 "$(_ 'Formatting has failed')"
domcox@2 1373 # uuid has changed
domcox@2 1374 case "$dest" in
domcox@2 1375 root_uuid)
domcox@2 1376 ROOT_UUID="$(/sbin/blkid -p "$dev" -o export | \
domcox@2 1377 grep ^UUID=)" ;;
domcox@2 1378 home_uuid)
domcox@2 1379 HOME_UUID="$(/sbin/blkid -p "$dev" -o export | \
domcox@2 1380 grep ^UUID=)" ;;
domcox@2 1381 esac
domcox@2 1382 else
domcox@2 1383 # case /dev/xxxx
al@73 1384 "$format" $uuid >>"$LOG" 2>>"$LOG" || error 4 "$(_ 'Formatting has failed')"
domcox@2 1385 fi
domcox@2 1386 }
domcox@2 1387
domcox@2 1388 # prepare partitions
domcox@2 1389 prepare_uuid()
domcox@2 1390 {
al@73 1391 log "$(_ 'Preparing target partition...')"
domcox@2 1392 local uuid
domcox@2 1393 # target may be in use
domcox@24 1394 if mount | grep -q "$ROOT_UUID" ;then
al@73 1395 log "$(_ 'Partition is already mounted, unmounting.')"
domcox@24 1396 umount "$ROOT_UUID"
domcox@24 1397 fi
domcox@2 1398 mount | grep -q "$ROOT_UUID" && \
al@73 1399 error 4 "$ROOT_UUID: $(_ 'Partition is already in use.')"
domcox@2 1400 # Mount point can be already used.
domcox@2 1401 mount | grep -q "$TARGET_ROOT" && \
domcox@2 1402 umount "$TARGET_ROOT" 2>>"$LOG"
domcox@2 1403
domcox@2 1404 # Formatting root partition
domcox@2 1405 case "$ROOT_FORMAT" in
domcox@2 1406 "")
al@73 1407 log "$(_ '%s: The partition will be cleaned...' "$ROOT_UUID")" ;;
domcox@2 1408 *)
domcox@2 1409 format "$ROOT_UUID" "$ROOT_FORMAT" root_uuid
domcox@2 1410 esac
domcox@2 1411
domcox@2 1412 # Formatting /home
domcox@2 1413 if [ -n "$HOME_UUID" ]; then
domcox@2 1414 case "$HOME_FORMAT" in
domcox@2 1415 "")
al@73 1416 log "$(_ '%s: The partition will be kept...' "$HOME_UUID")" ;;
domcox@2 1417 *)
domcox@2 1418 format "$HOME_UUID" "$HOME_FORMAT" home_uuid
domcox@2 1419 esac
domcox@2 1420 fi
domcox@2 1421
al@73 1422 log "$(_ 'Creating mount point: %s...' "$TARGET_ROOT")"
domcox@2 1423 mkdir -p "$TARGET_ROOT" >> "$LOG" || error8
domcox@2 1424 # Mount target.
domcox@2 1425 local mount_fs="$ROOT_FORMAT"
domcox@2 1426 [ -z "$mount_fs" ] && mount_fs="$(filesys $ROOT_UUID)"
domcox@2 1427 mount -t "$mount_fs" "$ROOT_UUID" \
domcox@2 1428 "$TARGET_ROOT" >>"$LOG" 2>>"$LOG"
domcox@2 1429 if [ $(mount | \
pascal@116 1430 grep -c "mnt/target") -eq 0 ]; then
al@73 1431 error 4 "$(_ '%s: Unable to mount partition' "$ROOT_UUID")"
domcox@2 1432 fi
domcox@2 1433 }
domcox@2 1434
domcox@2 1435
domcox@2 1436 #------------
domcox@2 1437 # 4.3 umount
domcox@2 1438 #------------
domcox@2 1439
domcox@2 1440 # copy log file, umount target and eject cdrom.
domcox@2 1441 umount_devices()
domcox@2 1442 {
domcox@2 1443 # umount target
domcox@2 1444 if mount | grep -q "$TARGET_ROOT"; then
al@73 1445 log "$(_ 'Unmounting target partition: %s' "$ROOT_UUID")"
domcox@2 1446 umount -l "$TARGET_ROOT" 2>>$LOG
domcox@2 1447 fi
domcox@2 1448
domcox@2 1449 # umount source
domcox@2 1450 if mount | grep -q "$SOURCE_ROOT"; then
al@73 1451 log "$(_ 'Unmounting: %s' "$SOURCE_ROOT")"
domcox@2 1452 umount -l "$SOURCE_ROOT"
domcox@2 1453 fi
domcox@2 1454 if [ -h $SOURCE_ROOT/boot ]; then
al@73 1455 log "$(_ 'Unlinking: %s' "$SOURCE_ROOT")"
domcox@2 1456 rm -f $SOURCE_ROOT/boot
domcox@2 1457 fi
domcox@2 1458
domcox@2 1459 # eject cd
pascal@98 1460 if [ "$SOURCE" = "cdrom" ]; then
al@73 1461 _ 'Ejecting CD-ROM...'
domcox@2 1462 eject
domcox@2 1463 fi
domcox@2 1464 # remove lock file
domcox@2 1465 rm -f "$LOCK"
domcox@2 1466 }
domcox@2 1467
domcox@2 1468 end_of_install()
domcox@2 1469 {
al@73 1470 log "$(_ 'Process completed. You can now restart (reboot) from your SliTaz GNU/Linux system.' |\
al@73 1471 fold -s)"
al@73 1472 _ '=== Tazinst ended on %s ===' "$(date "+%x %X")" >> "$LOG"
domcox@2 1473 unset LOGGING
domcox@2 1474 # saving log
al@73 1475 log "$(_ 'Copying log to %s' '/var/log/tazinst.log')"
domcox@2 1476 cp -a "$LOG" $TARGET_ROOT/var/log
domcox@2 1477 umount_devices
domcox@2 1478 }
domcox@2 1479
domcox@2 1480
domcox@2 1481 #---------------
domcox@2 1482 # 5. bootloader
domcox@2 1483 #---------------
domcox@2 1484
domcox@2 1485 #------------
domcox@2 1486 # 5.1 common
domcox@2 1487 #------------
domcox@2 1488
domcox@2 1489 # selection
domcox@2 1490 bootloader()
domcox@2 1491 {
pascal@98 1492 if [ "$BOOTLOADER" = "auto" ]; then
domcox@2 1493 # use syslinux, but if p_table=msdos take grub (if available)
domcox@2 1494 unset BOOTLOADER
domcox@12 1495 printf "%s" "$(list_bootloader)" | \
domcox@2 1496 grep -q "syslinux" && BOOTLOADER=syslinux
pascal@98 1497 if [ "$(p_table $ROOT_UUID)" = "msdos" ]; then
domcox@12 1498 printf "%s" "$(list_bootloader)" | \
domcox@2 1499 grep -q " grub" && BOOTLOADER=grub
domcox@2 1500 fi
domcox@2 1501 fi
domcox@2 1502 case "$BOOTLOADER" in
domcox@2 1503 grub)
domcox@2 1504 grub_config
domcox@2 1505 grub_install ;;
domcox@2 1506 syslinux)
domcox@2 1507 syslinux_config
domcox@2 1508 syslinux_install ;;
domcox@2 1509 *)
domcox@2 1510 syslinux_config
al@73 1511 log "$(_ 'No bootloader to install.')" ;;
domcox@2 1512 esac
pascal@106 1513 [ -d /sys/firmware/efi ] && efiboot_install
domcox@2 1514 }
domcox@2 1515
domcox@2 1516 # print disk num
domcox@2 1517 disknum()
domcox@2 1518 {
pascal@106 1519 local disk="$(uuid2dev $1 | /bin/busybox sed 's|p*[0-9]*$||')"
domcox@28 1520 /usr/sbin/parted -lms 2>&1 | grep "^/dev" | \
pascal@106 1521 /bin/busybox awk -v PART="$disk:" '{if (match($0,PART)) print NR-1}'
domcox@2 1522 }
domcox@2 1523
domcox@2 1524 # print partition num
domcox@2 1525 partnum()
domcox@2 1526 {
pascal@106 1527 printf "%s" "$(($(uuid2dev $1 | /bin/busybox sed 's|.*[^0-9]||')-1))"
domcox@2 1528 }
domcox@2 1529
domcox@2 1530 # print root device
domcox@2 1531 rootdev()
domcox@2 1532 {
domcox@2 1533 local partition="$1"
domcox@2 1534 case "$(p_table $partition)" in
domcox@2 1535 msdos)
domcox@2 1536 # print device
domcox@12 1537 printf "%s" "$(uuid2dev $partition)" ;;
domcox@2 1538 gpt)
domcox@2 1539 # print PARTUUID (different from UUID)
domcox@12 1540 printf "%s" "PARTUUID="
domcox@2 1541 /sbin/blkid -p -i -o udev $(uuid2dev $partition) \
domcox@2 1542 | grep ENTRY_UUID | cut -d '=' -f2 ;;
domcox@2 1543 esac
domcox@2 1544 }
domcox@2 1545
domcox@2 1546 # add rootdelay for removable devices
domcox@2 1547 rootdelay()
domcox@2 1548 {
pascal@106 1549 is_removable "$ROOT_UUID" && printf "%s" " rootdelay=9"
domcox@2 1550 }
domcox@2 1551
domcox@2 1552 # print winboot uuid
domcox@2 1553 winboot_uuid()
domcox@2 1554 {
domcox@2 1555 if [ "$WINBOOT" = "auto" ]; then
domcox@2 1556 # get the first uuid if any
domcox@2 1557 [ $(list_winboot | wc -w) -gt 1 ] \
domcox@12 1558 && printf "%s" "$(list_winboot | cut -d' ' -f2)"
domcox@2 1559 else
domcox@12 1560 printf "%s" "$WINBOOT"
domcox@2 1561 fi
domcox@2 1562 }
domcox@2 1563
domcox@2 1564
domcox@2 1565 #-----------
domcox@2 1566 # 5.1 grub1
domcox@2 1567 #-----------
domcox@2 1568
pascal@113 1569 grub_password_command()
pascal@113 1570 {
pascal@113 1571 grub --batch 2> /dev/null <<EOT | sed '/^Encrypted/!d;s|^Encrypted: |password --md5 |'
pascal@113 1572 md5crypt
pascal@113 1573 $ROOT_PWD
pascal@113 1574 EOT
pascal@113 1575 }
pascal@113 1576
domcox@2 1577 # create grub legacy conf
domcox@0 1578 grub_config()
domcox@0 1579 {
domcox@2 1580 # backup an existing conf
domcox@2 1581 [ -e "$TARGET_ROOT/boot/grub/menu.lst" ] && \
domcox@2 1582 cp $TARGET_ROOT/boot/grub/menu.lst \
domcox@2 1583 $TARGET_ROOT/boot/grub/menu.bak
domcox@2 1584 # create the target GRUB configuration.
domcox@2 1585 mkdir -p $TARGET_ROOT/boot/grub || error8
al@73 1586 cat > $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
domcox@0 1587 # /boot/grub/menu.lst: GRUB boot loader configuration.
domcox@0 1588 #
domcox@0 1589
domcox@0 1590 # By default, boot the first entry.
domcox@0 1591 default 0
domcox@0 1592
domcox@0 1593 # Boot automatically after 8 secs.
domcox@0 1594 timeout 8
domcox@0 1595
domcox@0 1596 # Graphical splash image.
domcox@0 1597 splashimage=/boot/grub/splash.xpm.gz
domcox@0 1598
pascal@113 1599 # Root password is required for edition
pascal@113 1600 $(grub_password_command)
pascal@113 1601
domcox@0 1602 # Change the colors.
domcox@0 1603 #color yellow/brown light-green/black
domcox@0 1604
domcox@2 1605 # For booting SliTaz from : $ROOT_UUID
domcox@0 1606 #
domcox@2 1607 title SliTaz GNU/Linux $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
domcox@2 1608 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
pascal@106 1609 kernel /boot/$KERNEL root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
domcox@0 1610
domcox@0 1611 _EOF_
domcox@2 1612
pascal@112 1613 if [ -n "$LIVEBOOT" ]; then
pascal@112 1614 local rootfs_files="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls rootfs*)"
pascal@112 1615 log "$(_ 'Enabling live/rescue boot with %s' "$rootfs_files")"
pascal@112 1616 for i in $rootfs_files; do
pascal@112 1617 [ -s $TARGET_ROOT/boot/$i ] &&
pascal@112 1618 mv $TARGET_ROOT/boot/$i $TARGET_ROOT/boot/$i.bak
pascal@112 1619 mv $TARGET_ROOT/boot/tazinst.$$/$i $TARGET_ROOT/boot/
pascal@112 1620 done
pascal@112 1621 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
pascal@112 1622 # For booting SliTaz Live from : $ROOT_UUID
pascal@112 1623 #
pascal@112 1624 title SliTaz GNU/Linux rescue $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
pascal@115 1625 $(grub_password_command)
pascal@112 1626 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
pascal@112 1627 kernel /boot/$KERNEL $(sed 's|.*gz ||' /proc/cmdline)
pascal@112 1628 initrd /boot/$ROOTFS
pascal@112 1629
pascal@112 1630 _EOF_
pascal@112 1631 fi
pascal@112 1632
pascal@116 1633 if [ -n "$WEBBOOT" ] && [ -n "$IPXE" ]; then
pascal@112 1634 log "$(_ 'Enabling Webboot using %s' $IPXE)"
pascal@112 1635 mv -f $TARGET_ROOT/boot/tazinst.$$/$IPXE $TARGET_ROOT/boot/
pascal@112 1636 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
pascal@112 1637 # For booting SliTaz Live from the web
pascal@112 1638 #
pascal@112 1639 title SliTaz GNU/Linux web boot
pascal@115 1640 $(grub_password_command)
pascal@112 1641 root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
pascal@112 1642 kernel /boot/$IPXE
pascal@112 1643
pascal@112 1644 _EOF_
pascal@112 1645 fi
pascal@112 1646 rm -rf $TARGET_ROOT/boot/tazinst.$$ 2> /dev/null
pascal@112 1647
domcox@2 1648 local winpart="$(winboot_uuid)"
domcox@2 1649 if [ -n "$winpart" ]; then
al@73 1650 log "$(_ 'Enabling Windows dual-boot')"
al@73 1651 cat >> $TARGET_ROOT/boot/grub/menu.lst <<_EOF_
domcox@0 1652 # For booting Windows :
domcox@0 1653 #
domcox@0 1654 title Microsoft Windows
domcox@2 1655 rootnoverify (hd$(disknum $winpart),$(partnum $winpart))
domcox@0 1656 chainloader +1
domcox@0 1657
domcox@0 1658 _EOF_
domcox@0 1659 fi
domcox@2 1660
domcox@0 1661 # log
domcox@12 1662 printf "%s\n" "/boot/grub/menu.lst:" >> "$LOG"
domcox@12 1663 printf "%s\n" "--- menu.lst -------------" >> "$LOG"
domcox@2 1664 cat $TARGET_ROOT/boot/grub/menu.lst >> "$LOG"
domcox@12 1665 printf "%s\n\n" "--- menu.lst -------------" >> "$LOG"
domcox@0 1666 }
domcox@0 1667
domcox@2 1668 # GRUB info with disk name used for grub
domcox@0 1669 grub_install()
domcox@0 1670 {
domcox@2 1671 # install grub
domcox@2 1672 local target_disk="$(uuid2disk $ROOT_UUID)"
al@73 1673 log "$(_ 'Installing GRUB on: %s' "$target_disk")"
al@73 1674 /usr/sbin/grub-install --version >> "$LOG" || error 5 "$(_ 'GRUB not found')"
domcox@2 1675 /usr/sbin/grub-install --no-floppy \
domcox@2 1676 --root-directory=$TARGET_ROOT $target_disk >>"$LOG" 2>>"$LOG"
domcox@2 1677 # set boot flag
al@73 1678 log "$(_ 'Setting the boot flag')"
domcox@2 1679 /usr/sbin/parted "$(uuid2disk $ROOT_UUID)" \
domcox@2 1680 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
domcox@2 1681 # splash image
domcox@2 1682 if [ -f "$SOURCE_ROOT/boot/grub/splash.xpm.gz" ]; then
al@73 1683 log "$(_ 'Copying splash image')"
domcox@2 1684 mkdir -p $TARGET_ROOT/boot/grub
domcox@2 1685 cp $SOURCE_ROOT/boot/grub/splash.xpm.gz \
domcox@2 1686 $TARGET_ROOT/boot/grub
domcox@0 1687 fi
domcox@0 1688 }
domcox@0 1689
domcox@2 1690
domcox@2 1691 #--------------
domcox@2 1692 # 5.2 syslinux
domcox@2 1693 #--------------
domcox@2 1694
domcox@2 1695 # create syslinux conf
domcox@2 1696 syslinux_config()
domcox@0 1697 {
domcox@2 1698 local version="[$(cat $TARGET_ROOT/etc/slitaz-release)]"
domcox@2 1699 version="$version\(Kernel $KERNEL)"
domcox@2 1700 # backup an existing conf
domcox@2 1701 [ -e "$TARGET_ROOT/boot/syslinux/syslinux.cfg" ] && \
domcox@2 1702 cp $TARGET_ROOT/boot/syslinux/syslinux.cfg \
domcox@2 1703 $TARGET_ROOT/boot/syslinux/syslinux.bak
domcox@2 1704 # create the target syslinux configuration.
domcox@2 1705 mkdir -p $TARGET_ROOT/boot/syslinux || error8
al@73 1706 cat > $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
domcox@2 1707 # use a boot menu
domcox@2 1708 UI vesamenu.c32
domcox@2 1709
domcox@2 1710 # display the boot
domcox@2 1711 PROMPT 1
domcox@2 1712
domcox@2 1713 # how long to pause at the boot
domcox@2 1714 TIMEOUT 50
domcox@2 1715
domcox@2 1716 # default label
domcox@2 1717 DEFAULT slitaz
domcox@2 1718
domcox@2 1719 # Menu settings
domcox@2 1720 MENU TITLE SliTaz GNU/Linux boot menu
domcox@2 1721 MENU BACKGROUND splash.jpg
domcox@2 1722 MENU WIDTH 78
domcox@2 1723 MENU MARGIN 6
domcox@2 1724 MENU ROW 10
domcox@2 1725 MENU VSHIFT 2
domcox@2 1726 MENU TIMEOUTROW 18
domcox@2 1727 MENU TABMSGROW 16
domcox@2 1728 MENU CMDLINEROW 16
domcox@2 1729
domcox@2 1730 # Menu colors
domcox@2 1731 MENU COLOR border * #00000000 #00000000 none
al@73 1732 MENU COLOR title * #ffffffff #00000000 *
domcox@2 1733 MENU COLOR sel 0 #ffffffff #00000000 none
domcox@2 1734 MENU COLOR unsel 0 #50ffffff #00000000 none
al@73 1735 MENU COLOR help * #ffffffff #00000000 *
domcox@2 1736 MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
domcox@2 1737 MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
domcox@2 1738 MENU COLOR msg07 37;40 #90ffffff #a0000000 std
domcox@2 1739 MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
domcox@2 1740
domcox@2 1741 # Labels
domcox@2 1742 LABEL slitaz
domcox@2 1743 MENU LABEL SliTaz GNU/Linux $version
domcox@2 1744 LINUX /boot/$KERNEL
pascal@106 1745 APPEND root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
domcox@2 1746
pascal@112 1747 EOF
pascal@112 1748 if [ -n "$LIVEBOOT" ]; then
pascal@112 1749 local rootfs_files="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls rootfs*)"
pascal@112 1750 log "$(_ 'Enabling live/rescue boot with %s' "$rootfs_files")"
pascal@112 1751 for i in $rootfs_files; do
pascal@112 1752 [ -s $TARGET_ROOT/boot/$i ] &&
pascal@112 1753 mv $TARGET_ROOT/boot/$i $TARGET_ROOT/boot/$i.bak
pascal@112 1754 mv $TARGET_ROOT/boot/tazinst.$$/$i $TARGET_ROOT/boot/
pascal@112 1755 done
pascal@112 1756 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
pascal@112 1757 LABEL live rescue
pascal@112 1758 MENU LABEL SliTaz GNU/Linux live/rescue $version
pascal@112 1759 LINUX /boot/$KERNEL
pascal@112 1760 INITRD /boot/$ROOTFS
pascal@112 1761 APPEND root=$(rootdev $ROOT_UUID) $(sed 's|.*gz ||' /proc/cmdline)
pascal@112 1762
pascal@112 1763 EOF
pascal@112 1764 fi
pascal@112 1765
pascal@116 1766 if [ -n "$WEBBOOT" ] && [ -n "$IPXE" ]; then
pascal@112 1767 log "$(_ 'Enabling Webboot using %s' $IPXE)"
pascal@112 1768 mv -f $TARGET_ROOT/boot/tazinst.$$/$IPXE $TARGET_ROOT/boot/
pascal@112 1769 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
pascal@112 1770 LABEL web zeb
pascal@112 1771 MENU LABEL SliTaz GNU/Linux web boot
pascal@112 1772 LINUX /boot/$IPXE
pascal@112 1773
pascal@112 1774 EOF
pascal@112 1775 fi
pascal@112 1776 rm -rf $TARGET_ROOT/boot/tazinst.$$ 2> /dev/null
pascal@112 1777
pascal@112 1778 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
domcox@2 1779 LABEL cmdline
domcox@2 1780 MENU LABEL Command Line
domcox@2 1781 MENU QUIT
domcox@2 1782
domcox@2 1783 EOF
domcox@2 1784 local winpart="$(winboot_uuid)"
domcox@2 1785 if [ -n "$winpart" ]; then
al@73 1786 log "$(_ 'Enabling Windows dual-boot')"
al@73 1787 cat >> $TARGET_ROOT/boot/syslinux/syslinux.cfg <<EOF
domcox@2 1788 LABEL windows
domcox@2 1789 MENU LABEL Windows
domcox@2 1790 COM32 chain.c32
domcox@2 1791 APPEND hd$(disknum $winpart) $(($(partnum $winpart)+1))
domcox@2 1792
domcox@2 1793 EOF
domcox@0 1794 fi
domcox@2 1795 # log
domcox@12 1796 printf "%s\n" "/boot/syslinux/syslinux.cfg:" >> "$LOG"
domcox@12 1797 printf "%s\n" "--- syslinux.cfg -------------" >> "$LOG"
domcox@2 1798 cat $TARGET_ROOT/boot/syslinux/syslinux.cfg >> "$LOG"
domcox@12 1799 printf "%s\n\n" "--- syslinux.cfg -------------" >> "$LOG"
domcox@0 1800 }
domcox@0 1801
domcox@2 1802 # install syslinux
domcox@2 1803 syslinux_install()
domcox@0 1804 {
al@73 1805 log "$(_ 'Installing Syslinux')"
domcox@2 1806 # needed tools
domcox@2 1807 local dir disk="$(uuid2disk $ROOT_UUID)"
pascal@107 1808 for dir in /home/boot/extlinux /home/boot/syslinux /boot/syslinux /boot/isolinux; do
pascal@107 1809 [ -d "$dir" ] && cp $dir/*.c32 $dir/*.sys "$TARGET_ROOT/boot/syslinux/"
domcox@2 1810 done
pascal@107 1811 cp /usr/share/boot/chain.c32 $TARGET_ROOT/boot/syslinux/chain.c32 2>> "$LOG"
domcox@2 1812 # install syslinux
al@73 1813 /bin/syslinux -version >> "$LOG" || error 5 "$(_ 'Syslinux not found')"
domcox@2 1814 /bin/extlinux --install $TARGET_ROOT/boot/syslinux >> "$LOG" 2>> "$LOG"
domcox@2 1815 case "$(p_table $ROOT_UUID)" in
domcox@2 1816 msdos)
al@73 1817 log "$(_ 'Setting the boot flag on')"
domcox@2 1818 /usr/sbin/parted "$disk" \
domcox@2 1819 set "$(($(partnum $ROOT_UUID)+1))" boot on 2>> "$LOG"
al@73 1820 [ -r /usr/share/boot/mbr.bin ] || error 5 "$(_ 'mbr.bin not found')"
al@73 1821 log "$(_ 'Installing MBR')"
domcox@2 1822 dd bs=440 count=1 conv=notrunc \
domcox@2 1823 if=/usr/share/boot/mbr.bin of=$disk >> "$LOG" ;;
domcox@2 1824 gpt)
al@73 1825 log "$(_ 'Setting the legacy_boot flag on')"
domcox@2 1826 # remove old boot flag
domcox@2 1827 local oldboot="$(parted $disk print \
domcox@2 1828 | grep boot | /bin/busybox awk '{print $1}')"
domcox@2 1829 /usr/sbin/parted "$disk" \
domcox@2 1830 set "$oldboot" legacy_boot off 2>> "$LOG"
domcox@2 1831 # set boot flag
domcox@2 1832 /usr/sbin/parted "$disk" \
domcox@2 1833 set "$(($(partnum $ROOT_UUID)+1))" legacy_boot on 2>> "$LOG"
al@73 1834 log "$(_ 'Installing GPTMBR')"
al@73 1835 [ -r /usr/share/boot/gptmbr.bin ] || error 5 "$(_ 'gptmbr.bin not found')"
domcox@2 1836 dd bs=440 conv=notrunc count=1 \
domcox@2 1837 if=/usr/share/boot/gptmbr.bin of=$disk >> "$LOG" ;;
domcox@2 1838 esac
domcox@2 1839 # splash image
domcox@2 1840 if [ -f "$SOURCE_ROOT/boot/isolinux/splash.jpg" ]; then
al@73 1841 log "$(_ 'Copying splash image')"
domcox@2 1842 cp -a $SOURCE_ROOT/boot/isolinux/splash.jpg \
domcox@2 1843 $TARGET_ROOT/boot/syslinux
domcox@0 1844 fi
domcox@0 1845 }
domcox@0 1846
domcox@2 1847
pascal@106 1848 #-------------
pascal@106 1849 # 5.3 efiboot
pascal@106 1850 #-------------
pascal@106 1851
pascal@106 1852 efiboot_install()
pascal@106 1853 {
pascal@106 1854 local esp_fs_uuid mnt="/media/esp$$" efiboot="/EFI/SLITAZ"
pascal@106 1855 # We need efi stub support
pascal@116 1856 strings $TARGET_ROOT/boot/$KERNEL | head | grep -q reloc || return
pascal@106 1857 # And the esp partition
pascal@106 1858 esp_fs_uuid="$(blkid | sed '/EFI system partition/!d;s|.* UUID="||;s|".*||;q')"
pascal@106 1859 [ "$esp_fs_uuid" ] || return
pascal@106 1860 # Copy SliTaz kernel and cmdline in esp partition
pascal@106 1861 mkdir $mnt &&
pascal@106 1862 mount "$(uuid2dev UUID=$esp_fs_uuid)" $mnt &&
pascal@106 1863 mkdir -p $mnt$efiboot 2> /dev/null
pascal@106 1864 if cp $TARGET_ROOT/boot/$KERNEL $mnt$efiboot/BZIMAGE.EFI; then
pascal@106 1865 log "$(_ 'Updating UEFI boot files')"
pascal@106 1866 echo "root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)" > $mnt$efiboot/linux.cmdline
pascal@106 1867 efibootmgr -v | grep -q SliTaz ||
pascal@106 1868 efibootmgr -c -d "$(uuid2disk UUID=$esp_fs_uuid)" -p "$(partnum UUID=$esp_fs_uuid)" \
pascal@106 1869 -L "SliTaz GNU/Linux" -l "${efiboot//\//\\}\\BZIMAGE.EFI"
pascal@106 1870 fi
pascal@106 1871 umount $mnt && rmdir $mnt
pascal@106 1872 }
pascal@106 1873
domcox@2 1874 #--------------------
domcox@2 1875 # 6. execute section
domcox@2 1876 #--------------------
domcox@2 1877
domcox@2 1878 execute()
domcox@2 1879 {
domcox@2 1880 local mode="$(get mode)" sighup=1 sigint=2 sigquit=3
domcox@2 1881 randomize_mirrors
domcox@2 1882 trap "error9" "$sighup" "$sigint" "$sigquit"
domcox@2 1883 case "$mode" in
domcox@2 1884 install)
domcox@2 1885 install ;;
domcox@2 1886 upgrade)
domcox@2 1887 upgrade ;;
domcox@2 1888 esac
domcox@2 1889 }
domcox@2 1890
domcox@2 1891 #-------------
domcox@2 1892 # 6.1 install
domcox@2 1893 #-------------
domcox@2 1894
domcox@2 1895 # get a clean target device
domcox@2 1896 clean_target()
domcox@2 1897 {
domcox@2 1898 if [ -z "$ROOT_FORMAT" ]; then
domcox@2 1899 # partition was not formatted
al@73 1900 log "$(_ 'Cleaning the root partition (%s)...' "$ROOT_UUID")"
domcox@2 1901 # keep /home in case of reinstall.
domcox@2 1902 local path="$(pwd)"
domcox@2 1903 cd "$TARGET_ROOT" || error8
domcox@2 1904 local dir
domcox@2 1905 for dir in *
domcox@2 1906 do
domcox@2 1907 case "$dir" in
domcox@2 1908 home)
al@73 1909 log "$(_ 'keeping /home found on: %s' "$ROOT_UUID")"
domcox@2 1910 mv home home.bak ;;
domcox@2 1911 lost+found)
domcox@2 1912 continue ;;
domcox@2 1913 *)
al@73 1914 log "$(_ 'removing target: %s' "$dir")"
domcox@2 1915 rm -rf "$dir" 2>>"$LOG" ;;
domcox@2 1916 esac
domcox@2 1917 done
domcox@2 1918 if [ ! -d lost+found ]; then
domcox@2 1919 mklost+found 2>>"$LOG"
domcox@2 1920 fi
domcox@2 1921 cd "$path" || error8
domcox@2 1922 fi
domcox@2 1923 }
domcox@2 1924
domcox@2 1925 # kernel is renamed to standard vmlinuz-$VERSION.
domcox@2 1926 install_kernel()
domcox@2 1927 {
pascal@108 1928 KERNEL="vmlinuz-$(uname -r)"
pascal@108 1929 [ -d /$TARGET_ROOT/lib/modules/$(uname -r) ] ||
al@73 1930 log "$(_ 'Kernel name not found, falling back to: %s' "$(uname -r)")"
domcox@2 1931 mkdir -p $TARGET_ROOT/boot || error8
pascal@40 1932 for i in $SOURCE_ROOT/boot/bzImage* ; do
pascal@56 1933 cp $i $TARGET_ROOT/boot/${KERNEL%slitaz*}slitaz${i#*bzImage}
pascal@40 1934 done
pascal@112 1935 mkdir $TARGET_ROOT/boot/tazinst.$$
pascal@112 1936 for i in $(ls -r $SOURCE_ROOT/boot/rootfs?*.gz 2> /dev/null | sed q) \
pascal@112 1937 $SOURCE_ROOT/boot/rootfs.gz $SOURCE_ROOT/boot/*pxe* ; do
pascal@112 1938 cp $i $TARGET_ROOT/boot/tazinst.$$/
pascal@112 1939 done
pascal@112 1940 IPXE="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls *pxe* 2> /dev/null)"
pascal@112 1941 ROOTFS="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls rootfs.* 2> /dev/null)"
pascal@112 1942 [ -n "$ROOTFS" ] ||
pascal@112 1943 ROOTFS="$(cd $TARGET_ROOT/boot/tazinst.$$ ; ls -r rootfs?*.* | sed q)"
al@73 1944 log "$(_ 'install_kernel: %s' "$KERNEL")"
domcox@2 1945 }
domcox@2 1946
domcox@2 1947 # extract packed rootfs: squashfs or cromfs
domcox@2 1948 extract_loramfs()
domcox@2 1949 {
domcox@2 1950 local i
domcox@2 1951 for i in $(/bin/busybox cpio -idvum 2> /dev/null); do
domcox@2 1952 case "$i" in
domcox@2 1953 rootfs*)
domcox@2 1954 need_package squashfs
domcox@2 1955 if ! unsquashfs $i ; then
domcox@2 1956 need_package cromfs
domcox@2 1957 unmkcromfs $i squashfs-root
domcox@2 1958 fi
domcox@2 1959 mv -f squashfs-root/* .
domcox@2 1960 rmdir squashfs-root
domcox@2 1961 rm -f $i
domcox@2 1962 esac
domcox@2 1963 done
domcox@2 1964 }
domcox@2 1965
domcox@2 1966 # this is a loram rootfs.gz, skip loram bootstrap and extract
domcox@2 1967 extract_first_loramfs()
domcox@2 1968 {
domcox@2 1969 local path="$(pwd)"
pascal@58 1970 (zcat $1 || /usr/bin/unlzma < $1) | \
domcox@2 1971 /bin/busybox cpio -i extractfs.cpio 2> /dev/null &&
domcox@2 1972 ( cd / ; /bin/busybox cpio -id ) < extractfs.cpio && \
domcox@2 1973 rm -f extractfs.cpio
domcox@2 1974 ofs=$(/bin/busybox awk '/07070100/ { o+=index($0,"07070100"); printf "%d\n",o/4 ; exit } { o+=1+length() }' < $1)
domcox@2 1975 dd if=$1 skip=$(($ofs / 1024)) bs=4k count=1 2> /dev/null | \
domcox@2 1976 ( dd skip=$(($ofs % 1024)) bs=4 2> /dev/null ; \
domcox@2 1977 dd if=$1 skip=$((1 + ($ofs / 1024) )) bs=4k ) | \
domcox@2 1978 extract_loramfs
domcox@2 1979 cd "$path" || error8
domcox@2 1980 }
domcox@2 1981
domcox@2 1982 # extract lzma'ed or gziped rootfs.
domcox@2 1983 extract_rootfs()
domcox@2 1984 {
domcox@2 1985 local path="$(pwd)"
domcox@2 1986 local isloramfs
domcox@2 1987 cd "$TARGET_ROOT" || error8
domcox@2 1988 if [ -d "$1"/../fs/etc ]; then
domcox@2 1989 # this is a tazlitobox loram (cdrom)
domcox@2 1990 cp -a "$1"/../fs/. .
domcox@2 1991 else
domcox@2 1992 for i in $(ls "$1"/rootfs* | sort -r); do
domcox@2 1993 if [ ! -d etc ]; then
domcox@2 1994 if [ $( (zcat "$i" 2>/dev/null \
domcox@2 1995 || /usr/bin/lzma d "$i" -so) | \
domcox@2 1996 wc -c) -lt $(stat -c %s "$i") ]; then
domcox@2 1997 # this is a tazlitobox loram (ram)
domcox@2 1998 isloramfs="$i"
domcox@2 1999 extract_first_loramfs "$i"
domcox@2 2000 continue
domcox@2 2001 fi
domcox@2 2002 fi
domcox@2 2003 if [ -n "$isloramfs" ]; then
domcox@2 2004 extract_loramfs < "$i"
domcox@2 2005 continue
domcox@2 2006 fi
domcox@2 2007 ( zcat "$i" 2>/dev/null || /usr/bin/lzma d "$i" -so || \
domcox@2 2008 cat "$i" ) 2>>"$LOG" | /bin/busybox cpio -idu
domcox@2 2009 done 2>>"$LOG" > /dev/null
domcox@2 2010 fi
pascal@110 2011 $(which install) -m 644 /etc/keymap.conf /etc/locale.conf /etc/TZ /etc/network.conf etc
pascal@111 2012 cp -a /usr/lib/locale usr/lib/
domcox@2 2013 # unpack /usr (double check...)
domcox@2 2014 if ls etc/tazlito | grep -q ".extract"; then
domcox@2 2015 for i in etc/tazlito/*.extract; do
domcox@2 2016 [ -f "$i" ] && . "$i" /media/cdrom
domcox@2 2017 done
domcox@2 2018 fi
domcox@2 2019 cd "$pwd" || error8
domcox@2 2020 }
domcox@2 2021
domcox@2 2022
domcox@2 2023 # pre configure freshly installed system (60 - 80%).
domcox@2 2024 pre_config_system()
domcox@2 2025 {
domcox@2 2026 local path="$(pwd)"
domcox@2 2027 cd "$TARGET_ROOT" || error8
domcox@2 2028 # restore backup of existing /home if exists.
domcox@2 2029 # (created by prepare_target_dev)
domcox@2 2030 if [ -d home.bak ]; then
al@73 2031 log "$(_ 'Restoring directory: /home...')"
domcox@2 2032 rm -rf home
domcox@2 2033 mv home.bak home
domcox@2 2034 fi
domcox@2 2035 # add root device to CHECK_FS in rcS.conf to check filesystem
domcox@2 2036 # on each boot.
al@73 2037 log "$(_ 'Adding / partition and CHECK_FS to file %s...' '/etc/rcS.conf')"
domcox@28 2038 sed -i s#'CHECK_FS=\"\"'#"CHECK_FS=\"$(dev2uuid $ROOT_UUID)\""# etc/rcS.conf
domcox@2 2039 # set hostname.
al@73 2040 log "$(_ 'Configuring host name: %s' "$HOSTNAME")"
domcox@12 2041 printf "%s\n" "$HOSTNAME" > etc/hostname
domcox@12 2042 printf "%s\n" "127.0.0.1 localhost $HOSTNAME tazpanel" > etc/hosts
domcox@2 2043 cd "$path" || error8
domcox@2 2044 }
domcox@2 2045
domcox@2 2046 # set root passwd and create user after rootfs extraction.
domcox@2 2047 users_settings()
domcox@2 2048 {
domcox@2 2049 # create file
domcox@2 2050 cat > "$TARGET_ROOT/users.sh" << _EOF_
domcox@2 2051 #!/bin/sh
domcox@2 2052 umask 0022
domcox@12 2053 printf "root:%s" "$ROOT_PWD" | chpasswd -m
domcox@2 2054 adduser -D -H $USER_LOGIN
domcox@2 2055
domcox@2 2056 for grp in audio cdrom floppy dialout disk kmem tape tty video; do
domcox@2 2057 if ! grep \$grp /etc/group | grep -q $USER_LOGIN ; then
domcox@2 2058 grep -q \$grp /etc/group && addgroup $USER_LOGIN \$grp
domcox@2 2059 fi
domcox@2 2060 done
domcox@2 2061
domcox@12 2062 printf "%s:%s" "$USER_LOGIN" "$USER_PWD" | chpasswd -m
domcox@2 2063 if [ ! -d /home/$USER_LOGIN ]; then
domcox@2 2064 cp -a /etc/skel /home/$USER_LOGIN
domcox@2 2065 [ -e /root/.xinitrc ] && cp /root/.xinitrc /home/$USER_LOGIN
domcox@2 2066 mkdir -p /home/$USER_LOGIN/.config/slitaz
domcox@2 2067 cp -a /etc/slitaz/applications.conf /home/$USER_LOGIN/.config/slitaz
domcox@2 2068 # Set ownership
domcox@2 2069 if grep -q ^users: /etc/group; then
domcox@2 2070 chown -R $USER_LOGIN:users /home/$USER_LOGIN
domcox@2 2071 else
domcox@2 2072 chown -R $USER_LOGIN:$USER_LOGIN /home/$USER_LOGIN
domcox@2 2073 fi
domcox@2 2074 # Path for user desktop files.
domcox@2 2075 for i in /home/$USER_LOGIN/.local/share/applications/*.desktop
domcox@2 2076 do
domcox@2 2077 [ -e "$i" ] && sed -i s/"user_name"/"$USER_LOGIN"/g \$i
domcox@2 2078 done
domcox@2 2079 fi
domcox@2 2080 # Slim default user.
domcox@2 2081 if [ -f /etc/slim.conf ]; then
domcox@2 2082 sed -i s/"default_user .*"/"default_user $USER_LOGIN"/ \
domcox@2 2083 /etc/slim.conf
domcox@2 2084 fi
domcox@2 2085 _EOF_
domcox@2 2086 chmod o+x "$TARGET_ROOT/users.sh"
domcox@2 2087 chroot "$TARGET_ROOT" ./users.sh 2>>"$LOG" >> "$LOG"
domcox@2 2088 rm "$TARGET_ROOT/users.sh"
domcox@2 2089 umask 0177
domcox@2 2090 }
domcox@2 2091
domcox@2 2092 # /home can be on a separate partition. If default user exists in /home
domcox@2 2093 # we remove default file created by users_settings().
domcox@2 2094 home_config()
domcox@2 2095 {
domcox@2 2096 if [ -n "$HOME_UUID" ]; then
domcox@2 2097 local path="$(pwd)" uuid
domcox@2 2098 cd "$TARGET_ROOT" || error8
domcox@2 2099 # detect fs
domcox@2 2100 local home_fs="$HOME_FORMAT"
domcox@2 2101 [ -z "$home_fs" ] && home_fs="$(filesys $HOME_UUID)"
domcox@2 2102 # manage /home
al@73 2103 log "$(_ 'Configuring partition to be used as /home: %s' "$HOME_UUID")"
domcox@2 2104 mv home/$USER_LOGIN tmp
domcox@2 2105 mount -t "$home_fs" "$HOME_UUID" home >> "$LOG" 2>> "$LOG"
domcox@2 2106 if [ -d $TARGET_ROOT/home/$USER_LOGIN ]; then
domcox@2 2107 rm -rf tmp/home/$USER_LOGIN
domcox@2 2108 else
domcox@2 2109 mv tmp/$USER_LOGIN home
domcox@2 2110 fi
domcox@2 2111 # write entry in fstab, force uuid
domcox@2 2112 uuid="$(dev2uuid "$HOME_UUID")"
domcox@12 2113 printf "%b\n" "$uuid /home $home_fs defaults \t0 \t2" >> etc/fstab
domcox@2 2114 umount home >> "$LOG" 2>> "$LOG"
domcox@2 2115 cd "$path" || error8
domcox@2 2116 fi
domcox@2 2117 }
domcox@2 2118
domcox@2 2119 install()
domcox@2 2120 {
domcox@2 2121 log_open
al@73 2122 log "1 $(_ 'Installing SliTaz on: %s' "$(get root_uuid)")"
al@73 2123 log "5 $(_ 'Checking settings...')"
domcox@2 2124 check all >> "$LOG" 2>> "$LOG"
domcox@2 2125 load_settings
domcox@2 2126
al@73 2127 log "10 $(_ 'Preparing source media...')"
domcox@2 2128 mount_source
domcox@2 2129
al@73 2130 log "20 $(_ 'Preparing target disk...')"
domcox@2 2131 prepare_uuid
domcox@2 2132
al@73 2133 log "30 $(_ 'Cleaning the root partition if necessary...')"
domcox@2 2134 clean_target
domcox@2 2135
al@73 2136 log "40 $(_ 'Extracting the root system...')"
domcox@2 2137 extract_rootfs $SOURCE_ROOT/boot
domcox@2 2138
al@73 2139 log "50 $(_ 'Installing the Kernel...')"
domcox@2 2140 install_kernel
domcox@2 2141
al@73 2142 log "60 $(_ 'Preconfiguring the system...')"
domcox@2 2143 pre_config_system
domcox@2 2144
al@73 2145 log "70 $(_ 'Configuring root and default user account...')"
domcox@2 2146 users_settings
domcox@2 2147
al@73 2148 log "80 $(_ 'Configuring /home...')"
domcox@2 2149 home_config
domcox@2 2150
al@73 2151 log "90 $(_ 'Checking bootloader installation...')"
domcox@2 2152 bootloader
domcox@2 2153
al@73 2154 log "100 $(_ 'Files installation completed')"
domcox@2 2155 end_of_install
domcox@2 2156 }
domcox@2 2157
domcox@2 2158
domcox@2 2159 #-------------
domcox@2 2160 # 6.2 upgrade
domcox@2 2161 #-------------
domcox@2 2162
domcox@2 2163 # search for SliTaz
domcox@0 2164 check_release()
domcox@0 2165 {
domcox@0 2166 if [ -f $TARGET_ROOT/etc/slitaz-release ]; then
domcox@2 2167 local release="$(cat $TARGET_ROOT/etc/slitaz-release)"
al@73 2168 log "$(_ 'Preparing upgrade of SliTaz release: %s' "$release")"
domcox@0 2169 else
al@73 2170 error 6 "$(_ "%s: This partition doesn't appear to contain a valid \
al@73 2171 SliTaz system, the file: %s doesn't exist." "$ROOT_UUID" '/etc/slitaz-release')"
domcox@2 2172 fi
domcox@0 2173 }
domcox@0 2174
domcox@2 2175 # backup packages list.
domcox@0 2176 backup_files()
domcox@0 2177 {
domcox@2 2178 local path="$(pwd)"
domcox@2 2179 cd "$TARGET_ROOT" || error8
domcox@0 2180 ls -1 var/lib/tazpkg/installed > home/packages-selection.list
domcox@2 2181 local dir
domcox@0 2182 for dir in *
domcox@0 2183 do
domcox@0 2184 case "$dir" in
domcox@0 2185 boot)
domcox@0 2186 rm -rf boot/vmlinuz-* ;;
domcox@0 2187 home)
domcox@0 2188 mv home home.bak
al@73 2189 log "$(_ 'keeping /home found on: %s' "$ROOT_UUID")" ;;
domcox@0 2190 etc)
domcox@2 2191 /bin/busybox tar czf etc.tar.gz etc
domcox@0 2192 mv etc etc.bak
al@73 2193 log "$(_ 'keeping /etc found on: %s' "$ROOT_UUID")" ;;
domcox@0 2194 var)
domcox@0 2195 if [ -d var/www ]; then
domcox@0 2196 mv var/www www.bak
al@73 2197 log "$(_ 'keeping /var/www found on: %s' "$ROOT_UUID")"
domcox@0 2198 fi
domcox@2 2199 rm -rf var 2>>"$LOG" ;;
domcox@0 2200 lost+found)
domcox@0 2201 continue ;;
domcox@0 2202 *)
al@73 2203 log "$(_ 'removing target: %s' "$dir")"
domcox@2 2204 rm -rf "$dir" 2>>"$LOG" ;;
domcox@0 2205 esac
domcox@0 2206 done
domcox@0 2207 if [ -d mklost+found ]; then
domcox@2 2208 mklost+found 2>>"$LOG"
domcox@0 2209 fi
domcox@2 2210 cd "$path" || error8
domcox@0 2211 }
domcox@0 2212
domcox@2 2213 # restore backups.
domcox@0 2214 restore_files()
domcox@0 2215 {
domcox@0 2216 rm -rf $TARGET_ROOT/home
domcox@0 2217 mv $TARGET_ROOT/home.bak $TARGET_ROOT/home
domcox@0 2218 rm -rf $TARGET_ROOT/etc
domcox@0 2219 mv $TARGET_ROOT/etc.bak $TARGET_ROOT/etc
domcox@0 2220 if [ -d $TARGET_ROOT/www.bak ]; then
domcox@0 2221 rm -rf $TARGET_ROOT/var/www
domcox@0 2222 mv $TARGET_ROOT/www.bak $TARGET_ROOT/var/www
domcox@0 2223 fi
al@73 2224 log "$(_ 'backups restored: %s' "$(date)")"
domcox@0 2225
domcox@0 2226 # /var/lib/slitaz-installer
domcox@2 2227 mkdir -p $TARGET_ROOT/var/lib/tazinst && \
domcox@2 2228 mv $TARGET_ROOT/etc.tar.gz $TARGET_ROOT/var/lib/tazinst && \
domcox@2 2229 mv $TARGET_ROOT/home/packages-selection.list \
domcox@2 2230 $TARGET_ROOT/var/lib/tazinst \
al@73 2231 && log "$(_ 'backups saved in %s' '/var/lib/tazinst')"
domcox@0 2232 }
domcox@0 2233
domcox@2 2234 # upgrade added pkgs
domcox@0 2235 install_pkgs()
domcox@0 2236 {
domcox@2 2237 # check if the pkg is on the mirror.
al@73 2238 log "$(_ 'Checking the availability of packages...')"
domcox@0 2239 touch packages-to-install.list
domcox@0 2240 packages=0
pascal@100 2241 diff="$(sort < packages-selection.diff)"
domcox@0 2242 for pkg in $diff
domcox@0 2243 do
pascal@116 2244 if grep -q "^$pkg-[0-9]" /var/lib/tazpkg/packages.list; then
domcox@2 2245 packages="$(($packages+1))"
domcox@12 2246 printf "%s\n" "$pkg" >> packages-to-install.list
domcox@0 2247 fi
domcox@0 2248 done
domcox@0 2249
domcox@2 2250 # install packages.
al@73 2251 log "$(_ 'Installing packages...')"
pascal@98 2252 if [ "$packages" = "0" ]; then
al@73 2253 log "$(_ 'packages to install: 0')"
domcox@0 2254 else
domcox@2 2255 # get-install all missing pkgs.
pascal@100 2256 while read pkg
domcox@0 2257 do
al@73 2258 log "$(_ 'Installing: %s...' "$pkg")"
domcox@2 2259 # get install package and answer yes in case of dependencies.
domcox@2 2260 pkgname="$(grep ^$pkg /var/lib/tazpkg/packages.list)"
domcox@2 2261 /usr/bin/tazpkg get "$pkg" >/dev/null 2>/dev/null
domcox@2 2262 yes "" | /usr/bin/tazpkg install $pkgname.tazpkg \
domcox@2 2263 --root=$TARGET_ROOT >/dev/null 2>/dev/null
domcox@0 2264 rm -f $pkgname.tazpkg
pascal@100 2265 done < packages-to-install.list
domcox@0 2266 fi
al@73 2267 log "$(_ 'Installation of packages complete...')"
domcox@0 2268 }
domcox@0 2269
domcox@2 2270 # search for added pkgs
domcox@0 2271 update_pkgs()
domcox@0 2272 {
domcox@2 2273 local path="$(pwd)"
domcox@2 2274 cd $TARGET_ROOT/var/lib/tazinst || error8
domcox@0 2275 # LiveCD packages list.
al@73 2276 log "$(_ 'Creating package lists...')"
domcox@2 2277 ls -1 $TARGET_ROOT/var/lib/tazpkg/installed > packages-source.list || error8
al@73 2278 log "$(_ '%s: done' 'packages-source.list')"
domcox@2 2279 # diff
domcox@2 2280 /bin/busybox diff packages-source.list packages-selection.list | \
pascal@116 2281 grep '^+[a-z]' | sed 's/^+//' > packages-selection.diff
al@73 2282 log "$(_ '%s: done' 'packages-selection.diff')"
domcox@2 2283 # get mirror list.
domcox@2 2284 /usr/bin/tazpkg recharge >>$LOG 2>>$LOG
domcox@0 2285 if [ -f /var/lib/tazpkg/packages.list ]; then
domcox@0 2286 install_pkgs
domcox@0 2287 else
domcox@0 2288 touch packages-to-install.list
al@73 2289 longline "$(_ "The list of available packages on the mirror could not \
al@73 2290 be downloaded. No missing packages will be reinstalled now, but you can do so \
al@73 2291 later by looking at the following list:")"
al@73 2292 echo '/var/lib/tazinst/packages-selection.diff'
domcox@0 2293 fi
domcox@2 2294 cd "$path" || error8
domcox@0 2295 }
domcox@0 2296
domcox@2 2297 # upgrade command
domcox@2 2298 upgrade()
domcox@0 2299 {
domcox@2 2300 log_open
al@73 2301 log "1 $(_ 'Upgrading SliTaz on: %s' "$(get root_uuid)")"
al@73 2302 log "5 $(_ 'Checking settings...')"
domcox@2 2303 check all >> "$LOG"
domcox@2 2304 load_settings
domcox@2 2305
al@73 2306 log "10 $(_ 'Preparing source media...')"
domcox@2 2307 mount_source
domcox@2 2308
al@73 2309 log "20 $(_ 'Preparing target disk...')"
domcox@2 2310 prepare_uuid
domcox@2 2311
al@73 2312 log "30 $(_ 'Searching for %s...' '/etc/slitaz-release')"
domcox@2 2313 check_release
domcox@2 2314
al@73 2315 log "40 $(_ 'Backup /etc, /home and the packages list...')"
domcox@2 2316 backup_files
domcox@2 2317
al@73 2318 log "50 $(_ 'Extracting the root system...')"
domcox@2 2319 extract_rootfs $SOURCE_ROOT/boot
domcox@2 2320
al@73 2321 log "60 $(_ 'Restoring configuration files...')"
domcox@2 2322 restore_files
domcox@2 2323
al@73 2324 log "70 $(_ 'Installing the Kernel...')"
domcox@2 2325 install_kernel
domcox@2 2326
al@73 2327 log "80 $(_ 'Upgrading added packages...')"
domcox@2 2328 update_pkgs
domcox@2 2329
al@73 2330 log "90 $(_ 'Bootloader...')"
domcox@2 2331 bootloader
domcox@2 2332
al@73 2333 log "100 $(_ 'Files installation completed')"
domcox@2 2334 end_of_install
domcox@0 2335 }
domcox@0 2336
domcox@0 2337
domcox@2 2338 #--------------
domcox@2 2339 # tazinst main
domcox@2 2340 #--------------
domcox@0 2341
domcox@0 2342 case $1 in
domcox@2 2343 new)
domcox@2 2344 new_file "$2" ;;
domcox@2 2345 set)
pascal@103 2346 [ -s "$4" ] || new_file "$4"
domcox@2 2347 read_file "$4"
domcox@2 2348 change "$2" "$3" "$4" ;;
domcox@2 2349 unset)
domcox@2 2350 read_file "$3"
domcox@2 2351 change "$2" "" "$3" "$4" ;;
domcox@2 2352 get)
domcox@2 2353 read_file "$3"
domcox@2 2354 get "$2" ;;
domcox@2 2355 check)
domcox@2 2356 read_file "$3"
domcox@2 2357 check "$2" ;;
domcox@2 2358 list)
domcox@2 2359 list "$2" "$3" ;;
domcox@2 2360 execute)
domcox@0 2361 check_root
domcox@2 2362 read_file "$2"
domcox@2 2363 execute "$2" ;;
domcox@0 2364 log)
domcox@2 2365 [ -r "$LOG" ] && cat "$LOG" ;;
domcox@2 2366 clean)
domcox@2 2367 clean "$2" ;;
domcox@0 2368 version)
domcox@12 2369 printf "%s\n" "$VERSION" ;;
domcox@2 2370 ""|usage)
domcox@0 2371 usage ;;
domcox@2 2372 help)
domcox@2 2373 help "$2" ;;
domcox@2 2374 *)
domcox@12 2375 usage_error "$1" ;;
domcox@0 2376 esac