bukin 0.1.0 → 0.2.0
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/LICENSE.txt +159 -613
- data/bin/bukin +1 -1
- data/lib/bukin.rb +1 -0
- data/lib/bukin/bukfile.rb +29 -15
- data/lib/bukin/cli.rb +48 -59
- data/lib/bukin/friendly_errors.rb +20 -0
- data/lib/bukin/installer.rb +22 -0
- data/lib/bukin/lockfile.rb +50 -39
- data/lib/bukin/providers/bukget.rb +17 -19
- data/lib/bukin/providers/bukkit_dl.rb +18 -24
- data/lib/bukin/utils.rb +37 -38
- data/lib/bukin/version.rb +1 -1
- metadata +4 -2
data/bin/bukin
CHANGED
data/lib/bukin.rb
CHANGED
data/lib/bukin/bukfile.rb
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
|
|
2
1
|
class Bukin::Bukfile
|
|
3
|
-
|
|
2
|
+
FILE_NAME = 'Bukfile'
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
attr_accessor :server_info, :plugins_info
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
def self.from_file(path = nil)
|
|
7
|
+
path ||= File.join(Dir.pwd, FILE_NAME)
|
|
8
|
+
from_code(File.read(path))
|
|
9
|
+
end
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
else
|
|
15
|
-
abort("Error: There is more than one server declared in your #{INSTALL_FILE}")
|
|
16
|
-
end
|
|
17
|
-
end
|
|
11
|
+
def self.from_block(&block)
|
|
12
|
+
from_code(&block)
|
|
13
|
+
end
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
def self.from_code(code)
|
|
16
|
+
bukfile = Bukin::Bukfile.new
|
|
17
|
+
bukfile.instance_eval(code)
|
|
18
|
+
bukfile
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def initialize
|
|
22
|
+
@plugins_info = []
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def server(name, version = 'latest-rb')
|
|
26
|
+
unless @server_info
|
|
27
|
+
@server_info = { name: name, version: version }
|
|
28
|
+
else
|
|
29
|
+
abort("Error: There is more than one server declared in your #{FILE_NAME}")
|
|
21
30
|
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def plugin(name, version = 'latest')
|
|
34
|
+
@plugins_info << { name: name, version: version }
|
|
35
|
+
end
|
|
22
36
|
end
|
data/lib/bukin/cli.rb
CHANGED
|
@@ -1,77 +1,66 @@
|
|
|
1
1
|
require 'thor'
|
|
2
|
-
require 'bukin/
|
|
2
|
+
require 'bukin/installer'
|
|
3
3
|
require 'bukin/bukfile'
|
|
4
4
|
require 'bukin/providers/bukget'
|
|
5
5
|
require 'bukin/providers/bukkit_dl'
|
|
6
6
|
|
|
7
|
-
# Path to install plugins to
|
|
8
|
-
PLUGINS_PATH = "plugins"
|
|
9
|
-
|
|
10
|
-
# Path to install the server in
|
|
11
|
-
SERVER_PATH = "."
|
|
12
|
-
|
|
13
7
|
class Bukin::CLI < Thor
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
desc 'install', "Download and install the resources specified in a Bukfile"
|
|
10
|
+
def install
|
|
11
|
+
# Parse in the Bukfile
|
|
12
|
+
bukfile = section 'Parsing Bukfile' do
|
|
13
|
+
Bukin::Bukfile.from_file
|
|
20
14
|
end
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
say 'Parsing Bukfile... '
|
|
25
|
-
contents = File.read(Bukin::Bukfile::NAME)
|
|
26
|
-
bukfile = Bukin::Bukfile.new
|
|
27
|
-
bukfile.instance_eval(contents)
|
|
28
|
-
say 'Done', :green
|
|
16
|
+
server = bukfile.server_info
|
|
17
|
+
plugins = bukfile.plugins_info
|
|
29
18
|
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
# Grab information from the various providers
|
|
20
|
+
bukkit_dl = Bukin::BukkitDl.new
|
|
21
|
+
bukget = Bukin::Bukget.new
|
|
32
22
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
server[:download_build] = @bukkit_dl.resolve_build(
|
|
39
|
-
server[:name],
|
|
40
|
-
server[:version]
|
|
41
|
-
)
|
|
42
|
-
say 'Done', :green
|
|
23
|
+
section "Fetching information from #{bukkit_dl.url}" do
|
|
24
|
+
info = bukkit_dl.info(server[:name], server[:version])
|
|
25
|
+
server[:download_version] = info['version']
|
|
26
|
+
server[:download_build] = "build-#{info['build_number']}"
|
|
27
|
+
end
|
|
43
28
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
end
|
|
52
|
-
say 'Done', :green
|
|
29
|
+
section "Fetching information from #{bukget.url}" do
|
|
30
|
+
plugins.each do |plugin|
|
|
31
|
+
info = bukget.info(plugin[:name], plugin[:version], server[:name])
|
|
32
|
+
plugin[:download_version] = info['versions'][0]['version']
|
|
33
|
+
end
|
|
34
|
+
end
|
|
53
35
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
save_download(data, file_name, SERVER_PATH)
|
|
57
|
-
@lockfile.set_server(server[:name], server[:download_build], file_name)
|
|
58
|
-
say 'Done', :green
|
|
36
|
+
# Download and install server and plugins
|
|
37
|
+
installer = Bukin::Installer.new(Dir.pwd, true)
|
|
59
38
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
data, file_name = @bukget.download(plugin[:name], plugin[:download_version], server[:name])
|
|
63
|
-
save_download(data, file_name, PLUGINS_PATH)
|
|
64
|
-
@lockfile.add_plugin(plugin[:name], plugin[:download_version], file_name)
|
|
65
|
-
say 'Done', :green
|
|
66
|
-
end
|
|
67
|
-
rescue Exception => ex
|
|
68
|
-
say('Error', :red)
|
|
69
|
-
raise ex
|
|
39
|
+
section "Downloading #{server[:name]} (#{server[:download_version]})" do
|
|
40
|
+
installer.install(:server, bukkit_dl, server[:name], server[:download_build])
|
|
70
41
|
end
|
|
71
42
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
43
|
+
plugins.each do |plugin|
|
|
44
|
+
section "Downloading #{plugin[:name]} (#{plugin[:download_version]})" do
|
|
45
|
+
installer.install(:plugin, bukget, plugin[:name], plugin[:download_version], server[:name])
|
|
46
|
+
end
|
|
76
47
|
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def help(*)
|
|
51
|
+
shell.say "Bukin is a plugin and server package manager for Minecraft."
|
|
52
|
+
shell.say
|
|
53
|
+
super
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
def section(message)
|
|
58
|
+
say "#{message}... "
|
|
59
|
+
value = yield
|
|
60
|
+
say 'Done', :green
|
|
61
|
+
value
|
|
62
|
+
rescue => ex
|
|
63
|
+
say 'Error', :red
|
|
64
|
+
raise ex
|
|
65
|
+
end
|
|
77
66
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'socket'
|
|
2
|
+
|
|
3
|
+
module Bukin
|
|
4
|
+
def self.with_friendly_errors
|
|
5
|
+
yield
|
|
6
|
+
rescue SocketError => error
|
|
7
|
+
abort "#{error.message}\nCheck that you have a stable connection and the service is online"
|
|
8
|
+
rescue Errno::ENOENT => error
|
|
9
|
+
abort error.message
|
|
10
|
+
rescue Interrupt
|
|
11
|
+
abort ''
|
|
12
|
+
rescue Exception => error
|
|
13
|
+
puts %Q(
|
|
14
|
+
Oops, Bukin just crashed. Please report this at http://bit.ly/bukin-issues
|
|
15
|
+
Be sure to include as much information as possible such as your Bukfile,
|
|
16
|
+
Bukfile.lock and the stack trace below.
|
|
17
|
+
)
|
|
18
|
+
raise error
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'bukin/lockfile'
|
|
2
|
+
|
|
3
|
+
class Bukin::Installer
|
|
4
|
+
|
|
5
|
+
def initialize(path, use_lockfile = false)
|
|
6
|
+
if use_lockfile
|
|
7
|
+
@lockfile = Bukin::Lockfile.new
|
|
8
|
+
end
|
|
9
|
+
@paths = { server: path, plugin: "#{path}/plugins" }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def install(type, provider, *args)
|
|
13
|
+
unless @paths.keys.include?(type)
|
|
14
|
+
raise(ArgumentError, "You must specify one of the following types to install: #{@paths.keys.to_s}")
|
|
15
|
+
end
|
|
16
|
+
data, file_name = provider.download(*args)
|
|
17
|
+
save_download(data, file_name, @paths[type])
|
|
18
|
+
if @lockfile
|
|
19
|
+
@lockfile.add(type, args[0], args[1], file_name)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/bukin/lockfile.rb
CHANGED
|
@@ -4,52 +4,63 @@ LOCK_FILE = 'Bukfile.lock'
|
|
|
4
4
|
|
|
5
5
|
class Bukin::Lockfile
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
end
|
|
7
|
+
def initialize(*)
|
|
8
|
+
if File.exist?(LOCK_FILE)
|
|
9
|
+
@lockfile = YAML::load_file(LOCK_FILE)
|
|
10
|
+
else
|
|
11
|
+
@lockfile = {
|
|
12
|
+
'server' => {},
|
|
13
|
+
'plugins' => {}
|
|
14
|
+
}
|
|
16
15
|
end
|
|
16
|
+
end
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
def set_server(name, version, file)
|
|
19
|
+
self.server = {
|
|
20
|
+
'name' => name,
|
|
21
|
+
'version' => version,
|
|
22
|
+
'file' => file
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
def add_plugin(name, version, *files)
|
|
27
|
+
self.plugins[name] = {
|
|
28
|
+
'version' => version,
|
|
29
|
+
'files' => files
|
|
30
|
+
}
|
|
31
|
+
save
|
|
32
|
+
end
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
def add(type, *args)
|
|
35
|
+
case type
|
|
36
|
+
when :server
|
|
37
|
+
set_server(*args)
|
|
38
|
+
when :plugin
|
|
39
|
+
add_plugin(*args)
|
|
40
|
+
else
|
|
41
|
+
raise(ArgumentError, "You must specify :server or :plugin as the type when adding to a lock file")
|
|
37
42
|
end
|
|
43
|
+
end
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
def remove_plugin(name)
|
|
46
|
+
plugins.delete(name)
|
|
47
|
+
save
|
|
48
|
+
end
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
def plugins
|
|
51
|
+
@lockfile['plugins']
|
|
52
|
+
end
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
end
|
|
54
|
+
def server
|
|
55
|
+
@lockfile['server']
|
|
56
|
+
end
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
def server=(value)
|
|
59
|
+
@lockfile['server'] = value
|
|
60
|
+
save
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def save
|
|
64
|
+
File.open(LOCK_FILE, "w") {|file| file.write @lockfile.to_yaml}
|
|
65
|
+
end
|
|
55
66
|
end
|
|
@@ -3,28 +3,26 @@ require 'json'
|
|
|
3
3
|
|
|
4
4
|
# BukGet api
|
|
5
5
|
# Docs: http://bukget.org/pages/docs/API3.html
|
|
6
|
-
BUKGET_API = "http://api.bukget.org/3"
|
|
7
|
-
|
|
8
6
|
class Bukin::Bukget
|
|
9
|
-
|
|
7
|
+
attr_reader :url
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
def initialize(url = 'http://api.bukget.org')
|
|
10
|
+
@url = url
|
|
11
|
+
end
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
download_file(url, true)
|
|
19
|
-
end
|
|
13
|
+
def api_url
|
|
14
|
+
"#{url}/3"
|
|
15
|
+
end
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
def download(name, version, server)
|
|
18
|
+
server = 'bukkit' if server == 'craftbukkit'
|
|
19
|
+
url = "#{api_url}/plugins/#{server}/#{name}/#{version}/download"
|
|
20
|
+
download_file(url, true)
|
|
21
|
+
end
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
def info(name, version, server)
|
|
24
|
+
server = 'bukkit' if server == 'craftbukkit'
|
|
25
|
+
url = "#{api_url}/plugins/#{server}/#{name}/#{version}"
|
|
26
|
+
JSON.parse(open(url).read)
|
|
27
|
+
end
|
|
30
28
|
end
|
|
@@ -1,36 +1,30 @@
|
|
|
1
1
|
require 'bukin/utils'
|
|
2
2
|
require 'json'
|
|
3
3
|
|
|
4
|
-
# Base url used for bukkit downloads
|
|
5
|
-
BUKKIT_DL_BASE = "http://dl.bukkit.org"
|
|
6
|
-
|
|
7
4
|
# Bukkit download api
|
|
8
5
|
# Docs: http://dl.bukkit.org/about/
|
|
9
|
-
BUKKIT_DL_API = "#{BUKKIT_DL_BASE}/api/1.0/downloads"
|
|
10
|
-
|
|
11
|
-
|
|
12
6
|
class Bukin::BukkitDl
|
|
13
|
-
|
|
7
|
+
attr_reader :url
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
def initialize(url = 'http://dl.bukkit.org')
|
|
10
|
+
@url = url
|
|
11
|
+
end
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
13
|
+
def api_url
|
|
14
|
+
"#{url}/api/1.0/downloads"
|
|
15
|
+
end
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
17
|
+
def download_url
|
|
18
|
+
url
|
|
19
|
+
end
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
def download(name, version)
|
|
22
|
+
url = download_url + info(name, version)['file']['url']
|
|
23
|
+
download_file(url)
|
|
24
|
+
end
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
def info(name, version)
|
|
27
|
+
url = "#{api_url}/projects/#{name}/view/#{version}/"
|
|
28
|
+
JSON.parse(open(url).read)
|
|
29
|
+
end
|
|
36
30
|
end
|
data/lib/bukin/utils.rb
CHANGED
|
@@ -1,52 +1,51 @@
|
|
|
1
1
|
require 'open-uri'
|
|
2
2
|
|
|
3
3
|
def save_download(data, name, path)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
FileUtils.mkdir_p(path)
|
|
5
|
+
open("#{path}/#{name}", "wb") do |file|
|
|
6
|
+
file.print data
|
|
7
|
+
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def download_file(url, content_disposition = false)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
open(url) do |download|
|
|
12
|
+
file_name = if content_disposition
|
|
13
|
+
download.meta['content-disposition']
|
|
14
|
+
.match(/filename=(\"?)(.+)\1/)[2]
|
|
15
|
+
.force_encoding("UTF-8")
|
|
16
|
+
else
|
|
17
|
+
File.basename(url)
|
|
18
|
+
end
|
|
19
|
+
data = download.read
|
|
20
|
+
return data, file_name
|
|
21
|
+
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
def install_plugin(name, version, server)
|
|
26
|
-
|
|
25
|
+
return false if @lockfile.plugins.has_key?(name)
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
download_version = @bukget.resolve_version(name, version, server)
|
|
28
|
+
data, file_name = @bukget.download(name, download_version, server)
|
|
29
|
+
save_download(data, file_name, PLUGINS_PATH)
|
|
30
|
+
@lockfile.add_plugin(name, download_version, file_name)
|
|
31
|
+
return file_name, download_version
|
|
33
32
|
end
|
|
34
33
|
|
|
35
34
|
def pretty_version(version)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
case version
|
|
36
|
+
when 'latest'
|
|
37
|
+
"the latest version"
|
|
38
|
+
when 'latest-rb'
|
|
39
|
+
"the latest recommended build"
|
|
40
|
+
when 'latest-beta'
|
|
41
|
+
"the latest beta build"
|
|
42
|
+
when 'latest-dev'
|
|
43
|
+
"the latest development build"
|
|
44
|
+
when /^git-(.*)$/
|
|
45
|
+
"git commit #{$1}"
|
|
46
|
+
when /^build-(.*)$/
|
|
47
|
+
"build \##{$1}"
|
|
48
|
+
else
|
|
49
|
+
"version #{version}"
|
|
50
|
+
end
|
|
52
51
|
end
|