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