Skip to content
Newer
Older
100755 358 lines (339 sloc) 9.11 KB
f479d2f revision 1
Various authored
1 #!/bin/bash
2
3 test "$1" = "--verbose" && { VERBOSE=true ; shift ; }
4 test "$1" = "--batchmode" && { BATCHMODE=true ; shift ; }
5 DIR_TO_CHECK=$1
6 DESTINATIONDIR=$2
3eace20 @bugfinder do tracked-check only in osc mode
bugfinder authored
7 OSC_MODE=""
f479d2f revision 1
Various authored
8 test -n "$DIR_TO_CHECK" || DIR_TO_CHECK=`pwd`
3eace20 @bugfinder do tracked-check only in osc mode
bugfinder authored
9 test -z "$DESTINATIONDIR" -a -d "$DIR_TO_CHECK/.osc" && {
10 DESTINATIONDIR="$DIR_TO_CHECK/.osc"
11 OSC_MODE="true"
12 }
f479d2f revision 1
Various authored
13
14
15 RETURN=0
16 RPMBUILD=rpm
17 test -x /usr/bin/rpmbuild && RPMBUILD=rpmbuild
18
19 #
20 # cleanup_and_exit
21 #
22 cleanup_and_exit () {
23 rm -rf $TMPDIR
24 exit $1
25 }
26
27 test "$VERBOSE" = true && echo -n "- checking if needed files are present and none stale "
28 #
29 # first make my TMPDIR
30 #
31 export TMPDIR=`mktemp -d -t check_if_valid_source_dir-XXXXXX 2>/dev/null || mktemp -d /var/tmp/check_if_valid_source_dir-XXXXXX`
32 #
33 # now create list of Sources.
34 #
35 MY_ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/`
36 case $MY_ARCH in
37 i386)
38 MY_ARCH="%ix86"
39 ;;
40 esac
41 for i in $DIR_TO_CHECK/*.spec ; do
42 test -f $i || continue
43 sed '/^#%([^)]*$/,/^[^(]*)/d
44 /^#[^%]/d
45 /^#%(.*)/d
46 /^%define/{
47 s@%(rpm -q.*)@1@
48 }
49 /^%define/{;p;d;}
50 /^%nil/{;p;d;}
51 /^%global.*%(.*)/d
52 /^%global/{;p;d;}
53 /^%include/d
9dad5ec @bugfinder 20-files-present-and-referenced add %rubygems_requires to prunelist
bugfinder authored
54 /^%rubygems_requires/d
3eace20 @bugfinder do tracked-check only in osc mode
bugfinder authored
55 /^%gconf_schemas_prereq/d
f479d2f revision 1
Various authored
56 /^%requires_eq/{;p;d;}
57 /^%requires_ge/{;p;d;}
58 /^%ifarch/{
59 s@.*@%ifarch '$MY_ARCH'@
60 }
61 /^ExcludeArch:/d
62 /^%error/d
63 /^ExclusiveArch:/{
64 s@.*@ExclusiveArch: '$MY_ARCH'@
65 }
66 /^BuildArch.*:/{
67 s@.*@BuildArch: '$MY_ARCH'@
68 }
69 /^%if.*%{name}/{;p;d;}
70 /^%if[^a]/{
71 s@.*@%if 1@
72 }
73 /^%if/{;p;d;}
74 /^%{\!/{;p;d;}
75 /^%{?/{;p;d;}
76 /^%{expand/d
77 /^%error/{;p;d;}
78 /^%else/{
79 s@.*@%endif\n%if 1@
80 }
81 /^%nil/{;p;d;}
82 /^%(.*)/{;d;}
83 /^%end/{;p;d;}
84 /^%bcond/{;p;d;}
85 /^%{py/{;p;d;}
86 /^%py_r/{;p;d;}
87 /^%/{;s/.*//;q;}
88 /^Requires:/d
89 /^No[Ss]ource/d
90 /^NoPatch/d
91 /^BuildPrereq/d
92 /^Build[Rr]equires/d
93 /^Pre[Rr]eq/d
94 /^Icon/d
95 /^Recommends/d
96 /^Supplements/d
97 /^Suggests/d
98 /^Enhances/d
7a9364f @bugfinder try to fix bnc#679980
bugfinder authored
99 /^\([Ss]ource\|[Pp]atch\)[0-9]*:[ ]*/{
100 s/^\(\([Ss]ource\|[Pp]atch\)[0-9]*:[ ]*\)\(.*\)/##seen \1\3\n%{echo:\3 }/
101 }
102 s/^Release:.*<RELEASE.*>/Release: 0/' $i >$TMPDIR/tmp.spec
f479d2f revision 1
Various authored
103 grep -a ^Icon: $i|sed -n 's/^Icon:[ ]*/%{echo:/
104 /^%{echo:/s/$/ }/p' >>$TMPDIR/tmp.spec
105 grep -a -q ^Release $i || {
106 sed -e "/^Version/{;p;s@\(.*\)@Release: 0\
107 @;}" $TMPDIR/tmp.spec > $TMPDIR/tmp.spec.new
108 mv $TMPDIR/tmp.spec.new $TMPDIR/tmp.spec
109 }
110 while test `grep -a "^%if" $TMPDIR/tmp.spec | wc -l` \
111 -gt `grep -a "^%endif" $TMPDIR/tmp.spec | wc -l` ; do
112 echo "%endif" >> $TMPDIR/tmp.spec
7a9364f @bugfinder try to fix bnc#679980
bugfinder authored
113 done
114 while read line ; do
115 grep -qx "##seen $line" $TMPDIR/tmp.spec || echo "$line" | sed -e "s/^\(\([Ss]ource\|[Pp]atch\)[0-9]*:[ ]*\)\(.*\)/##seen \1\3\n%{echo:\3 }/" >> $TMPDIR/tmp.spec
f479d2f revision 1
Various authored
116 done < <(grep -E "^Source:|^Source[0-9]*:|^Patch:|^Patch[0-9]*:" $i)
117 echo "%description" >> $TMPDIR/tmp.spec
c49e0e7 @bugfinder prevent dupes for Release and Version along with Name
bugfinder authored
118
119 # hack for really strange specfiles with more than one Name:/Release:/Version: line
120 for nodup in Name Version Release ; do
121 sed -e "s@^$nodup:@X$nodup:@" -e "0,/^X$nodup:/{s@^X$nodup:@$nodup:@}" -e "s@^X$nodup:.*@@" $TMPDIR/tmp.spec > $TMPDIR/tmp.spec.2 && mv $TMPDIR/tmp.spec.2 $TMPDIR/tmp.spec
f479d2f revision 1
Various authored
122 done
123
124 $RPMBUILD -bp $TMPDIR/tmp.spec 2>>$TMPDIR/sources || {
125 $RPMBUILD -bp $TMPDIR/tmp.spec
126 cleanup_and_exit 1
127 }
128 done
129
130 test -f $TMPDIR/sources || cleanup_and_exit
131
132 #
133 # check if all Sources, patches and the icon are present
134 #
135 touch $TMPDIR/sources.t
3eace20 @bugfinder do tracked-check only in osc mode
bugfinder authored
136 grep -aq "command not found" $TMPDIR/sources && {
137 echo "$0 seems to have problems evaluating macros in specfile."
138 COMD=`grep -a "command not found" $TMPDIR/sources | head -n 1 | sed -e "s@.*: \([^:]*\): command not found@\1@"`
139 echo "command \"$COMD\" is not available used in the following defines:"
140 grep -a "%define.*$COMD" $DIR_TO_CHECK/*.spec
f479d2f revision 1
Various authored
141 cleanup_and_exit 1
142 }
143
3eace20 @bugfinder do tracked-check only in osc mode
bugfinder authored
144 for i in `cat $TMPDIR/sources` ; do
f479d2f revision 1
Various authored
145 echo "${i##*/}" >> $TMPDIR/sources.t
146 done
147 mv $TMPDIR/sources.t $TMPDIR/sources
7f26ff0 @michal42 Also check if files are tracked by osc
michal42 authored
148
149 check_tracked()
150 {
151 local file=${1##*/}
152
7663b25 @bugfinder prefix error output lines by (E) where missing
bugfinder authored
153 if ! test -f "$DIR_TO_CHECK/$file"; then
7f26ff0 @michal42 Also check if files are tracked by osc
michal42 authored
154 echo "(E) $file mentioned in spec file does not exist."
155 return 1
3eace20 @bugfinder do tracked-check only in osc mode
bugfinder authored
156 fi
157 if test "$OSC_MODE" = "true" ; then
158 if test -f "$DESTINATIONDIR/$file"; then
159 return 0
160 fi
161 if grep -qsFx "$file" "$DESTINATIONDIR/_to_be_added"; then
162 return 0
7663b25 @bugfinder prefix error output lines by (E) where missing
bugfinder authored
163 fi
3eace20 @bugfinder do tracked-check only in osc mode
bugfinder authored
164 echo "(E) $file mentioned in spec file is not tracked."
7f26ff0 @michal42 Also check if files are tracked by osc
michal42 authored
165 return 1
166 fi
167 }
f479d2f revision 1
Various authored
168
7f26ff0 @michal42 Also check if files are tracked by osc
michal42 authored
169 for HASTOBETHER in `cat $TMPDIR/sources` ; do
f479d2f revision 1
Various authored
170 check_tracked "$HASTOBETHER" || RETURN=1
171 done
cac2ef9 (none)
Unknown authored
172
173 #
174 # Skip this test for now, if we have server side downloads
175 #
176 if [ -e $DIR_TO_CHECK/_service ]; then
177 exit 0
f479d2f revision 1
Various authored
178 fi
179
180 #
181 # now check if everything is marked in spec files.
182 #
183 for i in $DIR_TO_CHECK/* $DIR_TO_CHECK/.* ; do
184 BASE=${i##*/}
185 case $BASE in
186 \.|\.\.) continue ;;
187 esac
188 # files to display first
189 case $BASE in
190 config-dist.sh | \
191 get_version_number.sh | \
192 get_release_number.sh | \
193 check-build.sh | \
194 baselibs.conf )
195 if test -n "$DESTINATIONDIR" -a -f "$DESTINATIONDIR/$BASE" && cmp -s "$DIR_TO_CHECK/$BASE" "$DESTINATIONDIR/$BASE" ; then
196 echo "- package has $BASE: (unchanged)"
197 else
198 echo "- package has $BASE: (new or modified)"
199 echo "--------------------------------------------------------------"
200 cat $DIR_TO_CHECK/$BASE
201 echo "--------------------------------------------------------------"
202 if test "$BATCHMODE" != true ; then
203 echo -n "Is this correct? [N/y/d] (y to ignore) "
204 read ANSWER
205 test "$ANSWER" = y -o "$ANSWER" = Y || {
206 if test "$ANSWER" = d -o "$ANSWER" = D ; then
207 rm -v $DIR_TO_CHECK/$BASE
208 else
209 echo ok, please fix it...
210 RETURN=1
211 fi
212 }
213 else
214 echo "###ASK $DIR_TO_CHECK/$BASE"
215 fi
216 fi
217 ;;
218 *rpmlintrc)
219 if test -n "$DESTINATIONDIR" -a -f "$DESTINATIONDIR/$BASE" && cmp -s "$DIR_TO_CHECK/$BASE" "$DESTINATIONDIR/$BASE" ; then
220 echo "- package has $BASE: (unchanged)"
221 else
222 echo "- package has $BASE: (new or modified)"
223 echo "--------------------------------------------------------------"
224 cat $DIR_TO_CHECK/$BASE
225 echo "--------------------------------------------------------------"
226 if test "$BATCHMODE" != true ; then
227 echo -n "Is this correct? [N/y/d] (y to ignore) "
228 read ANSWER
229 test "$ANSWER" = y -o "$ANSWER" = Y || {
230 if test "$ANSWER" = d -o "$ANSWER" = D ; then
231 rm -v $DIR_TO_CHECK/$BASE
232 else
233 echo ok, please fix it...
234 RETURN=1
235 fi
236 }
237 else
238 echo "###ASK $DIR_TO_CHECK/$BASE"
239 fi
cb70675 @bugfinder update from dirk: fix for batch case
bugfinder authored
240 fi
241
242 LINE=$(egrep -w setBadness "$DIR_TO_CHECK/$BASE")
243 if [ "$LINE" != "" ]; then
f479d2f revision 1
Various authored
244 if test "$BATCHMODE" != true ; then
245 echo "ERROR: Found possibly illegal rpmlintrc line:"
246 echo " $LINE"
247 echo -n "Is this correct? [N/y] (y to ignore) "
248 read ANSWER
249 test "$ANSWER" = y -o "$ANSWER" = Y || {
250 echo ok, please fix it...
251 RETURN=1
cb70675 @bugfinder update from dirk: fix for batch case
bugfinder authored
252 }
253 else
f479d2f revision 1
Various authored
254 echo "###ASK $DIR_TO_CHECK/$BASE"
cb70675 @bugfinder update from dirk: fix for batch case
bugfinder authored
255 fi
f479d2f revision 1
Various authored
256 fi
257 ;;
258 .*.spec)
259 rm -v $DIR_TO_CHECK/$BASE
260 ;;
261 *.changes | \
262 *.lsm | \
263 *.spec | \
264 *.spec.in | \
265 *.changes.in | \
266 *.test | \
267 MD5SUMS | \
268 MD5SUMS.meta | \
269 Makefile | \
270 README.autobuild | \
271 bigpack | \
272 prepare-build.sh | \
273 minmem | \
274 needed_space_in_mb | \
275 pre_checkin.sh | \
276 newestfile | \
277 .osc | \
278 .bsinfo | \
279 .bsnote | \
280 .check_if_valid_source_dir | \
281 .setup | \
282 *.dsc | \
b94bede @nijel revision 8
nijel authored
283 ready | \
4f2521a @bugfinder from jw:
bugfinder authored
284 _* | \
285 *.orig | \
6c949b9 @bugfinder add debian special files
bugfinder authored
286 *~ | \
287 .gitignore | \
288 debian.changelog | \
289 debian.compat | \
290 debian.control | \
291 debian.copyright | \
292 debian.postinst | \
293 debian.postrm | \
294 debian.preinst | \
295 debian.prerm | \
296 debian.rules | \
297 debian.tar.gz | \
298 debian.triggers | \
299 debian.*.default | \
300 debian.*.dirs | \
301 debian.*.files | \
302 debian.*.init | \
303 debian.*.install | \
304 debian.*.logrotate | \
305 debian.*.postinst | \
306 debian.*.postrm | \
307 debian.*.preinst | \
f479d2f revision 1
Various authored
308 debian.*.prerm )
309 ;;
310 *)
7663b25 @bugfinder prefix error output lines by (E) where missing
bugfinder authored
311 grep -a -x $BASE $TMPDIR/sources > /dev/null && continue
f479d2f revision 1
Various authored
312 echo "(W) Attention, $BASE is not mentioned in spec files as source or patch."
b94bede @nijel revision 8
nijel authored
313 if [ -d $DIR_TO_CHECK/$BASE ] ; then
314 # be a bit more relaxed for osc, it won't upload directories anyway
f479d2f revision 1
Various authored
315 if [ ! -d $DIR_TO_CHECK/.osc ] ; then
b94bede @nijel revision 8
nijel authored
316 echo "!! $BASE is a directory !!"
4f2521a @bugfinder from jw:
bugfinder authored
317 if test "$BATCHMODE" != true ; then
318 echo " remove subtree with 'r'"
319 echo "ignore and continue with 'y'"
b94bede @nijel revision 8
nijel authored
320 echo -n "Is this correct? [N/y/r] "
321 read ANSWER
4f2521a @bugfinder from jw:
bugfinder authored
322 test "$ANSWER" = y -o "$ANSWER" = Y || {
323 # r for remove is also accepted, to make it compatible with osc itself
b94bede @nijel revision 8
nijel authored
324 if test "$ANSWER" = d -o "$ANSWER" = D -o "$ANSWER" = r -o "$ANSWER" = R; then
325 rm -Rfv $DIR_TO_CHECK/$BASE
326 else
327 echo ok, please fix it...
328 RETURN=1
329 fi
330 }
331 else
332 echo "###ASK -r $DIR_TO_CHECK/$BASE"
f479d2f revision 1
Various authored
333 fi
334 fi
335 else
336 if test "$BATCHMODE" != true ; then
337 echo -n "Is this correct? [N/y/d] (y to ignore) "
338 read ANSWER
339 test "$ANSWER" = y -o "$ANSWER" = Y || {
340 if test "$ANSWER" = d -o "$ANSWER" = D ; then
341 rm -v $DIR_TO_CHECK/$BASE
342 else
343 echo ok, please fix it...
344 RETURN=1
345 fi
346 }
347 else
348 echo "###ASK $DIR_TO_CHECK/$BASE"
349 fi
350 fi
351 ;;
352 esac
353 done
354
355 test "$VERBOSE" = true && echo done
356
Something went wrong with that request. Please try again.