-
Notifications
You must be signed in to change notification settings - Fork 2
/
mirror-pgdg-repo
executable file
·120 lines (88 loc) · 2.59 KB
/
mirror-pgdg-repo
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
#!/bin/bash
# Mirrors the full pgdg repo.
#
# - m.barnaba Sun Apr 26 10:22:15 CEST 2020
#
source $(dirname $(realpath $0))/.config.pgdg.subr
create_lock
download_pgdg_yum_gpg_key() {
pg_vers=$1
destdir=$2
inkey="RPM-GPG-KEY-PGDG"
outkey="RPM-GPG-KEY"
if [ -n "$pg_vers" ]; then
inkey="${inkey}-$pg_vers"
outkey="${outkey}-$pg_vers"
fi
curl -Lso $destdir/$outkey https://download.postgresql.org/pub/repos/yum/$inkey
}
mirror_pgdg_rsync() {
# Split $1 on :
IFS=: read -ra spec <<< "$1"
pkg_fmt=${spec[0]}
pg_vers=${spec[1]}
os_spec=${spec[2]}
if [ -z "$pkg_fmt" -o -z "$os_spec" ]; then
echo "ERROR: Invalid pgdg spec: $1"
return
fi
if [ -n "$pg_vers" ]; then
url="$RSYNC_HOST/pg${pkg_fmt}-${pg_vers}/${os_spec}/"
dst="$MIRROR_DIR/${pg_vers}/${os_spec}"
else
url="$RSYNC_HOST/pg${pkg_fmt}/${os_spec}/"
dst="$MIRROR_DIR/${pkg_fmt}/${os_spec}"
fi
echo
echo "--------------------------------------------------------------"
echo "`date` - PGDG mirror started for $os_spec ($pkg_fmt) from $url to $dst"
mkdir -p $dst
$RSYNC --verbose --human-readable \
--recursive --links --perms --times \
--itemize-changes --stats --delete \
$url $dst
ret=$?
echo "`date` - PGDG rirror from $url to $dst completed with status $ret"
echo "--------------------------------------------------------------"
echo
if [ "$pkg_fmt" == "rpm" -o "$pkg_fmt" == "common" ]; then
download_pgdg_yum_gpg_key "$pg_vers" $(dirname $dst)
fi
}
mirror_pgdg_yum() {
# Split $1 on :
IFS=: read -ra spec <<< "$1"
pg_vers="${spec[0]}"
os_spec="${spec[1]}"
repo="pgdg${pg_vers}-nonfree-$(echo $os_spec | sed 's#/#-#g')"
if [ -z "$pg_vers" -o -z "$os_spec" ]; then
echo "ERROR: Invalid pgdg spec: $1"
return
fi
dir=non-free/$pg_vers/$os_spec
dst=$MIRROR_DIR/$dir
echo
echo "--------------------------------------------------------------"
echo "`date` - PGDG non-free repo $repo mirror started to $dst"
mkdir -p $dst
[ ! -L $dst/$repo ] && ln -sf . $dst/$repo # HACK
echo "Syncing packages..."
reposync --quiet --gpgcheck --repoid=$repo --download_path=$dst
echo "Creating repo metadata..."
createrepo $dst
ret=$?
echo "`date` - PGDG non-free repo $repo to $dst mirror completed with status $ret"
echo "--------------------------------------------------------------"
echo
download_pgdg_yum_gpg_key $pg_vers $(dirname $dst)
}
# rsync repos
#
for pg_spec in $PG_RSYNC; do
mirror_pgdg_rsync $pg_spec
done
# mirror repos
#
for repo in $PG_NONFREE; do
mirror_pgdg_yum $repo
done