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