Relax chown requirements when check_owner is false
[hcoop/debian/exim4.git] / debian / create-custom-package
CommitLineData
de45f55a
AM
1#!/bin/bash
2
3set -e
4
5if [ -n "$EX4DEBUG" ]; then
6 echo "now debugging $0 $@"
7 set -x
8fi
9
10dh_testdir
11if [ -z "$(which grep-dctrl)" ] || ! [ -x "$(which grep-dctrl)" ]; then
12 echo >&2 "ERR: no grep-dctrl binary"
13 exit 1
14fi
15
16fakeroot debian/rules clean
17
18if [ -n "$1" ]; then
19 PACKAGESUFFIX="$1"
20fi
21
22#DEBUG=1
23
24dh_testdir
25
26cd debian
27
28replacepkgname() {
29 sed -e "s/exim4-daemon-custom/exim4-daemon-$PACKAGESUFFIX/g;\
30 s/exim4-custom/exim4-$PACKAGESUFFIX/g"
31}
32
33copytextreplace() {
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
51NEEDEDFILES="exim4-daemon-custom.* rules control"
52for file in $NEEDEDFILES; do
53 if ! [ -e $file ]; then
54 echo >&2 "ERR: $file does not exist, not starting"
55 exit 1
56 fi
57done
58
59# the grep-dctrl|grep construct is necessary on woody,
60# since woody grep-dctrl does not give sensible return values.
61if 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
65fi
66
67if grep -q exim4-daemon-$PACKAGESUFFIX rules; then
68 echo >&2 "ERR: exim4-daemon-$PACKAGESUFFIX already mentioned in debian/rules, not starting"
69 exit 1
70fi
71
72for file in exim4-daemon-custom.* ; do
73 copytextreplace $file ${file/exim4-daemon-custom/exim4-daemon-$PACKAGESUFFIX}
74done
75
76echo >> control
77grep-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
83echo >> 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
94chmod --reference=rules rules.new
95mv rules.new rules