Class: Manlycraft::Command::Init

Inherits:
Base
  • Object
show all
Defined in:
lib/manlycraft/command/init.rb

Instance Attribute Summary

Attributes inherited from Base

#args

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Manlycraft::Command::Base

Instance Method Details

#create_server_directoryObject



28
29
30
31
# File 'lib/manlycraft/command/init.rb', line 28

def create_server_directory
  FileUtils.mkdir_p(Manlycraft::Config.server_directory)
  FileUtils.chown_R(@username, @username, Manlycraft::Config.server_directory)
end

#create_user(username = "minecraft") ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/manlycraft/command/init.rb', line 13

def create_user(username="minecraft")
  @username = username

  if RUBY_PLATFORM.match /darwin/
    `dscl . -create /Users/#{username}`
    `dscl . -create /Users/#{username} UserShell /bin/bash`
    `dscl . -create /Users/#{username} RealName "Lucius Q. User"`
    `dscl . -create /Users/#{username} UniqueID "1010"`
    `dscl . -create /Users/#{username} PrimaryGroupID 80`
    `dscl . -create /Users/#{username} NFSHomeDirectory /Users/#{username}`
  elsif RUBY_PLATFORM.match /linux/
    `sudo adduser --system --no-create-home --home /srv/minecraft-server #{username}`
  end
end

#download_minecraft_jarObject



33
34
35
# File 'lib/manlycraft/command/init.rb', line 33

def download_minecraft_jar
  `sudo -u minecraft wget -P #{Manlycraft::Config.server_directory} https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar`
end

#runObject



6
7
8
9
10
11
# File 'lib/manlycraft/command/init.rb', line 6

def run
  create_user
  create_server_directory
  download_minecraft_jar
  change_permissions
end