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