checking in RPM build system
[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 REPO=testing
13 BRANCH=
14 DISTROS='centos sles'
15 CENTOSVERS='4 5'
16 SLESVERS=10
17 WHICHVERS=
18 ARCHS='i386 x86_64'
19 MOCKARGS='--autocache'
20
21 BUILDSYSDIR=`dirname $0`
22
23 if [ -f $HOME/buildsysrc ]; then
24         . $HOME/buildsysrc
25 fi
26
27 usage() {
28         echo "build-freeside: build RPMs for all target distros and architectures using mock"
29         echo "where:"
30         echo " -a <archs>: change architectures (currently: $ARCHS)"
31         echo " -b <branch>: change branch (currently: $BRANCH)"
32         echo " -d <distros>: change distributions (currently: $DISTROS)"
33         echo " -m <arguments>: change arguments passed to 'mock' (currently: $MOCKARGS)"
34         echo " -r <repo>: change repositories (currently: $REPO)"
35         echo " -s <srpms>: build these SRPMs instead of new ones in staging area"
36         echo " -v <versions>: change versions (currently: $VERSIONS)"
37         echo " -w <distvers>: change distro version (currently: $WHICHVERS)"
38         exit 0
39 }
40
41 while getopts "a:b:d:hm:r:s:v:w:" flag
42 do
43         case $flag in
44                 a)
45                         echo "Changing architectures from $ARCHS to $OPTARG"
46                         ARCHS=$OPTARG;;
47                 b)
48                         echo "Changing branch from $BRANCH to $OPTARG"
49                         BRANCH=$OPTARG;;
50                 d)
51                         echo "Changing distros from $DISTROS to $OPTARG"
52                         DISTROS=$OPTARG;;
53                 m)
54                         echo "Changing mock arguments from $MOCKARGS to $OPTARG"
55                         MOCKARGS=$OPTARG;;
56                 r)
57                         echo "Changing repository from $REPO to $OPTARG"
58                         REPO=$OPTARG;;
59                 s)
60                         echo "Changing SRPMS from $SRPMS to $OPTARG"
61                         SRPMS=$OPTARG;;
62                 v)
63                         echo "Changing versions from $VERSIONS to $OPTARG"
64                         VERSIONS=$OPTARG;;
65                 w)
66                         echo "Changing which distro versions from $WHICHVERS to $OPTARG"
67                         WHICHVERS=$OPTARG;;
68                 *)
69                         usage;;
70         esac
71 done
72
73 if [ "${SRCFOLDER}x" = "x" ]; then
74         echo "No source folder defined!"
75         exit
76 fi
77
78 if [ "${REFFOLDER}x" = "x" ]; then
79         echo "No reference folder defined!"
80         exit
81 fi
82
83 if [ "${SRPMS}x" = "x" ]; then
84         # Work out the new SRPMs on grosbeak
85         SRPMS=`/usr/bin/rsync -Cavz --dry-run $SRCFOLDER/ $REFFOLDER | grep .src.rpm | grep -v safecat | tr '\n' ' '`
86
87         # Go and get the SRPMs
88         /usr/bin/rsync -Cavz $SRCFOLDER/ $REFFOLDER
89 fi
90
91 # Make sure the SRPMs are there
92 for srpm in ${SRPMS}
93 do
94         if [ ! -f $REFFOLDER/${srpm} ]
95         then
96                 echo "No such file: $REFFOLDER/${srpm}"
97                 exit
98         fi
99 done
100
101 # Build all the SRPMs
102 for srpm in ${SRPMS}
103 do
104         for distro in $DISTROS
105         do
106                 if [ "${WHICHVERS}x" = "x" ]; then
107                         if [ "$distro" = "centos" ]; then
108                                 DISTVERS=$CENTOSVERS
109                         fi
110                         if [ "$distro" = "sles" ]; then
111                                 DISTVERS=$SLESVERS
112                         fi
113                 else
114                         DISTVERS=$WHICHVERS
115                 fi
116                 for distver in $DISTVERS
117                 do
118                         os=${distro}-${distver}
119                         for arch in $ARCHS
120                         do
121                                 echo "$os - $arch: $srpm"
122                                 time mock $MOCKARGS -r ${os}-${arch} $REFFOLDER/${srpm}
123                                 if [ -f /var/lib/mock/${os}-${arch}/state/status ] && grep done /var/lib/mock/${os}-${arch}/state/status
124                                 then
125                                         for VERSION in $VERSIONS
126                                         do
127                                                 DEST=$VERSION
128                                                 if [ "${BRANCH}x" != "x" ]
129                                                 then
130                                                         DEST=$BRANCH
131                                                 fi
132                                                 # Copy freeside RPMs for this version only
133                                                 FILES=`ls -1 /var/lib/mock/${os}-${arch}/result/freeside*-${VERSION}-*.rpm | grep -v .src.rpm | tr '\n' ' '`
134                                                 echo $FILES
135                                                 if [ "${FILES}x" != "x" ]
136                                                 then
137                                                         for FILE in $FILES
138                                                         do
139                                                                 $BUILDSYSDIR/expect-addsign $FILE
140                                                         done
141                                                         if [ "${REPOMACHINE}x" != "x" ]
142                                                         then
143                                                                 scp -p $FILES $REPOUSER@$REPOMACHINE:$REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
144                                                         else
145                                                                 cp -p $FILES $REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
146                                                         fi
147                                                 fi
148                                                 # Copy non-freeside RPMs to all versions
149                                                 FILES=`ls -1 /var/lib/mock/${os}-${arch}/result/*.rpm | grep -v freeside | grep -v .src.rpm | tr '\n' ' '`
150                                                 echo $FILES
151                                                 if [ "${FILES}x" != "x" ]
152                                                 then
153                                                         for FILE in $FILES
154                                                         do
155                                                                 $BUILDSYSDIR/expect-addsign $FILE
156                                                         done
157                                                         if [ "${REPOMACHINE}x" != "x" ]
158                                                         then
159                                                                 scp -p $FILES $REPOUSER@$REPOMACHINE:$REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
160                                                         else
161                                                                 cp -p $FILES $REPOFOLDER/repo/${distro}/${distver}/freeside-${DEST}/${REPO}/${arch}
162                                                         fi
163                                                 fi
164                                         done
165                                 fi
166                         done
167                 done
168         done
169 done