don't sync debug/ iso/ ppc/ source/
[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"
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 case $distro in
69     [Ff]edora*)
70         case $distroindex in
71             2|4|6)
72                 for repopath in core/$distroindex/$arch/os/ core/updates/$distroindex/$arch/ extras/$distroindex/$arch/
73                   do
74                   echo "============================== $distro -> $distroindex $repopath"
75                   mkdir -p ${root}/${repopath}
76                   rsync $options ${rsyncurl}/${repopath} ${root}/${repopath}
77                 done
78                 RES=0
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                 RES=0
89                 ;;
90             *)
91                 echo "Unknown fedora index $distroindex - exiting"
92                 RES=1
93                 ;;
94         esac
95         ;;
96     *)
97         echo "$distro $distroindex currently unsupported - exiting"
98         RES=1
99         ;;
100 esac
101
102 exit $RES