centos5.2
[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.1 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-9])
93                     [ -z "$skip_core" ] && paths="releases/$distroindex/Everything/$arch/os/"
94                     paths="$paths updates/$distroindex/$arch/"
95                     RES=0
96                     ;;
97             esac
98             localpath=fedora
99             ;;
100     
101         CentOS*)
102             case $distroindex in
103                 5*)
104                     [ -z "$skip_core" ] && paths="$distroindex/os/$arch/"
105                     paths="$paths $distroindex/updates/$arch/"
106                     RES=0
107                     ;;
108             esac
109             localpath=centos
110             ;;
111
112     esac
113
114     if [ "$RES" = 1 ] ; then
115         echo "DISTRIBUTION $distro $distroindex CURRENTLY UNSUPPORTED - skipped"
116     else
117         for repopath in $paths; do
118             echo "============================== $distro -> $distroindex $repopath"
119             [ -z "$dry_run" ] && mkdir -p ${root}/${localpath}/${repopath}
120             command="rsync $options ${rsyncurl}/${repopath} ${root}/${localpath}/${repopath}"
121             echo $command
122             $command
123         done
124     fi
125
126     return $RES 
127 }
128
129 function usage () {
130     echo "Usage: $COMMAND [-n] [-v] [-c] [-r root] [-u|U rsyncurl] [-e|-j] [-f distroname|-F] [-a arch|-A]"
131     echo "Defaults to -r $root -u $rsyncurl -f $default_distroname -a $default_arch"
132     echo "Options:"
133     echo " -n : dry run"
134     echo " -v : verbose"
135     echo " -c : skips core repository"
136     echo " -r root (default is $root)"
137     echo " -u rsyncurl for fedora (default is $fedora_url)"
138     echo " -U rsyncurl for centos (default is $centos_url)"
139     echo " -e : uses European mirrors $eu_fedora_url $eu_centos_url"
140     echo " -j : uses Japanese mirrors $jp_fedora_url $jp_centos_url"
141     echo " -f distroname - use vserver convention, e.g. fc6 and f7"
142     echo " -F : for distroname in $all_distronames"
143     echo " -a arch - use yum convention"
144     echo " -A : for arch in $all_archs"
145     exit 1
146 }
147
148 function main () {
149     distronames=""
150     archs=""
151     while getopts "nvcr:u:U:ef:Fa:Ah" opt ; do
152         case $opt in
153             n) dry_run=--dry-run ; verbose=--verbose ;;
154             v) verbose=--verbose ;;
155             c) skip_core=true ;;
156             r) root=$OPTARG ;;
157             u) fedora_url=$OPTARG ;;
158             U) centos_url=$OPTARG ;;
159             e) fedora_url=$eu_fedora_url ; centos_url=$eu_centos_url ;;
160             j) fedora_url=$jp_fedora_url ; centos_url=$jp_centos_url ;;
161             f) distronames="$distronames $OPTARG" ;;
162             F) distronames="$distronames $all_distronames" ;;
163             a) archs="$archs $OPTARG" ;;
164             A) archs="$archs $all_archs" ;;
165             h|*) usage ;;
166         esac
167     done
168     [ -z "$distronames" ] && distronames=$default_distroname
169     [ -z "$archs" ] && archs=$default_arch
170
171     RES=0
172     for distroname in $distronames ; do 
173         for arch in $archs; do 
174             mirror_distro_arch "$distroname" "$arch" || RES=1
175         done
176     done
177
178     exit $RES
179 }
180
181 main "$@"