fix fedora-mirror that was creating an extra x86_64/ step in mirrored paths
[build.git] / fedora-mirror.sh
1 #!/bin/bash
2 # this can help you create/update your fedora mirror
3
4 COMMAND=$(basename $0)
5 LOGDIR=/var/log/fedora-mirror
6 DATE=$(date '+%Y-%m-%d-%H-%M')
7 LOG=${LOGDIR}/${DATE}.log
8
9 dry_run=
10 verbose=--verbose
11 log=
12 skip_core=true
13 root=/mirror/
14
15
16 us_fedora_url=rsync://mirrors.kernel.org/fedora
17 eu_fedora_url=rsync://mirror1.hs-esslingen.de/fedora/linux
18
19 default_distroname="f29"
20 all_distronames="f27 f29"
21
22 global_arch="x86_64"
23
24 # use EU mirror
25 fedora_url=$eu_fedora_url
26
27 function mirror_distro_arch () {
28     distroname=$1; shift
29     arch=$1; shift
30
31     distroname=$(echo $distroname | tr '[A-Z]' '[a-z]')
32     case $distroname in
33     f*)
34         distroindex=$(echo $distroname | sed -e "s,f,,g")
35         distro="Fedora"
36         rsyncurl=$fedora_url
37         ;;
38     *)
39         echo "WARNING -- Unknown distribution $distroname -- skipped"
40         return 1
41         ;;
42     esac
43
44     excludelist="debug/ iso/ ppc/ source/"
45     options=""
46     [ -n "$(rsync --help | grep no-motd)" ] && options="$options --no-motd"
47     options="$options $dry_run $verbose"
48     options="$options -aH --numeric-ids"
49     options="$options --delete --delete-excluded --delete-after --delay-updates"
50     for e in $excludelist; do
51         options="$options --exclude $e"
52     done
53
54     echo ">>>>>>>>>>>>>>>>>>>> distroname=$distroname arch=$arch rsyncurl=$rsyncurl"
55     [ -n "$verbose" ] && echo "rsync options=$options"
56
57     paths=""
58     [ -z "$skip_core" ] && paths="releases/$distroindex/Everything/$arch/os/"
59     if [ "$distroindex" -le 27 ]; then
60         paths="$paths updates/$distroindex/$arch/"
61         localpath=fedora
62     else
63         paths="$paths updates/$distroindex/Everything/$arch/ updates/$distroindex/Modular/$arch/"
64     fi
65
66     for repopath in $paths; do
67         echo "===== $distro -> $distroindex $repopath"
68         [ -z "$dry_run" ] && mkdir -p ${root}/${localpath}/${repopath}
69         command="rsync $options ${rsyncurl}/${repopath} ${root}/${localpath}/${repopath}"
70         echo $command
71        $command
72     done
73
74     echo "<<<<<<<<<<<<<<<<<<<< $distroname $arch"
75
76     return $RES
77 }
78
79 function usage () {
80     echo "Usage: $COMMAND [-n] [-v] [-l] [-c] [-e|-s|-u rsyncurl] [-f distroname|-F]"
81     echo "Options:"
82     echo " -n : dry run"
83     echo " -v : turn off verbose"
84     echo " -l : turns on autologging in $LOGDIR"
85     echo " -c : also sync core repository (releases)"
86     echo " -s : uses US mirror $us_fedora_url"
87     echo " -e : uses EU mirror $eu_fedora_url"
88     echo " -u <url> : use this (rsync) for fedora (default is $fedora_url)"
89     echo " -f distroname - default is $default_distroname"
90     echo " -F : do on all distros $all_distronames"
91     exit 1
92 }
93
94 function run () {
95     RES=0
96     for distroname in $distronames ; do
97         for arch in $archs; do
98             mirror_distro_arch "$distroname" "$arch" || RES=1
99         done
100     done
101     return $RES
102 }
103
104 function main () {
105     distronames=""
106     archs="$global_arch"
107     while getopts "nvlcu:sef:Fh" opt ; do
108     case $opt in
109         n) dry_run=--dry-run ;;
110         v) verbose= ;;
111         l) log=true ;;
112         c) skip_core= ;;
113         u) fedora_url=$OPTARG ;;
114         s) fedora_url=$us_fedora_url ;;
115         e) fedora_url=$eu_fedora_url ;;
116         f) distronames="$distronames $OPTARG" ;;
117         F) distronames="$distronames $all_distronames" ;;
118         h|*) usage ;;
119     esac
120     done
121     shift $(($OPTIND-1))
122     [[ -n "$@" ]] && usage
123     [ -z "$distronames" ] && distronames=$default_distroname
124
125     # auto log : if specified
126     if [ -n "$log" ] ; then
127         mkdir -p $LOGDIR
128         run &> $LOG
129     else
130         run
131     fi
132     if [ "$?" == 0 ]; then
133         # report to fedora's infra
134         # can't get the config right...
135         #/usr/bin/report_mirror
136         exit 0
137     else
138         exit 1
139     fi
140 }
141
142 main "$@"