Skip to content

Instantly share code, notes, and snippets.

@felipec
Last active May 5, 2021
Embed
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 = {}
$all = false
ARGV.delete_if do |arg|
case arg
when '-a', '--all'
$all = true
end
end
IO.popen(%w[pacman -Qm]).each do |l|
name, version = l.chomp.split
$packages[name] = [version, nil]
end
exit if $packages.empty?
uri = URI('https://aur.archlinux.org/rpc/')
uri.query = URI.encode_www_form(v: 5, type: 'info', 'arg[]' => $packages.keys)
data = JSON.parse(Net::HTTP.get(uri), symbolize_names: true)
data[:results].each do |e|
name = e[:Name]
$packages[name][1] = e[:Version]
end
$packages.each do |package, (local, remote)|
if local == remote
puts "\e[1;37m%s\e[0m: \e[1;32m%s\e[0m (\e[1;34mup to date\e[0m)" % [package, local] if $all
elsif not remote
puts "\e[1;37m%s\e[0m: \e[1;32m%s\e[0m (\e[1;31mmissing\e[0m)" % [package, local]
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