cookutils view lib/libcookiso.sh @ rev 558

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