1 | #!/bin/bash |
---|
2 | #(C)DatuX 2005 - all rights reserved |
---|
3 | BUILDFILE=$1 |
---|
4 | DEPTH=$2 |
---|
5 | IGNORE_REGEX='/CVS/|md5$|/\.git|/\.svn|/\.cvs|/docs|~$|\.depver$|\.arch$|\.version$|\.major$|\.check$|\.build$|\.check\.ok$'; |
---|
6 | if [ ! "`id -u`" = "0" ]; then |
---|
7 | echo "root priviliges required. Quiting..."; |
---|
8 | exit 1; |
---|
9 | fi |
---|
10 | |
---|
11 | shift |
---|
12 | shift |
---|
13 | for PAR in $*; do eval "$PAR=1" &>/dev/null; done |
---|
14 | |
---|
15 | if ! [ "$BUILDFILE" ]; then |
---|
16 | echo "Usage:" |
---|
17 | echo " $0 </path/to/package.SlackBuild>" |
---|
18 | echo " $0 <packagename>" |
---|
19 | echo "To ignore changes to the package:" |
---|
20 | echo " $0 <packagename> '' ignoremd5" |
---|
21 | echo "To regenerate md5 sum of a package, without rebuilding:" |
---|
22 | echo " $0 <packagename> '' regenmd5" |
---|
23 | echo "To force rebuilding of a package that doesnt need it:" |
---|
24 | echo " $0 <packagename> '' force" |
---|
25 | exit 1 |
---|
26 | fi |
---|
27 | |
---|
28 | |
---|
29 | msg() |
---|
30 | { |
---|
31 | echo "$DEPTH$*" |
---|
32 | } |
---|
33 | |
---|
34 | #buildfile meegeven? |
---|
35 | if ! [ -f "$BUILDFILE" ]; then |
---|
36 | #pkgname in plaats van rechstreekse buildfile meegegeven? |
---|
37 | BUILDFILE=`./findbuild $BUILDFILE`.SlackBuild |
---|
38 | if ! [ -f "$BUILDFILE" ]; then |
---|
39 | msg "ERROR: $BUILDFILE not found. (specify the syn-3 pkgname or path to .SlackBuild file)" |
---|
40 | exit 1 |
---|
41 | fi |
---|
42 | fi |
---|
43 | |
---|
44 | #kijk of een directory veranderd is. |
---|
45 | #(dit is puur om rebuild check sneller te maken en md5 checks te skippen) |
---|
46 | dir_changed() |
---|
47 | { |
---|
48 | DIR=$1 |
---|
49 | MD5=`ls -lR "$DIR"|md5sum` |
---|
50 | ! grep -x "$MD5" "$DIR/.signature" &>/dev/null |
---|
51 | } |
---|
52 | |
---|
53 | #bewaar signature |
---|
54 | store_dir() |
---|
55 | { |
---|
56 | DIR=$1 |
---|
57 | ls -lR "$DIR"|md5sum > "$DIR/.signature" |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | # bepaald absoluut path |
---|
62 | DIRNAME=`dirname $BUILDFILE` |
---|
63 | BASENAME=`basename $BUILDFILE` |
---|
64 | pushd $DIRNAME >/dev/null || exit 1 |
---|
65 | BUILDFILE="`pwd`/$BASENAME" |
---|
66 | popd >/dev/null |
---|
67 | |
---|
68 | if [ "$fast" ] && grep -x $BUILDFILE .tmp/builded &>/dev/null; then |
---|
69 | exit 0 |
---|
70 | fi |
---|
71 | |
---|
72 | |
---|
73 | DEPS=`cat "$BUILDFILE" |grep '^#DEP:'|cut -f2 -d':'` |
---|
74 | |
---|
75 | |
---|
76 | #### controleer of MD5 van al onze files nog kloppen |
---|
77 | #-negeer cvs dirs, md5sums en hidden files, backup files |
---|
78 | #-negeer ook andere arch en version files! |
---|
79 | DIR=`dirname $BUILDFILE` |
---|
80 | MD5FILE=`echo $BUILDFILE|sed 's/.SlackBuild$//g'`.md5 |
---|
81 | if ! [ "$ignoremd5" ]; then |
---|
82 | pushd "$DIR" >/dev/null || exit 1 |
---|
83 | find . -type f | |
---|
84 | #negeer bepaalde files |
---|
85 | egrep -v $IGNORE_REGEX | |
---|
86 | while read FILE; do |
---|
87 | MD5=`md5sum "$FILE"` |
---|
88 | #md5 sum gewijzigd of ontbreekt? |
---|
89 | if ! grep "$MD5" "$MD5FILE" &>/dev/null; then |
---|
90 | msg "Rebuild required: $FILE has changed!" |
---|
91 | exit 2 #exit 2, rebuild dus |
---|
92 | fi |
---|
93 | done |
---|
94 | RET=$? |
---|
95 | popd >/dev/null |
---|
96 | |
---|
97 | if [ "$RET" == "2" ]; then |
---|
98 | REBUILD=1 |
---|
99 | elif [ "$RET" != "0" ]; then |
---|
100 | msg "ERROR!" |
---|
101 | exit 1 |
---|
102 | fi |
---|
103 | fi |
---|
104 | |
---|
105 | #### controleer of er DEPS zijn die een ANDER major nummer hebben, waardoor we opnieuw moeten compilen |
---|
106 | DEPVERFILE=`echo $BUILDFILE|sed 's/.SlackBuild$//g'`.depver |
---|
107 | DEPERROR=0 |
---|
108 | for DEP in $DEPS; do |
---|
109 | if DEPBUILDNAME=`./findbuild "$DEP"`; then |
---|
110 | DEPMAJOR=`cat "$DEPBUILDNAME.major" 2>/dev/null` |
---|
111 | if ! [ "$DEPMAJOR" ]; then |
---|
112 | DEPMAJOR=0 |
---|
113 | fi |
---|
114 | |
---|
115 | MAJOR=`cat $DEPVERFILE 2>/dev/null |grep "^$DEP[[:space:]]"| cut -f2|head -1` |
---|
116 | if ! [ "$MAJOR" ]; then |
---|
117 | MAJOR=0 |
---|
118 | #FIXME: should be -1, but the requires a rebuild of a lot of old packages |
---|
119 | fi |
---|
120 | # echo "$DEP is '$DEPMAJOR' en '$MAJOR'" |
---|
121 | if [ "$DEPMAJOR" -ne "$MAJOR" ]; then |
---|
122 | msg "Rebuild required: $DEP major is now $DEPMAJOR, but this package was build was against $MAJOR." |
---|
123 | DEPERROR=1 |
---|
124 | fi |
---|
125 | fi |
---|
126 | done |
---|
127 | |
---|
128 | |
---|
129 | #if we need to rebuild because of a DEPERROR, check our direct dependencys first so that we rebuild the |
---|
130 | #"deepest" stuff first. |
---|
131 | if ! [ "$ignoredep" ] && [ "$DEPERROR" == "1" ]; then |
---|
132 | for DEP in $DEPS; do |
---|
133 | #zoek de buildbase op, als deze er al is |
---|
134 | if BUILDBASE=`./findbuild "$DEP"` 2>/dev/null; then |
---|
135 | msg "Dependency check $DEP" |
---|
136 | #note: niet de parameters meegeven, anders gaat hij alles rebuilden bij een force |
---|
137 | ./rebuildcheck "$BUILDBASE.SlackBuild" "|-$DEPTH" || exit 1 |
---|
138 | fi |
---|
139 | done |
---|
140 | fi |
---|
141 | |
---|
142 | if [ "$DEPERROR" == "1" ]; then |
---|
143 | REBUILD=1 |
---|
144 | fi |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | if [ "$REBUILD" == "1" ] && [ "$nobuild" == "1" ]; then |
---|
149 | msg "Need to rebuild $BUILDFILE" |
---|
150 | msg "(no building because you specified nobuild)" |
---|
151 | REBUILD= |
---|
152 | fi |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | if [ "$force" == "1" ]; then |
---|
157 | REBUILD=1 |
---|
158 | fi |
---|
159 | |
---|
160 | fatal(){ |
---|
161 | echo -e "Error while rebuilding $BUILDFILE!\a"; |
---|
162 | exit 1; |
---|
163 | } |
---|
164 | |
---|
165 | #### rebuild nodig? |
---|
166 | if [ "$REBUILD" == "1" ]; then |
---|
167 | if [ ! "$regenmd5" ] ; then |
---|
168 | msg "REBUILDING $BUILDFILE:" |
---|
169 | if grep '#NOBUILDROOT' "$BUILDFILE" >/dev/null; then |
---|
170 | msg "Building package without buildroot!" |
---|
171 | ( |
---|
172 | cd `dirname $BUILDFILE` || exit 1 |
---|
173 | $BUILDFILE $* || exit 1 |
---|
174 | ) || fatal |
---|
175 | else |
---|
176 | ( |
---|
177 | cd ../builder |
---|
178 | ./runrooted "$BUILDFILE" $* |
---|
179 | ) || fatal |
---|
180 | fi |
---|
181 | |
---|
182 | #show all packages contents: |
---|
183 | for PKG in `dirname $BUILDFILE`/*.pkg; do |
---|
184 | echo |
---|
185 | echo "################## Contents of $PKG:" |
---|
186 | tar -tvzf $PKG || fatal |
---|
187 | echo "################## end of $PKG " |
---|
188 | done |
---|
189 | |
---|
190 | #show all diffs: |
---|
191 | for PKG in `dirname $BUILDFILE`/*.pkg; do |
---|
192 | if [ "`git status --porcelain $PKG|grep -v '^?'`" != "" ]; then |
---|
193 | echo |
---|
194 | echo "################## DIFF of $PKG:" |
---|
195 | ./diffpkg $PKG |
---|
196 | echo "################## end of DIFF $PKG " |
---|
197 | fi |
---|
198 | done |
---|
199 | |
---|
200 | msg "Updating build numbers for $BUILDFILE..." |
---|
201 | pushd $DIR > /dev/null |
---|
202 | for PKG in *.pkg; do |
---|
203 | BUILD_FILE=`echo "$PKG"| sed 's/.pkg$//'`.build |
---|
204 | BUILD=`cat $BUILD_FILE 2>/dev/null` |
---|
205 | if [ "$BUILD" == "" ]; then |
---|
206 | BUILD=1 |
---|
207 | else |
---|
208 | (( BUILD=BUILD+1 )) |
---|
209 | fi |
---|
210 | echo $BUILD > $BUILD_FILE || exit 1 |
---|
211 | done |
---|
212 | popd >/dev/null |
---|
213 | |
---|
214 | else |
---|
215 | msg "Not building, only updating md5 sums.." |
---|
216 | fi |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | |
---|
221 | msg "Updating md5 for $BUILDFILE..." |
---|
222 | #bepaal en bewaar major versies waartegen we gebuild hebben |
---|
223 | rm $MD5FILE &>/dev/null |
---|
224 | pushd $DIR >/dev/null |
---|
225 | find . -type f| sort | |
---|
226 | #negeer bepaalde files |
---|
227 | egrep -v $IGNORE_REGEX | |
---|
228 | while read FILE; do |
---|
229 | md5sum "$FILE" >> $MD5FILE |
---|
230 | done |
---|
231 | popd > /dev/null |
---|
232 | |
---|
233 | msg "Updating dependency information for $BUILDFILE..." |
---|
234 | DEPVERFILE=`echo $BUILDFILE | sed 's/.SlackBuild$//g'`.depver |
---|
235 | rm "$DEPVERFILE" &>/dev/null |
---|
236 | for DEP in $DEPS; do |
---|
237 | if DEPBUILDNAME=`./findbuild "$DEP"`; then |
---|
238 | DEPMAJOR=`cat "$DEPBUILDNAME.major" 2>/dev/null`; |
---|
239 | if ! [ "$DEPMAJOR" ]; then |
---|
240 | DEPMAJOR=0 |
---|
241 | fi |
---|
242 | echo -e "$DEP\t$DEPMAJOR" >> $DEPVERFILE || exit 1 |
---|
243 | fi |
---|
244 | done |
---|
245 | fi |
---|
246 | |
---|
247 | echo "$BUILDFILE" >> .tmp/builded |
---|
248 | |
---|
249 | if ! [ "$DEPTH" ]; then |
---|
250 | echo -e "All rebuilds completed.\a" |
---|
251 | fi |
---|
252 | |
---|
253 | #store_dir "$DIR" |
---|
254 | exit 0 |
---|