Adding new repo with DNF's config-manager

I know how move .repo file to /etc/yum.repos.d and making template for new .repo file with baseurl, but is there ability to add new repo from standard input or write .repo file content directly in config-manager?

Something like:
echo -e “repo file content” | sudo dnf config-manager --add-repo
or
sudo dnf config-manager --add-repo “repo file content”

Unfortunately that command provides limited customization options.
I prefer creating repos like this:

Okay, so “EOF” is the file where repo details is? Why “<<”? I think “<” is enough.

sudo tee /etc/yum.repos.d/anydesk.repo << “EOF” > /dev/null
[anydesk]
name=AnyDesk Stable
baseurl=http://rpm.anydesk.com/centos/${basearch}/
gpgkey=https://keys.anydesk.com/repos/RPM-GPG-KEY
EOF
sudo rpm --import https://keys.anydesk.com/repos/RPM-GPG-KEY
sudo dnf install anydesk

2 Likes

So with sudo tee /etc/yum.repos.d/anydesk.repo << “EOF” > /dev/null you interactively write .repo file?

I ask this because I want robust command to add .repo file with one line in script. config-manager can’t do this at all? Best way is echo -e "repo file content" | sudo tee /etc/yum.repos.d/example.repo?

It would require at least 2 command invocations using convoluted syntax and resulting in a weird auto-generated repo ID and file name that you might not like.

Keep in mind that modern terminals support multi-line copy-pasting just fine, while adding redundant pipes is considered bad practice.

1 Like

What redudant pipes? I want one line command that can add new repo for my script and doc.

Think about, if I put sudo tee /etc/yum.repos.d/anydesk.repo << “EOF” > /dev/null to my doc, 60% of readers copy firstly that command to terminal and then the .repo file content. And altough they don’t that command is IMO complicated. After pasting interface isn’t simple and you must press ctrl+d and additionally the command write “EOF” to the end of the repo file.

Just copy-paste the entire block of code as-is, and it should work.
You don’t need extra shortcuts.

I believe in Linux users, they can learn new stuff. :grin:

Do you use ZSH or something? In bash, this is what I get:

sudo tee /etc/yum.repos.d/anydesk.repo << “EOF” > /dev/null
[anydesk]
name=AnyDesk Stable
baseurl=http://rpm.anydesk.com/centos/${basearch}/
gpgkey=https://keys.anydesk.com/repos/RPM-GPG-KEY
EOF
> 
bash: warning: here-document at line 9 delimited by end-of-file (wanted `“EOF”')
[sudo] password for karpe:

and, as I already said, the command make this:

cat /etc/yum.repos.d/anydesk.repo 
[anydesk]
name=AnyDesk Stable
baseurl=http://rpm.anydesk.com/centos//
gpgkey=https://keys.anydesk.com/repos/RPM-GPG-KEY
EOF

Your code is using wrong double quotes:

The correct ones look like this:

1 Like