cookutils view lib/libcookiso.sh @ rev 526

libcookiso.sh: Change tazlito to cookiso. Add some more functions from tazlito.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Aug 25 06:45:02 2012 +0000 (2012-08-25)
parents 8e961ff6b711
children 39f3a73df0ea
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/cookiso.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/slitaz/*.$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/slitaz/info ]; then
187 if [ $(stat -c %s /etc/slitaz/info) -lt $(( 31*1024 )) ]; then
188 echo -n "Storing ISO info..."
189 dd if=/etc/slitaz/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 # Create an empty configuration file.
374 empty_config_file()
375 {
376 cat >> tazlito.conf << "EOF"
377 # tazlito.conf: Tazlito (SliTaz Live Tool)
378 # configuration file.
379 #
381 # Name of the ISO image to generate.
382 ISO_NAME=""
384 # ISO image volume name.
385 VOLUM_NAME="SliTaz"
387 # Name of the preparer.
388 PREPARED="$USER"
390 # Path to the packages repository and the packages.list.
391 PACKAGES_REPOSITORY=""
393 # Path to the distro tree to gen-distro from a
394 # list of packages.
395 DISTRO=""
397 # Path to the directory containing additional files
398 # to copy into the rootfs and rootcd of the LiveCD.
399 ADDFILES="$DISTRO/addfiles"
401 # Default answer for binary question (Y or N)
402 DEFAULT_ANSWER="ASK"
404 # Compression utility (lzma, gzip or none)
405 COMPRESSION="lzma"
406 EOF
407 }
409 # Display package list with version, set packed_size and unpacked_size
410 get_pkglist()
411 {
412 packed_size=0; unpacked_size=0
413 grep -v ^# $FLAVORS_REPOSITORY/$1/packages.list > $TMP_DIR/flavor.pkg
414 while read pkg; do
415 set -- $(get_size $pkg)
416 packed_size=$(( $packed_size + $1 ))
417 unpacked_size=$(( $unpacked_size + $2 ))
418 for i in $(grep -hs ^$pkg $LOCALSTATE/packages.list \
419 $TMP_DIR/packages.list); do
420 echo $i
421 break
422 done
423 done < $TMP_DIR/flavor.pkg
424 rm -f $TMP_DIR/flavor.pkg
425 }
427 human2cent()
428 {
429 case "$1" in
430 *k) echo $1 | sed 's/\(.*\).\(.\)k/\1\2/';;
431 *M) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)M/\1\2/') * 1024));;
432 *G) echo $(( $(echo $1 | sed 's/\(.*\).\(.\)G/\1\2/') * 1024 * 1024));;
433 esac
434 }
436 cent2human()
437 {
438 if [ $1 -lt 10000 ]; then
439 echo "$(($1 / 10)).$(($1 % 10))k"
440 elif [ $1 -lt 10000000 ]; then
441 echo "$(($1 / 10240)).$(( ($1/1024) % 10))M"
442 else
443 echo "$(($1 / 10485760)).$(( ($1/1048576) % 10))G"
444 fi
445 }
447 get_size()
448 {
449 cat $LOCALSTATE/packages.list $TMP_DIR/packages.list 2>/dev/null | awk "{ \
450 if (/^$(echo $1 | sed 's/[$+.\]/\\&/g')$/) get=1; \
451 if (/installed/ && get == 1) { print ; get++ } \
452 }
453 END { if (get < 2) print \" 0.0k (0.0k installed)\" }" | \
454 sed 's/ *\(.*\) .\(.*\) installed./\1 \2/' | while read packed unpacked; do
455 echo "$(human2cent $packed) $(human2cent $unpacked)"
456 done
457 }
459 # extract rootfs.gz somewhere
460 extract_rootfs()
461 {
462 (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \
463 (cd $2; cpio -idm > /dev/null)
464 }
466 # Remove duplicate files
467 mergefs()
468 {
469 echo -n "Merge $(basename $1) ($(du -hs $1 | awk '{ print $1}')) into "
470 echo -n "$(basename $2) ($(du -hs $2 | awk '{ print $1}'))"
471 # merge symlinks files and devices
472 ( cd $1; find ) | while read file; do
473 if [ -L $1/$file ]; then
474 [ -L $2/$file ] &&
475 [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] &&
476 rm -f $2/$file
477 elif [ -f $1/$file ]; then
478 [ -f $2/$file ] &&
479 cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file
480 [ -f $2/$file ] &&
481 [ "$(basename $file)" == "volatile.cpio.gz" ] &&
482 [ "$(dirname $(dirname $file))" == \
483 ".$INSTALLED" ] && rm -f $2/$file
484 elif [ -b $1/$file ]; then
485 [ -b $2/$file ] &&
486 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
487 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
488 rm -f $2/$file
489 elif [ -c $1/$file ]; then
490 [ -c $2/$file ] &&
491 [ "$(stat -c '%a:%u:%g:%t:%T' $1/$file)" == \
492 "$(stat -c '%a:%u:%g:%t:%T' $2/$file)" ] &&
493 rm -f $2/$file
494 fi
495 done
497 # cleanup directories
498 ( cd $1; find -type d ) | sed '1!G;h;$!d' | while read file; do
499 [ -d $2/$file ] && rmdir $2/$file 2> /dev/null
500 done
501 true
502 status
503 }
505 cleanup_merge()
506 {
507 rm -rf $TMP_DIR
508 exit 1
509 }
511 # tazlito gen-distro
512 gen_distro()
513 {
514 check_root
515 time=$(date +%s)
517 # Check if a package list was specified on cmdline.
518 DISTRO_LIST="distro-packages.list"
519 LIST_NAME="$DISTRO_LIST"
520 unset CDROM
521 while [ -n "$1" ]; do
522 case "$1" in
523 --iso=*)
524 CDROM="-o loop ${2#--iso=}"
525 ;;
526 --cdrom)
527 CDROM="/dev/cdrom"
528 ;;
529 --force)
530 DELETE_ROOTFS="true"
531 ;;
532 *) if [ ! -f "$1" ] ; then
533 echo -e "\nUnable to find the specified packages list."
534 echo -e "List name : $1\n"
535 exit 1
536 fi
537 LIST_NAME=$1
538 ;;
539 esac
540 shift
541 done
543 if [ -d $ROOTFS ] ; then
544 # Delete $ROOTFS if --force is set on command line
545 if [ ! -z $DELETE_ROOTFS ]; then
546 rm -rf $ROOTFS
547 unset $DELETE_ROOTFS
548 else
549 echo -e "\nA rootfs exists in : $DISTRO"
550 echo -e "Please clean the distro tree or change directory path.\n"
551 exit 0
552 fi
553 fi
554 if [ ! -f "$LIST_NAME" -a -d $INSTALLED ] ; then
555 # Build list with installed packages
556 for i in $(ls $INSTALLED); do
557 eval $(grep ^VERSION= $INSTALLED/$i/receipt)
558 EXTRAVERSION=""
559 eval $(grep ^EXTRAVERSION= $INSTALLED/$i/receipt)
560 echo "$i-$VERSION$EXTRAVERSION" >> $LIST_NAME
561 done
562 fi
563 # Exit if no list name.
564 if [ ! -f "$LIST_NAME" ]; then
565 echo -e "\nNo packages list found or specified. Please read the docs.\n"
566 exit 0
567 fi
568 # Start generation.
569 newline
570 echo -e "\033[1mGenerating a distro\033[0m"
571 separator
572 # Misc checks
573 [ -n "$PACKAGES_REPOSITORY" ] || PACKAGES_REPOSITORY="."
574 [ -d $PACKAGES_REPOSITORY ] || mkdir -p $PACKAGES_REPOSITORY
575 # Get the list of packages using cat for a file list.
576 LIST=$(cat $LIST_NAME)
577 # Verify if all packages in list are present in $PACKAGES_REPOSITORY.
578 unset REPACK DOWNLOAD
579 for pkg in $LIST
580 do
581 [ "$pkg" = "" ] && continue
582 pkg=${pkg%.tazpkg}
583 [ -f $PACKAGES_REPOSITORY/$pkg.tazpkg ] && continue
584 PACKAGE=$(installed_package_name $pkg)
585 [ -n "$PACKAGE" -a "$REPACK" = "y" ] && continue
586 [ -z "$PACKAGE" -a -n "$DOWNLOAD" ] && continue
587 echo -e "\nUnable to find $pkg in the repository."
588 echo -e "Path : $PACKAGES_REPOSITORY\n"
589 if [ -n "$PACKAGE" -a -z "$REPACK" ]; then
590 yesorno "Repack packages from rootfs (y/N) ? "
591 REPACK="$answer"
592 [ "$answer" = "y" ] || REPACK="n"
593 [ "$DOWNLOAD" = "y" ] && break
594 fi
595 if [ -f $MIRROR -a -z "$DOWNLOAD" ]; then
596 yesorno "Download packages from mirror (Y/n) ? "
597 DOWNLOAD="$answer"
598 if [ "$answer" = "n" ]; then
599 [ -z "$PACKAGE" ] && exit 1
600 else
601 DOWNLOAD="y"
602 [ -n "$REPACK" ] && break
603 fi
604 fi
605 [ "$REPACK" = "n" -a "$DOWNLOAD" = "n" ] && exit 1
606 done
608 # Mount cdrom to be able to repack boot-loader packages
609 if [ ! -e /boot -a -n "$CDROM" ]; then
610 mkdir $TMP_MNT
611 if mount -r $CDROM $TMP_MNT 2> /dev/null; then
612 ln -s $TMP_MNT/boot /
613 if [ ! -d "$ADDFILES/rootcd" ] ; then
614 mkdir -p $ADDFILES/rootcd
615 for i in $(ls $TMP_MNT); do
616 [ "$i" = "boot" ] && continue
617 cp -a $TMP_MNT/$i $ADDFILES/rootcd
618 done
619 fi
620 else
621 rmdir $TMP_MNT
622 fi
623 fi
625 # Root fs stuff.
626 echo "Preparing the rootfs directory..."
627 mkdir -p $ROOTFS
628 for pkg in $LIST
629 do
630 [ "$pkg" = "" ] && continue
631 # First copy and extract the package in tmp dir.
632 pkg=${pkg%.tazpkg}
633 PACKAGE=$(installed_package_name $pkg)
634 mkdir -p $TMP_DIR
635 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
636 # Look for package in cache
637 if [ -f $CACHE_DIR/$pkg.tazpkg ]; then
638 ln -s $CACHE_DIR/$pkg.tazpkg $PACKAGES_REPOSITORY
639 # Look for package in running distribution
640 elif [ -n "$PACKAGE" -a "$REPACK" = "y" ]; then
641 tazpkg repack $PACKAGE && \
642 mv $pkg.tazpkg $PACKAGES_REPOSITORY
643 fi
644 fi
645 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
646 # Get package from mirror
647 [ "$DOWNLOAD" = "y" ] && \
648 download $pkg.tazpkg && \
649 mv $pkg.tazpkg $PACKAGES_REPOSITORY
650 fi
651 if [ ! -f $PACKAGES_REPOSITORY/$pkg.tazpkg ]; then
652 echo "Missing package $pkg."
653 cleanup
654 exit 1
655 fi
656 done
657 if [ -f non-free.list ]; then
658 echo "Preparing non-free packages..."
659 cp non-free.list $ROOTFS/etc/slitaz/non-free.list
660 for pkg in $(cat non-free.list); do
661 if [ ! -d $INSTALLED/$pkg ]; then
662 if [ ! -d $INSTALLED/get-$pkg ]; then
663 tazpkg get-install get-$pkg
664 fi
665 get-$pkg
666 fi
667 tazpkg repack $pkg
668 pkg=$(ls $pkg*.tazpkg)
669 grep -q "^$pkg$" $LIST_NAME || \
670 echo $pkg >>$LIST_NAME
671 mv $pkg $PACKAGES_REPOSITORY
672 done
673 fi
674 cp $LIST_NAME $DISTRO/$DISTRO_LIST
675 sed 's/\(.*\)/\1.tazpkg/' < $DISTRO/$DISTRO_LIST > $DISTRO/list-packages
676 cd $PACKAGES_REPOSITORY
677 for pkg in $(cat $DISTRO/list-packages)
678 do
679 echo -n "Installing package: $pkg"
680 yes y | tazpkg install $pkg --root=$ROOTFS 2>&1 >> $log || exit 1
681 status
682 done
683 rm -f $ROOTFS/$DB/packages.*
684 cd $DISTRO
685 cp $DISTRO_LIST $ROOTFS/etc/slitaz
686 # Copy all files from $ADDFILES/rootfs to the rootfs.
687 if [ -d "$ADDFILES/rootfs" ] ; then
688 echo -n "Copying addfiles content to the rootfs... "
689 cp -a $ADDFILES/rootfs/* $ROOTFS
690 status
691 fi
692 echo -n "Root filesystem is generated..." && status
693 # Root CD part.
694 echo -n "Preparing the rootcd directory..."
695 mkdir -p $ROOTCD
696 status
697 # Move the boot dir with the Linux kernel from rootfs.
698 # The boot dir goes directly on the CD.
699 if [ -d "$ROOTFS/boot" ] ; then
700 echo -n "Moving the boot directory..."
701 mv $ROOTFS/boot $ROOTCD
702 cd $ROOTCD/boot
703 ln vmlinuz-* bzImage
704 status
705 fi
706 cd $DISTRO
707 # Copy all files from $ADDFILES/rootcd to the rootcd.
708 if [ -d "$ADDFILES/rootcd" ] ; then
709 echo -n "Copying addfiles content to the rootcd... "
710 cp -a $ADDFILES/rootcd/* $ROOTCD
711 status
712 fi
713 # Execute the distro script used to perform tasks in the rootfs
714 # before compression. Give rootfs path in arg
715 [ -z $DISTRO_SCRIPT ] && DISTRO_SCRIPT=$TOP_DIR/distro.sh
716 if [ -x $DISTRO_SCRIPT ]; then
717 echo "Executing distro script..."
718 sh $DISTRO_SCRIPT $DISTRO
719 fi
720 if [ -s /etc/slitaz/rootfs.list ]; then
721 FLAVOR_LIST="$(awk '{ for (i = 2; i <= NF; i+=2) \
722 printf("%s ",$i) }' < /etc/slitaz/rootfs.list)"
723 sed -i "s/ *//;s/)/), flavors $FLAVOR_LIST/" \
724 $ROOTCD/boot/isolinux/isolinux.msg 2> /dev/null
725 [ -f $ROOTCD/boot/isolinux/ifmem.c32 ] ||
726 cp /boot/isolinux/ifmem.c32 $ROOTCD/boot/isolinux
727 n=0
728 last=$ROOTFS
729 while read flavor; do
730 n=$(($n+1))
731 echo "Building $flavor rootfs..."
732 if [ -d $flavors/$flavor ]; then
733 cp -a $flavors
734 [ -s $TOP_DIR/$flavor.flavor ] &&
735 cp $TOP_DIR/$flavor.flavor .
736 [ -s $flavor.flavor ] || download $flavor.flavor
737 zcat $flavor.flavor | cpio -i \
738 $flavor.pkglist $flavor.rootfs
739 sed 's/.*/&.tazpkg/' < $flavor.pkglist \
740 > $DISTRO/list-packages0$n
741 mkdir ${ROOTFS}0$n
742 cd $PACKAGES_REPOSITORY
743 yes y | tazpkg install-list \
744 $DISTRO/list-packages0$n --root=${ROOTFS}0$n
745 rm -rf ${ROOTFS}0$n/boot ${ROOTFS}0$n/$DB/packages.*
746 status
747 cd $DISTRO
748 if [ -s $flavor.rootfs ]; then
749 echo "Adding $flavor rootfs extra files..."
750 zcat $flavor.rootfs | \
751 ( cd ${ROOTFS}0$n ; cpio -idmu )
752 fi
753 mv $flavor.pkglist ${ROOTFS}0$n/etc/slitaz/$DISTRO_LIST
754 rm -f $flavor.flavor install-list
755 mergefs ${ROOTFS}0$n $last
756 last=${ROOTFS}0$n
757 fi
758 done <<EOT
759 $(awk '{ for (i = 4; i <= NF; i+=2) print $i; }' < /etc/slitaz/rootfs.list)
760 EOT
761 i=$(($n+1))
762 while [ $n -gt 0 ]; do
763 mv ${ROOTFS}0$n ${ROOTFS}$i
764 echo "Compression ${ROOTFS}0$n ($(du -hs ${ROOTFS}$i | awk '{ print $1 }')) ..."
765 gen_initramfs ${ROOTFS}$i
766 n=$(($n-1))
767 i=$(($i-1))
768 done
769 mv $ROOTFS ${ROOTFS}$i
770 gen_initramfs ${ROOTFS}$i
771 update_bootconfig $ROOTCD/boot/isolinux \
772 "$(cat /etc/slitaz/rootfs.list)"
773 else
774 # Initramfs and ISO image stuff.
775 gen_initramfs $ROOTFS
776 fi
777 gen_livecd_isolinux
778 distro_stats
779 cleanup
780 }
783 # tazlito clean-distro
784 clean_distro()
785 {
786 # Remove old distro tree.
787 #
788 check_root
789 newline
790 boldify "Cleaning : $DISTRO"
791 separator
792 if [ -d "$DISTRO" ] ; then
793 if [ -d "$ROOTFS" ] ; then
794 echo -n "Removing the rootfs..."
795 rm -f $DISTRO/$INITRAMFS
796 rm -rf $ROOTFS
797 status
798 fi
799 if [ -d "$ROOTCD" ] ; then
800 echo -n "Removing the rootcd..."
801 rm -rf $ROOTCD
802 status
803 fi
804 echo -n "Removing eventual ISO image..."
805 rm -f $DISTRO/$ISO_NAME.iso
806 rm -f $DISTRO/$ISO_NAME.$SUM
807 status
808 fi
809 separator
810 newline
811 }
813 # tazlito pack-flavor
814 pack_flavor()
815 {
816 # Create a flavor from $FLAVORS_REPOSITORY.
817 FLAVOR=${1%.flavor}
818 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/receipt ]; then
819 mkdir $TMP_DIR
820 echo -n "Creating flavor $FLAVOR..."
821 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
822 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/mirrors ]; then
823 cp $FLAVORS_REPOSITORY/$FLAVOR/mirrors \
824 $TMP_DIR/$FLAVOR.mirrors
825 for i in $(cat $TMP_DIR/$FLAVOR.mirrors); do
826 wget -O - $i/packages.list >> $TMP_DIR/packages.list
827 done
828 fi
829 #add distro;sh if exist
830 if [ -s $FLAVORS_REPOSITORY/$FLAVOR/distro.sh ]; then
831 cp $FLAVORS_REPOSITORY/$FLAVOR/distro.sh $TMP_DIR/$FLAVOR-distro.sh
832 fi
833 [ -s $FLAVORS_REPOSITORY/$FLAVOR/packages.list ] &&
834 get_pkglist $FLAVOR > $TMP_DIR/$FLAVOR.pkglist
835 if grep -q ^ROOTFS_SELECTION \
836 $FLAVORS_REPOSITORY/$FLAVOR/receipt; then
837 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
838 set -- $ROOTFS_SELECTION
839 [ -n "$FRUGAL_RAM" ] || FRUGAL_RAM=$1
840 [ -f $FLAVORS_REPOSITORY/$2/packages.list ] ||
841 extract_flavor $2
842 get_pkglist $2 > $TMP_DIR/$FLAVOR.pkglist
843 for i in rootcd rootfs; do
844 mkdir $TMP_DIR/$i
845 # Copy extra files from the first flavor
846 [ -d $FLAVORS_REPOSITORY/$2/$i ] &&
847 cp -a $FLAVORS_REPOSITORY/$2/$i $TMP_DIR
848 # Overload extra files by meta flavor
849 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] &&
850 cp -a $FLAVORS_REPOSITORY/$FLAVOR/$i $TMP_DIR
851 [ -n "$(ls $TMP_DIR/$i)" ] &&
852 ( cd $TMP_DIR/$i ; find . | cpio -o -H newc 2> /dev/null ) | \
853 gzip -9 >$TMP_DIR/$FLAVOR.$i
854 rm -rf $TMP_DIR/$i
855 done
856 else
857 for i in rootcd rootfs; do
858 [ -d $FLAVORS_REPOSITORY/$FLAVOR/$i ] || \
859 continue
860 ( cd $FLAVORS_REPOSITORY/$FLAVOR/$i ; \
861 find . | cpio -o -H newc 2> /dev/null ) | \
862 gzip -9 >$TMP_DIR/$FLAVOR.$i
863 done
864 fi
865 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
866 packed_size=$(($packed_size \
867 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
868 unpacked_size=$(($unpacked_size \
869 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
870 fi
871 # Estimate lzma
872 packed_size=$(($packed_size * 2 / 3))
873 iso_size=$(( $packed_size + 26000 ))
874 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
875 iso_size=$(($iso_size \
876 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
877 fi
878 VERSION=""
879 MAINTAINER=""
880 ROOTFS_SELECTION=""
881 ROOTFS_SIZE="$(cent2human $unpacked_size) (estimated)"
882 INITRAMFS_SIZE="$(cent2human $packed_size) (estimated)"
883 ISO_SIZE="$(cent2human $iso_size) (estimated)"
884 . $FLAVORS_REPOSITORY/$FLAVOR/receipt
885 cat > $TMP_DIR/$FLAVOR.desc <<EOT
886 Flavor : $FLAVOR
887 Description : $SHORT_DESC
888 EOT
889 [ -n "$VERSION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
890 Version : $VERSION
891 EOT
892 [ -n "$MAINTAINER" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
893 Maintainer : $MAINTAINER
894 EOT
895 [ -n "$FRUGAL_RAM" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
896 LiveCD RAM size : $FRUGAL_RAM
897 EOT
898 [ -n "$ROOTFS_SELECTION" ] && cat >> $TMP_DIR/$FLAVOR.desc <<EOT
899 Rootfs list : $ROOTFS_SELECTION
900 EOT
901 cat >> $TMP_DIR/$FLAVOR.desc <<EOT
902 Build date : $(date +%Y%m%d\ \at\ \%H:%M:%S)
903 Packages : $(grep -v ^# $TMP_DIR/$FLAVOR.pkglist | wc -l)
904 Rootfs size : $ROOTFS_SIZE
905 Initramfs size : $INITRAMFS_SIZE
906 ISO image size : $ISO_SIZE
907 ================================================================================
909 EOT
910 rm -f $TMP_DIR/packages.list
911 ( cd $TMP_DIR ; ls | cpio -o -H newc 2> /dev/null) | \
912 gzip -9 > $FLAVOR.flavor
913 status
914 rm -Rf $TMP_DIR
915 else
916 echo "No $FLAVOR flavor in $FLAVORS_REPOSITORY."
917 fi
918 }
920 # tazlito extract-flavor
921 extract_flavor()
922 {
923 # Extract a flavor into $FLAVORS_REPOSITORY.
924 FLAVOR=${1%.flavor}
925 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
926 mkdir $TMP_DIR
927 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
928 echo -n "Extracting $FLAVOR..."
929 rm -rf $FLAVORS_REPOSITORY/$FLAVOR 2> /dev/null
930 mkdir -p $FLAVORS_REPOSITORY/$FLAVOR
931 echo "FLAVOR=\"$FLAVOR\"" > $FLAVORS_REPOSITORY/$FLAVOR/receipt
932 grep ^Description $TMP_DIR/$FLAVOR.desc | \
933 sed 's/.*: \(.*\)$/SHORT_DESC="\1"/' >> \
934 $FLAVORS_REPOSITORY/$FLAVOR/receipt
935 grep ^Version $TMP_DIR/$FLAVOR.desc | \
936 sed 's/.*: \(.*\)$/VERSION="\1"/' >> \
937 $FLAVORS_REPOSITORY/$FLAVOR/receipt
938 grep ^Maintainer $TMP_DIR/$FLAVOR.desc | \
939 sed 's/.*: \(.*\)$/MAINTAINER="\1"/' >> \
940 $FLAVORS_REPOSITORY/$FLAVOR/receipt
941 grep -q '^Rootfs list' $TMP_DIR/$FLAVOR.desc && \
942 grep '^Rootfs list' $TMP_DIR/$FLAVOR.desc | \
943 sed 's/.*: \(.*\)$/ROOTFS_SELECTION="\1"/' >> \
944 $FLAVORS_REPOSITORY/$FLAVOR/receipt
945 grep '^Rootfs size' $TMP_DIR/$FLAVOR.desc | \
946 sed 's/.*: \(.*\)$/ROOTFS_SIZE="\1"/' >> \
947 $FLAVORS_REPOSITORY/$FLAVOR/receipt
948 grep ^Initramfs $TMP_DIR/$FLAVOR.desc | \
949 sed 's/.*: \(.*\)$/INITRAMFS_SIZE="\1"/' >> \
950 $FLAVORS_REPOSITORY/$FLAVOR/receipt
951 grep ^ISO $TMP_DIR/$FLAVOR.desc | \
952 sed 's/.*: \(.*\)$/ISO_SIZE="\1"/' >> \
953 $FLAVORS_REPOSITORY/$FLAVOR/receipt
954 for i in rootcd rootfs; do
955 [ -f $TMP_DIR/$FLAVOR.$i ] || continue
956 mkdir $FLAVORS_REPOSITORY/$FLAVOR/$i
957 zcat $TMP_DIR/$FLAVOR.$i | \
958 (cd $FLAVORS_REPOSITORY/$FLAVOR/$i; \
959 cpio -idm > /dev/null)
960 done
961 [ -s $TMP_DIR/$FLAVOR.mirrors ] &&
962 cp $TMP_DIR/$FLAVOR.mirrors \
963 $FLAVORS_REPOSITORY/$FLAVOR/mirrors
964 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
965 while read org; do
966 i=0
967 pkg=$org
968 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
969 pkg=${pkg%-*}
970 i=$(($i + 1))
971 [ $i -gt 5 ] && break;
972 done
973 echo $pkg
974 done < $TMP_DIR/$FLAVOR.pkglist \
975 > $FLAVORS_REPOSITORY/$FLAVOR/packages.list
976 status
977 rm -Rf $TMP_DIR
978 fi
979 }
981 # tazlito show-flavor
982 show_flavor()
983 {
984 # Show flavor description.
985 FLAVOR=${1%.flavor}
986 if [ ! -f "$FLAVOR.flavor" ]; then
987 echo "File $FLAVOR.flavor not found."
988 exit 1
989 fi
990 mkdir $TMP_DIR
991 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i > /dev/null)
992 if [ "$2" = "--brief" ]; then
993 if [ "$3" != "--noheader" ]; then
994 echo "Name ISO Rootfs Description"
995 separator
996 fi
997 printf "%-16.16s %6.6s %6.6s %s\n" "$FLAVOR" \
998 "$(field ISO $TMP_DIR/$FLAVOR.desc)" \
999 "$(field 'Rootfs size' $TMP_DIR/$FLAVOR.desc)" \
1000 "$(grep ^Description $TMP_DIR/$FLAVOR.desc | cut -d: -f2)"
1001 else
1002 separator
1003 cat $TMP_DIR/$FLAVOR.desc
1004 fi
1005 rm -Rf $TMP_DIR
1008 # tazlito list-flavors
1009 list_flavors()
1011 # Show available flavors.
1012 if [ ! -s /tmp/flavors.list -o "$2" == "--recharge" ]; then
1013 download flavors.list -O - > /tmp/flavors.list
1014 fi
1015 newline
1016 echo -e "\033[1mList of flavors\033[0m"
1017 separator
1018 cat /tmp/flavors.list
1019 newline
1022 # tazlito extract-distro
1023 extract_distro()
1025 # Extract an ISO image to a directory and rebuild the LiveCD tree.
1027 check_root
1028 ISO_IMAGE=$1
1029 if [ -z "$ISO_IMAGE" ] ; then
1030 echo -e "\nPlease specify the path to the ISO image."
1031 echo -e "Example : `basename $0` image.iso /path/target\n"
1032 exit 0
1033 fi
1034 # Set the distro path by checking for $3 on cmdline.
1035 if [ -n "$2" ] ; then
1036 TARGET=$2
1037 else
1038 TARGET=$DISTRO
1039 fi
1040 # Exit if existing distro is found.
1041 if [ -d "$TARGET/rootfs" ] ; then
1042 echo -e "\nA rootfs exists in : $TARGET"
1043 echo -e "Please clean the distro tree or change directory path.\n"
1044 exit 0
1045 fi
1046 newline
1047 echo -e "\033[1mExtracting :\033[0m `basename $ISO_IMAGE`"
1048 separator
1049 # Start to mount the ISO.
1050 newline
1051 echo "Mounting ISO image..."
1052 mkdir -p $TMP_DIR
1053 # Get ISO file size.
1054 isosize=$(du -sh $ISO_IMAGE | cut -f1)
1055 mount -o loop $ISO_IMAGE $TMP_DIR
1056 sleep 2
1057 # Prepare target dir, copy the kernel and the rootfs.
1058 mkdir -p $TARGET/rootfs
1059 mkdir -p $TARGET/rootcd/boot
1060 echo -n "Copying the Linux kernel..."
1061 if cp $TMP_DIR/boot/vmlinuz* $TARGET/rootcd/boot 2> /dev/null; then
1062 ln $TARGET/rootcd/boot/vmlinuz* $TARGET/rootcd/boot/bzImage
1063 else
1064 cp $TMP_DIR/boot/bzImage $TARGET/rootcd/boot
1065 fi
1066 status
1067 echo -n "Copying isolinux files..."
1068 cp -a $TMP_DIR/boot/isolinux $TARGET/rootcd/boot
1069 for i in $(ls $TMP_DIR); do
1070 [ "$i" = "boot" ] && continue
1071 cp -a $TMP_DIR/$i $TARGET/rootcd
1072 done
1073 status
1074 if [ -d $TMP_DIR/boot/syslinux ]; then
1075 echo -n "Copying syslinux files..."
1076 cp -a $TMP_DIR/boot/syslinux $TARGET/rootcd/boot
1077 status
1078 fi
1079 if [ -d $TMP_DIR/boot/extlinux ]; then
1080 echo -n "Copying extlinux files..."
1081 cp -a $TMP_DIR/boot/extlinux $TARGET/rootcd/boot
1082 status
1083 fi
1084 if [ -d $TMP_DIR/boot/grub ]; then
1085 echo -n "Copying GRUB files..."
1086 cp -a $TMP_DIR/boot/grub $TARGET/rootcd/boot
1087 status
1088 fi
1089 echo -n "Copying the rootfs..."
1090 cp $TMP_DIR/boot/$INITRAMFS $TARGET/rootcd/boot
1091 status
1092 # Extract initramfs.
1093 cd $TARGET/rootfs
1094 echo -n "Extracting the rootfs... "
1095 extract_rootfs $TARGET/rootfs/rootcd/boot/$INITRAMFS $TARGET/rootfs
1096 # unpack /usr
1097 for i in etc/slitaz/*.extract; do
1098 [ -f "$i" ] && . $i ../rootcd
1099 done
1100 # Umount and remove temp directory and cd to $TARGET to get stats.
1101 umount $TMP_DIR && rm -rf $TMP_DIR
1102 cd ..
1103 newline
1104 separator
1105 echo "Extracted : `basename $ISO_IMAGE` ($isosize)"
1106 echo "Distro tree : `pwd`"
1107 echo "Rootfs size : `du -sh rootfs`"
1108 echo "Rootcd size : `du -sh rootcd`"
1109 separator
1110 newline
1113 # tazlito update-flavor
1114 update_flavor()
1116 # Update package list to the latest versions available.
1117 FLAVOR=${1%.flavor}
1118 if [ -f $FLAVOR.flavor ] || download $FLAVOR.flavor; then
1119 mkdir $TMP_DIR
1120 zcat $FLAVOR.flavor | ( cd $TMP_DIR; cpio -i >/dev/null )
1121 echo -n "Updating $FLAVOR package list..."
1122 [ -s $LOCALSTATE/packages.list ] || tazpkg recharge
1123 packed_size=0; unpacked_size=0
1124 while read org; do
1125 i=0
1126 pkg=$org
1127 while ! grep -q ^$pkg$ $LOCALSTATE/packages.txt; do
1128 pkg=${pkg%-*}
1129 i=$(($i + 1))
1130 [ $i -gt 5 ] && break;
1131 done
1132 set -- $(get_size $pkg)
1133 packed_size=$(( $packed_size + $1 ))
1134 unpacked_size=$(( $unpacked_size + $2 ))
1135 for i in $(grep ^$pkg $LOCALSTATE/packages.list); do
1136 echo $i
1137 break
1138 done
1139 done < $TMP_DIR/$FLAVOR.pkglist \
1140 > $TMP_DIR/$FLAVOR.pkglist.$$
1141 mv -f $TMP_DIR/$FLAVOR.pkglist.$$ $TMP_DIR/$FLAVOR.pkglist
1142 if [ -s $TMP_DIR/$FLAVOR.rootfs ]; then
1143 packed_size=$(($packed_size \
1144 + $(cat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1145 unpacked_size=$(($unpacked_size \
1146 + $(zcat $TMP_DIR/$FLAVOR.rootfs | wc -c ) / 100 ))
1147 fi
1148 # Estimate lzma
1149 packed_size=$(($packed_size * 2 / 3))
1150 iso_size=$(( $packed_size + 26000 ))
1151 if [ -s $TMP_DIR/$FLAVOR.rootcd ]; then
1152 iso_size=$(($iso_size \
1153 + $(zcat $TMP_DIR/$FLAVOR.rootcd | wc -c ) / 100 ))
1154 fi
1155 sed -i -e '/Image is ready/d' \
1156 -e "s/Rootfs size\( *:\) \(.*\)/Rootfs size\1 $(cent2human $unpacked_size) (estimated)/" \
1157 -e "s/Initramfs size\( *:\) \(.*\)/Initramfs size\1 $(cent2human $packed_size) (estimated)/" \
1158 -e "s/ISO image size\( *:\) \(.*\)/ISO image size\1 $(cent2human $iso_size) (estimated)/" \
1159 -e "s/date\( *:\) \(.*\)/date\1 $(date +%Y%m%d\ \at\ \%H:%M:%S)/" \
1160 $TMP_DIR/$FLAVOR.desc
1161 ( cd $TMP_DIR ; ls | cpio -o -H newc ) | gzip -9 > \
1162 $FLAVOR.flavor
1163 status
1164 rm -Rf $TMP_DIR
1165 fi
1168 # tazlito check-distro
1169 check_distro()
1171 # Check for a few LiveCD needed files not installed by packages.
1173 check_rootfs
1174 newline
1175 echo -e "\033[1mChecking distro :\033[0m $ROOTFS"
1176 separator
1177 # SliTaz release info.
1178 if [ ! -f "$ROOTFS/etc/slitaz-release" ]; then
1179 echo "Missing release info : /etc/slitaz-release"
1180 else
1181 release=$(cat $ROOTFS/etc/slitaz-release)
1182 echo -n "Release : $release"
1183 status
1184 fi
1185 # Tazpkg mirror.
1186 if [ ! -f "$ROOTFS$LOCALSTATE/mirror" ]; then
1187 echo -n "Mirror URL : Missing $LOCALSTATE/mirror"
1188 todomsg
1189 else
1190 echo -n "Mirror configuration exists..."
1191 status
1192 fi
1193 # Isolinux msg
1194 if grep -q "cooking-XXXXXXXX" /$ROOTCD/boot/isolinux/isolinux.*g; then
1195 echo -n "Isolinux msg : Missing cooking date XXXXXXXX (ex `date +%Y%m%d`)"
1196 todomsg
1197 else
1198 echo -n "Isolinux message seems good..."
1199 status
1200 fi
1201 separator
1202 newline
1205 # tazlito writeiso
1206 writeiso()
1208 # Writefs to ISO image including /home unlike gen-distro we dont use
1209 # packages to generate a rootfs, we build a compressed rootfs with all
1210 # the current filesystem similar to 'tazusb writefs'.
1212 DISTRO="/home/slitaz/$SLITAZ_VERSION/distro"
1213 ROOTCD="$DISTRO/rootcd"
1214 if [ -z $1 ]; then
1215 COMPRESSION=none
1216 else
1217 COMPRESSION=$1
1218 fi
1219 if [ -z $2 ]; then
1220 ISO_NAME="slitaz"
1221 else
1222 ISO_NAME="$2"
1223 fi
1224 check_root
1225 # Start info
1226 newline
1227 echo -e "\033[1mWrite filesystem to ISO\033[0m
1228 ===============================================================================
1229 The command writeiso will write the current filesystem into a suitable cpio
1230 archive ($INITRAMFS) and generate a bootable ISO image (slitaz.iso).
1232 Archive compression: $COMPRESSION"
1233 newline
1235 # Save some space
1236 rm /var/cache/tazpkg/* -r -f
1237 [ -d $DISTRO ] && rm -rf $DISTRO
1239 # Optionally remove sound card selection and screen resolution.
1240 echo "Do you wish to remove the sound card and screen configs ? "
1241 echo -n "Press ENTER to keep or answer (No|yes|exit): "
1242 read anser
1243 case $anser in
1244 e|E|"exit"|Exit)
1245 exit 0 ;;
1246 y|Y|yes|Yes)
1247 echo -n "Removing current sound card and screen configurations..."
1248 rm -f /var/lib/sound-card-driver
1249 rm -f /etc/asound.state
1250 rm -f /etc/X11/screen.conf
1251 rm -f /etc/X11/xorg.conf ;;
1252 *)
1253 echo -n "Keeping current sound card and screen configurations..." ;;
1254 esac
1255 status
1257 cd /
1258 # Create list of files including default user files since it is defined in /etc/passwd
1259 # and some new users might have been added.
1260 find bin etc init sbin var dev lib root usr home >/tmp/list
1262 for dir in proc sys tmp mnt media media/cdrom media/flash media/usbdisk
1263 do
1264 echo $dir >>/tmp/list
1265 done
1267 # Generate initramfs with specified compression and display rootfs
1268 # size in realtime.
1269 rm -f /tmp/rootfs
1270 write_initramfs &
1271 sleep 2
1272 cd - > /dev/null
1273 echo -en "\nFilesystem size:"
1274 while [ ! -f /tmp/rootfs ]
1275 do
1276 sleep 1
1277 echo -en "\\033[18G`du -sh /$INITRAMFS | awk '{print $1}'` "
1278 done
1279 echo -e "\n"
1281 # Move freshly generated rootfs to the cdrom.
1282 mkdir -p $ROOTCD/boot
1283 mv -f /$INITRAMFS $ROOTCD/boot
1285 # Now we need the kernel and isolinux files.
1286 if mount /dev/cdrom /media/cdrom 2>/dev/null; then
1287 cp /media/cdrom/boot/bzImage $ROOTCD/boot
1288 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
1289 unmeta_boot $ROOTCD
1290 umount /media/cdrom
1291 elif mount |grep /media/cdrom; then
1292 cp /media/cdrom/boot/bzImage $ROOTCD/boot
1293 cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
1294 unmeta_boot $ROOTCD
1295 umount /media/cdrom;
1296 else
1297 echo -e "
1298 When SliTaz is running in RAM the kernel and bootloader files are kept
1299 on the cdrom. Please insert a LiveCD or loop mount the slitaz.iso to
1300 /media/cdrom to let cookiso copy the files.\n"
1301 echo -en "----\nENTER to continue..."; read i
1302 exit 1
1303 fi
1305 # Generate the iso image.
1306 cd $DISTRO
1307 echo "Generating ISO image..."
1308 genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
1309 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
1310 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
1311 if [ -x /usr/bin/isohybrid ]; then
1312 echo -n "Creating hybrid ISO..."
1313 /usr/bin/isohybrid $ISO_NAME.iso -entry 2 2> /dev/null
1314 status
1315 fi
1316 echo -n "Creating the ISO $CHECKSUM..."
1317 $CHECKSUM $ISO_NAME.iso > $ISO_NAME.$SUM
1318 status
1320 echo "==============================================================================="
1321 echo "ISO image: `du -sh $DISTRO/$ISO_NAME.iso`"
1322 newline
1323 echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
1324 case $anser in
1325 burn)
1326 eject
1327 echo -n "Please insert a blank cdrom and press ENTER..."
1328 read i && sleep 2
1329 burn_iso $DISTRO/$ISO_NAME.iso
1330 echo -en "----\nENTER to continue..."; read i ;;
1331 *)
1332 exit 0 ;;
1333 esac
1336 # tazlito repack
1337 repack()
1339 # Repack an iso with maximum lzma compression ratio.
1342 ISO=$1
1344 mkdir -p $TMP_DIR/mnt
1345 # Extract filesystems
1346 echo -n "Mounting $ISO"
1347 mount -o loop,ro $ISO $TMP_DIR/mnt 2> /dev/null
1348 status || cleanup_merge
1349 cp -a $TMP_DIR/mnt $TMP_DIR/iso
1350 umount -d $TMP_DIR/mnt
1352 for i in $TMP_DIR/iso/boot/rootfs* ; do
1353 echo -n "Repacking $(basename $i)"
1354 (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \
1355 2>/dev/null > $TMP_DIR/rootfs
1356 lzma e $TMP_DIR/rootfs $i \
1357 $(lzma_switches $TMP_DIR/rootfs)
1358 status
1359 done
1361 create_iso $ISO $TMP_DIR/iso
1362 rm -rf $TMP_DIR
1365 frugal_install()
1367 ISO_IMAGE="$1"
1368 newline
1369 mkdir -p /boot/frugal
1370 if [ -f "$ISO_IMAGE" ]; then
1371 echo -n "Using ISO image: $ISO_IMAGE"
1372 mkdir -p /tmp/iso && mount -o loop $ISO_IMAGE /tmp/iso
1373 status
1374 echo -n "Installing the Kernel and rootfs..."
1375 cp -a /tmp/iso/boot/bzImage /boot/frugal
1376 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
1377 cd /tmp/iso/boot
1378 cat $(ls -r rootfs*.gz) > /boot/frugal/$INITRAMFS
1379 else
1380 cp -a /tmp/iso/boot/$INITRAMFS /boot/frugal
1381 fi
1382 umount /tmp/iso
1383 status
1384 else
1385 echo -n "Using distro: $DISTRO"
1386 cd $DISTRO && status
1387 echo -n "Installing the Kernel and rootfs..."
1388 cp -a $DISTRO/rootcd/boot/bzImage /boot/frugal
1389 if [ -f $DISTRO/rootcd/boot/rootfs1.gz ]; then
1390 cd $DISTRO/rootcd/boot
1391 cat $(ls -r rootfs*.gz) > /boot/frugal/$INITRAMFS
1392 else
1393 cp -a $DISTRO/rootcd/boot/$INITRAMFS /boot/frugal
1394 fi
1395 status
1396 fi
1397 # Grub entry
1398 if ! grep -q "^kernel /boot/frugal/bzImage" /boot/grub/menu.lst; then
1399 echo -n "Configuring GRUB menu list..."
1400 cat >> /boot/grub/menu.lst << EOT
1401 title SliTaz GNU/Linux (frugal)
1402 root (hd0,0)
1403 kernel /boot/frugal/bzImage root=/dev/null
1404 initrd /boot/frugal/rootfs.gz
1405 EOT
1406 else
1407 echo -n "GRUB menu list is up-to-date..."
1408 fi
1409 status
1410 newline