forked from redhat-cop/containers-quickstarts
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprepare-yum-repositories
executable file
·59 lines (49 loc) · 1.97 KB
/
prepare-yum-repositories
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
#!/bin/bash
# This script is used to prepare yum repositories, that are given as arguments.
# It is no-op if user also mounts the repo file(s) into the container during
# image build. This can be done by one of those commands:
#
# docker build -v /some/repo/file:/etc/yum.repos.d/sclorg_custom.repo
# docker build -v /some/repo/directory:/etc/yum.repos.d
# make CUSTOM_REPO=/some/repo/file/or/directory
#
# The last one works for projects where we have Makefile with the
# container-common-scripts support.
set -ex
# DEFAULT_REPOS and SKIP_REPOS_{ENABLE,DISABLE} are intentionally undocumented,
# but might be used if we need to change this behaviour.
# Once we realize there are real use cases for using those variables, we should
# document them properly.
DEFAULT_REPOS=${DEFAULT_REPOS:-"rhel-7-server-rpms rhel-7-server-optional-rpms"}
SKIP_REPOS_ENABLE=${SKIP_REPOS_ENABLE:-false}
SKIP_REPOS_DISABLE=${SKIP_REPOS_DISABLE:-false}
function is_subscribed() {
for f in /run/secrets/etc-pki-entitlement/*.pem ; do
[ -e "$f" ] && return 0
break
done
return 1
}
# DEBUGGING CASE! Mostly for 'make CUSTOM_REPO=/some/file/or/dir'.
test ! -f /etc/yum.repos.d/sclorg_custom.repo && \
! mountpoint /etc/yum.repos.d \
|| exit 0
# install yum-utils for yum-config-manager
yum install -y yum-utils
if [ "$SKIP_REPOS_DISABLE" = false ] && is_subscribed; then
# Disable only repos that might come from subscribed host, because there
# might be other repos provided by user or build system
disable_repos=
# Lines look like: "Repo-id : dist-tag-override/x86_64"
while IFS=' /' read -r _ _ repo_id _; do
case $repo_id in rhel-*)
disable_repos+=" $repo_id" ;;
esac
done <<<"$(yum repolist -v 2>/dev/null | grep Repo-id)"
if test -n "$disable_repos"; then
yum-config-manager --disable $disable_repos &> /dev/null
fi
fi
if [ ${SKIP_REPOS_ENABLE} = false ] && [ -n "${DEFAULT_REPOS}" -o $# -gt 0 ] ; then
yum-config-manager --enable ${DEFAULT_REPOS} "$@"
fi