-
Notifications
You must be signed in to change notification settings - Fork 2
/
mirror-buildservice-repo
executable file
·107 lines (82 loc) · 3.37 KB
/
mirror-buildservice-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
#!/bin/sh
# Mirrors builservice repos. Meant to be run daily.
#
# -- m.barnaba@ifad.org Sat Mar 29 16:46:48 CET 2014
#
source $(dirname $(realpath $0))/.config.buildservice.subr
create_lock
mirror_repo_rsync() {
REPO="$1"
echo
echo "--------------------------------------------------------------"
echo "`date` - OpenSuSE buildservice $REPO rsync mirror started"
mkdir -p $MIRROR_DIR/$REPO
cd $MIRROR_DIR
$RSYNC --verbose --human-readable --no-motd \
--recursive --links --perms --times \
--itemize-changes --stats \
--exclude 'openSUSE_*/src' --exclude 'openSUSE_*/src/**' \
--include 'openSUSE_Leap_*' --include 'openSUSE_Leap_*/**' \
--exclude 'RHEL_*/src' --exclude 'RHEL_*/src/**' \
--include 'RHEL_*' --include 'RHEL_*/**' \
--exclude 'SLE_*/src' --exclude 'SLE_*/src/**' \
--include 'SLE_*' --include 'SLE_*/**' \
--exclude 'rpm/src' --exclude 'rpm/src/**' \
--include 'rpm' --include 'rpm/**' \
--include 'repodata' --include 'repodata/**' \
--include '*.repo' \
--exclude '*' \
$RSYNC_HOST/$REPO/ $MIRROR_DIR/$REPO
ret=$?
echo "`date` - OpenSuSE buildservice $REPO mirror completed with status $ret"
echo "--------------------------------------------------------------"
echo
}
mirror_repo_yum() {
REPO="$1"
if ! echo $REPO | grep -q ^buildservice:; then
echo "Invalid repo ID $REPO. Requires a buildservice:XXX- heading to distinguish across multiple repos."
return
fi
echo
echo "--------------------------------------------------------------"
echo "`date` - OpenSuSE buildservice $REPO yum mirror started"
REPO_BS_ID=$(echo $REPO | sed -r -e 's#buildservice:.*?-##' -e 's#_#:#g')
REPO_BS_PATH=$(grep ^baseurl /etc/yum/repos.d/${REPO}.repo|sed -r -e 's#^baseurl=https?://[^/]+/repositories/##' -e 's#/$##')
REPO_DIR=$MIRROR_DIR/$REPO_BS_PATH
mkdir -p $REPO_DIR
# We want yum to download in the same directory as rsync, so to not change systems' configuration,
# but there is no option in reposync to ask to not create a directory whose name is the repo id, so
# we create a symlink from the target directory that reposync uses to the directory containing the
# symlink. Crude hack, but it works.
ln -s . $REPO_DIR/$REPO
echo "Syncing packages..."
reposync --gpgcheck --repoid=$REPO --download_path=$REPO_DIR
# Remove the symlink to avoid createrepo infinite loops.
#
rm -f $REPO_DIR/$REPO
echo "Creating repo metadata..."
createrepo --verbose --simple-md-filenames $REPO_DIR
echo "Regenerating .repo file..."
cat <<EOF > $REPO_DIR/${REPO_BS_ID}.repo
[$REPO]
name=Buildservice repository $REPO_BS_ID
baseurl=$MIRROR_URL/$REPO_BS_PATH
gpgcheck=1
gpgkey=$MIRROR_URL/$REPO_BS_PATH/repodata/repomd.xml.key
enabled=1
autorefresh=1
type=rpm-md
EOF
echo "`date` - Buildservice $REPO yum mirror completed"
echo "--------------------------------------------------------------"
echo
}
for repo in $BUILDSERVICE_REPOS_RSYNC; do
mirror_repo_rsync $repo
done
replace_repo_uris $MIRROR_DIR
for repo in $BUILDSERVICE_REPOS_YUM; do
mirror_repo_yum $repo
done
exit $ret