cookutils view modules/mk_pkg_receipt @ rev 999

cook: move mk_pkg_receipt() into module. Fix bug here: when main package was listed in $SPLIT, it was dependent on itself.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Nov 04 05:07:30 2017 +0200 (2017-11-04)
parents
children d807a30eadfe
line source
1 #!/bin/sh
2 #
3 # mk_pkg_receipt - module of the SliTaz Cook
4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
5 #
7 # Receipt used for cooking the package is redundant to be included into package.
8 # This script will strip the original receipt to bare minimum: variables,
9 # {pre,post}_{install,remove} functions.
11 . /usr/lib/slitaz/libcook.sh
13 orig_receipt="$1"
15 # Receipt's signature is important, although some receipts may miss it
16 signature=$(head -n1 "$orig_receipt")
17 [ "${signature:0:1}" == '#' ] || signature='# SliTaz package receipt.'
19 save="$(mktemp)"
20 cat > $save <<EOT
21 PACKAGE="$PACKAGE"; DEPENDS="$DEPENDS"; PROVIDE="$PROVIDE"
22 SUGGESTED="$SUGGESTED"; TAZPANEL_DAEMON="$TAZPANEL_DAEMON"
23 TAGS="$TAGS"
24 EOT
25 unset_receipt
26 . "$orig_receipt"
27 MAIN_PACKAGE="$PACKAGE"
28 . $save; rm $save # restore values
30 # Manage split packages
31 SPLIT=" $SPLIT "
32 if [ "$PACKAGE" != "$MAIN_PACKAGE" -a \
33 "$SPLIT" != ' ' -a \
34 "${SPLIT/ $PACKAGE /}" != "$SPLIT" ]; then
35 # For packages with empty $DEPENDS
36 if [ -z "$DEPENDS" ]; then
37 case $PACKAGE in
38 *-dev)
39 # main package and all the split packages but this *-dev itself
40 DEPENDS=$(echo "$MAIN_PACKAGE $SPLIT " | sed "s| $PACKAGE | |; s| *$||");;
41 *)
42 DEPENDS="$MAIN_PACKAGE";;
43 esac
44 fi
46 # Default $CAT
47 [ -z "$CAT" ] &&
48 case $PACKAGE in
49 *-dev) CAT="development|development files" ;;
50 esac
51 fi
53 # Manage two-in-one $CAT="$CATEGORY|$SHORT_DESC_ADDITION"
54 if [ -n "$CAT" ]; then
55 CATEGORY="${CAT%|*}"
56 SHORT_DESC="$SHORT_DESC (${CAT#*|})"
57 fi
59 # escape quotes for receipt
60 SHORT_DESC="${SHORT_DESC//\"/\\\"}"
62 # Mandatory variables
63 cat <<EOF
64 $signature
66 PACKAGE="$PACKAGE"
67 VERSION="$VERSION"
68 CATEGORY="$CATEGORY"
69 SHORT_DESC="$SHORT_DESC"
70 MAINTAINER="$MAINTAINER"
71 LICENSE="$LICENSE"
72 WEB_SITE="$WEB_SITE"
73 EOF
75 # Optional variables
76 [ -n "$TAGS" ] && echo "TAGS=\"$TAGS\"" | tr -ds '\t' ' '
77 [ -n "${DEPENDS# }" ] && echo "DEPENDS=\"$DEPENDS\"" | tr -ds '\t' ' '
78 [ -n "$PROVIDE" ] && echo "PROVIDE=\"$PROVIDE\"" | tr -ds '\t' ' '
79 [ -n "$CONFIG_FILES" ] && echo "CONFIG_FILES=\"$CONFIG_FILES\"" | tr -ds '\t' ' '
80 [ -n "$SUGGESTED" ] && echo "SUGGESTED=\"$SUGGESTED\"" | tr -ds '\t' ' '
81 [ -n "$DATABASE_FILES" ] && echo "DATABASE_FILES=\"$DATABASE_FILES\""
82 [ -n "$TAZPANEL_DAEMON" ] && echo "TAZPANEL_DAEMON=\"$TAZPANEL_DAEMON\""
84 # Extract {pre,post}_{install,remove} functions;
85 # post_install() will be copied for both main and all the split packages
86 # post_install_gtk_() will be copied as post_install() for gtk+ package only
87 #
88 # restricted name (gtk+ -> gtk_; acl-dev -> acl_dev)
89 rname=$(echo -n $PACKAGE | tr -c 'a-zA-Z0-9' '_')
90 for i in pre post; do
91 for j in install remove; do
92 sed "/^${i}_${j}()/,/^}/!d" "$orig_receipt"
93 sed "/^${i}_${j}_$rname()/,/^}/!d" "$orig_receipt" \
94 | sed "s|^${i}_${j}_$rname()|${i}_${j}()|"
95 done
96 done