enable CardFortress in test database, #71513
[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 $BUILDSYSDIR/buildsysrc ]; then
31         #chmod a+x $BUILDSYSDIR/buildsysrc
32         #echo $BUILDSYSDIR/buildsysrc
33         . $BUILDSYSDIR/buildsysrc
34 fi
35 if [ -f $HOME/buildsysrc ]; then
36         #chmod a+x $HOME/buildsysrc
37         #echo $HOME/buildsysrc
38         . $HOME/buildsysrc
39 fi
40
41
42 usage() {
43         echo "refresh-repo: refresh yum metadata for all yum repositories"
44         echo "where:"
45         echo " -a <archs>: change architectures (currently: $ARCHS)"
46         echo " -d <distros>: change distributions (currently: $DISTROS)"
47         echo " -r <repos>: change repositories (currently: $REPOS)"
48         echo " -v <versions>: change versions (currently: $VERSIONS)"
49         echo " -w <distvers>: change distro version (currently: $WHICHVERS)"
50         exit 0
51 }
52
53 while getopts "a:d:hqr:v:w:" flag
54 do
55         case $flag in
56                 a)
57                         echo "Changing architectures from $ARCHS to $OPTARG"
58                         ARCHS=$OPTARG;;
59                 d)
60                         echo "Changing distros from $DISTROS to $OPTARG"
61                         DISTROS=$OPTARG;;
62                 q)
63                         echo "Quiet mode"
64                         QUIET_FLAG=-q;;
65                 r)
66                         echo "Changing repository from $REPOS to $OPTARG"
67                         REPOS=$OPTARG;;
68                 v)
69                         echo "Changing versions from $VERSIONS to $OPTARG"
70                         VERSIONS=$OPTARG;;
71                 w)
72                         echo "Changing which distro versions from $WHICHVERS to $OPTARG"
73                         WHICHVERS=$OPTARG;;
74                 *)
75                         usage;;
76         esac
77 done
78
79 #for DISTRO in ${DISTROS}; do
80 #       for VERSION in ${VERSIONS}; do
81 #               for REPO in ${REPOS}; do
82 #                       for ARCH in ${ARCHS}; do
83 #                               # Determine which RPMs need to be signed
84 #                               NEWRPMS=`rpm --checksig $REPOBASEFOLDER/repo/$DISTROS/$DISTVERS/freeside-${VERSION}/${REPO}/${ARCH}/*.rpm | grep -v ' gpg ' | cut -d ':' -f 1 | tr '\n' ' '`
85 #                               RPMS=`echo "$RPMS $NEWRPMS"`
86 #                       done
87 #               done
88 #       done
89 #done
90 ##rpm --addsign $RPMS
91 #for RPM in $RPMS; do
92 #       ./expect-addsign $RPM
93 #done
94 for DISTRO in ${DISTROS}; do
95         for VERSION in ${VERSIONS}; do
96                 for REPO in ${REPOS}; do
97                         for ARCH in ${ARCHS}; do
98                                 if [ "${WHICHVERS}x" = "x" ]; then
99                                         if [ "$DISTRO" = "centos" ]; then
100                                                 DISTVERS=$CENTOSVERS
101                                         fi
102                                         if [ "$DISTRO" = "sles" ]; then
103                                                 DISTVERS=$SLESVERS
104                                         fi
105                                 else
106                                         DISTVERS=$WHICHVERS
107                                 fi
108                                 for distver in $DISTVERS
109                                 do
110                                         # Update the repo information
111                                         echo "${DISTRO}-${distver}: $VERSION - $REPO - $ARCH"
112                                         DIR=$REPOBASEFOLDER/repo/$DISTRO/$distver/freeside-${VERSION}/${REPO}/${ARCH}
113                                         if [ -d $DIR ]
114                                         then
115                                                 # SLES requires signed repodata.  Save any existing files so we don't regenerate
116                                                 for ext in asc key
117                                                 do
118                                                         if [ -e $DIR/repodata/repomd.xml.${ext} ]
119                                                         then
120                                                                 mv $DIR/repodata/repomd.xml.${ext} $SAVEDIR
121                                                         fi
122                                                 done
123                                                 if [ "$DISTRO" = "sles" ]
124                                                 then
125                                                         for file in $DIR/freeside-mysql-*.rpm
126                                                         do
127                                                                 mv $file $file.old
128                                                         done
129                                                         for file in $DIR/freeside-selfservice-*.rpm
130                                                         do
131                                                                 mv $file $DIR/../self-service/$ARCH
132                                                         done
133                                                 fi
134                                                 if [ "$DISTRO-$distver" = "centos-4" ]
135                                                 then
136                                                         yum-arch $QUIET_FLAG $DIR/
137                                                 fi
138 #                                               createrepo $QUIET_FLAG --checkts $DIR/
139                                                 createrepo $QUIET_FLAG $DIR/
140                                                 if [ "$DISTRO" = "sles" ]
141                                                 then
142                                                         # SLES requires signed repodata...
143                                                         if [ -e $SAVEDIR/repomd.xml.asc ]
144                                                         then
145                                                                 mv $SAVEDIR/repomd.xml.asc $DIR/repodata
146                                                         fi
147
148 #                                                       gpg -sab --yes -u "$KEYID" -o $DIR/repodata/repomd.xml.asc $DIR/repodata/repomd.xml
149                                                         ./expect-signrepo $KEYID $DIR/repodata/repomd.xml.asc $DIR/repodata/repomd.xml
150                                                         if [ -e $SAVEDIR/repomd.xml.key ]
151                                                         then
152                                                                 mv $SAVEDIR/repomd.xml.key $DIR/repodata
153                                                         else
154                                                                 gpg -a --yes -u "$KEYID" --export -o $DIR/repodata/repomd.xml.key
155                                                         fi
156                                                 fi
157                                         else
158                                                 echo "No such folder $DIR - skipping"
159                                         fi
160                                 done
161                         done
162                 done
163         done
164 done