forked from planetlab/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvbuild-fedora-mirror.sh
executable file
·241 lines (215 loc) · 6.44 KB
/
vbuild-fedora-mirror.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash
# this can help you create/update your fedora mirror
COMMAND=$(basename $0)
LOGDIR=/var/log/fedora-mirroring
DATE=$(date '+%Y-%m-%d-%H-%M')
LOG=${LOGDIR}/${DATE}.log
dry_run=
verbose=
log=
skip_core=
root=/mirror/
dhozac_url=rsync://rpm.hozac.com/dhozac/centos/
us_fedora_url=rsync://mirrors.kernel.org/fedora
us_centos_url=rsync://mirrors.rit.edu/centos
us_epel_url=rsync://rsync.gtlib.gatech.edu/fedora-epel
# ircam's fedora8 repo has been turned off
#eu_fedora_url=rsync://mirrors.ircam.fr/fedora-linux
#eu_fedora_url=rsync://mirror.ovh.net/download.fedora.redhat.com/linux
eu_fedora_url=rsync://ftp-stud.hs-esslingen.de/fedora/linux
eu_centos_url=rsync://mirrors.ircam.fr/CentOS
eu_epel_url=rsync://mirrors.ircam.fr/fedora-epel
pl_fedora_url=$eu_fedora_url
pl_centos_url=rsync://ftp.tpnet.pl/centos
pl_epel_url=rsync://ftp.icm.edu.pl/pub/Linux/fedora/linux/epel
default_distroname="f16"
all_distronames="f16 f18"
default_arch="i386"
all_archs="i386 x86_64"
case $(hostname) in
blitz*|*.fr|*.de|*.uk)
fedora_url=$eu_fedora_url ; centos_url=$eu_centos_url ; epel_url=$eu_epel_url ;;
*.pl)
fedora_url=$pl_fedora_url ; centos_url=$pl_centos_url ; epel_url=$pl_epel_url ;;
*.jp)
fedora_url=$jp_fedora_url ; centos_url=$jp_centos_url ; epel_url=$jp_epel_url ;;
*)
fedora_url=$us_fedora_url ; centos_url=$us_centos_url ; epel_url=$us_epel_url ;;
esac
function mirror_distro_arch () {
distroname=$1; shift
arch=$1; shift
distroname=$(echo $distroname | tr '[A-Z]' '[a-z]')
case $distroname in
fc*[1-6])
distroindex=$(echo $distroname | sed -e "s,fc,,g")
distro="Fedora Core"
rsyncurl=$fedora_url
;;
f*[7-9]|f1?)
distroindex=$(echo $distroname | sed -e "s,f,,g")
distro="Fedora"
rsyncurl=$fedora_url
;;
centos[4-5]|centos[4-5].[0-9])
distroindex=$(echo $distroname | sed -e "s,centos,,g")
distro="CentOS"
rsyncurl=$centos_url
;;
epel[5-6])
distroindex=$(echo $distroname | sed -e "s,epel,,g")
distro=epel
rsyncurl=$epel_url
;;
dhozac)
distroindex=5
distro="dhozac"
rsyncurl=$dhozac_url
;;
*)
echo "WARNING -- Unknown distribution $distroname -- skipped"
return 1
;;
esac
excludelist="debug/ iso/ ppc/ source/"
options="--archive --compress --delete --delete-excluded $dry_run $verbose"
[ -n "$(rsync --help | grep no-motd)" ] && options="$options --no-motd"
for e in $excludelist; do
options="$options --exclude $e"
done
echo ">>>>>>>>>>>>>>>>>>>> root=$root distroname=$distroname arch=$arch rsyncurl=$rsyncurl"
[ -n "$verbose" ] && echo "rsync options=$options"
RES=1
paths=""
case $distro in
[Ff]edora*)
case $distroindex in
2|4|6)
[ -z "$skip_core" ] && paths="core/$distroindex/$arch/os/"
paths="$paths core/updates/$distroindex/$arch/ extras/$distroindex/$arch/"
RES=0
;;
7|8|9|1?)
[ -z "$skip_core" ] && paths="releases/$distroindex/Everything/$arch/os/"
paths="$paths updates/$distroindex/$arch/"
# f8 and f9 have the additional newkey repo
case $distroindex in
8|9) paths="$paths updates/$distroindex/${arch}.newkey/" ;;
esac
RES=0
;;
esac
localpath=fedora
;;
CentOS*)
case $distroindex in
5*)
[ -z "$skip_core" ] && paths="$distroindex/os/$arch/"
paths="$paths $distroindex/updates/$arch/"
RES=0
;;
esac
localpath=centos
;;
epel*)
case $distroindex in
5|6)
paths="$paths $distroindex/$arch/"
RES=0
;;
esac
localpath=epel
;;
dhozac*)
case $distroindex in
5)
# leave off trailing '/'
paths="$paths $distroindex/vserver/$arch"
RES=0
;;
esac
localpath=dhozac
;;
esac
if [ "$RES" = 1 ] ; then
echo "DISTRIBUTION $distro $distroindex CURRENTLY UNSUPPORTED - skipped"
else
for repopath in $paths; do
echo "===== $distro -> $distroindex $repopath"
[ -z "$dry_run" ] && mkdir -p ${root}/${localpath}/${repopath}
command="rsync $options ${rsyncurl}/${repopath} ${root}/${localpath}/${repopath}"
echo $command
$command
done
fi
echo "<<<<<<<<<<<<<<<<<<<< $distroname $arch"
return $RES
}
function usage () {
echo "Usage: $COMMAND [-n] [-v] [-c] [-r root] [-u|U rsyncurl] [-e|-j] [-f distroname|-F] [-a arch|-A]"
echo "Defaults to -r $root -f $default_distroname -a $default_arch"
echo "Default urls : $fedora_url $centos_url"
echo "Options:"
echo " -n : dry run"
echo " -v : verbose"
echo " -l : turns on autologging in $LOGDIR"
echo " -c : skips core repository"
echo " -C : force syncing core repository (default)"
echo " -r root (default is $root)"
echo " -u rsyncurl for fedora (default is $fedora_url)"
echo " -U rsyncurl for centos (default is $centos_url)"
echo " -E rsyncurl for epel (default is $epel_url)"
echo " -s : uses standard (US) mirrors $us_fedora_url $us_centos_url $us_epel_url"
echo " -e : uses European mirrors $eu_fedora_url $eu_centos_url $eu_epel_url"
echo " -f distroname - use vserver convention, e.g. f8 or centos5"
echo " -F : for distroname in $all_distronames"
echo " -a arch - use yum convention"
echo " -A : for arch in $all_archs"
exit 1
}
function run () {
RES=0
for distroname in $distronames ; do
for arch in $archs; do
mirror_distro_arch "$distroname" "$arch" || RES=1
done
done
return $RES
}
function main () {
distronames=""
archs=""
while getopts "nvlcCr:u:U:E:sef:Fa:Ah" opt ; do
case $opt in
n) dry_run=--dry-run ;;
v) verbose=--verbose ;;
l) log=true ;;
c) skip_core=true ;;
C) skip_core= ;;
r) root=$OPTARG ;;
u) fedora_url=$OPTARG ;;
U) centos_url=$OPTARG ;;
E) epel_url=$OPTARG ;;
s) fedora_url=$us_fedora_url ; centos_url=$us_centos_url ; epel_url=$us_epel_url;;
e) fedora_url=$eu_fedora_url ; centos_url=$eu_centos_url ; epel_url=$eu_epel_url ;;
f) distronames="$distronames $OPTARG" ;;
F) distronames="$distronames $all_distronames" ;;
a) archs="$archs $OPTARG" ;;
A) archs="$archs $all_archs" ;;
h|*) usage ;;
esac
done
shift $(($OPTIND-1))
[[ -n "$@" ]] && usage
[ -z "$distronames" ] && distronames=$default_distroname
[ -z "$archs" ] && archs=$default_arch
# auto log : if specified
if [ -n "$log" ] ; then
mkdir -p $LOGDIR
run &> $LOG
else
run
fi
exit $?
}
main "$@"