tazlito annotate tazlito @ rev 18

pave the road to flavors. Can find packages with 'tazpkg --repack'
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Dec 14 20:40:12 2007 +0000 (2007-12-14)
parents 6bc856bd158d
children bd901a157586
rev   line source
pankso@1 1 #!/bin/sh
pankso@1 2 # TazLito - SliTaz Live Tool.
pankso@1 3 #
pankso@1 4 # Tazlito is a tool to help generating and configuring SliTaz LiveCD
pankso@1 5 # ISO images. You can creat a custom distro in one command from a list of
pankso@1 6 # packages, extract a existing ISO image to hack it, creat new initramfs
pankso@1 7 # and/or new ISO. Most commands must be run by root, expect the stats
pankso@1 8 # and the configuration file manipulation.
pankso@1 9 #
pankso@1 10 # (C) 2007 SliTaz - GNU General Public License.
pankso@9 11 # Initial author : <pankso@slitaz.org>
pankso@1 12 #
pankso@9 13 VERSION=1.2
pankso@1 14
pankso@1 15 # Tazlito configuration variables to be shorter
pankso@1 16 # and to use words rater than numbers.
pankso@1 17 COMMAND=$1
pankso@1 18 LIST_NAME=$2
pankso@1 19 TMP_DIR=/tmp/tazlito-$$-$RANDOM
pankso@1 20 TOP_DIR=`pwd`
pankso@1 21 INITRAMFS=rootfs.gz
pascal@11 22 LOCALSTATE=/var/lib/tazpkg
pascal@11 23 INSTALLED=$LOCALSTATE/installed
pascal@12 24 CACHE_DIR=/var/cache/tazpkg
pascal@12 25 MIRROR=$LOCALSTATE/mirror
pankso@1 26
pankso@1 27 # Try to include config file, continue if command is gen-config or exit.
pankso@4 28 # The main config used by default is in /etc/tazlito.
pankso@4 29 if [ -f "/etc/tazlito/tazlito.conf" ] ; then
pankso@4 30 CONFIG_FILE="/etc/tazlito/tazlito.conf"
pankso@1 31 fi
pankso@1 32 # Specific distro config file can be put in a distro tree.
pankso@1 33 if [ -f "$TOP_DIR/tazlito.conf" ] ; then
pankso@1 34 CONFIG_FILE="$TOP_DIR/tazlito.conf"
pankso@1 35 fi
pankso@1 36 if [ ! "$CONFIG_FILE" = "" ] ; then
pankso@1 37 . $CONFIG_FILE
pankso@1 38 else
pankso@1 39 if [ "$COMMAND" = "gen-config" ] ; then
pankso@1 40 continue
pankso@1 41 else
pankso@1 42 echo "Unable to find any configuration file. Please read the doc"
pankso@1 43 echo "or run '`basename $0` gen-config' to get an empty config file."
pankso@1 44 exit 0
pankso@1 45 fi
pankso@1 46 fi
pankso@1 47
pankso@1 48 # Set the rootfs and rootcd path with $DISTRO
pankso@1 49 # configuration variable.
pankso@1 50 ROOTFS=$DISTRO/rootfs
pankso@1 51 ROOTCD=$DISTRO/rootcd
pankso@1 52
pankso@1 53 #####################
pankso@1 54 # Tazlito functions #
pankso@1 55 #####################
pankso@1 56
pankso@1 57 # Print the usage.
pankso@1 58 usage ()
pankso@1 59 {
pankso@1 60 echo -e "\nSliTaz Live Tool - Version: $VERSION\n
pankso@1 61 \033[1mUsage: \033[0m `basename $0` [command] [list|iso] [dir]
pankso@1 62 \033[1mCommands: \033[0m\n
pankso@1 63 usage Print this short usage.
pankso@1 64 stats View Tazlito and distro configuration statistics.
pankso@1 65 gen-config Generate a new configuration file for a distro.
pankso@1 66 configure Configure the main config file or a specific tazlito.conf.
pankso@1 67 gen-iso Generate a new ISO from a distro tree.
pankso@1 68 gen-initiso Generate a new initramfs and ISO from the distro tree.
pankso@1 69 extract-distro Extract and ISO to a directory and rebuild LiveCD tree.
pankso@1 70 gen-distro Generated a Live distro and ISO from a list of packages.
pankso@1 71 clean-distro Remove all files generated by gen-distro.
pankso@1 72 addhacker Add Linux User Hacker to the current distro.
pankso@1 73 check-distro Help to check if distro is ready to release.
pankso@1 74 burn-iso Burn ISO image to a cdrom using Wodim.\n"
pankso@1 75 }
pankso@1 76
pankso@1 77 # Status function.
pankso@1 78 status()
pankso@1 79 {
pankso@1 80 local CHECK=$?
pankso@1 81 echo -en "\\033[70G[ "
pankso@1 82 if [ $CHECK = 0 ]; then
pankso@1 83 echo -en "\\033[1;33mOK"
pankso@1 84 else
pankso@1 85 echo -en "\\033[1;31mFailed"
pankso@1 86 fi
pankso@1 87 echo -e "\\033[0;39m ]"
pankso@1 88 }
pascal@12 89
pascal@12 90 yesorno()
pascal@12 91 {
pascal@12 92 echo -n "$1"
pascal@12 93 case "$DEFAULT_ANSWER" in
pascal@12 94 Y|y) answer="y";;
pascal@12 95 N|n) answer="n";;
pascal@12 96 *) read answer;;
pascal@12 97 esac
pascal@12 98 }
pascal@12 99
pankso@1 100 todomsg()
pankso@1 101 {
pankso@1 102 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
pankso@1 103 }
pankso@1 104
pascal@12 105 # Download a file trying each mirror
pascal@12 106 download()
pascal@12 107 {
pascal@12 108 for i in $(cat $MIRROR); do
pascal@12 109 wget $i$@
pascal@12 110 done
pascal@12 111 }
pascal@12 112
pascal@13 113 # exec hooks provided by some packages
pascal@13 114 genisohooks()
pascal@13 115 {
pascal@13 116 local here=`pwd`
pascal@13 117 cd $ROOTFS
pascal@13 118 for i in $(ls etc/tazlito/*.$1 2> /dev/null); do
pascal@13 119 . $i $ROOTCD
pascal@13 120 done
pascal@13 121 cd $here
pascal@13 122 }
pascal@13 123
pascal@18 124 # echo the package name if the tazpkg is already installed
pascal@18 125 installed_package_name()
pascal@18 126 {
pascal@18 127 local tazpkg
pascal@18 128 local package
pascal@18 129 local VERSION
pascal@18 130 tazpkg=$1
pascal@18 131 # try du find package name and version to be able
pascal@18 132 # to repack it from installation
pascal@18 133 # a dash (-) can exist in name *and* in version
pascal@18 134 package=${tazpkg%-*}
pascal@18 135 i=$package
pascal@18 136 while true; do
pascal@18 137 VERSION=""
pascal@18 138 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
pascal@18 139 if [ "$i-$VERSION" = "$tazpkg" ]; then
pascal@18 140 echo $i
pascal@18 141 break
pascal@18 142 fi
pascal@18 143 case "$i" in
pascal@18 144 *-*);;
pascal@18 145 *) break;;
pascal@18 146 esac
pascal@18 147 i=${i%-*}
pascal@18 148 done
pascal@18 149 }
pascal@18 150
pankso@1 151 # Check if user is root.
pankso@1 152 check_root()
pankso@1 153 {
pankso@1 154 if test $(id -u) != 0 ; then
pankso@1 155 echo -e "\nYou must be root to run `basename $0` with this option."
pankso@1 156 echo -e "Please type 'su' and root password to become super-user.\n"
pankso@1 157 exit 0
pankso@1 158 fi
pankso@1 159 }
pankso@1 160
pascal@11 161 # Check for the rootfs tree.
pascal@11 162 check_rootfs()
pascal@11 163 {
pascal@13 164 if [ ! -d "$ROOTFS/etc" ] ; then
pascal@13 165 echo -e "\nUnable to find a distro rootfs...\n"
pascal@11 166 exit 0
pascal@11 167 fi
pascal@11 168 }
pascal@11 169
pankso@1 170 # Check for the boot dir into the root CD tree.
pankso@1 171 verify_rootcd()
pankso@1 172 {
pankso@1 173 if [ ! -d "$ROOTCD/boot" ] ; then
pankso@1 174 echo -e "\nUnable to find the rootcd boot directory...\n"
pankso@1 175 exit 0
pankso@1 176 fi
pankso@1 177 }
pankso@1 178
pankso@1 179 # Gen a new ISO image using isolinux.
pankso@1 180 gen_livecd_isolinux()
pankso@1 181 {
pascal@13 182 # Some packages may want to alter iso
pascal@13 183 genisohooks iso
pankso@1 184 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ] ; then
pankso@1 185 echo -e "\nUnable to find isolinux binary.\n"
pankso@1 186 exit 0
pankso@1 187 fi
pankso@1 188 cd $DISTRO
pankso@1 189 echo ""
pankso@1 190 echo -e "\033[1mGenerating ISO image\033[0m"
pankso@1 191 echo "================================================================================"
pankso@1 192 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
pankso@1 193 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
pankso@1 194 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
pankso@1 195 -boot-info-table $ROOTCD
pankso@1 196 echo "================================================================================"
pankso@1 197 }
pankso@1 198
pankso@1 199 # Gen a new initramfs from the root file system.
pankso@1 200 gen_initramfs()
pankso@1 201 {
pascal@13 202 # Some packages may want to alter rootfs
pascal@13 203 genisohooks rootfs
pankso@1 204 cd $ROOTFS
pankso@1 205 echo ""
pankso@7 206 # Use lzma if installed
pankso@7 207 if [ -x /usr/bin/lzma ]; then
pascal@14 208 echo -n "Generating lzma'ed initramfs... "
pascal@14 209 find . -print | cpio -o -H newc | lzma e -si -so > $DISTRO/$INITRAMFS
pankso@7 210 else
pankso@7 211 echo -n "Generating gziped initramfs... "
pankso@7 212 find . -print | cpio -o -H newc | gzip -9 > $DISTRO/$INITRAMFS
pankso@7 213 fi
pascal@14 214 cd $DISTRO
pascal@14 215 mv $INITRAMFS $ROOTCD/boot
pankso@1 216 }
pankso@1 217
pankso@1 218 # Print ISO and rootfs size.
pankso@1 219 distro_stats()
pankso@1 220 {
pankso@1 221 echo ""
pankso@1 222 echo -e "\033[1mDistro statistics\033[0m"
pankso@1 223 echo "================================================================================"
pankso@1 224 echo "Build date : `date +%Y%m%d\ \at\ \%H:%M:%S`"
pankso@1 225 echo "Packages : `ls -1 $ROOTFS/var/lib/tazpkg/installed | wc -l`"
pankso@1 226 echo "Rootfs size : `du -sh $ROOTFS`"
pascal@14 227 echo "Initramfs size : `du -sh $ROOTCD/boot/$INITRAMFS`"
pankso@1 228 echo "ISO image size : `du -sh $ISO_NAME.iso`"
pankso@1 229 echo "================================================================================"
pankso@1 230 echo ""
pankso@1 231 }
pankso@1 232
pankso@1 233 # Creat an empty configuration file.
pankso@1 234 empty_config_file()
pankso@1 235 {
pankso@1 236 cat >> tazlito.conf << "EOF"
pankso@1 237 # tazlito.conf: Tazlito (SliTaz Live Tool)
pankso@1 238 # configuration file.
pankso@1 239 #
pankso@1 240
pankso@1 241 # Name of the ISO image to generate.
pankso@1 242 ISO_NAME=""
pankso@1 243
pankso@1 244 # ISO image volum name.
pankso@1 245 VOLUM_NAME="SliTaz"
pankso@1 246
pankso@1 247 # Name of the preparator.
pankso@1 248 PREPARED="$USER"
pankso@1 249
pankso@1 250 # Path to the packages repository and the packages.list.
pankso@1 251 PACKAGES_REPOSITORY=""
pankso@1 252
pankso@1 253 # Path to the distro tree to gen-distro from a
pankso@1 254 # list of packages.
pankso@1 255 DISTRO=""
pankso@1 256
pankso@1 257 # Path to the directory contening additional files
pankso@1 258 # to copy into the rootfs and rootcd of the LiveCD.
pankso@1 259 ADDFILES="$DISTRO/addfiles"
pascal@12 260
pascal@12 261 # Default answer for binary question (Y or N)
pascal@12 262 DEFAULT_ANSWER="ASK"
pankso@1 263 EOF
pankso@1 264 }
pankso@1 265
pankso@1 266 ####################
pankso@1 267 # Tazlito commands #
pankso@1 268 ####################
pankso@1 269
pankso@1 270 case "$COMMAND" in
pankso@1 271 stats)
pankso@1 272 # Tazlito general statistics from the config file.
pankso@1 273 #
pankso@1 274 echo ""
pankso@1 275 echo -e "\033[1mTazlito statistics\033[0m
pankso@1 276 ===============================================================================
pankso@1 277 Config file : $CONFIG_FILE
pankso@1 278 ISO name : $ISO_NAME.iso
pankso@1 279 Volum name : $VOLUM_NAME
pankso@1 280 Prepared : $PREPARED
pankso@1 281 Packages repository : $PACKAGES_REPOSITORY
pankso@1 282 Distro directory : $DISTRO"
pankso@1 283 if [ ! "$ADDFILES" = "" ] ; then
pankso@1 284 echo -e "Additional files : $ADDFILES"
pankso@1 285 fi
pankso@1 286 echo "================================================================================"
pankso@1 287 echo ""
pankso@1 288 ;;
pankso@1 289 gen-config)
pankso@1 290 # Gen a new config file in the current dir or the specified
pankso@1 291 # directory by $2.
pankso@1 292 #
pankso@1 293 if [ -n "$2" ] ; then
pankso@1 294 mkdir -p $2 && cd $2
pankso@1 295 fi
pankso@1 296 echo -n "Generating empty tazlito.conf..."
pankso@1 297 empty_config_file
pankso@1 298 status
pankso@1 299 echo ""
pankso@1 300 if [ -f "tazlito.conf" ] ; then
pankso@1 301 echo "Configuration file is ready to edit."
pankso@1 302 echo "File location : `pwd`/tazlito.conf"
pankso@1 303 echo ""
pankso@1 304 fi
pankso@1 305 ;;
pankso@1 306 configure)
pankso@1 307 # Configure a tazlito.conf config file. Start by getting
pankso@1 308 # a empty config file and sed it.
pankso@1 309 #
pankso@1 310 if [ -f "tazlito.conf" ] ; then
pankso@1 311 rm tazlito.conf
pankso@1 312 else
pankso@1 313 if test $(id -u) = 0 ; then
pankso@1 314 cd /etc
pankso@1 315 else
pankso@1 316 echo "You must be root to configure the main config file or in"
pankso@1 317 echo "the same directory of the file you want to configure."
pankso@1 318 exit 0
pankso@1 319 fi
pankso@1 320 fi
pankso@1 321 empty_config_file
pankso@1 322 echo""
pankso@1 323 echo -e "\033[1mConfiguring :\033[0m `pwd`/tazlito.conf"
pankso@1 324 echo "================================================================================"
pankso@1 325 # ISO name.
pascal@11 326 echo -n "ISO name : " ; read answer
pascal@11 327 sed -i s#'ISO_NAME=\"\"'#"ISO_NAME=\"$answer\""# tazlito.conf
pascal@14 328 # Volume name.
pascal@14 329 echo -n "Volume name : " ; read answer
pascal@11 330 sed -i s/'VOLUM_NAME=\"SliTaz\"'/"VOLUM_NAME=\"$answer\""/ tazlito.conf
pankso@1 331 # Packages repository.
pascal@11 332 echo -n "Packages repository : " ; read answer
pascal@11 333 sed -i s#'PACKAGES_REPOSITORY=\"\"'#"PACKAGES_REPOSITORY=\"$answer\""# tazlito.conf
pankso@1 334 # Distro path.
pascal@11 335 echo -n "Distro path : " ; read answer
pascal@11 336 sed -i s#'DISTRO=\"\"'#"DISTRO=\"$answer\""# tazlito.conf
pankso@1 337 echo "================================================================================"
pankso@1 338 echo "Config file is ready to use."
pankso@1 339 echo "You can now extract an ISO or generate a distro."
pankso@1 340 echo ""
pankso@1 341 ;;
pankso@1 342 gen-iso)
pankso@1 343 # Simply generated a new iso.
pankso@1 344 #
pankso@1 345 check_root
pankso@1 346 verify_rootcd
pankso@1 347 gen_livecd_isolinux
pankso@1 348 distro_stats
pankso@1 349 ;;
pankso@1 350 gen-initiso)
pankso@1 351 # Simply generated a new initramfs with a new iso.
pankso@1 352 #
pankso@1 353 check_root
pankso@1 354 verify_rootcd
pankso@1 355 gen_initramfs
pankso@1 356 gen_livecd_isolinux
pankso@1 357 distro_stats
pankso@1 358 ;;
pankso@1 359 extract-distro)
pankso@1 360 # Extract a ISO image to a directory and rebuild the LiveCD tree.
pankso@1 361 #
pankso@1 362 check_root
pankso@1 363 ISO_IMAGE=$2
pankso@1 364 if [ -z "$ISO_IMAGE" ] ; then
pankso@1 365 echo -e "\nPlease specify the path to the ISO image."
pankso@1 366 echo -e "Example : `basename $0` image.iso /path/target\n"
pankso@1 367 exit 0
pankso@1 368 fi
pankso@1 369 # Set the distro path by checking for $3 on cmdline.
pankso@1 370 if [ -n "$3" ] ; then
pankso@1 371 TARGET=$3
pankso@1 372 else
pankso@1 373 TARGET=$DISTRO
pankso@1 374 fi
pankso@1 375 # Exit if existing distro is found.
pankso@1 376 if [ -d "$TARGET/rootfs" ] ; then
pankso@1 377 echo -e "\nA rootfs exist in : $TARGET"
pankso@1 378 echo -e "Please clean the distro tree or change directory path.\n"
pankso@1 379 exit 0
pankso@1 380 fi
pankso@1 381 echo ""
pankso@1 382 echo -e "\033[1mTazlito extracting :\033[0m $ISO_IMAGE"
pankso@1 383 echo "================================================================================"
pankso@1 384 # Start to mount the ISO.
pankso@1 385 echo ""
pankso@1 386 echo "Mounting ISO image..."
pankso@1 387 mkdir -p $TMP_DIR
pankso@1 388 # Get ISO file size.
pankso@1 389 isosize=`du -sh $ISO_IMAGE`
pankso@1 390 mount -o loop $ISO_IMAGE $TMP_DIR
pankso@1 391 sleep 2
pankso@1 392 # Prepare target dir, copy the kernel and the rootfs.
pankso@1 393 mkdir -p $TARGET/rootfs
pankso@1 394 mkdir -p $TARGET/rootcd/boot
pankso@1 395 echo -n "Copying the Linux kernel..."
pascal@16 396 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
pascal@16 397 ln $TARGET/rootcd/vmlinuz* $TARGET/rootcd/bzImage
pascal@16 398 else
pascal@16 399 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
pascal@16 400 fi
pankso@1 401 status
pankso@1 402 echo -n "Copying isolinux files..."
pankso@1 403 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
pankso@1 404 status
pankso@1 405 echo -n "Copying the rootfs..."
pascal@11 406 cp $TMP_DIR/boot/rootfs.?z $TARGET/rootcd/boot
pankso@1 407 status
pankso@1 408 # Exract initramfs.
pankso@1 409 cd $TARGET/rootfs
pankso@1 410 echo -n "Extracting the rootfs... "
pascal@11 411 ( zcat ../rootcd/boot/rootfs.gz 2>/dev/null || \
pascal@14 412 lzma d ../rootcd/boot/rootfs.?z -so ) | cpio -id
pankso@1 413 # Umount and remove temp directory and cd to $TARGET to get stats.
pankso@1 414 umount $TMP_DIR && rm -rf $TMP_DIR
pankso@1 415 cd ..
pankso@1 416 echo ""
pankso@1 417 echo "================================================================================"
pankso@1 418 echo "Extracted : $ISO_IMAGE ($isosize)"
pankso@1 419 echo "Distro tree : `pwd`"
pankso@1 420 echo "Rootfs size : `du -sh rootfs`"
pankso@1 421 echo "Rootcd size : `du -sh rootcd`"
pankso@1 422 echo "================================================================================"
pankso@1 423 echo ""
pankso@1 424 ;;
pankso@1 425 gen-distro)
pankso@1 426 # Generate a live distro tree with a set of packages.
pankso@1 427 #
pankso@1 428 check_root
pankso@1 429 if [ -d $ROOTFS ] ; then
pankso@1 430 echo "A rootfs exist in : $DISTRO"
pankso@1 431 echo -e "Please clean the distro tree or change directory path.\n"
pankso@1 432 exit 0
pankso@1 433 fi
pankso@1 434 # First check for the main packages list then
pankso@1 435 # for a distro-packages.list in the current directory
pankso@1 436 # if none, check if a package list was specified on cmdline.
pankso@1 437 if [ -f "/etc/slitaz-tools/distro-packages.list" ] ; then
pankso@1 438 LIST_NAME="distro-packages.list"
pankso@1 439 fi
pankso@1 440 if [ -f "distro-packages.list" ] ; then
pankso@1 441 LIST_NAME="distro-packages.list"
pankso@1 442 fi
pankso@1 443 if [ -n "$2" ] ; then
pankso@1 444 if [ ! -f "$2" ] ; then
pankso@1 445 echo -e "\nUnable to find the specified packages list."
pankso@1 446 echo -e "List name : $2\n"
pankso@1 447 exit 0
pankso@1 448 else
pankso@1 449 LIST_NAME=$2
pankso@1 450 fi
pankso@1 451 fi
pankso@1 452 # Exit if no list name.
pascal@18 453 if [ ! -f "$LIST_NAME" ]; then
pankso@1 454 echo -e "\nNo packages list found or specified. Please read the doc.\n"
pankso@1 455 exit 0
pankso@1 456 fi
pankso@1 457 # Start generation.
pankso@1 458 echo ""
pankso@1 459 echo -e "\033[1mTazlito generating a distro\033[0m"
pankso@1 460 echo "================================================================================"
pascal@18 461 # Misc checks
pascal@18 462 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
pascal@18 463 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
pankso@1 464 # Get the list of packages using cat for a file list.
pankso@1 465 LIST=`cat $LIST_NAME`
pankso@1 466 # Verify if all packages in list are presents in $PACKAGES_REPOSITORY.
pascal@18 467 REPACK=""
pascal@18 468 DOWNLOAD=""
pankso@1 469 for pkg in $LIST
pankso@1 470 do
pankso@1 471 pkg=${pkg%.tazpkg}
pascal@18 472 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
pascal@18 473 PACKAGE=$(installed_package_name $pkg)
pascal@18 474 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
pascal@18 475 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
pascal@18 476 echo -e "\nUnable to find $pkg in the repository."
pascal@18 477 echo -e "Path : $PACKAGES_REPOSITORY\n"
pascal@18 478 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
pascal@18 479 yesorno "Repack packages from rootfs (y/N) ? "
pascal@18 480 REPACK="$answer"
pascal@18 481 [ "$answer" = "y" ] || REPACK="n"
pascal@18 482 [ "$DOWNLOAD" = "y" ] && break
pascal@18 483 fi
pascal@18 484 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
pascal@18 485 yesorno "Download packages from mirror (Y/n) ? "
pascal@18 486 DOWNLOAD="$answer"
pascal@18 487 if [ "$answer" = "n" ]; then
pascal@18 488 [ -z "$PACKAGE" ] && exit 1
pascal@18 489 else
pascal@18 490 DOWNLOAD="y"
pascal@18 491 [ -n "$REPACK" ] && break
pascal@12 492 fi
pankso@1 493 fi
pascal@18 494 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
pankso@1 495 done
pankso@1 496 # Root fs stuff.
pankso@1 497 echo "Preparing the rootfs directory..."
pankso@1 498 mkdir -p $ROOTFS
pankso@1 499 sleep 2
pankso@1 500 for pkg in $LIST
pankso@1 501 do
pankso@1 502 # First copy and extract the package in tmp dir.
pankso@1 503 pkg=${pkg%.tazpkg}
pascal@18 504 PACKAGE=$(installed_package_name $pkg)
pankso@1 505 mkdir -p $TMP_DIR
pascal@12 506 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
pascal@12 507 # look for package in cache
pascal@12 508 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
pascal@12 509 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
pascal@18 510 # look for package in running distribution
pascal@18 511 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
pascal@18 512 tazpkg repack $PACKAGE && \
pascal@18 513 mv $pkg.tazpkg $PACKAGES_REPOSITORY
pascal@18 514 fi
pascal@18 515 fi
pascal@18 516 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
pascal@12 517 # get package from mirror
pascal@18 518 [ "$DOWNLOAD" = "y" ] && \
pascal@18 519 download $pkg.tazpkg && \
pascal@18 520 mv $pkg.tazpkg $PACKAGES_REPOSITORY
pascal@12 521 fi
pascal@12 522 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
pascal@12 523 echo "Missing package $pkg."
pascal@12 524 exit 1
pascal@12 525 fi
pascal@17 526 yes "" | tazpkg install $PACKAGES_REPOSITORY/$pkg.tazpkg --root=$ROOTFS
pankso@1 527 done
pankso@1 528 echo ""
pankso@1 529 cd $DISTRO
pankso@1 530 # Copy all files from $ADDFILES/rootfs to the rootfs.
pankso@1 531 if [ -d "$ADDFILES/rootfs" ] ; then
pankso@1 532 echo -n "Copying addfiles content to the rootfs... "
pascal@11 533 cp -a $ADDFILES/rootfs/* $ROOTFS
pascal@11 534 status
pankso@1 535 fi
pankso@1 536 echo "Root file system is generated..."
pankso@1 537 # Root CD part.
pankso@1 538 echo -n "Preparing the rootcd directory..."
pankso@1 539 mkdir -p $ROOTCD
pankso@1 540 status
pankso@1 541 # Move the boot dir with the Linux kernel from rootfs.
pankso@1 542 # The boot dir goes directly on the CD.
pankso@1 543 if [ -d "$ROOTFS/boot" ] ; then
pankso@1 544 echo -n "Moving the boot directory..."
pankso@1 545 mv $ROOTFS/boot $ROOTCD
pankso@1 546 cd $ROOTCD/boot
pascal@11 547 ln vmlinuz-* bzImage
pankso@1 548 status
pankso@1 549 fi
pankso@1 550 cd $DISTRO
pankso@1 551 # Copy all files from $ADDFILES/rootcd to the rootcd.
pankso@1 552 if [ -d "$ADDFILES/rootcd" ] ; then
pankso@1 553 echo -n "Copying addfiles content to the rootcd... "
pascal@11 554 cp -a $ADDFILES/rootcd/* $ROOTCD
pascal@11 555 status
pankso@1 556 fi
pankso@1 557 # Initramfs and ISO image stuff.
pankso@1 558 gen_initramfs
pankso@1 559 gen_livecd_isolinux
pankso@1 560 distro_stats
pankso@1 561 ;;
pankso@1 562 clean-distro)
pankso@1 563 # Remove old distro tree.
pankso@1 564 #
pankso@1 565 check_root
pankso@1 566 echo ""
pankso@1 567 echo -e "\033[1mCleaning :\033[0m $DISTRO"
pankso@1 568 echo "================================================================================"
pankso@1 569 if [ -d "$DISTRO" ] ; then
pankso@1 570 if [ -d "$ROOTFS" ] ; then
pankso@1 571 echo -n "Removing the rootfs..."
pankso@1 572 rm -f $DISTRO/$INITRAMFS
pascal@11 573 rm -rf $ROOTFS
pascal@11 574 status
pankso@1 575 fi
pankso@1 576 if [ -d "$ROOTCD" ] ; then
pankso@1 577 echo -n "Removing the rootcd..."
pascal@11 578 rm -rf $ROOTCD
pascal@11 579 status
pankso@1 580 fi
pankso@1 581 echo -n "Removing eventual ISO image..."
pascal@11 582 rm -f $DISTRO/$ISO_NAME.iso
pascal@11 583 status
pankso@1 584 fi
pankso@1 585 echo "================================================================================"
pankso@1 586 echo ""
pankso@1 587 ;;
pankso@1 588 addhacker)
pankso@1 589 # Without /etc/passwd...
pankso@1 590 #
pankso@1 591 check_root
pankso@1 592 echo ""
pankso@1 593 echo -e "\033[1mAdduser hacker to :\033[0m $ROOTFS"
pankso@1 594 echo "================================================================================"
pankso@1 595 if [ ! -d "$ROOTFS/etc" ] ; then
pankso@1 596 echo -e "\nUnable to find : $ROOTFS/etc"
pankso@1 597 echo -e "Users and passwords config files will not be found.\n"
pankso@1 598 exit 0
pankso@1 599 fi
pankso@1 600 # Go for echoing on configuration files if any hacker was found.
pankso@1 601 #
pankso@1 602 if [ ! "`cat $ROOTFS/etc/passwd | grep hacker`" ] ; then
pankso@1 603 echo -n "Configuring $ROOTFS/etc..."
pankso@1 604 echo 'hacker:x:500:500:Linux User,,,:/home/hacker:/bin/ash' >> $ROOTFS/etc/passwd
pankso@1 605 echo 'hacker::13646:0:99999:7:::' >> $ROOTFS/etc/shadow
pankso@1 606 echo 'hacker:x:500:' >> $ROOTFS/etc/group
pankso@1 607 echo 'hacker:!::' >> $ROOTFS/etc/gshadow
pankso@1 608 status
pankso@1 609 else
pankso@1 610 echo "Hacker is already in : $ROOTFS/etc/passwd"
pankso@1 611 fi
pankso@8 612 # Hacker can listen to music
pankso@8 613 #
pankso@8 614 if grep -q audio $ROOTFS/etc/group; then
pankso@8 615 sed -i s/'audio:x:20:'/'audio:x:20:hacker'/ $ROOTFS/etc/group
pankso@8 616 fi
pankso@1 617 # /home/hacker files.
pankso@1 618 #
pankso@1 619 echo -n "Creating default directories... "
pankso@1 620 mkdir -p $ROOTFS/home/hacker/Documents \
pankso@1 621 $ROOTFS/home/hacker/Downloads \
pankso@1 622 $ROOTFS/home/hacker/Images \
pankso@1 623 $ROOTFS/home/hacker/Public \
pankso@1 624 $ROOTFS/home/hacker/Templates
pankso@1 625 status
pankso@1 626 # Change permissions.
pankso@1 627 #
pankso@1 628 echo -n "Chmodig all files in /home/hacker..."
pankso@1 629 chown -R 500.500 $ROOTFS/home/hacker
pankso@1 630 status
pankso@1 631 echo "================================================================================"
pankso@1 632 echo "Linux User Hacker have an account in the distro."
pankso@1 633 echo ""
pankso@1 634 ;;
pankso@1 635 check-distro)
pankso@1 636 # Check for a few LiveCD needed files not installed by packages.
pankso@1 637 #
pascal@11 638 check_rootfs
pankso@1 639 echo ""
pankso@1 640 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
pankso@1 641 echo "================================================================================"
pankso@1 642 # SliTaz release info.
pankso@1 643 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
pascal@11 644 echo "Missing release info : /etc/slitaz-release"
pankso@1 645 else
pankso@1 646 release=`cat $ROOTFS/etc/slitaz-release`
pankso@1 647 echo -n "Release : $release"
pankso@1 648 status
pankso@1 649 fi
pankso@1 650 # Tazpkg mirror.
pankso@1 651 if [ ! -f "$ROOTFS/var/lib/tazpkg/mirror" ]; then
pankso@1 652 echo -n "Mirror URL : Missing /var/lib/tazpkg/mirror"
pankso@1 653 todomsg
pankso@1 654 else
pankso@1 655 echo -n "Mirror configuration exist..."
pankso@1 656 status
pankso@1 657 fi
pankso@1 658 # Isolinux msg
pankso@1 659 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.msg; then
pankso@1 660 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
pankso@1 661 todomsg
pankso@1 662 else
pankso@1 663 echo -n "Isolinux message seems good..."
pankso@1 664 status
pankso@1 665 fi
pankso@1 666 echo "================================================================================"
pankso@1 667 echo ""
pankso@1 668 ;;
pankso@1 669 burn-iso)
pankso@1 670 # Guess cdrom device, ask user and burn the ISO.
pankso@1 671 #
pankso@1 672 check_root
pankso@1 673 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3`
pankso@1 674 DRIVE_SPEED=`cat /proc/sys/dev/cdrom/info | grep "drive speed" | cut -f 3`
pankso@1 675 # We can specify an alternative ISO from the cmdline.
pankso@1 676 if [ -n "$2" ] ; then
pankso@1 677 iso=$2
pankso@1 678 else
pankso@1 679 iso=$DISTRO/$ISO_NAME.iso
pankso@1 680 fi
pankso@1 681 if [ ! -f "$iso" ]; then
pankso@1 682 echo -e "\nUnable to find ISO : $iso\n"
pankso@1 683 exit 0
pankso@1 684 fi
pankso@1 685 echo ""
pankso@1 686 echo -e "\033[1mTazlito burn ISO\033[0m "
pankso@1 687 echo "================================================================================"
pankso@1 688 echo "Cdrom device : /dev/$DRIVE_NAME"
pankso@1 689 echo "Drive speed : $DRIVE_SPEED"
pankso@1 690 echo "ISO image : $iso"
pankso@1 691 echo "================================================================================"
pankso@1 692 echo ""
pascal@12 693 yesorno "Burn ISO image (y/N) ? "
pascal@11 694 if [ "$answer" == "y" ]; then
pankso@1 695 echo ""
pankso@1 696 echo "Starting Wodim to burn the iso..." && sleep 2
pankso@1 697 echo "================================================================================"
pankso@1 698 wodim speed=$DRIVE_SPEED dev=/dev/$DRIVE_NAME $DISTRO/$ISO_NAME.iso
pankso@1 699 echo "================================================================================"
pankso@1 700 echo "ISO image is burned to cdrom."
pankso@1 701 else
pankso@1 702 echo -e "\nExiting. No ISO burned."
pankso@1 703 fi
pankso@1 704 echo ""
pankso@1 705 ;;
pankso@1 706 usage|*)
pankso@1 707 # Clear and print usage also for all unknow commands.
pankso@1 708 #
pankso@1 709 clear
pankso@1 710 usage
pankso@1 711 ;;
pankso@1 712
pankso@1 713 esac
pankso@1 714
pankso@1 715 exit 0