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