| 1 |
#!/usr/bin/env ruby |
| 2 |
# |
| 3 |
# Copyright(C) 2014-2016 Kouhei Sutou <[email protected]> |
| 4 |
# Copyright(C) 2014 HAYASHI Kentaro <[email protected]> |
| 5 |
# |
| 6 |
# This library is free software; you can redistribute it and/or |
| 7 |
# modify it under the terms of the GNU Lesser General Public |
| 8 |
# License version 2.1 as published by the Free Software Foundation. |
| 9 |
# |
| 10 |
# This library is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
# Lesser General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU Lesser General Public |
| 16 |
# License along with this library; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA |
| 18 |
|
| 19 |
require "optparse" |
| 20 |
require "fileutils" |
| 21 |
require "pathname" |
| 22 |
require "open-uri" |
| 23 |
|
| 24 |
class Uploader |
| 25 |
def initialize |
| 26 |
@dput_configuration_name = "groonga-ppa" |
| 27 |
@use_pbuilder = false |
| 28 |
end |
| 29 |
|
| 30 |
def run |
| 31 |
ensure_dput_configuration |
| 32 |
|
| 33 |
parse_command_line! |
| 34 |
|
| 35 |
ensure_mysql_version |
| 36 |
|
| 37 |
@required_groonga_version = required_groonga_version |
| 38 |
|
| 39 |
@code_names.each do |code_name| |
| 40 |
mysql55_version = @mysql55_versions[code_name] |
| 41 |
mysql56_version = @mysql56_versions[code_name] |
| 42 |
mysql57_version = @mysql57_versions[code_name] |
| 43 |
mariadb10_0_version = @mariadb10_0_versions[code_name] |
| 44 |
if mysql55_version |
| 45 |
upload(code_name, "5.5", mysql55_version) |
| 46 |
end |
| 47 |
if mysql56_version |
| 48 |
upload(code_name, "5.6", mysql56_version) |
| 49 |
end |
| 50 |
if mysql57_version |
| 51 |
upload(code_name, "5.7", mysql57_version) |
| 52 |
end |
| 53 |
if mariadb10_0_version |
| 54 |
upload(code_name, "mariadb-10.0", mariadb10_0_version) |
| 55 |
end |
| 56 |
end |
| 57 |
end |
| 58 |
|
| 59 |
private |
| 60 |
def ensure_dput_configuration |
| 61 |
dput_cf_path = Pathname.new("~/.dput.cf").expand_path |
| 62 |
if dput_cf_path.exist? |
| 63 |
dput_cf_content = dput_cf_path.read |
| 64 |
else |
| 65 |
dput_cf_content = "" |
| 66 |
end |
| 67 |
dput_cf_content.each_line do |line| |
| 68 |
return if line.chomp == "[#{@dput_configuration_name}]" |
| 69 |
end |
| 70 |
|
| 71 |
dput_cf_path.open("w") do |dput_cf| |
| 72 |
dput_cf.puts(dput_cf_content) |
| 73 |
dput_cf.puts(<<-CONFIGURATION) |
| 74 |
[#{@dput_configuration_name}] |
| 75 |
fqdn = ppa.launchpad.net |
| 76 |
method = ftp |
| 77 |
incoming = ~groonga/ppa/ubuntu/ |
| 78 |
login = anonymous |
| 79 |
allow_unsigned_uploads = 0 |
| 80 |
CONFIGURATION |
| 81 |
end |
| 82 |
end |
| 83 |
|
| 84 |
def ensure_mysql_version |
| 85 |
@mysql_versions = {} |
| 86 |
@mysql55_versions = {} |
| 87 |
@mysql56_versions = {} |
| 88 |
@mysql57_versions = {} |
| 89 |
@mariadb10_0_versions = {} |
| 90 |
@code_names.each do |code_name| |
| 91 |
source_names = [code_name, "#{code_name}-updates"] |
| 92 |
source_names.each do |source_name| |
| 93 |
allpackages_url = |
| 94 |
"http://packages.ubuntu.com/#{source_name}/allpackages?format=txt.gz" |
| 95 |
open(allpackages_url) do |file| |
| 96 |
file.each_line do |line| |
| 97 |
case line |
| 98 |
when /\Amysql-server \((.+?)[\s)]/ |
| 99 |
@mysql_versions[code_name] = $1 |
| 100 |
when /\Amysql-server-5\.5 \((.+?)[\s)]/ |
| 101 |
@mysql55_versions[code_name] = $1 |
| 102 |
when /\Amysql-server-5\.6 \((.+?)[\s)]/ |
| 103 |
@mysql56_versions[code_name] = $1 |
| 104 |
when /\Amysql-server-5\.7 \((.+?)[\s)]/ |
| 105 |
@mysql57_versions[code_name] = $1 |
| 106 |
when /\Amariadb-server-10\.0 \((.+?)[\s)]/ |
| 107 |
@mariadb10_0_versions[code_name] = $1 |
| 108 |
end |
| 109 |
end |
| 110 |
end |
| 111 |
end |
| 112 |
end |
| 113 |
end |
| 114 |
|
| 115 |
def parse_command_line! |
| 116 |
parser = OptionParser.new |
| 117 |
parser.on("--package=NAME", |
| 118 |
"The package name") do |name| |
| 119 |
@package = name |
| 120 |
end |
| 121 |
parser.on("--version=VERSION", |
| 122 |
"The version") do |version| |
| 123 |
@version = version |
| 124 |
end |
| 125 |
parser.on("--source-archive-directory=DIRECTORY", |
| 126 |
"The directory that has source archives") do |directory| |
| 127 |
@source_archive_directory = Pathname.new(directory).expand_path |
| 128 |
end |
| 129 |
parser.on("--code-names=CODE_NAME1,CODE_NAME2,CODE_NAME3,...", Array, |
| 130 |
"The target code names") do |code_names| |
| 131 |
@code_names = code_names |
| 132 |
end |
| 133 |
parser.on("--debian-base-directory=DIRECTORY", |
| 134 |
"The directory that has debianXX/ directory") do |directory| |
| 135 |
@debian_base_directory = Pathname.new(directory).expand_path |
| 136 |
end |
| 137 |
parser.on("--ppa=PPA", |
| 138 |
"The personal package archive name (groonga-ppa or groonga-nightly") do |ppa| |
| 139 |
@dput_configuration_name = ppa |
| 140 |
end |
| 141 |
parser.on("--pgp-sign-key=KEY", |
| 142 |
"The PGP key to sign .changes and .dsc") do |pgp_sign_key| |
| 143 |
@pgp_sign_key = pgp_sign_key |
| 144 |
end |
| 145 |
parser.on("--[no-]pbuilder", |
| 146 |
"Use pbuilder for build check") do |use_pbuilder| |
| 147 |
@use_pbuilder = use_pbuilder |
| 148 |
end |
| 149 |
|
| 150 |
parser.parse! |
| 151 |
end |
| 152 |
|
| 153 |
def upload(code_name, mysql_short_version, mysql_version) |
| 154 |
default_mysql_version = (@mysql_versions[code_name] == mysql_version) |
| 155 |
deb_package_name = "#{@package}-#{mysql_short_version}" |
| 156 |
in_temporary_directory do |
| 157 |
source_archive = |
| 158 |
@source_archive_directory + "#{deb_package_name}_#{@version}.orig.tar.gz" |
| 159 |
run_command("tar", "xf", source_archive.to_s) |
| 160 |
directory_name = "#{deb_package_name}-#{@version}" |
| 161 |
Dir.chdir(directory_name) do |
| 162 |
debian_directory = |
| 163 |
@debian_base_directory + "debian-#{mysql_short_version}" |
| 164 |
FileUtils.cp_r(debian_directory.to_s, "debian") |
| 165 |
deb_version = "#{current_deb_version.succ}~#{code_name}1" |
| 166 |
run_command("dch", |
| 167 |
"--distribution", code_name, |
| 168 |
"--newversion", deb_version, |
| 169 |
"Build for #{code_name}.") |
| 170 |
remove_versionless_mroonga = true |
| 171 |
if default_mysql_version or mysql_short_version.start_with?("mariadb-") |
| 172 |
remove_versionless_mroonga = false |
| 173 |
end |
| 174 |
if remove_versionless_mroonga |
| 175 |
control_content = File.read("debian/control") |
| 176 |
File.open("debian/control", "w") do |control| |
| 177 |
in_mysql_server_mroonga = false |
| 178 |
control_content.each_line do |line| |
| 179 |
case line.chomp |
| 180 |
when "" |
| 181 |
if in_mysql_server_mroonga |
| 182 |
in_mysql_server_mroonga = false |
| 183 |
else |
| 184 |
control.print(line) |
| 185 |
end |
| 186 |
when "Package: mysql-server-mroonga" |
| 187 |
in_mysql_server_mroonga = true |
| 188 |
else |
| 189 |
next if in_mysql_server_mroonga |
| 190 |
control.print(line) |
| 191 |
end |
| 192 |
end |
| 193 |
end |
| 194 |
end |
| 195 |
run_command("sed", |
| 196 |
"-i", "-e", |
| 197 |
"s,MYSQL_VERSION\\|MARIADB_VERSION,#{mysql_version},", |
| 198 |
"debian/control") |
| 199 |
run_command("debuild", |
| 200 |
"--no-lintian", |
| 201 |
# Workaround for Launchpad. Launchpad doesn't accept |
| 202 |
# .buildinfo yet. |
| 203 |
# See also: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=853795 |
| 204 |
"--buildinfo-option=-O", |
| 205 |
"-d", |
| 206 |
"-S", |
| 207 |
"-sa", |
| 208 |
"-pgpg2", |
| 209 |
"-k#{@pgp_sign_key}") |
| 210 |
if @use_pbuilder |
| 211 |
run_command("pbuilder-dist", code_name, "build", |
| 212 |
"../#{deb_package_name}_#{deb_version}.dsc") |
| 213 |
else |
| 214 |
run_command("dput", @dput_configuration_name, |
| 215 |
"../#{deb_package_name}_#{deb_version}_source.changes") |
| 216 |
end |
| 217 |
end |
| 218 |
end |
| 219 |
end |
| 220 |
|
| 221 |
def required_groonga_version |
| 222 |
File.read("../../required_groonga_version").lines.first.chomp |
| 223 |
end |
| 224 |
|
| 225 |
def current_deb_version |
| 226 |
/\((.+)\)/ =~ File.read("debian/changelog").lines.first |
| 227 |
$1 |
| 228 |
end |
| 229 |
|
| 230 |
def in_temporary_directory |
| 231 |
name = "tmp" |
| 232 |
FileUtils.rm_rf(name) |
| 233 |
FileUtils.mkdir_p(name) |
| 234 |
Dir.chdir(name) do |
| 235 |
yield |
| 236 |
end |
| 237 |
end |
| 238 |
|
| 239 |
def run_command(*command_line) |
| 240 |
unless system(*command_line) |
| 241 |
raise "failed to run command: #{command_line.join(' ')}" |
| 242 |
end |
| 243 |
end |
| 244 |
end |
| 245 |
|
| 246 |
uploader = Uploader.new |
| 247 |
uploader.run |