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