Import Debian changes 4.92-8+deb10u3
[hcoop/debian/exim4.git] / debian / create-custom-package
1 #!/bin/bash
2
3 set -e
4
5 if [ -n "$EX4DEBUG" ]; then
6 echo "now debugging $0 $@"
7 set -x
8 fi
9
10 dh_testdir
11 if [ -z "$(which grep-dctrl)" ] || ! [ -x "$(which grep-dctrl)" ]; then
12 echo >&2 "ERR: no grep-dctrl binary"
13 exit 1
14 fi
15
16 fakeroot debian/rules clean
17
18 if [ -n "$1" ]; then
19 PACKAGESUFFIX="$1"
20 fi
21
22 #DEBUG=1
23
24 dh_testdir
25
26 cd debian
27
28 replacepkgname() {
29 sed -e "s/exim4-daemon-custom/exim4-daemon-$PACKAGESUFFIX/g;\
30 s/exim4-custom/exim4-$PACKAGESUFFIX/g"
31 }
32
33 copytextreplace() {
34 FILE="$1"
35 DSTFILE="$2"
36 if [ -z "$DSTFILE" ]; then
37 echo >&2 "no destination file given to copytextreplace $FILE"
38 exit 1
39 fi
40 [ $DEBUG ] && echo >&2 "DBG: source $FILE"
41 [ $DEBUG ] && echo >&2 "DBG: dst $DSTFILE"
42 if ! [ -e "$DSTFILE" ]; then
43 < $FILE replacepkgname > $DSTFILE
44 chmod --reference=$FILE $DSTFILE
45 else
46 echo >&2 "ERR: can't write to $DSTFILE, file exists"
47 exit 1
48 fi
49 }
50
51 NEEDEDFILES="exim4-daemon-custom.* rules control"
52 for file in $NEEDEDFILES; do
53 if ! [ -e $file ]; then
54 echo >&2 "ERR: $file does not exist, not starting"
55 exit 1
56 fi
57 done
58
59 # the grep-dctrl|grep construct is necessary on woody,
60 # since woody grep-dctrl does not give sensible return values.
61 if grep-dctrl --field=Package exim4-daemon-$PACKAGESUFFIX control | \
62 grep -q '^Package:'; then
63 echo >&2 "ERR: there is already a debian/control entry for exim4-daemon-$PACKAGESUFFIX, not starting"
64 exit 1
65 fi
66
67 if grep -q exim4-daemon-$PACKAGESUFFIX rules; then
68 echo >&2 "ERR: exim4-daemon-$PACKAGESUFFIX already mentioned in debian/rules, not starting"
69 exit 1
70 fi
71
72 for file in exim4-daemon-custom.* ; do
73 copytextreplace $file ${file/exim4-daemon-custom/exim4-daemon-$PACKAGESUFFIX}
74 done
75
76 echo >> control
77 grep-dctrl --field=Package exim4-daemon-custom control | \
78 replacepkgname >> control
79
80 < rules sed "/^builddaemonpackages/ \
81 {s/^builddaemonpackages=/builddaemonpackages=exim4-daemon-$PACKAGESUFFIX /; \
82 }" > rules.new
83 echo >> rules.new
84 < rules sed -n "\
85 /^build-exim4-daemon-custom/,/^[^[:space:]]/ \
86 { \
87 s/exim4-daemon-custom/exim4-daemon-$PACKAGESUFFIX/; \
88 s/exim4-custom/exim4-$PACKAGESUFFIX/; \
89 /^build-exim4-daemon-$PACKAGESUFFIX/p;
90 /^[^[:space:]]/d; \
91 p; \
92 }" \
93 >> rules.new
94 chmod --reference=rules rules.new
95 mv rules.new rules