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