]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- added "no-cvs" option to prevent builder from downloading sources
[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 set -xv; fi
92
93     sed -e "s#%prep#%dump#I" $SPECFILE | grep -v -i "^Icon\:" > $SPECFILE.__
94
95     SOURCES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ SOURCEURL[0-9]+/ {print $3}'`"
96     PATCHES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ PATCHURL[0-9]+/ {print $3}'`"
97     ICONS="`awk '/^Icon:/ {print $2}' ${SPECFILE}`"
98     PACKAGE_NAME="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ name/ {print $3}'`"
99     PACKAGE_VERSION="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ PACKAGE_VERSION/ {print $3}'`"
100     PACKAGE_RELEASE="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ PACKAGE_RELEASE/ {print $3}'`"
101
102     rm -f $SPECFILE.__
103
104     if [ -n "$BE_VERBOSE" ]; then
105         echo "- Sources :  `nourl $SOURCES`" 
106         if [ -n "$PATCHES" ]; then
107                 echo "- Patches :  `nourl $PATCHES`"
108         else
109                 echo "- Patches :  *no patches needed*"
110         fi
111         if [ -n "$ICONS" ]; then
112             echo "- Icon    :  `nourl $ICONS`"
113         else
114             echo "- Icon    :  *no package icon*"
115         fi
116         echo "- Name    : $PACKAGE_NAME"
117         echo "- Version : $PACKAGE_VERSION"
118         echo "- Release : $PACKAGE_RELEASE"
119     fi
120 }
121
122 Exit_error()
123 {
124     if [ -n "$DEBUG" ]; then set -xv; fi
125
126     cd $__PWD
127
128     case "$@" in
129     "err_no_spec_in_cmdl" )
130         echo "ERROR: spec file name not specified.";
131         exit 2 ;;
132     "err_no_spec_in_repo" )
133         echo "Error: spec file not stored in CVS repo.";
134         exit 3 ;;
135     "err_no_source_in_repo" )
136         echo "Error: some source, patch or icon files not stored in CVS repo.";
137         exit 4 ;;
138     "err_build_fail" )
139         echo "Error: package build failed.";
140         exit 5 ;;
141     esac
142 }
143
144 init_builder()
145 {
146     if [ -n "$DEBUG" ]; then set -xv; fi
147
148     SOURCE_DIR="`rpm --eval "%{_sourcedir}"`"
149     SPECS_DIR="`rpm --eval "%{_specdir}"`"
150
151     __PWD=`pwd`
152 }
153
154 get_spec()
155 {
156     if [ -n "$DEBUG" ]; then set -xv; fi
157
158     cd $SPECS_DIR
159
160     OPTIONS="up "
161
162     if [ -n "$CVSROOT" ]; then
163         OPTIONS="-d $CVSROOT $OPTIONS"
164     fi
165     if [ -n "$CVSTAG" ]; then
166         OPTIONS="$OPTIONS -r $CVSTAG"
167     else
168         OPTIONS="$OPTIONS -A"
169     fi
170
171     cvs $OPTIONS $SPECFILE
172     if [ "$?" -ne "0" ]; then
173         Exit_error err_no_spec_in_repo;
174     fi
175         if [ ! -f "$SPECFILE" ]; then
176         Exit_error err_no_spec_in_repo;
177         fi
178     
179     if [ "$CHMOD" = "yes" ]; then
180         chmod 444 $SPECFILE
181     fi
182     unset OPTIONS
183 }
184
185 get_all_files()
186 {
187     if [ -n "$DEBUG" ]; then set -xv; fi
188
189     if [ -n "$SOURCES$PATCHES$ICONS" ]; then
190         cd $SOURCE_DIR
191
192         OPTIONS="up "
193         if [ -n "$CVSROOT" ]; then
194             OPTIONS="-d $CVSROOT $OPTIONS"
195         fi
196         if [ -n "$CVSTAG" ]; then
197             OPTIONS="$OPTIONS -r $CVSTAG"
198         else
199             OPTIONS="$OPTIONS -A"
200         fi
201         for i in $SOURCES $PATCHES $ICONS; do
202                 if 
203                         echo $i | grep -v '^\(http\|ftp\)://' |\
204                         grep -q '\.\(gz\|bz2\)$'
205                 then
206                         echo "Warning: no URL given for $i"
207                 fi
208                 
209                 if      [ -z "$NOCVS" ]||\
210                         [ `echo $i | grep -v 'ftp://\|http://'` ]
211                 then
212                         cvs $OPTIONS `nourl $SOURCES $PATCHES $ICONS`
213                 fi
214                 
215                 if      [ -z "$NOURLS" ]&&[ ! -f "`nourl $i`" ]&&\
216                         [ `echo $i | grep 'ftp://\|http://'` ]
217                 then
218                         wget -c -t0 "$i"
219                 fi
220
221                 if [ ! -f "`nourl $i`" ]; then
222                         Exit_error err_no_source_in_repo;
223                 fi
224         done
225         
226         if [ "$CHMOD" = "yes" ]; then
227             chmod 444 `nourl $SOURCES $PATCHES $ICONS`
228         fi
229         unset OPTIONS
230     fi
231 }
232
233 build_package()
234 {
235     if [ -n "$DEBUG" ]; then set -xv; fi
236
237     cd $SPECS_DIR
238     case "$COMMAND" in
239         build )
240             BUILD_SWITCH="-ba" ;;
241         build-binary )
242             BUILD_SWITCH="-bb" ;;
243         build-source )
244             BUILD_SWITCH="-bs" ;;
245     esac
246     rpm $BUILD_SWITCH -v $QUIET $CLEAN $SPECFILE
247
248     if [ "$?" -ne "0" ]; then
249         Exit_error err_build_fail;
250     fi
251     unset BUILD_SWITCH
252 }
253
254 nourl()
255 {
256         echo "$@" | sed 's#\<\(ftp\|http\)://.*/##g'
257 }
258 #---------------------------------------------
259 # main()
260
261 if [ "$#" = 0 ]; then
262     usage;
263     exit 1
264 fi
265
266 while test $# -gt 0 ; do
267     case "${1}" in
268         -D | --debug )
269             DEBUG="yes"; shift ;;
270         -V | --version )
271             COMMAND="version"; shift ;;
272         -a | --as_anon )
273             CVSROOT=":pserver:cvs@anoncvs.pld.org.pl:/cvsroot"; shift ;;
274         -b | -ba | --build )
275             COMMAND="build"; shift ;;
276         -bb | --build-binary )
277             COMMAND="build-binary"; shift ;;
278         -bs | --build-source )
279             COMMAND="build-source"; shift ;;
280         -c | --clean )
281             CLEAN="--clean --rmspec --rmsource"; shift ;;
282         -d | --cvsroot )
283             shift; CVSROOT="${1}"; shift ;;
284         -g | --get )
285             COMMAND="get"; shift ;;
286         -h | --help )
287             COMMAND="usage"; shift ;;
288         -l | --logtofile )
289             shift; LOGFILE="${1}"; shift ;;
290         -m | --mr-proper )
291             COMMAND="mr-proper"; shift ;;
292         -nc | --no-cvs )
293             NOCVS="yes"; shift ;;
294         -nu | --no-urls )
295             NOURLS="yes"; shift ;;
296         -q | --quiet )
297             QUIET="--quiet"; shift ;;
298         -r | --cvstag )
299             shift; CVSTAG="${1}"; shift ;;
300         -v | --verbose )
301             BE_VERBOSE="1"; shift ;;
302         * )
303             SPECFILE="${1}"; shift ;;
304     esac
305 done
306
307 if [ -n "$DEBUG" ]; then set -xv; fi
308
309 case "$COMMAND" in
310     "build" | "build-binary" | "build-source" )
311         init_builder;
312         if [ -n "$SPECFILE" ]; then
313             get_spec;
314             parse_spec;
315             get_all_files;
316             build_package;
317         else
318             Exit_error err_no_spec_in_cmdl;
319         fi
320         ;;
321     "get" )
322         init_builder;
323         if [ -n "$SPECFILE" ]; then
324             get_spec;
325             parse_spec;
326             get_all_files;
327         else
328             Exit_error err_no_spec_in_cmdl;
329         fi
330         ;;
331     "mr-proper" )
332         rpm --clean --rmsource --rmspec --force --nodeps $SPECFILE
333         ;;
334     "usage" )
335         usage;;
336     "version" )
337         echo "$VERSION";;
338 esac
339
340 cd $__PWD
This page took 0.058599 seconds and 3 git commands to generate.