-e for a reasonable european mirror
[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=/data/fedora/linux
11 rsyncurl=rsync://mirrors.kernel.org/fedora
12 eu_rsyncurl=rsync://ftp-stud.hs-esslingen.de/fedora/linux
13 distroname=f8
14 arch=i386
15
16
17 function usage () {
18     echo "Usage: $COMMAND [-n] [-v] [-c] [-e] [-r root] [-u rsyncurl] [-f distroname] [-a arch]"
19     echo "Defaults to -r $root -u $rsyncurl -f $distroname -a $arch"
20     echo "Use vserver conventions for distroname, e.g. fc6 and f7"
21     echo "Options:"
22     echo " -n : dry run"
23     echo " -v : verbose"
24     echo " -c : skips core repository"
25     echo " -e : uses European mirror $eu_rsyncurl"
26     exit 1
27 }
28
29 while getopts "nvcer:u:f:a:h" opt ; do
30     case $opt in
31         n) dry_run=--dry-run ;;
32         v) verbose=--verbose ;;
33         c) skip_core=true ;;
34         e) rsyncurl=$eu_rsyncurl ;;
35         r) root=$OPTARG ;;
36         u) rsyncurl=$OPTARG ;;
37         f) distroname=$OPTARG ;;
38         a) arch=$OPTARG ;;
39         h|*) usage ;;
40     esac
41 done
42
43 case $distroname in
44     fc*[1-6])
45         distroindex=$(echo $distroname | sed -e "s,fc,,g")
46         distro="Fedora Core"
47         ;;
48     f*[7-8])
49         distroindex=$(echo $distroname | sed -e "s,f,,g")
50         distro="Fedora"
51         ;;
52     centos*[4-5])
53         distroindex=$(echo $distroname | sed -e "s,centos,,g")
54         distro="CentOS"
55         ;;
56     *)
57         echo "Unknown redhat distribution $distroname - exiting"
58         RES=1
59         ;;
60 esac
61
62 excludelist="debug/ iso/ ppc/ source/"
63 options="--archive --compress --delete --delete-excluded $dry_run $verbose"
64 [ -n "$(rsync --help | grep no-motd)" ] && options="$options --no-motd"
65 for e in $excludelist; do
66   options="$options --exclude $e"
67 done
68
69 if [ -n "$verbose" ] ; then 
70     echo "root=$root"
71     echo "distro=$distroname"
72     echo "distroname=$distroname"
73     echo "distroindex=$distroindex"
74     echo "arch=$arch"
75     echo rsyncurl="$rsyncurl"
76     echo "rsync options=$options"
77 fi
78
79 RES=1
80 paths=""
81 case $distro in
82     [Ff]edora*)
83         case $distroindex in
84             2|4|6)
85                 [ -z "$skip_core" ] && paths="core/$distroindex/$arch/os/"
86                 paths="$paths core/updates/$distroindex/$arch/ extras/$distroindex/$arch/"
87                 RES=0
88                 ;;
89             7|8)
90                 [ -z "$skip_core" ] && paths="releases/$distroindex/Everything/$arch/os/"
91                 paths="$paths updates/$distroindex/$arch/"
92                 RES=0
93                 ;;
94         esac
95         ;;
96     
97     CentOS*)
98         case $distroindex in
99             5)
100                 [ -z "$skip_core" ] && paths="$distroindex/os/$arch/"
101                 paths="$paths $distroindex/updates/$arch/"
102                 RES=0
103                 ;;
104         esac
105         ;;
106
107 esac
108
109 if [ "$RES" = 1 ] ; then
110     echo "$distro $distroindex currently unsupported - exiting"
111 else
112     for repopath in $paths; do
113         echo "============================== $distro -> $distroindex $repopath"
114         [ -z "$dry_run" ] && mkdir -p ${root}/${repopath}
115         command="rsync $options ${rsyncurl}/${repopath} ${root}/${repopath}"
116         echo $command
117         $command
118     done
119 fi
120
121 exit $RES