-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinuxMirrorScript.sh
239 lines (221 loc) · 9.67 KB
/
LinuxMirrorScript.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
#!/bin/env bash
#
# Written by: Robin Gierse - [email protected] - on 20180328
#
# Purpose:
# This script mirrors several remote repositories to a mirror server.
#
# Version: 1.0 on 20180328 - Initial commit. Script is productive.
# Version: 1.1 on 20180507 - Update Script with third party repository of iuscommunity.org
# Version: 1.2 on 20181006 - Update script with some improvements
# Version: 1.3 on 20181202 - Add debmirror abilities for debian
# Version: 1.4 on 20181217 - Add debmirror abilities for ubuntu
# Version: 1.5 on 20181230 - Add torproject repository - still testing
# Version: 2.0 on 20190102 - Add Ubuntu Bionic release
# Version: 2.1 on 20190109 - Tweak formatting and structure and update with some stuff - testing necessary
# Version: 2.2 on 20190228 - Add Debian i386 architecture
# Version: 2.3 on 20190327 - Add Debian security repository and did some formatting
# Version: 2.4 on 20190721 - Add Debian Buster
# Version: 2.5 Update script for github
#
# Usage:
# ./LinuxMirrorScript.sh
#
# Credits:
# https://www.tobanet.de/dokuwiki/debian:debmirror
# https://help.ubuntu.com/community/Debmirror
# https://gist.github.com/kleinig/3110783
# Variables
## Basic
rsync_exe="$(which rsync)"
createrepo_exe="$(which createrepo)"
reposync_exe="$(which reposync)"
mkdir_exe="$(which mkdir) -p"
logpath="/var/log/linux_mirror"
logfile="$logpath/$(date +%Y%m%d)_refresh_linux_repos.log"
start_date="$(date)"
## Repositories
base_url="mirror.netcologne.de"
base_local_repo="/var/www/repos"
centos_url="$base_url/centos"
centos_local_repo="$base_local_repo/centos"
centos_repos="os updates extras centosplus"
centos_versions="7 8"
epel_url="$base_url/fedora-epel"
epel_local_repo="$base_local_repo/epel"
debian_url="$base_url"
# Due to different syntax the two below variables have to be maintained independently. #
debian_versions="stretch,stretch-updates,buster,buster-updates"
debian_versions_security="stretch/updates,buster/updates"
#
debian_sections="main,contrib,non-free"
debian_arch="amd64,i386"
ubuntu_url="$base_url"
ubuntu_versions="bionic,bionic-security,bionic-updates,bionic-backports"
ubuntu_sections="main,restricted,universe,multiverse"
ubuntu_arch="amd64,i386"
third_repo="$base_local_repo/third"
third_repos="dl.iuscommunity.org/ius"
# Functions
_initialize() {
### Basic ###
$mkdir_exe $logpath
### Operating System Repositories ###
for repo in $centos_repos
do
for os_version in $centos_versions
do
echo "###################################################################################"
echo "$(date) Ensuring CentOS $os_version $repo Repository Directory exists- Please wait...."
if [ -d $centos_local_repo/$os_version/$repo/x86_64 ]
then
echo "Repository exists, moving on."
echo "###################################################################################"
else
echo "Repository does not exist, creating it."
$mkdir_exe $centos_local_repo/$os_version/$repo/x86_64
echo "Done."
echo "###################################################################################"
fi
done
done
### EPEL Repositories ###
for os_version in $centos_versions
do
echo "###################################################################################"
echo "$(date) Ensuring EPEL $os_version Repository Directory exists- Please wait...."
if [ -d $epel_local_repo/$os_version/x86_64 ]
then
echo "Repository exists, moving on."
echo "###################################################################################"
else
echo "Repository does not exist, creating it."
$mkdir_exe $epel_local_repo/$os_version/x86_64
echo "Done."
echo "###################################################################################"
fi
done
### Third Party Repositories ###
for repo in $third_repos
do
echo "###################################################################################"
echo "$(date) Ensuring $repo Repository Directory exists- Please wait...."
if [ -d $third_repo/$repo ]
then
echo "Repository exists, moving on."
echo "###################################################################################"
else
echo "Repository does not exist, creating it."
$mkdir_exe $third_repo/$repo
echo "Done."
echo "###################################################################################"
fi
done
}
_update_centos_repos() {
for repo in $centos_repos
do
for os_version in $centos_versions
do
echo "#################################################################################"
echo "$(date) Fetching CentOS $os_version $repo Repository - Please wait...."
$rsync_exe -avz --delete --exclude='repo*' rsync://$centos_url/$os_version/$repo/x86_64/ $centos_local_repo/$os_version/$repo/x86_64/
echo "$(date) Finished. Updating local Repository:"
$createrepo_exe --update $centos_local_repo/$os_version/$repo/x86_64
echo "#################################################################################"
echo
done
done
}
_update_epel_repos() {
for os_version in $centos_versions
do
echo "###################################################################################"
echo "$(date) Fetching CentOS $os_version EPEL Repository - Please wait...."
$rsync_exe -avz --delete --exclude='repo*' rsync://$epel_url/$os_version/x86_64/ $epel_local_repo/$os_version/x86_64/
echo "$(date) Finished. Updating local Repository:"
$createrepo_exe --update $epel_local_repo/$os_version/x86_64
echo "###################################################################################"
echo
done
}
_update_debian_repo() {
echo "#################################################################################"
echo "$(date) Updating Debian Repository:"
debmirror "${base_local_repo}/debian" --no-check-gpg -r debian -p --nosource --method=rsync --host=${debian_url} --dist=${debian_versions} --section=${debian_sections} --arch=${debian_arch} --cleanup
# no-check-gpg as workaround!?
echo "#################################################################################"
echo
}
_update_debian_security_repo() {
echo "#################################################################################"
echo "$(date) Updating Debian Security Repository:"
debmirror "${base_local_repo}/debian-security" --no-check-gpg -r debian-security -p --nosource --method=rsync --host=${debian_url} --dist=${debian_versions_security} --section=${debian_sections} --arch=${debian_arch} --cleanup
# no-check-gpg as workaround!?
echo "#################################################################################"
echo
}
_update_ubuntu_repo() {
echo "#################################################################################"
echo "$(date) Updating Ubuntu Repository:"
debmirror "${base_local_repo}/ubuntu" --no-check-gpg -r ubuntu -p --nosource --method=rsync --host=${ubuntu_url} --dist=${ubuntu_versions} --section=${ubuntu_sections} --arch=${ubuntu_arch} --cleanup
# no-check-gpg as workaround!?
echo "#################################################################################"
echo
}
_update_third_party_repos() {
for repo in $third_repos
do
echo "#################################################################################"
echo "$(date) Fetching $repo Repository - Please wait...."
$rsync_exe -avz --delete --exclude='archive/*' --exclude='development/*' --exclude='testing/*' --exclude='*/5/*' --exclude='*/6/*' --exclude='*/i386/*' --exclude='*/repoview/*' rsync://$repo/* $third_repo/$repo/
echo "$(date) Finished. Updating local Repository:"
$createrepo_exe --update $third_repo/$repo
echo "#################################################################################"
echo
done
}
_update_reposync_repos() {
for repo in $reposync_repos
do
echo "#################################################################################"
echo "$(date) Fetching $repo Repository - Please wait...."
$reposync_exe --arch=$reposync_arch --repoid=$repo --download_path=$third_repo/ --downloadcomps --download-metadata --delete
echo "$(date) Finished. Updating local Repository:"
$createrepo_exe --update $third_repo/$repo
echo "#################################################################################"
done
}
_finalize() {
echo
echo "#################################################################################"
echo
echo "### Fixing permissions ###n"
chmod 770 -R /var/www
echo
echo "### Fixing ownership ###"
chown apache:apache -R /var/www
echo
echo "### Fixing SELinux context ###"
chcon -Rt httpd_sys_content_t /var/www
echo
echo "### Mirror size ###"
echo
df -hP | head -1
df -hP | grep "$base_local_repo"
echo
echo "### Started on $start_date ###"
echo "### Finished on $(date) ###"
echo
echo "#################################################################################"
}
# Main
_initialize 2>&1 >> $logfile
_update_centos_repos 2>&1 >> $logfile
_update_epel_repos 2>&1 >> $logfile
_update_debian_repo 2>&1 >> $logfile
_update_debian_security_repo 2>&1 >> $logfile
_update_ubuntu_repo 2>&1 >> $logfile
_update_third_party_repos 2>&1 >> $logfile
_finalize 2>&1 >> $logfile
exit 0