f4c6ca78fb86e0ad8a0010ccbf32411ead79d654
[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 #MOCKARGS='--autocache'
24 MOCKARGS="--configdir=$BUILDSYSDIR/mock"
25
26
27 if [ -f $BUILDSYSDIR/buildsysrc ]; then
28         #chmod a+x $BUILDSYSDIR/buildsysrc
29         #echo $BUILDSYSDIR/buildsysrc
30         . $BUILDSYSDIR/buildsysrc
31 fi
32
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 [ -f /var/lib/mock/${os}-${arch}/state/status ] && grep done /var/lib/mock/${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 /var/lib/mock/${os}-${arch}/result/freeside*-${VERSION}-*.rpm | grep -v .src.rpm | tr '\n' ' '`
153                                                 echo $FILES
154                                                 if [ "${FILES}x" != "x" ]
155                                                 then
156                                                         for FILE in $FILES
157                                                         do
158                                                                 $EXPECT_ADDSIGN $FILE
159                                                         done
160                                                         if [ "${REPOMACHINE}x" != "x" ]
161                                                         then
162                                                                 scp -p $FILES $REPOUSER@$REPOMACHINE:$REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
163                                                         else
164                                                                 cp -p $FILES $REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
165                                                         fi
166                                                 fi
167                                                 # Copy non-freeside RPMs to all versions
168                                                 FILES=`ls -1 /var/lib/mock/${os}-${arch}/result/*.rpm | grep -v freeside | grep -v .src.rpm | tr '\n' ' '`
169                                                 echo $FILES
170                                                 if [ "${FILES}x" != "x" ]
171                                                 then
172                                                         for FILE in $FILES
173                                                         do
174                                                                 $EXPECT_ADDSIGN $FILE
175                                                         done
176                                                         if [ "${REPOMACHINE}x" != "x" ]
177                                                         then
178                                                                 scp -p $FILES $REPOUSER@$REPOMACHINE:$REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
179                                                         else
180                                                                 cp -p $FILES $REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
181                                                         fi
182                                                 fi
183                                         done
184                                 fi
185                         done
186                 done
187         done
188 done