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