Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Script to check AUR packages
#!/usr/bin/env ruby
# This script checks all your foreign packages against AUR to find newer versions
require 'net/http'
require 'json'
$packages = {}
$verbose = false
IO.popen(['pacman', '-Qm']).each do |l|
name, version = l.chomp.split
$packages[name] = [version, nil, nil]
end
# $packages['foobar'] = ['0.1', nil, nil]
exit if $packages.empty?
http = Net::HTTP.new('aur.archlinux.org', 443)
http.use_ssl = true
request = Net::HTTP::Get.new('/rpc/?v=5&type=info&%s' % $packages.keys.map {|e| "arg[]=#{e}"}.join('&') )
response = http.request(request)
data = JSON.parse(response.body)
data['results'].each do |r|
name = r['Name']
$packages[name][1] = r['Version']
$packages[name][2] = r['URLPath']
end
$packages.each do |package, (local, remote, path)|
next if local == remote
if not remote
puts "\e[1;37m%s\e[0m: \e[1;32m%s\e[0m (\e[1;31mmissing\e[0m)" % [package, local]
elsif $verbose
puts "\e[1;37m%s\e[0m: \e[1;32m%s\e[0m (aur: %s) [\e[0;34mhttps://aur.archlinux.org/%s\e[0m]" % [package, local, remote, path]
else
puts "\e[1;37m%s\e[0m: \e[1;32m%s\e[0m (aur: %s)" % [package, local, remote]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment