cookutils view lib/libcookiso.sh @ rev 523
Add libcookiso.sh. This is to replace tazlito by making it into functions for cookiso.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Fri Aug 24 22:00:29 2012 +0000 (2012-08-24) |
parents | |
children | 6eb46b5c9bea |
line source
1 #!/bin/sh
3 # libcookiso functions
5 . /usr/lib/slitaz/libcook.sh
7 TOP_DIR="$(pwd)"
8 TMP_DIR=/tmp/cookiso-$$-$RANDOM
9 TMP_MNT=/media/cookiso-$$-$RANDOM
10 INITRAMFS=rootfs.gz
11 [ -f "/etc/slitaz/cookiso.conf" ] && CONFIG_FILE="/etc/slitaz/cookiso.conf"
12 [ -f "$TOP_DIR/cookiso.conf" ] && CONFIG_FILE="$TOP_DIR/cookiso.conf"
13 DEFAULT_MIRROR="$MIRROR_URL/packages/$SLITAZ_VERSION/"
15 log=/var/log/tazlito.log
16 if check_root; then
17 newline > $log
18 fi
20 if [ ! "$CONFIG_FILE" = "" ] ; then
21 . $CONFIG_FILE
22 else
23 if [ "$COMMAND" = "gen-config" ] ; then
24 continue
25 else
26 echo "Unable to find any configuration file. Please read the docs"
27 echo "or run '`basename $0` gen-config' to get an empty config file."
28 exit 0
29 fi
30 fi
32 # While Tazpkg is not used the default mirror url file does not exist
33 # and user can't recharge the list of flavors.
34 if test $(id -u) = 0 ; then
35 if [ ! -f "$MIRROR" ]; then
36 echo "$DEFAULT_MIRROR" > $MIRROR
37 fi
38 fi
40 # Set the rootfs and rootcd path with $DISTRO
41 # configuration variable.
42 ROOTFS=$DISTRO/rootfs
43 ROOTCD=$DISTRO/rootcd
45 yesorno()
46 {
47 echo -n "$1"
48 case "$DEFAULT_ANSWER" in
49 Y|y) answer="y";;
50 N|n) answer="n";;
51 *) read answer;;
52 esac
53 }
55 field()
56 {
57 grep "^$1" "$2" | sed 's/.*: \([0-9KMG\.]*\).*/\1/'
58 }
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/tazlito/*.$1 2> /dev/null); do
94 cd $ROOTFS
95 . $i $ROOTCD
96 done
97 cd $here
98 }
100 cleanup()
101 {
102 if [ -d $TMP_MNT ]; then
103 umount $TMP_MNT
104 rmdir $TMP_MNT
105 rm -f /boot
106 fi
107 }
109 # Echo the package name if the tazpkg is already installed
110 installed_package_name()
111 {
112 local tazpkg
113 local package
114 local VERSION
115 local EXTRAVERSION
116 tazpkg=$1
117 # Try to find package name and version to be able
118 # to repack it from installation
119 # A dash (-) can exist in name *and* in version
120 package=${tazpkg%-*}
121 i=$package
122 while true; do
123 VERSION=""
124 eval $(grep -s ^VERSION= $INSTALLED/$i/receipt)
125 EXTRAVERSION=""
126 eval $(grep -s ^EXTRAVERSION= $INSTALLED/$i/receipt)
127 if [ "$i-$VERSION$EXTRAVERSION" = "$tazpkg" ]; then
128 echo $i
129 break
130 fi
131 case "$i" in
132 *-*);;
133 *) break;;
134 esac
135 i=${i%-*}
136 done
137 }
140 # Check for the rootfs tree.
141 check_rootfs()
142 {
143 if [ ! -d "$ROOTFS/etc" ] ; then
144 echo -e "\nUnable to find a distro rootfs...\n"
145 exit 0
146 fi
147 }
149 # Check for the boot dir into the root CD tree.
150 verify_rootcd()
151 {
152 if [ ! -d "$ROOTCD/boot" ] ; then
153 echo -e "\nUnable to find the rootcd boot directory...\n"
154 exit 0
155 fi
156 }
158 create_iso()
159 {
160 cd $2
161 echo -n "Computing $SUM..."
162 find * -type f ! -name $CHECKSUM -exec $CHECKSUM {} \; > $CHECKSUM
163 sed -i -e '/ boot\/isolinux\/isolinux.bin$/d' \
164 -e '/ boot\/isolinux\/boot.cat$/d' $CHECKSUM
165 status
166 cd - > /dev/null
167 newline
168 echo -e "\033[1mGenerating ISO image\033[0m"
169 separator
170 echo "Generating $1"
171 if [ $(ls $2/boot/vmlinuz* $2/boot/bzImage | wc -l) -eq 2 ]; then
172 if cmp $2/boot/vmlinuz* $2/boot/bzImage > /dev/null; then
173 rm -f $2/boot/bzImage
174 ln $2/boot/vmlinuz* $2/boot/bzImage
175 fi
176 fi
177 genisoimage -R -o $1 -b boot/isolinux/isolinux.bin \
178 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
179 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \
180 -boot-info-table $2
181 if [ -x /usr/bin/isohybrid ]; then
182 echo -n "Creating hybrid ISO..."
183 /usr/bin/isohybrid $1 -entry 2 2> /dev/null
184 status
185 fi
186 if [ -s /etc/tazlito/info ]; then
187 if [ $(stat -c %s /etc/tazlito/info) -lt $(( 31*1024 )) ]; then
188 echo -n "Storing ISO info..."
189 dd if=/etc/tazlito/info bs=1k seek=1 of=$1 \
190 conv=notrunc 2> /dev/null
191 status
192 fi
193 fi
194 }
196 # Generate a new ISO image using isolinux.
197 gen_livecd_isolinux()
198 {
199 # Some packages may want to alter iso
200 genisohooks iso
201 if [ ! -f "$ROOTCD/boot/isolinux/isolinux.bin" ]; then
202 echo -e "\nUnable to find isolinux binary.\n"
203 cleanup
204 exit 0
205 fi
206 # Set date for boot msg.
207 if grep -q 'XXXXXXXX' $ROOTCD/boot/isolinux/isolinux.*g; then
208 DATE=`date +%Y%m%d`
209 echo -n "Setting build date to: $DATE..."
210 sed -i "s/XXXXXXXX/$DATE/" $ROOTCD/boot/isolinux/isolinux.*g
211 status
212 fi
213 cd $DISTRO
214 create_iso $ISO_NAME.iso $ROOTCD
215 echo -n "Creating the ISO $CHECKSUM..."
216 $CHECKSUM $ISO_NAME.iso > $ISO_NAME.$SUM
217 status
218 separator
219 # Some packages may want to alter final iso
220 genisohooks final
221 }
223 lzma_history_bits()
224 {
225 #
226 # This generates an ISO which boots with Qemu but gives
227 # rootfs errors in frugal or liveUSB mode.
228 #
229 #local n
230 #local sz
231 #n=20 # 1Mb
232 #sz=$(du -sk $1 | cut -f1)
233 #while [ $sz -gt 1024 -a $n -lt 28 ]; do
234 #n=$(( $n + 1 ))
235 #sz=$(( $sz / 2 ))
236 #done
237 #echo $n
238 echo 24
239 }
241 lzma_switches()
242 {
243 local proc=$(grep -s '^processor' < /proc/cpuinfo | wc -l)
244 echo "-d$(lzma_history_bits $1) -mt${proc:-1}"
245 }
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 }
294 # Deduplicate files (MUST be on the same filesystem).
295 deduplicate()
296 {
297 find "$@" -type f -size +0c -exec stat -c '%s-%a-%u-%g %i %h %n' {} \; | \
298 sort | ( save=0; old_attr=""; old_inode=""; old_link=""; old_file=""
299 while read attr inode link file; do
300 [ -L "$file" ] && continue
301 if [ "$attr" = "$old_attr" -a "$inode" != "$old_inode" ]; then
302 if cmp "$file" "$old_file" >/dev/null 2>&1 ; then
303 rm -f "$file"
304 ln "$old_file" "$file"
305 inode="$old_inode"
306 [ "$link" = "1" ] && save="$(expr $save + ${attr%%-*})"
307 fi
308 fi
309 old_attr="$attr" ; old_inode="$inode" ; old_file="$file"
310 done
311 echo "$save bytes saved in duplicate files."
312 )
313 }
315 # Generate a new initramfs from the root filesystem.
316 gen_initramfs()
317 {
318 # Just in case CTRL+c
319 rm -f $DISTRO/gen
321 # Some packages may want to alter rootfs
322 genisohooks rootfs
323 cd $1
325 # Link duplicate files
326 deduplicate .
328 # Use lzma if installed. Display rootfs size in realtime.
329 rm -f /tmp/rootfs
330 pack_rootfs . $DISTRO/$(basename $1).gz &
331 sleep 2
332 echo -en "\nFilesystem size:"
333 while [ ! -f /tmp/rootfs ]
334 do
335 sleep 1
336 echo -en "\\033[18G`du -sh $DISTRO/$(basename $1).gz | awk '{print $1}'` "
337 done
338 echo -e "\n"
339 cd $DISTRO
340 mv $(basename $1).gz $ROOTCD/boot
341 }
343 distro_sizes()
344 {
345 if [ "$time" ]; then
346 time=$(($(date +%s) - $time))
347 sec=$time
348 div=$(( ($time + 30) / 60))
349 [ "$div" != 0 ] && min="~ ${div}m"
350 echo "Build time : ${sec}s $min"
351 fi
352 cat << EOT
353 Build date : $(date +%Y%m%d)
354 Packages : $(ls -1 $ROOTFS*$INSTALLED/*/receipt | wc -l)
355 Rootfs size : $(du -csh $ROOTFS*/ | awk '{ s=$1 } END { print s }')
356 Initramfs size : $(du -csh $ROOTCD/boot/rootfs*.gz | awk '{ s=$1 } END { print s }')
357 ISO image size : $(du -sh $ISO_NAME.iso | awk '{ print $1 }')
358 ================================================================================
359 Image is ready: $ISO_NAME.iso
361 EOT
362 }
364 # Print ISO and rootfs size.
365 distro_stats()
366 {
367 newline
368 echo -e "\033[1mDistro statistics\033[0m ($DISTRO)"
369 separator
370 distro_sizes
371 }
373 # tazlito gen-distro
374 gen_distro()
375 {
376 check_root
377 time=$(date +%s)
379 # Check if a package list was specified on cmdline.
380 DISTRO_LIST="distro-packages.list"
381 LIST_NAME="$DISTRO_LIST"
382 unset CDROM
383 while [ -n "$1" ]; do
384 case "$1" in
385 --iso=*)
386 CDROM="-o loop ${2#--iso=}"
387 ;;
388 --cdrom)
389 CDROM="/dev/cdrom"
390 ;;
391 --force)
392 DELETE_ROOTFS="true"
393 ;;
394 *) if [ ! -f "$1" ] ; then
395 echo -e "\nUnable to find the specified packages list."
396 echo -e "List name : $1\n"
397 exit 1
398 fi
399 LIST_NAME=$1
400 ;;
401 esac
402 shift
403 done
405 if [ -d $ROOTFS ] ; then
406 # Delete $ROOTFS if --force is set on command line
407 if [ ! -z $DELETE_ROOTFS ]; then
408 rm -rf $ROOTFS
409 unset $DELETE_ROOTFS
410 else
411 echo -e "\nA rootfs exists in : $DISTRO"
412 echo -e "Please clean the distro tree or change directory path.\n"
413 exit 0
414 fi
415 fi
416 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
417 # Build list with installed packages
418 for i in $(ls $INSTALLED); do
419 eval $(grep ^VERSION= $INSTALLED/$i/receipt))
420 EXTRAVERSION=""
421 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
422 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
423 done
424 fi
425 # Exit if no list name.
426 if [ ! -f "$LIST_NAME" ]; then
427 echo -e "\nNo packages list found or specified. Please read the docs.\n"
428 exit 0
429 fi
430 # Start generation.
431 newline
432 echo -e "\033[1mGenerating a distro\033[0m"
433 separator
434 # Misc checks
435 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
436 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
437 # Get the list of packages using cat for a file list.
438 LIST=$(cat $LIST_NAME)
439 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
440 unset REPACK DOWNLOAD
441 for pkg in $LIST
442 do
443 [ "$pkg" = "" ] && continue
444 pkg=${pkg%.tazpkg}
445 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
446 PACKAGE=$(installed_package_name $pkg)
447 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
448 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
449 echo -e "\nUnable to find $pkg in the repository."
450 echo -e "Path : $PACKAGES_REPOSITORY\n"
451 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
452 yesorno "Repack packages from rootfs (y/N) ? "
453 REPACK="$answer"
454 [ "$answer" = "y" ] || REPACK="n"
455 [ "$DOWNLOAD" = "y" ] && break
456 fi
457 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
458 yesorno "Download packages from mirror (Y/n) ? "
459 DOWNLOAD="$answer"
460 if [ "$answer" = "n" ]; then
461 [ -z "$PACKAGE" ] && exit 1
462 else
463 DOWNLOAD="y"
464 [ -n "$REPACK" ] && break
465 fi
466 fi
467 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
468 done
470 # Mount cdrom to be able to repack boot-loader packages
471 if [ ! -e /boot -a -n "$CDROM" ]; then
472 mkdir $TMP_MNT
473 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
474 ln -s $TMP_MNT/boot /
475 if [ ! -d "$ADDFILES/rootcd" ] ; then
476 mkdir -p $ADDFILES/rootcd
477 for i in $(ls $TMP_MNT); do
478 [ "$i" = "boot" ] && continue
479 cp -a $TMP_MNT/$i $ADDFILES/rootcd
480 done
481 fi
482 else
483 rmdir $TMP_MNT
484 fi
485 fi
487 # Root fs stuff.
488 echo "Preparing the rootfs directory..."
489 mkdir -p $ROOTFS
490 for pkg in $LIST
491 do
492 [ "$pkg" = "" ] && continue
493 # First copy and extract the package in tmp dir.
494 pkg=${pkg%.tazpkg}
495 PACKAGE=$(installed_package_name $pkg)
496 mkdir -p $TMP_DIR
497 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
498 # Look for package in cache
499 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
500 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
501 # Look for package in running distribution
502 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
503 tazpkg repack $PACKAGE && \
504 mv $pkg.tazpkg $PACKAGES_REPOSITORY
505 fi
506 fi
507 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
508 # Get package from mirror
509 [ "$DOWNLOAD" = "y" ] && \
510 download $pkg.tazpkg && \
511 mv $pkg.tazpkg $PACKAGES_REPOSITORY
512 fi
513 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
514 echo "Missing package $pkg."
515 cleanup
516 exit 1
517 fi
518 done
519 if [ -f non-free.list ]; then
520 echo "Preparing non-free packages..."
521 cp non-free.list $ROOTFS/etc/tazlito/non-free.list
522 for pkg in $(cat non-free.list); do
523 if [ ! -d $INSTALLED/$pkg ]; then
524 if [ ! -d $INSTALLED/get-$pkg ]; then
525 tazpkg get-install get-$pkg
526 fi
527 get-$pkg
528 fi
529 tazpkg repack $pkg
530 pkg=$(ls $pkg*.tazpkg)
531 grep -q "^$pkg$" $LIST_NAME || \
532 echo $pkg >>$LIST_NAME
533 mv $pkg $PACKAGES_REPOSITORY
534 done
535 fi
536 cp $LIST_NAME $DISTRO/$DISTRO_LIST
537 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/$DISTRO_LIST > $DISTRO/list-packages
538 cd $PACKAGES_REPOSITORY
539 for pkg in $(cat $DISTRO/list-packages)
540 do
541 echo -n "Installing package: $pkg"
542 yes y | tazpkg install $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
543 status
544 done
545 rm -f $ROOTFS/$DB/packages.*
546 cd $DISTRO
547 cp $DISTRO_LIST $ROOTFS/etc/tazlito
548 # Copy all files from $ADDFILES/rootfs to the rootfs.
549 if [ -d "$ADDFILES/rootfs" ] ; then
550 echo -n "Copying addfiles content to the rootfs... "
551 cp -a $ADDFILES/rootfs/* $ROOTFS
552 status
553 fi
554 echo -n "Root filesystem is generated..." && status
555 # Root CD part.
556 echo -n "Preparing the rootcd directory..."
557 mkdir -p $ROOTCD
558 status
559 # Move the boot dir with the Linux kernel from rootfs.
560 # The boot dir goes directly on the CD.
561 if [ -d "$ROOTFS/boot" ] ; then
562 echo -n "Moving the boot directory..."
563 mv $ROOTFS/boot $ROOTCD
564 cd $ROOTCD/boot
565 ln vmlinuz-* bzImage
566 status
567 fi
568 cd $DISTRO
569 # Copy all files from $ADDFILES/rootcd to the rootcd.
570 if [ -d "$ADDFILES/rootcd" ] ; then
571 echo -n "Copying addfiles content to the rootcd... "
572 cp -a $ADDFILES/rootcd/* $ROOTCD
573 status
574 fi
575 # Execute the distro script used to perform tasks in the rootfs
576 # before compression. Give rootfs path in arg
577 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
578 if [ -x $DISTRO_SCRIPT ]; then
579 echo "Executing distro script..."
580 sh $DISTRO_SCRIPT $DISTRO
581 fi
582 if [ -s /etc/tazlito/rootfs.list ]; then
583 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
584 printf("%s ",$i) }' < /etc/tazlito/rootfs.list)"
585 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
586 $ROOTCD/boot/isolinux/isolinux.msg 2> /dev/null
587 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
588 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
589 n=0
590 last=$ROOTFS
591 while read flavor; do
592 n=$(($n+1))
593 echo "Building $flavor rootfs..."
594 if [ -d $flavors/$flavor ]; then
595 cp -a $flavors
596 [ -s $TOP_DIR/$flavor.flavor ] &&
597 cp $TOP_DIR/$flavor.flavor .
598 [ -s $flavor.flavor ] || download $flavor.flavor
599 zcat $flavor.flavor | cpio -i \
600 $flavor.pkglist $flavor.rootfs
601 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
602 > $DISTRO/list-packages0$n
603 mkdir ${ROOTFS}0$n
604 cd $PACKAGES_REPOSITORY
605 yes y | tazpkg install-list \
606 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
607 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/$DB/packages.*
608 status
609 cd $DISTRO
610 if [ -s $flavor.rootfs ]; then
611 echo "Adding $flavor rootfs extra files..."
612 zcat $flavor.rootfs | \
613 ( cd ${ROOTFS}0$n ; cpio -idmu )
614 fi
615 mv $flavor.pkglist ${ROOTFS}0$n/etc/tazlito/$DISTRO_LIST
616 rm -f $flavor.flavor install-list
617 mergefs ${ROOTFS}0$n $last
618 last=${ROOTFS}0$n
619 done <<EOT
620 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/tazlito/rootfs.list)
621 EOT
622 i=$(($n+1))
623 while [ $n -gt 0 ]; do
624 mv ${ROOTFS}0$n ${ROOTFS}$i
625 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
626 gen_initramfs ${ROOTFS}$i
627 n=$(($n-1))
628 i=$(($i-1))
629 done
630 mv $ROOTFS ${ROOTFS}$i
631 gen_initramfs ${ROOTFS}$i
632 update_bootconfig $ROOTCD/boot/isolinux \
633 "$(cat /etc/tazlito/rootfs.list)"
634 else
635 # Initramfs and ISO image stuff.
636 gen_initramfs $ROOTFS
637 fi
638 gen_livecd_isolinux
639 distro_stats
640 cleanup
641 }
643 # tazlito clean-distro
644 clean_distro()
645 {
646 # Remove old distro tree.
647 #
648 check_root
649 newline
650 boldify "Cleaning : $DISTRO"
651 separator
652 if [ -d "$DISTRO" ] ; then
653 if [ -d "$ROOTFS" ] ; then
654 echo -n "Removing the rootfs..."
655 rm -f $DISTRO/$INITRAMFS
656 rm -rf $ROOTFS
657 status
658 fi
659 if [ -d "$ROOTCD" ] ; then
660 echo -n "Removing the rootcd..."
661 rm -rf $ROOTCD
662 status
663 fi
664 echo -n "Removing eventual ISO image..."
665 rm -f $DISTRO/$ISO_NAME.iso
666 rm -f $DISTRO/$ISO_NAME.$SUM
667 status
668 fi
669 separator
670 newline
671 }
673 # tazlito pack-flavor
674 pack_flavor()
675 {
676 # Create a flavor from $FLAVORS_REPOSITORY.
677 FLAVOR=${1%.flavor}
678 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
679 mkdir $TMP_DIR
680 echo -n "Creating flavor $FLAVOR..."
681 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
682 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
683 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
684 $TMP_DIR/$FLAVOR.mirrors
685 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
686 wget -O - $i/packages.list >> $TMP_DIR/packages.list
687 done
688 fi
689 #add distro;sh if exist
690 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/distro.sh ]; then
691 cp $FLAVORS_REPOSITORY/$FLAVOR/distro.sh $TMP_DIR/$FLAVOR-distro.sh
692 fi
693 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
694 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
695 if grep -q ^ROOTFS_SELECTION \
696 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
697 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
698 set -- $ROOTFS_SELECTION
699 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
700 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
701 extract_flavor $2
702 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
703 for i in rootcd rootfs; do
704 mkdir $TMP_DIR/$i
705 # Copy extra files from the first flavor
706 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
707 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
708 # Overload extra files by meta flavor
709 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
710 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
711 [ -n "$(ls $TMP_DIR/$i)" ] &&
712 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
713 gzip -9 >$TMP_DIR/$FLAVOR.$i
714 rm -rf $TMP_DIR/$i
715 done
716 else
717 for i in rootcd rootfs; do
718 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
719 continue
720 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
721 find . | cpio -o -H newc 2> /dev/null ) | \
722 gzip -9 >$TMP_DIR/$FLAVOR.$i
723 done
724 fi
725 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
726 packed_size=$(($packed_size \
727 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
728 unpacked_size=$(($unpacked_size \
729 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
730 fi
731 # Estimate lzma
732 packed_size=$(($packed_size * 2 / 3))
733 iso_size=$(( $packed_size + 26000 ))
734 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
735 iso_size=$(($iso_size \
736 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
737 fi
738 VERSION=""
739 MAINTAINER=""
740 ROOTFS_SELECTION=""
741 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
742 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
743 ISO_SIZE="$(cent2human $iso_size) (estimated)"
744 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
745 cat > $TMP_DIR/$FLAVOR.desc <<EOT
746 Flavor : $FLAVOR
747 Description : $SHORT_DESC
748 EOT
749 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
750 Version : $VERSION
751 EOT
752 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
753 Maintainer : $MAINTAINER
754 EOT
755 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
756 LiveCD RAM size : $FRUGAL_RAM
757 EOT
758 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
759 Rootfs list : $ROOTFS_SELECTION
760 EOT
761 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
762 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
763 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
764 Rootfs size : $ROOTFS_SIZE
765 Initramfs size : $INITRAMFS_SIZE
766 ISO image size : $ISO_SIZE
767 ================================================================================
769 EOT
770 rm -f $TMP_DIR/packages.list
771 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
772 gzip -9 > $FLAVOR.flavor
773 status
774 rm -Rf $TMP_DIR
775 else
776 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
777 fi
778 }
780 # tazlito extract-flavor
781 extract_flavor()
782 {
783 # Extract a flavor into $FLAVORS_REPOSITORY.
784 FLAVOR=${1%.flavor}
785 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
786 mkdir $TMP_DIR
787 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
788 echo -n "Extracting $FLAVOR..."
789 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
790 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
791 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
792 grep ^Description $TMP_DIR/$FLAVOR.desc | \
793 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
794 $FLAVORS_REPOSITORY/$FLAVOR/receipt
795 grep ^Version $TMP_DIR/$FLAVOR.desc | \
796 sed 's/.*: \(.*\)$/VERSION="\1"/' >> \
797 $FLAVORS_REPOSITORY/$FLAVOR/receipt
798 grep ^Maintainer $TMP_DIR/$FLAVOR.desc | \
799 sed 's/.*: \(.*\)$/MAINTAINER="\1"/' >> \
800 $FLAVORS_REPOSITORY/$FLAVOR/receipt
801 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
802 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
803 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
804 $FLAVORS_REPOSITORY/$FLAVOR/receipt
805 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
806 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
807 $FLAVORS_REPOSITORY/$FLAVOR/receipt
808 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
809 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
810 $FLAVORS_REPOSITORY/$FLAVOR/receipt
811 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
812 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
813 $FLAVORS_REPOSITORY/$FLAVOR/receipt
814 for i in rootcd rootfs; do
815 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
816 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
817 zcat $TMP_DIR/$FLAVOR.$i | \
818 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
819 cpio -idm > /dev/null)
820 done
821 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
822 cp $TMP_DIR/$FLAVOR.mirrors \
823 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
824 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
825 while read org; do
826 i=0
827 pkg=$org
828 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
829 pkg=${pkg%-*}
830 i=$(($i + 1))
831 [ $i -gt 5 ] && break;
832 done
833 echo $pkg
834 done < $TMP_DIR/$FLAVOR.pkglist \
835 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
836 status
837 rm -Rf $TMP_DIR
838 fi
839 }
841 # tazlito show-flavor
842 show_flavor()
843 {
844 # Show flavor description.
845 FLAVOR=${1%.flavor}
846 if [ ! -f "$FLAVOR.flavor" ]; then
847 echo "File $FLAVOR.flavor not found."
848 exit 1
849 fi
850 mkdir $TMP_DIR
851 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
852 if [ "$2" = "--brief" ]; then
853 if [ "$3" != "--noheader" ]; then
854 echo "Name ISO Rootfs Description"
855 separator
856 fi
857 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
858 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
859 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
860 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
861 else
862 separator
863 cat $TMP_DIR/$FLAVOR.desc
864 fi
865 rm -Rf $TMP_DIR
866 }
868 # tazlito list-flavors
869 list_flavors()
870 {
871 # Show available flavors.
872 if [ ! -s /tmp/flavors.list -o "$2" == "--recharge" ]; then
873 download flavors.list -O - > /tmp/flavors.list
874 fi
875 newline
876 echo -e "\033[1mList of flavors\033[0m"
877 separator
878 cat /tmp/flavors.list
879 newline
880 }
882 # tazlito extract-distro
883 extract_distro()
884 {
885 # Extract an ISO image to a directory and rebuild the LiveCD tree.
886 #
887 check_root
888 ISO_IMAGE=$1
889 if [ -z "$ISO_IMAGE" ] ; then
890 echo -e "\nPlease specify the path to the ISO image."
891 echo -e "Example : `basename $0` image.iso /path/target\n"
892 exit 0
893 fi
894 # Set the distro path by checking for $3 on cmdline.
895 if [ -n "$2" ] ; then
896 TARGET=$2
897 else
898 TARGET=$DISTRO
899 fi
900 # Exit if existing distro is found.
901 if [ -d "$TARGET/rootfs" ] ; then
902 echo -e "\nA rootfs exists in : $TARGET"
903 echo -e "Please clean the distro tree or change directory path.\n"
904 exit 0
905 fi
906 newline
907 echo -e "\033[1mExtracting :\033[0m `basename $ISO_IMAGE`"
908 separator
909 # Start to mount the ISO.
910 newline
911 echo "Mounting ISO image..."
912 mkdir -p $TMP_DIR
913 # Get ISO file size.
914 isosize=$(du -sh $ISO_IMAGE | cut -f1)
915 mount -o loop $ISO_IMAGE $TMP_DIR
916 sleep 2
917 # Prepare target dir, copy the kernel and the rootfs.
918 mkdir -p $TARGET/rootfs
919 mkdir -p $TARGET/rootcd/boot
920 echo -n "Copying the Linux kernel..."
921 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
922 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
923 else
924 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
925 fi
926 status
927 echo -n "Copying isolinux files..."
928 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
929 for i in $(ls $TMP_DIR); do
930 [ "$i" = "boot" ] && continue
931 cp -a $TMP_DIR/$i $TARGET/rootcd
932 done
933 status
934 if [ -d $TMP_DIR/boot/syslinux ]; then
935 echo -n "Copying syslinux files..."
936 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
937 status
938 fi
939 if [ -d $TMP_DIR/boot/extlinux ]; then
940 echo -n "Copying extlinux files..."
941 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
942 status
943 fi
944 if [ -d $TMP_DIR/boot/grub ]; then
945 echo -n "Copying GRUB files..."
946 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
947 status
948 fi
949 echo -n "Copying the rootfs..."
950 cp $TMP_DIR/boot/$INITRAMFS $TARGET/rootcd/boot
951 status
952 # Extract initramfs.
953 cd $TARGET/rootfs
954 echo -n "Extracting the rootfs... "
955 extract_rootfs $TARGET/rootfs/rootcd/boot/$INITRAMFS $TARGET/rootfs
956 # unpack /usr
957 for i in etc/tazlito/*.extract; do
958 [ -f "$i" ] && . $i ../rootcd
959 done
960 # Umount and remove temp directory and cd to $TARGET to get stats.
961 umount $TMP_DIR && rm -rf $TMP_DIR
962 cd ..
963 newline
964 separator
965 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
966 echo "Distro tree : `pwd`"
967 echo "Rootfs size : `du -sh rootfs`"
968 echo "Rootcd size : `du -sh rootcd`"
969 separator
970 newline
971 }
973 # tazlito update-flavor
974 update_flavor()
975 {
976 # Update package list to the latest versions available.
977 FLAVOR=${1%.flavor}
978 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
979 mkdir $TMP_DIR
980 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
981 echo -n "Updating $FLAVOR package list..."
982 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
983 packed_size=0; unpacked_size=0
984 while read org; do
985 i=0
986 pkg=$org
987 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
988 pkg=${pkg%-*}
989 i=$(($i + 1))
990 [ $i -gt 5 ] && break;
991 done
992 set -- $(get_size $pkg)
993 packed_size=$(( $packed_size + $1 ))
994 unpacked_size=$(( $unpacked_size + $2 ))
995 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
996 echo $i
997 break
998 done
999 done < $TMP_DIR/$FLAVOR.pkglist \
1000 > $TMP_DIR/$FLAVOR.pkglist.$$
1001 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1002 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1003 packed_size=$(($packed_size \
1004 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1005 unpacked_size=$(($unpacked_size \
1006 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1007 fi
1008 # Estimate lzma
1009 packed_size=$(($packed_size * 2 / 3))
1010 iso_size=$(( $packed_size + 26000 ))
1011 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1012 iso_size=$(($iso_size \
1013 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1014 fi
1015 sed -i -e '/Image is ready/d' \
1016 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1017 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1018 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1019 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1020 $TMP_DIR/$FLAVOR.desc
1021 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1022 $FLAVOR.flavor
1023 status
1024 rm -Rf $TMP_DIR
1025 fi
1026 }
1028 # tazlito check-distro
1029 check_distro()
1030 {
1031 # Check for a few LiveCD needed files not installed by packages.
1032 #
1033 check_rootfs
1034 newline
1035 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
1036 separator
1037 # SliTaz release info.
1038 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
1039 echo "Missing release info : /etc/slitaz-release"
1040 else
1041 release=$(cat $ROOTFS/etc/slitaz-release)
1042 echo -n "Release : $release"
1043 status
1044 fi
1045 # Tazpkg mirror.
1046 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
1047 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
1048 todomsg
1049 else
1050 echo -n "Mirror configuration exists..."
1051 status
1052 fi
1053 # Isolinux msg
1054 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
1055 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
1056 todomsg
1057 else
1058 echo -n "Isolinux message seems good..."
1059 status
1060 fi
1061 separator
1062 newline
1063 }
1065 # tazlito writeiso
1066 writeiso()
1067 {
1068 # Writefs to ISO image including /home unlike gen-distro we dont use
1069 # packages to generate a rootfs, we build a compressed rootfs with all
1070 # the current filesystem similar to 'tazusb writefs'.
1071 #
1072 DISTRO="/home/slitaz/$SLITAZ_VERSION/distro"
1073 ROOTCD="$DISTRO/rootcd"
1074 if [ -z $1 ]; then
1075 COMPRESSION=none
1076 else
1077 COMPRESSION=$1
1078 fi
1079 if [ -z $2 ]; then
1080 ISO_NAME="slitaz"
1081 else
1082 ISO_NAME="$2"
1083 fi
1084 check_root
1085 # Start info
1086 newline
1087 echo -e "\033[1mWrite filesystem to ISO\033[0m
1088 ===============================================================================
1089 The command writeiso will write the current filesystem into a suitable cpio
1090 archive ($INITRAMFS) and generate a bootable ISO image (slitaz.iso).
1092 Archive compression: $COMPRESSION"
1093 newline
1095 # Save some space
1096 rm /var/cache/tazpkg/* -r -f
1097 [ -d $DISTRO ] && rm -rf $DISTRO
1099 # Optionally remove sound card selection and screen resolution.
1100 echo "Do you wish to remove the sound card and screen configs ? "
1101 echo -n "Press ENTER to keep or answer (No|yes|exit): "
1102 read anser
1103 case $anser in
1104 e|E|"exit"|Exit)
1105 exit 0 ;;
1106 y|Y|yes|Yes)
1107 echo -n "Removing current sound card and screen configurations..."
1108 rm -f /var/lib/sound-card-driver
1109 rm -f /etc/asound.state
1110 rm -f /etc/X11/screen.conf
1111 rm -f /etc/X11/xorg.conf ;;
1112 *)
1113 echo -n "Keeping current sound card and screen configurations..." ;;
1114 esac
1115 status
1117 cd /
1118 # Create list of files including default user files since it is defined in /etc/passwd
1119 # and some new users might have been added.
1120 find bin etc init sbin var dev lib root usr home >/tmp/list
1122 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
1123 do
1124 echo $dir >>/tmp/list
1125 done
1127 # Generate initramfs with specified compression and display rootfs
1128 # size in realtime.
1129 rm -f /tmp/rootfs
1130 write_initramfs &
1131 sleep 2
1132 cd - > /dev/null
1133 echo -en "\nFilesystem size:"
1134 while [ ! -f /tmp/rootfs ]
1135 do
1136 sleep 1
1137 echo -en "\\033[18G`du -sh /$INITRAMFS | awk '{print $1}'` "
1138 done
1139 echo -e "\n"
1141 # Move freshly generated rootfs to the cdrom.
1142 mkdir -p $ROOTCD/boot
1143 mv -f /$INITRAMFS $ROOTCD/boot
1145 # Now we need the kernel and isolinux files.
1146 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
1147 cp /media/cdrom/boot/bzImage $ROOTCD/boot
1148 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
1149 unmeta_boot $ROOTCD
1150 umount /media/cdrom
1151 elif mount |grep /media/cdrom; then
1152 cp /media/cdrom/boot/bzImage $ROOTCD/boot
1153 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
1154 unmeta_boot $ROOTCD
1155 umount /media/cdrom;
1156 else
1157 echo -e "
1158 When SliTaz is running in RAM the kernel and bootloader files are kept
1159 on the cdrom. Please insert a LiveCD or loop mount the slitaz.iso to
1160 /media/cdrom to let Tazlito copy the files.\n"
1161 echo -en "----\nENTER to continue..."; read i
1162 exit 1
1163 fi
1165 # Generate the iso image.
1166 cd $DISTRO
1167 echo "Generating ISO image..."
1168 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
1169 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
1170 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
1171 if [ -x /usr/bin/isohybrid ]; then
1172 echo -n "Creating hybrid ISO..."
1173 /usr/bin/isohybrid $ISO_NAME.iso -entry 2 2> /dev/null
1174 status
1175 fi
1176 echo -n "Creating the ISO $CHECKSUM..."
1177 $CHECKSUM $ISO_NAME.iso > $ISO_NAME.$SUM
1178 status
1180 echo "==============================================================================="
1181 echo "ISO image: `du -sh $DISTRO/$ISO_NAME.iso`"
1182 newline
1183 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
1184 case $anser in
1185 burn)
1186 eject
1187 echo -n "Please insert a blank cdrom and press ENTER..."
1188 read i && sleep 2
1189 tazlito burn-iso $DISTRO/$ISO_NAME.iso
1190 echo -en "----\nENTER to continue..."; read i ;;
1191 *)
1192 exit 0 ;;
1193 esac
1194 }
1196 # tazlito repack
1197 repack()
1198 {
1199 # Repack an iso with maximum lzma compression ratio.
1200 #
1202 ISO=$1
1204 mkdir -p $TMP_DIR/mnt
1205 # Extract filesystems
1206 echo -n "Mounting $ISO"
1207 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
1208 status || cleanup_merge
1209 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1210 umount -d $TMP_DIR/mnt
1212 for i in $TMP_DIR/iso/boot/rootfs* ; do
1213 echo -n "Repacking $(basename $i)"
1214 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
1215 2>/dev/null > $TMP_DIR/rootfs
1216 lzma e $TMP_DIR/rootfs $i \
1217 $(lzma_switches $TMP_DIR/rootfs)
1218 status
1219 done
1221 create_iso $ISO $TMP_DIR/iso
1222 rm -rf $TMP_DIR
1223 }
1225 frugal_install()
1226 {
1227 ISO_IMAGE="$1"
1228 newline
1229 mkdir -p /boot/frugal
1230 if [ -f "$ISO_IMAGE" ]; then
1231 echo -n "Using ISO image: $ISO_IMAGE"
1232 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
1233 status
1234 echo -n "Installing the Kernel and rootfs..."
1235 cp -a /tmp/iso/boot/bzImage /boot/frugal
1236 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
1237 cd /tmp/iso/boot
1238 cat $(ls -r rootfs*.gz) > /boot/frugal/$INITRAMFS
1239 else
1240 cp -a /tmp/iso/boot/$INITRAMFS /boot/frugal
1241 fi
1242 umount /tmp/iso
1243 status
1244 else
1245 echo -n "Using distro: $DISTRO"
1246 cd $DISTRO && status
1247 echo -n "Installing the Kernel and rootfs..."
1248 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
1249 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
1250 cd $DISTRO/rootcd/boot
1251 cat $(ls -r rootfs*.gz) > /boot/frugal/$INITRAMFS
1252 else
1253 cp -a $DISTRO/rootcd/boot/$INITRAMFS /boot/frugal
1254 fi
1255 status
1256 fi
1257 # Grub entry
1258 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
1259 echo -n "Configuring GRUB menu list..."
1260 cat >> /boot/grub/menu.lst << EOT
1261 title SliTaz GNU/Linux (frugal)
1262 root (hd0,0)
1263 kernel /boot/frugal/bzImage root=/dev/null
1264 initrd /boot/frugal/rootfs.gz
1265 EOT
1266 else
1267 echo -n "GRUB menu list is up-to-date..."
1268 fi
1269 status
1270 newline
1271 }