need to mirror additional newkey repos for f8 and f9
[build.git] / vbuild-fedora-mirror.sh
1 #!/bin/bash
2 # this can help you create/update your fedora mirror
3 # $Id$
4
5 COMMAND=$(basename $0)
6
7 dry_run=
8 verbose=
9 skip_core=
10 root=/mirror/
11
12 us_fedora_url=rsync://mirrors.kernel.org/fedora
13 # change this
14 us_centos_url=rsync://mirrors.rit.edu/centos
15
16 eu_fedora_url=rsync://ftp-stud.hs-esslingen.de/fedora/linux
17 eu_centos_url=rsync://mirrors.ircam.fr/CentOS
18
19 # change this
20 jp_fedora_url="need-to-be-defined"
21 # change this
22 jp_centos_url="need-to-be-defined"
23
24 default_distroname=f8
25 all_distronames="f7 f8 f9 centos5.2"
26 default_arch=i386
27 all_archs="i386 x86_64"
28
29 case $(hostname) in 
30     *.fr|*.de|*.uk)
31         fedora_url=$eu_fedora_url ; centos_url=$eu_centos_url ;;
32     *.jp)
33         fedora_url=$jp_fedora_url ; centos_url=$jp_centos_url ;;
34     *)
35         fedora_url=$us_fedora_url ; centos_url=$us_centos_url ;;
36 esac
37
38 function mirror_distro_arch () {
39     distroname=$1; shift
40     arch=$1; shift
41
42     distroname=$(echo $distroname | tr '[A-Z]' '[a-z]')
43     case $distroname in
44         fc*[1-6])
45             distroindex=$(echo $distroname | sed -e "s,fc,,g")
46             distro="Fedora Core"
47             rsyncurl=$fedora_url
48             ;;
49         f*[7-9])
50             distroindex=$(echo $distroname | sed -e "s,f,,g")
51             distro="Fedora"
52             rsyncurl=$fedora_url
53             ;;
54         centos[4-5]|centos[4-5].[0-9])
55             distroindex=$(echo $distroname | sed -e "s,centos,,g")
56             distro="CentOS"
57             rsyncurl=$centos_url
58             ;;
59         *)
60             echo "WARNING -- Unknown distribution $distroname -- skipped"
61             return 1
62             ;;
63     esac
64
65     excludelist="debug/ iso/ ppc/ source/"
66     options="--archive --compress --delete --delete-excluded $dry_run $verbose"
67     [ -n "$(rsync --help | grep no-motd)" ] && options="$options --no-motd"
68     for e in $excludelist; do
69         options="$options --exclude $e"
70     done
71
72     if [ -n "$verbose" ] ; then 
73         echo "root=$root"
74         echo "distro=$distroname"
75         echo "distroname=$distroname"
76         echo "distroindex=$distroindex"
77         echo "arch=$arch"
78         echo rsyncurl="$rsyncurl"
79         echo "rsync options=$options"
80     fi
81
82     RES=1
83     paths=""
84     case $distro in
85         [Ff]edora*)
86             case $distroindex in
87                 2|4|6)
88                     [ -z "$skip_core" ] && paths="core/$distroindex/$arch/os/"
89                     paths="$paths core/updates/$distroindex/$arch/ extras/$distroindex/$arch/"
90                     RES=0
91                     ;;
92                 7|8|9)
93                     [ -z "$skip_core" ] && paths="releases/$distroindex/Everything/$arch/os/"
94                     paths="$paths updates/$distroindex/$arch/"
95                     # f8 and f9 have the additional newkey repo
96                     case $distroindex in 
97                         8|9) paths="$paths updates/$distroindex/${arch}.newkey/" ;;
98                     esac
99                     RES=0
100                     ;;
101             esac
102             localpath=fedora
103             ;;
104     
105         CentOS*)
106             case $distroindex in
107                 5*)
108                     [ -z "$skip_core" ] && paths="$distroindex/os/$arch/"
109                     paths="$paths $distroindex/updates/$arch/"
110                     RES=0
111                     ;;
112             esac
113             localpath=centos
114             ;;
115
116     esac
117
118     if [ "$RES" = 1 ] ; then
119         echo "DISTRIBUTION $distro $distroindex CURRENTLY UNSUPPORTED - skipped"
120     else
121         for repopath in $paths; do
122             echo "============================== $distro -> $distroindex $repopath"
123             [ -z "$dry_run" ] && mkdir -p ${root}/${localpath}/${repopath}
124             command="rsync $options ${rsyncurl}/${repopath} ${root}/${localpath}/${repopath}"
125             echo $command
126             $command
127         done
128     fi
129
130     return $RES 
131 }
132
133 function usage () {
134     echo "Usage: $COMMAND [-n] [-v] [-c] [-r root] [-u|U rsyncurl] [-e|-j] [-f distroname|-F] [-a arch|-A]"
135     echo "Defaults to -r $root -f $default_distroname -a $default_arch"
136     echo "Default urls : $fedora_url $centos_url"
137     echo "Options:"
138     echo " -n : dry run"
139     echo " -v : verbose"
140     echo " -c : skips core repository"
141     echo " -r root (default is $root)"
142     echo " -u rsyncurl for fedora (default is $fedora_url)"
143     echo " -U rsyncurl for centos (default is $centos_url)"
144     echo " -e : uses European mirrors $eu_fedora_url $eu_centos_url"
145     echo " -j : uses Japanese mirrors $jp_fedora_url $jp_centos_url"
146     echo " -f distroname - use vserver convention, e.g. fc6 and f7"
147     echo " -F : for distroname in $all_distronames"
148     echo " -a arch - use yum convention"
149     echo " -A : for arch in $all_archs"
150     exit 1
151 }
152
153 function main () {
154     distronames=""
155     archs=""
156     while getopts "nvcr:u:U:ef:Fa:Ah" opt ; do
157         case $opt in
158             n) dry_run=--dry-run ; verbose=--verbose ;;
159             v) verbose=--verbose ;;
160             c) skip_core=true ;;
161             r) root=$OPTARG ;;
162             u) fedora_url=$OPTARG ;;
163             U) centos_url=$OPTARG ;;
164             e) fedora_url=$eu_fedora_url ; centos_url=$eu_centos_url ;;
165             j) fedora_url=$jp_fedora_url ; centos_url=$jp_centos_url ;;
166             f) distronames="$distronames $OPTARG" ;;
167             F) distronames="$distronames $all_distronames" ;;
168             a) archs="$archs $OPTARG" ;;
169             A) archs="$archs $all_archs" ;;
170             h|*) usage ;;
171         esac
172     done
173     [ -z "$distronames" ] && distronames=$default_distroname
174     [ -z "$archs" ] && archs=$default_arch
175
176     RES=0
177     for distroname in $distronames ; do 
178         for arch in $archs; do 
179             mirror_distro_arch "$distroname" "$arch" || RES=1
180         done
181     done
182
183     exit $RES
184 }
185
186 main "$@"