-
Notifications
You must be signed in to change notification settings - Fork 3
/
BUILD_MYTHTV_RPMS
executable file
·237 lines (208 loc) · 6.1 KB
/
BUILD_MYTHTV_RPMS
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
#!/bin/bash
#
# Support mock config specification
#
MOCKOPTS=""
REPO="https://github.com/MythTV/mythtv.git"
while :; do
case $1 in
-r|--root) # Takes an option argument; ensure it has been specified.
if [ ! -z "$2" ]; then
MOCKOPTS="$MOCKOPTS --root=$2"
shift
else
printf 'ERROR: "--root" requires a non-empty option argument.\n'
exit 1
fi
;;
--root=*) # directly specified long argument
MOCKOPTS="$MOCKOPTS $1"
;;
--with)
if [ ! -z "$2" ]; then
MOCKOPTS="$MOCKOPTS --with=$2"
shift
else
printf 'ERROR: "--with" requires a non-empty option argument.\n'
exit 1
fi
;;
--with=*)
MOCKOPTS="$MOCKOPTS $1"
;;
--without)
if [ ! -z "$2" ]; then
MOCKOPTS="$MOCKOPTS --without=$2"
shift
else
printf 'ERROR: "--without" requires a non-empty option argument.\n'
exit 1
fi
;;
--without=*)
MOCKOPTS="$MOCKOPTS $1"
;;
--repo)
if [ ! -z "$2" ]; then
REPO="$2"
shift
else
printf 'ERROR: "--repo" requires a non-empty option argument.\n'
exit 1
fi
;;
--repo=*)
REPO="${1#*=}"
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
GITCOMMITISH=$1
if [ "$GITCOMMITISH" == "" ]; then
GITCOMMITISH="master"
fi
#
# First, we clone the repo, in order to obtain the
# description and commit hash for the specified
# version to build for/to (yes, this is sort of
# ugly, but while we can use ls-remote to get the
# commit hash, there is no (known) way to get the
# describe (maybe some future github api?))
#
TMPCLONEDIR=`mktemp -d`
pushd $TMPCLONEDIR >/dev/null
git clone $REPO mythtv
pushd mythtv >/dev/null
git checkout $GITCOMMITISH
if [ $? -ne 0 ]; then
echo "Unable to checkout $GITCOMMITISH in $TMPCLONEDIR/mythtv"
exit 1
fi
GITDESCRIBE=`git describe`
GITDESCRIBELONG=`git describe --long`
GITCOMMIT=`git rev-parse HEAD`
GITCOMMITSHORT=`git rev-parse --short HEAD`
GITCOMMITDATE=`TZ=UTC git --no-pager log -1 --format='%cd' --date=format:"%Y%m%d"`
popd >/dev/null
popd >/dev/null
# MythTV project specific tag format
if ! [ ${GITDESCRIBE:0:1} == 'v' ]; then
echo "Unable to parse mythtv git describe $GITDESCRIBE from $TMPCLONEDIR/mythtv"
exit 1
fi
# Adjust git-describe to acceptable RPM format
RPMVERSION=${GITDESCRIBE:1}
RPMVERSION=${RPMVERSION//-/.}
# Determine if we are at a post branch/tag checkout
# and adjust the describe to use the current
# recommendations for the package name
if [ "$GITDESCRIBE" == "$GITDESCRIBELONG" ] ; then
RPMVERSION=${RPMVERSION:0:-(${#GITCOMMITSHORT} + 1)}${GITCOMMITDATE}git${GITCOMMITSHORT}
fi
#
# Announce to world and dog what we are doing
#
echo "----"
echo "Building mythtv version $RPMVERSION at commit $GITCOMMIT"
echo "----"
#
# Build an expanded SPEC file with our definitions so that
# the src.rpm will be reproducably buildable outside of this
# build script
#
TMPSDIR=`mktemp -d`
cp -r SOURCES $TMPSDIR/
cp -r SPECS $TMPSDIR/
sed -i -e "s/^Version: .*/Version: $RPMVERSION/" $TMPSDIR/SPECS/mythtv.spec
sed -i -e "s/^%global commit .*/%global commit $GITCOMMIT/" $TMPSDIR/SPECS/mythtv.spec
sed -i -e "s/^Version: .*/Version: $RPMVERSION/" $TMPSDIR/SPECS/mythtv-plugins.spec
sed -i -e "s/^%global commit .*/%global commit $GITCOMMIT/" $TMPSDIR/SPECS/mythtv-plugins.spec
# Use git-archive to create source tarball from our clone
pushd $TMPCLONEDIR/mythtv > /dev/null
git archive --output $TMPSDIR/SOURCES/mythtv-$GITCOMMIT.tar.gz --prefix mythtv-$GITCOMMIT/ $GITCOMMIT
popd >/dev/null
# Cleanup our clone
rm -rf $TMPCLONEDIR/mythtv
rmdir $TMPCLONEDIR
#
# create src.rpm resultdir
#
TMPSRCRPMDIR=`mktemp -d`
#
# Build buildable src.rpms
#
mock $MOCKOPTS --define="dist %{nil}" --spec=$TMPSDIR/SPECS/mythtv.spec --sources=$TMPSDIR/SOURCES --resultdir=$TMPSRCRPMDIR --buildsrpm
if [ $? -ne 0 ]; then
echo "Unable to build source rpm"
exit 1
fi
SRCBASERPM=`ls $TMPSRCRPMDIR/mythtv-*$RPMVERSION*.src.rpm`
if [ ! -f "$SRCBASERPM" ]; then
echo "Source RPM for mythtv was not built"
exit 1
fi
mock $MOCKOPTS --define="dist %{nil}" --spec=$TMPSDIR/SPECS/mythtv-plugins.spec --sources=$TMPSDIR/SOURCES --resultdir=$TMPSRCRPMDIR --buildsrpm
if [ $? -ne 0 ]; then
echo "Unable to build source rpm"
exit 1
fi
SRCPLUGINSRPM=`ls $TMPSRCRPMDIR/mythtv-plugins-*$RPMVERSION*.src.rpm`
if [ ! -f "$SRCPLUGINSRPM" ]; then
echo "Source RPM for mythtv-plugins was not built"
exit 1
fi
#
# Create rpm localrepo dir
#
TMPLOCALREPODIR=`mktemp -p /var/tmp -d`
#
# Build the mythtv rpms
#
mock $MOCKOPTS --chain --localrepo=$TMPLOCALREPODIR $SRCBASERPM $SRCPLUGINSRPM
if [ $? -ne 0 ]; then
echo "Unable to build mythtv rpms"
exit 1
fi
#
# Obtain/copy rpms
#
REPORPMS=`find $TMPLOCALREPODIR/ -name \*.rpm -print`
mkdir -p SRPMS RPMS
for fn in ${REPORPMS}
do
[[ "$fn" =~ ^.*\.(.+)\.rpm$ ]] &&
(
archdir="${BASH_REMATCH[1]}"
if [ "$archdir" == "src" ]; then
cp $fn SRPMS/
else
if [ "$archdir" == "i686" ]; then
archdir="i386"
elif [ "$archdir" == "armv7hl" ]; then
archdir="armhfp"
fi
mkdir -p RPMS/$archdir
cp $fn RPMS/$archdir/
fi
)
done
#
# Cleanup
#
rm -f $TMPSRCRPMDIR/*.log
rm -f $TMPSRCRPMDIR/*.rpm
rmdir $TMPSRCRPMDIR
rm -rf $TMPLOCALREPODIR/results
rmdir $TMPLOCALREPODIR
rm -rf $TMPSDIR/SPECS
rm -rf $TMPSDIR/SOURCES
rmdir $TMPSDIR