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