]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
- getting spec file now work.
[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 #---------------------------------------------
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/^Summary:*/Summary:\%dump/I" $SPECFILE > $SPECFILE.__
59
60     SOURCES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ SOURCE[0-9]+/ {print $3}'`"
61     PATCHES="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/ PATCH[0-9]+/ {print $3}'`"
62     ICON="`rpm -bp --test $SPECFILE.__ 2>&1 | awk '/^Icon:/ {print $2}' ${SPEC}`"
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 [ "$BE_VERBOSE" != "" ]; then
70         echo -e "- Sources :\n  " $SOURCES
71         echo -e "- Patches :\n  " $PATCHES
72         if [ "$ICON" != "" ]; then
73             echo -e "- Icon    :\n  " $ICON
74         else
75             echo -e "- Icon    :  *no package icon*"
76         fi
77         echo -e "- Name    : " $PACKAGE_NAME
78         echo -e "- Version : " $PACKAGE_VERSION
79         echo -e "- 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 echo aaa \"$SPECS_DIR\" 
123 #    rm -f $DUMB_SPEC_FILE
124
125     __PWD=`pwd`
126 }
127
128 get_spec()
129 {
130     cd $SPECS_DIR
131
132     if [ "$CVSROOT" -n "" ]; then
133         cvs -d "$CVSROOT" up $SPECFILE
134     else
135         cvs up $SPECFILE
136     fi
137
138     if [ "$?" != 0 ]; then
139         Exit_error err_no_spec_in_repo;
140     fi
141 }
142
143 get_all_files()
144 {
145     cd $SOURCE_DIR
146     if [ "$CVSROOT" -n ""]; then
147         cvs -d "$CVSROOT" up $SOURCES $PATCHES $ICON
148     else
149         cvs up $SPECFILE
150     fi
151
152
153     if [ "$?" != 0 ]; then
154         Exit_error err_no_source_in_repo;
155     fi
156 }
157
158 build_package()
159 {
160     cd $SPECS_DIR
161     rpm -ba -v $QUIET $SPECFILE
162
163     if [ "$?" != 0 ]; then
164         Exit_error err_build_fail;
165     fi
166 }
167
168
169 #---------------------------------------------
170 # main()
171
172 if [ "$#" == 0 ]; then
173     usage;
174     exit 1
175 fi
176
177 while test $# -gt 0 ; do
178     case "${1}" in
179         -V | --version )
180             COMMAND="version"; shift ;;
181         -a | --as_anon )
182             CVSROOT=":pserver:cvs@cvs.pld.org.pl:/cvsroot"; shift ;;
183         -b | --build )
184             COMMAND="build"; shift ;;
185         -d | --cvsroot )
186             shift; CVSROOT="${1}"; shift ;;
187         -g | --get )
188             COMMAND="get"; shift ;;
189         -h | --help )
190             COMMAND="usage"; shift ;;
191         -l | --logtofile )
192             shift; LOGFILE="${1}"; shift ;;
193         -q | --quiet )
194             QUIET="--quiet"; shift ;;
195         -v | --verbose )
196             BE_VERBOSE="1"; shift ;;
197         * )
198             SPECFILE="${1}"; shift ;;
199     esac
200 done
201
202 case "$COMMAND" in
203     "build" )
204         init_builder;
205         if [ -n "$SPECFILE" ]; then
206             get_spec;
207             parse_spec;
208             get_all_files;
209             build_package;
210         else
211             Exit_error err_no_spec_in_cmdl;
212         fi
213         ;;
214     "get" )
215         init_builder;
216         if [ -n "$SPECFILE" ]; then
217             get_spec;
218             parse_spec;
219             get_all_files;
220         else
221             Exit_error err_no_spec_in_cmdl;
222         fi
223         ;;
224     "usage" )
225         usage;;
226     "version" )
227         echo "$VERSION";;
228 esac
This page took 0.047436 seconds and 4 git commands to generate.