contact search, RT#25687 (also possibly #25583 and #22991)
[freeside.git] / rpm / build / build-freeside
1 #!/bin/sh
2 #
3 # Copyright 2008, Elirion, Inc.  All rights reserved.
4 # This software is licensed under the same terms as Freeside itself.
5 #
6 # This script rebuilds SRPMs of Freeside builds or the required Perl modules on all the target
7 # distributions and versions using mock.  After a successful build, it signs the resulting RPMs
8 # and scp's them to the server where the yum repositories are hosted.
9 # (Of course, koji is supposed to do all this, including updating the repo.)
10
11 VERSIONS='1.7 1.9'
12 #VERSIONS='1.7 1.9 2.1'
13 REPO=testing
14 BRANCH=
15 DISTROS='centos sles'
16 CENTOSVERS='5'
17 SLESVERS=10
18 WHICHVERS=
19 ARCHS='i386 x86_64'
20
21 BUILDSYSDIR=`dirname $0`
22
23 MOCKWORK="$BUILDSYSDIR/mockwork"
24
25 #MOCKARGS='--autocache'
26 MOCKARGS="--configdir=$BUILDSYSDIR/mock  --resultdir=$MOCKWORK"
27
28 if [ -f $BUILDSYSDIR/buildsysrc ]; then
29         #chmod a+x $BUILDSYSDIR/buildsysrc
30         #echo $BUILDSYSDIR/buildsysrc
31         . $BUILDSYSDIR/buildsysrc
32 fi
33 if [ -f $HOME/buildsysrc ]; then
34         #chmod a+x $HOME/buildsysrc
35         #echo $HOME/buildsysrc
36         . $HOME/buildsysrc
37 fi
38
39 EXPECT_ADDSIGN=$BUILDSYSDIR/expect-addsign
40 if [ -f /usr/local/bin/expect-addsign ]; then
41    EXPECT_ADDSIGN=/usr/local/bin/expect-addsign
42 fi
43
44 usage() {
45         echo "build-freeside: build RPMs for all target distros and architectures using mock"
46         echo "where:"
47         echo " -a <archs>: change architectures (currently: $ARCHS)"
48         echo " -b <branch>: change branch (currently: $BRANCH)"
49         echo " -d <distros>: change distributions (currently: $DISTROS)"
50         echo " -m <arguments>: change arguments passed to 'mock' (currently: $MOCKARGS)"
51         echo " -r <repo>: change repositories (currently: $REPO)"
52         echo " -s <srpms>: build these SRPMs instead of new ones in staging area"
53         echo " -v <versions>: change versions (currently: $VERSIONS)"
54         echo " -w <distvers>: change distro version (currently: $WHICHVERS)"
55         exit 0
56 }
57
58 while getopts "a:b:d:hm:r:s:v:w:" flag
59 do
60         case $flag in
61                 a)
62                         echo "Changing architectures from $ARCHS to $OPTARG"
63                         ARCHS=$OPTARG;;
64                 b)
65                         echo "Changing branch from $BRANCH to $OPTARG"
66                         BRANCH=$OPTARG;;
67                 d)
68                         echo "Changing distros from $DISTROS to $OPTARG"
69                         DISTROS=$OPTARG;;
70                 m)
71                         echo "Changing mock arguments from $MOCKARGS to $OPTARG"
72                         MOCKARGS=$OPTARG;;
73                 r)
74                         echo "Changing repository from $REPO to $OPTARG"
75                         REPO=$OPTARG;;
76                 s)
77                         echo "Changing SRPMS from $SRPMS to $OPTARG"
78                         SRPMS=$OPTARG;;
79                 v)
80                         echo "Changing versions from $VERSIONS to $OPTARG"
81                         VERSIONS=$OPTARG;;
82                 w)
83                         echo "Changing which distro versions from $WHICHVERS to $OPTARG"
84                         WHICHVERS=$OPTARG;;
85                 *)
86                         usage;;
87         esac
88 done
89
90 if [ "${SRCFOLDER}x" = "x" ]; then
91         PWD=`pwd`
92         echo "No source folder defined! (BUILDSYSDIR=$BUILDSYSDIR pwd=$PWD)"
93         exit
94 fi
95
96 if [ "${REFFOLDER}x" = "x" ]; then
97         echo "No reference folder defined!"
98         exit
99 fi
100
101 if [ "${SRPMS}x" = "x" ]; then
102         # Work out the new SRPMs on grosbeak
103         SRPMS=`/usr/bin/rsync -Cavz --dry-run $SRCFOLDER/ $REFFOLDER | grep .src.rpm | grep -v safecat | tr '\n' ' '`
104
105         # Go and get the SRPMs
106         /usr/bin/rsync -Cavz $SRCFOLDER/ $REFFOLDER
107 fi
108
109 # Make sure the SRPMs are there
110 for srpm in ${SRPMS}
111 do
112         if [ ! -f $REFFOLDER/${srpm} ]
113         then
114                 echo "No such file: $REFFOLDER/${srpm}"
115                 exit
116         fi
117 done
118
119 # Build all the SRPMs
120 for srpm in ${SRPMS}
121 do
122         for distro in $DISTROS
123         do
124                 if [ "${WHICHVERS}x" = "x" ]; then
125                         if [ "$distro" = "centos" ]; then
126                                 DISTVERS=$CENTOSVERS
127                         fi
128                         if [ "$distro" = "sles" ]; then
129                                 DISTVERS=$SLESVERS
130                         fi
131                 else
132                         DISTVERS=$WHICHVERS
133                 fi
134                 for distver in $DISTVERS
135                 do
136                         os=${distro}-${distver}
137                         for arch in $ARCHS
138                         do
139                                 echo "$os - $arch: $srpm"
140                                 echo mock $MOCKARGS -r ${os}-${arch} $REFFOLDER/${srpm}
141                                 time mock $MOCKARGS -r ${os}-${arch} $REFFOLDER/${srpm}
142                                 if true #[ -f $MOCKWORK/${os}-${arch}/state/status ] && grep done $MOCKWORK/${os}-${arch}/state/status
143                                 then
144                                         for VERSION in $VERSIONS
145                                         do
146                                                 DEST=$VERSION
147                                                 if [ "${BRANCH}x" != "x" ]
148                                                 then
149                                                         DEST=$BRANCH
150                                                 fi
151                                                 # Copy freeside RPMs for this version only
152                                                 #FILES=`ls -1 $MOCKWORK/${os}-${arch}/result/freeside*-${VERSION}-*.rpm | grep -v .src.rpm | tr '\n' ' '`
153                                                 FILES=`ls -1 $MOCKWORK/freeside*-${VERSION}-*.rpm | grep -v .src.rpm | tr '\n' ' '`
154                                                 echo $FILES
155                                                 if [ "${FILES}x" != "x" ]
156                                                 then
157                                                         for FILE in $FILES
158                                                         do
159                                                                 $EXPECT_ADDSIGN $FILE
160                                                         done
161                                                         if [ "${REPOMACHINE}x" != "x" ]
162                                                         then
163                                                                 scp -p $FILES $REPOUSER@$REPOMACHINE:$REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
164                                                         else
165                                                                 cp -p $FILES $REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
166                                                         fi
167                                                 fi
168                                                 # Copy non-freeside RPMs to all versions
169                                                 #FILES=`ls -1 $MOCKWORK/${os}-${arch}/result/*.rpm | grep -v freeside | grep -v .src.rpm | tr '\n' ' '`
170                                                 FILES=`ls -1 $MOCKWORK/*.rpm | grep -v freeside | grep -v .src.rpm | tr '\n' ' '`
171                                                 echo $FILES
172                                                 if [ "${FILES}x" != "x" ]
173                                                 then
174                                                         for FILE in $FILES
175                                                         do
176                                                                 $EXPECT_ADDSIGN $FILE
177                                                         done
178                                                         if [ "${REPOMACHINE}x" != "x" ]
179                                                         then
180                                                                 scp -p $FILES $REPOUSER@$REPOMACHINE:$REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
181                                                         else
182                                                                 cp -p $FILES $REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
183                                                         fi
184                                                 fi
185                                         done
186                                 fi
187                         done
188                 done
189         done
190 done
191
192 echo "build-freeside done"