summarylogtreecommitdiffstats
path: root/update.rb
blob: 4cb8e4a908b5a3dd2b5dc315a3b0101b45fb19a6 (plain)
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
69
70
71
72
73
#!/usr/bin/env ruby

require 'net/http'

# carch: "x86_64" or "i686"
def path_for_version(version, carch="x86_64")
	"https://ftp.mozilla.org/pub/devedition/releases/#{version}/linux-#{carch}/de/firefox-#{version}.tar.bz2"
end

# Check current version.
pkgbuild = File.read "PKGBUILD"
current_version = /^pkgver=(.*)$/.match(pkgbuild)[1].to_s
puts "Current packaged version: #{current_version}"

def attempt_upgrade(version)
	# Check if the release actually exists (sometimes it's not included in the directory).
	uri = URI(path_for_version(version))
	puts "attempting upgrade (#{version}), checking: #{uri}"
	
	request = Net::HTTP.new uri.host
	response = request.request_head uri.path
	if response.code.to_i != 200
		return false
	end

	# Update PKGBUILD file.
	pkgbuild = File.read "PKGBUILD"
	pkgbuild.gsub!(/^pkgver=.*$/, "pkgver=#{version}")
	
	File.open "PKGBUILD", "w" do |file|
		file.write pkgbuild
	end
	
	true
end

# Update logic: Start with current version, alway incrementing the beta part by one and see if it exists, if yes
#	we perform an additional step if not we are happy with what we've found.
success = false
new_version = nil
v_num, v_patch = current_version.split("b")
loop do
	v_patch = v_patch.to_i + 1
	new_version = "#{v_num}b#{v_patch}"

	if attempt_upgrade(new_version)
		success = true
	else
		break
	end
end

if success
	puts "Finishing update to version #{new_version}."

	# Clean old files.
	system "git clean -fx"

	# Update package sums & srcinfo.
	system "updpkgsums"
	system "mksrcinfo"

	# If run with --publish it will be uploaded to the remotes.
	if ARGV.include? "--publish"
		puts "Publishing update to AUR."
		system "git add PKGBUILD .SRCINFO"
		system "git commit -m 'Automatic upgrade to version #{FF_VERSION} (#{new_version}).'"
		system "git push"
	end
else
	puts "No update was available."
end