log actions
[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 # manage LOG - beware it might be a symlink so nuke it first
43 LOG=$(mktemp /tmp/vserver-fedora-mirror-log.XXXX)
44 rm -f $LOG
45 exec > $LOG 2>&1
46
47 echo "root=$root"
48 echo rsyncurl="$rsyncurl"
49 echo "fcdistro=$fcdistro"
50 echo "findex=$findex"
51 echo "arch=$arch"
52
53 case $findex in
54     2|4|6)
55         echo "============================== $findex core"
56         mkdir -p ${root}/core/$findex/$arch/os/
57         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/$findex/$arch/os/ ${root}/core/$findex/$arch/os/
58         echo "============================== $findex updates"
59         mkdir -p  ${root}/core/updates/$findex/$arch/
60         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/updates/$findex/$arch/ ${root}/core/updates/$findex/$arch/
61         echo "============================== $findex extras"
62         mkdir -p ${root}/extras/$findex/$arch/
63         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/extras/$findex/$arch/ ${root}/extras/$findex/$arch/
64         RES=0
65         ;;
66     7)
67         echo "============================== $findex core"
68         mkdir -p ${root}/core/$findex/$arch/os/
69         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/$findex/Everything/$arch/os/ ${root}/core/$findex/$arch/os/
70         echo "============================== $findex updates"
71         mkdir -p ${root}/core/updates/$findex/$arch/
72         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/updates/$findex/$arch/ ${root}/core/updates/$findex/$arch/
73         RES=0
74         ;;
75     8)
76     # somehow the layout on my favorite mirror is different in 7 and 8, /Everything/ has gone 
77         echo "============================== $findex core"
78         mkdir -p ${root}/core/$findex/$arch/os/
79         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/$findex/$arch/os/ ${root}/core/$findex/$arch/os/
80         echo "============================== $findex updates"
81         mkdir -p ${root}/core/updates/$findex/$arch/
82         rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/updates/$findex/$arch/ ${root}/core/updates/$findex/$arch/
83         RES=0
84         ;;
85     *)
86         echo "Unknown fedora index $findex - exiting"
87         RES=1
88         ;;
89 esac
90
91 exit $RES