Skip to content

Commit 8c7ed6b

Browse files
committed
rpm: always replace existing repo-configuration
The installation script's main purpose is to perform a fresh install, because it's not guaranteed to work correctly when updating an existing installation, and we print a warning if we find docker is already installed. However, it's known that the script is used to update existing installations. The current script has some limitations for the update scenario; - When using the script for installing from the staging domain, the existing repo configuration is not overwritten. When using `yum`, or older `dnf` versions this resulted in 2 separate repo files to be created (docker-ce.repo and docker-ce-staging.repo), which resulted in errors due to duplicate repo definitions with the same name. - When using `dnf5`, we specified the filename to store the configuration, which resulted in an error; + sh -c 'dnf5 config-manager addrepo --save-filename=docker-ce.repo --from-repofile='\''https://download-stage.docker.com/linux/fedora/docker-ce-staging.repo'\''' File "/etc/yum.repos.d/docker-ce.repo" already exists and configures repositories with IDs "docker-ce-stable docker-ce-stable-debuginfo docker-ce-stable-source docker-ce-test docker-ce-test-debuginfo docker-ce-test-source docker-ce-nightly docker-ce-nightly-debuginfo docker-ce-nightly-source". Add "--overwrite" to overwrite. - On SLES, it would result in a similar error; + sh -c 'zypper addrepo https://download-stage.docker.com/linux/sles/docker-ce-staging.repo' Adding repository 'Docker CE Nightly - s390x' ......................................................................................[error] Repository named 'docker-ce-nightly' already exists. Please use another alias. Adding repository 'Docker CE Nightly - Debuginfo s390x' ............................................................................[error] Repository named 'docker-ce-nightly-debuginfo' already exists. Please use another alias. This patch updates the script to overwrite / replace the existing repo config. This brings the rpm-based installations in line with the Debian approach, which unconditionally overwrites `/etc/apt/sources.list.d/docker.list`. It's worth noting that this change will therefore overwrite any customisations made to the repo-configurations, so a warning is added for that. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 15dfae0 commit 8c7ed6b

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

install.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@ do_install() {
368368
installation.
369369
370370
If you installed the current Docker package using this script and are using it
371-
again to update Docker, you can safely ignore this message.
371+
again to update Docker, you can ignore this message, but be aware that the
372+
script resets any custom changes in the deb and rpm repo configuration
373+
files to match the parameters passed to the script.
372374
373375
You may press Ctrl+C now to abort this script.
374376
EOF
@@ -559,7 +561,7 @@ do_install() {
559561
fi
560562
if command_exists dnf5; then
561563
$sh_c "dnf -y -q --setopt=install_weak_deps=False install dnf-plugins-core"
562-
$sh_c "dnf5 config-manager addrepo --save-filename=docker-ce.repo --from-repofile='$repo_file_url'"
564+
$sh_c "dnf5 config-manager addrepo --overwrite --save-filename=docker-ce.repo --from-repofile='$repo_file_url'"
563565

564566
if [ "$CHANNEL" != "stable" ]; then
565567
$sh_c "dnf5 config-manager setopt \"docker-ce-*.enabled=0\""
@@ -568,6 +570,7 @@ do_install() {
568570
$sh_c "dnf makecache"
569571
elif command_exists dnf; then
570572
$sh_c "dnf -y -q --setopt=install_weak_deps=False install dnf-plugins-core"
573+
$sh_c "rm -f /etc/yum.repos.d/docker-ce.repo /etc/yum.repos.d/docker-ce-staging.repo"
571574
$sh_c "dnf config-manager --add-repo $repo_file_url"
572575

573576
if [ "$CHANNEL" != "stable" ]; then
@@ -577,6 +580,7 @@ do_install() {
577580
$sh_c "dnf makecache"
578581
else
579582
$sh_c "yum -y -q install yum-utils"
583+
$sh_c "rm -f /etc/yum.repos.d/docker-ce.repo /etc/yum.repos.d/docker-ce-staging.repo"
580584
$sh_c "yum-config-manager --add-repo $repo_file_url"
581585

582586
if [ "$CHANNEL" != "stable" ]; then
@@ -659,18 +663,23 @@ do_install() {
659663
set -x
660664
fi
661665
$sh_c "zypper install -y $pre_reqs"
666+
$sh_c "rm -f /etc/zypp/repos.d/docker-ce-*.repo"
662667
$sh_c "zypper addrepo $repo_file_url"
663-
if ! is_dry_run; then
664-
cat >&2 <<-'EOF'
665-
WARNING!!
666-
openSUSE repository (https://download.opensuse.org/repositories/security:/SELinux) will be enabled now.
667-
Do you wish to continue?
668-
You may press Ctrl+C now to abort this script.
668+
669+
opensuse_factory_url="https://download.opensuse.org/repositories/security:/SELinux/openSUSE_Factory/"
670+
if ! zypper lr -d | grep -q "${opensuse_factory_url}"; then
671+
opensuse_repo="${opensuse_factory_url}security:SELinux.repo"
672+
if ! is_dry_run; then
673+
cat >&2 <<- EOF
674+
WARNING!!
675+
openSUSE repository ($opensuse_repo) will be enabled now.
676+
Do you wish to continue?
677+
You may press Ctrl+C now to abort this script.
669678
EOF
670-
( set -x; sleep 30 )
679+
( set -x; sleep 20 )
680+
fi
681+
$sh_c "zypper addrepo $opensuse_repo"
671682
fi
672-
opensuse_repo="https://download.opensuse.org/repositories/security:/SELinux/openSUSE_Factory/security:SELinux.repo"
673-
$sh_c "zypper addrepo $opensuse_repo"
674683
$sh_c "zypper --gpg-auto-import-keys refresh"
675684
$sh_c "zypper lr -d"
676685
)

0 commit comments

Comments
 (0)