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