passes verbose to rsync
[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 distroname=fc6
10 arch=i386
11
12
13 function usage () {
14     echo "Usage: $COMMAND [-n] [-v] [-r root] [-u rsyncurl] [-f distroname] [-a arch]"
15     echo "Defaults to -r $root -u $rsyncurl -f $distroname -a $arch"
16     echo "Use vserver conventions for distroname, e.g. fc6 and f7"
17     exit 1
18 }
19
20 while getopts "nvr:u:f:a:h" opt ; do
21     case $opt in
22         n) dry_run=-n ;;
23         v) set -x ; verbose=true ;;
24         r) root=$OPTARG ;;
25         u) rsyncurl=$OPTARG ;;
26         f) distroname=$OPTARG ;;
27         a) arch=$OPTARG ;;
28         h|*) usage ;;
29     esac
30 done
31
32 case $distroname in
33     fc*[1-6])
34         distroindex=$(echo $distroname | sed -e "s,fc,,g")
35         distro="Fedora Core"
36         ;;
37     f*[7-8])
38         distroindex=$(echo $distroname | sed -e "s,f,,g")
39         distro="Fedora"
40         ;;
41     centos*[4-5])
42         distroindex=$(echo $distroname | sed -e "s,centos,,g")
43         distro="CentOS"
44         ;;
45     *)
46         echo "Unknown redhat distribution $distroname - exiting"
47         RES=1
48         ;;
49
50 esac
51
52 excludelist="debug/ iso/ ppc/ source/"
53 options="$dry_run -avz --delete --delete-excluded --quiet"
54 [ -n "$verbose" ] && options="$options --verbose"
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