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