menu: added new Keywords tag to .desktop files
[barry.git] / maintainer / make-rpm.sh
blobf8a7acfa5c31af02d3e39c35e99a7f6a77b97649
1 #!/bin/bash
3 if [ -z "$1" -o -z "$2" -o -z "$3" -o -z "$4" -o -z "$5" ] ; then
4 echo
5 echo "Usage: ./make-rpm.sh tarball spec_target rpm_args build_dir results_dir"
6 echo
7 echo "<build_dir>/rpmbuild is the RPM tree where the build will"
8 echo "take place. If rpmbuild does not exist, but SPECS does, then"
9 echo "it is assumed build_dir == the rpmbuild dir. This is useful"
10 echo "in the (hopefully) rare occasions where you need to build in"
11 echo "/usr/src."
12 echo
13 echo "tarball is the full pathname of the tarball to extract."
14 echo "It is allowed to be relative to the current directory."
15 echo "It will be copied to rpmbuild/SOURCES, and the entire tar tree"
16 echo "will be extracted into <builddir>/binarybuild,"
17 echo "in order to fetch the spec file."
18 echo
19 echo "spec_target is the filename of the tarball spec file to use"
20 echo "when building. For example, in most cases it will be"
21 echo "rpm/barry.spec. This file will be copied into rpmbuild/SPECS"
22 echo "as 'barry.spec' and will be used to build the binary packages."
23 echo "If the string is empty, this step will be skipped."
24 echo
25 echo "rpm_args is the full command line to build the package."
26 echo
27 echo "<results_dir>/results/ is where the resulting RPM and SRC RPM"
28 echo "packages will be copied."
29 echo
30 exit 1
33 TARBALL="$1"
34 SPECPATH="$2"
35 RPMTARGETS="$3"
36 RPMPATH="$4"
37 if [ -d "$RPMPATH/rpmbuild/SPECS" ] ; then
38 RPMPATH="$4/rpmbuild"
40 BUILDPATH="$RPMPATH/binarybuild"
41 DESTPATH="$5/results"
43 set -e
46 # Note that all commands below are done from the current directory.
47 # Where the directory must change, it is done within brackets so that
48 # we return to the current directory immediately afterward.
50 # This is so that all paths and directories given on the command line
51 # may be relative, and everything still works.
54 # setup directories
55 rm -rf "$BUILDPATH"
56 mkdir -p "$BUILDPATH"
57 rm -rf "$DESTPATH"
58 mkdir -p "$DESTPATH"
59 rm -f "$RPMPATH"/RPMS/*/* "$RPMPATH"/SRPMS/*
61 # expand source
62 tar -C "$BUILDPATH" -xjvf "$TARBALL"
64 # setup RPM build tree
65 cp "$TARBALL" "$RPMPATH/SOURCES"
66 if [ -n "$SPECPATH" ] ; then
67 cp "$BUILDPATH"/barry-*/"$SPECPATH" "$RPMPATH/SPECS/barry.spec"
70 # build binary packages
71 if ! (cd "$RPMPATH"/SPECS && eval $RPMTARGETS) ; then
72 echo "RPM build failed"
73 exit 1
76 # move results to destination directory
77 mv $(find "$RPMPATH/RPMS" "$RPMPATH/SRPMS" -type f -name "*barry*.rpm" -print) "$DESTPATH"