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