0

I'm programmatically building boxes, but I need to update a .repo file for PHP which has the following contents:

# Repository: http://rpms.remirepo.net/ # Blog: http://blog.remirepo.net/ # Forum: http://forum.remirepo.net/ [remi] name=Remi's RPM repository for Enterprise Linux 6 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/ mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php55] name=Remi's PHP 5.5 RPM repository for Enterprise Linux 6 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/6/php55/$basearch/ mirrorlist=http://rpms.remirepo.net/enterprise/6/php55/mirror # NOTICE: common dependencies are in "remi-safe" enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php56] name=Remi's PHP 5.6 RPM repository for Enterprise Linux 6 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/6/php56/$basearch/ mirrorlist=http://rpms.remirepo.net/enterprise/6/php56/mirror # NOTICE: common dependencies are in "remi-safe" enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-test] name=Remi's test RPM repository for Enterprise Linux 6 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/6/test/$basearch/ mirrorlist=http://rpms.remirepo.net/enterprise/6/test/mirror # WARNING: If you enable this repository, you must also enable "remi" enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-debuginfo] name=Remi's RPM repository for Enterprise Linux 6 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/6/debug-remi/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php55-debuginfo] name=Remi's PHP 5.5 RPM repository for Enterprise Linux 6 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/6/debug-php55/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php56-debuginfo] name=Remi's PHP 5.6 RPM repository for Enterprise Linux 6 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/6/debug-php56/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-test-debuginfo] name=Remi's test RPM repository for Enterprise Linux 6 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/6/debug-test/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi 

I would only like to enable PHP 5.6, so I need to find the string [remi-php56], and then the first instance of enabled=0 and change it to enabled=1.

I'm sure there is a sed or awk for this, but I have been unable to figure it out.

2 Answers 2

2

Try this:

sed -i -e '/\[remi-php56\]/,/^\[/s/enabled=0/enabled=1/' /etc/yum.repos.d/*.repo 

for process all .repo files, or you can specify single target .repo file.

Or you can use you-config-manager to permanent enable/disable repo by name, if yum-utils packaje is installed in your systems.

1
  • Worked like a charm! Commented Jan 16, 2017 at 20:39
3

Even if this can probably be solved by a sed command, it would be simpler to use the proper command to change yum configuration:

yum install yum-utils yum-config-manager --enable remi-php56 

And notice, this is explained in the Wizard instructions.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.