-
Notifications
You must be signed in to change notification settings - Fork 0
/
port-info
executable file
·68 lines (54 loc) · 1.64 KB
/
port-info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/ruby
require 'English'
require 'net/https'
require 'yaml'
def print_field(key, value)
printf("%-21s %s\n", key, value)
end
OS_VERSION = `uname -r`.split('.')[0]
Port = Struct.new(:name) do
def set_version(str)
@variants = str.delete_prefix!("#{name} @").slice!(/\+.+/)
str
end
def file_names
output = `port info --fullname --revision #{name}`
hash = YAML.safe_load(output, symbolize_names: true)
version, revision = set_version(hash[:fullname]), hash[:revision]
base = "#{name}-#{version}_#{revision}#{@variants}.darwin_#{OS_VERSION}"
%w[x86_64 noarch].map { |arch| "#{base}.#{arch}.tbz2" }
end
def has_package?(http)
file_names.any? do |file_name|
http.request_head("/#{name}/#{file_name}").is_a?(Net::HTTPSuccess)
end
end
def print_package
value = Net::HTTP.start(
'packages.macports.org', 443, use_ssl: true) do |http|
if has_package?(http)
'yes'
elsif http.request_head("/#{name}/").is_a?(Net::HTTPSuccess)
"(partial) https://packages.macports.org/#{name}/"
else
'no'
end
end
print_field('Package URL:', value)
end
def print_info_url
print_field('Port URL:', "https://ports.macports.org/port/#{name}/details/")
end
end
raise 'Expect at least one argument.' if ARGV.empty?
system('port', 'info', *ARGV)
# skip the case of multiple ports, or invalid arguments
exit($CHILD_STATUS.exitstatus) if ARGV.size != 1 || !$CHILD_STATUS.success?
port_name = ARGV[0]
unless `port file "#{port_name}"`.include?('/rsync.macports.org/')
# skip local ports
exit
end
port = Port.new(port_name)
port.print_info_url
port.print_package