Skip to content

Instantly share code, notes, and snippets.

@hron84
Last active September 17, 2019 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hron84/1bd20053ba18d930f461c4878d586f54 to your computer and use it in GitHub Desktop.
Save hron84/1bd20053ba18d930f461c4878d586f54 to your computer and use it in GitHub Desktop.
Interactive YUM updates

Interactive YUM Updates

This script allows you to select certain packages for update. It is useful if you having trouble running a single yum update and have a lot of packages to update (which is very common on production systems) or you want to delay the update of some packages but want the rest as soon as possible.

Usage

Just run the yum-interactive-update.rb and select updates you want to apply. You can specify the updates by their index (appears before the package name). The UI accepts a range of indexes in ruby notation syntax, FROM..TO (e.g. 12..25). The range is closed at the both end that means if you select 12..25 packages indexed with 12 and 25 will be included into the updateable package list.

Note: It's clear from the name of the script but it need an emphasizement: this script can only work with YUM package manager (that is included in e.g. CentOS, Fedora, CloudLinux, etc).

License

This package is licensed under the terms of CreativeCommons BY-SA 4.0 license.

Copyright (c) 2019 Gabor Garami. Some rights reserved.

#!/usr/bin/env ruby
lines = %x{/bin/yum -d 0 -e 0 list updates}.split(/[\r\n]+/)
#lines = File.read('up.txt').split(/[\r\n]+/)
lines.shift # No header pls
updates = lines.map { |line| line.split(/\s+/).first }.compact
exit if updates.empty?
puts 'Available updates:'
puts "=" * 40
updates.each_with_index do |pkg, i|
puts sprintf("%3d) %s", i, pkg)
end
puts '=' * 40
print 'Select applicable updates (e.g.: 1, 2..15): '
answer = gets.strip.split(/,\s*/)
if answer.first == '-1'
exit
end
indexes = []
answer.each do |v|
if v.match(/^\d+\.\.\d+$/)
indexes += eval(v).to_a
else
indexes << v.to_i
end
end
packages = indexes.map { |i| updates[i] }
puts
puts " >> Selected packages: #{packages.join(', ')}"
system('/bin/yum', 'install', *packages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment