Ticket #9452: build_myth.sh

File build_myth.sh, 9.7 KB (added by David Knight <dlknight@…>, 13 years ago)
Line 
1#!/bin/bash
2
3#
4# Script for building MythTV packages from an SVN checkout.
5#
6# by:   Chris Petersen <rpm@forevermore.net>
7#
8# The latest version of this file can be found in mythtv git repository:
9#
10# https://github.com/MythTV/packaging/tree/fixes/0.24/rpm/build_myth.sh
11#
12# See --help for usage instructions.
13#
14# Please make sure that the rpm build parameters are to your liking (a
15# number of plugins are disabled by default/example in this script to
16# show you that the spec is capable of compiling only those plugins that
17# you wish to install).  The same goes for the installmyth function,
18# which only installs those packages which I personally use.
19#
20# I will eventually clean up this script to enhance the parameters and
21# make it a little easier to configure/use.
22#
23
24###############################################################################
25# Configuration
26###############################################################################
27
28# Hard-code the version of MythTV
29    VERSION="0.24"
30
31# Branch should be "master" or "stable"
32    BRANCH="master"
33
34# Hard-code the git clone directory.  Leave blank to auto-detect based on
35# the location of this script
36    GITDIR=""
37
38###############################################################################
39# Functions to be used by the program
40###############################################################################
41
42# Print the help/usage message
43    function usage {
44        cat <<EOF
45Usage:  $PROG [OPTIONS]
46
47Build RPMs for MythTV, MythPlugins, etc.
48
49Options:
50
51$PROG --help
52
53    print this menu
54
55$PROG -i REVISION
56$PROG --install REVISION
57
58    Install the pre-build package for REVISION
59
60$PROG REVISION
61$PROG -r REVISION
62$PROG --revision REVISION
63
64    Build/install the requested revision
65
66EOF
67    }
68
69# Update the requested spec to the requested revision/branch/version
70    function updatespec {
71        R="$1"
72        SPEC="$2"
73        echo "Updating $SPEC _gitver to r$R"
74        sed -i \
75            -e "s,define _gitrev .\+,define _svnrev r$R," \
76            -e "s,define branch .\+,define branch $BRANCH,"  \
77            -e "s,Version:.\+,Version: $VERSION,"             \
78            $SPEC
79    }
80
81# Function to build mythtv packages
82    function buildmyth {
83    # Remove the existing mythtv-devel so it doesn't confuse qmake
84    # (we can't override the order of the include file path)
85        PKG=`rpm -q mythtv-devel`
86        if [ `expr match "$PKG" 'mythtv-libs.*'` -gt 0 ]; then
87            echo "Removing existing mythtv-devel package to avoid conflicts"
88            sudo rpm -e mythtv-devel.i386 mythtv-devel.x86_64 2>/dev/null
89        fi
90    # Clean up any old tarballs that might exist
91        rm -f "$ABSPATH"/mythtv/myth*.tar.bz2
92    # Create the appropriate tarballs
93        echo "Creating tarballs from git clones at $GITDIR"
94        for file in mythtv mythplugins; do
95            git archive --format tar --remote "$GITDIR"/ HEAD "$file"/ | bzip2 > "$ABSPATH/mythtv/$file-$GITVER.tar.bz2"
96            echo "$ABSPATH/mythtv/$file-$GITVER.tar.bz2"
97        done
98    # Build MythTV
99        time rpmbuild -bb "$ABSPATH"/mythtv.spec \
100            --define "_sourcedir $ABSPATH/mythtv" \
101            --with debug            \
102            --without mytharchive   \
103            --without mythgallery   \
104            --without mythgame      \
105            --without mythnews      \
106            --without mythzoneminder
107    # Error?
108        if [ "$?" -ne 0 ]; then
109            echo "MythTV build error."
110            return
111        fi
112    # Install
113        echo -n "Install $VSTRING? [n] "
114        read INST
115        if [ "$INST" = "y" -o "$INST" = "Y" -o "$INST" = "yes" ]; then
116            installmyth "$VSTRING"
117        else
118            echo "If you wish to install later, just run: $PROG --install \"$VSTRING\""
119        fi
120    }
121
122# Function to build mythtv themes packages
123    function buildthemes {
124    # Update the SVN checkout -- make sure not to
125        svnupdate mythtv-themes "$1"
126    # Update the spec
127        updatespec $REL "$ABSPATH/mythtv-themes.spec"
128    # Clean up any old tarballs that might exist
129        rm -f "$ABSPATH"/mythtv-themes/*themes*.tar.bz2
130    # Create the appropriate tarballs
131        for file in myththemes themes; do
132            if [ -d "$file-$GITVER" ]; then
133                rm -rf "$file-$GITVER"
134            fi
135            echo -n "    "
136            mv "$file" "$file-$GITVER"
137            tar jcf "$ABSPATH/mythtv-themes/$file-$GITVER.tar.bz2" --exclude .svn "$file-$GITVER"
138            mv "$file-$GITVER" "$file"
139            echo "$ABSPATH/mythtv-themes/$file-$GITVER.tar.bz2"
140        done
141    # Disabled until I can clean this up later -- themes now require mythtv-libs in
142    # order to compile.
143    #
144    ## Build MythTV Themes
145    #    rpmbuild -bb /usr/src/redhat/SPECS/mythtv-themes.spec
146    ## Error?
147    #    if [ "$?" -ne 0 ]; then
148    #        echo "MythTV Themes build error."
149    #        return
150    #    fi
151    }
152
153# A function to install mythtv packages
154    function installmyth {
155        sudo rpm -Uvh --force --nodeps                                                   \
156            /usr/src/redhat/RPMS/x86_64/mythtv-docs-$GITVER-0.1.git.$GITREV.*.rpm         \
157            /usr/src/redhat/RPMS/x86_64/mythtv-libs-$GITVER-0.1.git.$GITREV.*.rpm             \
158            /usr/src/redhat/RPMS/x86_64/mythtv-devel-$GITVER-0.1.git.$GITREV.*.rpm       \
159            /usr/src/redhat/RPMS/x86_64/mythtv-base-themes-$GITVER-0.1.git.$GITREV.*.rpm  \
160            /usr/src/redhat/RPMS/x86_64/mythtv-frontend-$GITVER-0.1.git.$GITREV.*.rpm     \
161            /usr/src/redhat/RPMS/x86_64/mythtv-backend-$GITVER-0.1.git.$GITREV.*.rpm      \
162            /usr/src/redhat/RPMS/x86_64/mythtv-setup-$GITVER-0.1.git.$GITREV.*.rpm        \
163            /usr/src/redhat/RPMS/x86_64/mythtv-common-$GITVER-0.1.git.$GITREV.*.rpm       \
164            /usr/src/redhat/RPMS/x86_64/perl-MythTV-$GITVER-0.1.git.$GITREV.*.rpm         \
165            /usr/src/redhat/RPMS/x86_64/python-MythTV-$GITVER-0.1.git.$GITREV.*.rpm       \
166            /usr/src/redhat/RPMS/x86_64/mythmusic-$GITVER-0.1.git.$GITREV.*.rpm           \
167            /usr/src/redhat/RPMS/x86_64/mythbrowser-$GITVER-0.1.git.$GITREV.*.rpm         \
168            /usr/src/redhat/RPMS/x86_64/mythnetvision-$GITVER-0.1.git.$GITREV.*.rpm       \
169            /usr/src/redhat/RPMS/x86_64/mythvideo-$GITVER-0.1.git.$GITREV.*.rpm           \
170            /usr/src/redhat/RPMS/x86_64/mythweather-$GITVER-0.1.git.$GITREV.*.rpm         \
171            /usr/src/redhat/RPMS/x86_64/mythtv-debuginfo-$GITVER-0.1.git.$GITREV.*.rpm
172            #/usr/src/redhat/RPMS/x86_64/mythtv-themes-$GITVER-0.1.git.$GITREV.*.rpm  \
173    }
174
175# And a function to install mythtv theme packages, since they need mythtv-libs
176# to be already installed in order to build them
177    function installthemes {
178        REL="$1"
179    }
180
181
182###############################################################################
183# Actually execute the program here
184###############################################################################
185
186# Get the absolute path to this script
187    ABSPATH=$(cd `dirname "$0"` && pwd)
188
189# The nice name of this program
190    PROG=`basename $0`
191
192# Check a few things for sanity
193    for PKG in 'mythtv' 'mythtv-themes'; do
194    # Make sure the spec exists
195        if [ ! -f "$ABSPATH/$PKG.spec" ]; then
196            echo "$ABSPATH/$PKG.spec does not exist"
197            exit
198        fi
199    # Make sure we have a sources directory
200        if [ ! -d "$ABSPATH/$PKG/" ]; then
201            echo "$ABSPATH/$PKG does not exist"
202            exit
203        fi
204    done
205
206# Auto-detect the source directory?
207    if [ -z "$GITDIR" ]; then
208        GITDIR=$(dirname $(dirname "$ABSPATH"))/mythtv
209    fi
210    if [ ! -d "$GITDIR" ]; then
211        echo "$GITDIR does not exist.  Please check out using:"
212        echo "    git clone -b fixes/0.24 https://github.com/MythTV/mythtv"
213        exit
214    fi
215
216# Default revision
217    REV=""
218
219# Do the requested operation
220    case "$1" in
221        -h*|--h*|h*|-u*|--u*|u*)
222            usage
223            exit
224            ;;
225        -i*|--i*|i*)
226            installmyth "$2"
227            exit
228            ;;
229        -r*|--r*|r*)
230            REV="$2"
231            ;;
232        *)
233            REV="$1"
234    esac
235
236# Make sure our git clone is up to date
237    echo "Fetching latest information from git repository."
238    cd "$GITDIR"
239    git fetch
240    git fetch --tags
241
242# Get information about the latest/requested Git sha
243    if [[ $REV ]]; then
244        DESCRIBE=`git describe "$REV" -- 2>/dev/null`
245    else
246        DESCRIBE=`git describe -- 2>/dev/null`
247    fi
248    if [[ ! $DESCRIBE ]]; then
249        echo "Unknown/Invalid revision:  $REV"
250        exit
251    fi
252    GITVER=`echo "$DESCRIBE" | sed -e 's,^\([^-]\+\)-.\+$,\1,'`
253    GITREV=`echo "$DESCRIBE" | sed -e 's,^[^-]\+-,,' -e 's,-,.,'`
254    # do some magic here to detect v, b, or pre notations
255    if [[ $GITVER =~ pre$ ]]; then
256        GITVER=${GITVER#v}
257        GITVER=${GITVER%pre}
258    elif [[ $GITVER =~ ^v ]]; then
259        GITVER=${GITVER#v}
260        GITREV=1
261    elif [[ $GITVER =~ ^b ]]; then
262        GITVER=0.$((${GITVER#b0.}+1))
263        GITREV="0.$GITREV"
264    fi
265    VSTRING="$GITVER.$GITREV"
266
267# Done doing that, now back to the working dir
268    cd - >/dev/null
269
270# What to do now?
271    if [[ ! $REV ]]; then
272        echo "Building $VSTRING (latest revision)"
273    else
274        echo "Building $VSTRING"
275    fi
276
277# Update the revision in the specfile
278    echo "Updating mythtv.spec _gitver to $VSTRING"
279    sed -i \
280        -e "s,define _gitrev .\+,define _gitrev $GITREV," \
281        -e "s,define branch .\+,define branch $BRANCH,"   \
282        -e "s,define vers_string .\+,define vers_string $DESCRIBE,"   \
283        -e "s,Version:.\+,Version: $GITVER,"              \
284        mythtv.spec
285
286# Update the other spec files to the MythTV spec version
287    # later...
288
289# Build MythTV
290    buildmyth
291
292# Done
293    exit
294