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