Skip to content

Commit

Permalink
Initial Import
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Fitzgerald committed Jun 14, 2012
0 parents commit 2773dbe
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

## v0.1
* Initial release
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2012, Greg Fitzgerald
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
Description
===========

Installs vanilla Minecraft (http://www.minecraft.net) server.

Requirements
============

Requires the [java](https://github.com/opscode-cookbooks/java) cookbook which is defined in the recipe.

Platform
--------

* Debian, Ubuntu

Attributes
==========
See `attributes/default.rb` for default values.

`default['minecraft']['user']`
`default['minecraft']['install_dir'] `

`default['minecraft']['banned-ips'] `
`default['minecraft']['banned-players']`
`default['minecraft']['white-list-users']`
`default['minecraft']['ops']`

`default['minecraft']['allow-nether']`
`default['minecraft']['level-name']`
`default['minecraft']['enable-query']`
`default['minecraft']['allow-flight']`
`default['minecraft']['server-port']`
`default['minecraft']['level-type']`
`default['minecraft']['enable_rcon']`
`default['minecraft']['level-seed']`
`default['minecraft']['server-ip']`
`default['minecraft']['max-build-height']`
`default['minecraft']['spawn-npcs']`
`default['minecraft']['white-list']`
`default['minecraft']['spawn-animals'] `
`default['minecraft']['online-mode']`
`default['minecraft']['pvp']`
`default['minecraft']['difficulty']`
`default['minecraft']['gamemode']`
`default['minecraft']['max-players']`
`default['minecraft']['spawn-monsters']`
`default['minecraft']['generate-structures']`
`default['minecraft']['view-distance']`
`default['minecraft']['motd']`

Usage
=====

Include the `minecraft` recipe and modify your run list and set any attributes
you would like changed.

run_list [
"recipe[minecraft]"
]
"minecraft":{
"motd": "Welcome all griefers!"
"max-players": 9001
"ops": ["nappa", "goku"]
}


Recipes
=======

default
-------

Include the default recipe into the runlist to install `minecraft` server.
Configuration files are prepopulated based on values in attributes. I will keep
the defaults in sync with upstream.

TODO
====

* Proper init scripts (currently missing)
* More attributes
- min/max ram
- group
- custom download url, no one at mojang knows what a version number is..
- checksums?
* Support more distros & BSD
* Plugin support once 1.3 is released?

License and Author

==================
Copyright 2012, Greg Fitzgerald
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

27 changes: 27 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env rake

desc "Runs foodcritic linter"
task :foodcritic do
if Gem::Version.new("1.9.2") <= Gem::Version.new(RUBY_VERSION.dup)
sandbox = File.join(File.dirname(__FILE__), %w{tmp foodcritic cookbook})
prepare_foodcritic_sandbox(sandbox)

sh "foodcritic --epic-fail any #{File.dirname(sandbox)}"
else
puts "WARN: foodcritic run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2."
end
end

task :default => 'foodcritic'

private

def prepare_foodcritic_sandbox(sandbox)
files = %w{*.md *.rb attributes definitions files providers
recipes resources templates}

rm_rf sandbox
mkdir_p sandbox
cp_r Dir.glob("{#{files.join(',')}}"), sandbox
puts "\n\n"
end
30 changes: 30 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
default['minecraft']['user'] = 'minecraft'
default['minecraft']['install_dir'] = '/srv/minecraft'

default['minecraft']['banned-ips'] = []
default['minecraft']['banned-players'] = []
default['minecraft']['white-list-users'] = []
default['minecraft']['ops'] = []

default['minecraft']['allow-nether'] = true
default['minecraft']['level-name'] = 'world'
default['minecraft']['enable-query'] = false
default['minecraft']['allow-flight'] = false
default['minecraft']['server-port'] = 25565
default['minecraft']['level-type'] = 'DEFAULT'
default['minecraft']['enable_rcon'] = false
default['minecraft']['level-seed'] = ''
default['minecraft']['server-ip'] = ''
default['minecraft']['max-build-height'] = 256
default['minecraft']['spawn-npcs'] = true
default['minecraft']['white-list'] = false
default['minecraft']['spawn-animals'] = true
default['minecraft']['online-mode'] = true
default['minecraft']['pvp'] = true
default['minecraft']['difficulty'] = 1
default['minecraft']['gamemode'] = 0
default['minecraft']['max-players'] = 20
default['minecraft']['spawn-monsters'] = true
default['minecraft']['generate-structures'] = true
default['minecraft']['view-distance'] = 10
default['minecraft']['motd'] = 'A Minecraft Server'
14 changes: 14 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
maintainer "Greg Fitzgerald"
maintainer_email "[email protected]"
license "MIT"
description "Installs/Configures minecraft server"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.0.1"

recipe "minecraft", "Installs and configures minecraft server."

depends 'java'

%w { debian ubuntu }.each do |os|
supports os
end
86 changes: 86 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#
# Cookbook Name:: minecraft
# Recipe:: default
#
# Copyright 2012, Greg Fitzgerald
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

# Only focusing on Linux and BSD suppport. Patches are welcome for OSX and Windows.

include_recipe 'java::default'

minecraft_downloads = { :linux => "https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar" }

tmpdir = Chef::Config[:file_cache_path]
minecraft_jar = "#{tmpdir}/minecraft_server.jar"
minecraft_platform = case node['os']
when "linux"
:linux
else
puts "Only supports linux right now, patches welcome."
end

if node['minecraft']['source']
minecraft_source = node['minecraft']['source']
else
minecraft_source = minecraft_downloads[minecraft_platform]
end

user node['minecraft']['user'] do
system true
shell "/bin/false"
home node['minecraft']['install_dir']
action :create
end

remote_file minecraft_jar do
source minecraft_source
owner node['minecraft']['user']
group node['minecraft']['user']
mode "0644"
backup 5
end

directory node['minecraft']['install_dir'] do
owner node['minecraft']['user']
group node['minecraft']['user']
mode '0755'
action :create
recursive true
end

execute "copy-minecraft_server.jar" do
cwd node['minecraft']['install_dir']
command "cp -p #{minecraft_jar} ."
creates "#{node['minecraft']['install_dir']}/minecraft_server.jar"
end

%w[ops.txt server.properties banned-ips.txt
banned-players.txt white-list.txt].each do |template|
template "#{node['minecraft']['install_dir']}/#{template}" do
source "#{template}.erb"
owner node['minecraft']['user']
group node['minecraft']['user']
mode 0644
action :create
end
end
6 changes: 6 additions & 0 deletions templates/default/banned-ips.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if node['minecraft']['banned-ips'].length > 0 -%>
<% node['minecraft']['banned-ips'].each do |device| -%>
<%= "#{node['minecraft']['banned-ips']}" %>
<% end -%>
<% end -%>

6 changes: 6 additions & 0 deletions templates/default/banned-players.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if node['minecraft']['banned-players'].length > 0 -%>
<% node['minecraft']['banned-players'].each do |device| -%>
<%= "#{node['minecraft']['banned-players']}" %>
<% end -%>
<% end -%>

6 changes: 6 additions & 0 deletions templates/default/ops.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if node['minecraft']['ops'].length > 0 -%>
<% node['minecraft']['ops'].each do |device| -%>
<%= "#{node['minecraft']['ops']}" %>
<% end -%>
<% end -%>

24 changes: 24 additions & 0 deletions templates/default/server.properties.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#Minecraft server properties
#<%= Time.now.strftime("%a %b %T %Z %Y") %>
allow-nether=<%= "#{node['minecraft']['allow-nether']}" %>
level-name=<%= "#{node['minecraft']['level-name']}" %>
enable-query=<%= "#{node['minecraft']['enable-query']}" %>
allow-flight=<%= "#{node['minecraft']['allow-flight']}" %>
server-port=<%= "#{node['minecraft']['server-port']}" %>
level-type=<%= "#{node['minecraft']['level-type']}" %>
enable-rcon=<%= "#{node['minecraft']['rcon']}" %>
level-seed=<%= "#{node['minecraft']['level-seed']}" %>
server-ip=<%= "#{node['minecraft']['server-ip']}" %>
max-build-height=<%= "#{node['minecraft']['max-build-height']}" %>
spawn-npcs=<%= "#{node['minecraft']['spawn-npcs']}" %>
white-list=<%= "#{node['minecraft']['white-list']}" %>
spawn-animals=<%= "#{node['minecraft']['spawn-animals']}" %>
online-mode=<%= "#{node['minecraft']['online-mode']}" %>
pvp=<%= "#{node['minecraft']['pvp']}" %>
difficulty=<%= "#{node['minecraft']['difficulty']}" %>
gamemode=<%= "#{node['minecraft']['gamemode']}" %>
max-players=<%= "#{node['minecraft']['max-players']}" %>
spawn-monsters=<%= "#{node['minecraft']['spawn-monsters']}" %>
generate-structures=<%= "#{node['minecraft']['generate-structures']}" %>
view-distance=<%= "#{node['minecraft']['view-distance']}" %>
motd=<%= "#{node['minecraft']['motd']}" %>
6 changes: 6 additions & 0 deletions templates/default/white-list.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if node['minecraft']['white-list-users'].length > 0 -%>
<% node['minecraft']['white-list-users'].each do |device| -%>
<%= "#{node['minecraft']['white-list-users']}" %>
<% end -%>
<% end -%>

4 changes: 4 additions & 0 deletions test/support/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem 'rake'
gem 'foodcritic'

0 comments on commit 2773dbe

Please sign in to comment.