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