Script to check AUR packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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