gigamo-aurb 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/aurb.gemspec +13 -0
- data/bin/aurb +150 -0
- metadata +54 -0
data/aurb.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'aurb'
|
3
|
+
s.version = '0.2.2'
|
4
|
+
s.date = '2009-04-05'
|
5
|
+
s.summary = 'A simple AUR utility'
|
6
|
+
s.email = 'gigamo@gmail.com'
|
7
|
+
s.homepage = 'http://github.com/gigamo/aurb'
|
8
|
+
s.description = s.summary
|
9
|
+
s.rubyforge_project = 'Aurb'
|
10
|
+
s.has_rdoc = false
|
11
|
+
s.authors = ['Gigamo']
|
12
|
+
s.files = ['bin/aurb', 'aurb.gemspec']
|
13
|
+
end
|
data/bin/aurb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
libraries = %w[rubygems zlib facets/minitar facets/ansicode json cgi open-uri optparse]
|
3
|
+
for library in libraries do
|
4
|
+
require library
|
5
|
+
end
|
6
|
+
|
7
|
+
module Aurb
|
8
|
+
Config = Struct.new(:search, :info, :sync, :dir)
|
9
|
+
Version = [0, 2, 2]
|
10
|
+
|
11
|
+
def self.aur
|
12
|
+
@aur ||= Aur.new
|
13
|
+
end
|
14
|
+
|
15
|
+
class AurbError < Exception; end
|
16
|
+
|
17
|
+
class Aur
|
18
|
+
attr_accessor :config
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@config = Config.new(
|
22
|
+
'http://aur.archlinux.org/rpc.php?type=search&arg=%s',
|
23
|
+
'http://aur.archlinux.org/rpc.php?type=info&arg=%s',
|
24
|
+
'/var/lib/pacman/sync/%s',
|
25
|
+
# Change this to reflect your personal download path
|
26
|
+
File.join(ENV['HOME'], 'abs')
|
27
|
+
)
|
28
|
+
@opts = Opts.new(ARGV)
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
begin
|
33
|
+
if @opts[:cmd]
|
34
|
+
instance_eval(@opts[:cmd])
|
35
|
+
else
|
36
|
+
raise AurbError, "#{color('Fatal', :on_red)}: no option given, see --help"
|
37
|
+
end
|
38
|
+
rescue AurbError => e
|
39
|
+
puts e.message
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def download(package)
|
44
|
+
unless File.exists? File.join(@config.dir, package)
|
45
|
+
for names in list(package) do
|
46
|
+
if names.first == package
|
47
|
+
Dir.chdir(@config.dir) do |dir|
|
48
|
+
if in_sync? package, 'community'
|
49
|
+
puts "#{color('==>', :yellow)} Found #{package} in community repo. Pacman will do."
|
50
|
+
# exec will automatically terminate the script
|
51
|
+
exec "sudo pacman -S #{package}"
|
52
|
+
else
|
53
|
+
puts "#{color('==>', :yellow)} Downloading #{package}."
|
54
|
+
open("http://aur.archlinux.org/packages/#{package}/#{package}.tar.gz") do |remote|
|
55
|
+
File.open("#{dir}/#{package}.tar.gz", 'wb') do |file|
|
56
|
+
file.write(remote.read)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
puts "#{color('==>', :yellow)} Unpacking #{package}."
|
62
|
+
Archive::Tar::Minitar.unpack(
|
63
|
+
Zlib::GzipReader.new(File.open("#{package}.tar.gz", 'rb')),
|
64
|
+
Dir.pwd
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
raise AurbError, "#{color('Fatal', :on_red)}: directory already exists"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def search(package)
|
75
|
+
threads, count = [], 0
|
76
|
+
for name in list(package) do
|
77
|
+
threads << Thread.new do
|
78
|
+
result = JSON.parse(open(@config.info % name[1]).read)
|
79
|
+
if result['type'] == 'error'
|
80
|
+
raise AurbError, "#{color('Fatal', :on_red)}: no results"
|
81
|
+
else
|
82
|
+
result = result['results']
|
83
|
+
next if in_sync? result['Name'], 'community'
|
84
|
+
if package.any? do |pac|
|
85
|
+
result['Name'].include? pac or result['Description'].include? pac
|
86
|
+
end
|
87
|
+
count += 1
|
88
|
+
|
89
|
+
puts "[#{result['OutOfDate'] == '1' ? color('✘', :red) : color('✔', :green)}] #{color(result['Name'], :blue)} (#{result['Version']}): #{result['Description']}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
threads.each { |t| t.join }
|
95
|
+
|
96
|
+
puts "\nFound #{color(count.to_s, :magenta)} #{count == 1 ? 'result' : 'results'}."
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
def color(text, effect)
|
101
|
+
return ANSICode.send(effect) << text << ANSICode.clear
|
102
|
+
end
|
103
|
+
|
104
|
+
def in_sync?(package, repo)
|
105
|
+
repo = @config.sync % repo
|
106
|
+
return true if Dir["#{repo}/#{package}-*"].first
|
107
|
+
end
|
108
|
+
|
109
|
+
def list(package)
|
110
|
+
info, list = JSON.parse(open(@config.search % CGI::escape(package)).read), []
|
111
|
+
if info['type'] == 'error'
|
112
|
+
raise AurbError, "#{color('Fatal', :on_red)}: #{info['results']}"
|
113
|
+
end
|
114
|
+
for result in info['results'] do
|
115
|
+
list << [result['Name'], result['ID']]
|
116
|
+
end
|
117
|
+
|
118
|
+
return list.sort
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class Opts < Hash
|
123
|
+
def initialize(args)
|
124
|
+
parse(args)
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
def parse(args)
|
129
|
+
OptionParser.new do |o|
|
130
|
+
o.version = Version*'.'
|
131
|
+
o.program_name = 'Aurb'
|
132
|
+
o.release = '2009-04-05'
|
133
|
+
|
134
|
+
o.on('-D', '--download=PKG', 'Download +PKG+') do |p|
|
135
|
+
self[:cmd] = "download('#{p}')"
|
136
|
+
end
|
137
|
+
o.on('-S', '--search=PKG', 'Search for +PKG+') do |p|
|
138
|
+
self[:cmd] = "search('#{p}')"
|
139
|
+
end
|
140
|
+
end.parse!(args)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
at_exit do
|
146
|
+
if __FILE__ == $0
|
147
|
+
raise $! if $!
|
148
|
+
Aurb.aur.start
|
149
|
+
end
|
150
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gigamo-aurb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gigamo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-05 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A simple AUR utility
|
17
|
+
email: gigamo@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- bin/aurb
|
26
|
+
- aurb.gemspec
|
27
|
+
has_rdoc: false
|
28
|
+
homepage: http://github.com/gigamo/aurb
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: "0"
|
39
|
+
version:
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project: Aurb
|
49
|
+
rubygems_version: 1.2.0
|
50
|
+
signing_key:
|
51
|
+
specification_version: 2
|
52
|
+
summary: A simple AUR utility
|
53
|
+
test_files: []
|
54
|
+
|