summaryrefslogtreecommitdiff
path: root/rpm/build/build-freeside
blob: afef96ab6347c2d101fd81f4d26a7edb05384b1d (plain)
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
#!/bin/sh
#
# Copyright 2008, Elirion, Inc.  All rights reserved.
# This software is licensed under the same terms as Freeside itself.
#
# This script rebuilds SRPMs of Freeside builds or the required Perl modules on all the target
# distributions and versions using mock.  After a successful build, it signs the resulting RPMs
# and scp's them to the server where the yum repositories are hosted.
# (Of course, koji is supposed to do all this, including updating the repo.)

VERSIONS='1.7 1.9'
#VERSIONS='1.7 1.9 2.1'
REPO=testing
BRANCH=
DISTROS='centos sles'
CENTOSVERS='5'
SLESVERS=10
WHICHVERS=
ARCHS='i386 x86_64'

BUILDSYSDIR=`dirname $0`

MOCKWORK="$BUILDSYSDIR/mockwork"

#MOCKARGS='--autocache'
MOCKARGS="--configdir=$BUILDSYSDIR/mock  --resultdir=$MOCKWORK"

if [ -f $BUILDSYSDIR/buildsysrc ]; then
        #chmod a+x $BUILDSYSDIR/buildsysrc
	#echo $BUILDSYSDIR/buildsysrc
	. $BUILDSYSDIR/buildsysrc
fi
if [ -f $HOME/buildsysrc ]; then
        #chmod a+x $HOME/buildsysrc
	#echo $HOME/buildsysrc
	. $HOME/buildsysrc
fi

EXPECT_ADDSIGN=$BUILDSYSDIR/expect-addsign
if [ -f /usr/local/bin/expect-addsign ]; then
   EXPECT_ADDSIGN=/usr/local/bin/expect-addsign
fi

usage() {
	echo "build-freeside: build RPMs for all target distros and architectures using mock"
	echo "where:"
	echo " -a <archs>: change architectures (currently: $ARCHS)"
	echo " -b <branch>: change branch (currently: $BRANCH)"
	echo " -d <distros>: change distributions (currently: $DISTROS)"
	echo " -m <arguments>: change arguments passed to 'mock' (currently: $MOCKARGS)"
	echo " -r <repo>: change repositories (currently: $REPO)"
	echo " -s <srpms>: build these SRPMs instead of new ones in staging area"
	echo " -v <versions>: change versions (currently: $VERSIONS)"
	echo " -w <distvers>: change distro version (currently: $WHICHVERS)"
	exit 0
}

while getopts "a:b:d:hm:r:s:v:w:" flag
do
	case $flag in
		a)
			echo "Changing architectures from $ARCHS to $OPTARG"
			ARCHS=$OPTARG;;
		b)
			echo "Changing branch from $BRANCH to $OPTARG"
			BRANCH=$OPTARG;;
		d)
			echo "Changing distros from $DISTROS to $OPTARG"
			DISTROS=$OPTARG;;
		m)
			echo "Changing mock arguments from $MOCKARGS to $OPTARG"
			MOCKARGS=$OPTARG;;
		r)
			echo "Changing repository from $REPO to $OPTARG"
			REPO=$OPTARG;;
		s)
			echo "Changing SRPMS from $SRPMS to $OPTARG"
			SRPMS=$OPTARG;;
		v)
			echo "Changing versions from $VERSIONS to $OPTARG"
			VERSIONS=$OPTARG;;
		w)
			echo "Changing which distro versions from $WHICHVERS to $OPTARG"
			WHICHVERS=$OPTARG;;
		*)
			usage;;
	esac
done

if [ "${SRCFOLDER}x" = "x" ]; then
        PWD=`pwd`
	echo "No source folder defined! (BUILDSYSDIR=$BUILDSYSDIR pwd=$PWD)"
	exit
fi

if [ "${REFFOLDER}x" = "x" ]; then
	echo "No reference folder defined!"
	exit
fi

if [ "${SRPMS}x" = "x" ]; then
	# Work out the new SRPMs on grosbeak
	SRPMS=`/usr/bin/rsync -Cavz --dry-run $SRCFOLDER/ $REFFOLDER | grep .src.rpm | grep -v safecat | tr '\n' ' '`

	# Go and get the SRPMs
	/usr/bin/rsync -Cavz $SRCFOLDER/ $REFFOLDER
fi

# Make sure the SRPMs are there
for srpm in ${SRPMS}
do
	if [ ! -f $REFFOLDER/${srpm} ]
	then
		echo "No such file: $REFFOLDER/${srpm}"
		exit
	fi
done

# Build all the SRPMs
for srpm in ${SRPMS}
do
	for distro in $DISTROS
	do
		if [ "${WHICHVERS}x" = "x" ]; then
			if [ "$distro" = "centos" ]; then
				DISTVERS=$CENTOSVERS
			fi
			if [ "$distro" = "sles" ]; then
				DISTVERS=$SLESVERS
			fi
		else
			DISTVERS=$WHICHVERS
		fi
		for distver in $DISTVERS
		do
			os=${distro}-${distver}
			for arch in $ARCHS
			do
				echo "$os - $arch: $srpm"
				echo mock $MOCKARGS -r ${os}-${arch} $REFFOLDER/${srpm}
				time mock $MOCKARGS -r ${os}-${arch} $REFFOLDER/${srpm}
				if true #[ -f $MOCKWORK/${os}-${arch}/state/status ] && grep done $MOCKWORK/${os}-${arch}/state/status
				then
					for VERSION in $VERSIONS
					do
						DEST=$VERSION
						if [ "${BRANCH}x" != "x" ]
						then
							DEST=$BRANCH
						fi
						# Copy freeside RPMs for this version only
						#FILES=`ls -1 $MOCKWORK/${os}-${arch}/result/freeside*-${VERSION}-*.rpm | grep -v .src.rpm | tr '\n' ' '`
						FILES=`ls -1 $MOCKWORK/freeside*-${VERSION}-*.rpm | grep -v .src.rpm | tr '\n' ' '`
						echo $FILES
						if [ "${FILES}x" != "x" ]
						then
							for FILE in $FILES
							do
								$EXPECT_ADDSIGN $FILE
							done
							if [ "${REPOMACHINE}x" != "x" ]
							then
								scp -p $FILES $REPOUSER@$REPOMACHINE:$REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
							else
								cp -p $FILES $REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
							fi
						fi
						# Copy non-freeside RPMs to all versions
						#FILES=`ls -1 $MOCKWORK/${os}-${arch}/result/*.rpm | grep -v freeside | grep -v .src.rpm | tr '\n' ' '`
						FILES=`ls -1 $MOCKWORK/*.rpm | grep -v freeside | grep -v .src.rpm | tr '\n' ' '`
						echo $FILES
						if [ "${FILES}x" != "x" ]
						then
							for FILE in $FILES
							do
								$EXPECT_ADDSIGN $FILE
							done
							if [ "${REPOMACHINE}x" != "x" ]
							then
								scp -p $FILES $REPOUSER@$REPOMACHINE:$REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
							else
								cp -p $FILES $REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
							fi
						fi
					done
				fi
			done
		done
	done
done

echo "build-freeside done"