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