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