# HG changeset patch # User Christopher Rogers # Date 1345877102 0 # Node ID 6eb46b5c9beaccd686fd7a4b10706a0dca61fc7c # Parent a1d274eeaf00a90d740bf40cfb2d2c9cd659e867 libcookiso.sh: Change tazlito to cookiso. Add some more functions from tazlito. diff -r a1d274eeaf00 -r 6eb46b5c9bea lib/libcookiso.sh --- a/lib/libcookiso.sh Fri Aug 24 22:05:20 2012 +0000 +++ b/lib/libcookiso.sh Sat Aug 25 06:45:02 2012 +0000 @@ -12,7 +12,7 @@ [ -f "$TOP_DIR/cookiso.conf" ] && CONFIG_FILE="$TOP_DIR/cookiso.conf" DEFAULT_MIRROR="$MIRROR_URL/packages/$SLITAZ_VERSION/" -log=/var/log/tazlito.log +log=/var/log/cookiso.log if check_root; then newline > $log fi @@ -89,8 +89,8 @@ # Execute hooks provided by some packages genisohooks() { - local here=`pwd` - for i in $(ls $ROOTFS/etc/tazlito/*.$1 2> /dev/null); do + local here=$(pwd) + for i in $(ls $ROOTFS/etc/slitaz/*.$1 2> /dev/null); do cd $ROOTFS . $i $ROOTCD done @@ -183,10 +183,10 @@ /usr/bin/isohybrid $1 -entry 2 2> /dev/null status fi - if [ -s /etc/tazlito/info ]; then - if [ $(stat -c %s /etc/tazlito/info) -lt $(( 31*1024 )) ]; then + if [ -s /etc/slitaz/info ]; then + if [ $(stat -c %s /etc/slitaz/info) -lt $(( 31*1024 )) ]; then echo -n "Storing ISO info..." - dd if=/etc/tazlito/info bs=1k seek=1 of=$1 \ + dd if=/etc/slitaz/info bs=1k seek=1 of=$1 \ conv=notrunc 2> /dev/null status fi @@ -370,6 +370,144 @@ distro_sizes } +# Create an empty configuration file. +empty_config_file() +{ + cat >> tazlito.conf << "EOF" +# tazlito.conf: Tazlito (SliTaz Live Tool) +# configuration file. +# + +# Name of the ISO image to generate. +ISO_NAME="" + +# ISO image volume name. +VOLUM_NAME="SliTaz" + +# Name of the preparer. +PREPARED="$USER" + +# Path to the packages repository and the packages.list. +PACKAGES_REPOSITORY="" + +# Path to the distro tree to gen-distro from a +# list of packages. +DISTRO="" + +# Path to the directory containing additional files +# to copy into the rootfs and rootcd of the LiveCD. +ADDFILES="$DISTRO/addfiles" + +# Default answer for binary question (Y or N) +DEFAULT_ANSWER="ASK" + +# Compression utility (lzma, gzip or none) +COMPRESSION="lzma" +EOF +} + +# Display package list with version, set packed_size and unpacked_size +get_pkglist() +{ +packed_size=0; unpacked_size=0 +grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg +while read pkg; do + set -- $(get_size $pkg) + packed_size=$(( $packed_size + $1 )) + unpacked_size=$(( $unpacked_size + $2 )) + for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \ + $TMP_DIR/packages.list); do + echo $i + break + done +done < $TMP_DIR/flavor.pkg +rm -f $TMP_DIR/flavor.pkg +} + +human2cent() +{ +case "$1" in +*k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';; +*M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));; +*G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));; +esac +} + +cent2human() +{ +if [ $1 -lt 10000 ]; then + echo "$(($1 / 10)).$(($1 % 10))k" +elif [ $1 -lt 10000000 ]; then + echo "$(($1 / 10240)).$(( ($1/1024) % 10))M" +else + echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G" +fi +} + +get_size() +{ +cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \ +if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \ +if (/installed/ && get == 1) { print ; get++ } \ +} +END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \ +sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do + echo "$(human2cent $packed) $(human2cent $unpacked)" +done +} + +# extract rootfs.gz somewhere +extract_rootfs() +{ + (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \ + (cd $2; cpio -idm > /dev/null) +} + +# Remove duplicate files +mergefs() +{ + echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into " + echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))" + # merge symlinks files and devices + ( cd $1; find ) | while read file; do + if [ -L $1/$file ]; then + [ -L $2/$file ] && + [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] && + rm -f $2/$file + elif [ -f $1/$file ]; then + [ -f $2/$file ] && + cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file + [ -f $2/$file ] && + [ "$(basename $file)" == "volatile.cpio.gz" ] && + [ "$(dirname $(dirname $file))" == \ + ".$INSTALLED" ] && rm -f $2/$file + elif [ -b $1/$file ]; then + [ -b $2/$file ] && + [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \ + "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] && + rm -f $2/$file + elif [ -c $1/$file ]; then + [ -c $2/$file ] && + [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \ + "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] && + rm -f $2/$file + fi + done + + # cleanup directories + ( cd $1; find -type d ) | sed '1!G;h;$!d' | while read file; do + [ -d $2/$file ] && rmdir $2/$file 2> /dev/null + done + true + status +} + +cleanup_merge() +{ + rm -rf $TMP_DIR + exit 1 +} + # tazlito gen-distro gen_distro() { @@ -416,7 +554,7 @@ if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then # Build list with installed packages for i in $(ls $INSTALLED); do - eval $(grep ^VERSION= $INSTALLED/$i/receipt)) + eval $(grep ^VERSION= $INSTALLED/$i/receipt) EXTRAVERSION="" eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt) echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME @@ -518,7 +656,7 @@ done if [ -f non-free.list ]; then echo "Preparing non-free packages..." - cp non-free.list $ROOTFS/etc/tazlito/non-free.list + cp non-free.list $ROOTFS/etc/slitaz/non-free.list for pkg in $(cat non-free.list); do if [ ! -d $INSTALLED/$pkg ]; then if [ ! -d $INSTALLED/get-$pkg ]; then @@ -544,7 +682,7 @@ done rm -f $ROOTFS/$DB/packages.* cd $DISTRO - cp $DISTRO_LIST $ROOTFS/etc/tazlito + cp $DISTRO_LIST $ROOTFS/etc/slitaz # Copy all files from $ADDFILES/rootfs to the rootfs. if [ -d "$ADDFILES/rootfs" ] ; then echo -n "Copying addfiles content to the rootfs... " @@ -579,9 +717,9 @@ echo "Executing distro script..." sh $DISTRO_SCRIPT $DISTRO fi - if [ -s /etc/tazlito/rootfs.list ]; then + if [ -s /etc/slitaz/rootfs.list ]; then FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \ - printf("%s ",$i) }' < /etc/tazlito/rootfs.list)" + printf("%s ",$i) }' < /etc/slitaz/rootfs.list)" sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \ $ROOTCD/boot/isolinux/isolinux.msg 2> /dev/null [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] || @@ -593,31 +731,32 @@ echo "Building $flavor rootfs..." if [ -d $flavors/$flavor ]; then cp -a $flavors - [ -s $TOP_DIR/$flavor.flavor ] && - cp $TOP_DIR/$flavor.flavor . - [ -s $flavor.flavor ] || download $flavor.flavor - zcat $flavor.flavor | cpio -i \ - $flavor.pkglist $flavor.rootfs - sed 's/.*/&.tazpkg/' < $flavor.pkglist \ - > $DISTRO/list-packages0$n - mkdir ${ROOTFS}0$n - cd $PACKAGES_REPOSITORY - yes y | tazpkg install-list \ - $DISTRO/list-packages0$n --root=${ROOTFS}0$n - rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/$DB/packages.* - status - cd $DISTRO - if [ -s $flavor.rootfs ]; then - echo "Adding $flavor rootfs extra files..." - zcat $flavor.rootfs | \ - ( cd ${ROOTFS}0$n ; cpio -idmu ) + [ -s $TOP_DIR/$flavor.flavor ] && + cp $TOP_DIR/$flavor.flavor . + [ -s $flavor.flavor ] || download $flavor.flavor + zcat $flavor.flavor | cpio -i \ + $flavor.pkglist $flavor.rootfs + sed 's/.*/&.tazpkg/' < $flavor.pkglist \ + > $DISTRO/list-packages0$n + mkdir ${ROOTFS}0$n + cd $PACKAGES_REPOSITORY + yes y | tazpkg install-list \ + $DISTRO/list-packages0$n --root=${ROOTFS}0$n + rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/$DB/packages.* + status + cd $DISTRO + if [ -s $flavor.rootfs ]; then + echo "Adding $flavor rootfs extra files..." + zcat $flavor.rootfs | \ + ( cd ${ROOTFS}0$n ; cpio -idmu ) + fi + mv $flavor.pkglist ${ROOTFS}0$n/etc/slitaz/$DISTRO_LIST + rm -f $flavor.flavor install-list + mergefs ${ROOTFS}0$n $last + last=${ROOTFS}0$n fi - mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/$DISTRO_LIST - rm -f $flavor.flavor install-list - mergefs ${ROOTFS}0$n $last - last=${ROOTFS}0$n done <