-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.rb
executable file
·49 lines (43 loc) · 927 Bytes
/
update.rb
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
#!/usr/bin/env ruby
# rubocop: disable all
def usage
puts "#{$0} version [path_to_shasums]"
exit 1
end
$version = ARGV.shift or usage
def sums
if ARGV.empty?
`curl -fLSs https://github.com/get-bridge/muss/releases/download/#{$version}/SHA256SUMS`.tap do |s|
raise s if $? != 0
end.split("\n")
else
path = ARGV.first
if path == "-"
STDIN.readlines
else
File.readlines(path)
end
end.map(&:chomp)
end
subs = {
"version" => $version
}
sums.each do |line|
sha, name = line.split(/ +/)
subs[%("#{name}")] = sha
end
formula = File.join(__dir__, "Formula", "muss.rb")
lines = File.readlines(formula)
lines.map! do |line|
if match = line.match(/^((?:\s*)(\S+)(?:.+?"))(?:[^"]+)(",?)$/)
key = match[2]
if subs.key?(key)
[match[1], subs[key], match[3], "\n"].join("")
else
line
end
else
line
end
end
File.write(formula, lines.join(""))