cookutils rev 537 slitaz-tank

lib: Update both libmodular.sh and libcookiso.sh.
author Christopher Rogers <slaxemulator@gmail.com>
date Sun Sep 23 09:35:49 2012 +0000 (2012-09-23)
parents 6b2e60bbf266
children 62860c25523f
files lib/libcookiso.sh lib/libmodular.sh
line diff
     1.1 --- a/lib/libcookiso.sh	Sun Sep 23 09:34:59 2012 +0000
     1.2 +++ b/lib/libcookiso.sh	Sun Sep 23 09:35:49 2012 +0000
     1.3 @@ -120,7 +120,7 @@
     1.4  	while true; do
     1.5  		VERSION=""
     1.6  		eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
     1.7 -		EXTRAVERSION=""
     1.8 +		unset EXTRAVERSION
     1.9  		eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
    1.10  		if [ "$i-$VERSION$EXTRAVERSION" = "$tazpkg" ]; then
    1.11  			echo $i
    1.12 @@ -289,6 +289,7 @@
    1.13  	echo 1 > /tmp/rootfs
    1.14  }
    1.15  
    1.16 +
    1.17  # Deduplicate files (MUST be on the same filesystem).
    1.18  deduplicate()
    1.19  {
    1.20 @@ -326,7 +327,7 @@
    1.21  	# Use lzma if installed. Display rootfs size in realtime.
    1.22  	rm -f /tmp/rootfs
    1.23  	if [ "$MODULAR" ]; then
    1.24 -		pack_rootfs . $DISTRO/$INITRAMFS &
    1.25 +		pack_rootfs $INIT $DISTRO/$INITRAMFS &
    1.26  	else
    1.27  		pack_rootfs . $DISTRO/$(basename $1).gz &
    1.28  	fi
    1.29 @@ -336,14 +337,24 @@
    1.30  	do
    1.31  		sleep 1
    1.32  		if [ "$MODULAR" ]; then
    1.33 -			echo -en "\\033[18G`du -sh $DISTRO/$INITRAMFS.gz | awk '{print $1}'`    "
    1.34 +			echo -en "\\033[18G`du -sh $DISTRO/$INITRAMFS | awk '{print $1}'`    "
    1.35  		else
    1.36  			echo -en "\\033[18G`du -sh $DISTRO/$(basename $1).gz | awk '{print $1}'`    "
    1.37  		fi
    1.38  	done
    1.39  	echo -e "\n"
    1.40  	cd $DISTRO
    1.41 -	mv $(basename $1).gz $ROOTCD/boot
    1.42 +	if [ $MODULAR ]; then
    1.43 +		mv $INITRAMFS $ROOTCD/boot
    1.44 +	else
    1.45 +		mv $(basename $1).gz $ROOTCD/boot
    1.46 +	fi
    1.47 +	if [ $MODULAR ]; then
    1.48 +		if [ $(mount | grep "tmpfs on $ROOTFS" 2>/dev/null) ]; then
    1.49 +			umount $ROOTFS
    1.50 +		fi
    1.51 +	fi
    1.52 +	
    1.53  }
    1.54  
    1.55  distro_sizes()
    1.56 @@ -355,14 +366,26 @@
    1.57  		[ "$div" != 0 ] && min="~ ${div}m"
    1.58  		echo "Build time      : ${sec}s $min"
    1.59  	fi
    1.60 -	cat << EOT
    1.61 -Build date      : $(date +%Y%m%d)
    1.62 -Packages        : $(ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l)
    1.63 -Rootfs size     : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')
    1.64 -Initramfs size  : $(du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }')
    1.65 -ISO image size  : $(du -sh $ISO_NAME.iso | awk '{ print $1 }')
    1.66 -================================================================================
    1.67 -Image is ready: $ISO_NAME.iso
    1.68 +	if [ "$MODULAR" ]; then
    1.69 +		PKGS_NUM=$(ls -1 $ROOTFS/modules/*$INSTALLED/*/receipt | wc -l)
    1.70 +	else
    1.71 +		PKGS_NUM=$(ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l)
    1.72 +	done
    1.73 +	
    1.74 +echo "Build date       : $(date +%Y%m%d)"
    1.75 +if [ "$MODULAR" ]; then
    1.76 +	echo "Modular Packages : $PKGS_NUM"
    1.77 +	echo "Init Packages    : $(ls -1 $INIT*$INSTALLED/*/receipt | wc -l)"
    1.78 +	echo "Rootfs size      : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')"
    1.79 +else
    1.80 +	echo "Packages         : $PKGS_NUM"
    1.81 +	echo "Rootfs size      : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')"
    1.82 +fi
    1.83 +
    1.84 +echo "Initramfs size   : $(du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }')"
    1.85 +echo "ISO image size   : $(du -sh $ISO_NAME.iso | awk '{ print $1 }')"
    1.86 +echo "================================================================================"
    1.87 +echo "Image is ready: $ISO_NAME.iso"
    1.88  
    1.89  EOT
    1.90  }
    1.91 @@ -678,15 +701,20 @@
    1.92  			done
    1.93  	fi
    1.94  	cp $LIST_NAME $DISTRO/$DISTRO_LIST
    1.95 -	sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/$DISTRO_LIST > $DISTRO/list-packages
    1.96 -	cd $PACKAGES_REPOSITORY
    1.97 -	for pkg in $(cat $DISTRO/list-packages)
    1.98 -	do
    1.99 -		echo -n "Installing package: $pkg"
   1.100 -		yes y | tazpkg install $pkg --root=$ROOTFS 2>/dev/null >> $log || exit 1
   1.101 -		status
   1.102 -	done
   1.103 -	rm -f $ROOTFS/$DB/packages.*
   1.104 +	if [ "$MODULAR" ]; then
   1.105 +		union
   1.106 +	else
   1.107 +		sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/$DISTRO_LIST > $DISTRO/list-packages
   1.108 +		cd $PACKAGES_REPOSITORY
   1.109 +		for pkg in $(cat $DISTRO/list-packages)
   1.110 +		do
   1.111 +			echo -n "Installing package: $pkg"
   1.112 +			yes y | tazpkg install $pkg --root=$ROOTFS 2>/dev/null >> $log || exit 1
   1.113 +			status
   1.114 +		done
   1.115 +		rm -f $ROOTFS/$DB/packages.*
   1.116 +	fi
   1.117 +
   1.118  	cd $DISTRO
   1.119  	cp $DISTRO_LIST $ROOTFS/etc/slitaz
   1.120  	# Copy all files from $ADDFILES/rootfs to the rootfs.
   1.121 @@ -702,16 +730,20 @@
   1.122  	status
   1.123  	# Move the boot dir with the Linux kernel from rootfs.
   1.124  	# The boot dir goes directly on the CD.
   1.125 -	if [ -d "$ROOTFS/boot" ] ; then
   1.126 -		echo -n "Moving the boot directory..."
   1.127 -		if [ "$MODULAR" ]; then
   1.128 +	if [ $MODULAR ]; then
   1.129 +		if [ -d "$INIT/boot" ]; then
   1.130 +			echo -n "Moving the boot directory..."
   1.131  			mv $INIT/boot $ROOTCD
   1.132 -		else
   1.133 +			cd $ROOTCD/boot
   1.134 +			ln vmlinuz-* bzImage
   1.135 +			status
   1.136 +		elif [ -d "$ROOTFS/boot" ] ; then
   1.137 +			echo -n "Moving the boot directory..."
   1.138  			mv $ROOTFS/boot $ROOTCD
   1.139 +			cd $ROOTCD/boot
   1.140 +			ln vmlinuz-* bzImage
   1.141 +			status
   1.142  		fi
   1.143 -		cd $ROOTCD/boot
   1.144 -		ln vmlinuz-* bzImage
   1.145 -		status
   1.146  	fi
   1.147  	cd $DISTRO
   1.148  	# Copy all files from $ADDFILES/rootcd to the rootcd.
   1.149 @@ -1510,7 +1542,7 @@
   1.150  		status
   1.151  		echo -n "Installing the Kernel and rootfs..."
   1.152  		cp -a /tmp/iso/boot/bzImage /boot/frugal
   1.153 -		if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
   1.154 +		if [ -f $ROOTCD/boot/rootfs1.gz ]; then
   1.155  			cd /tmp/iso/boot
   1.156  			cat $(ls -r rootfs*.gz) > /boot/frugal/$INITRAMFS
   1.157  		else
   1.158 @@ -1522,12 +1554,12 @@
   1.159  		echo -n "Using distro: $DISTRO"
   1.160  		cd $DISTRO && status
   1.161  		echo -n "Installing the Kernel and rootfs..."
   1.162 -		cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
   1.163 -		if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
   1.164 -			cd $DISTRO/rootcd/boot
   1.165 +		cp -a $ROOTCD/boot/bzImage /boot/frugal
   1.166 +		if [ -f $ROOTCD/boot/rootfs1.gz ]; then
   1.167 +			cd $ROOTCD/boot
   1.168  			cat $(ls -r rootfs*.gz) > /boot/frugal/$INITRAMFS
   1.169  		else
   1.170 -			cp -a $DISTRO/rootcd/boot/$INITRAMFS /boot/frugal
   1.171 +			cp -a $ROOTCD/boot/$INITRAMFS /boot/frugal
   1.172  		fi
   1.173  		status
   1.174  	fi
   1.175 @@ -1538,7 +1570,7 @@
   1.176  title SliTaz GNU/Linux (frugal)
   1.177  root (hd0,0)
   1.178  kernel /boot/frugal/bzImage root=/dev/null
   1.179 -initrd /boot/frugal/rootfs.gz
   1.180 +initrd /boot/frugal/\$INITRAMFS
   1.181  EOT
   1.182  	else
   1.183  		echo -n "GRUB menu list is up-to-date..."
   1.184 @@ -1546,3 +1578,421 @@
   1.185  	status
   1.186  	newline
   1.187  }
   1.188 +
   1.189 +# Check iso for loram transformation
   1.190 +check_iso_for_loram()
   1.191 +{
   1.192 +	[ -s $TMP_DIR/iso/boot/$INITRAMFS ] ||
   1.193 +	[ -s $TMP_DIR/iso/boot/rootfs1.gz ]
   1.194 +}
   1.195 +
   1.196 +# Build initial rootfs for loram ISO ram/cdrom/http
   1.197 +build_initfs()
   1.198 +{
   1.199 +	urliso="mirror.slitaz.org mirror.switch.ch/ftp/mirror/slitaz \
   1.200 +download.tuxfamily.org/slitaz slitaz.c3sl.ufpr.br"
   1.201 +	version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//')
   1.202 +	if [ -z "$version" ]; then
   1.203 +		cat <<EOT
   1.204 +Can't find the kernel version.
   1.205 +No file /boot/vmlinuz-<version> in ISO image.
   1.206 +Abort.
   1.207 +EOT
   1.208 +		exit 1
   1.209 +	fi
   1.210 +	[ -s /usr/share/boot/busybox-static ] || install_package busybox-static
   1.211 +	need_lib=false
   1.212 +	mkdir -p $TMP_DIR/initfs/bin $TMP_DIR/initfs/dev $TMP_DIR/initfs/lib \
   1.213 +		 $TMP_DIR/initfs/mnt $TMP_DIR/initfs/proc $TMP_DIR/initfs/tmp \
   1.214 +		 $TMP_DIR/initfs/sys
   1.215 +	while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz ]; do
   1.216 +		install_package aufs $version || return 1
   1.217 +	done
   1.218 +	# bootfloppybox will need floppy.ko.gz, /dev/fd0, /dev/tty0
   1.219 +	cp /lib/modules/$version/kernel/drivers/block/floppy.ko.gz \
   1.220 +		$TMP_DIR/initfs/lib 2> /dev/null
   1.221 +	cp -a /dev/tty0 /dev/fd0 $TMP_DIR/initfs/dev 2> /dev/null
   1.222 +	cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz \
   1.223 +		$TMP_DIR/initfs/lib
   1.224 +	if [ -f /bin/cromfs-driver ]; then
   1.225 +		cp /bin/cromfs-driver $TMP_DIR/initfs/bin
   1.226 +		ls /bin/unmkcromfs | \
   1.227 +			cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
   1.228 +	else
   1.229 +		[ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
   1.230 +		while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz ]; do
   1.231 +			install_package linux-squashfs $version || return 1
   1.232 +		done
   1.233 +		cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz \
   1.234 +			 $TMP_DIR/initfs/lib
   1.235 +		ls /sbin/unsquashfs /usr/lib/liblzma.so* $INSTALLED/squashfs/* | \
   1.236 +			cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
   1.237 +	fi
   1.238 +	if [ "$1" == "cdrom" ]; then
   1.239 +		for i in $(ls /dev/[hs]d[a-f]*); do
   1.240 +			cp -a $i $TMP_DIR/initfs/dev
   1.241 +		done
   1.242 +	fi
   1.243 +	if [ "$1" == "http" ]; then
   1.244 +		mkdir $TMP_DIR/initfs/etc
   1.245 +		ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
   1.246 +		cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
   1.247 +		sed -i 's|/sbin/||' $TMP_DIR/initfs/lib/udhcpc
   1.248 +		cp -a /dev/fuse $TMP_DIR/initfs/dev
   1.249 +		if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
   1.250 +			cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/httpfs
   1.251 +		else
   1.252 +			cp /usr/bin/fusermount $TMP_DIR/initfs/bin
   1.253 +			need_lib=true
   1.254 +		fi
   1.255 +		if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
   1.256 +			cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
   1.257 +		else
   1.258 +			[ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
   1.259 +			cp /usr/bin/httpfs $TMP_DIR/initfs/bin
   1.260 +			cp -a /lib/librt* $TMP_DIR/initfs/lib
   1.261 +			cp -a /lib/libdl* $TMP_DIR/initfs/lib
   1.262 +			cp -a /lib/libpthread* $TMP_DIR/initfs/lib
   1.263 +			cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
   1.264 +			cp -a /lib/libresolv* $TMP_DIR/initfs/lib
   1.265 +			cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
   1.266 +			need_lib=true
   1.267 +		fi
   1.268 +		cd $TMP_DIR/initfs
   1.269 +		echo "Getting slitaz-release..."
   1.270 +		for i in $TMP_DIR/iso/boot/rootfs*.gz; do
   1.271 +			( zcat $i 2> /dev/null || unlzma -c $i) | \
   1.272 +			cpio -idmu etc/slitaz-release > /dev/null
   1.273 +		done
   1.274 +		cd - > /dev/null
   1.275 +		echo "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"
   1.276 +		echo -n "List of urls to insert: "
   1.277 +		read -t 30 urliso2
   1.278 +		urliso="$urliso2 $urliso"
   1.279 +	fi
   1.280 +	if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
   1.281 +		cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
   1.282 +	else
   1.283 +		cp /bin/busybox $TMP_DIR/initfs/bin
   1.284 +		need_lib=true
   1.285 +	fi
   1.286 +	for i in $($TMP_DIR/initfs/bin/busybox | awk \
   1.287 +	  '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
   1.288 +		ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
   1.289 +	done
   1.290 +	for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \
   1.291 +		 /dev/kmem /dev/mem /dev/random /dev/urandom; do
   1.292 +		cp -a $i $TMP_DIR/initfs/dev
   1.293 +	done
   1.294 +	$need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do
   1.295 +		cp -a $i $TMP_DIR/initfs/lib
   1.296 +	done
   1.297 +	cat > $TMP_DIR/initfs/init <<EOTEOT
   1.298 +#!/bin/sh
   1.299 +
   1.300 +getarg()
   1.301 +{
   1.302 +	grep -q " \$1=" /proc/cmdline || return 1
   1.303 +	eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
   1.304 +	return 0
   1.305 +}
   1.306 +
   1.307 +copy_rootfs()
   1.308 +{
   1.309 +	total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
   1.310 +	need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
   1.311 +	[ \$(( \$total / \$need )) -gt 1 ] || return 1
   1.312 +	if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
   1.313 +		path=/mnt/
   1.314 +		return 0
   1.315 +	else
   1.316 +		rm -f /mnt/rootfs*
   1.317 +		return 1
   1.318 +	fi
   1.319 +}
   1.320 +
   1.321 +echo "Switching / to tmpfs..."
   1.322 +mount -t proc proc /proc
   1.323 +size="\$(grep rootfssize= < /proc/cmdline | \\
   1.324 +	sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
   1.325 +[ -n "\$size" ] || size="-o size=90%"
   1.326 +
   1.327 +if [ -x /bin/httpfs ]; then	# loram-http
   1.328 +
   1.329 +while read var default; do
   1.330 +	eval \$var=\$default
   1.331 +	getarg \$var \$var
   1.332 +done <<EOT
   1.333 +eth	eth0
   1.334 +dns	208.67.222.222,208.67.220.220
   1.335 +netmask	255.255.255.0
   1.336 +gw
   1.337 +ip
   1.338 +EOT
   1.339 +if [ -n "\$ip" ]; then
   1.340 +	ifconfig \$eth \$ip netmask \$netmask up
   1.341 +	route add default gateway \$gw
   1.342 +	for i in \$(echo \$dns | sed 's/,/ /g'); do
   1.343 +		echo "nameserver \$i" >> /etc/resolv.conf
   1.344 +	done
   1.345 +else
   1.346 +	udhcpc -f -q -s /lib/udhcpc -i \$eth
   1.347 +fi
   1.348 +for i in $urliso ; do
   1.349 +	[ -n "\$URLISO" ] && URLISO="\$URLISO,"
   1.350 +	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"
   1.351 +done
   1.352 +getarg urliso URLISO
   1.353 +DIR=fs
   1.354 +if getarg loram DIR; then
   1.355 +	DEVICE=\${DIR%,*}
   1.356 +	DIR=/\${DIR#*,}
   1.357 +fi
   1.358 +mount -t tmpfs \$size tmpfs /mnt
   1.359 +path2=/mnt/.httpfs/
   1.360 +path=/mnt/.cdrom/
   1.361 +mkdir -p /mnt/.rw \$path \$path2
   1.362 +while [ ! -d \$path/boot ]; do
   1.363 +	for i in \$(echo \$URLISO | sed 's/,/ /g'); do
   1.364 +		httpfs \$i \$path2 && break
   1.365 +	done
   1.366 +	mount -o loop,ro -t iso9660 \$path2/*.iso \$path
   1.367 +done
   1.368 +#copy_rootfs && umount -d \$path && umount -d \$path2
   1.369 +
   1.370 +elif [ -f \$(echo /rootfs*.gz | cut -f1 -d' ') ]; then	# loram-ram
   1.371 +
   1.372 +total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
   1.373 +free=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
   1.374 +if [ \$(( \$total/\$free )) -gt 1 ] || ! mount -t tmpfs \$size tmpfs /mnt; then
   1.375 +	echo "No tmpfs for /mnt"
   1.376 +	mkdir -p /mnt/.rw
   1.377 +	mount -t tmpfs tmpfs /mnt/.rw
   1.378 +	mkdir -p /mnt/.rw/mnt/.rw
   1.379 +	path=/
   1.380 +else
   1.381 +	mkdir -p /mnt/.rw
   1.382 +	path=/mnt/.
   1.383 +	for i in rootfs* ; do
   1.384 +		mv /\$i \$path\$i
   1.385 +	done
   1.386 +fi
   1.387 +
   1.388 +else				# loram-cdrom
   1.389 +
   1.390 +getarg cdrom DRIVE_NAME ||
   1.391 +DRIVE_NAME=\$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
   1.392 +DEVICE=/dev/\$DRIVE_NAME
   1.393 +DIR=fs
   1.394 +if getarg loram DIR; then
   1.395 +	DEVICE=\${DIR%,*}
   1.396 +	DIR=/\${DIR#*,}
   1.397 +fi
   1.398 +mount -t tmpfs \$size tmpfs /mnt
   1.399 +mkdir -p /mnt/.rw /mnt/.cdrom /mnt/mnt/.cdrom
   1.400 +i=0
   1.401 +while [ \$i -lt 5 ] && ! mount -r \$DEVICE /mnt/.cdrom; do
   1.402 +	case "\$DEVICE" in
   1.403 +	/dev/sd*|UUID=*|LABEL=*)
   1.404 +		mount -t sysfs sysfs /sys
   1.405 +		USBDELAY=\$(cat /sys/module/usb_storage/parameters/delay_use)
   1.406 +		umount /sys
   1.407 +		sleep \$((1+\$USBDELAY)) ;;
   1.408 +	esac
   1.409 +	i=\$((i+1))
   1.410 +done
   1.411 +path=/mnt/.cdrom/
   1.412 +copy_rootfs && umount -d /mnt/.cdrom
   1.413 +
   1.414 +fi
   1.415 +
   1.416 +memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
   1.417 +umount /proc
   1.418 +branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR
   1.419 +if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
   1.420 +branch=br=/mnt/.rw
   1.421 +for i in \${path}rootfs* ; do
   1.422 +	fs=\${i#*root}
   1.423 +	branch=\$branch:/mnt/.\$fs
   1.424 +	mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
   1.425 +	if [ -f /bin/cromfs-driver ]; then
   1.426 +		cromfs-driver \${path}root\$fs /mnt/.\$fs -o ro,dev,suid,allow_other
   1.427 +	else
   1.428 +		insmod /lib/squashfs.ko.gz 2> /dev/null
   1.429 +		mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs
   1.430 +	fi
   1.431 +done
   1.432 +else
   1.433 +mkdir -p /mnt/.rw/mnt/.httpfs
   1.434 +fi
   1.435 +insmod /lib/aufs.ko.gz
   1.436 +mount -t aufs -o \$branch none /mnt
   1.437 +[ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
   1.438 +[ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
   1.439 +[ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
   1.440 +EOTEOT
   1.441 +	chmod +x $TMP_DIR/initfs/init
   1.442 +	( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
   1.443 +	lzma e $TMP_DIR/initfs.gz -si
   1.444 +	lzma_set_size $TMP_DIR/initfs.gz
   1.445 +	rm -rf $TMP_DIR/initfs
   1.446 +	rem=$(( $(stat -c "%s" $TMP_DIR/initfs.gz) % 4 ))
   1.447 +	[ $rem -ne 0 ] &&
   1.448 +	dd if=/dev/zero bs=1 count=$(( 4 - $rem )) >> $TMP_DIR/initfs.gz 2> /dev/null
   1.449 +	return 0
   1.450 +}
   1.451 +
   1.452 +# Move each initramfs to squashfs (or cromfs)
   1.453 +build_loram_rootfs_cdrom()
   1.454 +{
   1.455 +	mkdir -p $TMP_DIR/fs
   1.456 +	cd $TMP_DIR/fs
   1.457 +	for i in $(ls -r $TMP_DIR/iso/boot/rootfs*.gz); do
   1.458 +		( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idmu
   1.459 +	done
   1.460 +	rootfs=$TMP_DIR/$INITRAMFS
   1.461 +	if [ -x /usr/bin/mkcromfs ]; then
   1.462 +		/usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
   1.463 +	else
   1.464 +		/usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
   1.465 +	fi
   1.466 +	rm -rf $TMP_DIR/fs
   1.467 +	cd - > /dev/null
   1.468 +}
   1.469 +
   1.470 +# Move meta boot configuration files to basic configuration files
   1.471 +# because meta loram flavor is useless when rootfs is not loaded in ram
   1.472 +unmeta_boot()
   1.473 +{
   1.474 +	local root=${1:-$TMP_DIR/loramiso}
   1.475 +	if [ -f $root/boot/isolinux/noram.cfg ]; then
   1.476 +		# We keep enough information to do unloram...
   1.477 +		[ -s $root/boot/isolinux/common.cfg ] &&
   1.478 +		sed -i 's/label slitaz/label orgslitaz/' \
   1.479 +			$root/boot/isolinux/common.cfg
   1.480 +		set -- $(grep 'append ifmem [0-9]' $root/boot/isolinux/isolinux.cfg)
   1.481 +		shift
   1.482 +		sed -i '/ifmem/{NNNNNNNNd};/^LABEL/{N;/LABEL SliTaz [^L]/{NNNd}}' \
   1.483 +			$root/boot/isolinux/isolinux.cfg
   1.484 +		[ -n "$3" ] || set -- $(grep 'append [0-9]' $root/boot/isolinux/common.cfg)
   1.485 +		sed -i "s/label $3\$/label slitaz/;s|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |" \
   1.486 +			$root/boot/isolinux/*.cfg
   1.487 +	fi
   1.488 +}
   1.489 +
   1.490 +# Move each initramfs to squashfs (or cromfs)
   1.491 +build_loram_rootfs()
   1.492 +{
   1.493 +	rootfs_sizes=""
   1.494 +	for i in $TMP_DIR/iso/boot/rootfs*.gz; do
   1.495 +		mkdir -p $TMP_DIR/fs
   1.496 +		cd $TMP_DIR/fs
   1.497 +		( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
   1.498 +		cd - > /dev/null
   1.499 +		rootfs=$TMP_DIR/$(basename $i)
   1.500 +		if [ -x /usr/bin/mkcromfs ]; then
   1.501 +			/usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
   1.502 +		else
   1.503 +			/usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
   1.504 +		fi
   1.505 +		cd $TMP_DIR
   1.506 +		rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
   1.507 +		( cd $(dirname $rootfs); echo $(basename $rootfs) | \
   1.508 +			  cpio -o -H newc ) > $rootfs.cpio
   1.509 +		rm -f $rootfs
   1.510 +		mv $rootfs.cpio $rootfs
   1.511 +		cd - > /dev/null
   1.512 +		rm -rf $TMP_DIR/fs
   1.513 +	done
   1.514 +}
   1.515 +
   1.516 +# Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
   1.517 +# These squashfs may be loaded in ram a boot time.
   1.518 +# Rootfs are also copied to cdrom for tiny ramsize systems.
   1.519 +# Meta flavors are converted to normal flavors.
   1.520 +build_loram_cdrom()
   1.521 +{
   1.522 +	build_initfs cdrom || return 1
   1.523 +	build_loram_rootfs_cdrom
   1.524 +	cp -a $TMP_DIR/iso $TMP_DIR/loramiso
   1.525 +	if [ "$1" == "small" ]; then
   1.526 +		rm -f $TMP_DIR/loramiso/boot/root*
   1.527 +	else
   1.528 +		mkdir $TMP_DIR/loramiso/fs
   1.529 +		cd $TMP_DIR/loramiso/fs
   1.530 +		for i in $( ls ../boot/root* | sort -r ) ; do
   1.531 +			( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
   1.532 +			rm -f $i
   1.533 +		done
   1.534 +		mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
   1.535 +		cd - > /dev/null
   1.536 +	fi
   1.537 +	mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/$INITRAMFS
   1.538 +	mv $TMP_DIR/rootfs*.gz $TMP_DIR/loramiso
   1.539 +	unmeta_boot
   1.540 +	VOLUM_NAME="SliTaz_LoRAM_CDROM"
   1.541 +	sed -i "s/root=/loram=LABEL=$VOLUM_NAME,fs &/" \
   1.542 +		$TMP_DIR/loramiso/boot/isolinux/*.cfg
   1.543 +	create_iso $OUTPUT $TMP_DIR/loramiso
   1.544 +}
   1.545 +
   1.546 +# Create http bootstrap to load and remove loram_cdrom
   1.547 +# Meta flavors are converted to normal flavors.
   1.548 +build_loram_http()
   1.549 +{
   1.550 +	build_initfs http || return 1
   1.551 +	cp -a $TMP_DIR/iso $TMP_DIR/loramiso
   1.552 +	rm -f $TMP_DIR/loramiso/boot/rootfs*
   1.553 +	mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/$INITRAMFS
   1.554 +	unmeta_boot
   1.555 +	create_iso $OUTPUT $TMP_DIR/loramiso
   1.556 +}
   1.557 +
   1.558 +# Update meta flavor selection sizes.
   1.559 +# Reduce sizes with rootfs gains.
   1.560 +update_metaiso_sizes()
   1.561 +{
   1.562 +	for cfg in $(grep -El '(append|ifmem) [0-9]' $TMP_DIR/loramiso/boot/isolinux/*.cfg)
   1.563 +	do
   1.564 +		local append="$(grep -E '(append|ifmem) [0-9]' $cfg)"
   1.565 +		local sizes="$rootfs_sizes"
   1.566 +		local new
   1.567 +		set -- $append
   1.568 +		shift
   1.569 +		[ "$1" == "ifmem" ] && shift
   1.570 +		new=""
   1.571 +		while [ -n "$2" ]; do
   1.572 +			local s
   1.573 +			case "$1" in
   1.574 +			*G) s=$(( ${1%G} * 1024 * 1024 ));;
   1.575 +			*M) s=$(( ${1%M} * 1024 ));;
   1.576 +			*)  s=${1%K};;
   1.577 +			esac
   1.578 +			sizes=${sizes#* }
   1.579 +			for i in $sizes ; do
   1.580 +				s=$(( $s - $i ))
   1.581 +			done
   1.582 +			new="$new $s $2"
   1.583 +			shift 2
   1.584 +		done
   1.585 +		sed -i -e "/append [0-9]/s/append .*/append$new $1/" -e \
   1.586 +			"/append ifmem [0-9]/s/append .*/append ifmem$new $1/" $cfg
   1.587 +	done
   1.588 +}
   1.589 +
   1.590 +# Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
   1.591 +# Meta flavor selection sizes are updated.
   1.592 +build_loram_ram()
   1.593 +{
   1.594 +	build_initfs ram || return 1
   1.595 +	build_loram_rootfs
   1.596 +	cp -a $TMP_DIR/iso $TMP_DIR/loramiso
   1.597 +	rm -f $TMP_DIR/loramiso/boot/bzImage
   1.598 +	ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
   1.599 +	rootfs=$(ls $TMP_DIR/rootfs* | sort | tail -n 1)
   1.600 +	cat $rootfs >> $TMP_DIR/initfs.gz
   1.601 +	mv $TMP_DIR/initfs.gz $rootfs
   1.602 +	cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
   1.603 +	update_metaiso_sizes
   1.604 +	create_iso $OUTPUT $TMP_DIR/loramiso
   1.605 +}
     2.1 --- a/lib/libmodular.sh	Sun Sep 23 09:34:59 2012 +0000
     2.2 +++ b/lib/libmodular.sh	Sun Sep 23 09:35:49 2012 +0000
     2.3 @@ -6,7 +6,8 @@
     2.4  UNION=$ROOTFS/union
     2.5  LASTBR=$INIT
     2.6  MODULES_DIR=$ROOTFS/modules
     2.7 -SGNFILE=$ROOTC/${CDNAME}/livecd.sgn
     2.8 +CDNAME="slitaz"
     2.9 +SGNFILE=$ROOTCD/${CDNAME}/livecd.sgn
    2.10  KEY_FILES="init liblinuxlive linuxrc"
    2.11  
    2.12  error () { echo -e "\033[1;31;40m!!! \033[1;37;40m$@\033[1;0m"; }
    2.13 @@ -16,7 +17,7 @@
    2.14  initramfs () {
    2.15  
    2.16  	FLAVOR=${1%.flavor}
    2.17 -	if [ -s "$FLAVORS_REPOSITORY/$FLAVOR/receipt" ]; then
    2.18 +	if [ ! -f "$FLAVORS_REPOSITORY/$FLAVOR/receipt" ]; then
    2.19  		error "error: $FLAVORS_REPOSITORY/$FLAVOR/receipt doesn't exist, aborting."
    2.20  		exit 1
    2.21  	fi
    2.22 @@ -33,7 +34,7 @@
    2.23  	[ -f $LOG/initramfs.log ] && rm -f $LOG/initramfs.log
    2.24  	cat "$FLAVORS_REPOSITORY/$FLAVOR/packages.list" | grep -v "^#" | while read pkgname; do
    2.25  		if [ ! -f ${INIT}${INSTALLED}/${pkgname}/files.list ]; then
    2.26 -			tazpkg get-install $pkgname --root=$INIT 2>&1 | tee -a $LOG/initramfs.log
    2.27 +			tazpkg get-install $pkgname --root=$INIT 2>/dev/null | tee -a $LOG/initramfs.log
    2.28  			sleep 1
    2.29  		else
    2.30  			info "${pkgname} installed" | tee -a $LOG/initramfs.log
    2.31 @@ -63,7 +64,7 @@
    2.32  			[ -f ${LOG}/${mod}-current.log ] && rm -f ${LOG}/${mod}-current.log
    2.33  			cat "$FLAVORS_REPOSITORY/${mod}/packages.list" | grep -v "^#" | while read pkgname; do
    2.34  				if [ ! -f ${UNION}${INSTALLED}/${pkgname}/files.list ]; then
    2.35 -					tazpkg get-install $pkgname --root=${UNION} 2>&1 | tee -a ${LOG}/${mod}-current.log
    2.36 +					tazpkg get-install $pkgname --root=${UNION} | tee -a ${LOG}/${mod}-current.log
    2.37  					sleep 1
    2.38  				else
    2.39  					info "${pkgname} installed" | tee -a ${LOG}/${mod}-current.log
    2.40 @@ -98,7 +99,7 @@
    2.41  		error "Error loading Union filesystem module. (aufs)"
    2.42  		exit 1
    2.43  	fi
    2.44 -	
    2.45 +
    2.46  	# $INIT is now $LASTBR
    2.47  	# This will be copyed to /mnt/memory/changes on boot
    2.48  	initramfs init-modular