0

A group of Amazon Linux 2 instances have duplicate instances of name=packages-microsoft-com-prod in redundant yum repositories with different names. What is a safe way to remove the duplicate references to the same package without causing other things that run in the same operating system to break?

Here is how the problem is illustrated by a grep:

[user-name@host-name ~]$ sudo grep name=packages-microsoft-com-prod /etc/yum.repos.d/*
/etc/yum.repos.d/microsoft-prod.repo:name=packages-microsoft-com-prod
/etc/yum.repos.d/msprod.repo:name=packages-microsoft-com-prod

The two instances of the package are causing other programs in the instances to return errors indicating that they do not know which of the two identically named packages to use.

I tried yum update, but the problem persists. I could write some bash script to check for duplicate names and delete one repo until there are no duplicates. But I am concerned that deleting repos might be a hack approach that might cause collateral damage elsewhere in the machines.


User Requests:

Per @JeffSchaller 's comment, I am adding the following terminal output to elaborate the situation:

[user-name@host-name ~]$ grep -c ^name= /etc/yum.repos.d/microsoft-prod.repo /etc/yum.repos.d/msprod.repo
/etc/yum.repos.d/microsoft-prod.repo:1
/etc/yum.repos.d/msprod.repo:1

[user-name@host-name ~]$ rpm -qf /etc/yum.repos.d/microsoft-prod.repo /etc/yum.repos.d/msprod.repo
packages-microsoft-prod-1.0-1.el7.noarch
file /etc/yum.repos.d/msprod.repo is not owned by any package

[user-name@host-name ~]$ sudo cat /etc/yum.repos.d/microsoft-prod.repo
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/rhel/7/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc

[user-name@host-name ~]$ sudo cat /etc/yum.repos.d/msprod.repo
[packages-microsoft-com-prod]
name=packages-microsoft-com-prod
baseurl=https://packages.microsoft.com/rhel/7/prod/
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
CodeMed
  • 5,199
  • @JeffSchaller Answers to your questions are now at the end of the OP. How can I handle this safely? Without causing side effect crashes of other things. – CodeMed May 31 '19 at 18:04

1 Answers1

2

Given the situation you've demonstrated, I would rm /etc/yum.repos.d/msprod.repo, as it is a duplicate of /etc/yum.repos.d/microsoft-prod.repo, and is also not owned by any package.

To programmatically determine whether a file is owned by a package, check the return code of rpm:

if rpm -qf /the/file > /dev/null 2>&1
then
  : the file is owned by an RPM
else
  : the file is not owned by an RPM
fi
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • Do you still stand by this answer after the information I added to the OP? Note that this has to be done using an automation script, because these instances are being created and managed by automation. – CodeMed May 31 '19 at 18:06
  • Well, I'd want to prevent the duplication in the first place. I pointed to the un-owned file as being safer to remove, since the package that owns the other file would expect it to be there and might re-place it there during upgrades. – Jeff Schaller May 31 '19 at 18:19
  • OK. Thank you. But then with a script, how can a script tell which one is not owned? – CodeMed May 31 '19 at 18:23
  • @Codemed, see the edit. Although I'd expect automated instances to be created according to some sort consistent rules, which you could chase upstream to find the creator of the stray file. – Jeff Schaller May 31 '19 at 18:26
  • Can you please give an explicit description of what > /dev/null 2>&1 does within the line if rpm -qf /the/file > /dev/null 2>&1? – CodeMed May 31 '19 at 20:08
  • @CodeMed, see https://unix.stackexchange.com/questions/159513/what-are-the-shells-control-and-redirection-operators for more; the short version is that we don't care about any of the output from the command, so we dump it all in the /dev/null bitbucket. – Jeff Schaller May 31 '19 at 20:11