forked from QMailToaster/qmailtoaster-develope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qt-build-srpms
executable file
·206 lines (173 loc) · 5.43 KB
/
qt-build-srpms
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
#!/bin/bash
# Copyright (C) 2009-2013 Eric Shubert <[email protected]>
#
# Build QMailToaster srpm file
######################################################################
# Change Log
# 05/26/14 shubes - removed test, unit_tests from clamav source
# 12/15/13 shubes - cleaned up input parameter, multi-spec process
# 12/14/13 shubes - don't overlay github from existing srpm
# 12/05/13 shubes - added multiple specs per repo for qmailadmin-spambox
# 12/03/13 shubes - removed win32 from clamav source
# 12/02/13 shubes - fixed up 'expect' code
# 11/29/13 shubes - modified to copy resulting src.rpm to repo staging
# 11/28/13 shubes - modified to use gspecdir as rpmbuild/SOURCES
# - added spectool for obtaining external sources
# - refactored a bit
# 11/25/13 shubes - created
# TODOs:
# .) check mygithub for uncommitted changes
# .) check mygithub SHA against lastest SHA on github.com (unpushed commits)
# e.g. https://api.github.com/repos/QmailToaster/qmailtoaster-build/commits
######################################################################
# change my* variables appropriately. Nothing else should be changed.
mygithub=~/github
mygpgpass="use your gpg key pass"
myrepouser=shubes-stage
######################################################################
# find the grepo (git repo) name
#
a1_find_git_repo_name(){
if [ -z "$1" ]; then
if [ -z "ls *.spec 2>/dev/null" ]; then
echo "$me what? (no .spec file here)"
exit 1
else
grepo=${PWD##*/}
fi
else
specfile="$(find $mygithub/$1 -maxdepth 1 -name "*.spec" -print -quit)"
if [ -z "$specfile" ]; then
echo "$me - .spec file not found within $mygithub/$1"
exit 1
else
grepo=$1
fi
fi
}
######################################################################
# clone the git repo to a temporary directory,
#
a3_clone_git_to_temp(){
tempgit=$(tempfile 2>/dev/null) || tempgit=/tmp/$me.$$
# make sure the temp stuff is deleted when we're done
trap "rm -rf $tempgit" 0 1 2 5 15
mkdir $tempgit
# git 1.8.5 will have a -C option. 'til then, we need to cd to the target
savepwd=$PWD
cd $tempgit
git clone https://github.com/QMailToaster/$grepo
cd $savepwd
gspecdir=$tempgit/$grepo
if [ ! -d "$gspecdir/.git" ]; then
echo "$me - unable to clone git repo - terminating"
exit 1
fi
}
######################################################################
# build an src.rpm file from the .spec file
#
a5_create_src_rpm(){
pkg=${specfile##*/}
pkg=${pkg%.spec}
b52_use_existing_src_rpm
b54_get_external_sources
b56_trim_clamav
b58_build_signed_rpm
if [ -f "$srcrpm" ]; then
scp -p -P 17132 $srcrpm $myrepouser@$repohost:$repostage 2>/dev/null
else
echo "$me - $srcrpm not found, not copied to repo staging"
exit 1
fi
}
######################################################################
# use an existing src rpm file if one exists
#
b52_use_existing_src_rpm(){
read vertag version anythingleft <<!EOF!
$(grep --max-count=1 "^Version:" $specfile)
!EOF!
read reltag relstring anythingleft <<!EOF!
$(grep --max-count=1 "^Release:" $specfile)
!EOF!
release=$(echo $relstring | sed -e "s|%{?dist}|$repotag|")
# we only want to get the external sources from the existing srpm,
# not the spec or github sources
srcrpmname=$pkg-$version-$release.src.rpm
srcrpm=$(rpm --eval='%{_srcrpmdir}')/$srcrpmname
if [ -f "$srcrpm" ]; then
rpm -ivh $srcrpm
fi
}
######################################################################
# get sources from their internet locations
# we take them from the local sourcedir if they exist there
#
b54_get_external_sources(){
while read srctag srcval anythingleft; do
# this loop is done at least once even with no input
# it appears that read does not treat a single \n as EOF
if [ -z "$srcval" ]; then
break
fi
srcname=${srcval##*/}
if [ ! -f "$gspecdir/$srcname" ]; then
if [ -f "$sourcedir/$srcname" ]; then
cp -p $sourcedir/$srcname $gspecdir/$srcname
else
srcstring=${srctag%:}
srcnum=${srcstring#Source}
echo "$me getting source $srcnum"
spectool --get-files -C $gspecdir --source $srcnum $specfile
fi
fi
done <<!EOF!
$(spectool --list-files $specfile)
!EOF!
}
######################################################################
# remove 95M of win32 from clamav tarball
#
b56_trim_clamav(){
if [ "$pkg" == clamav ]; then
if [ -f "$gspecdir/clamav-$version.tar.gz" ]; then
tar -C $gspecdir -xzf $gspecdir/clamav-$version.tar.gz
rm -rf $gspecdir/clamav-$version/win32 \
$gspecdir/clamav-$version/test \
$gspecdir/clamav-$version/unit_tests
tar -C $gspecdir -czf $gspecdir/clamav-$version.tar.gz clamav-$version
else
echo "$me - $gspecdir/clamav-$version.tar.gz not found"
ls $gspecdir
exit 1
fi
fi
}
######################################################################
# build and invoke expect script to build and sign src.rpm with no prompt
#
b58_build_signed_rpm(){
expect -c "
set timeout -1
spawn rpmbuild -bs --define \"dist $repotag\" --define \"_sourcedir $gspecdir\" --sign $specfile
expect {
phrase: { send \"$mygpgpass\r\"; exp_continue }
}
"
}
######################################################################
# main routine begins here
#
me=${0##*/}
myver=v1.3
repotag=.qt
repohost=masterepo.qmailtoaster.com
repostage=/stage/testing/SRPMS/.
sourcedir=$(rpm --eval='%{_sourcedir}')
a1_find_git_repo_name $1
a3_clone_git_to_temp
for specfile in $(ls $gspecdir/*.spec); do
a5_create_src_rpm
done
exit 0