do output logging externally from within cron job
[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 fcdistro=fc6
11 arch=i386
12
13
14 function usage () {
15     echo "Usage: $COMMAND [-n] [-v] [-r root] [-u rsyncurl] [-f fcdistro] [-a arch]"
16     echo "Defaults to -r $root -u $rsyncurl -f $fcdistro -a $arch"
17     echo "Use vserver conventions for fcdistro, 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) fcdistro=$OPTARG ;;
28         a) arch=$OPTARG ;;
29         h|*) usage ;;
30     esac
31 done
32
33 case $fcdistro in
34     fc*[1-6])
35         findex=$(echo $fcdistro | sed -e s,fc,,g)
36         ;;
37     *)
38         findex=$(echo $fcdistro | sed -e s,f,,g)
39         ;;
40 esac
41
42 echo "root=$root"
43 echo rsyncurl="$rsyncurl"
44 echo "fcdistro=$fcdistro"
45 echo "findex=$findex"
46 echo "arch=$arch"
47
48 case $findex in
49     2|4|6)
50         echo "============================== $findex core"
51         mkdir -p ${root}/core/$findex/$arch/os/
52         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/$findex/$arch/os/ ${root}/core/$findex/$arch/os/
53         echo "============================== $findex updates"
54         mkdir -p  ${root}/core/updates/$findex/$arch/
55         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/updates/$findex/$arch/ ${root}/core/updates/$findex/$arch/
56         echo "============================== $findex extras"
57         mkdir -p ${root}/extras/$findex/$arch/
58         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/extras/$findex/$arch/ ${root}/extras/$findex/$arch/
59         RES=0
60         ;;
61     7)
62         echo "============================== $findex core"
63         mkdir -p ${root}/core/$findex/$arch/os/
64         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/$findex/Everything/$arch/os/ ${root}/core/$findex/$arch/os/
65         echo "============================== $findex updates"
66         mkdir -p ${root}/core/updates/$findex/$arch/
67         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/updates/$findex/$arch/ ${root}/core/updates/$findex/$arch/
68         RES=0
69         ;;
70     8)
71     # somehow the layout on my favorite mirror is different in 7 and 8, /Everything/ has gone 
72         echo "============================== $findex core"
73         mkdir -p ${root}/core/$findex/$arch/os/
74         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/$findex/$arch/os/ ${root}/core/$findex/$arch/os/
75         echo "============================== $findex updates"
76         mkdir -p ${root}/core/updates/$findex/$arch/
77         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/updates/$findex/$arch/ ${root}/core/updates/$findex/$arch/
78         RES=0
79         ;;
80     *)
81         echo "Unknown fedora index $findex - exiting"
82         RES=1
83         ;;
84 esac
85
86 exit $RES