blob: 4fcfba3a233c3b07bc5b5bba7651c4f88487eaed (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
#! @BASH@
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# See the COPYING and AUTHORS files for more details.
if ! [ -r @SCRIPTS@/patchfns ]
then
echo "Cannot read library @SCRIPTS@/patchfns" >&2
exit 1
fi
. @SCRIPTS@/patchfns
cd ${SUBDIR:-.}
usage() {
echo "Usage: ${0##*/} specfile"
exit 1
}
if [ "$1" = -v ]
then
verbose=1
shift
fi
specfile=$1
if [ $# -ne 1 -o ! -f "$specfile" ]
then
usage
fi
if [ "${specfile:0:1}" != / ]
then
specfile="$PWD/$specfile"
fi
sourcedir=${specfile%/*}
tmpdir="$(gen_tempfile -d ${TMPDIR-/tmp}/${0##*/})"
mkdir -p $tmpdir || exit 1
trap "rm -rf $tmpdir" EXIT
mkdir -p $tmpdir/build
mkdir -p $tmpdir/bin
# Redirect file descriptors
if [ -n "$verbose" ]
then
exec 3>&1 4>/dev/null
else
exec 3>&1 4>&2 2>/dev/null
fi
# create md5 sums, also for uncompressed files
echo -n "### md5sum: " >&4
shopt -s nullglob
for file in *
do
file=${file##*/}
case "$file" in
ready|bigpack|MD5SUMS|MD5SUMS.meta|*.spec|*.changes)
continue
;;
esac
[ -f "$file" ] || continue
echo -n "." >&4
echo "md5sum < $file" >&2
set -- $(md5sum < $file)
echo "$1 $file"
case "$(file -b $file)" in
compress*|gzip*)
echo -n "g" >&4
echo "md5sum < <(gzip -cd $file)" >&2
set -- $(gzip -cd $file | md5sum)
echo "$1 $file"
;;
bzip2*)
echo -n "b" >&4
echo "md5sum < <(bzip2 -cd $file)" >&2
set -- $(bzip2 -cd $file | md5sum)
echo "$1 $file"
;;
esac
done > $tmpdir/md5sum
echo >&4
shopt -u nullglob
RPM=( @RPMBUILD@ --eval "%define _sourcedir $sourcedir" \
--eval "%define _specdir $sourcedir" \
--eval "%define _builddir $tmpdir/build" )
PATH="$tmpdir/bin:$PATH"
# wrapper script for patch and tar
cat <<-'EOF' > $tmpdir/bin/wrapper
#! @BASH@
# search the path for command $1
path_search() {
local cmd=$1 dir
IFS=:
set -- $PATH
shift
for dir in "$@"; do
if [ -x $dir/$cmd ]
then
echo $dir/$cmd
return 0
fi
done
return 1
}
# find original data file by md5sum
original_file() {
local file=$1
set -- $(md5sum < $file)
while read md5sum file
do
if [ $1 = $md5sum ]
then
echo $file
return 0
fi
done < $tmpdir/md5sum
return 1
}
# Extract the -p option from the command line
strip_option() {
while [ $# -ne 0 -a "${1:0:2}" != -p ]
do
shift
done
if [ "${1:0:2}" = -p ]
then
[ "$1" = -p ] && set -- "$1$2"
[ "$1" != -p1 ] && echo $1
fi
}
# put data into tmpfile
tmpdir=${RPM_BUILD_DIR%/*}
cat > $tmpdir/data
unpackfile="$(original_file $tmpdir/data)"
if [ -n "$unpackfile" ]
then
dir=${PWD/$RPM_BUILD_DIR}
dir=${dir##/}
case "${0##*/}" in
patch)
echo -n p >&4
echo "${0##*/} ${dir:-.} $unpackfile" \
$(strip_option "$@") >&3
;;
tar)
echo -n t >&4
echo "${0##*/} ${dir:-.} $unpackfile" >&3
;;
esac
fi
realcmd="$(path_search ${0##*/})" \
&& $realcmd "$@" < $tmpdir/data
EOF
chmod 755 $tmpdir/bin/wrapper
ln -s wrapper $tmpdir/bin/patch
ln -s wrapper $tmpdir/bin/tar
# let rpm do all the dirty specfile stuff ...
set -- @RPMBUILD@
echo -n "### ${1##*/}: " >&4
"${RPM[@]}" --nodeps -bp "$specfile" < /dev/null > /dev/null
echo >&4
### Local Variables:
### mode: shell-script
### End:
# vim:filetype=sh
|