cookutils view lib/libcookiso.sh @ rev 543
libcookiso.sh: Add some more comments.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Mon Oct 15 16:28:45 2012 +0000 (2012-10-15) |
parents | d1f57160b838 |
children | 3974b72eb580 |
line source
1 #!/bin/sh
3 # libcookiso functions
5 . /usr/lib/slitaz/libcook.sh
6 . /usr/lib/slitaz/libmodular.sh
8 TOP_DIR="$(pwd)"
9 TMP_DIR=/tmp/cookiso-$$-$RANDOM
10 TMP_MNT=/media/cookiso-$$-$RANDOM
11 INITRAMFS=rootfs.gz
12 MIRROR=$DB/mirror
13 [ -f "/etc/slitaz/cookiso.conf" ] && CONFIG_FILE="/etc/slitaz/cookiso.conf"
14 [ -f "$TOP_DIR/cookiso.conf" ] && CONFIG_FILE="$TOP_DIR/cookiso.conf"
15 DEFAULT_MIRROR="$MIRROR_URL/packages/$SLITAZ_VERSION/"
17 log=/var/log/cookiso.log
18 if check_root; then
19 newline > $log
20 fi
22 if [ ! "$CONFIG_FILE" = "" ] ; then
23 . $CONFIG_FILE
24 else
25 if [ "$COMMAND" = "gen-config" ] ; then
26 continue
27 else
28 echo "Unable to find any configuration file. Please read the docs"
29 echo "or run '`basename $0` gen-config' to get an empty config file."
30 exit 0
31 fi
32 fi
34 # While Tazpkg is not used the default mirror url file does not exist
35 # and user can't recharge the list of flavors.
36 if test $(id -u) = 0 ; then
37 if [ ! -f "$MIRROR" ]; then
38 echo "$DEFAULT_MIRROR" > $MIRROR
39 fi
40 fi
43 yesorno()
44 {
45 echo -n "$1"
46 case "$DEFAULT_ANSWER" in
47 Y|y) answer="y";;
48 N|n) answer="n";;
49 *) read answer;;
50 esac
51 }
53 field()
54 {
55 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
56 }
58 todomsg()
59 {
60 echo -e "\\033[70G[ \\033[1;31mTODO\\033[0;39m ]"
61 }
63 # Download a file from this mirror
64 download_from()
65 {
66 local i
67 local mirrors
68 mirrors="$1"
69 shift
70 for i in $mirrors; do
71 case "$i" in
72 http://*|ftp://*) wget -c $i$@ && break;;
73 *) cp $i/$1 . && break;;
74 esac
75 done
76 }
78 # Download a file trying all mirrors
79 download()
80 {
81 local i
82 for i in $(cat $MIRROR $DB/undigest/*/mirror 2> /dev/null); do
83 download_from "$i" "$@" && break
84 done
85 }
87 # Execute hooks provided by some packages
88 genisohooks()
89 {
90 local here=$(pwd)
91 for i in $(ls $ROOTFS/etc/slitaz/*.$1 2> /dev/null); do
92 cd $ROOTFS
93 . $i $ROOTCD
94 done
95 cd $here
96 }
98 # clean up TMP_MNT folder
99 cleanup()
100 {
101 if [ -d $TMP_MNT ]; then
102 umount $TMP_MNT
103 rmdir $TMP_MNT
104 rm -f /boot
105 fi
106 }
108 # Echo the package name if the tazpkg is already installed
109 installed_package_name()
110 {
111 local tazpkg
112 local package
113 local VERSION
114 local EXTRAVERSION
115 tazpkg=$1
116 # Try to find package name and version to be able
117 # to repack it from installation
118 # A dash (-) can exist in name *and* in version
119 package=${tazpkg%-*}
120 i=$package
121 while true; do
122 VERSION=""
123 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
124 unset EXTRAVERSION
125 eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
126 if [ "$i-$VERSION$EXTRAVERSION" = "$tazpkg" ]; then
127 echo $i
128 break
129 fi
130 case "$i" in
131 *-*);;
132 *) break;;
133 esac
134 i=${i%-*}
135 done
136 }
139 # Check for the rootfs tree.
140 check_rootfs()
141 {
142 if [ ! -d "$ROOTFS/etc" ] ; then
143 echo -e "\nUnable to find a distro rootfs...\n"
144 exit 0
145 fi
146 }
148 # Check for the boot dir into the root CD tree.
149 verify_rootcd()
150 {
151 if [ ! -d "$ROOTCD/boot" ] ; then
152 echo -e "\nUnable to find the rootcd boot directory...\n"
153 exit 0
154 fi
155 }
157 create_iso()
158 {
159 cd $2
160 echo -n "Computing $SUM..."
161 find * -type f ! -name $CHECKSUM -exec $CHECKSUM {} \; > $CHECKSUM
162 sed -i -e '/ boot\/isolinux\/isolinux.bin$/d' \
163 -e '/ boot\/isolinux\/boot.cat$/d' $CHECKSUM
164 status
165 cd - > /dev/null
166 newline
167 echo -e "\033[1mGenerating ISO image\033[0m"
168 separator
169 echo "Generating $1"
170 if [ $(ls $2/boot/vmlinuz* $2/boot/bzImage | wc -l) -eq 2 ]; then
171 if cmp $2/boot/vmlinuz* $2/boot/bzImage > /dev/null; then
172 rm -f $2/boot/bzImage
173 ln $2/boot/vmlinuz* $2/boot/bzImage
174 fi
175 fi
176 genisoimage -R -o $1 -b boot/isolinux/isolinux.bin \
177 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
178 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
179 -boot-info-table $2
180 if [ -x /usr/bin/isohybrid ]; then
181 echo -n "Creating hybrid ISO..."
182 /usr/bin/isohybrid $1 -entry 2 2> /dev/null
183 status
184 fi
185 if [ -s /etc/slitaz/info ]; then
186 if [ $(stat -c %s /etc/slitaz/info) -lt $(( 31*1024 )) ]; then
187 echo -n "Storing ISO info..."
188 dd if=/etc/slitaz/info bs=1k seek=1 of=$1 \
189 conv=notrunc 2> /dev/null
190 status
191 fi
192 fi
193 }
195 # Generate a new ISO image using isolinux.
196 gen_livecd_isolinux()
197 {
198 # Some packages may want to alter iso
199 genisohooks iso
200 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
201 echo -e "\nUnable to find isolinux binary.\n"
202 cleanup
203 exit 0
204 fi
205 # Set date for boot msg.
206 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.*g; then
207 DATE=`date +%Y%m%d`
208 echo -n "Setting build date to: $DATE..."
209 sed -i "s/XXXXXXXX/$DATE/" $ROOTCD/boot/isolinux/isolinux.*g
210 status
211 fi
212 cd $DISTRO
213 create_iso $ISO_NAME.iso $ROOTCD
214 echo -n "Creating the ISO $CHECKSUM..."
215 $CHECKSUM $ISO_NAME.iso > $ISO_NAME.$SUM
216 status
217 separator
218 # Some packages may want to alter final iso
219 genisohooks final
220 }
222 lzma_history_bits()
223 {
224 #
225 # This generates an ISO which boots with Qemu but gives
226 # rootfs errors in frugal or liveUSB mode.
227 #
228 #local n
229 #local sz
230 #n=20 # 1Mb
231 #sz=$(du -sk $1 | cut -f1)
232 #while [ $sz -gt 1024 -a $n -lt 28 ]; do
233 #n=$(( $n + 1 ))
234 #sz=$(( $sz / 2 ))
235 #done
236 #echo $n
237 echo 24
238 }
240 lzma_switches()
241 {
242 local proc=$(grep -s '^processor' < /proc/cpuinfo | wc -l)
243 echo "-d$(lzma_history_bits $1) -mt${proc:-1}"
244 }
246 lzma_set_size()
247 {
248 # Update size field for lzma'd file packed using -si switch
249 local n
250 local i
251 return # Need to fix kernel code ?
252 n=$(unlzma -c $1 | wc -c)
253 for i in $(seq 1 8); do
254 printf '\\\\x%02X' $(($n & 255))
255 n=$(($n >> 8))
256 done | xargs echo -en | dd of=$1 conv=notrunc bs=1 seek=5 2> /dev/null
257 }
259 # Pack rootfs
260 pack_rootfs()
261 {
262 ( cd $1 ; find . -print | cpio -o -H newc ) | \
263 if [ "$COMPRESSION" = "none" ]; then
264 echo "Generating uncompressed initramfs... "
265 cat > $2
266 elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then
267 echo -n "Generating lzma'ed initramfs... "
268 lzma e -si -so $(lzma_switches $1) > $2
269 lzma_set_size $2
270 else
271 echo "Generating gziped initramfs... "
272 gzip -9 > $2
273 fi
274 echo 1 > /tmp/rootfs
275 }
277 # Compression functions for writeiso.
278 write_initramfs()
279 {
280 if [ "$COMPRESSION" = "lzma" ]; then
281 echo -n "Creating $INITRAMFS with lzma compression... "
282 cat /tmp/list | cpio -o -H newc | lzma e -si -so > /$INITRAMFS
283 lzma_set_size /$INITRAMFS
284 elif [ "$COMPRESSION" = "gzip" ]; then
285 echo "Creating $INITRAMFS with gzip compression... "
286 cat /tmp/list | cpio -o -H newc | gzip -9 > /$INITRAMFS
287 else
288 echo "Creating $INITRAMFS without compression... "
289 cat /tmp/list | cpio -o -H newc > /$INITRAMFS
290 fi
291 echo 1 > /tmp/rootfs
292 }
295 # Deduplicate files (MUST be on the same filesystem).
296 deduplicate()
297 {
298 find "$@" -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
299 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
300 while read attr inode link file; do
301 [ -L "$file" ] && continue
302 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
303 if cmp "$file" "$old_file" >/dev/null 2>&1 ; then
304 rm -f "$file"
305 ln "$old_file" "$file"
306 inode="$old_inode"
307 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
308 fi
309 fi
310 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
311 done
312 echo "$save bytes saved in duplicate files."
313 )
314 }
316 # Generate a new initramfs from the root filesystem.
317 gen_initramfs()
318 {
319 # Just in case CTRL+c
320 rm -f $DISTRO/gen
322 # Some packages may want to alter rootfs
323 genisohooks rootfs
324 cd $1
326 # Link duplicate files
327 deduplicate .
329 # Use lzma if installed. Display rootfs size in realtime.
330 rm -f /tmp/rootfs
331 if [ "$MODULAR" ]; then
332 pack_rootfs $INIT $DISTRO/$INITRAMFS &
333 else
334 pack_rootfs . $DISTRO/$(basename $1).gz &
335 fi
336 sleep 2
337 echo -en "\nFilesystem size:"
338 while [ ! -f /tmp/rootfs ]
339 do
340 sleep 1
341 if [ "$MODULAR" ]; then
342 echo -en "\\033[18G`du -sh $DISTRO/$INITRAMFS | awk '{print $1}'` "
343 else
344 echo -en "\\033[18G`du -sh $DISTRO/$(basename $1).gz | awk '{print $1}'` "
345 fi
346 done
347 echo -e "\n"
348 cd $DISTRO
349 if [ $MODULAR ]; then
350 mv $INITRAMFS $ROOTCD/boot
351 else
352 mv $(basename $1).gz $ROOTCD/boot
353 fi
354 if [ $MODULAR ]; then
355 if [ $(mount | grep "tmpfs on $ROOTFS" 2>/dev/null) ]; then
356 umount $ROOTFS
357 fi
358 fi
360 }
362 # find out the distro size and number of packages
363 distro_sizes()
364 {
365 if [ "$time" ]; then
366 time=$(($(date +%s) - $time))
367 sec=$time
368 div=$(( ($time + 30) / 60))
369 [ "$div" != 0 ] && min="~ ${div}m"
370 echo "Build time : ${sec}s $min"
371 fi
372 if [ "$MODULAR" ]; then
373 PKGS_NUM=$(ls -1 $ROOTFS/modules/*$INSTALLED/*/receipt | wc -l)
374 else
375 PKGS_NUM=$(ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l)
376 fi
378 echo "Build date : $(date +%Y%m%d)"
379 if [ "$MODULAR" ]; then
380 echo "Modular Packages : $PKGS_NUM"
381 echo "Init Packages : $(ls -1 $INIT*$INSTALLED/*/receipt | wc -l)"
382 echo "Rootfs size : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')"
383 else
384 echo "Packages : $PKGS_NUM"
385 echo "Rootfs size : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')"
386 fi
388 echo "Initramfs size : $(du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }')"
389 echo "ISO image size : $(du -sh $ISO_NAME.iso | awk '{ print $1 }')"
390 echo "================================================================================"
391 echo "Image is ready: $ISO_NAME.iso"
392 }
394 # Print ISO and rootfs size.
395 distro_stats()
396 {
397 newline
398 echo -e "\033[1mDistro statistics\033[0m ($DISTRO)"
399 separator
400 distro_sizes
401 }
403 # Create an empty configuration file.
404 empty_config_file()
405 {
406 cat >> cookiso.conf << "EOF"
407 # cookiso.conf: cookiso (SliTaz Live Tool)
408 # configuration file.
409 #
411 # Name of the ISO image to generate.
412 ISO_NAME=""
414 # ISO image volume name.
415 VOLUM_NAME="SliTaz"
417 # Name of the preparer.
418 PREPARED="$USER"
420 # Path to the packages repository and the packages.list.
421 PACKAGES_REPOSITORY=""
423 # Path to the distro tree to gen-distro from a
424 # list of packages.
425 DISTRO=""
427 # Path to the directory containing additional files
428 # to copy into the rootfs and rootcd of the LiveCD.
429 ADDFILES="$DISTRO/addfiles"
431 # Default answer for binary question (Y or N)
432 DEFAULT_ANSWER="ASK"
434 # Compression utility (lzma, gzip or none)
435 COMPRESSION="lzma"
436 EOF
437 }
439 # Display package list with version, set packed_size and unpacked_size
440 get_pkglist()
441 {
442 packed_size=0; unpacked_size=0
443 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
444 while read pkg; do
445 set -- $(get_size $pkg)
446 packed_size=$(( $packed_size + $1 ))
447 unpacked_size=$(( $unpacked_size + $2 ))
448 for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \
449 $TMP_DIR/packages.list); do
450 echo $i
451 break
452 done
453 done < $TMP_DIR/flavor.pkg
454 rm -f $TMP_DIR/flavor.pkg
455 }
457 human2cent()
458 {
459 case "$1" in
460 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
461 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
462 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
463 esac
464 }
466 cent2human()
467 {
468 if [ $1 -lt 10000 ]; then
469 echo "$(($1 / 10)).$(($1 % 10))k"
470 elif [ $1 -lt 10000000 ]; then
471 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
472 else
473 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
474 fi
475 }
477 # get size based on package list
478 get_size()
479 {
480 cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
481 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
482 if (/installed/ && get == 1) { print ; get++ } \
483 }
484 END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \
485 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
486 echo "$(human2cent $packed) $(human2cent $unpacked)"
487 done
488 }
490 # extract rootfs.gz somewhere
491 extract_rootfs()
492 {
493 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
494 (cd $2; cpio -idm > /dev/null)
495 }
497 # Remove duplicate files
498 mergefs()
499 {
500 echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
501 echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
502 # merge symlinks files and devices
503 ( cd $1; find ) | while read file; do
504 if [ -L $1/$file ]; then
505 [ -L $2/$file ] &&
506 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
507 rm -f $2/$file
508 elif [ -f $1/$file ]; then
509 [ -f $2/$file ] &&
510 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
511 [ -f $2/$file ] &&
512 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
513 [ "$(dirname $(dirname $file))" == \
514 ".$INSTALLED" ] && rm -f $2/$file
515 elif [ -b $1/$file ]; then
516 [ -b $2/$file ] &&
517 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
518 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
519 rm -f $2/$file
520 elif [ -c $1/$file ]; then
521 [ -c $2/$file ] &&
522 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
523 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
524 rm -f $2/$file
525 fi
526 done
528 # cleanup directories
529 ( cd $1; find -type d ) | sed '1!G;h;$!d' | while read file; do
530 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
531 done
532 true
533 status
534 }
536 # cleanup merge
537 cleanup_merge()
538 {
539 rm -rf $TMP_DIR
540 exit 1
541 }
543 # tazlito gen-distro
544 gen_distro()
545 {
546 check_root
547 time=$(date +%s)
549 # Check if a package list was specified on cmdline.
550 DISTRO_LIST="distro-packages.list"
551 LIST_NAME="$DISTRO_LIST"
552 unset CDROM
553 while [ -n "$1" ]; do
554 case "$1" in
555 --iso=*)
556 CDROM="-o loop ${2#--iso=}"
557 ;;
558 --cdrom)
559 CDROM="/dev/cdrom"
560 ;;
561 --force)
562 DELETE_ROOTFS="true"
563 ;;
564 *) if [ ! -f "$1" ] ; then
565 echo -e "\nUnable to find the specified packages list."
566 echo -e "List name : $1\n"
567 exit 1
568 fi
569 LIST_NAME=$1
570 ;;
571 esac
572 shift
573 done
575 if [ -d $ROOTFS ] ; then
576 # Delete $ROOTFS if --force is set on command line
577 if [ ! -z $DELETE_ROOTFS ]; then
578 rm -rf $ROOTFS
579 unset $DELETE_ROOTFS
580 else
581 echo -e "\nA rootfs exists in : $DISTRO"
582 echo -e "Please clean the distro tree or change directory path.\n"
583 exit 0
584 fi
585 fi
586 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
587 # Build list with installed packages
588 for i in $(ls $INSTALLED); do
589 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
590 EXTRAVERSION=""
591 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
592 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
593 done
594 fi
595 # Exit if no list name.
596 if [ ! -f "$LIST_NAME" ]; then
597 echo -e "\nNo packages list found or specified. Please read the docs.\n"
598 exit 0
599 fi
600 # Start generation.
601 newline
602 echo -e "\033[1mGenerating a distro\033[0m"
603 separator
604 # Misc checks
605 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
606 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
607 # Get the list of packages using cat for a file list.
608 LIST=$(cat $LIST_NAME)
609 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
610 unset REPACK DOWNLOAD
611 for pkg in $LIST
612 do
613 [ "$pkg" = "" ] && continue
614 pkg=${pkg%.tazpkg}
615 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
616 PACKAGE=$(installed_package_name $pkg)
617 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
618 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
619 echo -e "\nUnable to find $pkg in the repository."
620 echo -e "Path : $PACKAGES_REPOSITORY\n"
621 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
622 yesorno "Repack packages from rootfs (y/N) ? "
623 REPACK="$answer"
624 [ "$answer" = "y" ] || REPACK="n"
625 [ "$DOWNLOAD" = "y" ] && break
626 fi
627 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
628 yesorno "Download packages from mirror (Y/n) ? "
629 DOWNLOAD="$answer"
630 if [ "$answer" = "n" ]; then
631 [ -z "$PACKAGE" ] && exit 1
632 else
633 DOWNLOAD="y"
634 [ -n "$REPACK" ] && break
635 fi
636 fi
637 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
638 done
640 # Mount cdrom to be able to repack boot-loader packages
641 if [ ! -e /boot -a -n "$CDROM" ]; then
642 mkdir $TMP_MNT
643 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
644 ln -s $TMP_MNT/boot /
645 if [ ! -d "$ADDFILES/rootcd" ] ; then
646 mkdir -p $ADDFILES/rootcd
647 for i in $(ls $TMP_MNT); do
648 [ "$i" = "boot" ] && continue
649 cp -a $TMP_MNT/$i $ADDFILES/rootcd
650 done
651 fi
652 else
653 rmdir $TMP_MNT
654 fi
655 fi
657 # Root fs stuff.
658 echo "Preparing the rootfs directory..."
659 mkdir -p $ROOTFS
660 for pkg in $LIST
661 do
662 [ "$pkg" = "" ] && continue
663 # First copy and extract the package in tmp dir.
664 pkg=${pkg%.tazpkg}
665 PACKAGE=$(installed_package_name $pkg)
666 mkdir -p $TMP_DIR
667 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
668 # Look for package in cache
669 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
670 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
671 # Look for package in running distribution
672 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
673 tazpkg repack $PACKAGE && \
674 mv $pkg.tazpkg $PACKAGES_REPOSITORY
675 fi
676 fi
677 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
678 # Get package from mirror
679 [ "$DOWNLOAD" = "y" ] && \
680 download $pkg.tazpkg && \
681 mv $pkg.tazpkg $PACKAGES_REPOSITORY
682 fi
683 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
684 echo "Missing package $pkg."
685 cleanup
686 exit 1
687 fi
688 done
689 if [ -f non-free.list ]; then
690 echo "Preparing non-free packages..."
691 cp non-free.list $ROOTFS/etc/slitaz/non-free.list
692 for pkg in $(cat non-free.list); do
693 if [ ! -d $INSTALLED/$pkg ]; then
694 if [ ! -d $INSTALLED/get-$pkg ]; then
695 tazpkg get-install get-$pkg
696 fi
697 get-$pkg
698 fi
699 tazpkg repack $pkg
700 pkg=$(ls $pkg*.tazpkg)
701 grep -q "^$pkg$" $LIST_NAME || \
702 echo $pkg >>$LIST_NAME
703 mv $pkg $PACKAGES_REPOSITORY
704 done
705 fi
706 cp $LIST_NAME $DISTRO/$DISTRO_LIST
707 if [ "$MODULAR" ]; then
708 union
709 else
710 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/$DISTRO_LIST > $DISTRO/list-packages
711 cd $PACKAGES_REPOSITORY
712 for pkg in $(cat $DISTRO/list-packages)
713 do
714 echo -n "Installing package: $pkg"
715 yes y | tazpkg install $pkg --root=$ROOTFS 2>/dev/null >> $log || exit 1
716 status
717 done
718 rm -f $ROOTFS/$DB/packages.*
719 fi
721 cd $DISTRO
722 if [ "$MODULAR" ]; then
723 cp $DISTRO_LIST $INIT/etc/slitaz
724 else
725 cp $DISTRO_LIST $ROOTFS/etc/slitaz
726 fi
727 # Copy all files from $ADDFILES/rootfs to the rootfs.
728 if [ -d "$ADDFILES/rootfs" ] ; then
729 echo -n "Copying addfiles content to the rootfs... "
730 cp -a $ADDFILES/rootfs/* $ROOTFS
731 status
732 fi
733 echo -n "Root filesystem is generated..." && status
734 # Root CD part.
735 echo -n "Preparing the rootcd directory..."
736 mkdir -p $ROOTCD
737 status
738 # Move the boot dir with the Linux kernel from rootfs.
739 # The boot dir goes directly on the CD.
740 if [ $MODULAR ]; then
741 if [ -d "$INIT/boot" ]; then
742 echo -n "Moving the boot directory..."
743 mv $INIT/boot $ROOTCD
744 cd $ROOTCD/boot
745 ln vmlinuz-* bzImage
746 status
747 elif [ -d "$ROOTFS/boot" ] ; then
748 echo -n "Moving the boot directory..."
749 mv $ROOTFS/boot $ROOTCD
750 cd $ROOTCD/boot
751 ln vmlinuz-* bzImage
752 status
753 fi
754 fi
755 cd $DISTRO
756 # Copy all files from $ADDFILES/rootcd to the rootcd.
757 if [ -d "$ADDFILES/rootcd" ] ; then
758 echo -n "Copying addfiles content to the rootcd... "
759 cp -a $ADDFILES/rootcd/* $ROOTCD
760 status
761 fi
762 # Execute the distro script used to perform tasks in the rootfs
763 # before compression. Give rootfs path in arg
764 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
765 if [ -x $DISTRO_SCRIPT ]; then
766 echo "Executing distro script..."
767 sh $DISTRO_SCRIPT $DISTRO
768 fi
769 if [ -s /etc/slitaz/rootfs.list ]; then
770 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
771 printf("%s ",$i) }' < /etc/slitaz/rootfs.list)"
772 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
773 $ROOTCD/boot/isolinux/isolinux.msg 2> /dev/null
774 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
775 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
776 n=0
777 last=$ROOTFS
778 while read flavor; do
779 n=$(($n+1))
780 echo "Building $flavor rootfs..."
781 if [ -d $flavors/$flavor ]; then
782 cp -a $flavors
783 [ -s $TOP_DIR/$flavor.flavor ] &&
784 cp $TOP_DIR/$flavor.flavor .
785 [ -s $flavor.flavor ] || download $flavor.flavor
786 zcat $flavor.flavor | cpio -i \
787 $flavor.pkglist $flavor.rootfs
788 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
789 > $DISTRO/list-packages0$n
790 mkdir ${ROOTFS}0$n
791 cd $PACKAGES_REPOSITORY
792 yes y | tazpkg install-list \
793 $DISTRO/list-packages0$n --root=${ROOTFS}0$n 2>/dev/null
794 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/$DB/packages.*
795 status
796 cd $DISTRO
797 if [ -s $flavor.rootfs ]; then
798 echo "Adding $flavor rootfs extra files..."
799 zcat $flavor.rootfs | \
800 ( cd ${ROOTFS}0$n ; cpio -idmu )
801 fi
802 mv $flavor.pkglist ${ROOTFS}0$n/etc/slitaz/$DISTRO_LIST
803 rm -f $flavor.flavor install-list
804 mergefs ${ROOTFS}0$n $last
805 last=${ROOTFS}0$n
806 fi
807 done <<EOT
808 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/slitaz/rootfs.list)
809 EOT
810 i=$(($n+1))
811 while [ $n -gt 0 ]; do
812 mv ${ROOTFS}0$n ${ROOTFS}$i
813 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
814 gen_initramfs ${ROOTFS}$i
815 n=$(($n-1))
816 i=$(($i-1))
817 done
818 mv $ROOTFS ${ROOTFS}$i
819 gen_initramfs ${ROOTFS}$i
820 update_bootconfig $ROOTCD/boot/isolinux \
821 "$(cat /etc/slitaz/rootfs.list)"
822 else
823 # Initramfs and ISO image stuff.
824 gen_initramfs $ROOTFS
825 fi
826 gen_livecd_isolinux
827 distro_stats
828 cleanup
829 }
831 # tazlito gen-flavor
832 gen_flavor()
833 {
834 # Generate a new flavor from the last iso image generated.
835 FLAVOR=${1%.flavor}
836 newline
837 echo -e "\033[1mFlavor generation\033[0m"
838 separator
839 if [ -z "$FLAVOR" ]; then
840 echo -n "Flavor name : "
841 read FLAVOR
842 [ -z "$FLAVOR" ] && exit 1
843 fi
844 check_rootfs
845 FILES="$FLAVOR.pkglist"
846 echo -n "Creating file $FLAVOR.flavor..."
847 for i in rootcd rootfs; do
848 if [ -d "$ADDFILES/$i" ] ; then
849 FILES="$FILES\n$FLAVOR.$i"
850 ( cd "$ADDFILES/$i"; find . | \
851 cpio -o -H newc 2> /dev/null | gzip -9 ) > $FLAVOR.$i
852 fi
853 done
854 status
855 answer=`grep -s ^Description $FLAVOR.desc`
856 answer=${answer#Description : }
857 if [ -z "$answer" ]; then
858 echo -n "Description : "
859 read answer
860 fi
861 echo -n "Compressing flavor $FLAVOR..."
862 echo "Flavor : $FLAVOR" > $FLAVOR.desc
863 echo "Description : $answer" >> $FLAVOR.desc
864 ( cd $DISTRO; distro_sizes) >> $FLAVOR.desc
865 \rm -f $FLAVOR.pkglist $FLAVOR.nonfree 2> /dev/null
866 for i in $(ls $ROOTFS$INSTALLED); do
867 eval $(grep ^VERSION= $ROOTFS$INSTALLED/$i/receipt)
868 EXTRAVERSION=""
869 eval $(grep ^EXTRAVERSION= $ROOTFS$INSTALLED/$i/receipt)
870 eval $(grep ^CATEGORY= $ROOTFS$INSTALLED/$i/receipt)
871 if [ "$CATEGORY" = "non-free" -a "${i%%-*}" != "get" ]
872 then
873 echo "$i" >> $FLAVOR.nonfree
874 else
875 echo "$i-$VERSION$EXTRAVERSION" >> $FLAVOR.pkglist
876 fi
877 done
878 [ -s $FLAVOR.nonfree ] && $FILES="$FILES\n$FLAVOR.nonfree"
879 for i in $LOCALSTATE/undigest/*/mirror ; do
880 [ -s $i ] && cat $i >> $FLAVOR.mirrors
881 done
882 [ -s $FLAVOR.mirrors ] && $FILES="$FILES\n$FLAVOR.mirrors"
883 echo -e "$FLAVOR.desc\n$FILES" | cpio -o -H newc 2>/dev/null | \
884 gzip -9 > $FLAVOR.flavor
885 rm `echo -e $FILES`
886 status
887 separator
888 echo "Flavor size : `du -sh $FLAVOR.flavor`"
889 newline
890 }
892 # tazlito get-flavor
893 get_flavor()
894 {
895 # Get a flavor's files and prepare for gen-distro.
896 FLAVOR=${1%.flavor}
897 echo -e "\n\033[1mPreparing $FLAVOR distro flavor\033[0m"
898 separator
899 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
900 echo -n "Cleaning $DISTRO..."
901 rm -R $DISTRO 2> /dev/null
902 mkdir -p $DISTRO
903 status
904 mkdir $TMP_DIR
905 echo -n "Extracting flavor $FLAVOR.flavor... "
906 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
907 status
908 echo -n "Creating distro-packages.list..."
909 mv $TMP_DIR/$FLAVOR.nonfree non-free.list 2> /dev/null
910 mv $TMP_DIR/$FLAVOR.pkglist distro-packages.list
911 status
912 if [ -f "$TMP_DIR/$FLAVOR-distro.sh" ]; then
913 echo -n "Extracting distro.sh... "
914 mv $TMP_DIR/$FLAVOR-distro.sh distro.sh 2> /dev/null
915 status
916 fi
917 infos="$FLAVOR.desc"
918 for i in rootcd rootfs; do
919 if [ -f $TMP_DIR/$FLAVOR.$i ]; then
920 echo -n "Adding $i files... "
921 mkdir -p "$ADDFILES/$i"
922 zcat $TMP_DIR/$FLAVOR.$i | \
923 ( cd "$ADDFILES/$i"; cpio -id > /dev/null)
924 zcat $TMP_DIR/$FLAVOR.$i | cpio -tv 2> /dev/null \
925 > $TMP_DIR/$FLAVOR.list$i
926 infos="$infos\n$FLAVOR.list$i"
927 status
928 fi
929 done
930 if [ -s $TMP_DIR/$FLAVOR.mirrors ]; then
931 n=""
932 while read line; do
933 mkdir -p $LOCALSTATE/undigest/$FLAVOR$n
934 echo "$line" > $LOCALSTATE/undigest/$FLAVOR$n/mirror
935 n=$(( $n + 1 ))
936 done < $TMP_DIR/$FLAVOR.mirrors
937 infos="$infos\n$FLAVOR.mirrors"
938 tazpkg recharge
939 fi
940 rm -f /etc/slitaz/rootfs.list
941 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc &&
942 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
943 sed 's/.*: \(.*\)$/\1/' > /etc/slitaz/rootfs.list
944 echo -n "Updating cookiso.conf..."
945 [ -f cookiso.conf ] || cp /etc/slitaz/cookiso.conf .
946 cat cookiso.conf | grep -v "^#VOLUM_NAME" | \
947 sed "s/^VOLUM_NA/VOLUM_NAME=\"SliTaz $FLAVOR\"\\n#VOLUM_NA/" \
948 > cookiso.conf.$$ && mv cookiso.conf.$$ cookiso.conf
949 sed -i "s/ISO_NAME=.*/ISO_NAME=\"slitaz-$FLAVOR\"/" cookiso.conf
950 status
951 ( cd $TMP_DIR ; echo -e $infos | cpio -o -H newc ) | \
952 gzip -9 > /etc/slitaz/info
953 rm -Rf $TMP_DIR
954 fi
955 separator
956 echo -e "Flavor is ready to be generated by: cookiso gen-distro\n"
957 }
959 # tazlito clean-distro
960 clean_distro()
961 {
962 # Remove old distro tree.
963 #
964 check_root
965 newline
966 boldify "Cleaning : $DISTRO"
967 separator
968 if [ -d "$DISTRO" ] ; then
969 if [ -d "$ROOTFS" ] ; then
970 echo -n "Removing the rootfs..."
971 rm -f $DISTRO/$INITRAMFS
972 rm -rf $ROOTFS
973 status
974 fi
975 if [ -d "$ROOTCD" ] ; then
976 echo -n "Removing the rootcd..."
977 rm -rf $ROOTCD
978 status
979 fi
980 echo -n "Removing eventual ISO image..."
981 rm -f $DISTRO/$ISO_NAME.iso
982 rm -f $DISTRO/$ISO_NAME.$SUM
983 status
984 fi
985 separator
986 newline
987 }
989 # tazlito pack-flavor
990 pack_flavor()
991 {
992 # Create a flavor from $FLAVORS_REPOSITORY.
993 FLAVOR=${1%.flavor}
994 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
995 mkdir $TMP_DIR
996 echo -n "Creating flavor $FLAVOR..."
997 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
998 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
999 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
1000 $TMP_DIR/$FLAVOR.mirrors
1001 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
1002 wget -O - $i/packages.list >> $TMP_DIR/packages.list
1003 done
1004 fi
1005 #add distro;sh if exist
1006 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/distro.sh ]; then
1007 cp $FLAVORS_REPOSITORY/$FLAVOR/distro.sh $TMP_DIR/$FLAVOR-distro.sh
1008 fi
1009 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
1010 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
1011 if grep -q ^ROOTFS_SELECTION \
1012 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
1013 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1014 set -- $ROOTFS_SELECTION
1015 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
1016 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
1017 extract_flavor $2
1018 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
1019 for i in rootcd rootfs; do
1020 mkdir $TMP_DIR/$i
1021 # Copy extra files from the first flavor
1022 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
1023 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
1024 # Overload extra files by meta flavor
1025 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
1026 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
1027 [ -n "$(ls $TMP_DIR/$i)" ] &&
1028 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
1029 gzip -9 >$TMP_DIR/$FLAVOR.$i
1030 rm -rf $TMP_DIR/$i
1031 done
1032 else
1033 for i in rootcd rootfs; do
1034 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
1035 continue
1036 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
1037 find . | cpio -o -H newc 2> /dev/null ) | \
1038 gzip -9 >$TMP_DIR/$FLAVOR.$i
1039 done
1040 fi
1041 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1042 packed_size=$(($packed_size \
1043 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1044 unpacked_size=$(($unpacked_size \
1045 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1046 fi
1047 # Estimate lzma
1048 packed_size=$(($packed_size * 2 / 3))
1049 iso_size=$(( $packed_size + 26000 ))
1050 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1051 iso_size=$(($iso_size \
1052 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1053 fi
1054 VERSION=""
1055 MAINTAINER=""
1056 ROOTFS_SELECTION=""
1057 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
1058 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
1059 ISO_SIZE="$(cent2human $iso_size) (estimated)"
1060 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
1061 cat > $TMP_DIR/$FLAVOR.desc <<EOT
1062 Flavor : $FLAVOR
1063 Description : $SHORT_DESC
1064 EOT
1065 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1066 Version : $VERSION
1067 EOT
1068 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1069 Maintainer : $MAINTAINER
1070 EOT
1071 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1072 LiveCD RAM size : $FRUGAL_RAM
1073 EOT
1074 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1075 Rootfs list : $ROOTFS_SELECTION
1076 EOT
1077 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
1078 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
1079 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
1080 Rootfs size : $ROOTFS_SIZE
1081 Initramfs size : $INITRAMFS_SIZE
1082 ISO image size : $ISO_SIZE
1083 ================================================================================
1085 EOT
1086 rm -f $TMP_DIR/packages.list
1087 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
1088 gzip -9 > $FLAVOR.flavor
1089 status
1090 rm -Rf $TMP_DIR
1091 else
1092 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
1093 fi
1094 }
1096 # tazlito extract-flavor
1097 extract_flavor()
1098 {
1099 # Extract a flavor into $FLAVORS_REPOSITORY.
1100 FLAVOR=${1%.flavor}
1101 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1102 mkdir $TMP_DIR
1103 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1104 echo -n "Extracting $FLAVOR..."
1105 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
1106 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
1107 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
1108 grep ^Description $TMP_DIR/$FLAVOR.desc | \
1109 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
1110 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1111 grep ^Version $TMP_DIR/$FLAVOR.desc | \
1112 sed 's/.*: \(.*\)$/VERSION="\1"/' >> \
1113 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1114 grep ^Maintainer $TMP_DIR/$FLAVOR.desc | \
1115 sed 's/.*: \(.*\)$/MAINTAINER="\1"/' >> \
1116 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1117 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
1118 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
1119 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
1120 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1121 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
1122 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
1123 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1124 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
1125 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
1126 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1127 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
1128 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
1129 $FLAVORS_REPOSITORY/$FLAVOR/receipt
1130 for i in rootcd rootfs; do
1131 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
1132 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
1133 zcat $TMP_DIR/$FLAVOR.$i | \
1134 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
1135 cpio -idm > /dev/null)
1136 done
1137 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
1138 cp $TMP_DIR/$FLAVOR.mirrors \
1139 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
1140 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1141 while read org; do
1142 i=0
1143 pkg=$org
1144 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1145 pkg=${pkg%-*}
1146 i=$(($i + 1))
1147 [ $i -gt 5 ] && break;
1148 done
1149 echo $pkg
1150 done < $TMP_DIR/$FLAVOR.pkglist \
1151 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
1152 status
1153 rm -Rf $TMP_DIR
1154 fi
1155 }
1157 # tazlito show-flavor
1158 show_flavor()
1159 {
1160 # Show flavor description.
1161 FLAVOR=${1%.flavor}
1162 if [ ! -f "$FLAVOR.flavor" ]; then
1163 echo "File $FLAVOR.flavor not found."
1164 exit 1
1165 fi
1166 mkdir $TMP_DIR
1167 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
1168 if [ "$2" = "--brief" ]; then
1169 if [ "$3" != "--noheader" ]; then
1170 echo "Name ISO Rootfs Description"
1171 separator
1172 fi
1173 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
1174 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
1175 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1176 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1177 else
1178 separator
1179 cat $TMP_DIR/$FLAVOR.desc
1180 fi
1181 rm -Rf $TMP_DIR
1182 }
1184 # tazlito list-flavors
1185 list_flavors()
1186 {
1187 # Show available flavors.
1188 if [ ! -s /tmp/flavors.list -o "$2" == "--recharge" ]; then
1189 download flavors.list -O - > /tmp/flavors.list
1190 fi
1191 newline
1192 echo -e "\033[1mList of flavors\033[0m"
1193 separator
1194 cat /tmp/flavors.list
1195 newline
1196 }
1198 # tazlito extract-distro
1199 extract_distro()
1200 {
1201 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1202 #
1203 check_root
1204 ISO_IMAGE=$1
1205 if [ -z "$ISO_IMAGE" ] ; then
1206 echo -e "\nPlease specify the path to the ISO image."
1207 echo -e "Example : `basename $0` image.iso /path/target\n"
1208 exit 0
1209 fi
1210 # Set the distro path by checking for $3 on cmdline.
1211 if [ -n "$2" ] ; then
1212 TARGET=$2
1213 else
1214 TARGET=$DISTRO
1215 fi
1216 # Exit if existing distro is found.
1217 if [ -d "$TARGET/rootfs" ] ; then
1218 echo -e "\nA rootfs exists in : $TARGET"
1219 echo -e "Please clean the distro tree or change directory path.\n"
1220 exit 0
1221 fi
1222 newline
1223 echo -e "\033[1mExtracting :\033[0m `basename $ISO_IMAGE`"
1224 separator
1225 # Start to mount the ISO.
1226 newline
1227 echo "Mounting ISO image..."
1228 mkdir -p $TMP_DIR
1229 # Get ISO file size.
1230 isosize=$(du -sh $ISO_IMAGE | cut -f1)
1231 mount -o loop $ISO_IMAGE $TMP_DIR
1232 sleep 2
1233 # Prepare target dir, copy the kernel and the rootfs.
1234 mkdir -p $TARGET/rootfs
1235 mkdir -p $TARGET/rootcd/boot
1236 echo -n "Copying the Linux kernel..."
1237 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1238 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1239 else
1240 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1241 fi
1242 status
1243 echo -n "Copying isolinux files..."
1244 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1245 for i in $(ls $TMP_DIR); do
1246 [ "$i" = "boot" ] && continue
1247 cp -a $TMP_DIR/$i $TARGET/rootcd
1248 done
1249 status
1250 if [ -d $TMP_DIR/boot/syslinux ]; then
1251 echo -n "Copying syslinux files..."
1252 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1253 status
1254 fi
1255 if [ -d $TMP_DIR/boot/extlinux ]; then
1256 echo -n "Copying extlinux files..."
1257 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1258 status
1259 fi
1260 if [ -d $TMP_DIR/boot/grub ]; then
1261 echo -n "Copying GRUB files..."
1262 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1263 status
1264 fi
1265 echo -n "Copying the rootfs..."
1266 cp $TMP_DIR/boot/$INITRAMFS $TARGET/rootcd/boot
1267 status
1268 # Extract initramfs.
1269 cd $TARGET/rootfs
1270 echo -n "Extracting the rootfs... "
1271 extract_rootfs $TARGET/rootfs/rootcd/boot/$INITRAMFS $TARGET/rootfs
1272 # unpack /usr
1273 for i in etc/slitaz/*.extract; do
1274 [ -f "$i" ] && . $i ../rootcd
1275 done
1276 # Umount and remove temp directory and cd to $TARGET to get stats.
1277 umount $TMP_DIR && rm -rf $TMP_DIR
1278 cd ..
1279 newline
1280 separator
1281 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1282 echo "Distro tree : `pwd`"
1283 echo "Rootfs size : `du -sh rootfs`"
1284 echo "Rootcd size : `du -sh rootcd`"
1285 separator
1286 newline
1287 }
1289 # tazlito update-flavor
1290 update_flavor()
1291 {
1292 # Update package list to the latest versions available.
1293 FLAVOR=${1%.flavor}
1294 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1295 mkdir $TMP_DIR
1296 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1297 echo -n "Updating $FLAVOR package list..."
1298 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1299 packed_size=0; unpacked_size=0
1300 while read org; do
1301 i=0
1302 pkg=$org
1303 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1304 pkg=${pkg%-*}
1305 i=$(($i + 1))
1306 [ $i -gt 5 ] && break;
1307 done
1308 set -- $(get_size $pkg)
1309 packed_size=$(( $packed_size + $1 ))
1310 unpacked_size=$(( $unpacked_size + $2 ))
1311 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1312 echo $i
1313 break
1314 done
1315 done < $TMP_DIR/$FLAVOR.pkglist \
1316 > $TMP_DIR/$FLAVOR.pkglist.$$
1317 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1318 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1319 packed_size=$(($packed_size \
1320 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1321 unpacked_size=$(($unpacked_size \
1322 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1323 fi
1324 # Estimate lzma
1325 packed_size=$(($packed_size * 2 / 3))
1326 iso_size=$(( $packed_size + 26000 ))
1327 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1328 iso_size=$(($iso_size \
1329 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1330 fi
1331 sed -i -e '/Image is ready/d' \
1332 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1333 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1334 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1335 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1336 $TMP_DIR/$FLAVOR.desc
1337 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1338 $FLAVOR.flavor
1339 status
1340 rm -Rf $TMP_DIR
1341 fi
1342 }
1344 # tazlito check-distro
1345 check_distro()
1346 {
1347 # Check for a few LiveCD needed files not installed by packages.
1348 #
1349 check_rootfs
1350 newline
1351 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
1352 separator
1353 # SliTaz release info.
1354 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
1355 echo "Missing release info : /etc/slitaz-release"
1356 else
1357 release=$(cat $ROOTFS/etc/slitaz-release)
1358 echo -n "Release : $release"
1359 status
1360 fi
1361 # Tazpkg mirror.
1362 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
1363 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
1364 todomsg
1365 else
1366 echo -n "Mirror configuration exists..."
1367 status
1368 fi
1369 # Isolinux msg
1370 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
1371 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
1372 todomsg
1373 else
1374 echo -n "Isolinux message seems good..."
1375 status
1376 fi
1377 separator
1378 newline
1379 }
1381 # tazlito writeiso
1382 writeiso()
1383 {
1384 # Writefs to ISO image including /home unlike gen-distro we dont use
1385 # packages to generate a rootfs, we build a compressed rootfs with all
1386 # the current filesystem similar to 'tazusb writefs'.
1387 #
1388 DISTRO="/home/slitaz/$SLITAZ_VERSION/distro"
1389 ROOTCD="$DISTRO/rootcd"
1390 if [ -z $1 ]; then
1391 COMPRESSION=none
1392 else
1393 COMPRESSION=$1
1394 fi
1395 if [ -z $2 ]; then
1396 ISO_NAME="slitaz"
1397 else
1398 ISO_NAME="$2"
1399 fi
1400 check_root
1401 # Start info
1402 newline
1403 echo -e "\033[1mWrite filesystem to ISO\033[0m
1404 ===============================================================================
1405 The command writeiso will write the current filesystem into a suitable cpio
1406 archive ($INITRAMFS) and generate a bootable ISO image (slitaz.iso).
1408 Archive compression: $COMPRESSION"
1409 newline
1411 # Save some space
1412 rm /var/cache/tazpkg/* -r -f
1413 [ -d $DISTRO ] && rm -rf $DISTRO
1415 # Optionally remove sound card selection and screen resolution.
1416 echo "Do you wish to remove the sound card and screen configs ? "
1417 echo -n "Press ENTER to keep or answer (No|yes|exit): "
1418 read anser
1419 case $anser in
1420 e|E|"exit"|Exit)
1421 exit 0 ;;
1422 y|Y|yes|Yes)
1423 echo -n "Removing current sound card and screen configurations..."
1424 rm -f /var/lib/sound-card-driver
1425 rm -f /etc/asound.state
1426 rm -f /etc/X11/screen.conf
1427 rm -f /etc/X11/xorg.conf ;;
1428 *)
1429 echo -n "Keeping current sound card and screen configurations..." ;;
1430 esac
1431 status
1433 cd /
1434 # Create list of files including default user files since it is defined in /etc/passwd
1435 # and some new users might have been added.
1436 find bin etc init sbin var dev lib root usr home >/tmp/list
1438 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
1439 do
1440 echo $dir >>/tmp/list
1441 done
1443 # Generate initramfs with specified compression and display rootfs
1444 # size in realtime.
1445 rm -f /tmp/rootfs
1446 write_initramfs &
1447 sleep 2
1448 cd - > /dev/null
1449 echo -en "\nFilesystem size:"
1450 while [ ! -f /tmp/rootfs ]
1451 do
1452 sleep 1
1453 echo -en "\\033[18G`du -sh /$INITRAMFS | awk '{print $1}'` "
1454 done
1455 echo -e "\n"
1457 # Move freshly generated rootfs to the cdrom.
1458 mkdir -p $ROOTCD/boot
1459 mv -f /$INITRAMFS $ROOTCD/boot
1461 # Now we need the kernel and isolinux files.
1462 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
1463 cp /media/cdrom/boot/bzImage $ROOTCD/boot
1464 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
1465 unmeta_boot $ROOTCD
1466 umount /media/cdrom
1467 elif mount |grep /media/cdrom; then
1468 cp /media/cdrom/boot/bzImage $ROOTCD/boot
1469 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
1470 unmeta_boot $ROOTCD
1471 umount /media/cdrom;
1472 else
1473 echo -e "
1474 When SliTaz is running in RAM the kernel and bootloader files are kept
1475 on the cdrom. Please insert a LiveCD or loop mount the slitaz.iso to
1476 /media/cdrom to let cookiso copy the files.\n"
1477 echo -en "----\nENTER to continue..."; read i
1478 exit 1
1479 fi
1481 # Generate the iso image.
1482 cd $DISTRO
1483 echo "Generating ISO image..."
1484 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
1485 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
1486 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
1487 if [ -x /usr/bin/isohybrid ]; then
1488 echo -n "Creating hybrid ISO..."
1489 /usr/bin/isohybrid $ISO_NAME.iso -entry 2 2> /dev/null
1490 status
1491 fi
1492 echo -n "Creating the ISO $CHECKSUM..."
1493 $CHECKSUM $ISO_NAME.iso > $ISO_NAME.$SUM
1494 status
1496 echo "==============================================================================="
1497 echo "ISO image: `du -sh $DISTRO/$ISO_NAME.iso`"
1498 newline
1499 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
1500 case $anser in
1501 burn)
1502 eject
1503 echo -n "Please insert a blank cdrom and press ENTER..."
1504 read i && sleep 2
1505 burn_iso $DISTRO/$ISO_NAME.iso
1506 echo -en "----\nENTER to continue..."; read i ;;
1507 *)
1508 exit 0 ;;
1509 esac
1510 }
1512 # tazlito repack
1513 repack()
1514 {
1515 # Repack an iso with maximum lzma compression ratio.
1516 #
1518 ISO=$1
1520 mkdir -p $TMP_DIR/mnt
1521 # Extract filesystems
1522 echo -n "Mounting $ISO"
1523 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
1524 status || cleanup_merge
1525 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1526 umount -d $TMP_DIR/mnt
1528 for i in $TMP_DIR/iso/boot/rootfs* ; do
1529 echo -n "Repacking $(basename $i)"
1530 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
1531 2>/dev/null > $TMP_DIR/rootfs
1532 lzma e $TMP_DIR/rootfs $i \
1533 $(lzma_switches $TMP_DIR/rootfs)
1534 status
1535 done
1537 create_iso $ISO $TMP_DIR/iso
1538 rm -rf $TMP_DIR
1539 }
1541 frugal_install()
1542 {
1543 ISO_IMAGE="$1"
1544 newline
1545 mkdir -p /boot/frugal
1546 if [ -f "$ISO_IMAGE" ]; then
1547 echo -n "Using ISO image: $ISO_IMAGE"
1548 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
1549 status
1550 echo -n "Installing the Kernel and rootfs..."
1551 cp -a /tmp/iso/boot/bzImage /boot/frugal
1552 if [ -f $ROOTCD/boot/rootfs1.gz ]; then
1553 cd /tmp/iso/boot
1554 cat $(ls -r rootfs*.gz) > /boot/frugal/$INITRAMFS
1555 else
1556 cp -a /tmp/iso/boot/$INITRAMFS /boot/frugal
1557 fi
1558 umount /tmp/iso
1559 status
1560 else
1561 echo -n "Using distro: $DISTRO"
1562 cd $DISTRO && status
1563 echo -n "Installing the Kernel and rootfs..."
1564 cp -a $ROOTCD/boot/bzImage /boot/frugal
1565 if [ -f $ROOTCD/boot/rootfs1.gz ]; then
1566 cd $ROOTCD/boot
1567 cat $(ls -r rootfs*.gz) > /boot/frugal/$INITRAMFS
1568 else
1569 cp -a $ROOTCD/boot/$INITRAMFS /boot/frugal
1570 fi
1571 status
1572 fi
1573 # Grub entry
1574 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
1575 echo -n "Configuring GRUB menu list..."
1576 cat >> /boot/grub/menu.lst << EOT
1577 title SliTaz GNU/Linux (frugal)
1578 root (hd0,0)
1579 kernel /boot/frugal/bzImage root=/dev/null
1580 initrd /boot/frugal/\$INITRAMFS
1581 EOT
1582 else
1583 echo -n "GRUB menu list is up-to-date..."
1584 fi
1585 status
1586 newline
1587 }
1589 # Check iso for loram transformation
1590 check_iso_for_loram()
1591 {
1592 [ -s $TMP_DIR/iso/boot/$INITRAMFS ] ||
1593 [ -s $TMP_DIR/iso/boot/rootfs1.gz ]
1594 }
1596 # Build initial rootfs for loram ISO ram/cdrom/http
1597 build_initfs()
1598 {
1599 urliso="mirror.slitaz.org mirror.switch.ch/ftp/mirror/slitaz \
1600 download.tuxfamily.org/slitaz slitaz.c3sl.ufpr.br"
1601 version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//')
1602 if [ -z "$version" ]; then
1603 cat <<EOT
1604 Can't find the kernel version.
1605 No file /boot/vmlinuz-<version> in ISO image.
1606 Abort.
1607 EOT
1608 exit 1
1609 fi
1610 [ -s /usr/share/boot/busybox-static ] || install_package busybox-static
1611 need_lib=false
1612 mkdir -p $TMP_DIR/initfs/bin $TMP_DIR/initfs/dev $TMP_DIR/initfs/lib \
1613 $TMP_DIR/initfs/mnt $TMP_DIR/initfs/proc $TMP_DIR/initfs/tmp \
1614 $TMP_DIR/initfs/sys
1615 while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz ]; do
1616 install_package aufs $version || return 1
1617 done
1618 # bootfloppybox will need floppy.ko.gz, /dev/fd0, /dev/tty0
1619 cp /lib/modules/$version/kernel/drivers/block/floppy.ko.gz \
1620 $TMP_DIR/initfs/lib 2> /dev/null
1621 cp -a /dev/tty0 /dev/fd0 $TMP_DIR/initfs/dev 2> /dev/null
1622 cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz \
1623 $TMP_DIR/initfs/lib
1624 if [ -f /bin/cromfs-driver ]; then
1625 cp /bin/cromfs-driver $TMP_DIR/initfs/bin
1626 ls /bin/unmkcromfs | \
1627 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
1628 else
1629 [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1
1630 while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz ]; do
1631 install_package linux-squashfs $version || return 1
1632 done
1633 cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz \
1634 $TMP_DIR/initfs/lib
1635 ls /sbin/unsquashfs /usr/lib/liblzma.so* $INSTALLED/squashfs/* | \
1636 cpio -o -H newc > $TMP_DIR/initfs/extractfs.cpio
1637 fi
1638 if [ "$1" == "cdrom" ]; then
1639 for i in $(ls /dev/[hs]d[a-f]*); do
1640 cp -a $i $TMP_DIR/initfs/dev
1641 done
1642 fi
1643 if [ "$1" == "http" ]; then
1644 mkdir $TMP_DIR/initfs/etc
1645 ln -s /proc/mounts $TMP_DIR/initfs/etc/mtab
1646 cp /usr/share/udhcpc/default.script $TMP_DIR/initfs/lib/udhcpc
1647 sed -i 's|/sbin/||' $TMP_DIR/initfs/lib/udhcpc
1648 cp -a /dev/fuse $TMP_DIR/initfs/dev
1649 if ! $need_lib && [ -x /usr/share/boot/fusermount-static ]; then
1650 cp /usr/share/boot/fusermount-static $TMP_DIR/initfs/bin/httpfs
1651 else
1652 cp /usr/bin/fusermount $TMP_DIR/initfs/bin
1653 need_lib=true
1654 fi
1655 if ! $need_lib && [ -x /usr/share/boot/httpfs-static ]; then
1656 cp /usr/share/boot/httpfs-static $TMP_DIR/initfs/bin/httpfs
1657 else
1658 [ ! -f /usr/bin/httpfs ] && ! install_package httpfs-fuse && return 1
1659 cp /usr/bin/httpfs $TMP_DIR/initfs/bin
1660 cp -a /lib/librt* $TMP_DIR/initfs/lib
1661 cp -a /lib/libdl* $TMP_DIR/initfs/lib
1662 cp -a /lib/libpthread* $TMP_DIR/initfs/lib
1663 cp -a /usr/lib/libfuse* $TMP_DIR/initfs/lib
1664 cp -a /lib/libresolv* $TMP_DIR/initfs/lib
1665 cp -a /lib/libnss_dns* $TMP_DIR/initfs/lib
1666 need_lib=true
1667 fi
1668 cd $TMP_DIR/initfs
1669 echo "Getting slitaz-release..."
1670 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
1671 ( zcat $i 2> /dev/null || unlzma -c $i) | \
1672 cpio -idmu etc/slitaz-release > /dev/null
1673 done
1674 cd - > /dev/null
1675 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"
1676 echo -n "List of urls to insert: "
1677 read -t 30 urliso2
1678 urliso="$urliso2 $urliso"
1679 fi
1680 if ! $need_lib && [ -x /usr/share/boot/busybox-static ]; then
1681 cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox
1682 else
1683 cp /bin/busybox $TMP_DIR/initfs/bin
1684 need_lib=true
1685 fi
1686 for i in $($TMP_DIR/initfs/bin/busybox | awk \
1687 '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do
1688 ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i
1689 done
1690 for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \
1691 /dev/kmem /dev/mem /dev/random /dev/urandom; do
1692 cp -a $i $TMP_DIR/initfs/dev
1693 done
1694 $need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do
1695 cp -a $i $TMP_DIR/initfs/lib
1696 done
1697 cat > $TMP_DIR/initfs/init <<EOTEOT
1698 #!/bin/sh
1700 getarg()
1701 {
1702 grep -q " \$1=" /proc/cmdline || return 1
1703 eval \$2=\$(sed "s/.* \$1=\\\\([^ ]*\\\\).*/\\\\1/" < /proc/cmdline)
1704 return 0
1705 }
1707 copy_rootfs()
1708 {
1709 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
1710 need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1)
1711 [ \$(( \$total / \$need )) -gt 1 ] || return 1
1712 if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then
1713 path=/mnt/
1714 return 0
1715 else
1716 rm -f /mnt/rootfs*
1717 return 1
1718 fi
1719 }
1721 echo "Switching / to tmpfs..."
1722 mount -t proc proc /proc
1723 size="\$(grep rootfssize= < /proc/cmdline | \\
1724 sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')"
1725 [ -n "\$size" ] || size="-o size=90%"
1727 if [ -x /bin/httpfs ]; then # loram-http
1729 while read var default; do
1730 eval \$var=\$default
1731 getarg \$var \$var
1732 done <<EOT
1733 eth eth0
1734 dns 208.67.222.222,208.67.220.220
1735 netmask 255.255.255.0
1736 gw
1737 ip
1738 EOT
1739 if [ -n "\$ip" ]; then
1740 ifconfig \$eth \$ip netmask \$netmask up
1741 route add default gateway \$gw
1742 for i in \$(echo \$dns | sed 's/,/ /g'); do
1743 echo "nameserver \$i" >> /etc/resolv.conf
1744 done
1745 else
1746 udhcpc -f -q -s /lib/udhcpc -i \$eth
1747 fi
1748 for i in $urliso ; do
1749 [ -n "\$URLISO" ] && URLISO="\$URLISO,"
1750 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"
1751 done
1752 getarg urliso URLISO
1753 DIR=fs
1754 if getarg loram DIR; then
1755 DEVICE=\${DIR%,*}
1756 DIR=/\${DIR#*,}
1757 fi
1758 mount -t tmpfs \$size tmpfs /mnt
1759 path2=/mnt/.httpfs/
1760 path=/mnt/.cdrom/
1761 mkdir -p /mnt/.rw \$path \$path2
1762 while [ ! -d \$path/boot ]; do
1763 for i in \$(echo \$URLISO | sed 's/,/ /g'); do
1764 httpfs \$i \$path2 && break
1765 done
1766 mount -o loop,ro -t iso9660 \$path2/*.iso \$path
1767 done
1768 #copy_rootfs && umount -d \$path && umount -d \$path2
1770 elif [ -f \$(echo /rootfs*.gz | cut -f1 -d' ') ]; then # loram-ram
1772 total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g')
1773 free=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
1774 if [ \$(( \$total/\$free )) -gt 1 ] || ! mount -t tmpfs \$size tmpfs /mnt; then
1775 echo "No tmpfs for /mnt"
1776 mkdir -p /mnt/.rw
1777 mount -t tmpfs tmpfs /mnt/.rw
1778 mkdir -p /mnt/.rw/mnt/.rw
1779 path=/
1780 else
1781 mkdir -p /mnt/.rw
1782 path=/mnt/.
1783 for i in rootfs* ; do
1784 mv /\$i \$path\$i
1785 done
1786 fi
1788 else # loram-cdrom
1790 getarg cdrom DRIVE_NAME ||
1791 DRIVE_NAME=\$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3)
1792 DEVICE=/dev/\$DRIVE_NAME
1793 DIR=fs
1794 if getarg loram DIR; then
1795 DEVICE=\${DIR%,*}
1796 DIR=/\${DIR#*,}
1797 fi
1798 mount -t tmpfs \$size tmpfs /mnt
1799 mkdir -p /mnt/.rw /mnt/.cdrom /mnt/mnt/.cdrom
1800 i=0
1801 while [ \$i -lt 5 ] && ! mount -r \$DEVICE /mnt/.cdrom; do
1802 case "\$DEVICE" in
1803 /dev/sd*|UUID=*|LABEL=*)
1804 mount -t sysfs sysfs /sys
1805 USBDELAY=\$(cat /sys/module/usb_storage/parameters/delay_use)
1806 umount /sys
1807 sleep \$((1+\$USBDELAY)) ;;
1808 esac
1809 i=\$((i+1))
1810 done
1811 path=/mnt/.cdrom/
1812 copy_rootfs && umount -d /mnt/.cdrom
1814 fi
1816 memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g')
1817 umount /proc
1818 branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR
1819 if [ ! -d /mnt/.cdrom/\$DIR/etc ]; then
1820 branch=br=/mnt/.rw
1821 for i in \${path}rootfs* ; do
1822 fs=\${i#*root}
1823 branch=\$branch:/mnt/.\$fs
1824 mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs /mnt/.rw/mnt/.cdrom
1825 if [ -f /bin/cromfs-driver ]; then
1826 cromfs-driver \${path}root\$fs /mnt/.\$fs -o ro,dev,suid,allow_other
1827 else
1828 insmod /lib/squashfs.ko.gz 2> /dev/null
1829 mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs
1830 fi
1831 done
1832 else
1833 mkdir -p /mnt/.rw/mnt/.httpfs
1834 fi
1835 insmod /lib/aufs.ko.gz
1836 mount -t aufs -o \$branch none /mnt
1837 [ -x /bin/httpfs ] && sed -i 's/DHCP="yes"/DHCP="no"/' /mnt/etc/network.conf
1838 [ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf
1839 [ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh
1840 EOTEOT
1841 chmod +x $TMP_DIR/initfs/init
1842 ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \
1843 lzma e $TMP_DIR/initfs.gz -si
1844 lzma_set_size $TMP_DIR/initfs.gz
1845 rm -rf $TMP_DIR/initfs
1846 rem=$(( $(stat -c "%s" $TMP_DIR/initfs.gz) % 4 ))
1847 [ $rem -ne 0 ] &&
1848 dd if=/dev/zero bs=1 count=$(( 4 - $rem )) >> $TMP_DIR/initfs.gz 2> /dev/null
1849 return 0
1850 }
1852 # Move each initramfs to squashfs (or cromfs)
1853 build_loram_rootfs_cdrom()
1854 {
1855 mkdir -p $TMP_DIR/fs
1856 cd $TMP_DIR/fs
1857 for i in $(ls -r $TMP_DIR/iso/boot/rootfs*.gz); do
1858 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idmu
1859 done
1860 rootfs=$TMP_DIR/$INITRAMFS
1861 if [ -x /usr/bin/mkcromfs ]; then
1862 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
1863 else
1864 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
1865 fi
1866 rm -rf $TMP_DIR/fs
1867 cd - > /dev/null
1868 }
1870 # Move meta boot configuration files to basic configuration files
1871 # because meta loram flavor is useless when rootfs is not loaded in ram
1872 unmeta_boot()
1873 {
1874 local root=${1:-$TMP_DIR/loramiso}
1875 if [ -f $root/boot/isolinux/noram.cfg ]; then
1876 # We keep enough information to do unloram...
1877 [ -s $root/boot/isolinux/common.cfg ] &&
1878 sed -i 's/label slitaz/label orgslitaz/' \
1879 $root/boot/isolinux/common.cfg
1880 set -- $(grep 'append ifmem [0-9]' $root/boot/isolinux/isolinux.cfg)
1881 shift
1882 sed -i '/ifmem/{NNNNNNNNd};/^LABEL/{N;/LABEL SliTaz [^L]/{NNNd}}' \
1883 $root/boot/isolinux/isolinux.cfg
1884 [ -n "$3" ] || set -- $(grep 'append [0-9]' $root/boot/isolinux/common.cfg)
1885 sed -i "s/label $3\$/label slitaz/;s|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |" \
1886 $root/boot/isolinux/*.cfg
1887 fi
1888 }
1890 # Move each initramfs to squashfs (or cromfs)
1891 build_loram_rootfs()
1892 {
1893 rootfs_sizes=""
1894 for i in $TMP_DIR/iso/boot/rootfs*.gz; do
1895 mkdir -p $TMP_DIR/fs
1896 cd $TMP_DIR/fs
1897 ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm
1898 cd - > /dev/null
1899 rootfs=$TMP_DIR/$(basename $i)
1900 if [ -x /usr/bin/mkcromfs ]; then
1901 /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs
1902 else
1903 /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp xz -Xbcj x86
1904 fi
1905 cd $TMP_DIR
1906 rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))"
1907 ( cd $(dirname $rootfs); echo $(basename $rootfs) | \
1908 cpio -o -H newc ) > $rootfs.cpio
1909 rm -f $rootfs
1910 mv $rootfs.cpio $rootfs
1911 cd - > /dev/null
1912 rm -rf $TMP_DIR/fs
1913 done
1914 }
1916 # Move rootfs to squashfs filesystem(s) to the cdrom writeable with aufs.
1917 # These squashfs may be loaded in ram a boot time.
1918 # Rootfs are also copied to cdrom for tiny ramsize systems.
1919 # Meta flavors are converted to normal flavors.
1920 build_loram_cdrom()
1921 {
1922 build_initfs cdrom || return 1
1923 build_loram_rootfs_cdrom
1924 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1925 if [ "$1" == "small" ]; then
1926 rm -f $TMP_DIR/loramiso/boot/root*
1927 else
1928 mkdir $TMP_DIR/loramiso/fs
1929 cd $TMP_DIR/loramiso/fs
1930 for i in $( ls ../boot/root* | sort -r ) ; do
1931 ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu
1932 rm -f $i
1933 done
1934 mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom
1935 cd - > /dev/null
1936 fi
1937 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/$INITRAMFS
1938 mv $TMP_DIR/rootfs*.gz $TMP_DIR/loramiso
1939 unmeta_boot
1940 VOLUM_NAME="SliTaz_LoRAM_CDROM"
1941 sed -i "s/root=/loram=LABEL=$VOLUM_NAME,fs &/" \
1942 $TMP_DIR/loramiso/boot/isolinux/*.cfg
1943 create_iso $OUTPUT $TMP_DIR/loramiso
1944 }
1946 # Create http bootstrap to load and remove loram_cdrom
1947 # Meta flavors are converted to normal flavors.
1948 build_loram_http()
1949 {
1950 build_initfs http || return 1
1951 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1952 rm -f $TMP_DIR/loramiso/boot/rootfs*
1953 mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/$INITRAMFS
1954 unmeta_boot
1955 create_iso $OUTPUT $TMP_DIR/loramiso
1956 }
1958 # Update meta flavor selection sizes.
1959 # Reduce sizes with rootfs gains.
1960 update_metaiso_sizes()
1961 {
1962 for cfg in $(grep -El '(append|ifmem) [0-9]' $TMP_DIR/loramiso/boot/isolinux/*.cfg)
1963 do
1964 local append="$(grep -E '(append|ifmem) [0-9]' $cfg)"
1965 local sizes="$rootfs_sizes"
1966 local new
1967 set -- $append
1968 shift
1969 [ "$1" == "ifmem" ] && shift
1970 new=""
1971 while [ -n "$2" ]; do
1972 local s
1973 case "$1" in
1974 *G) s=$(( ${1%G} * 1024 * 1024 ));;
1975 *M) s=$(( ${1%M} * 1024 ));;
1976 *) s=${1%K};;
1977 esac
1978 sizes=${sizes#* }
1979 for i in $sizes ; do
1980 s=$(( $s - $i ))
1981 done
1982 new="$new $s $2"
1983 shift 2
1984 done
1985 sed -i -e "/append [0-9]/s/append .*/append$new $1/" -e \
1986 "/append ifmem [0-9]/s/append .*/append ifmem$new $1/" $cfg
1987 done
1988 }
1990 # Move rootfs to a squashfs filesystem into the initramfs writeable with aufs.
1991 # Meta flavor selection sizes are updated.
1992 build_loram_ram()
1993 {
1994 build_initfs ram || return 1
1995 build_loram_rootfs
1996 cp -a $TMP_DIR/iso $TMP_DIR/loramiso
1997 rm -f $TMP_DIR/loramiso/boot/bzImage
1998 ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage
1999 rootfs=$(ls $TMP_DIR/rootfs* | sort | tail -n 1)
2000 cat $rootfs >> $TMP_DIR/initfs.gz
2001 mv $TMP_DIR/initfs.gz $rootfs
2002 cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot
2003 update_metaiso_sizes
2004 create_iso $OUTPUT $TMP_DIR/loramiso
2005 }