]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
workaround for problems with rpm when icons isn't cvs up'ed
[packages/rpm-build-tools.git] / builder.sh
1 #!/bin/sh
2 # -----------
3 # $Id$
4 # Exit codes:
5 #       0 - succesful
6 #       1 - help dispayed
7 #       2 - no spec file name in cmdl parameters
8 #       3 - spec file not stored in repo
9 #       4 - some source, apatch or icon files not stored in repo
10 #       5 - build package no succed
11
12 VERSION="\
13 Build package utility from PLD CVS repository
14 V 0.9 (C) 1999-2001 Tomasz K³oczko".
15
16 PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
17  
18 COMMAND="build"
19
20 SPECFILE=""
21 BE_VERBOSE=""
22 QUIET=""
23 CLEAN=""
24 DEBUG=""
25 NOURLS=""
26 NOCVS=""
27 ALLWAYS_CVSUP="yes"
28 CVSROOT=${CVSROOT:-""}
29 LOGFILE=""
30 CHMOD="yes"
31 RPMOPTS=""
32
33 PATCHES=""
34 SOURCES=""
35 ICONS=""
36 PACKAGE_RELEASE=""
37 PACKAGE_VERSION=""
38 PACKAGE_NAME=""
39
40 DEF_NICE_LEVEL=0
41
42 GETURI="wget -c -nd -t0"
43
44 if [ -f ~/etc/builderrc ]; then
45   . ~/etc/builderrc
46 elif [ -f ~/.builderrc ]; then
47   . ~/.builderrc
48 fi
49
50 #---------------------------------------------
51 # functions
52
53 usage()
54 {
55     if [ -n "$DEBUG" ]; then set -xv; fi
56     echo "\
57 Usage: builder [-D] [--debug] [-V] [--version] [-a] [--as_anon] [-b] [-ba]
58         [--build] [-bb] [--build-binary] [-bs] [--build-source]
59         [-d <cvsroot>] [--cvsroot <cvsroot>] [-g] [--get] [-h] [--help]
60         [-l <logfile>] [-m] [--mr-proper] [--logtofile <logfile>] [-q] [--quiet]
61         [-r <cvstag>] [--cvstag <cvstag>] [-u] [--no-urls] [-v] [--verbose]
62         [--opts <rpm opts>] <package>.spec
63
64         -D, --debug     - enable script debugging mode,
65         -V, --version   - output builder version
66         -a, --as_anon   - get files via pserver as cvs@anoncvs.pld.org.pl,
67         -b, -ba,
68         --build         - get all files from CVS repo or HTTP/FTP and build
69                           package from <package>.spec,
70         -bb,
71         --build-binary  - get all files from CVS repo or HTTP/FTP and build
72                           binary only package from <package>.spec,
73         -bs,
74         --build-source  - get all files from CVS repo or HTTP/FTP and only
75                           pack them into src.rpm,
76         -c, --clean     - clean all temporarily created files (in BUILD,
77                           SOURCES, SPECS and \$RPM_BUILD_ROOT),
78                           SOURCES, SPECS and \$RPM_BUILD_ROOT),
79         -d, --cvsroot   - setup \$CVSROOT,
80         -g, --get       - get <package>.spec and all related files from
81                           CVS repo or HTTP/FTP,
82         -h, --help      - this message,
83         -l, --logtofile - log all to file,
84         -m, --mr-proper - only remove all files related to spec file and
85                           all work resources,
86         -nc, --no-cvs   - don't download from CVS, if source URL is given,
87         -nu, --no-urls  - don't try to download from FTP/HTTP location,
88         -ns, --no-srcs  - don't downland Sources
89         --opts          - additional options for rpm
90         -q, --quiet     - be quiet,
91         -r, --cvstag    - build package using resources from specified CVS
92                           tag,
93         -v, --verbose   - be verbose,
94
95 "
96 }
97
98 parse_spec()
99 {
100     if [ -n "$DEBUG" ]; then 
101         set -x;
102         set -v;
103     fi
104
105     cd $SPECS_DIR
106
107     if [ "$NOSRCS" != "yes" ]; then
108         SOURCES="`rpm -bp --nobuild --define "prep %dump" $SPECFILE 2>&1 | awk '/SOURCEURL[0-9]+/ {print $3}'`"
109     fi
110
111     PATCHES="`rpm -bp --nobuild --define "prep %dump" $SPECFILE 2>&1 | awk '/PATCHURL[0-9]+/ {print $3}'`"
112     ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
113     PACKAGE_NAME="`rpm -bp --nobuild $SPECFILE.__ 2>&1 | awk '/ name/ {print $3}'`"
114     PACKAGE_VERSION="`rpm -bp --nobuild $SPECFILE.__ 2>&1 | awk '/ PACKAGE_VERSION/ {print $3}'`"
115     PACKAGE_RELEASE="`rpm -bp --nobuild $SPECFILE.__ 2>&1 | awk '/ PACKAGE_RELEASE/ {print $3}'`"
116
117     if [ -n "$BE_VERBOSE" ]; then
118         echo "- Sources :  `nourl $SOURCES`" 
119         if [ -n "$PATCHES" ]; then
120                 echo "- Patches :  `nourl $PATCHES`"
121         else
122                 echo "- Patches :  *no patches needed*"
123         fi
124         if [ -n "$ICONS" ]; then
125             echo "- Icon    :  `nourl $ICONS`"
126         else
127             echo "- Icon    :  *no package icon*"
128         fi
129         echo "- Name    : $PACKAGE_NAME"
130         echo "- Version : $PACKAGE_VERSION"
131         echo "- Release : $PACKAGE_RELEASE"
132     fi
133 }
134
135 Exit_error()
136 {
137     if [ -n "$DEBUG" ]; then 
138         set -x;
139         set -v; 
140     fi
141
142     cd $__PWD
143
144     case "$@" in
145     "err_no_spec_in_cmdl" )
146         echo "ERROR: spec file name not specified.";
147         exit 2 ;;
148     "err_no_spec_in_repo" )
149         echo "Error: spec file not stored in CVS repo.";
150         exit 3 ;;
151     "err_no_source_in_repo" )
152         echo "Error: some source, patch or icon files not stored in CVS repo.";
153         exit 4 ;;
154     "err_build_fail" )
155         echo "Error: package build failed.";
156         exit 5 ;;
157     esac
158 }
159
160 init_builder()
161 {
162     if [ -n "$DEBUG" ]; then 
163         set -x;
164         set -v; 
165     fi
166
167     SOURCE_DIR="`rpm --eval "%{_sourcedir}"`"
168     SPECS_DIR="`rpm --eval "%{_specdir}"`"
169
170     __PWD=`pwd`
171 }
172
173 get_spec()
174 {
175     if [ -n "$DEBUG" ]; then 
176         set -x;
177         set -v; 
178     fi
179
180     cd $SPECS_DIR
181
182     OPTIONS="up "
183
184     if [ -n "$CVSROOT" ]; then
185         OPTIONS="-d $CVSROOT $OPTIONS"
186     fi
187     if [ -n "$CVSTAG" ]; then
188         OPTIONS="$OPTIONS -r $CVSTAG"
189     else
190         OPTIONS="$OPTIONS -A"
191     fi
192
193     cvs $OPTIONS $SPECFILE
194     if [ "$?" -ne "0" ]; then
195         Exit_error err_no_spec_in_repo;
196     fi
197         if [ ! -f "$SPECFILE" ]; then
198         Exit_error err_no_spec_in_repo;
199         fi
200     
201     if [ "$CHMOD" = "yes" ]; then
202         chmod 444 $SPECFILE
203     fi
204     unset OPTIONS
205 }
206
207 get_files()
208 {
209     GET_FILES="$@"
210
211     if [ -n "$DEBUG" ]; then 
212         set -x;
213         set -v; 
214     fi
215
216     if [ -n "$1$2$3$4$5$6$7$8$9${10}" ]; then
217         cd $SOURCE_DIR
218
219         OPTIONS="up "
220         if [ -n "$CVSROOT" ]; then
221             OPTIONS="-d $CVSROOT $OPTIONS"
222         fi
223         if [ -n "$CVSTAG" ]; then
224             OPTIONS="$OPTIONS -r $CVSTAG"
225         else
226             OPTIONS="$OPTIONS -A"
227         fi
228         for i in $GET_FILES; do
229             if [ ! -f `nourl $i` ] || [ $ALLWAYS_CVSUP = "yes" ] 
230               then
231                 if 
232                         echo $i | grep -vE '(http|ftp|https|cvs)://' |\
233                         grep -qE '\.(gz|bz2)$'
234                 then
235                         echo "Warning: no URL given for $i"
236                 fi
237                 
238                 if      [ -z "$NOCVS" ]||\
239                         [ `echo $i | grep -vE '(ftp|http|https)://'` ]
240                 then
241                         cvs $OPTIONS `nourl $i`
242                 fi
243                 
244                 if      [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ]&&\
245                         [ `echo $i | grep -E 'ftp://|http://|https://'` ]
246                 then
247                         ${GETURI} "$i"
248                 fi
249
250                 if [ ! -f "`nourl $i`" ]; then
251                         Exit_error err_no_source_in_repo;
252                 fi
253             fi
254         done
255         
256         if [ "$CHMOD" = "yes" ]; then
257             chmod 444 `nourl $SOURCES $PATCHES $ICONS`
258         fi
259         unset OPTIONS
260     fi
261 }
262
263 build_package()
264 {
265     if [ -n "$DEBUG" ]; then 
266         set -x;
267         set -v; 
268     fi
269
270     cd $SPECS_DIR
271     case "$COMMAND" in
272         build )
273             BUILD_SWITCH="-ba" ;;
274         build-binary )
275             BUILD_SWITCH="-bb" ;;
276         build-source )
277             BUILD_SWITCH="-bs --nodeps" ;;
278     esac
279     nice -n ${DEF_NICE_LEVEL} rpm $BUILD_SWITCH -v $QUIET $CLEAN $RPMOPTS $SPECFILE 
280
281     if [ "$?" -ne "0" ]; then
282         Exit_error err_build_fail;
283     fi
284     unset BUILD_SWITCH
285 }
286
287 nourl()
288 {
289         echo "$@" | sed 's#\<\(ftp\|http\|https\|cvs\)://.*/##g'
290 }
291 #---------------------------------------------
292 # main()
293
294 if [ "$#" = 0 ]; then
295     usage;
296     exit 1
297 fi
298
299 while test $# -gt 0 ; do
300     case "${1}" in
301         -D | --debug )
302             DEBUG="yes"; shift ;;
303         -V | --version )
304             COMMAND="version"; shift ;;
305         -a | --as_anon )
306             CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
307         -b | -ba | --build )
308             COMMAND="build"; shift ;;
309         -bb | --build-binary )
310             COMMAND="build-binary"; shift ;;
311         -bs | --build-source )
312             COMMAND="build-source"; shift ;;
313         -c | --clean )
314             CLEAN="--clean --rmspec --rmsource"; shift ;;
315         -d | --cvsroot )
316             shift; CVSROOT="${1}"; shift ;;
317         -g | --get )
318             COMMAND="get"; shift ;;
319         -h | --help )
320             COMMAND="usage"; shift ;;
321         -l | --logtofile )
322             shift; LOGFILE="${1}"; shift ;;
323         -ni| --nice )
324             shift; DEF_NICE_LEVEL=${1}; shift ;;
325         -m | --mr-proper )
326             COMMAND="mr-proper"; shift ;;
327         -nc | --no-cvs )
328             NOCVS="yes"; shift ;;
329         -nu | --no-urls )
330             NOURLS="yes"; shift ;;
331         -ns | --no-srcs )
332             NOSRCS="yes"; shift ;;
333         --opts )
334             shift; RPMOPTS="${1}"; shift ;;
335         -q | --quiet )
336             QUIET="--quiet"; shift ;;
337         -r | --cvstag )
338             shift; CVSTAG="${1}"; shift ;;
339         -v | --verbose )
340             BE_VERBOSE="1"; shift ;;
341         * )
342             SPECFILE="${1}"; shift ;;
343     esac
344 done
345
346 if [ -n "$DEBUG" ]; then 
347         set -x;
348         set -v; 
349 fi
350
351 case "$COMMAND" in
352     "build" | "build-binary" | "build-source" )
353         init_builder;
354         if [ -n "$SPECFILE" ]; then
355             get_spec;
356             parse_spec;
357             if [ -n "$ICONS" ]; then
358                 get_files "$ICONS";
359                 parse_spec;
360             fi
361             get_files "$SOURCES $PATCHES";
362             build_package;
363         else
364             Exit_error err_no_spec_in_cmdl;
365         fi
366         ;;
367     "get" )
368         init_builder;
369         if [ -n "$SPECFILE" ]; then
370             get_spec;
371             parse_spec;
372             if [ -n "$ICONS" ]; then
373                     get_files "$ICONS"
374                     parse_spec;
375             fi
376             get_files "$SOURCES $PATCHES"
377         else
378             Exit_error err_no_spec_in_cmdl;
379         fi
380         ;;
381     "mr-proper" )
382         rpm --clean --rmsource --rmspec --force --nodeps $SPECFILE
383         ;;
384     "usage" )
385         usage;;
386     "version" )
387         echo "$VERSION";;
388 esac
389
390 cd $__PWD
391
392 # $Log$
393 #
This page took 0.100846 seconds and 3 git commands to generate.