40f62cdebad462c8b6315972b66dca4a31de79b3
[freeside.git] / rpm / build / refresh-repo
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 iterates through all the specified Freeside repositories, running
7 # both yum-arch and createrepo to update the yum repository meta-data.
8 # The script should be run after the repository contents are changed.
9 #
10 # TBD: Run yum-arch, createrepo, or both, as appropriate for the distro and version
11 # the repository is targetted for.
12 #
13 DISTROS='centos sles'
14 CENTOSVERS='4 5'
15 SLESVERS=10
16 WHICHVERS=
17 VERSIONS='1.7 1.9'
18 ARCHS='i386 x86_64'
19 REPOS='testing stable prerelease'
20 RPMS=
21 KEYID=rsiddall
22 SAVEDIR=$HOME
23
24 REPOBASEFOLDER=/var/www/html
25
26 QUIET_FLAG=
27
28 BUILDSYSDIR=`dirname $0`
29
30 if [ -f $HOME/buildsysrc ]; then
31         . $HOME/buildsysrc
32 fi
33
34 usage() {
35         echo "refresh-repo: refresh yum metadata for all yum repositories"
36         echo "where:"
37         echo " -a <archs>: change architectures (currently: $ARCHS)"
38         echo " -d <distros>: change distributions (currently: $DISTROS)"
39         echo " -r <repos>: change repositories (currently: $REPOS)"
40         echo " -v <versions>: change versions (currently: $VERSIONS)"
41         echo " -w <distvers>: change distro version (currently: $WHICHVERS)"
42         exit 0
43 }
44
45 while getopts "a:d:hqr:v:w:" flag
46 do
47         case $flag in
48                 a)
49                         echo "Changing architectures from $ARCHS to $OPTARG"
50                         ARCHS=$OPTARG;;
51                 d)
52                         echo "Changing distros from $DISTROS to $OPTARG"
53                         DISTROS=$OPTARG;;
54                 q)
55                         echo "Quiet mode"
56                         QUIET_FLAG=-q;;
57                 r)
58                         echo "Changing repository from $REPOS to $OPTARG"
59                         REPOS=$OPTARG;;
60                 v)
61                         echo "Changing versions from $VERSIONS to $OPTARG"
62                         VERSIONS=$OPTARG;;
63                 w)
64                         echo "Changing which distro versions from $WHICHVERS to $OPTARG"
65                         WHICHVERS=$OPTARG;;
66                 *)
67                         usage;;
68         esac
69 done
70
71 #for DISTRO in ${DISTROS}; do
72 #       for VERSION in ${VERSIONS}; do
73 #               for REPO in ${REPOS}; do
74 #                       for ARCH in ${ARCHS}; do
75 #                               # Determine which RPMs need to be signed
76 #                               NEWRPMS=`rpm --checksig $REPOBASEFOLDER/repo/$DISTROS/$DISTVERS/freeside-${VERSION}/${REPO}/${ARCH}/*.rpm | grep -v ' gpg ' | cut -d ':' -f 1 | tr '\n' ' '`
77 #                               RPMS=`echo "$RPMS $NEWRPMS"`
78 #                       done
79 #               done
80 #       done
81 #done
82 ##rpm --addsign $RPMS
83 #for RPM in $RPMS; do
84 #       ./expect-addsign $RPM
85 #done
86 for DISTRO in ${DISTROS}; do
87         for VERSION in ${VERSIONS}; do
88                 for REPO in ${REPOS}; do
89                         for ARCH in ${ARCHS}; do
90                                 if [ "${WHICHVERS}x" = "x" ]; then
91                                         if [ "$DISTRO" = "centos" ]; then
92                                                 DISTVERS=$CENTOSVERS
93                                         fi
94                                         if [ "$DISTRO" = "sles" ]; then
95                                                 DISTVERS=$SLESVERS
96                                         fi
97                                 else
98                                         DISTVERS=$WHICHVERS
99                                 fi
100                                 for distver in $DISTVERS
101                                 do
102                                         # Update the repo information
103                                         echo "${DISTRO}-${distver}: $VERSION - $REPO - $ARCH"
104                                         DIR=$REPOBASEFOLDER/repo/$DISTRO/$distver/freeside-${VERSION}/${REPO}/${ARCH}
105                                         if [ -d $DIR ]
106                                         then
107                                                 # SLES requires signed repodata.  Save any existing files so we don't regenerate
108                                                 for ext in asc key
109                                                 do
110                                                         if [ -e $DIR/repodata/repomd.xml.${ext} ]
111                                                         then
112                                                                 mv $DIR/repodata/repomd.xml.${ext} $SAVEDIR
113                                                         fi
114                                                 done
115                                                 if [ "$DISTRO" = "sles" ]
116                                                 then
117                                                         for file in $DIR/freeside-mysql-*.rpm
118                                                         do
119                                                                 mv $file $file.old
120                                                         done
121                                                         for file in $DIR/freeside-selfservice-*.rpm
122                                                         do
123                                                                 mv $file $DIR/../self-service/$ARCH
124                                                         done
125                                                 fi
126                                                 if [ "$DISTRO-$distver" = "centos-4" ]
127                                                 then
128                                                         yum-arch $QUIET_FLAG $DIR/
129                                                 fi
130 #                                               createrepo $QUIET_FLAG --checkts $DIR/
131                                                 createrepo $QUIET_FLAG $DIR/
132                                                 if [ "$DISTRO" = "sles" ]
133                                                 then
134                                                         # SLES requires signed repodata...
135                                                         if [ -e $SAVEDIR/repomd.xml.asc ]
136                                                         then
137                                                                 mv $SAVEDIR/repomd.xml.asc $DIR/repodata
138                                                         fi
139
140 #                                                       gpg -sab --yes -u "$KEYID" -o $DIR/repodata/repomd.xml.asc $DIR/repodata/repomd.xml
141                                                         ./expect-signrepo $KEYID $DIR/repodata/repomd.xml.asc $DIR/repodata/repomd.xml
142                                                         if [ -e $SAVEDIR/repomd.xml.key ]
143                                                         then
144                                                                 mv $SAVEDIR/repomd.xml.key $DIR/repodata
145                                                         else
146                                                                 gpg -a --yes -u "$KEYID" --export -o $DIR/repodata/repomd.xml.key
147                                                         fi
148                                                 fi
149                                         else
150                                                 echo "No such folder $DIR - skipping"
151                                         fi
152                                 done
153                         done
154                 done
155         done
156 done