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]
# $packages['foobar'] = ['0.1', nil, nil]
exit if $packages.empty?
http ='', 443)
http.use_ssl = true
request ='/rpc/?v=5&type=info&%s' % $ {|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']
$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;34m\e[0m]" % [package, local, remote, path]
puts "\e[1;37m%s\e[0m: \e[1;32m%s\e[0m (aur: %s)" % [package, local, remote]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment