]> git.pld-linux.org Git - packages/rpm-build-tools.git/blob - builder.sh
-n instead != ""
[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/^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 | grep "SOURCE_DIR"`
120     SPEC_DIR=`rpm -bp $DUMB_SPEC_FILE | grep "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 [ "${CVSROOT}" != "" ]; then
132         cvs -d "$CVSROOT" up $SPECFILE
133     else
134         cvs up $SPECFILE
135     fi
136
137     if [ "$?" != 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 [ "${CVSROOT}" != ""]; then
146         cvs -d "$CVSROOT" up $SOURCES $PATCHES $ICON
147     else
148         cvs up $SPECFILE
149     fi
150
151
152     if [ "$?" != 0 ]; then
153         Exit_error err_no_source_in_repo;
154     fi
155 }
156
157 build_package()
158 {
159     cd $SPECS_DIR
160     rpm -ba -v $QUIET $SPECFILE
161
162     if [ "$?" != 0 ]; then
163         Exit_error err_build_fail;
164     fi
165 }
166
167
168 #---------------------------------------------
169 # main()
170
171 if [ "$#" == 0 ]; then
172     usage;
173     exit 1
174 fi
175
176 while test $# -gt 0 ; do
177     case "${1}" in
178         -V | --version )
179             COMMAND="version"; shift ;;
180         -a | --as_anon )
181             CVSROOT=":pserver:cvs@cvs.pld.org.pl:/cvsroot"; shift ;;
182         -b | --build )
183             COMMAND="build"; shift ;;
184         -d | --cvsroot )
185             shift; CVSROOT="${1}"; shift ;;
186         -g | --get )
187             COMMAND="get"; shift ;;
188         -h | --help )
189             COMMAND="usage"; shift ;;
190         -l | --logtofile )
191             shift; LOGFILE="${1}"; shift ;;
192         -q | --quiet )
193             QUIET="--quiet"; shift ;;
194         -v | --verbose )
195             BE_VERBOSE="1"; shift ;;
196         * )
197             SPECFILE="${1}"; shift ;;
198     esac
199 done
200
201 case "$COMMAND" in
202     "build" )
203         init_builder;
204         if [ -n "$SPECFILE" ]; then
205             get_spec;
206             parse_spec;
207             get_all_files;
208             build_package;
209         else
210             Exit_error err_no_spec_in_cmdl;
211         fi
212         ;;
213     "get" )
214         init_builder;
215         if [ -n "$SPECFILE" ]; then
216             get_spec;
217             parse_spec;
218             get_all_files;
219         else
220             Exit_error err_no_spec_in_cmdl;
221         fi
222         ;;
223     "usage" )
224         usage;;
225     "version" )
226         echo "$VERSION";;
227 esac
This page took 0.065228 seconds and 4 git commands to generate.