added centos5 support
[build.git] / vbuild-fedora-mirror.sh
1 #!/bin/bash
2 # this can help you create/update your fedora mirror
3
4 COMMAND=$(basename $0)
5
6 dry_run=
7 root=/data/fedora/linux
8 rsyncurl=rsync://mirrors.kernel.org/fedora
9 #rsyncurl=rsync://fr.rpmfind.net/linux/fedora
10 distroname=fc6
11 arch=i386
12
13
14 function usage () {
15     echo "Usage: $COMMAND [-n] [-v] [-r root] [-u rsyncurl] [-f distroname] [-a arch]"
16     echo "Defaults to -r $root -u $rsyncurl -f $distroname -a $arch"
17     echo "Use vserver conventions for distroname, e.g. fc6 and f7"
18     exit 1
19 }
20
21 while getopts "nvr:u:f:a:h" opt ; do
22     case $opt in
23         n) dry_run=-n ;;
24         v) set -x ;;
25         r) root=$OPTARG ;;
26         u) rsyncurl=$OPTARG ;;
27         f) distroname=$OPTARG ;;
28         a) arch=$OPTARG ;;
29         h|*) usage ;;
30     esac
31 done
32
33 case $distroname in
34     fc*[1-6])
35         distroindex=$(echo $distroname | sed -e "s,fc,,g")
36         distro="Fedora Core"
37         ;;
38     f*[7-8])
39         distroindex=$(echo $distroname | sed -e "s,f,,g")
40         distro="Fedora"
41         ;;
42     centos*[4-5])
43         distroindex=$(echo $distroname | sed -e "s,centos,,g")
44         distro="CentOS"
45         ;;
46     *)
47         echo "Unknown redhat distribution $distroname - exiting"
48         RES=1
49         ;;
50
51 esac
52
53 excludelist="debug/ iso/ ppc/ source/"
54 options="$dry_run -avz --delete --delete-excluded --quiet"
55 for e in $excludelist
56 do
57   options="$options --exclude $e"
58 done
59
60 echo "root=$root"
61 echo "distro=$distroname"
62 echo "distroname=$distroname"
63 echo "distroindex=$distroindex"
64 echo "arch=$arch"
65 echo rsyncurl="$rsyncurl"
66 echo "rsync options=$options"
67
68 RES=0
69 case $distro in
70     [Ff]edora*)
71         case $distroindex in
72             2|4|6)
73                 for repopath in core/$distroindex/$arch/os/ core/updates/$distroindex/$arch/ extras/$distroindex/$arch/
74                   do
75                   echo "============================== $distro -> $distroindex $repopath"
76                   mkdir -p ${root}/${repopath}
77                   rsync $options ${rsyncurl}/${repopath} ${root}/${repopath}
78                 done
79                 ;;
80
81             7|8)
82                 for repopath in releases/$distroindex/Everything/$arch/os/ updates/$distroindex/$arch/
83                   do
84                   echo "============================== $distro -> $distroindex $repopath"
85                   mkdir -p ${root}/${repopath}
86                   rsync $options ${rsyncurl}/${repopath} ${root}/${repopath}
87                 done
88                 ;;
89             *)
90                 echo "Unknown fedora index $distroindex - exiting"
91                 RES=1
92                 ;;
93         esac
94         ;;
95     
96     CentOS*)
97         case $distroindex in
98             5)
99                 for repopath in $distroindex/os/$arch/ $distroindex/updates/$arch/
100                   do
101                   echo "============================== $distro -> $distroindex $repopath"
102                   mkdir -p ${root}/${repopath}
103                   rsync $options ${rsyncurl}/${repopath} ${root}/${repopath}
104                 done
105                 
106                 ;;
107             *)
108                 echo "$distro $distroindex currently unsupported - exiting"
109                 RES=1
110                 ;;
111         esac
112         ;;
113
114     *)
115         echo "$distro $distroindex currently unsupported - exiting"
116         RES=1
117         ;;
118 esac
119
120 exit $RES