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