tazlito annotate tazlito @ rev 508

Fix cleanup_efi_boot
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jun 03 13:08:22 2018 +0200 (16 months ago)
parents 035c08dd4580
children d585f8404493
rev   line source
pankso@1 1 #!/bin/sh
pankso@1 2 # TazLito - SliTaz Live Tool.
pankso@1 3 #
al@412 4 # Tazlito is a tool to help generate and configure SliTaz Live CD
MikeDSmith25@83 5 # ISO images. You can create a custom distro in one command from a list of
MikeDSmith25@83 6 # packages, extract an existing ISO image to hack it, create a new initramfs
MikeDSmith25@83 7 # and/or a new ISO. Most commands must be run by root, except the stats
pankso@1 8 # and the configuration file manipulation.
pankso@1 9 #
pascal@497 10 # (C) 2007-2018 SliTaz - GNU General Public License.
pankso@1 11 #
al@412 12 # Authors: see the AUTHORS file
pankso@28 13 #
al@412 14
al@412 15 VERSION='6.0'
pankso@1 16
pankso@279 17 . /lib/libtaz.sh
al@412 18 # Force to use Busybox cpio and wget
al@412 19 alias cpio='busybox cpio'
al@412 20 alias wget='busybox wget'
pascal@492 21 alias stat='busybox stat'
pascal@492 22 alias awk='busybox awk'
pankso@279 23
pankso@1 24 # Tazlito configuration variables to be shorter
paul@94 25 # and to use words rather than numbers.
al@412 26 COMMAND="$1"
al@412 27 LIST_NAME="$2"
al@412 28 TMP_DIR="/tmp/tazlito-$$-$RANDOM"
al@412 29 TMP_MNT="/media/tazlito-$$-$RANDOM"
al@412 30 TOP_DIR="$(pwd)"
al@412 31 INITRAMFS='rootfs.gz'
al@412 32 LOCALSTATE='/var/lib/tazpkg'
al@412 33 INSTALLED="$LOCALSTATE/installed"
al@412 34 CACHE_DIR='/var/cache/tazpkg'
al@412 35 MIRROR="$LOCALSTATE/mirror"
al@418 36 DEFAULT_MIRROR="http://mirror1.slitaz.org/packages/$(cat /etc/slitaz-release)/"
al@412 37
al@412 38 log='/var/log/tazlito.log'
al@412 39 if [ $(id -u) -eq 0 ]; then
pankso@333 40 newline > $log
pankso@279 41 fi
pankso@218 42
pascal@13 43
pankso@332 44 cleanup() {
al@412 45 if [ -d "$TMP_MNT" ]; then
pascal@19 46 umount $TMP_MNT
pascal@19 47 rmdir $TMP_MNT
pascal@19 48 rm -f /boot
pascal@19 49 fi
al@412 50 [ -d "$tmp_dir" ] && rm -r "$tmp_dir"
al@412 51 [ -d "$flv_dir" ] && rm -r "$flv_dir"
pascal@19 52 }
pascal@19 53
al@412 54
al@412 55 # Report error and finish work
al@412 56
al@412 57 die() {
al@412 58 emsg "<n>$(longline "$@")<n> " >&2
al@412 59 cleanup
al@412 60 exit 1
al@412 61 }
al@412 62
al@412 63
al@416 64 # Run Tazlito module
al@416 65 module() {
al@416 66 local mod="$1"; shift
al@416 67 /usr/libexec/tazlito/$mod $@
al@416 68 }
al@416 69
al@416 70
al@412 71
al@412 72 # Try to include config file, continue if command is gen-config or exit.
al@412 73 # The main config used by default is in /etc/tazlito.
al@412 74 # Specific distro config file can be put in a distro tree.
al@412 75 for i in /etc/tazlito "$TOP_DIR"; do
al@412 76 [ -f "$i/tazlito.conf" ] && CONFIG_FILE="$i/tazlito.conf"
al@412 77 done
al@412 78
al@412 79 [ -z "$CONFIG_FILE" -a "$COMMAND" != 'gen-config' ] && \
al@412 80 die 'Unable to find any configuration file.' \
al@412 81 'Please read the docs or run `tazlito gen-config` to get an empty config file.'
al@412 82
al@412 83 . $CONFIG_FILE
al@412 84
al@412 85 # While Tazpkg is not used the default mirror URL file does not exist
al@412 86 # and user can't recharge the list of flavors.
al@412 87 [ $(id -u) -eq 0 -a ! -f "$MIRROR" ] && echo "$DEFAULT_MIRROR" > $MIRROR
al@412 88
al@412 89 # Set the rootfs and rootcd path with $DISTRO
al@412 90 # configuration variable.
al@412 91 ROOTFS="$DISTRO/rootfs"
al@412 92 ROOTCD="$DISTRO/rootcd"
al@412 93
al@412 94
al@412 95
al@412 96
al@412 97 #####################
al@412 98 # Tazlito functions #
al@412 99 #####################
al@412 100
al@412 101
al@412 102 # Print the usage.
al@412 103
al@412 104 usage () {
al@412 105 [ $(basename $0) == 'tazlito' ] && cat <<EOT
al@412 106
al@412 107 SliTaz Live Tool - Version: $(colorize 34 "$VERSION")
al@412 108
al@412 109 $(boldify "Usage:") tazlito [command] [list|iso|flavor|compression] [dir|iso]
al@412 110
al@412 111 $(boldify "Commands:")
al@412 112 EOT
al@412 113 optlist "\
al@412 114 usage Print this short usage.
al@412 115 stats View Tazlito and distro configuration statistics.
al@412 116 list-addfiles Simple list of additional files in the rootfs.
al@412 117 gen-config Generate a new configuration file for a distro.
al@412 118 configure Configure the main config file or a specific tazlito.conf.
al@412 119 gen-iso Generate a new ISO from a distro tree.
al@412 120 gen-initiso Generate a new initramfs and ISO from the distro tree.
al@412 121 list-flavors List all flavors available on the mirror.
al@412 122 gen-flavor Generate a new Live CD description.
al@412 123 gen-liveflavor Generate a Live CD description from current system.
al@412 124 show-flavor Show Live CD description.
al@412 125 get-flavor Get a flavor's list of packages (--noup to skip update).
al@412 126 upgrade-flavor Update package list to the latest available versions.
al@412 127 extract-flavor Extract a *.flavor file into $FLAVORS_REPOSITORY.
al@412 128 pack-flavor Pack (and update) a flavor from $FLAVORS_REPOSITORY.
al@412 129 iso2flavor Create a flavor file from a SliTaz ISO image.
al@412 130 extract-distro Extract an ISO to a directory and rebuild Live CD tree.
al@412 131 gen-distro Generate a Live distro and ISO from a list of packages.
al@412 132 clean-distro Remove all files generated by gen-distro.
al@412 133 check-distro Help to check if distro is ready to release.
al@412 134 writeiso Use running system to generate a bootable ISO (with /home).
al@412 135 merge Merge multiple rootfs into one ISO.
al@412 136 deduplicate Deduplicate files in a tree.
al@412 137 repack Recompress rootfs into ISO with maximum ratio.
al@412 138 build-loram Generate a Live CD for low-RAM systems.
al@412 139 emu-iso Emulate an ISO image with QEMU.
al@412 140 burn-iso Burn ISO image to a CD-ROM using Wodim.
al@412 141 "
al@412 142 }
al@412 143
al@412 144
al@412 145 yesorno() {
al@412 146 local answer
al@412 147 echo -n "$1 (y=yes, n=no) [$2] " >&2
al@412 148 case "$DEFAULT_ANSWER" in
al@412 149 Y|y) answer="y";;
al@412 150 N|n) answer="n";;
al@412 151 *)
al@414 152 read -t 30 answer
al@412 153 [ -z "$answer" ] && answer="$2"
al@412 154 [ "$answer" != 'y' -a "$answer" != 'n' ] && answer="$2"
al@412 155 ;;
al@412 156 esac
al@412 157 echo "$answer"
al@412 158 }
al@412 159
al@412 160
al@412 161 field() {
al@412 162 grep "^$1" "$2" | \
al@412 163 case "$1" in
al@412 164 Desc*) sed 's|^.*: *||';;
al@412 165 *) sed 's/.*: \([0-9KMG\.]*\).*/\1/';;
al@412 166 esac
al@412 167 }
al@412 168
al@412 169
al@412 170 todomsg() {
al@412 171 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
al@412 172 }
al@412 173
al@412 174
al@412 175 # Download a file from this mirror
al@412 176
al@412 177 download_from() {
al@412 178 local i mirrors="$1"
al@412 179 shift
al@412 180 for i in $mirrors; do
al@412 181 case "$i" in
al@412 182 http://*|ftp://*|https://*)
al@412 183 wget -c $i$@ && break;;
al@412 184 *)
al@412 185 cp $i/$1 . && break;;
al@412 186 esac
al@412 187 done
al@412 188 }
al@412 189
al@412 190
al@412 191 # Download a file trying all mirrors
al@412 192
al@412 193 download() {
al@412 194 local i
al@412 195 for i in $(cat $MIRROR $LOCALSTATE/undigest/*/mirror 2>/dev/null); do
al@412 196 download_from "$i" "$@" && break
al@412 197 done
al@412 198 }
al@412 199
al@412 200
al@412 201 # Execute hooks provided by some packages
al@412 202
al@412 203 genisohooks() {
al@412 204 local here="$(pwd)"
al@412 205 for i in $(ls $ROOTFS/etc/tazlito/*.$1 2>/dev/null); do
al@412 206 cd $ROOTFS
al@412 207 . $i $ROOTCD
al@412 208 done
al@412 209 cd "$here"
al@412 210 }
al@412 211
al@412 212
MikeDSmith25@83 213 # Echo the package name if the tazpkg is already installed
al@412 214
pankso@333 215 installed_package_name() {
al@412 216 local tazpkg="$1" package VERSION EXTRAVERSION
al@412 217
MikeDSmith25@83 218 # Try to find package name and version to be able
pascal@18 219 # to repack it from installation
MikeDSmith25@83 220 # A dash (-) can exist in name *and* in version
pascal@18 221 package=${tazpkg%-*}
pascal@18 222 i=$package
pascal@18 223 while true; do
al@412 224 unset VERSION EXTRAVERSION
al@412 225 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
pascal@78 226 eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
al@412 227 if [ "$i-$VERSION$EXTRAVERSION" == "$tazpkg" ]; then
pascal@18 228 echo $i
pascal@18 229 break
pascal@18 230 fi
pascal@18 231 case "$i" in
al@412 232 *-*);;
al@412 233 *) break;;
pascal@18 234 esac
pascal@18 235 i=${i%-*}
pascal@18 236 done
pascal@18 237 }
pascal@18 238
al@412 239
pascal@11 240 # Check for the rootfs tree.
al@412 241
pankso@333 242 check_rootfs() {
al@412 243 [ -d "$ROOTFS/etc" ] || die 'Unable to find a distro rootfs...'
pascal@11 244 }
pascal@11 245
al@412 246
pankso@1 247 # Check for the boot dir into the root CD tree.
al@412 248
al@412 249 verify_rootcd() {
al@412 250 [ -d "$ROOTCD/boot" ] || die 'Unable to find the rootcd boot directory...'
pankso@1 251 }
pankso@1 252
pascal@497 253 set32() {
pascal@497 254 for i in $(seq 0 8 $((${4:-32}-8))); do
pascal@497 255 printf '\\\\x%02X' $((($2 >> $i) & 255))
pascal@497 256 done | xargs echo -en | dd bs=1 conv=notrunc of=$3 seek=$1 2>/dev/null
pascal@476 257 }
pascal@476 258
pascal@476 259 set64() {
pascal@476 260 for i in $(seq 0 8 24 ; seq 24 -8 0); do
pascal@476 261 printf '\\\\x%02X' $((($2 >> $i) & 255))
pascal@476 262 done | xargs echo -en | dd bs=1 conv=notrunc of=$3 seek=$1 2>/dev/null
pascal@476 263 }
pascal@476 264
pascal@476 265
pascal@492 266 first_block() {
pascal@492 267 busybox stat -m "$1" | sed q
pascal@492 268 }
pascal@492 269
pascal@492 270
pascal@492 271
pascal@490 272 # Force size and location in the 2nd eltorito boot file (/boot/isolinux/efi.img)
pascal@478 273
pascal@478 274 fix_efi_boot_img_size() {
pascal@497 275 local n=$3
pascal@497 276 [ $n -gt 65535 ] && n=65535
pascal@497 277 set32 $((0x66+2048*$(first_block $2/boot/isolinux/boot.cat))) $n $1 16
pascal@497 278 set32 $((0x1C+2048*$4)) $(($4*4)) $1
pascal@478 279 }
pascal@478 280
pascal@478 281
pascal@476 282 # Force the size for the /boot/isolinux/efi.img file
pascal@476 283
pascal@476 284 fix_efi_img_size() {
pascal@476 285 local e=$((0x809C))
pascal@476 286 for i in BOOT ISOLINUX EFI.IMG ; do
pascal@497 287 local sz=$(get $(($e+10)) "$2" 4)
pascal@497 288 e=$(($(get $(($e+2)) "$2" 4) * 2048))
pascal@476 289 while [ $sz -gt 0 ]; do
pascal@497 290 local len=$(get $e "$2")
pascal@476 291 [ "$(dd if="$2" bs=1 skip=$(($e+33)) count=${#i} \
pascal@476 292 2>/dev/null)" == "$i" ] && continue 2
pascal@476 293 [ $len -eq 0 ] && break
pascal@476 294 sz=$(($sz-$len))
pascal@476 295 e=$(($e+$len))
pascal@476 296 done
pascal@476 297 return # not found
pascal@476 298 done
pascal@476 299 set64 $(($e+10)) $1 "$2"
pascal@476 300 }
pascal@476 301
pascal@476 302
pascal@476 303 # create /boot/isolinux/efi.img to share EFI files with the iso image
pascal@476 304
pascal@476 305 fixup_uefi_part() {
pascal@476 306 [ -s $2/boot/isolinux/efi.img ] || return
pascal@497 307 local n=$(get 19 "$2/boot/isolinux/efi.img")
pascal@497 308 [ $n -eq 0 ] && n=$(get 32 "$2/boot/isolinux/efi.img" 4)
pascal@497 309 efiblock=$(first_block "$2/boot/isolinux/efi.img")
pascal@497 310 fix_efi_img_size $(($n*512)) $1
pascal@497 311 fix_efi_boot_img_size $1 $2 $n $efiblock
pascal@497 312
pascal@476 313 # Build file list tree
pascal@497 314 resv=$(get 14 "$2/boot/isolinux/efi.img")
pascal@499 315 if [ $(get 57 "$2/boot/isolinux/efi.img" 1) -ne 49 ]; then
pascal@499 316 skiphead=5
pascal@499 317 fatsz=$(get 36 "$2/boot/isolinux/efi.img" 4)
pascal@499 318 basecluster=$((($resv+2*$fatsz)/4+$efiblock-2))
pascal@499 319 dd if=$1 bs=512 skip=$(($efiblock*4)) count=3 \
pascal@499 320 of=$1 seek=$(($efiblock*4+3)) conv=notrunc
pascal@499 321 else
pascal@499 322 skiphead=4
pascal@499 323 fatsz=$(get 22 "$2/boot/isolinux/efi.img")
pascal@499 324 basecluster=$((($resv+2*$fatsz)/4+$efiblock-1))
pascal@499 325 fi 2> /dev/null
pascal@499 326 hd "$2/boot/isolinux/efi.img" | awk 'BEGIN { skiphead='$skiphead' }
pascal@497 327 {
pascal@497 328 if (skiphead!=0) {
pascal@497 329 if ($1=="*") skiphead--
pascal@497 330 next
pascal@497 331 }
pascal@497 332 if (skipdot!=0) {
pascal@497 333 if (skipdot==2) up[cur]=$13 $12
pascal@497 334 else cur=$13 $12
pascal@497 335 skipdot=0
pascal@497 336 next
pascal@497 337 }
pascal@497 338 if (($2=="2e" && $3=="20") || ($2=="2e" && $3=="2e" && $4=="20")) {
pascal@497 339 if ($3=="2e") skipdot=2
pascal@497 340 else skipdot=1
pascal@497 341 next
pascal@497 342 }
pascal@497 343 if (gotname!=0) {
pascal@497 344 path=""
pascal@497 345 for (i=cur;i!="" && i!="0000";i=up[i]) path=dir[i] path
pascal@497 346 if (gotname==2) dir[$13 $12]=name
pascal@497 347 else print $1 " " $13 $12 " " path name
pascal@497 348 gotname=0
pascal@497 349 name=""
pascal@497 350 next
pascal@497 351 }
pascal@497 352 if (s!="") {
pascal@497 353 if (eos==0)
pascal@497 354 for (i=2;i<18;i+=2) {
pascal@497 355 if (i==12) i+=2
pascal@497 356 if ($i=="00") break
pascal@497 357 s=s substr($0,i+60,1)
pascal@497 358 }
pascal@497 359 name=s name
pascal@497 360 s=""
pascal@497 361 eos=0
pascal@497 362 next
pascal@497 363 }
pascal@497 364 if ($13=="0f") {
pascal@497 365 s=""
pascal@497 366 for (i=3;i<16;i+=2) {
pascal@497 367 if (i==13) i+=3
pascal@497 368 if ($i=="00") { eos=1; break }
pascal@497 369 s=s substr($0,i+60,1)
pascal@497 370 }
pascal@497 371 next
pascal@497 372 }
pascal@497 373 if ($13=="10") {
pascal@497 374 name=name "/"
pascal@497 375 gotname=2
pascal@497 376 next
pascal@497 377 }
pascal@497 378 if ($13=="20") {
pascal@497 379 gotname=1
pascal@497 380 next
pascal@497 381 }
pascal@497 382 }
pascal@497 383 ' | ( while read offset cluster file; do
pascal@497 384 cluster=$(($(first_block "$2/$file")-$basecluster))
pascal@497 385 set32 $(($efiblock*2048+0x$offset+10)) $cluster "$1" 16
pascal@499 386 set32 $(($efiblock*2048+0x$offset+4)) $(($cluster>>16)) "$1" 16
pascal@497 387 echo "$cluster $((($(stat -c %s "$2/$file")+2047)/2048)) $file"
pascal@497 388 done
pascal@497 389
pascal@497 390 # Update fat12 or fat16
pascal@497 391 get 57 "$2/boot/isolinux/efi.img"
pascal@497 392 dd if="$2/boot/isolinux/efi.img" bs=512 count=$fatsz skip=$resv 2> /dev/null | \
pascal@497 393 od -An -t u1 -w1 -v
pascal@497 394 ) | awk '
pascal@497 395 {
pascal@497 396 if (state==0) {
pascal@497 397 if ($2=="") {
pascal@497 398 if ($1==12849) fat=12
pascal@499 399 else if ($1==13873) fat=16
pascal@499 400 else fat=32
pascal@497 401 state++
pascal@497 402 }
pascal@497 403 else {
pascal@497 404 for (i=1;i<$2;i++) c[$1+i]=$1+i
pascal@499 405 c[$1+$2]=268435455
pascal@497 406 }
pascal@497 407 next
pascal@497 408 }
pascal@497 409 if (state==1) {
pascal@497 410 prev=$1
pascal@497 411 state++
pascal@497 412 next
pascal@497 413 }
pascal@497 414 if (state==2) {
pascal@497 415 if (fat==12) {
pascal@497 416 n=($1%16)*256+prev
pascal@497 417 if (n!=0) c[pos+1]=n
pascal@497 418 pos++
pascal@498 419 prev=int($1/16)
pascal@497 420 state++
pascal@497 421 next
pascal@497 422 }
pascal@497 423 n=$1*256+prev
pascal@499 424 if (fat==32) {
pascal@499 425 prev=n
pascal@499 426 state=13
pascal@499 427 next
pascal@499 428 }
pascal@497 429 }
pascal@497 430 else if (state==3) {
pascal@497 431 n=$1*16+prev
pascal@497 432 }
pascal@499 433 else if (state==13) {
pascal@499 434 prev=$1*65536+prev
pascal@499 435 state++
pascal@499 436 next
pascal@499 437 }
pascal@499 438 else n=$1*16777216+prev
pascal@497 439 if (n!=0) c[pos+1]=n
pascal@497 440 pos++
pascal@497 441 state=1
pascal@497 442 }
pascal@497 443 END {
pascal@497 444 for (i=1;i<=pos;i+=2) {
pascal@497 445 if (c[i]=="") c[i]=0
pascal@497 446 if (c[i+1]=="") c[i+1]=0
pascal@498 447 if (fat==12) printf "0 %02X %1X%1X %02X |\n",c[i]%256,c[i+1]%16,(c[i]/256)%16,(c[i+1]/16)%256
pascal@499 448 else if (fat==16) printf "0 %02X %02X %02X %02X |\n",c[i]%256,(c[i]/256)%256,c[i+1]%256,(c[i+1]/256)%256
pascal@499 449 else {
pascal@499 450 printf "0 %02X %02X %02X %02X |\n",c[i]%256,(c[i]/256)%256,(c[i]/65536)%256,(c[i]/16777216)%256
pascal@499 451 printf "0 %02X %02X %02X %02X |\n",c[i+1]%256,(c[i+1]/256)%256,(c[i+1]/65536)%256,(c[i+1]/16777216)%256
pascal@499 452 }
pascal@497 453 }
pascal@497 454 }' | hexdump -R | dd of="$1" seek=$((4*$efiblock+$fatsz+$resv)) \
pascal@497 455 conv=notrunc bs=512 > /dev/null 2>&1
pascal@497 456 dd if="$1" of="$1" conv=notrunc bs=512 skip=$((4*$efiblock+$fatsz+$resv)) \
pascal@497 457 count=$fatsz seek=$((4*$efiblock+$resv)) > /dev/null 2>&1
pascal@497 458
pascal@497 459 # Cleanup cache
pascal@497 460 umount $2
pascal@497 461 mount -o loop,ro $1 $2
pascal@497 462 }
pascal@497 463
pascal@497 464
pascal@497 465 # allocate efi.img stub to share EFI files in the EFI boot partition
pascal@497 466
pascal@497 467 alloc_uefi_part() {
pascal@497 468 local basedir=$(dirname "$1")/..
pascal@497 469 local fclust=$({
pascal@497 470 [ -d $basedir/efi ] &&
pascal@497 471 find $basedir/efi -type f -exec stat -c "%s %n" {} \;
pascal@497 472 while [ -s "$1" ]; do
pascal@497 473 local efifile
pascal@497 474 case "$1" in
pascal@497 475 *taz) efifile=bootia32.efi ;;
pascal@497 476 *taz64) efifile=bootx64.efi ;;
pascal@497 477 esac
pascal@497 478 if [ ! -s $basedir/efi/boot/$efifile ] &&
pascal@497 479 [ $(get $((0x82)) "$1") == $((0x4550)) ]; then
pascal@497 480 mkdir -p $basedir/efi/boot 2> /dev/null
pascal@507 481 ln "$1" "$basedir/efi/boot/$efifile"
pascal@504 482 stat -c "%s %n" "$1"
pascal@504 483 for i in $basedir/boot/rootfs* ; do
pascal@502 484 ln "$i" $basedir/efi/boot/ &&
pascal@497 485 stat -c "%s %n" "$i"
pascal@497 486 done 2> /dev/null
pascal@507 487 sed 's|/|\\|g' > $basedir/efi/boot/linux.cmdline <<EOT
pascal@507 488 rw root=0x100 autologin\
pascal@498 489 $( ( cd $basedir/efi/boot ; ls -r rootfs*gz ) | while read f ; do \
pascal@507 490 echo -n " initrd=/EFI/BOOT/$f";done)
pascal@497 491 EOT
pascal@497 492 fi
pascal@497 493 shift
pascal@498 494 done; } | sort | uniq | awk '{ n+=int(($1+2047)/2048) } END { print n+1 }')
pascal@497 495 [ ${fclust:-0} -eq 0 ] && return
pascal@497 496 local dclust=$( (cd $basedir; find efi -type d 2>/dev/null) | awk '
pascal@497 497 BEGIN {
pascal@497 498 FS="/"
pascal@497 499 }
pascal@476 500 NF > 1 {
pascal@476 501 d[NF $NF]+=2
pascal@497 502 d[NF-1 $(NF-1)]+=($NF+25)/13
pascal@476 503 }
pascal@476 504 END {
pascal@497 505 for (i in d)
pascal@497 506 n+=int((d[i]+63)/64)
pascal@497 507 print n
pascal@497 508 }')
pascal@497 509 local clusters=$(($fclust+$dclust))
pascal@499 510 if [ $clusters -lt 4068 ]; then
pascal@497 511 fsect=$(((($clusters+2)*3+1023)/1024))
pascal@497 512 ftype="31 32"
pascal@497 513 fhead="F8 FF FF"
pascal@499 514 rsect=$(( 1+ ((2*$fsect)-1)%4 ))
pascal@499 515 fsz="$(printf "%04X" $fsect | sed 's/\(..\)\(..\)/\2 \1/')"
pascal@499 516 rootsz=2
pascal@499 517 elif [ $clusters -lt 65525 ]; then
pascal@497 518 fsect=$((($clusters+2+255)/256))
pascal@497 519 ftype="31 36"
pascal@497 520 fhead="F8 FF FF FF"
pascal@499 521 rsect=$(( 1+ ((2*$fsect)-1)%4 ))
pascal@499 522 fsz="$(printf "%04X" $fsect | sed 's/\(..\)\(..\)/\2 \1/')"
pascal@499 523 rootsz=2
pascal@499 524 else
pascal@499 525 fsect=$((($clusters+2+127)/128))
pascal@499 526 ftype="33 32"
pascal@499 527 fhead="F8 FF FF 0F FF FF FF FF F8 FF FF 0F"
pascal@499 528 rsect=$(( 6+ ((2*$fsect)-6)%4 ))
pascal@499 529 fsz="$(printf "%08X" $fsect | sed 's/\(..\)\(..\)\(..\)\(..\)/\4 \3 \2 \1/')"
pascal@499 530 rootsz=1
pascal@476 531 fi
pascal@497 532 # reserved + fat*2 + root dir + dirs
pascal@499 533 count=$((($rsect + $fsect*2)/4 + $rootsz + $dclust ))
pascal@497 534 s=$((($count+$fclust)*4))
pascal@476 535 if [ $s -gt 65535 ]; then
pascal@476 536 size="00 00"
pascal@476 537 size32="$(printf "%02X %02X %02X %02X" $(($s%256)) \
pascal@476 538 $((($s>>8)%256)) $((($s>>16)%256)) $((($s>>24)%256)) )"
pascal@476 539 else
pascal@476 540 size="$(printf "%02X %02X" $(($s%256)) $((($s>>8)%256)) )"
pascal@476 541 size32="00 00 00 00"
pascal@476 542 fi
pascal@497 543 dd if=/dev/zero bs=512 of=$basedir/boot/isolinux/efi.img \
pascal@497 544 count=$s 2> /dev/null
pascal@497 545
pascal@497 546 # Create boot sector
pascal@499 547 if [ "$ftype" == "33 32" ]; then
pascal@499 548 hexdump -R <<EOT | dd of=$basedir/boot/isolinux/efi.img \
pascal@499 549 conv=notrunc
pascal@499 550 0 eb 58 90 53 6c 69 54 61 7a 00 00 00 02 04 $rsect 00 |
pascal@499 551 0 02 00 00 $size f8 00 00 20 00 40 00 00 00 00 00 |
pascal@499 552 0 $size32 $fsz 00 00 00 00 02 00 00 00 |
pascal@499 553 0 01 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 |
pascal@499 554 0 80 00 29 00 00 00 00 53 59 53 54 45 4d 00 00 00 |
pascal@499 555 0 00 00 46 41 54 $ftype 20 20 20 cd 18 cd 19 eb fa |
pascal@499 556 EOT
pascal@499 557 while read ofs data; do
pascal@499 558 echo "0 ${data//:/ } |" | hexdump -R | dd conv=notrunc \
pascal@499 559 bs=1 seek=$ofs of=$basedir/boot/isolinux/efi.img
pascal@499 560 done <<EOT
pascal@499 561 510 55:aa:52:52:61:41
pascal@499 562 996 72:72:41:61:ff:ff:ff:ff:02
pascal@499 563 1022 55:aa
pascal@499 564 EOT
pascal@499 565 else
pascal@499 566 echo -en '\x55\xAA' | dd of=$basedir/boot/isolinux/efi.img \
pascal@499 567 seek=510 bs=1 conv=notrunc
pascal@499 568 hexdump -R <<EOT | dd of=$basedir/boot/isolinux/efi.img \
pascal@499 569 conv=notrunc
pascal@497 570 0 eb 3c 90 53 6c 69 54 61 7a 00 00 00 02 04 $rsect 00 |
pascal@497 571 0 02 40 00 $size f8 $fsz 20 00 40 00 00 00 00 00 |
pascal@499 572 0 $size32 80 00 29 00 00 00 00 53 59 53 54 45 |
pascal@499 573 0 4d 20 20 20 20 20 46 41 54 $ftype 20 20 20 cd 18 |
pascal@476 574 0 cd 19 eb fa |
pascal@476 575 EOT
pascal@499 576 fi 2> /dev/null
pascal@476 577
pascal@497 578 # Create fats
pascal@497 579 echo "0 $fhead |" | hexdump -R | dd of=$basedir/boot/isolinux/efi.img \
pascal@497 580 seek=$(($rsect)) bs=512 conv=notrunc 2> /dev/null
pascal@497 581 echo "0 $fhead |" | hexdump -R | dd of=$basedir/boot/isolinux/efi.img \
pascal@497 582 seek=$(($rsect+$fsect)) bs=512 conv=notrunc 2> /dev/null
pascal@497 583
pascal@499 584 # Add label
pascal@500 585 echo "0 53 59 53 54 45 4d 20 20 20 20 20 08 |" | hexdump -R | \
pascal@499 586 dd of=$basedir/boot/isolinux/efi.img bs=512 conv=notrunc \
pascal@499 587 seek=$(($rsect+$fsect+$fsect)) 2> /dev/null
pascal@499 588
pascal@497 589 mkdir -p /tmp/mnt$$
pascal@497 590 mount -o loop $basedir/boot/isolinux/efi.img /tmp/mnt$$
pascal@497 591 ( cd $basedir; find efi -type d | cpio -o -H newc ) | \
pascal@498 592 ( cd /tmp/mnt$$ ; cpio -idmu 2> /dev/null )
pascal@497 593 sync
pascal@497 594 dd if=$basedir/boot/isolinux/efi.img of=/tmp/fat$$ \
pascal@497 595 skip=$rsect bs=512 count=$fsect 2> /dev/null
pascal@497 596 ( cd $basedir; find efi -type f | cpio -o -H newc ) | \
pascal@498 597 ( cd /tmp/mnt$$ ; cpio -idmu 2> /dev/null )
pascal@497 598 umount /tmp/mnt$$
pascal@497 599 cat /tmp/fat$$ /tmp/fat$$ | dd of=$basedir/boot/isolinux/efi.img \
pascal@497 600 seek=$rsect bs=512 conv=notrunc 2> /dev/null
pascal@497 601 rm /tmp/fat$$
pascal@497 602 rmdir /tmp/mnt$$
pascal@497 603
pascal@497 604 dd count=0 bs=2k of=$basedir/boot/isolinux/efi.img \
pascal@497 605 seek=$count 2> /dev/null
pascal@476 606 }
pascal@476 607
al@412 608
pascal@362 609 # isolinux.conf doesn't know the kernel version.
paul@363 610 # We name the kernel image 'bzImage'.
paul@363 611 # isolinux/syslinux first tries the '64' suffix with a 64bits cpu.
al@412 612
al@412 613 make_bzImage_hardlink() {
pascal@476 614 if [ -e ${1:-.}/vmlinuz*slitaz ]; then
al@412 615 rm -f ${1:-.}/bzImage 2>/dev/null
al@412 616 ln ${1:-.}/vmlinuz*slitaz ${1:-.}/bzImage
pascal@362 617 fi
pascal@476 618 if [ -e ${1:-.}/vmlinuz*slitaz64 ]; then
pascal@362 619 rm -f ${1:-.}/bzImage64 2> /dev/null
al@412 620 ln ${1:-.}/vmlinuz*slitaz64 ${1:-.}/bzImage64
pascal@362 621 fi
pascal@362 622 }
pascal@362 623
al@412 624
al@412 625 create_iso() {
pascal@274 626 cd $2
pascal@365 627 deduplicate
al@412 628
pascal@494 629 [ $(ls $2/boot/grub* 2> /dev/null | wc -l) -lt 2 ] && rm -rf $2/boot/grub*
pascal@476 630 make_bzImage_hardlink $2/boot
pascal@476 631 alloc_uefi_part $(ls -r $2/boot/vmlinuz*slitaz*)
pascal@476 632
pascal@444 633 cat > /tmp/cdsort$$ <<EOT
pascal@476 634 $PWD/boot/isolinux 100
pascal@476 635 $(ls -r $PWD/boot/rootfs* | awk 'BEGIN{n=149} { print $1 " " n-- }')
pascal@476 636 $(ls $PWD/boot/bzImage* | awk 'BEGIN{n=200} { print $1 " " n-- }')
pascal@497 637 $(find $PWD/efi -type f 2>/dev/null | sort -r | awk 'BEGIN{n=299} { print $1 " " n-- }')
pascal@476 638 $PWD/boot/isolinux/efi.img 300
pascal@476 639 $PWD/boot/isolinux/isolinux.bin 399
pascal@444 640 $PWD/boot/isolinux/boot.cat 400
pascal@444 641 EOT
pascal@444 642
al@412 643 action 'Computing md5...'
pascal@467 644 touch boot/isolinux/boot.cat
pascal@485 645 find * -type f ! -name md5sum ! -name 'vmlinuz-*' -exec md5sum {} \; | \
pascal@485 646 sort -k 2 > md5sum
pascal@274 647 status
al@412 648
al@412 649 cd - >/dev/null
al@412 650 title 'Generating ISO image'
al@412 651
al@416 652 _ 'Generating %s' "$1"
pascal@476 653 uefi="$(cd $2 ; ls boot/isolinux/efi.img 2> /dev/null)"
pascal@444 654 genisoimage -R -o $1 -hide-rr-moved -sort /tmp/cdsort$$ \
pascal@436 655 -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
pascal@436 656 -no-emul-boot -boot-load-size 4 -boot-info-table \
pascal@436 657 ${uefi:+-eltorito-alt-boot -efi-boot $uefi -no-emul-boot} \
pascal@433 658 -V "${VOLUM_NAME:-SliTaz}" -p "${PREPARED:-$(id -un)}" \
pascal@434 659 -volset "SliTaz $SLITAZ_VERSION" -input-charset utf-8 \
pascal@426 660 -A "tazlito $VERSION/$(genisoimage --version)" \
pascal@465 661 -copyright README -P "www.slitaz.org" -no-pad $2
pascal@444 662 rm -f /tmp/cdsort$$
pascal@467 663 dd if=/dev/zero bs=2k count=16 >> $1 2> /dev/null
pascal@467 664
pascal@467 665 mkdir /tmp/mnt$$
pascal@467 666 mount -o loop,ro $1 /tmp/mnt$$
pascal@476 667 fixup_uefi_part $1 /tmp/mnt$$
pascal@476 668 for i in boot/isolinux/isolinux.bin boot/isolinux/boot.cat \
pascal@476 669 ${uefi:+boot/isolinux/efi.img} ; do
pascal@467 670 sed -i "s|.* $i|$( cd /tmp/mnt$$ ; md5sum $i)|" $2/md5sum
pascal@467 671 done
pascal@467 672 dd if=$2/md5sum of=$1 conv=notrunc bs=2k \
pascal@492 673 seek=$(first_block /tmp/mnt$$/md5sum) 2> /dev/null
pascal@468 674 umount -d /tmp/mnt$$
pascal@467 675 rmdir /tmp/mnt$$
pascal@467 676
al@412 677 if [ -s '/etc/tazlito/info' ]; then
pascal@196 678 if [ $(stat -c %s /etc/tazlito/info) -lt $(( 31*1024 )) ]; then
al@412 679 action 'Storing ISO info...'
al@412 680 dd if=/etc/tazlito/info bs=1k seek=1 of=$1 conv=notrunc 2>/dev/null
pascal@195 681 status
pascal@195 682 fi
pascal@195 683 fi
al@412 684
pascal@436 685 if [ -x '/usr/bin/isohybrid' ]; then
pascal@436 686 action 'Creating hybrid ISO...'
pascal@476 687 isohybrid $1 $([ -n "$uefi" ] || echo -entry 2) 2>/dev/null
pascal@436 688 status
pascal@436 689 fi
pascal@436 690
al@412 691 if [ -x '/usr/bin/iso2exe' ]; then
al@412 692 echo 'Creating EXE header...'
al@412 693 /usr/bin/iso2exe $1 2>/dev/null
pascal@297 694 fi
pascal@101 695 }
pascal@101 696
al@412 697
MikeDSmith25@83 698 # Generate a new ISO image using isolinux.
al@412 699
al@412 700 gen_livecd_isolinux() {
pascal@13 701 # Some packages may want to alter iso
pascal@13 702 genisohooks iso
al@412 703 [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ] && die 'Unable to find isolinux binary.'
al@412 704
pankso@35 705 # Set date for boot msg.
al@412 706 if grep -q 'XXXXXXXX' "$ROOTCD/boot/isolinux/isolinux.cfg"; then
al@412 707 DATE=$(date +%Y%m%d)
al@412 708 action 'Setting build date to: %s...' "$DATE"
al@412 709 sed -i "s/XXXXXXXX/$DATE/" "$ROOTCD/boot/isolinux/isolinux.cfg"
pankso@35 710 status
pankso@35 711 fi
al@412 712
pankso@1 713 cd $DISTRO
pascal@101 714 create_iso $ISO_NAME.iso $ROOTCD
al@412 715
al@412 716 action 'Creating the ISO md5sum...'
pascal@486 717 md5sum $ISO_NAME.iso > $ISO_NAME.md5
pankso@53 718 status
al@412 719
pankso@279 720 separator
pascal@37 721 # Some packages may want to alter final iso
pascal@37 722 genisohooks final
pankso@1 723 }
pankso@1 724
al@412 725
al@412 726 lzma_history_bits() {
pankso@123 727 #
paul@154 728 # This generates an ISO which boots with Qemu but gives
pankso@123 729 # rootfs errors in frugal or liveUSB mode.
pankso@123 730 #
al@412 731 # local n
al@412 732 # local sz
al@412 733 # n=20 # 1Mb
al@412 734 # sz=$(du -sk $1 | cut -f1)
al@412 735 # while [ $sz -gt 1024 -a $n -lt 28 ]; do
al@412 736 # n=$(( $n + 1 ))
al@412 737 # sz=$(( $sz / 2 ))
al@412 738 # done
al@412 739 # echo $n
pascal@432 740 echo ${LZMA_HISTORY_BITS:-24}
pascal@103 741 }
pascal@103 742
al@412 743
al@412 744 lzma_switches() {
al@412 745 local proc_num=$(grep -sc '^processor' /proc/cpuinfo)
pascal@431 746 echo "-d$(lzma_history_bits $1) -mt${proc_num:-1} -mc1000"
pascal@111 747 }
pascal@111 748
al@412 749
al@412 750 lzma_set_size() {
pascal@232 751 # Update size field for lzma'd file packed using -si switch
al@412 752 return # Need to fix kernel code?
al@412 753
al@412 754 local n i
pascal@387 755 n=$(unlzma < $1 | wc -c)
pascal@231 756 for i in $(seq 1 8); do
pascal@231 757 printf '\\\\x%02X' $(($n & 255))
pascal@231 758 n=$(($n >> 8))
al@412 759 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2>/dev/null
pascal@231 760 }
pascal@231 761
al@412 762
al@412 763 align_to_32bits() {
al@412 764 local size=$(stat -c %s ${1:-/dev/null})
pascal@312 765 [ $((${size:-0} & 3)) -ne 0 ] &&
al@412 766 dd if=/dev/zero bs=1 count=$((4 - ($size & 3))) >> $1 2>/dev/null
pascal@289 767 }
pascal@289 768
al@412 769
pascal@439 770 dogzip() {
pascal@439 771 gzip -9 > $1
pascal@439 772 [ -x /usr/bin/advdef ] && advdef -qz4 $1
pascal@439 773 }
pascal@439 774
pascal@439 775
pascal@101 776 # Pack rootfs
al@412 777
al@412 778 pack_rootfs() {
al@412 779 ( cd $1; find . -print | cpio -o -H newc ) | \
al@412 780 case "$COMPRESSION" in
al@412 781 none)
al@412 782 _ 'Creating %s without compression...' 'initramfs'
al@412 783 cat > $2
al@412 784 ;;
al@412 785 gzip)
al@412 786 _ 'Creating %s with gzip compression...' 'initramfs'
pascal@439 787 dogzip $2
al@412 788 ;;
al@412 789 *)
al@412 790 _ 'Creating %s with lzma compression...' 'initramfs'
al@412 791 lzma e -si -so $(lzma_switches $1) > $2
al@412 792 lzma_set_size $2
al@412 793 ;;
al@412 794 esac
pascal@289 795 align_to_32bits $2
pankso@150 796 echo 1 > /tmp/rootfs
pankso@150 797 }
pankso@150 798
al@412 799
pankso@150 800 # Compression functions for writeiso.
al@412 801
al@412 802 write_initramfs() {
al@412 803 case "$COMPRESSION" in
al@412 804 lzma)
al@412 805 _n 'Creating %s with lzma compression...' "$INITRAMFS"
al@412 806 cpio -o -H newc | lzma e -si -so $(lzma_switches) > "/$INITRAMFS"
al@412 807 align='y'
al@412 808 lzma_set_size "/$INITRAMFS"
al@412 809 ;;
al@412 810 gzip)
al@412 811 _ 'Creating %s with gzip compression...' "$INITRAMFS"
pascal@439 812 cpio -o -H newc | dogzip "/$INITRAMFS"
al@412 813 ;;
al@412 814 *)
al@412 815 # align='y'
al@412 816 _ 'Creating %s without compression...' "$INITRAMFS"
al@412 817 cpio -o -H newc > "/$INITRAMFS"
al@412 818 ;;
al@412 819 esac < /tmp/list
al@412 820 [ "$align" == 'y' -a -z "$noalign" ] && align_to_32bits "/$INITRAMFS"
pankso@150 821 echo 1 > /tmp/rootfs
pascal@101 822 }
pascal@101 823
al@412 824
paul@341 825 # Deduplicate files (MUST be on the same filesystem).
al@412 826
al@412 827 deduplicate() {
al@412 828 find "${@:-.}" -type f -size +0c -xdev -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | sort | \
al@412 829 (
al@412 830 save=0; hardlinks=0; old_attr=""; old_inode=""; old_link=""; old_file=""
al@412 831 while read attr inode link file; do
al@412 832 [ -L "$file" ] && continue
al@412 833 if [ "$attr" == "$old_attr" -a "$inode" != "$old_inode" ]; then
al@412 834 if cmp "$file" "$old_file" >/dev/null 2>&1 ; then
al@412 835 rm -f "$file"
al@412 836 if ln "$old_file" "$file" 2>/dev/null; then
al@412 837 inode="$old_inode"
al@412 838 [ "$link" -eq 1 ] && hardlinks=$(($hardlinks+1)) &&
al@412 839 save="$(($save+(${attr%%-*}+512)/1024))"
al@412 840 else
al@412 841 cp -a "$old_file" "$file"
al@412 842 fi
al@412 843 fi
al@412 844 fi
al@412 845 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
al@412 846 done
al@416 847 _ '%s Kbytes saved in %s duplicate files.' "$save" "$hardlinks"
al@412 848 )
al@412 849
al@412 850 find "$@" -type l -xdev -exec stat -c '%s-%u-%g-TARGET- %i %h %n' {} \; | sort | \
al@412 851 (
al@412 852 old_attr=""; hardlinks=0;
al@412 853 while read attr inode link file; do
al@412 854 attr="${attr/-TARGET-/-$(readlink $file)}"
al@412 855 if [ "$attr" == "$old_attr" ]; then
al@412 856 if [ "$inode" != "$old_inode" ]; then
al@412 857 rm -f "$file"
al@412 858 if ln "$old_file" "$file" 2>/dev/null; then
al@412 859 [ "$link" -eq 1 ] && hardlinks=$(($hardlinks+1))
al@412 860 else
al@412 861 cp -a "$old_file" "$file"
al@412 862 fi
al@412 863 fi
pascal@305 864 else
al@412 865 old_file="$file"
al@412 866 old_attr="$attr"
al@412 867 old_inode="$inode"
pascal@305 868 fi
al@412 869 done
al@416 870 _ '%s duplicate symlinks.' "$hardlinks"
al@412 871 )
pascal@285 872 }
pascal@285 873
al@412 874
pascal@285 875 # Generate a new initramfs from the root filesystem.
al@412 876
al@412 877 gen_initramfs() {
pascal@285 878 # Just in case CTRL+c
pascal@285 879 rm -f $DISTRO/gen
pascal@285 880
pascal@285 881 # Some packages may want to alter rootfs
pascal@285 882 genisohooks rootfs
pascal@285 883 cd $1
pascal@285 884
pascal@445 885 # Normalize file time
pascal@446 886 find $1 -newer $1 -exec touch -hr $1 {} \;
pascal@445 887
pascal@285 888 # Link duplicate files
pascal@365 889 deduplicate
pascal@69 890
pankso@150 891 # Use lzma if installed. Display rootfs size in realtime.
al@412 892 rm -f /tmp/rootfs 2>/dev/null
pankso@150 893 pack_rootfs . $DISTRO/$(basename $1).gz &
pankso@150 894 sleep 2
pankso@150 895 echo -en "\nFilesystem size:"
al@412 896 while [ ! -f /tmp/rootfs ]; do
pankso@150 897 sleep 1
al@412 898 echo -en "\\033[18G$(du -sh $DISTRO/$(basename $1).gz | awk '{print $1}') "
pankso@150 899 done
pankso@150 900 echo -e "\n"
pascal@361 901 rm -f /tmp/rootfs
pascal@14 902 cd $DISTRO
pascal@111 903 mv $(basename $1).gz $ROOTCD/boot
pankso@1 904 }
pankso@1 905
al@412 906
pankso@332 907 distro_sizes() {
al@412 908 if [ -n "$start_time" ]; then
al@412 909 time=$(($(date +%s) - $start_time))
pankso@264 910 sec=$time
pankso@264 911 div=$(( ($time + 30) / 60))
al@412 912 [ "$div" -ne 0 ] && min="~ ${div}m"
al@416 913 _ 'Build time : %ss %s' "$sec" "$min"
pankso@264 914 fi
al@398 915 cat <<EOT
pankso@264 916 Build date : $(date +%Y%m%d)
al@412 917 Packages : $(ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l)
al@412 918 Rootfs size : $(du -csh $ROOTFS*/ | awk 'END { print $1 }')
al@412 919 Initramfs size : $(du -csh $ROOTCD/boot/rootfs*.gz | awk 'END { print $1 }')
al@412 920 ISO image size : $(du -sh $ISO_NAME.iso | awk '{ print $1 }')
pankso@264 921 EOT
al@412 922 footer "Image is ready: $ISO_NAME.iso"
pankso@1 923 }
pankso@1 924
al@412 925
pascal@22 926 # Print ISO and rootfs size.
al@412 927
pankso@332 928 distro_stats() {
al@412 929 title 'Distro statistics: %s' "$DISTRO"
pascal@22 930 distro_sizes
pascal@22 931 }
pascal@22 932
al@412 933
MikeDSmith25@83 934 # Create an empty configuration file.
al@412 935
al@412 936 empty_config_file() {
al@398 937 cat >> tazlito.conf <<"EOF"
pankso@338 938 # tazlito.conf: Tazlito (SliTaz Live Tool) configuration file.
pankso@1 939 #
pankso@1 940
pankso@1 941 # Name of the ISO image to generate.
pankso@1 942 ISO_NAME=""
pankso@1 943
MikeDSmith25@83 944 # ISO image volume name.
pankso@1 945 VOLUM_NAME="SliTaz"
pankso@1 946
MikeDSmith25@83 947 # Name of the preparer.
pankso@1 948 PREPARED="$USER"
pankso@1 949
pankso@1 950 # Path to the packages repository and the packages.list.
pankso@1 951 PACKAGES_REPOSITORY=""
pankso@1 952
al@412 953 # Path to the distro tree to gen-distro from a list of packages.
pankso@1 954 DISTRO=""
pankso@1 955
MikeDSmith25@83 956 # Path to the directory containing additional files
pankso@1 957 # to copy into the rootfs and rootcd of the LiveCD.
pankso@1 958 ADDFILES="$DISTRO/addfiles"
pascal@12 959
pascal@12 960 # Default answer for binary question (Y or N)
pascal@12 961 DEFAULT_ANSWER="ASK"
pascal@21 962
pascal@38 963 # Compression utility (lzma, gzip or none)
pascal@21 964 COMPRESSION="lzma"
pankso@1 965 EOF
pankso@1 966 }
pankso@1 967
al@412 968
al@412 969 # Extract rootfs.gz somewhere
al@412 970
al@412 971 extract_rootfs() {
al@412 972 # Detect compression format: *.lzma.cpio, *.gzip.cpio, or *.cpio
paul@479 973 # First part (lzcat or zcat) may not fail, but cpio will fail on incorrect format
al@412 974 (cd "$2"; lzcat "$1" | cpio -idm --quiet 2>/dev/null) && return
al@412 975 (cd "$2"; zcat "$1" | cpio -idm --quiet 2>/dev/null) && return
al@412 976 (cd "$2"; cat "$1" | cpio -idm --quiet 2>/dev/null)
pascal@101 977 }
pascal@101 978
al@412 979
al@412 980 # Extract flavor file to temp directory
al@412 981
al@412 982 extract_flavor() {
al@412 983 # Input: $1 - flavor name to extract;
al@412 984 # $2 = absent/empty: just extract 'outer layer'
al@412 985 # $2 = 'full': also extract 'inner' rootcd and rootfs archives, make files rename
al@412 986 # $2 = 'info': as 'full' and also make 'info' file to put into ISO
al@412 987 # Output: temp dir path where flavor was extracted
al@412 988 local f="$1.flavor" from to infos="$1.desc"
al@412 989 [ -f "$f" ] || die "File '$f' not found"
al@412 990 local dir="$(mktemp -d)"
al@412 991 zcat "$f" | (cd $dir; cpio -i --quiet >/dev/null)
al@412 992
al@412 993 if [ -n "$2" ]; then
al@412 994 cd $dir
al@412 995
al@412 996 [ -s "$1.receipt" ] && infos="$infos\n$1.receipt"
al@412 997
al@412 998 for i in rootcd rootfs; do
al@412 999 [ -f "$1.$i" ] || continue
al@412 1000 mkdir "$i"
al@412 1001 zcat "$1.$i" | (cd "$i"; cpio -idm --quiet 2>/dev/null)
al@412 1002 zcat "$1.$i" | cpio -tv 2>/dev/null > "$1.list$i"; infos="$infos\n$1.list$i"
al@412 1003 rm "$1.$i"
al@412 1004 done
pascal@491 1005 touch -t 197001010100.00 $1.*
al@412 1006 # Info to be stored inside ISO
pascal@439 1007 [ "$2" == info ] && echo -e $infos | cpio -o -H newc | dogzip info
al@412 1008 rm $1.list*
al@412 1009
al@412 1010 # Renames
al@412 1011 while read from to; do
al@412 1012 [ -f "$from" ] || continue
al@412 1013 mv "$from" "$to"
al@412 1014 done <<EOT
al@412 1015 $1.nonfree non-free.list
al@412 1016 $1.pkglist packages.list
al@412 1017 $1-distro.sh distro.sh
al@412 1018 $1.receipt receipt
al@412 1019 $1.mirrors mirrors
al@412 1020 $1.desc description
al@412 1021 EOT
al@412 1022 fi
al@412 1023
al@412 1024 echo $dir
al@412 1025 }
al@412 1026
al@412 1027
al@412 1028 # Pack flavor file from temp directory
al@412 1029
al@412 1030 pack_flavor() {
pascal@439 1031 (cd "$1"; ls | grep -v err | cpio -o -H newc) | dogzip "$2.flavor"
al@412 1032 }
al@412 1033
al@412 1034
pascal@101 1035 # Remove duplicate files
al@412 1036
pascal@468 1037 files_match() {
pascal@468 1038 if [ -d "$1" ]; then
pascal@468 1039 return 1
pascal@468 1040
pascal@468 1041 elif [ -L "$1" ] && [ -L "$2" ]; then
pascal@468 1042 [ "$(readlink "$1")" == "$(readlink "$2")" ] && return 0
pascal@468 1043
pascal@468 1044 elif [ -f "$1" ] && [ -f "$2" ]; then
pascal@468 1045 cmp -s "$1" "$2" && return 0
pascal@468 1046
pascal@468 1047 [ "$(basename "$3")" == 'volatile.cpio.gz' ] &&
pascal@468 1048 [ "$(dirname $(dirname "$3"))" == ".$INSTALLED" ] &&
pascal@468 1049 return 0
pascal@468 1050
pascal@468 1051 elif [ "$(ls -l "$1"|cut -c1-10)$(stat -c '%a:%u:%g:%t:%T' "$1")" == \
pascal@470 1052 "$(ls -l "$2"|cut -c1-10)$(stat -c '%a:%u:%g:%t:%T' "$2")" ]; then
pascal@468 1053 return 0
pascal@468 1054
pascal@483 1055 fi 2> /dev/null
pascal@468 1056 return 1
pascal@468 1057 }
pascal@468 1058
pascal@468 1059 remove_with_path() {
pascal@468 1060 dir="$(dirname $1)"
pascal@468 1061 rm -f "$1"
pascal@468 1062 while rmdir "$dir" 2> /dev/null; do
pascal@468 1063 dir="$(dirname $dir)"
pascal@468 1064 done
pascal@468 1065 }
pascal@468 1066
al@412 1067 mergefs() {
al@392 1068 # Note, many packages have files with spaces in the name
al@392 1069 IFS=$'\n'
al@392 1070
al@412 1071 local size1=$(du -hs "$1" | awk '{ print $1 }')
al@412 1072 local size2=$(du -hs "$2" | awk '{ print $1 }')
al@412 1073 action 'Merge %s (%s) into %s (%s)' "$(basename "$1")" "$size1" "$(basename "$2")" "$size2"
al@412 1074
pascal@101 1075 # merge symlinks files and devices
al@412 1076 ( cd "$1"; find ) | \
al@412 1077 while read file; do
pascal@468 1078 files_match "$1/$file" "$2/$file" "$file" &&
pascal@468 1079 remove_with_path "$2/$file"
pascal@488 1080 [ -d "$1/$file" ] && [ -d "$2/$file" ] && rmdir "$2/$file" 2>/dev/null
pascal@101 1081 done
al@412 1082
al@412 1083 unset IFS
pascal@111 1084 status
pascal@101 1085 }
pascal@101 1086
al@412 1087
al@412 1088 cleanup_merge() {
pascal@101 1089 rm -rf $TMP_DIR
pascal@101 1090 exit 1
pascal@101 1091 }
pascal@101 1092
pascal@111 1093
pascal@111 1094 # Update isolinux config files for multiple rootfs
al@412 1095
al@412 1096 update_bootconfig() {
pascal@235 1097 local files
al@416 1098 action 'Updating boot config files...'
pascal@235 1099 files="$(grep -l 'include common' $1/*.cfg)"
al@412 1100 for file in $files; do
al@412 1101 awk -v n=$(echo $2 | awk '{ print NF/2 }') '{
al@412 1102 if (/label/) label=$0;
al@412 1103 else if (/kernel/) kernel=$0;
al@412 1104 else if (/append/) {
al@412 1105 i=index($0,"rootfs.gz");
al@412 1106 append=substr($0,i+9);
al@412 1107 }
al@412 1108 else if (/include/) {
al@412 1109 for (i = 1; i <= n; i++) {
al@412 1110 print label i
al@412 1111 print kernel;
al@412 1112 initrd="initrd=/boot/rootfs" n ".gz"
al@412 1113 for (j = n - 1; j >= i; j--) {
al@412 1114 initrd=initrd ",/boot/rootfs" j ".gz";
al@412 1115 }
al@412 1116 printf "\tappend %s%s\n",initrd,append;
al@412 1117 print "";
al@412 1118 }
al@412 1119 print;
al@412 1120 }
al@412 1121 else print;
al@412 1122 }' < $file > $file.$$
al@412 1123 mv -f $file.$$ $file
pascal@111 1124 done
pascal@235 1125 sel="$(echo $2 | awk '{
al@412 1126 for (i=1; i<=NF; i++)
al@412 1127 if (i % 2 == 0) printf " slitaz%d", i/2
al@412 1128 else printf " %s", $i
al@412 1129 }')"
al@412 1130
pascal@278 1131 [ -s $1/common.cfg ] && cat >> $1/common.cfg <<EOT
pascal@111 1132
pascal@111 1133 label slitaz
pascal@111 1134 kernel /boot/isolinux/ifmem.c32
pascal@235 1135 append$sel noram
pascal@111 1136
pascal@111 1137 label noram
pascal@111 1138 config noram.cfg
pascal@111 1139
pascal@111 1140 EOT
al@412 1141
pascal@235 1142 # Update vesamenu
al@412 1143 if [ -s "$1/isolinux.cfg" ]; then
pascal@235 1144 files="$files $1/isolinux.cfg"
pascal@278 1145 awk -v n=$(echo $2 | awk '{ print NF/2 }') -v "sel=$sel" '
al@412 1146 BEGIN {
al@412 1147 kernel = " COM32 c32box.c32"
pascal@235 1148 }
al@412 1149 {
al@412 1150 if (/ROWS/) print "MENU ROWS " n+$3;
al@412 1151 else if (/TIMEOUTROW/) print "MENU TIMEOUTROW " n+$3;
al@412 1152 else if (/TABMSGROW/) print "MENU TABMSGROW " n+$3;
al@412 1153 else if (/CMDLINEROW/) print "MENU CMDLINEROW " n+$3;
al@412 1154 else if (/VSHIFT/) {
al@412 1155 x = $3-n;
al@412 1156 if (x < 0) x = 0;
al@412 1157 print "MENU VSHIFT " x;
al@412 1158 }
al@412 1159 else if (/rootfs.gz/) {
al@412 1160 linux = "";
al@412 1161 if (/bzImage/) linux = "linux /boot/bzImage ";
al@412 1162 i = index($0, "rootfs.gz");
al@412 1163 append = substr($0, i+9);
al@413 1164 printf "\tkernel /boot/isolinux/ifmem.c32\n";
al@413 1165 printf "\tappend%s noram\n", sel;
al@413 1166 printf "\nlabel noram\n\tMENU HIDE\n\tconfig noram.cfg\n\n";
al@412 1167 for (i = 1; i <= n; i++) {
al@412 1168 print "LABEL slitaz" i
al@413 1169 printf "\tMENU LABEL SliTaz slitaz%d Live\n", i;
al@413 1170 printf "%s\n", kernel;
al@412 1171 initrd = "initrd=/boot/rootfs" n ".gz"
al@412 1172 for (j = n - 1; j >= i; j--) {
al@412 1173 initrd = initrd ",/boot/rootfs" j ".gz";
al@412 1174 }
al@413 1175 printf "\tappend %s%s%s\n\n", linux, initrd, append;
al@412 1176 }
al@412 1177 }
al@412 1178 else if (/bzImage/) kernel = $0;
al@412 1179 else print;
al@412 1180 }' < $1/isolinux.cfg > $1/isolinux.cfg.$$
pascal@235 1181 mv $1/isolinux.cfg.$$ $1/isolinux.cfg
pascal@235 1182 fi
al@412 1183
pascal@278 1184 [ -s $1/c32box.c32 ] && sed -i -e '/kernel.*ifmem/d' \
pascal@278 1185 -e 's/append \([0-9]\)/append ifmem \1/' $1/isolinux.cfg
pascal@111 1186 cat > $1/noram.cfg <<EOT
pascal@111 1187 implicit 0
pascal@111 1188 prompt 1
pascal@111 1189 timeout 80
pascal@344 1190 $(grep '^F[0-9]' $1/isolinux.cfg)
pascal@278 1191
pascal@344 1192 $([ -s $1/isolinux.msg ] && echo display isolinux.msg)
pascal@319 1193 say Not enough RAM to boot slitaz. Trying hacker mode...
pascal@319 1194 default hacker
pascal@319 1195 label hacker
pascal@319 1196 KERNEL /boot/bzImage
pascal@319 1197 append rw root=/dev/null vga=normal
pascal@319 1198
pascal@278 1199 label reboot
pascal@111 1200 EOT
al@412 1201
pascal@278 1202 if [ -s $1/c32box.c32 ]; then
pascal@278 1203 cat >> $1/noram.cfg <<EOT
pascal@278 1204 COM32 c32box.c32
pascal@278 1205 append reboot
pascal@278 1206
pascal@278 1207 label poweroff
pascal@278 1208 COM32 c32box.c32
pascal@278 1209 append poweroff
pascal@278 1210
pascal@278 1211 EOT
pascal@278 1212 else
pascal@278 1213 echo " com32 reboot.c32" >> $1/noram.cfg
pascal@278 1214 fi
al@412 1215
pascal@182 1216 # Restore real label names
pascal@278 1217 [ -s $1/common.cfg ] && files="$1/common.cfg $files"
pascal@182 1218 echo $2 | awk '{ for (i=NF; i>1; i-=2) printf "%d/%s\n",i/2,$i }' | \
pascal@182 1219 while read pat; do
pascal@278 1220 sed -i "s/slitaz$pat/" $files
pascal@182 1221 done
pascal@111 1222 status
pascal@111 1223 }
pascal@111 1224
al@412 1225
pascal@426 1226 # Uncompress rootfs or module to stdout
pascal@426 1227
pascal@426 1228 uncompress() {
pascal@458 1229 zcat $1 2> /dev/null || xzcat $1 2> /dev/null ||
pascal@458 1230 { [ $(od -N 1 -An $1) -eq 135 ] && unlzma < $1; } || cat $1
pascal@426 1231 }
pascal@426 1232
pascal@426 1233
pascal@170 1234 # Install a missing package
al@412 1235
al@412 1236 install_package() {
al@412 1237 if [ -z "$2" ]; then
al@416 1238 answer=$(yesorno "$(_ 'Install package %s?' "$1")" 'n')
al@412 1239 else
al@416 1240 answer=$(yesorno "$(_n 'Install package %s for Kernel %s? ' "$1" "$2")" 'n')
al@412 1241 fi
pascal@170 1242 case "$answer" in
al@416 1243 y)
al@412 1244 # We don't want package on host cache.
al@412 1245 action 'Getting and installing package: %s' "$1"
al@412 1246 yes y | tazpkg get-install $1 --quiet 2>&1 >> $log || exit 1
al@412 1247 status ;;
al@412 1248 *)
al@412 1249 return 1 ;;
pascal@170 1250 esac
pascal@170 1251 }
pascal@170 1252
al@412 1253
pascal@170 1254 # Check iso for loram transformation
al@412 1255
al@412 1256 check_iso_for_loram() {
al@412 1257 [ -s "$TMP_DIR/iso/boot/rootfs.gz" ] ||
al@412 1258 [ -s "$TMP_DIR/iso/boot/rootfs1.gz" ]
pascal@170 1259 }
pascal@170 1260
al@412 1261
pascal@501 1262 # Remove duplicated files in $1/efi/boot from $1/boot
pascal@501 1263
pascal@501 1264 cleanup_efi_boot() {
pascal@501 1265 for i in $1/efi/boot/* ; do
pascal@501 1266 [ -f $i ] || continue
pascal@508 1267 case "$i" in
pascal@508 1268 */rootfs*) cmp $i ${i/\/efi\//\/} || continue ;;
pascal@508 1269 */bootia32.efi) cmp $i $1/boot/bzImage || continue
pascal@508 1270 rm $1/efi/boot/linux.cmdline ;;
pascal@508 1271 */bootx64.efi) cmp $i $1/boot/bzImage64 || continue
pascal@508 1272 rm $1/efi/boot/linux.cmdline* ;;
pascal@508 1273 esac
pascal@501 1274 rm -f $i
pascal@507 1275 rmdir $1/efi/boot && rmdir $1/efi
pascal@503 1276 done 2> /dev/null
pascal@501 1277 }
pascal@501 1278
pascal@501 1279
pascal@172 1280 # Build initial rootfs for loram ISO ram/cdrom/http
al@412 1281
al@412 1282 build_initfs() {
pascal@426 1283 urliso="mirror.switch.ch/ftp/mirror/slitaz \
pascal@426 1284 download.tuxfamily.org/slitaz mirror1.slitaz.org mirror2.slitaz.org \
pascal@426 1285 mirror3.slitaz.org mirror.slitaz.org"
pascal@170 1286 version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//')
al@412 1287 [ -z "$version" ] && die "Can't find the kernel version." \
al@412 1288 'No file /boot/vmlinuz-<version> in ISO image. Abort.'
al@412 1289
pascal@225 1290 [ -s /usr/share/boot/busybox-static ] || install_package busybox-static
pascal@170 1291 need_lib=false
al@412 1292 for i in bin dev run mnt proc tmp sys lib/modules; do
al@412 1293 mkdir -p $TMP_DIR/initfs/$i
al@412 1294 done
pascal@312 1295 ln -s bin $TMP_DIR/initfs/sbin
al@412 1296 ln -s . $TMP_DIR/initfs/usr
al@412 1297 for aufs in aufs overlayfs; do
pascal@425 1298 [ -f /lib/modules/$version/kernel/fs/$aufs/$aufs.ko.?z ] && break
pascal@487 1299 install_package linux-$aufs $version && break
pascal@407 1300 install_package $aufs $version && break
pascal@387 1301 done || return 1
pascal@473 1302 [ -s /init ] || install_package slitaz-boot-scripts
pascal@289 1303 cp /init $TMP_DIR/initfs/
pascal@387 1304 cp /lib/modules/$version/kernel/fs/$aufs/$aufs.ko.?z \
pascal@289 1305 $TMP_DIR/initfs/lib/modules
al@412 1306 if [ "$1" == 'cdrom' ]; then
pascal@319 1307 sed -i '/mod squashfs/d' $TMP_DIR/initfs/init
pascal@313 1308 else
pascal@313 1309 [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
pascal@313 1310 while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.?z ]; do
pascal@313 1311 install_package linux-squashfs $version || return 1
pascal@313 1312 done
pascal@313 1313 cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.?z \
al@412 1314 $TMP_DIR/initfs/lib/modules
pascal@474 1315 #ls /sbin/unsquashfs /usr/lib/liblzma.so* $INSTALLED/squashfs/* | \
pascal@474 1316 #cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
pascal@313 1317 fi
al@412 1318 if [ "$1" == 'http' ]; then
pascal@426 1319 mkdir $TMP_DIR/initfs/etc $TMP_DIR/fs
pascal@172 1320 ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
pascal@172 1321 cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
pascal@426 1322 sed -i 's|/sbin/||;s/^logger/#&/' $TMP_DIR/initfs/lib/udhcpc
pascal@172 1323 cp -a /dev/fuse $TMP_DIR/initfs/dev
pascal@172 1324 if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
pascal@426 1325 cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/fusermount
pascal@172 1326 else
pascal@172 1327 need_lib=true
pascal@172 1328 fi
pascal@172 1329 if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
pascal@172 1330 cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
pascal@172 1331 else
pascal@172 1332 [ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
al@416 1333 cp /usr/bin/httpfs $TMP_DIR/initfs/bin
pascal@426 1334 cp /usr/bin/fusermount $TMP_DIR/initfs/bin
al@416 1335 cp -a /lib/librt* $TMP_DIR/initfs/lib
al@416 1336 cp -a /lib/libdl* $TMP_DIR/initfs/lib
al@416 1337 cp -a /lib/libpthread* $TMP_DIR/initfs/lib
pascal@172 1338 cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
al@416 1339 cp -a /lib/libresolv* $TMP_DIR/initfs/lib
al@416 1340 cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
pascal@172 1341 need_lib=true
pascal@172 1342 fi
pascal@426 1343 cd $TMP_DIR/fs
pascal@426 1344 echo 'Getting slitaz-release & ethernet modules...'
pascal@426 1345 for i in $(ls -r $TMP_DIR/iso/boot/rootfs*z); do
pascal@458 1346 uncompress $i | cpio -idmu etc/slitaz-release lib/modules rootfs*
pascal@458 1347 [ -s rootfs* ] || continue
pascal@458 1348 unsquashfs -f -d . rootfs* rootfs* etc/slitaz-release lib/modules &&
pascal@458 1349 rm -f rootfs*
pascal@458 1350 done 2>&1 > /dev/null
pascal@172 1351 cd - > /dev/null
pascal@426 1352 cp $TMP_DIR/fs/etc/slitaz-release $TMP_DIR/initfs/etc/
pascal@426 1353 find $TMP_DIR/fs/lib/modules/*/kernel/drivers/net/ethernet \
pascal@426 1354 -type f -name '*.ko*' | while read mod; do
pascal@426 1355 f=$TMP_DIR/initfs/lib/modules/$(basename $mod | sed s/..z$//)
pascal@426 1356 uncompress $mod > $f
pascal@426 1357 grep -q alias=pci: $f || rm -f $f
pascal@426 1358 done
pascal@426 1359 for i in $TMP_DIR/initfs/lib/modules/*.ko ; do
pascal@426 1360 f=$(basename $i)..z
pascal@426 1361 grep -q $f:$ $TMP_DIR/fs/lib/modules/*/modules.dep && continue
pascal@426 1362 deps="$(grep $f: $TMP_DIR/fs/lib/modules/*/modules.dep | sed 's/.*: //')"
pascal@426 1363 echo "$deps" | sed 's|kernel/[^ ]*/||g;s/.ko..z//g' > $TMP_DIR/initfs/lib/modules/$(basename $i .ko).dep
pascal@426 1364 for j in $deps; do
pascal@426 1365 mod=$(ls $TMP_DIR/fs/lib/modules/*/$j)
pascal@426 1366 uncompress $mod > $TMP_DIR/initfs/lib/modules/$(basename $j | sed s/..z$//)
pascal@426 1367 done
pascal@426 1368 done
al@412 1369 longline "Default URLs for /iso/$(cat $TMP_DIR/initfs/etc/slitaz-release)/flavors/slitaz-loram-cdrom.iso /iso/$(cat $TMP_DIR/initfs/etc/slitaz-release)/flavors/slitaz-$(cat $TMP_DIR/initfs/etc/slitaz-release)-loram-cdrom.iso: $urliso"
al@416 1370 _n 'List of URLs to insert: '
pascal@172 1371 read -t 30 urliso2
pascal@172 1372 urliso="$urliso2 $urliso"
pascal@172 1373 fi
pascal@172 1374 if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
pascal@170 1375 cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
pascal@475 1376 sed -i 's/LD_T.*ot/echo/;s/".*ld-.*) /"/' $TMP_DIR/initfs/init
pascal@170 1377 else
pascal@170 1378 cp /bin/busybox $TMP_DIR/initfs/bin
pascal@457 1379 if ! cmp /bin/busybox /sbin/insmod > /dev/null ; then
pascal@457 1380 cp /sbin/insmod $TMP_DIR/initfs/bin
pascal@457 1381 cp -a /lib/libkmod.so.* $TMP_DIR/initfs/lib
pascal@457 1382 cp -a /usr/lib/liblzma.so.* $TMP_DIR/initfs/lib
pascal@457 1383 cp -a /usr/lib/libz.so.* $TMP_DIR/initfs/lib
pascal@457 1384 fi
pascal@170 1385 need_lib=true
pascal@170 1386 fi
pascal@170 1387 for i in $($TMP_DIR/initfs/bin/busybox | awk \
pascal@170 1388 '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
pascal@170 1389 ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
pascal@170 1390 done
pascal@474 1391 # bootfloppybox will need floppy.ko.?z, /dev/fd0, /dev/tty0
pascal@474 1392 cp /lib/modules/$version/kernel/drivers/block/floppy.ko.?z \
pascal@474 1393 $TMP_DIR/initfs/lib/modules 2>/dev/null
pascal@474 1394 for i in /dev/console /dev/null /dev/tty /dev/tty0 /dev/zero \
pascal@170 1395 /dev/kmem /dev/mem /dev/random /dev/urandom; do
pascal@170 1396 cp -a $i $TMP_DIR/initfs/dev
pascal@170 1397 done
pascal@474 1398 grep -q '/sys/block/./dev' $TMP_DIR/initfs/init ||
pascal@474 1399 for i in /dev/fd0 /dev/[hs]d[a-f]* /dev/loop* ; do
pascal@474 1400 cp -a $i $TMP_DIR/initfs/dev
pascal@476 1401 done 2>/dev/null
pascal@474 1402 $need_lib && for i in /lib/ld-* /lib/lib[cm][-\.]* ; do
pascal@170 1403 cp -a $i $TMP_DIR/initfs/lib
pascal@170 1404 done
al@412 1405 [ "$1" == 'http' ] && cat > $TMP_DIR/initfs/init <<EOTEOT
pascal@170 1406 #!/bin/sh
pascal@170 1407
al@412 1408 getarg() {
pascal@170 1409 grep -q " \$1=" /proc/cmdline || return 1
pascal@203 1410 eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
pascal@170 1411 return 0
pascal@170 1412 }
pascal@170 1413
al@412 1414 copy_rootfs() {
pascal@170 1415 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
pascal@170 1416 need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
pascal@170 1417 [ \$(( \$total / \$need )) -gt 1 ] || return 1
pascal@170 1418 if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
pascal@170 1419 path=/mnt/
pascal@170 1420 return 0
pascal@170 1421 else
pascal@170 1422 rm -f /mnt/rootfs*
pascal@170 1423 return 1
pascal@170 1424 fi
pascal@170 1425 }
pascal@170 1426
pascal@170 1427 echo "Switching / to tmpfs..."
pascal@170 1428 mount -t proc proc /proc
pascal@170 1429 size="\$(grep rootfssize= < /proc/cmdline | \\
pascal@170 1430 sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
pascal@170 1431 [ -n "\$size" ] || size="-o size=90%"
pascal@170 1432
pascal@426 1433 mount -t sysfs sysfs /sys
pascal@426 1434 for i in /lib/modules/*.ko ; do
pascal@457 1435 echo -en "Probe \$i \\r"
pascal@426 1436 for j in \$(grep alias=pci: \$i | sed 's/alias//;s/\*/.*/g'); do
pascal@426 1437 grep -q "\$j" /sys/bus/pci/devices/*/uevent || continue
pascal@426 1438 for k in \$(cat \${i/ko/dep} 2> /dev/null); do
pascal@426 1439 insmod /lib/modules/\$k.ko 2> /dev/null
pascal@426 1440 done
pascal@457 1441 echo "Loading \$i"
pascal@426 1442 insmod \$i 2> /dev/null
pascal@426 1443 break
pascal@426 1444 done
pascal@426 1445 done
pascal@426 1446 umount /sys
pascal@172 1447 while read var default; do
pascal@172 1448 eval \$var=\$default
pascal@172 1449 getarg \$var \$var
pascal@172 1450 done <<EOT
pascal@172 1451 eth eth0
pascal@172 1452 dns 208.67.222.222,208.67.220.220
pascal@172 1453 netmask 255.255.255.0
pascal@172 1454 gw
pascal@172 1455 ip
pascal@172 1456 EOT
pascal@458 1457 grep -q \$eth /proc/net/dev || sh
pascal@172 1458 if [ -n "\$ip" ]; then
pascal@172 1459 ifconfig \$eth \$ip netmask \$netmask up
pascal@172 1460 route add default gateway \$gw
pascal@172 1461 for i in \$(echo \$dns | sed 's/,/ /g'); do
pascal@172 1462 echo "nameserver \$i" >> /etc/resolv.conf
pascal@172 1463 done
pascal@172 1464 else
pascal@186 1465 udhcpc -f -q -s /lib/udhcpc -i \$eth
pascal@172 1466 fi
pascal@172 1467 for i in $urliso ; do
pascal@172 1468 [ -n "\$URLISO" ] && URLISO="\$URLISO,"
pascal@182 1469 URLISO="\${URLISO}http://\$i/iso/\$(cat /etc/slitaz-release)/flavors/slitaz-loram-cdrom.iso,http://\$i/iso/\$(cat /etc/slitaz-release)/flavors/slitaz-\$(cat /etc/slitaz-release)-loram-cdrom.iso"
pascal@457 1470 URLISO="\$URLISO,http://\$i/iso/rolling/slitaz-rolling-loram-cdrom.iso,http://\$i/iso/rolling/slitaz-rolling-loram.iso"
pascal@172 1471 done
pascal@172 1472 getarg urliso URLISO
pascal@172 1473 DIR=fs
pascal@172 1474 if getarg loram DIR; then
pascal@172 1475 DEVICE=\${DIR%,*}
pascal@172 1476 DIR=/\${DIR#*,}
pascal@172 1477 fi
pascal@172 1478 mount -t tmpfs \$size tmpfs /mnt
pascal@189 1479 path2=/mnt/.httpfs/
pascal@172 1480 path=/mnt/.cdrom/
pascal@387 1481 mkdir -p /mnt/.rw /mnt/.wd \$path \$path2
pascal@172 1482 while [ ! -d \$path/boot ]; do
pascal@172 1483 for i in \$(echo \$URLISO | sed 's/,/ /g'); do
pascal@457 1484 httpfs \$i \$path2 && echo \$i && break
pascal@172 1485 done
pascal@458 1486 mount -o loop,ro -t iso9660 \$path2/*.iso \$path || sh
pascal@172 1487 done
pascal@170 1488
pascal@170 1489 memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
pascal@170 1490 umount /proc
pascal@387 1491 branch=:/mnt/.cdrom/\$DIR
pascal@206 1492 if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
pascal@387 1493 branch=
pascal@457 1494 lp=1
pascal@457 1495 insmod /lib/modules/squashfs.ko 2> /dev/null
pascal@457 1496 for i in \${path}boot/rootfs?.* ; do
pascal@170 1497 fs=\${i#*root}
pascal@170 1498 branch=\$branch:/mnt/.\$fs
pascal@198 1499 mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
pascal@457 1500 losetup -o 124 /dev/loop\$lp \$i
pascal@457 1501 mount -o loop,ro -t squashfs /dev/loop\$lp /mnt/.\$fs
pascal@457 1502 lp=\$((\$lp+1))
pascal@170 1503 done
pascal@463 1504 fi
pascal@189 1505 mkdir -p /mnt/.rw/mnt/.httpfs
pascal@387 1506 while read type opt; do
pascal@426 1507 insmod /lib/modules/\$type.ko && mount -t \$type -o \$opt none /mnt && break
pascal@387 1508 done <<EOT
pascal@387 1509 aufs br=/mnt/.rw\$branch
pascal@387 1510 overlayfs workdir=/mnt/.wd\${branch/:/,lowerdir=},upperdir=/mnt/.rw
pascal@387 1511 EOT
pascal@426 1512 rm -rf /lib/modules
pascal@186 1513 [ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
pascal@170 1514 [ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
pascal@170 1515 [ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
pascal@170 1516 EOTEOT
pascal@170 1517 chmod +x $TMP_DIR/initfs/init
pascal@312 1518 for i in $TMP_DIR/initfs/lib/modules/*z ; do
pascal@312 1519 unxz $i || gunzip $i || lzma d $i ${i%.gz}
pascal@312 1520 rm -f $i
al@412 1521 done 2>/dev/null
al@412 1522 (cd $TMP_DIR/initfs; find | busybox cpio -o -H newc 2>/dev/null) | \
pascal@170 1523 lzma e $TMP_DIR/initfs.gz -si
pascal@232 1524 lzma_set_size $TMP_DIR/initfs.gz
pascal@170 1525 rm -rf $TMP_DIR/initfs
pascal@289 1526 align_to_32bits $TMP_DIR/initfs.gz
pascal@170 1527 return 0
pascal@170 1528 }
pascal@170 1529
al@412 1530
pascal@289 1531 # Move each initramfs to squashfs
al@412 1532
al@412 1533 build_loram_rootfs() {
pascal@170 1534 rootfs_sizes=""
pascal@426 1535 for i in $TMP_DIR/iso/boot/rootfs*; do
pascal@170 1536 mkdir -p $TMP_DIR/fs
pascal@170 1537 cd $TMP_DIR/fs
pascal@426 1538 uncompress $i | cpio -idm
pascal@434 1539 deduplicate
pascal@170 1540 cd - > /dev/null
pascal@170 1541 rootfs=$TMP_DIR/$(basename $i)
pascal@473 1542 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp ${1:-xz -Xbcj x86}
pascal@170 1543 cd $TMP_DIR
pascal@170 1544 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
al@412 1545 ( cd $(dirname $rootfs); echo $(basename $rootfs) | cpio -o -H newc ) > $rootfs.cpio
pascal@201 1546 rm -f $rootfs
pascal@201 1547 mv $rootfs.cpio $rootfs
pascal@170 1548 cd - > /dev/null
pascal@170 1549 rm -rf $TMP_DIR/fs
pascal@170 1550 done
pascal@170 1551 }
pascal@170 1552
al@412 1553
pascal@170 1554 # Move meta boot configuration files to basic configuration files
al@412 1555 # because meta loram flavor is useless when rootfs is not loaded in RAM
al@412 1556
al@412 1557 unmeta_boot() {
pascal@248 1558 local root=${1:-$TMP_DIR/loramiso}
pascal@248 1559 if [ -f $root/boot/isolinux/noram.cfg ]; then
pascal@170 1560 # We keep enough information to do unloram...
pascal@278 1561 [ -s $root/boot/isolinux/common.cfg ] &&
pascal@170 1562 sed -i 's/label slitaz/label orgslitaz/' \
pascal@248 1563 $root/boot/isolinux/common.cfg
pascal@278 1564 set -- $(grep 'append ifmem [0-9]' $root/boot/isolinux/isolinux.cfg)
pascal@278 1565 shift
pascal@250 1566 sed -i '/ifmem/{NNNNNNNNd};/^LABEL/{N;/LABEL SliTaz [^L]/{NNNd}}' \
pascal@248 1567 $root/boot/isolinux/isolinux.cfg
pascal@278 1568 [ -n "$3" ] || set -- $(grep 'append [0-9]' $root/boot/isolinux/common.cfg)
pascal@472 1569 sed -i "s/label $3\$/label slitaz/;s|=\(.*rootfs\)\(.*\)\.gz |=\1.gz |" \
pascal@248 1570 $root/boot/isolinux/*.cfg
pascal@170 1571 fi
pascal@170 1572 }
pascal@170 1573
al@412 1574
pascal@387 1575 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs/overlayfs.
al@412 1576 # These squashfs may be loaded in RAM at boot time.
al@412 1577 # Rootfs are also copied to CD-ROM for tiny ramsize systems.
pascal@170 1578 # Meta flavors are converted to normal flavors.
al@412 1579
al@412 1580 build_loram_cdrom() {
pascal@170 1581 build_initfs cdrom || return 1
pascal@170 1582 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
pascal@501 1583 cleanup_efi_boot $TMP_DIR/loramiso
pascal@313 1584 mkdir $TMP_DIR/loramiso/fs
pascal@313 1585 cd $TMP_DIR/loramiso/fs
pascal@313 1586 for i in $( ls ../boot/root* | sort -r ) ; do
pascal@426 1587 uncompress $i | cpio -idmu
pascal@313 1588 rm -f $i
pascal@313 1589 done
pascal@313 1590 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
al@412 1591 cd - >/dev/null
pascal@170 1592 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
pascal@170 1593 unmeta_boot
pascal@203 1594 VOLUM_NAME="SliTaz_LoRAM_CDROM"
pascal@313 1595 sed -i "s|root=|isofs= rodev=/dev/cdrom/fs &|;s/.ive/cdrom/" \
pascal@203 1596 $TMP_DIR/loramiso/boot/isolinux/*.cfg
pascal@426 1597 sed -i '/LABEL slitaz/{NNNNp;s|z cdrom|& text|;s|L slitaz|&text|;s|root=|screen=text &|;s|,[^ ]*||}' \
pascal@426 1598 $TMP_DIR/loramiso/boot/isolinux/*.cfg
pascal@170 1599 create_iso $OUTPUT $TMP_DIR/loramiso
pascal@170 1600 }
pascal@170 1601
al@412 1602
paul@173 1603 # Create http bootstrap to load and remove loram_cdrom
pascal@172 1604 # Meta flavors are converted to normal flavors.
al@412 1605
al@412 1606 build_loram_http() {
pascal@172 1607 build_initfs http || return 1
pascal@172 1608 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
pascal@501 1609 cleanup_efi_boot $TMP_DIR/loramiso
pascal@172 1610 rm -f $TMP_DIR/loramiso/boot/rootfs*
pascal@172 1611 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
pascal@172 1612 unmeta_boot
pascal@172 1613 create_iso $OUTPUT $TMP_DIR/loramiso
pascal@172 1614 }
pascal@172 1615
al@412 1616
pascal@170 1617 # Update meta flavor selection sizes.
pascal@170 1618 # Reduce sizes with rootfs gains.
al@412 1619
al@412 1620 update_metaiso_sizes() {
pascal@278 1621 for cfg in $(grep -El '(append|ifmem) [0-9]' $TMP_DIR/loramiso/boot/isolinux/*.cfg)
pascal@241 1622 do
pascal@278 1623 local append="$(grep -E '(append|ifmem) [0-9]' $cfg)"
pascal@241 1624 local sizes="$rootfs_sizes"
pascal@241 1625 local new
pascal@241 1626 set -- $append
pascal@241 1627 shift
pascal@278 1628 [ "$1" == "ifmem" ] && shift
pascal@241 1629 new=""
pascal@241 1630 while [ -n "$2" ]; do
pascal@241 1631 local s
pascal@241 1632 case "$1" in
al@412 1633 *G) s=$(( ${1%G} * 1024 * 1024 ));;
al@412 1634 *M) s=$(( ${1%M} * 1024 ));;
al@412 1635 *) s=${1%K};;
pascal@241 1636 esac
pascal@241 1637 sizes=${sizes#* }
pascal@241 1638 for i in $sizes ; do
pascal@241 1639 s=$(( $s - $i ))
pascal@241 1640 done
pascal@241 1641 new="$new $s $2"
pascal@241 1642 shift 2
pascal@170 1643 done
pascal@278 1644 sed -i -e "/append [0-9]/s/append .*/append$new $1/" -e \
pascal@278 1645 "/append ifmem [0-9]/s/append .*/append ifmem$new $1/" $cfg
pascal@472 1646 sed -i 's|\(initrd=\)\([^r]*\)\(rootfs\)|\1\2rootfs.gz,\2\3|' $cfg
pascal@312 1647 sed -i '/LABEL base/{NNNNp;s|base .ive|cdrom|;s|base|cdrom|;s|,[^ ]*||}' $cfg
pascal@425 1648 sed -i '/LABEL cdrom/{NNNNp;s|z cdrom|& text|;s|L cdrom|&text|;s|root=|screen=text &|;s|,[^ ]*||}' $cfg
pascal@170 1649 done
pascal@170 1650 }
pascal@170 1651
al@412 1652
pascal@387 1653 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs/overlayfs.
pascal@170 1654 # Meta flavor selection sizes are updated.
al@412 1655
al@412 1656 build_loram_ram() {
pascal@170 1657 build_initfs ram || return 1
pascal@473 1658 build_loram_rootfs "$1"
al@412 1659 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
pascal@501 1660 cleanup_efi_boot $TMP_DIR/loramiso
pascal@289 1661 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz
al@412 1662 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
pascal@170 1663 update_metaiso_sizes
al@412 1664 create_iso $OUTPUT $TMP_DIR/loramiso
pascal@170 1665 }
pascal@170 1666
al@412 1667
pankso@279 1668 # Remove files installed by packages
al@412 1669
al@412 1670 find_flavor_rootfs() {
pascal@191 1671 for i in $1/etc/tazlito/*.extract; do
pascal@191 1672 [ -e $i ] || continue
pascal@191 1673 chroot $1 /bin/sh ${i#$1}
pascal@191 1674 done
pankso@279 1675
pankso@279 1676 # Clean hardlinks and files patched by genisofs in /boot
pascal@191 1677 for i in isolinux/isolinux.bin isolinux/boot.cat bzImage ; do
pascal@362 1678 rm -f $1/boot/$i*
pascal@191 1679 done
pankso@279 1680
pascal@191 1681 # Clean files generated in post_install
pascal@191 1682 rm -f $1/lib/modules/*/modules.* $1/etc/mtab \
pascal@191 1683 $1/dev/core $1/dev/fd $1/dev/std*
pankso@279 1684
pascal@191 1685 # Verify md5
pascal@217 1686 cat $1$INSTALLED/*/md5sum | \
pascal@191 1687 while read md5 file; do
pascal@405 1688 [ -e "$1$file" ] || continue
pascal@405 1689 [ "$(md5sum < "$1$file")" == "$md5 -" ] &&
pascal@405 1690 rm -f "$1$file"
pascal@191 1691 done
pankso@279 1692
pascal@191 1693 # Check configuration files
pascal@217 1694 for i in $1$INSTALLED/*/volatile.cpio.gz; do
pascal@191 1695 [ -e $i ] || continue
pascal@191 1696 mkdir /tmp/volatile$$
pascal@227 1697 zcat $i | ( cd /tmp/volatile$$ ; cpio -idmu > /dev/null 2>&1 )
pascal@227 1698 ( cd /tmp/volatile$$ ; find * -type f 2> /dev/null) | \
pascal@227 1699 while read file ; do
pascal@405 1700 [ -e "$1/$file" ] || continue
pascal@405 1701 cmp -s "/tmp/volatile$$/$file" "$1/$file" && rm -f "$1/$file"
pascal@191 1702 done
pascal@191 1703 rm -rf /tmp/volatile$$
pascal@191 1704 done
pankso@279 1705
pascal@191 1706 # Remove other files blindly
pascal@217 1707 for i in $1$INSTALLED/*/files.list; do
pascal@405 1708 for file in $(cat "$i"); do
pascal@405 1709 [ "$1$file" -nt "$i" ] && continue
pascal@405 1710 [ -f "$1$file" -a ! -L "$1$file" ] && continue
pascal@405 1711 [ -d "$1$file" ] || rm -f "$1$file"
pascal@191 1712 done
pascal@191 1713 done
pankso@279 1714
pascal@193 1715 # Remove tazpkg files and tmp files
pascal@217 1716 rm -rf $1$INSTALLED* $1/tmp $1/var/tmp
pascal@217 1717 rm -f $1$LOCALSTATE/*packages* $1$LOCALSTATE/files.list.lzma \
pascal@217 1718 $1$LOCALSTATE/mirror* $1/var/cache/*/* \
pascal@193 1719 $1/var/lock/* $1/var/log/* $1/var/run/* $1/var/run/*/* \
al@412 1720 $1/var/lib/* $1/var/lib/dbus/* 2>/dev/null
pankso@279 1721
pascal@191 1722 # Cleanup directory tree
pascal@191 1723 cd $1
pascal@191 1724 find * -type d | sort -r | while read dir; do
al@412 1725 rmdir "$dir" 2>/dev/null
pascal@191 1726 done
pascal@191 1727 cd - > /dev/null
pascal@191 1728 }
pascal@191 1729
al@412 1730
al@412 1731 # Get byte(s) from a binary file
al@412 1732
al@412 1733 get() {
pascal@497 1734 od -v -j $1 -N ${3:-2} -t u${3:-2} -w${3:-2} -An $2 2>/dev/null | sed 's/ *//'
pascal@404 1735 }
pascal@404 1736
al@412 1737
al@412 1738 # Get cpio flavor info from the ISO image
al@412 1739
al@412 1740 flavordata() {
pascal@404 1741 [ $(get 1024 $1) -eq 35615 ] && n=2 || n=$((1+$(get 417 $1 1)))
pascal@404 1742 dd if=$1 bs=512 skip=$n count=20 2>/dev/null | zcat 2>/dev/null
pascal@404 1743 }
pascal@404 1744
pascal@404 1745
al@412 1746 # Restore undigest mirrors
al@412 1747
al@412 1748 restore_mirrors() {
al@412 1749 local undigest="$root$LOCALSTATE/undigest" priority="$root$LOCALSTATE/priority"
al@412 1750 [ -d "$undigest.bak" ] || [ -e "$priority.bak" ] || return
al@412 1751
al@412 1752 action 'Restoring mirrors...'
al@412 1753 if [ -d "$undigest.bak" ]; then
al@412 1754 [ -d "$undigest" ] && rm -r "$undigest"
al@412 1755 mv "$undigest.bak" "$undigest"
al@412 1756 fi
al@412 1757 [ -e "$priority.bak" ] && mv -f "$priority.bak" "$priority"
al@412 1758 :; status
al@412 1759 }
al@412 1760
al@412 1761
al@412 1762 # Setup undigest mirrors
al@412 1763
al@412 1764 setup_mirrors() {
al@412 1765 # Setup mirrors in plain system or in chroot (with variable root=)
al@412 1766 local mirrorlist="$1" fresh repacked
al@412 1767 local undigest="$root$LOCALSTATE/undigest" priority="$root$LOCALSTATE/priority"
al@412 1768
al@412 1769 # Restore mirrors first: in case of non-clear exits, hangs, etc.
al@412 1770 restore_mirrors
al@412 1771
al@412 1772 _ 'Setting up mirrors for %s...' "$root/"
al@412 1773 # Backing up current undigest mirrors and priority
al@412 1774 [ -d "$undigest" ] && mv "$undigest" "$undigest.bak"
al@412 1775 [ -e "$priority" ] && mv "$priority" "$priority.bak"
al@412 1776 rm -rf '/var/www/tazlito/'
al@412 1777 mkdir -p '/var/www/tazlito/'
al@412 1778
al@412 1779 # Packages produced by CookUtils: on Tank or local, or repacked packages: highest priority
al@412 1780 fresh='/home/slitaz/packages'
al@412 1781 if [ -d "$fresh" ]; then
al@412 1782 # Setup first undigest mirror
al@412 1783 mkdir -p "$undigest/fresh"
al@418 1784 echo "$fresh" > "$undigest/fresh/mirror"
al@412 1785 echo 'fresh' >> "$priority"
al@412 1786 # Rebuild mirror DB if needed
al@412 1787 [ ! -e "$fresh/IDs" ] && tazpkg mkdb "$fresh" --forced --root=''
al@412 1788 [ -n "$(find -L "$fresh" -name '*.tazpkg' -newer "$fresh/IDs")" ] && \
al@412 1789 tazpkg mkdb "$fresh" --forced --root=''
al@412 1790 cp -a "$fresh/files.list.lzma" "$fresh/files-list.lzma"
al@412 1791 fi
al@412 1792
al@412 1793 # Repacked packages: high priority
al@412 1794 repacked="$PACKAGES_REPOSITORY"
al@412 1795 if [ -d "$repacked" -a "$repacked" != "$fresh" ] && ls "$repacked" | grep -q ".tazpkg"; then
al@412 1796 # According to Tazlito setup file (tazlito.conf):
al@412 1797 # WORK_DIR="/home/slitaz/$SLITAZ_VERSION"
al@412 1798 # or
al@412 1799 # WORK_DIR="/home/slitaz"
al@412 1800 # and
al@412 1801 # PACKAGES_REPOSITORY="$WORK_DIR/packages"
al@412 1802 # It MAY or MAY NOT match /home/slitaz/packages, so here we setup second repository
al@412 1803
al@412 1804 # Setup second undigest mirror
al@412 1805 mkdir -p "$undigest/repacked"
al@418 1806 echo "$repacked" > "$undigest/repacked/mirror"
al@412 1807 echo 'repacked' >> "$priority"
al@412 1808 # Rebuild mirror DB if needed
al@412 1809 [ ! -e "$repacked/IDs" ] && tazpkg mkdb "$repacked" --forced --root=''
al@412 1810 [ -n "$(find -L "$repacked" -name '*.tazpkg' -newer "$repacked/IDs")" ] && \
al@412 1811 tazpkg mkdb "$repacked" --forced --root=''
al@412 1812 cp -a "$repacked/files.list.lzma" "$repacked/files-list.lzma"
al@412 1813 fi
al@412 1814
al@412 1815 # All repositories listed in mirrors list: normal priority
al@412 1816 [ -e "$mirrorlist" ] && \
al@412 1817 while read mirror; do
al@412 1818 # Provide consistent mirror ID for caching purpose: /var/cache/tazpkg/<mirror ID>/packages
al@412 1819 mirrorid=$(echo "$mirror" | md5sum | cut -d' ' -f1)
al@412 1820 mkdir -p "$undigest/$mirrorid"
al@412 1821 echo "$mirror" > "$undigest/$mirrorid/mirror"
al@412 1822 echo "$mirrorid" >> "$priority"
al@412 1823 done < "$mirrorlist"
al@412 1824
al@412 1825 # And, finally, main mirror with the lowest (failsafe) priority (nothing to do)
al@412 1826
al@412 1827 # Show list of mirrors
al@414 1828 [ -f "$priority" ] && awk -vdb="$root$LOCALSTATE" '
al@418 1829 function show(num, name, url) {
al@418 1830 printf " %-1.1d. %32.32s %-44.44s\n", num, name " ...............................", url;
al@412 1831 }
al@412 1832 {
al@412 1833 num++;
al@412 1834 "cat " db "/undigest/" $0 "/mirror" | getline url;
al@412 1835 show(num, $0, url);
al@412 1836 }
al@412 1837 END {
al@412 1838 num++;
al@412 1839 "cat " db "/mirror" | getline url;
al@412 1840 show(num, "main", url);
al@412 1841 }' "$priority"
al@412 1842
al@417 1843 tazpkg recharge --quiet >/dev/null
al@412 1844 }
al@412 1845
al@412 1846
al@412 1847 # Get list of 'packages.info' lists using priority
al@412 1848
al@412 1849 pi_lists() {
al@412 1850 local pi
al@415 1851 [ -s "$root$LOCALSTATE/packages.info" ] || tazpkg recharge --root="$root" >/dev/null 2>&1
al@412 1852 local priority="$root$LOCALSTATE/priority"
al@412 1853 local undigest="$root$LOCALSTATE/undigest"
al@412 1854
al@412 1855 {
al@412 1856 [ -s "$priority" ] && cat "$priority"
al@412 1857 echo 'main'
al@412 1858 [ -d "$undigest" ] && ls "$undigest"
al@412 1859 } | awk -vun="$undigest/" '
al@412 1860 {
al@412 1861 if (arr[$0] != 1) {
al@412 1862 arr[$0] = 1;
al@412 1863 print un $0 "/packages.info";
al@412 1864 }
al@412 1865 }' | sed 's|/undigest/main||' | \
al@412 1866 while read pi; do
al@412 1867 [ -e "$pi" ] && echo "$pi"
al@412 1868 done
al@412 1869 }
al@412 1870
al@412 1871
al@412 1872 # Strip versions from packages list
al@412 1873
al@412 1874 strip_versions() {
al@460 1875 if [ -n "$stripped" ]; then
al@460 1876 action 'Consider list %s already stripped' "$(basename "$1")"
al@460 1877 status
al@460 1878 return 0
al@460 1879 fi
al@412 1880 action 'Strip versions from list %s...' "$(basename "$1")"
al@412 1881 local in_list="$1" tmp_list="$(mktemp)" namever pkg
al@412 1882 [ -f "$in_list" ] || die "List '$in_list' not found."
al@412 1883
al@412 1884 # $pkg=<name>-<version> or $pkg=<name>; both <name> and <version> may contain dashes
al@412 1885 awk '
al@412 1886 {
al@412 1887 if (FILENAME ~ "packages.info") {
al@412 1888 # Collect package names
al@412 1889 FS = "\t"; pkg[$1] = 1;
al@412 1890 } else {
al@416 1891 FS = OFS = "-"; $0 = $0; # Fix bug with FS for first record
al@412 1892 while (NF > 1 && ! pkg[$0])
al@412 1893 NF --;
al@412 1894 printf "%s\n", $0;
al@412 1895 }
al@412 1896 }' $(pi_lists) "$in_list" > "$tmp_list"
al@412 1897
al@412 1898 cat "$tmp_list" > "$in_list"
al@412 1899 rm "$tmp_list"
al@412 1900 status
al@412 1901 }
al@412 1902
al@412 1903
al@412 1904 # Display list of unknown packages (informative)
al@414 1905
al@412 1906 display_unknown() {
al@412 1907 [ -s "$1" ] || return
al@412 1908 echo "Unknown packages:" >&2
al@412 1909 cat "$1" >&2
al@412 1910 rm "$1"
al@412 1911 }
al@412 1912
al@412 1913
al@412 1914 # Display warnings about critical packages absent (informative)
al@414 1915
al@412 1916 display_warn() {
al@412 1917 [ -s "$1" ] || return
al@412 1918 echo "Absent critical packages:" >&2
al@412 1919 cat "$1" >&2
al@412 1920 rm "$1"
al@412 1921 echo "Probably ISO image will be unusable."
al@412 1922 }
al@412 1923
al@412 1924
al@414 1925 # Install packages to rootfs
al@414 1926
al@414 1927 install_list_to_rootfs() {
al@414 1928 local list="$1" rootfs="$2" pkg i ii
al@415 1929 local undigest="$rootfs/var/lib/tazpkg/undigest"
al@414 1930
al@414 1931 # initial tazpkg setup in empty rootfs
al@414 1932 tazpkg --root=$rootfs >/dev/null 2>&1
al@459 1933 # pass current 'mirror' to the rootfs
al@461 1934 mkdir -p $rootfs/var/lib/tazpkg $rootfs/etc
al@459 1935 cp -f /var/lib/tazpkg/mirror $rootfs/var/lib/tazpkg/mirror
al@460 1936 cp -f /etc/slitaz-release $rootfs/etc/slitaz-release
al@414 1937 # link rootfs packages cache to the regular packages cache
al@414 1938 rm -r "$rootfs/var/cache/tazpkg"
al@414 1939 ln -s /var/cache/tazpkg "$rootfs/var/cache/tazpkg"
al@414 1940
al@414 1941 setup_mirrors mirrors
al@414 1942
paul@479 1943 # Just in case if flavor doesn't contain "tazlito" package
al@414 1944 mkdir -p "$rootfs/etc/tazlito"
al@414 1945
al@415 1946 newline
al@462 1947
al@462 1948 # Choose detailed log with --detailed
al@462 1949 if [ -n "$detailed" ]; then
al@462 1950 while read pkg; do
al@462 1951 separator '-'
al@462 1952 echo $pkg
al@462 1953 tazpkg -gi $pkg --root=$rootfs --local --quiet --cookmode | tee -a $log
al@462 1954 done < $list
al@462 1955 separator '='
al@462 1956 else
al@462 1957 while read pkg; do
al@462 1958 action 'Installing package: %s' "$pkg"
al@462 1959 yes y | tazpkg -gi $pkg --root=$rootfs --quiet >> $log || exit 1
al@462 1960 status
al@462 1961 done < $list
al@462 1962 fi
al@414 1963 newline
al@414 1964
al@414 1965 restore_mirrors
al@414 1966 # Remove 'fresh' and 'repacked' undigest repos leaving all other
al@414 1967 for i in fresh repacked; do
al@415 1968 ii="$undigest/$i"
al@414 1969 [ -d "$ii" ] && rm -rf "$ii"
al@414 1970 ii="$rootfs/var/lib/tazpkg/priority"
al@414 1971 if [ -f "$ii" ]; then
al@414 1972 sed -i "/$i/d" "$ii"
al@414 1973 [ -s "$ii" ] || rm "$ii"
al@414 1974 fi
al@414 1975 done
al@415 1976 [ -d "$undigest" ] && \
al@415 1977 for i in $(find "$undigest" -type f); do
al@414 1978 # Remove all undigest PKGDB files but 'mirror'
al@414 1979 [ "$(basename "$i")" != 'mirror' ] && rm "$i"
al@414 1980 done
al@415 1981 [ -d "$undigest" ] && \
al@415 1982 rmdir --ignore-fail-on-non-empty "$undigest"
al@414 1983
al@414 1984 # Un-link packages cache
al@414 1985 rm "$rootfs/var/cache/tazpkg"
al@414 1986
al@414 1987 # Clean /var/lib/tazpkg
al@415 1988 (cd $rootfs/var/lib/tazpkg; rm ID* descriptions.txt extra.list files* packages.* 2>/dev/null)
al@414 1989 }
al@414 1990
al@414 1991
al@412 1992
al@412 1993
pankso@1 1994 ####################
pankso@1 1995 # Tazlito commands #
pankso@1 1996 ####################
pankso@1 1997
al@412 1998 # /usr/bin/tazlito is linked with /usr/bin/reduplicate and /usr/bin/deduplicate
pascal@361 1999 case "$0" in
pascal@365 2000 *reduplicate)
pascal@365 2001 find ${@:-.} ! -type d -links +1 \
pascal@365 2002 -exec cp -a {} {}$$ \; -exec mv {}$$ {} \;
pascal@365 2003 exit 0 ;;
pascal@361 2004 *deduplicate)
pascal@361 2005 deduplicate "$@"
pascal@361 2006 exit 0 ;;
pascal@361 2007 esac
pascal@361 2008
al@412 2009
pankso@1 2010 case "$COMMAND" in
pankso@1 2011 stats)
pankso@1 2012 # Tazlito general statistics from the config file.
pankso@1 2013 #
al@412 2014 title 'Tazlito statistics'
al@412 2015 optlist "\
al@412 2016 Config file : $CONFIG_FILE
al@412 2017 ISO name : $ISO_NAME.iso
al@412 2018 Volume name : $VOLUM_NAME
al@412 2019 Prepared : $PREPARED
al@412 2020 Packages repository : $PACKAGES_REPOSITORY
al@412 2021 Distro directory : $DISTRO
al@412 2022 Additional files : $ADDFILES
al@412 2023 " | sed '/: $/d'
al@412 2024 footer
al@412 2025 ;;
al@412 2026
al@412 2027
pankso@122 2028 list-addfiles)
paul@154 2029 # Simple list of additional files in the rootfs
pankso@333 2030 newline
al@412 2031 if [ -d "$ADDFILES/rootfs" ]; then
al@412 2032 cd $ADDFILES
al@412 2033 find rootfs -type f
al@412 2034 else
al@412 2035 _ 'Additional files not found: %s' "$ADDFILES/rootfs/"
al@412 2036 fi
al@412 2037 newline
al@412 2038 ;;
al@412 2039
al@412 2040
pankso@1 2041 gen-config)
MikeDSmith25@83 2042 # Generate a new config file in the current dir or the specified
pankso@1 2043 # directory by $2.
pankso@1 2044 #
al@412 2045 if [ -n "$2" ]; then
al@412 2046 mkdir -p "$2" && cd "$2"
pankso@1 2047 fi
al@412 2048
al@412 2049 newline
al@412 2050 action 'Generating empty tazlito.conf...'
pankso@1 2051 empty_config_file
pankso@1 2052 status
al@412 2053
al@412 2054 separator
al@412 2055 if [ -f 'tazlito.conf' ] ; then
al@412 2056 _ 'Configuration file is ready to edit.'
al@412 2057 _ 'File location: %s' "$(pwd)/tazlito.conf"
pankso@333 2058 newline
al@412 2059 fi
al@412 2060 ;;
al@412 2061
al@412 2062
pankso@1 2063 configure)
pankso@1 2064 # Configure a tazlito.conf config file. Start by getting
pankso@1 2065 # a empty config file and sed it.
pankso@1 2066 #
al@412 2067 if [ -f 'tazlito.conf' ]; then
pankso@1 2068 rm tazlito.conf
pankso@1 2069 else
al@412 2070 [ $(id -u) -ne 0 ] && die 'You must be root to configure the main config file' \
al@412 2071 'or in the same directory of the file you want to configure.'
al@412 2072 cd /etc
pankso@1 2073 fi
al@412 2074
pankso@1 2075 empty_config_file
al@412 2076
al@412 2077 title 'Configuring: %s' "$(pwd)/tazlito.conf"
al@412 2078
pankso@1 2079 # ISO name.
pascal@11 2080 echo -n "ISO name : " ; read answer
pascal@11 2081 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
pascal@14 2082 # Volume name.
pascal@14 2083 echo -n "Volume name : " ; read answer
pascal@11 2084 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
pankso@1 2085 # Packages repository.
pascal@11 2086 echo -n "Packages repository : " ; read answer
pascal@11 2087 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
pankso@1 2088 # Distro path.
pascal@11 2089 echo -n "Distro path : " ; read answer
pascal@11 2090 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
al@412 2091 footer "Config file is ready to use."
al@412 2092 echo 'You can now extract an ISO or generate a distro.'
al@412 2093 newline
al@412 2094 ;;
al@412 2095
al@412 2096
pankso@1 2097 gen-iso)
paul@94 2098 # Simply generate a new iso.
pankso@1 2099 #
pankso@1 2100 check_root
pankso@1 2101 verify_rootcd
pankso@1 2102 gen_livecd_isolinux
al@412 2103 distro_stats
al@412 2104 ;;
al@412 2105
al@412 2106
pankso@1 2107 gen-initiso)
paul@94 2108 # Simply generate a new initramfs with a new iso.
pankso@1 2109 #
pankso@1 2110 check_root
pankso@1 2111 verify_rootcd
al@412 2112 gen_initramfs "$ROOTFS"
pankso@1 2113 gen_livecd_isolinux
al@412 2114 distro_stats
al@412 2115 ;;
al@412 2116
al@412 2117
pascal@498 2118 extract-distro|extract-iso)
MikeDSmith25@83 2119 # Extract an ISO image to a directory and rebuild the LiveCD tree.
pankso@1 2120 #
pankso@1 2121 check_root
al@412 2122 ISO_IMAGE="$2"
al@412 2123 [ -z "$ISO_IMAGE" ] && die 'Please specify the path to the ISO image.' \
al@412 2124 'Example:\n tazlito image.iso /path/target'
al@412 2125
pankso@1 2126 # Set the distro path by checking for $3 on cmdline.
al@412 2127 TARGET="${3:-$DISTRO}"
al@412 2128
pankso@1 2129 # Exit if existing distro is found.
al@412 2130 [ -d "$TARGET/rootfs" ] && die "A rootfs exists in '$TARGET'." \
al@412 2131 'Please clean the distro tree or change directory path.'
al@412 2132
al@412 2133 title 'Tazlito extracting: %s' "$(basename $ISO_IMAGE)"
al@412 2134
pankso@1 2135 # Start to mount the ISO.
al@412 2136 action 'Mounting ISO image...'
al@412 2137 mkdir -p "$TMP_DIR"
pankso@1 2138 # Get ISO file size.
al@412 2139 isosize=$(du -sh "$ISO_IMAGE" | cut -f1)
al@412 2140 mount -o loop -r "$ISO_IMAGE" "$TMP_DIR"
pankso@1 2141 sleep 2
pankso@1 2142 # Prepare target dir, copy the kernel and the rootfs.
al@412 2143 mkdir -p "$TARGET/rootfs" "$TARGET/rootcd/boot"
al@412 2144 status
al@412 2145
al@412 2146 action 'Copying the Linux kernel...'
al@412 2147 if cp $TMP_DIR/boot/vmlinuz* "$TARGET/rootcd/boot" 2>/dev/null; then
al@412 2148 make_bzImage_hardlink "$TARGET/rootcd/boot"
pascal@16 2149 else
al@412 2150 cp "$TMP_DIR/boot/bzImage" "$TARGET/rootcd/boot"
pascal@16 2151 fi
pankso@1 2152 status
al@412 2153
pascal@41 2154 for i in $(ls $TMP_DIR); do
al@412 2155 [ "$i" == 'boot' ] && continue
al@412 2156 cp -a "$TMP_DIR/$i" "$TARGET/rootcd"
pascal@41 2157 done
al@412 2158
al@412 2159 for loader in isolinux syslinux extlinux grub; do
al@412 2160 [ -d "$TMP_DIR/boot/$loader" ] || continue
al@412 2161 action 'Copying %s files...' "$loader"
al@412 2162 cp -a "$TMP_DIR/boot/$loader" "$TARGET/rootcd/boot"
al@412 2163 status
al@412 2164 done
al@412 2165
al@412 2166 action 'Copying the rootfs...'
pascal@498 2167 cp $TMP_DIR/boot/rootfs*.?z* "$TARGET/rootcd/boot"
pankso@1 2168 status
al@412 2169
pascal@503 2170 cleanup_efi_boot "$TARGET/rootcd"
pascal@503 2171
paul@94 2172 # Extract initramfs.
al@412 2173 cd "$TARGET/rootfs"
al@412 2174 action 'Extracting the rootfs...'
pascal@498 2175 for i in $(ls -r $TARGET/rootcd/boot/rootfs*z); do
pascal@495 2176 extract_rootfs "$i" "$TARGET/rootfs"
pascal@494 2177 done
pascal@38 2178 # unpack /usr
pascal@48 2179 for i in etc/tazlito/*.extract; do
pascal@50 2180 [ -f "$i" ] && . $i ../rootcd
pascal@48 2181 done
pankso@1 2182 # Umount and remove temp directory and cd to $TARGET to get stats.
al@412 2183 umount "$TMP_DIR" && rm -rf "$TMP_DIR"
pankso@1 2184 cd ..
al@412 2185 status
al@412 2186
pankso@333 2187 newline
pankso@279 2188 separator
al@412 2189 echo "Extracted : $(basename $ISO_IMAGE) ($isosize)"
al@412 2190 echo "Distro tree : $(pwd)"
al@412 2191 echo "Rootfs size : $(du -sh rootfs)"
al@412 2192 echo "Rootcd size : $(du -sh rootcd)"
al@412 2193 footer
al@412 2194 ;;
al@412 2195
al@412 2196
pascal@22 2197 list-flavors)
pascal@22 2198 # Show available flavors.
al@455 2199 list='/etc/tazlito/flavors.list'
al@412 2200 [ ! -s $list -o -n "$recharge" ] && download flavors.list -O - > $list
al@412 2201 title 'List of flavors'
al@412 2202 cat $list
al@412 2203 footer
al@412 2204 ;;
al@412 2205
al@412 2206
pascal@22 2207 show-flavor)
paul@479 2208 # Show flavor descriptions.
al@412 2209 set -e
al@412 2210 flavor=${2%.flavor}
al@412 2211 flv_dir="$(extract_flavor "$flavor")"
al@412 2212 desc="$flv_dir/$flavor.desc"
al@412 2213 if [ -n "$brief" ]; then
al@412 2214 if [ -z "$noheader" ]; then
al@412 2215 printf "%-16.16s %6.6s %6.6s %s\n" 'Name' 'ISO' 'Rootfs' 'Description'
pankso@279 2216 separator
pascal@22 2217 fi
al@412 2218 printf "%-16.16s %6.6s %6.6s %s\n" "$flavor" \
al@412 2219 "$(field ISO "$desc")" \
al@412 2220 "$(field Rootfs "$desc")" \
al@412 2221 "$(field Description "$desc")"
pascal@22 2222 else
pankso@279 2223 separator
al@412 2224 cat "$desc"
pascal@22 2225 fi
al@412 2226 cleanup
al@412 2227 ;;
al@412 2228
al@412 2229
pascal@60 2230 gen-liveflavor)
paul@154 2231 # Generate a new flavor from the live system.
pascal@106 2232 FLAVOR=${2%.flavor}
al@412 2233 [ -z "$FLAVOR" ] && die 'Please specify flavor name on the commandline.'
al@412 2234
pascal@60 2235 case "$FLAVOR" in
al@412 2236 -?|-h*|--help)
al@412 2237 cat <<EOT
pascal@60 2238 SliTaz Live Tool - Version: $VERSION
al@412 2239
al@412 2240 $(boldify 'Usage:') tazlito gen-liveflavor <flavor-name> [<flavor-patch-file>]
al@412 2241
al@412 2242 $(boldify '<flavor-patch-file> format:')
al@412 2243 $(optlist "\
pascal@60 2244 code data
pascal@60 2245 + package to add
pascal@60 2246 - package to remove
pascal@65 2247 ! non-free package to add
pascal@60 2248 ? display message
pascal@60 2249 @ flavor description
al@412 2250 ")
al@412 2251
al@412 2252 $(boldify 'Example:')
al@412 2253 $(optlist "\
al@412 2254 @ Developer tools for SliTaz maintainers
pascal@60 2255 + slitaz-toolchain
pascal@60 2256 + mercurial
al@412 2257 ")
al@412 2258 EOT
al@412 2259 exit 1
al@412 2260 ;;
pascal@60 2261 esac
pascal@60 2262 mv /etc/tazlito/distro-packages.list \
al@412 2263 /etc/tazlito/distro-packages.list.$$ 2>/dev/null
al@412 2264 rm -f distro-packages.list non-free.list 2>/dev/null
pascal@60 2265 tazpkg recharge
al@412 2266
al@412 2267 DESC=""
al@412 2268 [ -n "$3" ] && \
al@412 2269 while read action pkg; do
pascal@60 2270 case "$action" in
al@412 2271 +) yes | tazpkg get-install $pkg 2>&1 >> $log || exit 1 ;;
al@412 2272 -) yes | tazpkg remove $pkg ;;
al@412 2273 !) echo $pkg >> non-free.list ;;
al@412 2274 @) DESC="$pkg" ;;
al@412 2275 \?) echo -en "$pkg"; read action ;;
pascal@60 2276 esac
pascal@60 2277 done < $3
al@412 2278
pascal@60 2279 yes '' | tazlito gen-distro
pascal@60 2280 echo "$DESC" | tazlito gen-flavor "$FLAVOR"
pascal@60 2281 mv /etc/tazlito/distro-packages.list.$$ \
al@412 2282 /etc/tazlito/distro-packages.list 2>/dev/null
al@412 2283 ;;
al@412 2284
al@412 2285
pascal@22 2286 gen-flavor)
al@412 2287 # Generate a new flavor from the last ISO image generated
pascal@106 2288 FLAVOR=${2%.flavor}
al@412 2289 [ -z "$FLAVOR" ] && die 'Please specify flavor name on the commandline.'
al@412 2290
al@412 2291 title 'Flavor generation'
pascal@22 2292 check_rootfs
pascal@68 2293 FILES="$FLAVOR.pkglist"
al@412 2294
al@412 2295 action 'Creating file %s...' "$FLAVOR.flavor"
pascal@22 2296 for i in rootcd rootfs; do
pascal@22 2297 if [ -d "$ADDFILES/$i" ] ; then
pascal@22 2298 FILES="$FILES\n$FLAVOR.$i"
pascal@450 2299 ( cd "$ADDFILES/$i"; find . ) | cpio -o -H newc 2>/dev/null | dogzip $FLAVOR.$i
pascal@22 2300 fi
pascal@22 2301 done
pankso@35 2302 status
al@412 2303
al@412 2304 answer=$(grep -s ^Description $FLAVOR.desc)
pascal@22 2305 answer=${answer#Description : }
pascal@22 2306 if [ -z "$answer" ]; then
al@412 2307 echo -n "Description: "
pascal@22 2308 read answer
pascal@22 2309 fi
al@412 2310
al@412 2311 action 'Compressing flavor %s...' "$FLAVOR"
al@412 2312 echo "Flavor : $FLAVOR" > $FLAVOR.desc
pascal@22 2313 echo "Description : $answer" >> $FLAVOR.desc
al@412 2314 (cd $DISTRO; distro_sizes) >> $FLAVOR.desc
al@412 2315 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2>/dev/null
pascal@22 2316 for i in $(ls $ROOTFS$INSTALLED); do
pascal@22 2317 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
pascal@78 2318 EXTRAVERSION=""
pascal@78 2319 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
pascal@61 2320 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
al@412 2321 if [ "$CATEGORY" == 'non-free' -a "${i%%-*}" != 'get' ]; then
pascal@61 2322 echo "$i" >> $FLAVOR.nonfree
pascal@61 2323 else
pascal@78 2324 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
pascal@61 2325 fi
pascal@22 2326 done
pascal@68 2327 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
pascal@109 2328 for i in $LOCALSTATE/undigest/*/mirror ; do
pascal@109 2329 [ -s $i ] && cat $i >> $FLAVOR.mirrors
pascal@109 2330 done
pascal@109 2331 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
pascal@452 2332 touch -t 197001010100.00 $FLAVOR.*
pascal@439 2333 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | dogzip $FLAVOR.flavor
al@412 2334 rm $(echo -e $FILES)
pascal@22 2335 status
al@412 2336
al@412 2337 footer "Flavor size: $(du -sh $FLAVOR.flavor)"
al@412 2338 ;;
al@412 2339
al@412 2340
pascal@105 2341 upgrade-flavor)
al@412 2342 # Strip versions from pkglist and update estimated numbers in flavor.desc
al@412 2343 flavor="${2%.flavor}"
al@412 2344 set -e
al@412 2345 [ -f "$flavor.flavor" ] || download "$flavor.flavor"
al@412 2346 set +e
al@412 2347
al@412 2348 flv_dir="$(extract_flavor "$flavor")"
al@412 2349
al@412 2350 strip_versions "$flv_dir/$flavor.pkglist"
al@412 2351
al@412 2352 action 'Updating %s...' "$flavor.desc"
al@412 2353
al@412 2354 [ -f "$flv_dir/$flavor.mirrors" ] && setup_mirrors "$flv_dir/$flavor.mirrors" >/dev/null
al@416 2355 set -- $(module calc_sizes "$flv_dir" "$flavor")
al@412 2356 restore_mirrors >/dev/null
al@412 2357
al@412 2358 sed -i -e '/Image is ready/d' \
al@412 2359 -e "s|\(Rootfs size *:\).*$|\1 $1 (estimated)|" \
al@412 2360 -e "s|\(Initramfs size *:\).*$|\1 $2 (estimated)|" \
al@412 2361 -e "s|\(ISO image size *:\).*$|\1 $3 (estimated)|" \
al@412 2362 -e "s|\(Packages *:\).*$|\1 $4|" \
al@412 2363 -e "s|\(Build date *:\).*$|\1 $(date '+%Y%m%d at %T')|" \
al@412 2364 "$flv_dir/$flavor.desc"
al@412 2365
al@412 2366 pack_flavor "$flv_dir" "$flavor"
al@412 2367 status
al@412 2368 display_unknown "$flv_dir/err"
al@412 2369 display_warn "$flv_dir/warn"
al@412 2370 cleanup
al@412 2371 ;;
al@412 2372
al@412 2373
pascal@106 2374 extract-flavor)
al@412 2375 # Extract a flavor into $FLAVORS_REPOSITORY
al@412 2376 flavor="${2%.flavor}"
al@412 2377 set -e
al@412 2378 [ -f "$flavor.flavor" ] || download "$flavor.flavor"
al@412 2379 set +e
al@412 2380
al@412 2381 action 'Extracting %s...' "$flavor.flavor"
al@412 2382 flv_dir="$(extract_flavor "$flavor" full)"
al@412 2383 storage="$FLAVORS_REPOSITORY/$flavor"
al@412 2384
al@412 2385 rm -rf "$storage" 2>/dev/null
al@412 2386 mkdir -p "$storage"
al@412 2387 cp -a "$flv_dir"/* "$storage"
al@412 2388 rm "$storage/description"
al@412 2389 status
al@412 2390
al@412 2391 strip_versions "$storage/packages.list"
al@412 2392
al@412 2393 cleanup
al@412 2394 ;;
al@412 2395
al@412 2396
pascal@106 2397 pack-flavor)
pascal@106 2398 # Create a flavor from $FLAVORS_REPOSITORY.
al@412 2399 flavor=${2%.flavor}
al@412 2400 storage="$FLAVORS_REPOSITORY/$flavor"
al@412 2401
al@412 2402 [ -s "$storage/receipt" ] || die "No $flavor receipt in $FLAVORS_REPOSITORY."
al@412 2403
al@412 2404 action 'Creating flavor %s...' "$flavor"
al@412 2405 tmp_dir="$(mktemp -d)"
al@412 2406
al@412 2407 while read from to; do
al@412 2408 [ -s "$storage/$from" ] || continue
al@412 2409 cp -a "$storage/$from" "$tmp_dir/$to"
al@412 2410 done <<EOT
al@412 2411 mirrors $flavor.mirrors
al@412 2412 distro.sh $flavor-distro.sh
al@412 2413 receipt $flavor.receipt
al@412 2414 non-free.list $flavor.nonfree
al@412 2415 EOT
al@412 2416
al@412 2417 # Build the package list.
al@412 2418 # It can include a list from another flavor with the keyword @include
al@412 2419 if [ -s "$storage/packages.list" ]; then
al@412 2420 include=$(grep '^@include' "$storage/packages.list")
al@412 2421 if [ -n "$include" ]; then
al@412 2422 include=${include#@include }
al@412 2423 if [ -s "$FLAVORS_REPOSITORY/$include/packages.list" ]; then
al@412 2424 cp -f "$FLAVORS_REPOSITORY/$include/packages.list" "$tmp_dir/$flavor.pkglist"
al@412 2425 else
al@412 2426 echo -e "\nERROR: Can't find include package list from $include\n"
al@412 2427 fi
pascal@112 2428 fi
al@412 2429 # Generate the final/initial package list
al@412 2430 [ -s "$storage/packages.list" ] && \
al@412 2431 cat "$storage/packages.list" >> "$tmp_dir/$flavor.pkglist"
al@412 2432 sed -i '/@include/d' "$tmp_dir/$flavor.pkglist"
al@412 2433 fi
al@412 2434
al@412 2435 if grep -q ^ROOTFS_SELECTION "$storage/receipt"; then
al@412 2436 # Process multi-rootfs flavor
al@412 2437 . "$storage/receipt"
al@412 2438 set -- $ROOTFS_SELECTION
al@412 2439 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
al@412 2440 [ -f "$FLAVORS_REPOSITORY/$2/packages.list" ] || tazlito extract-flavor $2
al@412 2441 cp "$FLAVORS_REPOSITORY/$2/packages.list" "$tmp_dir/$flavor.pkglist"
al@412 2442
al@412 2443 for i in rootcd rootfs; do
al@412 2444 mkdir "$tmp_dir/$i"
al@412 2445 # Copy extra files from the first flavor
al@412 2446 [ -d "$FLAVORS_REPOSITORY/$2/$i" ] &&
al@412 2447 cp -a "$FLAVORS_REPOSITORY/$2/$i" "$tmp_dir"
al@412 2448 # Overload extra files by meta flavor
al@412 2449 [ -d "$storage/$i" ] && cp -a "$storage/$i" "$tmp_dir"
al@412 2450 [ -n "$(ls $tmp_dir/$i)" ] &&
al@412 2451 (cd "$tmp_dir/$i"; find . | cpio -o -H newc 2>/dev/null ) | \
pascal@439 2452 dogzip "$tmp_dir/$flavor.$i"
al@412 2453 rm -rf "$tmp_dir/$i"
al@412 2454 done
al@412 2455 else
al@412 2456 # Process plain flavor
al@412 2457 for i in rootcd rootfs; do
al@412 2458 [ -d "$storage/$i" ] || continue
al@412 2459 (cd "$storage/$i";
pascal@439 2460 find . | cpio -o -H newc 2>/dev/null) | dogzip "$tmp_dir/$flavor.$i"
al@412 2461 done
al@412 2462 fi
al@412 2463
al@412 2464 unset VERSION MAINTAINER ROOTFS_SELECTION
al@416 2465 set -- $(module calc_sizes "$tmp_dir" "$flavor")
al@412 2466 ROOTFS_SIZE="$1 (estimated)"
al@412 2467 INITRAMFS_SIZE="$2 (estimated)"
al@412 2468 ISO_SIZE="$3 (estimated)"
al@412 2469 PKGNUM="$4"
al@412 2470 . "$storage/receipt"
al@412 2471
al@412 2472 sed '/: $/d' > "$tmp_dir/$flavor.desc" <<EOT
pascal@107 2473 Flavor : $FLAVOR
pascal@108 2474 Description : $SHORT_DESC
pascal@108 2475 Version : $VERSION
pascal@108 2476 Maintainer : $MAINTAINER
pascal@108 2477 LiveCD RAM size : $FRUGAL_RAM
pascal@111 2478 Rootfs list : $ROOTFS_SELECTION
al@412 2479 Build date : $(date '+%Y%m%d at %T')
al@412 2480 Packages : $PKGNUM
pascal@108 2481 Rootfs size : $ROOTFS_SIZE
pascal@108 2482 Initramfs size : $INITRAMFS_SIZE
pascal@108 2483 ISO image size : $ISO_SIZE
pascal@107 2484 ================================================================================
pascal@107 2485
pascal@107 2486 EOT
al@412 2487
al@412 2488 rm -f $tmp_dir/packages.list
al@412 2489 pack_flavor "$tmp_dir" "$flavor"
al@412 2490 status
al@412 2491 display_unknown "$tmp_dir/err"
al@412 2492 display_warn "$flv_dir/warn"
al@412 2493 cleanup
al@412 2494 ;;
al@412 2495
al@412 2496
pascal@22 2497 get-flavor)
pascal@22 2498 # Get a flavor's files and prepare for gen-distro.
al@412 2499 flavor=${2%.flavor}
al@412 2500 title 'Preparing %s distro flavor' "$flavor"
al@412 2501 set -e
al@412 2502 [ -f "$flavor.flavor" ] || download "$flavor.flavor"
al@412 2503 set +e
al@412 2504
al@412 2505 action 'Cleaning %s...' "$DISTRO"
al@412 2506 [ -d "$DISTRO" ] && rm -r "$DISTRO"
al@412 2507 # Clean old files
al@412 2508 for i in non-free.list distro-packages.list distro.sh receipt mirrors err; do
al@412 2509 [ -f "$i" ] && rm "$i"
al@412 2510 done
al@412 2511 mkdir -p "$DISTRO"
al@412 2512 status
al@412 2513
al@412 2514 [ -z "$noup" ] && tazlito upgrade-flavor "$flavor.flavor"
al@412 2515
al@412 2516 action 'Extracting flavor %s...' "$flavor.flavor"
al@412 2517 flv_dir="$(extract_flavor "$flavor" info)"
al@412 2518 cp -a "$flv_dir"/* .
al@412 2519 mv packages.list distro-packages.list
al@412 2520 mv -f info /etc/tazlito
al@412 2521 status
al@412 2522
al@412 2523 for i in rootcd rootfs; do
al@412 2524 if [ -d "$i" ]; then
al@412 2525 mkdir -p "$ADDFILES"; mv "$i" "$ADDFILES/$i"
pankso@263 2526 fi
al@412 2527 done
al@412 2528
pascal@468 2529 sed '/^Rootfs list/!d;s/.*: //' description > /etc/tazlito/rootfs.list
pascal@468 2530 [ -s /etc/tazlito/rootfs.list ] || rm -f /etc/tazlito/rootfs.list
al@412 2531
al@416 2532 action 'Updating %s...' 'tazlito.conf'
al@412 2533 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .
al@412 2534 grep -v "^#VOLUM_NAME" < tazlito.conf | \
al@412 2535 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $flavor\"\\n#VOLUM_NA/" \
al@412 2536 > tazlito.conf.$$ && mv tazlito.conf.$$ tazlito.conf
al@412 2537 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$flavor\"/" tazlito.conf
al@412 2538 status
al@412 2539
al@412 2540 footer 'Flavor is ready to be generated by `tazlito gen-distro`'
al@412 2541 cleanup
al@412 2542 ;;
al@412 2543
pankso@279 2544
pascal@191 2545 iso2flavor)
al@412 2546 [ -z "$3" -o ! -s "$2" ] && die 'Usage: tazlito iso2flavor <image.iso> <flavor_name>' \
al@412 2547 '\n\nCreate a file <flavor_name>.flavor from the CD-ROM image file <image.iso>'
al@412 2548
pascal@191 2549 FLAVOR=${3%.flavor}
pascal@404 2550 mkdir -p $TMP_DIR/iso $TMP_DIR/rootfs $TMP_DIR/flavor
pascal@191 2551 mount -o loop,ro $2 $TMP_DIR/iso
al@412 2552 flavordata $2 | (cd $TMP_DIR/flavor; cpio -i 2>/dev/null)
pascal@404 2553 if [ -s $TMP_DIR/iso/boot/rootfs1.gz -a \
al@412 2554 ! -s $TMP_DIR/flavor/*.desc ]; then
al@416 2555 _ 'META flavors are not supported.'
pascal@191 2556 umount -d $TMP_DIR/iso
pascal@404 2557 elif [ ! -s $TMP_DIR/iso/boot/rootfs.gz -a \
pascal@404 2558 ! -s $TMP_DIR/iso/boot/rootfs1.gz ]; then
al@416 2559 _ 'No %s in ISO image. Needs a SliTaz ISO.' '/boot/rootfs.gz'
pascal@191 2560 umount -d $TMP_DIR/iso
pascal@191 2561 else
pascal@426 2562 for i in $(ls -r $TMP_DIR/iso/boot/rootfs*z); do
pascal@426 2563 uncompress $i | \
pascal@227 2564 ( cd $TMP_DIR/rootfs ; cpio -idmu > /dev/null 2>&1 )
pascal@404 2565 done
pascal@191 2566 if [ ! -s $TMP_DIR/rootfs/etc/slitaz-release ]; then
al@416 2567 _ 'No file %s in %s of ISO image. Needs a non-loram SliTaz ISO.' \
al@416 2568 '/etc/slitaz-release' '/boot/rootfs.gz'
pascal@191 2569 umount -d $TMP_DIR/iso
pascal@191 2570 else
pascal@191 2571 ROOTFS_SIZE=$(du -hs $TMP_DIR/rootfs | awk '{ print $1 }')
pascal@191 2572 RAM_SIZE=$(du -s $TMP_DIR/rootfs | awk '{ print 32*int(($1+36000)/32768) "M" }')
pascal@191 2573 cp -a $TMP_DIR/iso $TMP_DIR/rootcd
pascal@191 2574 ISO_SIZE=$(df -h $TMP_DIR/iso | awk 'END { print $2 }')
al@412 2575 BUILD_DATE=$(date '+%Y%m%d at %T' -r "$TMP_DIR/iso/md5sum")
pascal@191 2576 umount -d $TMP_DIR/iso
pascal@404 2577 INITRAMFS_SIZE=$(du -chs $TMP_DIR/rootcd/boot/rootfs*.gz | awk 'END { print $1 }')
pascal@191 2578 rm -f $TMP_DIR/rootcd/boot/rootfs.gz $TMP_DIR/rootcd/md5sum
pascal@191 2579 mv $TMP_DIR/rootcd/boot $TMP_DIR/rootfs
pascal@476 2580 [ -d $TMP_DIR/rootcd/efi ] && mv $TMP_DIR/rootcd/efi $TMP_DIR/rootfs
pascal@191 2581 sed 's/.* \(.*\).tazpkg*/\1/' > $TMP_DIR/$FLAVOR.pkglist \
pascal@217 2582 < $TMP_DIR/rootfs$INSTALLED.md5
pascal@191 2583 PKGCNT=$(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l | awk '{ print $1 }')
pascal@404 2584 if [ -s $TMP_DIR/flavor/*desc ]; then
pascal@404 2585 cp $TMP_DIR/flavor/*.desc $TMP_DIR/$FLAVOR.desc
pascal@404 2586 [ -s $TMP_DIR/$FLAVOR.receipt ] &&
pascal@404 2587 cp $TMP_DIR/flavor/*.receipt $TMP_DIR/$FLAVOR.receipt
pascal@404 2588 for i in rootfs rootcd ; do
pascal@404 2589 [ -s $TMP_DIR/flavor/*.list$i ] &&
al@412 2590 sed 's/.\{1,45\}//;/^\.$/d' $TMP_DIR/flavor/*.list$i | \
pascal@439 2591 ( cd $TMP_DIR/$i ; cpio -o -H newc ) | dogzip $TMP_DIR/$FLAVOR.$i
pascal@404 2592 done
pascal@404 2593 else
pascal@404 2594 find_flavor_rootfs $TMP_DIR/rootfs
pascal@404 2595 [ -d $TMP_DIR/rootfs/boot ] && mv $TMP_DIR/rootfs/boot $TMP_DIR/rootcd
pascal@476 2596 [ -d $TMP_DIR/rootfs/efi ] && mv $TMP_DIR/rootfs/efi $TMP_DIR/rootcd
pascal@404 2597 for i in rootfs rootcd ; do
pascal@404 2598 [ "$(ls $TMP_DIR/$i)" ] &&
pascal@439 2599 ( cd "$TMP_DIR/$i"; find * | cpio -o -H newc ) | dogzip "$TMP_DIR/$FLAVOR.$i"
pascal@404 2600 done
al@412 2601 unset VERSION MAINTAINER
pascal@404 2602 echo -en "Flavor short description \007: "; read -t 30 DESCRIPTION
pascal@404 2603 if [ -n "$DESCRIPTION" ]; then
al@416 2604 _n 'Flavor version : '; read -t 30 VERSION
al@416 2605 _n 'Flavor maintainer (your email) : '; read -t 30 MAINTAINER
pascal@404 2606 fi
al@412 2607
pascal@404 2608 cat > $TMP_DIR/$FLAVOR.desc <<EOT
pascal@191 2609 Flavor : $FLAVOR
al@412 2610 Description : ${DESCRIPTION:-SliTaz $FLAVOR flavor}
al@412 2611 Version : ${VERSION:-1.0}
al@412 2612 Maintainer : ${MAINTAINER:-nobody@slitaz.org}
pascal@191 2613 LiveCD RAM size : $RAM_SIZE
pascal@191 2614 Build date : $BUILD_DATE
pascal@191 2615 Packages : $PKGCNT
pascal@191 2616 Rootfs size : $ROOTFS_SIZE
pascal@191 2617 Initramfs size : $INITRAMFS_SIZE
pascal@191 2618 ISO image size : $ISO_SIZE
pascal@191 2619 ================================================================================
pascal@191 2620
pascal@191 2621 EOT
al@412 2622 longline "Tazlito can't detect each file installed during \
al@412 2623 a package post_install. You should extract this flavor (tazlito extract-flavor \
al@412 2624 $FLAVOR), check the files in /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/rootfs \
al@412 2625 tree and remove files generated by post_installs.
al@412 2626 Check /home/slitaz/flavors/$(cat /etc/slitaz-release)/$FLAVOR/receipt too and \
al@412 2627 repack the flavor (tazlito pack-flavor $FLAVOR)"
pascal@404 2628 fi
pascal@439 2629 ( cd $TMP_DIR; ls $FLAVOR.* | cpio -o -H newc ) | dogzip $FLAVOR.flavor
pascal@191 2630 fi
pascal@191 2631 fi
al@412 2632 rm -rf $TMP_DIR
al@412 2633 ;;
al@412 2634
al@412 2635
pankso@1 2636 gen-distro)
pankso@1 2637 # Generate a live distro tree with a set of packages.
pankso@1 2638 #
pankso@1 2639 check_root
al@412 2640 start_time=$(date +%s)
al@412 2641
al@412 2642 # Tazlito options: --iso or --cdrom
al@412 2643 CDROM=''
al@412 2644 [ -n "$iso" ] && CDROM="-o loop $iso"
al@412 2645 [ -n "$cdrom" ] && CDROM="/dev/cdrom"
al@412 2646
pascal@19 2647 # Check if a package list was specified on cmdline.
pankso@333 2648 if [ -f "$2" ]; then
al@412 2649 LIST_NAME="$2"
pankso@333 2650 else
al@412 2651 LIST_NAME='distro-packages.list'
pankso@333 2652 fi
pankso@279 2653
al@412 2654 [ -d "$ROOTFS" -a -z "$forced" ] && die "A rootfs exists in '$DISTRO'." \
al@412 2655 'Please clean the distro tree or change directory path.'
al@412 2656 [ -d "$ROOTFS" ] && rm -rf "$ROOTFS"
al@412 2657 [ -d "$ROOTCD" ] && rm -rf "$ROOTCD"
al@412 2658
al@412 2659 # If list not given: build list with all installed packages
al@412 2660 if [ ! -f "$LIST_NAME" -a -f "$LOCALSTATE/installed.info" ]; then
al@412 2661 awk -F$'\t' '{print $1}' "$LOCALSTATE/installed.info" >> "$LIST_NAME"
erjo@99 2662 fi
al@412 2663
pankso@1 2664 # Exit if no list name.
al@412 2665 [ ! -f "$LIST_NAME" ] && die 'No packages list found or specified. Please read the docs.'
al@412 2666
pankso@1 2667 # Start generation.
al@412 2668 title 'Tazlito generating a distro'
al@412 2669
pascal@18 2670 # Misc checks
al@412 2671 mkdir -p "$PACKAGES_REPOSITORY"
al@412 2672 REPACK=$(yesorno 'Repack packages from rootfs?' 'n')
al@417 2673 newline
al@412 2674
al@412 2675 # Mount CD-ROM to be able to repack boot-loader packages
pascal@19 2676 if [ ! -e /boot -a -n "$CDROM" ]; then
pascal@19 2677 mkdir $TMP_MNT
al@412 2678 if mount -r "$CDROM $TMP_MNT" 2>/dev/null; then
al@412 2679 ln -s "$TMP_MNT/boot" /
pascal@19 2680 if [ ! -d "$ADDFILES/rootcd" ] ; then
al@412 2681 mkdir -p "$ADDFILES/rootcd"
pascal@19 2682 for i in $(ls $TMP_MNT); do
al@412 2683 [ "$i" == 'boot' ] && continue
al@412 2684 cp -a "$TMP_MNT/$i" "$ADDFILES/rootcd"
pascal@19 2685 done
pascal@19 2686 fi
pascal@19 2687 else
al@412 2688 rmdir "$TMP_MNT"
pascal@19 2689 fi
pascal@19 2690 fi
pascal@19 2691
pankso@337 2692 # Rootfs stuff.
al@412 2693 echo 'Preparing the rootfs directory...'
al@412 2694 mkdir -p "$ROOTFS"
al@415 2695 export root="$ROOTFS"
al@459 2696 # pass current 'mirror' to the root
al@461 2697 mkdir -p $root/var/lib/tazpkg $root/etc
al@459 2698 cp -f /var/lib/tazpkg/mirror $root/var/lib/tazpkg/mirror
al@460 2699 cp -f /etc/slitaz-release $root/etc/slitaz-release
al@412 2700 strip_versions "$LIST_NAME"
al@412 2701
al@412 2702 if [ "$REPACK" == 'y' ]; then
al@412 2703 # Determine full packages list with all dependencies
al@412 2704 tmp_dir="$(mktemp -d)"
al@412 2705 cp "$LIST_NAME" "$tmp_dir/flavor.pkglist"
al@412 2706 touch "$tmp_dir/full.pkglist"
al@416 2707 module calc_sizes "$tmp_dir" 'flavor' "$tmp_dir/full.pkglist" >/dev/null
al@412 2708
al@412 2709 awk -F$'\t' '{printf "%s %s\n", $1, $2}' "$LOCALSTATE/installed.info" | \
al@412 2710 while read pkgname pkgver; do
al@412 2711 # Is package in full list?
al@412 2712 grep -q "^$pkgname$" "$tmp_dir/full.pkglist" || continue
al@412 2713 # Is package already repacked?
al@412 2714 [ -e "$PACKAGES_REPOSITORY/$pkgname-$pkgver.tazpkg" ] && continue
al@412 2715 _ 'Repacking %s...' "$pkgname-$pkgver"
al@412 2716 tazpkg repack "$pkgname" --quiet
al@412 2717 [ -f "$pkgname-$pkgver.tazpkg" ] && mv "$pkgname-$pkgver.tazpkg" "$PACKAGES_REPOSITORY"
al@412 2718 status
al@412 2719 done
al@412 2720
al@412 2721 rm -r "$tmp_dir"
al@412 2722 fi
al@412 2723
pascal@61 2724 if [ -f non-free.list ]; then
al@412 2725 # FIXME: working in the ROOTFS chroot?
al@412 2726 newline
al@412 2727 echo 'Preparing non-free packages...'
al@412 2728 cp 'non-free.list' "$ROOTFS/etc/tazlito/non-free.list"
al@412 2729 for pkg in $(cat 'non-free.list'); do
al@412 2730 if [ ! -d "$INSTALLED/$pkg" ]; then
al@412 2731 if [ ! -d "$INSTALLED/get-$pkg" ]; then
pascal@61 2732 tazpkg get-install get-$pkg
pascal@61 2733 fi
al@412 2734 get-$pkg "$ROOTFS"
pascal@61 2735 fi
pascal@61 2736 tazpkg repack $pkg
pascal@79 2737 pkg=$(ls $pkg*.tazpkg)
al@412 2738 grep -q "^$pkg$" $LIST_NAME || echo $pkg >> $LIST_NAME
pankso@279 2739 mv $pkg $PACKAGES_REPOSITORY
pascal@61 2740 done
pascal@61 2741 fi
pascal@80 2742 cp $LIST_NAME $DISTRO/distro-packages.list
al@412 2743 newline
al@412 2744
al@414 2745 install_list_to_rootfs "$DISTRO/distro-packages.list" "$ROOTFS"
al@391 2746
pankso@1 2747 cd $DISTRO
pascal@80 2748 cp distro-packages.list $ROOTFS/etc/tazlito
pankso@1 2749 # Copy all files from $ADDFILES/rootfs to the rootfs.
pankso@1 2750 if [ -d "$ADDFILES/rootfs" ] ; then
al@412 2751 action 'Copying addfiles content to the rootfs...'
pascal@11 2752 cp -a $ADDFILES/rootfs/* $ROOTFS
pascal@11 2753 status
pankso@1 2754 fi
al@412 2755
al@412 2756 action 'Root filesystem is generated...'; status
al@412 2757
pankso@1 2758 # Root CD part.
al@412 2759 action 'Preparing the rootcd directory...'
pankso@1 2760 mkdir -p $ROOTCD
pankso@1 2761 status
al@412 2762
pankso@1 2763 # Move the boot dir with the Linux kernel from rootfs.
pascal@476 2764 # The efi & boot dirs go directly on the CD.
pascal@476 2765 if [ -d "$ROOTFS/efi" ] ; then
pascal@476 2766 action 'Moving the efi directory...'
pascal@476 2767 mv $ROOTFS/efi $ROOTCD
pascal@476 2768 status
pascal@476 2769 fi
pankso@1 2770 if [ -d "$ROOTFS/boot" ] ; then
al@412 2771 action 'Moving the boot directory...'
pankso@1 2772 mv $ROOTFS/boot $ROOTCD
pankso@1 2773 status
pankso@1 2774 fi
pankso@1 2775 cd $DISTRO
pankso@1 2776 # Copy all files from $ADDFILES/rootcd to the rootcd.
pankso@1 2777 if [ -d "$ADDFILES/rootcd" ] ; then
al@412 2778 action 'Copying addfiles content to the rootcd...'
pascal@11 2779 cp -a $ADDFILES/rootcd/* $ROOTCD
pascal@11 2780 status
pankso@1 2781 fi
paul@154 2782 # Execute the distro script used to perform tasks in the rootfs
pankso@95 2783 # before compression. Give rootfs path in arg
al@412 2784 [ -z "$DISTRO_SCRIPT" ] && DISTRO_SCRIPT="$TOP_DIR/distro.sh"
al@412 2785 if [ -x "$DISTRO_SCRIPT" ]; then
al@412 2786 echo 'Executing distro script...'
pankso@95 2787 sh $DISTRO_SCRIPT $DISTRO
pankso@95 2788 fi
al@412 2789
al@412 2790 # Execute the custom_rules() found in receipt.
al@412 2791 if [ -s "$TOP_DIR/receipt" ]; then
al@412 2792 if grep -q ^custom_rules "$TOP_DIR/receipt"; then
al@412 2793 echo -e "Executing: custom_rules()\n"
al@412 2794 . "$TOP_DIR/receipt"
al@412 2795 custom_rules || echo -e "\nERROR: custom_rules() failed\n"
erjo@316 2796 fi
al@412 2797 fi
al@412 2798
pankso@337 2799 # Multi-rootfs
pascal@111 2800 if [ -s /etc/tazlito/rootfs.list ]; then
al@398 2801
al@412 2802 FLAVOR_LIST="$(awk '{
al@412 2803 for (i = 2; i <= NF; i+=2)
pascal@464 2804 printf "%s ", $i;
al@412 2805 }' /etc/tazlito/rootfs.list)"
al@412 2806
al@412 2807 [ -s "$ROOTCD/boot/isolinux/isolinux.msg" ] &&
al@412 2808 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
al@412 2809 "$ROOTCD/boot/isolinux/isolinux.msg" 2>/dev/null
al@412 2810
al@412 2811 [ -f "$ROOTCD/boot/isolinux/ifmem.c32" -o \
al@412 2812 -f "$ROOTCD/boot/isolinux/c32box.c32" ] ||
al@412 2813 cp '/boot/isolinux/c32box.c32' "$ROOTCD/boot/isolinux" 2>/dev/null ||
al@412 2814 cp '/boot/isolinux/ifmem.c32' "$ROOTCD/boot/isolinux"
al@398 2815
pascal@111 2816 n=0
pascal@111 2817 last=$ROOTFS
pascal@111 2818 while read flavor; do
pascal@111 2819 n=$(($n+1))
al@419 2820 mkdir ${ROOTFS}0$n
al@419 2821 export root="${ROOTFS}0$n"
al@419 2822 # initial tazpkg setup in empty rootfs
al@419 2823 tazpkg --root=$root >/dev/null 2>&1
al@419 2824
pankso@337 2825 newline
pankso@337 2826 boldify "Building $flavor rootfs..."
al@398 2827
al@412 2828 [ -s "$TOP_DIR/$flavor.flavor" ] &&
al@412 2829 cp "$TOP_DIR/$flavor.flavor" .
al@412 2830
al@412 2831 if [ ! -s "$flavor.flavor" ]; then
pankso@337 2832 # We may have it in $FLAVORS_REPOSITORY
pankso@337 2833 if [ -d "$FLAVORS_REPOSITORY/$flavor" ]; then
pankso@337 2834 tazlito pack-flavor $flavor
pankso@337 2835 else
pankso@337 2836 download $flavor.flavor
pankso@337 2837 fi
pankso@337 2838 fi
al@398 2839
al@412 2840 action 'Extracting %s and %s...' "$flavor.pkglist" "$flavor.rootfs"
al@412 2841 zcat $flavor.flavor | cpio -i --quiet $flavor.pkglist $flavor.rootfs
al@419 2842 cp $flavor.pkglist $DISTRO/list-packages0$n
pankso@337 2843 status
al@398 2844
al@412 2845 strip_versions "$DISTRO/list-packages0$n"
al@412 2846
al@414 2847 install_list_to_rootfs "$DISTRO/list-packages0$n" "${ROOTFS}0$n"
al@412 2848
pascal@485 2849 action 'Updating the boot directory...'
pascal@488 2850 yes n | cp -ai ${ROOTFS}0$n/boot $ROOTCD 2> /dev/null
al@412 2851 rm -rf ${ROOTFS}0$n/boot
al@412 2852
pascal@111 2853 cd $DISTRO
pascal@179 2854 if [ -s $flavor.rootfs ]; then
al@416 2855 _n 'Adding %s rootfs extra files...' "$flavor"
pankso@338 2856 zcat < $flavor.rootfs | ( cd ${ROOTFS}0$n ; cpio -idmu )
pascal@179 2857 fi
al@412 2858
al@412 2859 action 'Moving %s to %s' "list-packages0$n" "rootfs0$n"
al@416 2860 mv "$DISTRO/list-packages0$n" "${ROOTFS}0$n/etc/tazlito/distro-packages.list"
pankso@337 2861 status
al@412 2862
pascal@111 2863 rm -f $flavor.flavor install-list
pascal@111 2864 mergefs ${ROOTFS}0$n $last
pascal@111 2865 last=${ROOTFS}0$n
pascal@111 2866 done <<EOT
pascal@111 2867 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
pascal@111 2868 EOT
psychomaniak@383 2869 #'
pascal@111 2870 i=$(($n+1))
pascal@111 2871 while [ $n -gt 0 ]; do
pascal@111 2872 mv ${ROOTFS}0$n ${ROOTFS}$i
al@416 2873 _ 'Compressing %s (%s)...' "${ROOTFS}0$n" "$(du -hs ${ROOTFS}$i | awk '{ print $1 }')"
pascal@111 2874 gen_initramfs ${ROOTFS}$i
pascal@111 2875 n=$(($n-1))
pascal@111 2876 i=$(($i-1))
pascal@431 2877 export LZMA_HISTORY_BITS=26
pascal@111 2878 done
pascal@111 2879 mv $ROOTFS ${ROOTFS}$i
pascal@111 2880 gen_initramfs ${ROOTFS}$i
al@416 2881 update_bootconfig "$ROOTCD/boot/isolinux" "$(cat /etc/tazlito/rootfs.list)"
pascal@483 2882 ROOTFS=${ROOTFS}1
pascal@111 2883 else
pascal@111 2884 # Initramfs and ISO image stuff.
pascal@111 2885 gen_initramfs $ROOTFS
pascal@111 2886 fi
pankso@1 2887 gen_livecd_isolinux
pankso@1 2888 distro_stats
al@412 2889 cleanup
al@412 2890 ;;
al@412 2891
al@412 2892
pankso@1 2893 clean-distro)
pankso@1 2894 # Remove old distro tree.
pankso@1 2895 #
pankso@1 2896 check_root
al@412 2897 title 'Cleaning: %s' "$DISTRO"
pankso@1 2898 if [ -d "$DISTRO" ] ; then
pankso@1 2899 if [ -d "$ROOTFS" ] ; then
al@412 2900 action 'Removing the rootfs...'
al@412 2901 rm -f $DISTRO/$INITRAMFS
pascal@11 2902 rm -rf $ROOTFS
pascal@11 2903 status
pankso@1 2904 fi
pankso@1 2905 if [ -d "$ROOTCD" ] ; then
al@412 2906 action 'Removing the rootcd...'
pascal@11 2907 rm -rf $ROOTCD
pascal@11 2908 status
pankso@1 2909 fi
al@412 2910 action 'Removing eventual ISO image...'
pascal@11 2911 rm -f $DISTRO/$ISO_NAME.iso
pascal@56 2912 rm -f $DISTRO/$ISO_NAME.md5
pascal@11 2913 status
pankso@1 2914 fi
al@412 2915 footer
al@412 2916 ;;
al@412 2917
al@412 2918
pankso@1 2919 check-distro)
pankso@1 2920 # Check for a few LiveCD needed files not installed by packages.
pankso@1 2921 #
al@412 2922 # TODO: Remove this function.
al@412 2923 # First two files are maintained by tazpkg while it runs on rootfs,
al@412 2924 # while last one file should be maintained by tazlito itself.
pascal@11 2925 check_rootfs
al@412 2926 title 'Checking distro: %s' "$ROOTFS"
pankso@1 2927 # SliTaz release info.
al@416 2928 rel='/etc/slitaz-release'
al@416 2929 if [ ! -f "$ROOTFS$rel" ]; then
al@416 2930 _ 'Missing release info: %s' "$rel"
pankso@1 2931 else
al@416 2932 action 'Release : %s' "$(cat $ROOTFS$rel)"
pankso@1 2933 status
pankso@1 2934 fi
pankso@1 2935 # Tazpkg mirror.
pascal@217 2936 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
al@416 2937 action 'Mirror URL : Missing %s' "$LOCALSTATE/mirror"
pankso@1 2938 todomsg
pankso@1 2939 else
al@412 2940 action 'Mirror configuration exists...'
pankso@1 2941 status
pankso@1 2942 fi
pankso@279 2943 # Isolinux msg
pascal@235 2944 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
al@416 2945 action 'Isolinux msg : Missing cooking date XXXXXXXX (ex %s)' "$(date +%Y%m%d)"
pankso@1 2946 todomsg
pankso@1 2947 else
al@412 2948 action 'Isolinux message seems good...'
pankso@1 2949 status
pankso@1 2950 fi
al@412 2951 footer
al@412 2952 ;;
al@412 2953
al@412 2954
pankso@123 2955 writeiso)
al@412 2956 # Writefs to ISO image including /home unlike gen-distro we don't use
pankso@279 2957 # packages to generate a rootfs, we build a compressed rootfs with all
paul@134 2958 # the current filesystem similar to 'tazusb writefs'.
pankso@123 2959 #
al@412 2960 DISTRO='/home/slitaz/distro'
pankso@123 2961 ROOTCD="$DISTRO/rootcd"
al@412 2962 COMPRESSION="${2:-none}"
al@412 2963 ISO_NAME="${3:-slitaz}"
pankso@123 2964 check_root
pankso@123 2965 # Start info
al@412 2966 title 'Write filesystem to ISO'
al@412 2967 longline "The command writeiso will write the current filesystem into a \
al@412 2968 suitable cpio archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso)."
pankso@330 2969 newline
al@412 2970 emsg "<b>Archive compression:</b> <c 36>$COMPRESSION</c>"
al@412 2971
al@412 2972 [ "$COMPRESSION" == 'gzip' ] && colorize 31 "gzip-compressed rootfs unsupported and may fail to boot"
pankso@123 2973 # Save some space
al@412 2974 rm -rf /var/cache/tazpkg/*
al@412 2975 rm -f /var/lib/tazpkg/*.bak
psychomaniak@388 2976 rm -rf $DISTRO
pankso@123 2977
pankso@143 2978 # Optionally remove sound card selection and screen resolution.
psychomaniak@383 2979 if [ -z $LaunchedByTazpanel ]; then
al@416 2980 anser=$(yesorno 'Do you wish to remove the sound card and screen configs?' 'n')
pankso@123 2981 case $anser in
al@416 2982 y)
al@416 2983 action 'Removing current sound card and screen configurations...'
pankso@123 2984 rm -f /var/lib/sound-card-driver
pankso@290 2985 rm -f /var/lib/alsa/asound.state
pankso@123 2986 rm -f /etc/X11/xorg.conf ;;
pankso@123 2987 *)
al@416 2988 action 'Keeping current sound card and screen configurations...' ;;
pankso@123 2989 esac
al@412 2990 status
al@412 2991 newline
al@412 2992
pankso@330 2993 # Optionally remove i18n settings
al@416 2994 anser=$(yesorno 'Do you wish to remove locale/keymap settings?' 'n')
pankso@330 2995 case $anser in
al@416 2996 y)
al@416 2997 action 'Removing current locale/keymap settings...'
pankso@333 2998 newline > /etc/locale.conf
pankso@333 2999 newline > /etc/keymap.conf ;;
pankso@330 3000 *)
al@416 3001 action 'Keeping current locale/keymap settings...' ;;
pankso@330 3002 esac
pankso@123 3003 status
psychomaniak@383 3004 fi
al@412 3005
pankso@330 3006 # Clean-up files by default
pankso@333 3007 newline > /etc/udev/rules.d/70-persistent-net.rules
pankso@333 3008 newline > /etc/udev/rules.d/70-persistant-cd.rules
pankso@279 3009
pankso@123 3010 # Create list of files including default user files since it is defined in /etc/passwd
pankso@123 3011 # and some new users might have been added.
pankso@330 3012 cd /
psychomaniak@373 3013 echo 'init' > /tmp/list
al@412 3014 for dir in bin etc sbin var dev lib root usr home opt; do
pascal@361 3015 [ -d $dir ] && find $dir
al@412 3016 done >> /tmp/list
al@412 3017
al@412 3018 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk run run/udev; do
pascal@361 3019 [ -d $dir ] && echo $dir
al@412 3020 done >> /tmp/list
psychomaniak@373 3021
psychomaniak@388 3022 sed '/var\/run\/.*pid$/d ; /var\/run\/utmp/d ; /.*\/.gvfs/d ; /home\/.*\/.cache\/.*/d' -i /tmp/list
psychomaniak@386 3023
psychomaniak@388 3024 #if [ ! $(find /var/log/slitaz/tazpkg.log -size +4k) = "" ]; then
psychomaniak@388 3025 # sed -i "/var\/log\/slitaz\/tazpkg.log/d" /tmp/list
psychomaniak@388 3026 #fi
psychomaniak@386 3027 mv -f /var/log/wtmp /tmp/tazlito-wtmp
psychomaniak@386 3028 touch /var/log/wtmp
psychomaniak@386 3029
al@412 3030 for removelog in auth boot messages dmesg daemon slim .*old Xorg tazpanel cups; do
psychomaniak@378 3031 sed -i "/var\/log\/$removelog/d" /tmp/list
psychomaniak@374 3032 done
psychomaniak@373 3033
paul@152 3034 # Generate initramfs with specified compression and display rootfs
pankso@150 3035 # size in realtime.
psychomaniak@386 3036 rm -f /tmp/.write-iso* /tmp/rootfs 2>/dev/null
psychomaniak@383 3037
pankso@150 3038 write_initramfs &
pankso@143 3039 sleep 2
pascal@194 3040 cd - > /dev/null
pankso@143 3041 echo -en "\nFilesystem size:"
al@412 3042 while [ ! -f /tmp/rootfs ]; do
pankso@143 3043 sleep 1
al@412 3044 echo -en "\\033[18G$(du -sh /$INITRAMFS | awk '{print $1}') "
pankso@143 3045 done
psychomaniak@383 3046 mv -f /tmp/tazlito-wtmp /var/log/wtmp
pankso@143 3047 echo -e "\n"
pascal@361 3048 rm -f /tmp/rootfs
pankso@123 3049
pankso@123 3050 # Move freshly generated rootfs to the cdrom.
pankso@123 3051 mkdir -p $ROOTCD/boot
al@412 3052 mv -f /$INITRAMFS $ROOTCD/boot
al@416 3053 _ 'Located in: %s' "$ROOTCD/boot/$INITRAMFS"
pankso@279 3054
pankso@123 3055 # Now we need the kernel and isolinux files.
al@412 3056 copy_from_cd() {
pascal@362 3057 cp /media/cdrom/boot/bzImage* $ROOTCD/boot
pankso@123 3058 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
pascal@248 3059 unmeta_boot $ROOTCD
pankso@123 3060 umount /media/cdrom
psychomaniak@378 3061 }
al@412 3062
psychomaniak@378 3063 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
psychomaniak@378 3064 copy_from_cd;
al@412 3065 elif mount | grep /media/cdrom; then
psychomaniak@378 3066 copy_from_cd;
psychomaniak@428 3067 #elif [ -f "$bootloader" -a -f /boot/vmlinuz*slitaz* ]; then
psychomaniak@428 3068 # [ -f /boot/*slitaz ] && cp /boot/vmlinuz*slitaz $ROOTCD/boot/bzImage
psychomaniak@428 3069 # [ -f /boot/*slitaz64 ] && cp /boot/vmlinuz*slitaz64 $ROOTCD/boot/bzImage64
psychomaniak@378 3070 else
psychomaniak@383 3071 touch /tmp/.write-iso-error
al@412 3072 longline "When SliTaz is running in RAM the kernel and bootloader \
psychomaniak@429 3073 files are kept on the CD-ROM. `boldify ' Please insert a Live CD or run:
psychomaniak@429 3074 # mount -o loop slitaz.iso /media/cdrom ' ` to let Tazlito copy the files."
pankso@143 3075 echo -en "----\nENTER to continue..."; read i
psychomaniak@378 3076 [ ! -d /media/cdrom/boot/isolinux ] && exit 1
psychomaniak@378 3077 copy_from_cd
pankso@123 3078 fi
pankso@279 3079
pankso@123 3080 # Generate the iso image.
psychomaniak@383 3081 touch /tmp/.write-iso
psychomaniak@383 3082 newline
pankso@123 3083 cd $DISTRO
pascal@431 3084 create_iso $ISO_NAME.iso $ROOTCD
al@412 3085 action 'Creating the ISO md5sum...'
pascal@486 3086 md5sum $ISO_NAME.iso > $ISO_NAME.md5
pankso@123 3087 status
pankso@123 3088
al@416 3089 footer "ISO image: $(du -sh $DISTRO/$ISO_NAME.iso)"
psychomaniak@383 3090 rm -f /tmp/.write-iso
al@416 3091
psychomaniak@383 3092 if [ -z $LaunchedByTazpanel ]; then
al@416 3093 anser=$(yesorno 'Burn ISO to CD-ROM?' 'n')
pankso@123 3094 case $anser in
al@416 3095 y)
al@412 3096 umount /dev/cdrom 2>/dev/null
pankso@123 3097 eject
al@412 3098 echo -n "Please insert a blank CD-ROM and press ENTER..."
pankso@123 3099 read i && sleep 2
psychomaniak@388 3100 tazlito burn-iso $DISTRO/$ISO_NAME.iso
pankso@123 3101 echo -en "----\nENTER to continue..."; read i ;;
pankso@123 3102 *)
pankso@123 3103 exit 0 ;;
psychomaniak@383 3104 esac
al@412 3105 fi
al@412 3106 ;;
al@412 3107
al@412 3108
pankso@1 3109 burn-iso)
al@412 3110 # Guess CD-ROM device, ask user and burn the ISO.
pankso@1 3111 #
pankso@1 3112 check_root
al@412 3113 DRIVE_NAME=$(grep "drive name" /proc/sys/dev/cdrom/info | cut -f3)
al@412 3114 DRIVE_SPEED=$(grep "drive speed" /proc/sys/dev/cdrom/info | cut -f3)
pankso@1 3115 # We can specify an alternative ISO from the cmdline.
al@412 3116 iso="${2:-$DISTRO/$ISO_NAME.iso}"
al@412 3117 [ ! -f "$iso" ] && die "Unable to find ISO: $iso"
al@412 3118
al@412 3119 title 'Tazlito burn ISO'
al@412 3120 echo "CD-ROM device : /dev/$DRIVE_NAME"
pankso@1 3121 echo "Drive speed : $DRIVE_SPEED"
pankso@1 3122 echo "ISO image : $iso"
al@412 3123 footer
al@412 3124
al@412 3125 case $(yesorno 'Burn ISO image?' 'n') in
al@412 3126 y)
al@412 3127 title 'Starting Wodim to burn the ISO...'
al@412 3128 sleep 2
al@412 3129 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $iso
al@412 3130 footer 'ISO image is burned to CD-ROM.'
al@412 3131 ;;
al@412 3132 *)
al@412 3133 die 'Exiting. No ISO burned.'
al@412 3134 ;;
al@412 3135 esac
al@412 3136 ;;
al@412 3137
al@412 3138
pascal@101 3139 merge)
pascal@101 3140 # Merge multiple rootfs into one iso.
pascal@101 3141 #
pascal@101 3142 if [ -z "$2" ]; then
al@398 3143 cat <<EOT
pascal@101 3144 Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]...
pascal@101 3145
al@412 3146 Merge multiple rootfs into one ISO. Rootfs are like russian dolls
pascal@101 3147 i.e: rootfsN is a subset of rootfsN-1
al@412 3148 rootfs1 is found in ISO, sizeN is the RAM size needed to launch rootfsN.
pascal@101 3149 The boot loader will select the rootfs according to the RAM size detected.
pascal@101 3150
pankso@279 3151 Example:
pascal@101 3152 $ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz
pascal@101 3153
pascal@101 3154 Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM,
pascal@101 3155 slitaz-base with 32M-96M RAM and display an error message if RAM < 32M.
xfred222@293 3156
pascal@101 3157 EOT
pascal@101 3158 exit 2
pascal@101 3159 fi
pascal@101 3160
pascal@101 3161 shift # skip merge
pascal@111 3162 append="$1 slitaz1"
pascal@101 3163 shift # skip size1
pascal@101 3164 mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1
pascal@101 3165
pascal@101 3166 ISO=$1.merged
al@412 3167
pascal@101 3168 # Extract filesystems
al@412 3169 action 'Mounting %s' "$1"
pascal@101 3170 mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null
pascal@101 3171 status || cleanup_merge
al@412 3172
pascal@101 3173 cp -a $TMP_DIR/mnt $TMP_DIR/iso
pascal@362 3174 make_bzImage_hardlink $TMP_DIR/iso/boot
pascal@101 3175 umount -d $TMP_DIR/mnt
pascal@101 3176 if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then
al@416 3177 _ '%s is already a merged iso. Aborting.' "$1"
pascal@101 3178 cleanup_merge
pascal@101 3179 fi
pascal@278 3180 if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 -a
pascal@278 3181 ! -f $TMP_DIR/iso/boot/isolinux/c32box.c32 ]; then
pascal@278 3182 if [ ! -f /boot/isolinux/ifmem.c32 -a
pascal@278 3183 ! -f /boot/isolinux/c32box.c32 ]; then
pascal@101 3184 cat <<EOT
pascal@101 3185 No file /boot/isolinux/ifmem.c32
pascal@101 3186 Please install syslinux package !
pascal@101 3187 EOT
pascal@101 3188 rm -rf $TMP_DIR
pascal@101 3189 exit 1
pascal@101 3190 fi
pascal@278 3191 cp /boot/isolinux/c32box.c32 $TMP_DIR/iso/boot/isolinux 2> /dev/null ||
pascal@101 3192 cp /boot/isolinux/ifmem.c32 $TMP_DIR/iso/boot/isolinux
pascal@101 3193 fi
pankso@279 3194
al@416 3195 action 'Extracting %s' 'iso/rootfs.gz'
pascal@101 3196 extract_rootfs $TMP_DIR/iso/boot/rootfs.gz $TMP_DIR/rootfs1 &&
al@412 3197 [ -d $TMP_DIR/rootfs1/etc ]
pascal@101 3198 status || cleanup_merge
al@412 3199
pascal@101 3200 n=1
pascal@101 3201 while [ -n "$2" ]; do
pascal@101 3202 shift # skip rootfs N-1
pascal@101 3203 p=$n
pascal@101 3204 n=$(($n + 1))
pascal@111 3205 append="$append $1 slitaz$n"
pascal@101 3206 shift # skip size N
pascal@101 3207 mkdir -p $TMP_DIR/rootfs$n
al@412 3208
al@412 3209 action 'Extracting %s' "$1"
pascal@101 3210 extract_rootfs $1 $TMP_DIR/rootfs$n &&
al@412 3211 [ -d "$TMP_DIR/rootfs$n/etc" ]
pascal@101 3212 status || cleanup_merge
al@412 3213
pascal@101 3214 mergefs $TMP_DIR/rootfs$n $TMP_DIR/rootfs$p
al@416 3215 action 'Creating %s' "rootfs$p.gz"
al@412 3216 pack_rootfs "$TMP_DIR/rootfs$p" "$TMP_DIR/iso/boot/rootfs$p.gz"
pascal@101 3217 status
pascal@101 3218 done
al@416 3219 action 'Creating %s' "rootfs$n.gz"
al@412 3220 pack_rootfs "$TMP_DIR/rootfs$n" "$TMP_DIR/iso/boot/rootfs$n.gz"
pascal@101 3221 status
pascal@101 3222 rm -f $TMP_DIR/iso/boot/rootfs.gz
pascal@111 3223 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append"
pascal@101 3224 create_iso $ISO $TMP_DIR/iso
al@412 3225 rm -rf $TMP_DIR
al@412 3226 ;;
al@412 3227
pascal@101 3228
pascal@102 3229 repack)
pascal@102 3230 # Repack an iso with maximum lzma compression ratio.
pascal@102 3231 #
pascal@102 3232 ISO=$2
pascal@102 3233 mkdir -p $TMP_DIR/mnt
al@412 3234
pascal@102 3235 # Extract filesystems
al@412 3236 action 'Mounting %s' "$ISO"
al@412 3237 mount -o loop,ro $ISO $TMP_DIR/mnt 2>/dev/null
pascal@102 3238 status || cleanup_merge
al@412 3239
pascal@102 3240 cp -a $TMP_DIR/mnt $TMP_DIR/iso
pascal@102 3241 umount -d $TMP_DIR/mnt
pankso@279 3242
pascal@102 3243 for i in $TMP_DIR/iso/boot/rootfs* ; do
al@412 3244 action 'Repacking %s' "$(basename $i)"
pascal@426 3245 uncompress $i 2>/dev/null > $TMP_DIR/rootfs
al@412 3246 lzma e $TMP_DIR/rootfs $i $(lzma_switches $TMP_DIR/rootfs)
pascal@289 3247 align_to_32bits $i
pascal@102 3248 status
pascal@102 3249 done
pankso@279 3250
pascal@102 3251 create_iso $ISO $TMP_DIR/iso
al@412 3252 rm -rf $TMP_DIR
al@412 3253 ;;
al@412 3254
pascal@170 3255
pascal@170 3256 build-loram)
al@412 3257 # Build a Live CD for low RAM systems.
pascal@170 3258 #
al@412 3259 ISO="$2"
al@412 3260 OUTPUT="$3"
al@412 3261 [ -z "$3" ] && \
al@412 3262 die "Usage: tazlito build-loram <input>.iso <output>.iso [cdrom|smallcdrom|http|ram]"
al@412 3263 mkdir -p "$TMP_DIR/iso"
al@412 3264 mount -o loop,ro -t iso9660 "$ISO" "$TMP_DIR/iso"
pascal@426 3265 loopdev=$( (losetup -a 2>/dev/null || losetup) | sed "/$(echo $ISO | sed 's|/|\\/|g')$/!d;s/:.*//;q")
pascal@170 3266 if ! check_iso_for_loram ; then
al@412 3267 umount -d "$TMP_DIR/iso"
al@412 3268 die "$ISO is not a valid SliTaz live CD. Abort."
pascal@170 3269 fi
pascal@170 3270 case "$4" in
pankso@333 3271 cdrom) build_loram_cdrom ;;
pankso@333 3272 http) build_loram_http ;;
pascal@473 3273 *) build_loram_ram "$5" ;;
pascal@170 3274 esac
pascal@286 3275 umount $TMP_DIR/iso # no -d: needs /proc
pascal@286 3276 losetup -d $loopdev
al@412 3277 rm -rf $TMP_DIR
al@412 3278 ;;
al@412 3279
pascal@170 3280
pankso@115 3281 emu-iso)
pankso@115 3282 # Emulate an ISO image with Qemu.
al@412 3283 iso="${2:-$DISTRO/$ISO_NAME.iso}"
al@412 3284 [ -f "$iso" ] || die "Unable to find ISO file '$iso'."
al@412 3285 [ -x '/usr/bin/qemu' ] || die "Unable to find Qemu binary. Please install package 'qemu'."
pankso@115 3286 echo -e "\nStarting Qemu emulator:\n"
pankso@115 3287 echo -e "qemu $QEMU_OPTS $iso\n"
al@412 3288 qemu $QEMU_OPTS $iso
al@412 3289 ;;
al@412 3290
pascal@102 3291
paul@341 3292 deduplicate)
paul@341 3293 # Deduplicate files in a tree
pascal@285 3294 shift
al@412 3295 deduplicate "$@"
al@412 3296 ;;
al@412 3297
al@412 3298
pankso@1 3299 usage|*)
pankso@333 3300 # Print usage also for all unknown commands.
al@412 3301 usage
al@412 3302 ;;
pankso@1 3303 esac
pankso@1 3304
pankso@1 3305 exit 0