cookutils view modules/pack @ rev 1120

modules/pack: fix compatibility with variables set in genpkg_rules()
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Dec 22 13:07:38 2018 +0200 (2018-12-22)
parents f87179115961
children 1a99de37dc73
line source
1 #!/bin/sh
2 #
3 # pack - module of the SliTaz Cook
4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
5 #
7 . /usr/lib/slitaz/libcook.sh
10 ######################################################
11 # BEGIN: Functions may be used in the genpkg_rules() #
12 ######################################################
15 # A bit smarter function than the classic `cp` command
17 scopy() {
18 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
19 cp -a "$1" "$2" # copy generic files
20 else
21 cp -al "$1" "$2" # copy hardlinks
22 fi
23 }
26 # Copy specified files from $install to $fs
28 cook_copy_files() {
29 action 'Copying files...'
30 cd $install
31 local i j
32 IFS=$'\n'
33 for i in $@; do
34 for j in $(find . -name $i ! -type d); do
35 mkdir -p $fs$(dirname ${j#.})
36 scopy $j $fs$(dirname ${j#.})
37 done
38 done
39 cd - >/dev/null
40 status
41 }
44 # Copy specified folders from $install to $fs
46 cook_copy_folders() {
47 action 'Copying folders...'
48 cd $install
49 local i j
50 IFS=$'\n'
51 for i in $@; do
52 for j in $(find . -name $i -type d); do
53 mkdir -p $fs$(dirname ${j#.})
54 cp -a $j $fs$(dirname ${j#.})
55 done
56 done
57 cd - >/dev/null
58 status
59 }
62 # Remove from current $fs files that are already packed (for receipts v2).
63 # Note: the order in $SPLIT is very important.
64 # Note 2: working in the current set.
66 remove_already_packed() {
67 local i j
68 # $pkg is the name of the main package; $PACKAGE is the name of the current one
69 # $pkg may (or may not) be included in the $SPLIT
70 neighbors=$(
71 echo $basepkg $SPLIT" " \
72 | awk -F$'\t' -vpkg="$thispkg" '
73 BEGIN { RS = " "; FS = ":"; }
74 { set[$1] = $2; }
75 END {
76 current_set = set[pkg];
77 for (i in set)
78 { if (i != pkg && set[i] == current_set) print i; }
79 }
80 ')
81 IFS=$'\n'
82 for neighbor in $neighbors; do
83 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
84 [ -e "$i" ] || continue
85 while read j; do
86 [ -f $fs$j -o -h $fs$j ] || continue
87 rm $fs$j
88 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
89 done < $i
90 done
91 unset IFS
92 }
95 # Copy hicolor icons in specified sizes (default: 16 and 48) from $install to $fs
97 cook_copy_icons() {
98 local sizes=$@ i j ifs="$IFS"
99 unset IFS
100 action 'Copying hicolor icons...'
101 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
102 mkdir -p $fs/usr/share/icons/hicolor
103 for i in ${sizes:-16 48}; do
104 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
105 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
106 scopy $install/usr/share/icons/hicolor/$j \
107 $fs/usr/share/icons/hicolor
108 done
109 status
110 IFS="$ifs"
111 }
114 # Common function to copy files, folders and patterns
116 copy() {
117 action 'Copying folders and files...'
118 local i j k filelist=$(mktemp) folderlist=$(mktemp)
120 IFS=$'\n'
121 cd $install
122 find ! -type d | sed 's|\.||' > $filelist
123 find -type d | sed 's|\.||' > $folderlist
125 for i in $@; do
126 case $i in
127 @std)
128 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
129 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
130 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
131 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
132 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
133 /\/share\/devhelp\//d; /\/share\/locale\//d;
134 /\/share\/bash-completion\//d; /\/etc\/bash_completion\.d\//d; /\/lib\/systemd\//d;
135 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
136 /\/share\/appdata\//d; /\/share\/help\//d; /\/share\/metainfo\//d; /\/share\/mimelnk\//d;
137 /\/share\/application-registry\//d; /\/share\/mime-info\//d;
138 /\/share\/gnome\/help\//d; /\/share\/omf\//d;
139 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
140 /\.so\.dbg$/d;
141 ' $filelist
142 ;;
143 @dev)
144 # Copy "developer files"
145 sed -n '
146 /\/share\/doc\//d;
147 /\.h$/p; /\.hxx$/p; /\.a$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
148 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
149 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
150 /\.so\.dbg$/p;
151 ' $filelist
152 ;;
153 @ruby)
154 # Copy mandatory Ruby files
155 gem_base="\/usr\/lib\/ruby\/gems\/.*\/${PACKAGE#*-}-$VERSION"
156 sed -n '/\/extensions\/.*\.so$/p; /'$gem_base'\/lib\//p; /\.gemspec$/p;
157 /\/usr\/bin\//p; /\/gems\/.*\/bin\//p;
158 ' $filelist | sed '/\/gems\/.*\/lib\/.*\.so$/d; /\/gems\/.*\/lib\/.*\.h$/d;
159 /\/gems\/.*\/gems\/.*\.gemspec$/d;'
160 ;;
161 @ruby-dev)
162 sed -n '/\/ext\/.*\.h$/p; /\/ext\/.*\.pc$/p; /\/gem.build_complete$/p;
163 /\/gems\/.*\/lib\/.*\.h$/p;
164 ' $filelist
165 ;;
166 @rm)
167 # Quick alias
168 remove_already_packed
169 ;;
170 @ico)
171 # Quick alias
172 cook_copy_icons >/dev/null
173 ;;
174 */)
175 # Copy specified folders.
176 i="${i%/}"
177 find -type d -path "*/${i#/}" | sed 's|^.||'
178 ;;
179 *)
180 # Copy specified files.
181 find ! -type d -path "*/${i#/}" | sed 's|^.||'
182 ;;
183 esac \
184 | sort -u \
185 | while read j; do
186 mkdir -p $fs$(dirname "$j")
187 if [ -d "$install$j" ]; then
188 cp -a "$install$j" $fs$(dirname "$j")
189 else
190 scopy "$install$j" $fs$(dirname "$j")
191 fi
192 done
193 # Copy empty directories
194 case $i in
195 @std)
196 while read j; do
197 case $j in
198 # skip empty man & doc folders
199 */man/*|*/doc/*) continue;;
200 esac
201 [ -z "$(ls -A "$install$j")" ] || continue
202 # directory $j is empty
203 k="$j"
204 # make 'ladder' from directories, from root dir to $j
205 # /a /a/b /a/b/c etc.
206 while :; do
207 [ -z "$k" ] && break
208 echo "$k"
209 k="${k%/*}"
210 done \
211 | tac \
212 | while read k; do
213 # make dir if it does not exist
214 if [ ! -d "$fs$k" ]; then
215 # It's like "copy the directory without its underlying content".
216 # keep original ownership/permissions, access:
217 keepIFS="$IFS"; unset IFS
218 install -d $(stat -c'-o%u -g%g -m%a' "$install$k") "$fs$k"
219 # keep last-modified date:
220 touch -r "$install$k" "$fs$k"
221 IFS="$keepIFS"; unset keepIFS
222 fi
223 done
224 done < $folderlist
225 ;;
226 esac
227 done
228 cd - >/dev/null
229 unset IFS
230 rm $filelist $folderlist
231 status
232 }
234 ####################################################
235 # END: Functions may be used in the genpkg_rules() #
236 ####################################################
241 # Receipt used for cooking the package is redundant to be included into package.
242 # This script will strip the original receipt to bare minimum: variables,
243 # {pre,post}_{install,remove} functions.
245 mk_pkg_receipt() {
246 orig_receipt="$1"
248 # 1. Main package.
249 # By default it has no dependencies.
250 # You can write or omit DEPENDS="" for indicating packages that have no
251 # dependencies.
252 # 2. Split package (excluding *-dev).
253 # By default every split package depends on the main package.
254 # Unfortunately, in the shell script (receipt is the shell script too),
255 # every undeclared variable has an empty value, so there's no difference if
256 # you wrote DEPENDS="" or omit it - result will be the same empty value.
257 # If you want to define that the split package has no dependencies - you need
258 # to to put a single space between the quotes: DEPENDS=" ".
259 # 3. Development split package.
260 # Installing *-dev package should install all the files produced during
261 # compilation and then were separated into the different packages, so
262 # by default (if you wrote DEPENDS="" or omit it) *-dev package depends
263 # on the main package and all the split packages (excluding itself).
264 [ "$DEPENDS" == ' ' ] && DEPENDS='@EMPTY@'
266 # Receipt's signature is important, although some receipts may miss it
267 signature=$(head -n1 "$orig_receipt")
268 [ "${signature:0:1}" == '#' ] || signature='# SliTaz package receipt.'
270 save="$(mktemp)"
271 # `$(echo ...)`: normalize whitespace (space, tab, newline and their
272 # combinations and repeats)
273 cat > $save <<EOT
274 PACKAGE="$PACKAGE"; DEPENDS="$(echo $DEPENDS)"; PROVIDE="$(echo $PROVIDE)"
275 SUGGESTED="$(echo $SUGGESTED)"; TAZPANEL_DAEMON="$TAZPANEL_DAEMON"
276 TAGS="$(echo $TAGS)"; VERSION="$VERSION"; SHORT_DESC="$SHORT_DESC"
277 WEB_SITE="$WEB_SITE"; CATEGORY="$CATEGORY"
278 EOT
279 unset_receipt
280 . "$orig_receipt"
281 MAIN_PACKAGE="$PACKAGE"
282 . $save; rm $save # restore values
284 # Manage split packages
285 SPLIT=" $SPLIT "
286 if [ "$PACKAGE" != "$MAIN_PACKAGE" -a "$SPLIT" != ' ' ] &&
287 echo "$SPLIT" | fgrep -q " $PACKAGE "; then
288 # For packages with empty $DEPENDS
289 if [ -z "$DEPENDS" ]; then
290 case $PACKAGE in
291 *-dev)
292 # main package and all the split packages but this *-dev itself
293 DEPENDS=$(echo "$MAIN_PACKAGE $SPLIT " | sed "s| $PACKAGE | |; s| *$||");;
294 *)
295 DEPENDS="$MAIN_PACKAGE";;
296 esac
297 fi
299 # Default $CAT
300 [ -z "$CAT" ] &&
301 case $PACKAGE in
302 *-dev) CAT="development|development files" ;;
303 esac
304 fi
306 # Manage two-in-one $CAT="$CATEGORY|$SHORT_DESC_ADDITION"
307 if [ -n "$CAT" ]; then
308 CATEGORY="${CAT%|*}"
309 SHORT_DESC="$SHORT_DESC (${CAT#*|})"
310 fi
312 # escape quotes for receipt
313 SHORT_DESC="${SHORT_DESC//\"/\\\"}"
315 # Mandatory variables
316 cat <<-EOF
317 $signature
319 PACKAGE="$PACKAGE"
320 VERSION="$VERSION"
321 EOF
322 [ -n "$EXTRAVERSION" ] && echo "EXTRAVERSION=\"$EXTRAVERSION\""
323 cat <<-EOF
324 CATEGORY="$CATEGORY"
325 SHORT_DESC="$SHORT_DESC"
326 MAINTAINER="$MAINTAINER"
327 LICENSE="$LICENSE"
328 WEB_SITE="$WEB_SITE"
329 EOF
331 # Optional variables
332 [ -n "$TAGS" ] && echo "TAGS=\"$TAGS\"" | tr -ds '\t' ' '
333 case "x$DEPENDS" in
334 x|x@EMPTY@) ;;
335 *) echo "DEPENDS=\"$DEPENDS\"" | tr -ds '\t' ' ';;
336 esac
337 [ -n "$PROVIDE" ] && echo "PROVIDE=\"$PROVIDE\"" | tr -ds '\t' ' '
338 [ -n "$CONFIG_FILES" ] && echo "CONFIG_FILES=\"$CONFIG_FILES\"" | tr -ds '\t' ' '
339 [ -n "$SUGGESTED" ] && echo "SUGGESTED=\"$SUGGESTED\"" | tr -ds '\t' ' '
340 [ -n "$DATABASE_FILES" ] && echo "DATABASE_FILES=\"$DATABASE_FILES\""
341 [ -n "$TAZPANEL_DAEMON" ] && echo "TAZPANEL_DAEMON=\"$TAZPANEL_DAEMON\""
343 # Extract {pre,post}_{install,remove} functions;
344 # post_install() will be copied for both main and all the split packages
345 # post_install_gtk_() will be copied as post_install() for gtk+ package only
346 #
347 # restricted name (gtk+ -> gtk_; acl-dev -> acl_dev)
348 rname=$(echo -n $PACKAGE | tr -c 'a-zA-Z0-9' '_')
349 for i in pre post; do
350 for j in install remove; do
351 sed "/^${i}_${j}()/,/^}/!d" "$orig_receipt"
352 sed "/^${i}_${j}_$rname()/,/^}/!d" "$orig_receipt" \
353 | sed "s|^${i}_${j}_$rname()|${i}_${j}()|"
354 done
355 done
356 }
359 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
360 # We use standard paths, so some packages need to copy these files with the
361 # receipt and genpkg_rules.
362 # This function executes inside the packaging process, before compressor call.
364 copy_generic_files() {
365 # $LOCALE is set in cook.conf
366 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
367 if [ -d "$install/usr/share/locale" ]; then
368 mkdir -p "$fs/usr/share/locale"
369 for i in $LOCALE; do
370 if [ -d "$install/usr/share/locale/$i" ]; then
371 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
372 fi
373 done
374 fi
375 fi
377 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
378 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
379 if [ -d "$install/usr/share/pixmaps" ]; then
380 mkdir -p "$fs/usr/share/pixmaps"
381 for i in png xpm; do
382 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
383 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
384 done
385 fi
386 fi
388 # Desktop entry (.desktop).
389 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
390 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
391 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
392 mkdir -p "$fs/usr/share"
393 cp -r $install/usr/share/applications $fs/usr/share
394 fi
395 fi
396 }
399 # Determine package architecture
400 # Input: $1 = $fs; output string: i486 | x86_64 | any
402 determine_pkg_arch() {
403 if [ "${COOKOPTS/force-arch/}" != "$COOKOPTS" ]; then
404 action 'Forced package architecture to' >&2
405 echo " $ARCH" >&2
406 arch="$ARCH"
407 else
408 action 'Determining package architecture...' >&2
409 archs="$(
410 IFS=$'\n'
411 {
412 # examine all the executables and static libs (*.a)
413 busybox find "$1" -type f \( -perm +111 -o -name '*.a' \) \
414 | while read i; do
415 readelf -Wh "$i" 2>/dev/null \
416 | sed '/Machine:/!d; s|.* ||'
417 done
419 # examine compressed kernel modules (we use exclusively *.ko.xz)
420 tmpko=$(mktemp)
421 find "$1" -type f -name '*.ko.xz' \
422 | while read i; do
423 unxz -kc $i >$tmpko
424 readelf -Wh "$tmpko" 2>/dev/null \
425 | sed '/Machine:/!d; s|.* ||'
426 done
427 rm $tmpko
429 # examine Guile *.go files (Machine: None, so check Class)
430 find "$1" -type f -name '*.go' \
431 | while read i; do
432 readelf -Wh "$i" 2>/dev/null \
433 | sed '/Class:/!d; s|.* ||'
434 done \
435 | sed 's|ELF32|80386|; s|ELF64|X86-64|'
436 } | sort -u
437 )"
439 case $archs in
440 80386) arch='i486'; echo ' i486' >&2;;
441 X86-64) arch='x86_64'; echo ' x86_64' >&2;;
442 '') arch='any'; echo ' any' >&2;;
443 *) arch="$ARCH"; echo ' ' $archs >&2
444 echo "Warning: weird architecture found, forced to use $ARCH for now." >&2
445 ;;
446 esac
447 fi
449 touch $pkgdir/.arch
450 sed -i "/^$PACKAGE /d" $pkgdir/.arch # remove previous entry
451 echo "$PACKAGE $arch" >> $pkgdir/.arch # put new one
453 echo $arch
454 }
457 # Find the variables inside receipt
459 find_vars() {
460 # You can define variables in the root of the receipt describing
461 # the dependencies (or tags, config files, etc.) for each sub-package.
462 # Example:
463 # PACKAGE="cool"
464 # SPLIT="$PACKAGE-extra libcool $PACKAGE-dev"
465 #
466 # DEPENDS_cool or DEPENDS_std # latter is the universal name for main package deps
467 # DEPENDS_cool_extra or DEPENDS_extra # you can skip "$PACKAGE" at the start
468 # DEPENDS_libcool # name not starts with "$PACKAGE" so no "short" name
469 # DEPENDS_cool_dev or DEPENDS_dev
471 local out
472 local var=$1
473 local pkg=$(echo -n $2 | tr -c 'a-zA-Z0-9' '_')
474 local end=$(echo -n ${2#$basepkg-} | tr -c 'a-zA-Z0-9' '_')
475 if [ "$2" == "$basepkg" ]; then
476 eval out="\$${var}_$pkg" # DEPENDS_cool
477 [ -n "$out" ] || eval out="\$${var}_std" # DEPENDS_std
478 [ -n "$out" ] || eval out="\$$var" # DEPENDS
479 else
480 eval out="\$${var}_$pkg" # DEPENDS_cool_extra
481 [ -n "$out" ] || eval out="\$${var}_$end" # DEPENDS_extra
482 fi
483 echo "$out"
484 }
487 # Create the package
489 packit() {
490 basepkg="$PACKAGE"
491 thispkg="$1"
493 pkgdir="$WOK/$basepkg"
494 receipt="$pkgdir/receipt"
495 . $receipt
497 title 'Pack: %s' "$thispkg $VERSION"
500 #
501 # Set variables
502 #
504 # Determine set name for specified package from $SPLIT variable
505 local set=$(echo -n $SPLIT \
506 | awk -vpkg="$thispkg" '
507 BEGIN { RS = " "; FS = ":"; }
508 { if ($1 == pkg && $2 != "") { print "-" $2; exit; } }')
510 # Set paths
511 export stuff="$pkgdir/stuff"
512 export src="$pkgdir/source/$basepkg-$VERSION$set"
513 export install="$pkgdir/install$set"
514 export DESTDIR="$install"
515 export taz="$pkgdir/taz"
516 export pack="$taz/$thispkg-$VERSION$EXTRAVERSION"
517 export fs="$pack/fs"
519 export PACKAGE=$thispkg
522 #
523 # Execute genpkg_rules()
524 #
526 require_copy='yes'
527 [ "${COOKOPTS/empty-pkg/}" != "$COOKOPTS" ] && require_copy='no'
529 if grep -q ^genpkg_rules $receipt; then
530 _ 'Executing: %s' 'genpkg_rules'
531 set -e
532 cd $pkgdir; mkdir -p $fs
533 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> $LOGS/$pkg.log
534 require_copy='no'
535 else
536 cd $pkgdir; mkdir -p $fs
537 if [ "$CATEGORY" == 'meta' -a "$thispkg" == "$basepkg" ]; then
538 _ 'No packages rules: meta package'
539 require_copy='no'
540 fi
541 fi
543 # Auto-packing
545 for i in DEPENDS SUGGESTED PROVIDE CONFIG_FILES TAGS CATEGORY CAT COPY; do
546 # variable may be already set in genpkg_rules(), check it
547 eval tmpvar="\$i"
548 [ -n "$tmpvar" ] && continue
549 eval $i="\$(find_vars $i $thispkg)"
550 done
552 [ -n "$CAT" ] && CATEGORY=$(echo "$CAT" | cut -d'|' -f1)
554 if [ "$CATEGORY" != 'meta' -a "$CATEGORY" != 'nopack' ]; then
555 if [ -z "$COPY" -a "$require_copy" == 'yes' ]; then
556 case "$thispkg" in
557 $basepkg) COPY='@std @rm';;
558 *-dev) COPY='@dev @rm';;
559 lib$basepkg) COPY='*.so*';;
560 esac
561 fi
563 if [ -n "$COPY" ]; then
564 copy $COPY
565 elif [ "$require_copy" == 'yes' ]; then
566 var=$(echo -n COPY_$thispkg | tr -c 'a-zA-Z0-9' '_')
567 die "ERROR: $var rules undefined"
568 fi
569 fi
571 if [ "$CATEGORY" == 'nopack' ]; then
572 echo "Skipping $thispkg"
573 return
574 fi
577 #
578 # Check CONFIG_FILES
579 #
581 if [ -n "$CONFIG_FILES" ]; then
582 unset IFS
583 for i in $CONFIG_FILES; do
584 if [ ! -e $fs$i ]; then
585 case $i in
586 */) mkdir -p $fs$i ;;
587 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
588 esac
589 fi
590 done
591 fi
593 # First QA check to stop now if genpkg_rules failed.
594 if fgrep -q '^ERROR' $LOGS/$basepkg.log; then
595 broken; exit 1
596 fi
599 #
600 # Copy receipt and description
601 #
603 cd $taz
604 action 'Copying "%s"...' 'receipt'
605 mk_pkg_receipt "$(realpath ../receipt)" > $pack/receipt
606 chown 0:0 $pack/receipt
607 status
609 unset desc
610 # description common to all the sub-packages
611 [ -f "../description.txt" ] && desc="../description.txt"
612 # description for specified sub-package
613 [ -f "../description.$thispkg.txt" ] && desc="../description.$thispkg.txt"
614 if [ -n "$desc" ]; then
615 action 'Copying "%s"...' "$(basename "$desc")"
616 cp -f $desc $pack/description.txt
617 chown 0:0 $pack/description.txt
618 status
619 fi
622 #
623 # Copy generic files
624 #
626 # Proceed only for "main" package (for v2), and for any packages (v1)
627 [ "$thispkg" == "$mainpkg" ] && copy_generic_files
630 #
631 # Strip / compress files
632 #
634 arch="$(determine_pkg_arch $fs)"
636 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
639 #
640 # Make lists
641 #
643 # Create files.list
644 action 'Creating the list of files...'
645 cd $fs
646 find . \( -type f -o -type l \) | sed 's|^.||' > ../files.list
647 cd ..
648 status
650 # Md5sum of files.
651 action 'Creating md5sum of files...'
652 while read file; do
653 [ -L "fs$file" ] && continue
654 [ -f "fs$file" ] || continue
655 case "$file" in
656 /lib/modules/*/modules.*|*.pyc) continue ;;
657 esac
658 md5sum "fs$file" | sed 's| fs| |'
659 done < files.list | sort -k2 > md5sum
660 status
663 #
664 # Calculate release checksum
665 #
667 # Usually it does not change on "just recook".
668 # Md5sum of the *.tazpkg will change every time because of embedded timestamps;
669 # on the other hand release checksums don't rely on the timestamps, but
670 # only on files content and their permissions.
672 # Calculate rsum for new package
673 RSUM=$(
674 {
675 # a) md5sums of all files
676 cat $pack/md5sum
677 # b) md5sum of receipt
678 md5sum $pack/receipt | sed 's| [^ ]*/| |'
679 # c) md5sum of description.txt
680 [ -e "$pack/description.txt" ] &&
681 md5sum $pack/description.txt | sed 's| [^ ]*/| |'
682 # d) md5sum of list of permissions and ownership of all the files and
683 # folders of the package
684 # stat line example: -rwsr-xr-x 0:0 ./bin/busybox
685 {
686 cd $fs
687 find . -print0 | sort -z | xargs -0rn 1 stat -c '%A %g:%u %N' | md5sum
688 }
689 } | md5sum $rsum_file | awk '{print $1}')
692 #
693 # Compressing
694 #
696 UNPACKED_SIZE=$(du -cks fs receipt files.list md5sum description.txt \
697 2>/dev/null | awk 'END{ print $1 "K"}')
699 # Build fs cpio archive
700 action 'Compressing the FS...'
701 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
702 # find fs | cpio -o -H newc --quiet | lzma-alone e fs.cpio.lzma -si
703 find fs | cpio -o -H newc --quiet | /bin/lzma -qzeT0 >fs.cpio.lzma
704 mv fs ../
705 status
707 PACKED_SIZE=$(du -cks fs.cpio.lzma receipt files.list md5sum description.txt \
708 2>/dev/null | awk 'END{ print $1 "K"}')
711 #
712 # Add variables to the receipt
713 #
715 # Store sizes
716 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
717 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
719 # Store RSUM
720 sed -i "s|^PACKAGE=|RSUM=\"$RSUM\"\nPACKAGE=|" receipt
722 # Set extra version
723 if [ -n "$EXTRAVERSION" ]; then
724 sed -i '/^EXTRAVERSION=/d' receipt
725 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
726 fi
729 #
730 # Build *.tazpkg
731 #
733 action 'Creating full cpio archive...'
734 find . -newer $receipt -exec touch -hr $receipt '{}' \;
735 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION-$arch.tazpkg
736 status
738 # Restoring original package tree.
739 mv ../fs .
741 rm fs.cpio.lzma; cd ..
743 tazpkg=$(ls *.tazpkg)
746 #
747 # Verify package quality and consistency
748 #
750 # Preferrable way is to combine the commands chain in the compile_rules()
751 # using '&&': when any of the chunk broke, process will stop and function
752 # will return non-zero return code.
753 # On the other hand some old receipts don't use '&&' but depend on the
754 # error messages on the log.
755 # Sometimes it produces false positives in the configuration stage.
756 # In this case we can use the "skip-log-errors".
757 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ]; then
758 # Exit if any error found in log file.
759 if fgrep -q ^ERROR $LOGS/$basepkg.log; then
760 rm -f $command
761 broken; exit 1
762 fi
763 fi
766 # Allow meta-packages in v2 receipts
767 [ -n "$CAT" ] && CATEGORY="${CAT%|*}"
769 if [ "${COOKOPTS/empty-pkg/}" == "$COOKOPTS" ]; then
770 action 'QA: checking for empty package...'
771 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
772 broken
773 rm -f $command
774 false; status
775 die 'ERROR: empty package'
776 fi
777 :; status
778 fi
781 #
782 # Get RSUM from the old package
783 #
785 pkg_file="$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$arch.tazpkg"
786 if [ -f "$pkg_file" ]; then
787 # don't trust database entry, check the package file
788 tmpdir=$(mktemp -d)
789 cd $tmpdir
790 cpio -F "$pkg_file" -i receipt >/dev/null 2>&1
791 RSUM_OLD=$(unset RSUM; . receipt; echo $RSUM)
792 cd - >/dev/null
793 rm -r $tmpdir
794 else
795 unset RSUM_OLD
796 fi
799 #
800 # Removing unhandled old packages
801 #
803 if [ $ARCH == 'i486' -a -e $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg ]; then
804 action 'Removing old i486 package without arch specifier'
805 rm -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
806 status
807 fi
809 # For example, if *-dev package contains *.a static libs, it will be either
810 # i486 or x86_64 arch; otherwise it will be "any" arch. This transition
811 # may be done back and forth depending on if you disable static libs or not.
812 case $arch in
813 any)
814 if [ -e $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg ]; then
815 action "Removing old $ARCH package because it arch-less now"
816 rm -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg
817 status
818 fi
819 ;;
820 *)
821 if [ -e $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-any.tazpkg ]; then
822 action "Removing old arch-less package because it $ARCH now"
823 rm -f $PKGS/$PACKAGE-$VERSION$EXTRAVERSION-any.tazpkg
824 status
825 fi
826 ;;
827 esac
829 # Find and remove old package only if "release checksum" has changed
831 pi="$PKGS/packages-$ARCH.info"
832 touch $pi
834 if [ "$RSUM" != "$RSUM_OLD" ]; then
835 old_file=$(awk -F$'\t' -vname="$PACKAGE" -varch="$arch" '{
836 if ($1 == name) printf("%s-%s-%s.tazpkg", $1, $2, arch);
837 }' $pi) # <name>-<version><extra_version>-<arch>.tazpkg
838 if [ -f "$PKGS/$old_file" ]; then
839 action 'Removing old package "%s"' "$old_file"
840 rm -f "$PKGS/$old_file"
841 status
842 fi
843 # package changed, substitute old package for new one
844 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION-$arch.tazpkg $PKGS
845 _ 'The release checksum has changed.'
846 else
847 # package not changed, remove new package
848 rm -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION-$arch.tazpkg
849 _ 'The release checksum has not changed.'
850 fi
853 #
854 # Package isn't broken anymore
855 #
857 touch $broken
858 sed -i "/^${thispkg}$/d" $broken
861 #
862 # Update packages database every time after successful build
863 #
865 # packages-arch.info (unsorted, located near to packages)
866 unset_receipt; . $pack/receipt
867 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
868 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
869 case $arch in
870 i?86) arch_code='3';; # 3 for 32-bit
871 x86_64) arch_code='6';; # 6 for 64-bit
872 any) arch_code='0';; # 0 for any arch
873 esac
875 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
876 cat >> $pi <<EOT
877 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE $arch_code
878 EOT
880 # files.list (uncompressed, unsorted, located in $cache)
881 fl="$cache/files.list"
882 touch $fl
883 sed -i "/^$PACKAGE: /d" $fl
884 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
886 footer "$(_ 'Package "%s" created' "$tazpkg")"
887 }
890 packit "$1"