]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- default $COMMAND if no switches passed (only spec dile name) is now
[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 ICON=""
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     ICON="`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 "$ICON" ]; then
78             echo "- Icon    :  $ICON"
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     cd $SOURCE_DIR
152     if [ -n "$CVSROOT" ]; then
153         cvs -d "$CVSROOT" up $SOURCES $PATCHES $ICON
154     else
155         cvs up $SOURCES $PATCHES $ICON
156     fi
157
158     if [ "$?" -ne "0" ]; then
159         Exit_error err_no_source_in_repo;
160     fi
161
162     chmod 444 $SOURCES $PATCHES $ICON
163 }
164
165 build_package()
166 {
167     cd $SPECS_DIR
168     rpm -ba -v $QUIET $CLEAN $SPECFILE
169
170     if [ "$?" -ne "0" ]; then
171         Exit_error err_build_fail;
172     fi
173 }
174
175
176 #---------------------------------------------
177 # main()
178
179 if [ "$#" == 0 ]; then
180     usage;
181     exit 1
182 fi
183
184 while test $# -gt 0 ; do
185     case "${1}" in
186         -V | --version )
187             COMMAND="version"; shift ;;
188         -a | --as_anon )
189             CVSROOT=":pserver:cvs@cvs.pld.org.pl:/cvsroot"; shift ;;
190         -b | --build )
191             COMMAND="build"; shift ;;
192         -c | --clean )
193             CLEAN="--clean --rmspec --rmsource"; shift ;;
194         -d | --cvsroot )
195             shift; CVSROOT="${1}"; shift ;;
196         -g | --get )
197             COMMAND="get"; shift ;;
198         -h | --help )
199             COMMAND="usage"; shift ;;
200         -l | --logtofile )
201             shift; LOGFILE="${1}"; shift ;;
202         -q | --quiet )
203             QUIET="--quiet"; shift ;;
204         -v | --verbose )
205             BE_VERBOSE="1"; shift ;;
206         * )
207             SPECFILE="${1}"; shift ;;
208     esac
209 done
210
211 case "$COMMAND" in
212     "build" )
213         init_builder;
214         if [ -n "$SPECFILE" ]; then
215             get_spec;
216             parse_spec;
217             get_all_files;
218             build_package;
219         else
220             Exit_error err_no_spec_in_cmdl;
221         fi
222         ;;
223     "get" )
224         init_builder;
225         if [ -n "$SPECFILE" ]; then
226             get_spec;
227             parse_spec;
228             get_all_files;
229         else
230             Exit_error err_no_spec_in_cmdl;
231         fi
232         ;;
233     "usage" )
234         usage;;
235     "version" )
236         echo "$VERSION";;
237 esac
238
239 cd $__PWD
This page took 0.0558 seconds and 4 git commands to generate.