cookutils view modules/mk_pkg_receipt @ rev 1005

(and again)
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Nov 07 13:57:02 2017 +0200 (2017-11-07)
parents 75b330dd2734
children 553a90d99a5b
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 # `$(echo ...)`: normalize whitespace (space, tab, newline and they combinations and repeats)
21 cat > $save <<EOT
22 PACKAGE="$PACKAGE"; DEPENDS="$(echo $DEPENDS)"; PROVIDE="$(echo $PROVIDE)"
23 SUGGESTED="$(echo $SUGGESTED)"; TAZPANEL_DAEMON="$TAZPANEL_DAEMON"
24 TAGS="$(echo $TAGS)"
25 EOT
26 unset_receipt
27 . "$orig_receipt"
28 MAIN_PACKAGE="$PACKAGE"
29 . $save; rm $save # restore values
31 # Manage split packages
32 SPLIT=" $SPLIT "
33 if [ "$PACKAGE" != "$MAIN_PACKAGE" -a \
34 "$SPLIT" != ' ' -a \
35 "${SPLIT/ $PACKAGE /}" != "$SPLIT" ]; then
36 # For packages with empty $DEPENDS
37 if [ -z "$DEPENDS" ]; then
38 case $PACKAGE in
39 *-dev)
40 # main package and all the split packages but this *-dev itself
41 DEPENDS=$(echo "$MAIN_PACKAGE $SPLIT " | sed "s| $PACKAGE | |; s| *$||");;
42 *)
43 DEPENDS="$MAIN_PACKAGE";;
44 esac
45 fi
47 # Default $CAT
48 [ -z "$CAT" ] &&
49 case $PACKAGE in
50 *-dev) CAT="development|development files" ;;
51 esac
52 fi
54 # Manage two-in-one $CAT="$CATEGORY|$SHORT_DESC_ADDITION"
55 if [ -n "$CAT" ]; then
56 CATEGORY="${CAT%|*}"
57 SHORT_DESC="$SHORT_DESC (${CAT#*|})"
58 fi
60 # escape quotes for receipt
61 SHORT_DESC="${SHORT_DESC//\"/\\\"}"
63 # Mandatory variables
64 cat <<EOF
65 $signature
67 PACKAGE="$PACKAGE"
68 VERSION="$VERSION"
69 EOF
70 [ -n "$EXTRAVERSION" ] && echo "EXTRAVERSION=\"$EXTRAVERSION\""
71 cat <<EOF
72 CATEGORY="$CATEGORY"
73 SHORT_DESC="$SHORT_DESC"
74 MAINTAINER="$MAINTAINER"
75 LICENSE="$LICENSE"
76 WEB_SITE="$WEB_SITE"
77 EOF
79 # Optional variables
80 [ -n "$TAGS" ] && echo "TAGS=\"$TAGS\"" | tr -ds '\t' ' '
81 [ -n "${DEPENDS# }" ] && echo "DEPENDS=\"$DEPENDS\"" | tr -ds '\t' ' '
82 [ -n "$PROVIDE" ] && echo "PROVIDE=\"$PROVIDE\"" | tr -ds '\t' ' '
83 [ -n "$CONFIG_FILES" ] && echo "CONFIG_FILES=\"$CONFIG_FILES\"" | tr -ds '\t' ' '
84 [ -n "$SUGGESTED" ] && echo "SUGGESTED=\"$SUGGESTED\"" | tr -ds '\t' ' '
85 [ -n "$DATABASE_FILES" ] && echo "DATABASE_FILES=\"$DATABASE_FILES\""
86 [ -n "$TAZPANEL_DAEMON" ] && echo "TAZPANEL_DAEMON=\"$TAZPANEL_DAEMON\""
88 # Extract {pre,post}_{install,remove} functions;
89 # post_install() will be copied for both main and all the split packages
90 # post_install_gtk_() will be copied as post_install() for gtk+ package only
91 #
92 # restricted name (gtk+ -> gtk_; acl-dev -> acl_dev)
93 rname=$(echo -n $PACKAGE | tr -c 'a-zA-Z0-9' '_')
94 for i in pre post; do
95 for j in install remove; do
96 sed "/^${i}_${j}()/,/^}/!d" "$orig_receipt"
97 sed "/^${i}_${j}_$rname()/,/^}/!d" "$orig_receipt" \
98 | sed "s|^${i}_${j}_$rname()|${i}_${j}()|"
99 done
100 done