-
Notifications
You must be signed in to change notification settings - Fork 1
/
qt-build-rpms
executable file
·201 lines (163 loc) · 5.05 KB
/
qt-build-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
#!/bin/bash
# Copyright (C) 2013 Eric Shubert <[email protected]>
#
# Build QMailToaster binary rpm file
######################################################################
# Change Log
# 12/02/13 shubes - created
######################################################################
# change my* variables appropriately. Nothing else should be changed.
mygpgpass="use your gpg key pass"
myrepouser=shubes-stage
######################################################################
# set temp names for rpm indexes
#
a1_setup_temp_stuff(){
temparch=$(tempfile 2>/dev/null) || temparch=/tmp/$me.$$
# make sure the temp stuff is deleted when we're done
trap "rm -f $temparch" 0 1 2 5 15
}
######################################################################
# process each status
# get index of binary files in temparch, then process each src.rpm file
#
a5_each_status(){
echo "$me - checking $status ..."
statdistverarch=$status/$DISTRO/${OSVER%%.*}/$arch
repostage=/stage/$statdistverarch
wget -O $temparch $webmirror/$statdistverarch/ 2>/dev/null
while read grepstring; do
if [ ! -z "$grepstring" ]; then
b55_check_package
fi
done << !EOF!
$(wget -O - $webmirror/$status/SRPMS/ 2>/dev/null | grep \.src\.rpm\<)
!EOF!
}
######################################################################
# check to see if the package needs to be built
#
b55_check_package(){
grepstring=${grepstring%</a>*}
srcname=${grepstring#*src.rpm\">}
pkgverrel=${srcname%.src.rpm}
release=${pkgverrel##*-}
pkg=${pkgverrel%-$release}
version=${pkg##*-}
pkg=${pkg%-$version}
echo "$me - checking $pkgverrel ..."
# look for "BuildArch: noarch" tag in spec, and bypass if it's there
wget -O - --no-check-certificate https://raw.github.com/QMailToaster/$pkg/master/$pkg.spec 2>/dev/null | grep -m 1 ^BuildArch | grep -q noarch
if [ $? -eq 0 ]; then
return
fi
# we look for anything between package and version
# because libdomainkeys and libvpopmail only create -devel binary.
# we don't do this for other pkgs because of qmailadmin and qmailadmin-spambox,
# which are separate packages.
# This is a bit of a hack, and could be done more generically.
case "$pkg" in
libdomainkeys | libvpopmail )
grepfor="$pkg.*-$version-$release.*\.rpm"
;;
* )
grepfor="$pkg-$version-$release.*\.rpm"
;;
esac
if [ -z "$(grep $grepfor $temparch)" ]; then
c555_build_package
fi
}
######################################################################
# process each package
#
c555_build_package(){
echo "$me - processing $srcname"
srpmfile=$srcrpmdir/$srcname
rm -f $srpmfile
wget -O $srpmfile $webmirror/$status/SRPMS/$srcname
rpm --checksig $srpmfile
if [ "$?" != "0" ]; then
echo "$me -- $srcname in $status failed signature check"
exit 1
fi
# we need to rebuild the src.rpm first,
# to use the --nomd5 flag for backward (COS5) compatibility
# TODO: if we're not COS5, don't do this
rpm -ivh --nomd5 $srpmfile
rm -f $srpmfile
release=${pkgverrel##*-}
pkg=${pkgverrel%-$release}
version=${pkg##*-}
pkg=${pkg%-$version}
rpmbuild -bs --define "dist $repo" $specdir/$pkg.spec
# TODO: set up sudo so a password isn't required?
# or perhaps create a script run as root which downloads all the packages
# and then runs yum-builddep on each one. Probably a better idea.
# could *not* be done in %post of qmailtoaster-build package (recursive yum).
#sudo yum-builddep
d5554_build_signed_rpms
d5557_upload_resulting_rpms
if [ -f $logfile ]; then
chmod -x $logfile
scp -p -P 17132 $logfile $myrepouser@$repohost:$repostage/.
rm $logfile
fi
}
######################################################################
# invoke expect build and sign src.rpm with no prompt
#
d5554_build_signed_rpms(){
logfile=$logdir/$pkgverrel$dist.$arch.buildlog.txt
rm -f $logfile
expect -c "
set timeout -1
log_file $logfile
spawn rpmbuild --rebuild --define \"dist $repo$dist\" --sign $srpmfile
expect {
phrase: { send \"$mygpgpass\r\"; exp_continue }
}
"
}
######################################################################
# upload the binary rpm(s) to staging
#
d5557_upload_resulting_rpms(){
while read wrotestring; do
# for some reason this loop executes once when there's nothing read
if [ -z "$wrotestring" ]; then
echo "$me - build appears to have failed - exiting"
exit 1
fi
rpmfile=${wrotestring#Wrote: }
# there's a \r at the end of this string that we need to get rid of
rpmfile=${rpmfile%.rpm*}
rpmfile=${rpmfile}.rpm
if [ ! -z "$rpmfile" ]; then
scp -p -P 17132 $rpmfile $myrepouser@$repohost:$repostage/.
rm $rpmfile
fi
done << !EOF!
$(grep ^Wrote $logfile)
!EOF!
}
######################################################################
# main routine begins here
#
me=${0##*/}
myver=v1.0
webmirror=http://mirror1.qmailtoaster.com
repo=".qt"
repohost=masterepo.qmailtoaster.com
srcrpmdir="$(rpm --eval='%{_srcrpmdir}')"
specdir="$(rpm --eval='%{_specdir}')"
dist="$(rpm --eval='%{dist}')"
arch=$(rpm --eval='%{_arch}')
logdir="$(rpm --eval='%{_topdir}')/BUILDLOGS"
mkdir -p $logdir
. qmt-whatami -s
a1_setup_temp_stuff
for status in devel testing; do
a5_each_status
done
echo "$me - done"