gsd-cli 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1af1b9f1e06257b793b423b63114a3bab02cd955f4e55faaeb2a4a79f42cf2e7
4
+ data.tar.gz: 2a84ab555e3ee15fe6be3e8667a56fe4fe6bea640641fa002f9543db275b97bc
5
+ SHA512:
6
+ metadata.gz: fb952a50c5307b0793139bcfa1cbb076c65054418cbf487b9884fd5dc3b7763baea3ea371364853645661ffa8576b5af0e5763e0b564cddd29132aa20525665c
7
+ data.tar.gz: 57e13347822f92779403c24dc3d9059321724919e158fbfc84cccdc5c51fbd6a9fc6cba49db9392fe0c36436f5d295e2f1a037d6d09f9ae24ef19f69613e9f1b
data/bin/gsd-cli ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "cli"
data/lib/cli.rb ADDED
@@ -0,0 +1,117 @@
1
+ require "commander/import"
2
+ require "game_template"
3
+ require "game_servers/gmod"
4
+ require "game_servers/rust"
5
+ require "game_servers/terraria"
6
+ require "game_servers/starbound"
7
+ require "game_servers/seven_days"
8
+ require "game_servers/team_fortress"
9
+ require "game_servers/minecraft_ftb"
10
+ require "game_servers/minecraft_spigot"
11
+ require "game_servers/ace_of_spades"
12
+
13
+ def userdata
14
+ {
15
+ "rust" => Rust.new,
16
+ "sdtd" => SevenDays.new,
17
+ "gmod" => GarrysMod.new,
18
+ "aos" => AceOfSpades.new,
19
+ "tf2" => TeamFortress.new,
20
+ "ftb" => MinecraftFtb.new,
21
+ "terraria" => Terraria.new,
22
+ "starbound" => Starbound.new,
23
+ "minecraft" => MinecraftSpigot.new
24
+ }
25
+ end
26
+
27
+ @games = userdata
28
+
29
+ program :name, "gsc-cli"
30
+ program :version, "0.1.0"
31
+ program :description, "A cli tool to manage dedicated game servers on Linux"
32
+
33
+ command :install do |c|
34
+ c.syntax = "gsd install [args] [options]"
35
+ c.summary = "Install and deploy a dedicated game server as a daemon."
36
+ c.description = "Installs and deploy a dedicated game server as a daemon (systemd unit)."
37
+ c.option "--path STRING", String, "Path that the game server will be installed to."
38
+ c.option "--steamuser STRING", String, "Steam user account required to install certain games."
39
+ c.option "--steampassword STRING", String, "Steam account password for installing certain games."
40
+ c.action do |args, options|
41
+ GameTemplate.new(@games[args.first()], options.path).install(options.steamuser, options.steampassword)
42
+ end
43
+ end
44
+
45
+ command :run do |c|
46
+ c.syntax = "gsd run [args]"
47
+ c.summary = "Run an installed dedicated game server as a new process."
48
+ c.description = "Runs an installed dedicated game server as a new process. This command is used by the daemon and is not designed to be run manually."
49
+ c.option "--path STRING", String, "Path that the game server will be installed to."
50
+ c.action do |args, options|
51
+ GameTemplate.new(@games[args.first()], options.path).run()
52
+ end
53
+ end
54
+
55
+ command :update do |c|
56
+ c.syntax = "gsd install [args] [options]"
57
+ c.summary = "Updates an installed dedicated game server."
58
+ c.description = "Updates an installed dedicated game server."
59
+ c.option "--path STRING", String, "Path that the game server will be update to."
60
+ c.action do |args, options|
61
+ GameTemplate.new(@games[args.first()], options.path).update()
62
+ end
63
+ end
64
+
65
+ command :start do |c|
66
+ c.syntax = "gsd start [args]"
67
+ c.summary = "Start a installed dedicated game server."
68
+ c.description = "Starts a dedicated game server daemon that has already been installed to the system."
69
+ c.action do |args|
70
+ GameTemplate.new(@games[args.first()]).start()
71
+ end
72
+ end
73
+
74
+ command :restart do |c|
75
+ c.syntax = "gsd restart [args]"
76
+ c.summary = "Restart a installed dedicated game server."
77
+ c.description = "Restarts a dedicated game server daemon that has already been installed to the system."
78
+ c.action do |args|
79
+ GameTemplate.new(@games[args.first()]).restart()
80
+ end
81
+ end
82
+
83
+ command :status do |c|
84
+ c.syntax = "gsd status [args]"
85
+ c.summary = "Display the status of a installed dedicated game server."
86
+ c.description = "Requests and returns the status of a installed dedicated game server from systemd."
87
+ c.action do |args|
88
+ GameTemplate.new(@games[args.first()]).status()
89
+ end
90
+ end
91
+
92
+ command :stop do |c|
93
+ c.syntax = "gsd stop [args]"
94
+ c.summary = "Stop running dedicated game server."
95
+ c.description = "Stops a running dedicated game server daemon."
96
+ c.action do |args|
97
+ GameTemplate.new(@games[args.first()]).stop()
98
+ end
99
+ end
100
+
101
+ command :enable do |c|
102
+ c.syntax = "gsd enable [args]"
103
+ c.summary = "Force a dedicated game server daemon to launch at system start."
104
+ c.description = "Enables a dedicated game server daemon to start when the system starts."
105
+ c.action do |args|
106
+ GameTemplate.new(@games[args.first()]).stop()
107
+ end
108
+ end
109
+
110
+ command :disable do |c|
111
+ c.syntax = "gsd disable [args]"
112
+ c.summary = "Disable a dedicated game server daemon from starting at system start."
113
+ c.description = "Disables a dedicated game server daemon from starting when the system starts."
114
+ c.action do |args|
115
+ GameTemplate.new(@games[args.first()]).stop()
116
+ end
117
+ end
@@ -0,0 +1,14 @@
1
+ # A class for Feed The Beast Minecraft Server
2
+ class AceOfSpades
3
+ attr_reader :name, :app_id
4
+ def initialize
5
+ @name = "aos"
6
+ @app_id = nil
7
+ end
8
+
9
+ def launch(install_path)
10
+ end
11
+
12
+ def install_server(install_path)
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ # A module to produce resources for a Garry's Mod server
2
+ class GarrysMod
3
+ attr_reader :name, :app_id
4
+ def initialize
5
+ @name = "gmod"
6
+ @app_id = "4020"
7
+ end
8
+
9
+ def launch(install_path, map = "gm_construct", players = 16, collection_id = "1270037458")
10
+ "cd #{install_path} &&
11
+ #{install_path}/srcds_run \
12
+ -console \
13
+ -game garrysmod \
14
+ +map #{map} \
15
+ +maxplayers #{players} \
16
+ +host_workshop_collection #{collection_id} \
17
+ -condebug & \
18
+ /usr/bin/tail -f #{install_path}/garrysmod/console.log"
19
+ end
20
+
21
+ def post_install(install_path)
22
+ system("touch #{install_path}/garrysmod/console.log")
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ # A class for Feed The Beast Minecraft Server
2
+ class MinecraftFtb
3
+ attr_reader :name, :app_id
4
+ def initialize
5
+ @name = "ftb"
6
+ @app_id = nil
7
+ end
8
+
9
+ def launch(install_path)
10
+ "cd #{install_path} && /bin/bash #{install_path}/ServerStart.sh"
11
+ end
12
+
13
+ def install_server(install_path)
14
+ system("wget https://media.forgecdn.net/files/2658/240/FTBRevelationServer_2.7.0.zip -O /tmp/server.zip")
15
+ system("mkdir #{install_path}")
16
+ system("unzip /tmp/server.zip -d#{install_path}")
17
+ system("chmod +x #{install_path}/ServerStart.sh")
18
+ system("chmod +x #{install_path}/FTBInstall.sh")
19
+ system("/bin/bash #{install_path}/FTBInstall.sh")
20
+ system("rm #{install_path}/eula.txt")
21
+ system("echo eula=true > #{install_path}/eula.txt")
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require "open-uri"
2
+ require "fileutils"
3
+
4
+ # A class for Feed The Beast Minecraft Server
5
+ class MinecraftSpigot
6
+ attr_reader :name, :app_id
7
+ def initialize
8
+ @name = "minecraft"
9
+ @app_id = nil
10
+ end
11
+
12
+ def launch(install_path, version = "1.13.2")
13
+ "cd #{install_path} && java -Xms1G -Xmx2G -jar spigot-#{version}.jar --noconsole"
14
+ end
15
+
16
+ def install_server(install_path, version = "1.13.2")
17
+ FileUtils.mkdir_p(install_path)
18
+ File.open("#{install_path}/BuildTools.jar", "wb") do |file|
19
+ file.write(open("https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar").read())
20
+ end
21
+ system("cd #{install_path} && java -jar #{install_path}/BuildTools.jar --rev #{version}")
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # Create a Rust server
2
+ class Rust
3
+ attr_reader :name, :app_id
4
+ def initialize
5
+ @name = "rust"
6
+ @app_id = "258550"
7
+ end
8
+
9
+ def launch(install_path, password = "_", ip = "0.0.0.0", port = "28015")
10
+ "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:#{install_path}/RustDedicated_Data/Plugins/x86_64 &&
11
+ cd #{install_path} &&
12
+ ./RustDedicated +server.ip #{ip} +server.port #{port} +server.identity rust +rcon.web 1 \
13
+ +rcon.ip #{ip} \
14
+ +rcon.port 28016 \
15
+ +rcon.password #{password}"
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ # Create a 7 Days to Die server
2
+ class SevenDays
3
+ attr_reader :name, :app_id
4
+ def initialize
5
+ @name = "sdtd"
6
+ @app_id = "294420"
7
+ end
8
+
9
+ def launch(install_path)
10
+ "cd #{install_path} &&
11
+ export LD_LIBRARY_PATH=. &&
12
+ #{install_path}/7DaysToDieServer.x86_64 \
13
+ -logfile #{install_path}/server.log \
14
+ -quit \
15
+ -batchmode \
16
+ -nographics \
17
+ -dedicated \
18
+ -configfile=#{install_path}/serverconfig.xml & \
19
+ /usr/bin/tail -f #{install_path}/server.log"
20
+ end
21
+
22
+ def post_install(install_path)
23
+ system("touch #{install_path}/server.log") # TODO: This won't scale
24
+ system("rm #{install_path}/serverconfig.xml")
25
+ system("cp #{Dir.pwd}/conf/sdtd.xml #{install_path}/serverconfig.xml")
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ # A module to produce resources for a Starbound server
2
+ class Starbound
3
+ attr_reader :name, :app_id
4
+ def initialize
5
+ @name = "starbound"
6
+ @app_id = "533830"
7
+ end
8
+
9
+ def launch(install_path)
10
+ "cd #{install_path}/linux &&
11
+ #{install_path}/linux/starbound_server"
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ # A module to produce resources for a Team Fortress 2 server
2
+ class TeamFortress
3
+ attr_reader :name, :app_id
4
+ def initialize
5
+ @name = "tf2"
6
+ @app_id = "232250"
7
+ end
8
+
9
+ def launch(install_path, map = "ctf_2fort", players = 24)
10
+ "cd #{install_path} &&
11
+ #{install_path}/srcds_run \
12
+ -console \
13
+ -game tf \
14
+ +sv_pure 1 \
15
+ +map #{map} \
16
+ +maxplayers #{players} \
17
+ -condebug & \
18
+ /usr/bin/tail -f #{install_path}/tf/console.log"
19
+ end
20
+
21
+ def post_install(install_path)
22
+ system("touch #{install_path}/tf/console.log")
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ # A class for Feed The Beast Minecraft Server
2
+ class Terraria
3
+ attr_reader :name, :app_id
4
+ def initialize
5
+ @name = "terraria"
6
+ @app_id = nil
7
+ end
8
+
9
+ def launch(install_path)
10
+ end
11
+
12
+ def install_server(install_path)
13
+ end
14
+ end
@@ -0,0 +1,109 @@
1
+ require "colorize"
2
+
3
+ # Create a Rust server
4
+ class GameTemplate
5
+ def initialize(game, path = nil)
6
+ @game = game
7
+ @install_path = get_install_path(path)
8
+ @file_path = "/tmp/#{@game.name}.service"
9
+ end
10
+
11
+ def start
12
+ system("sudo -p 'sudo password: ' systemctl start #{@game.name}")
13
+ end
14
+
15
+ def restart
16
+ system("sudo -p 'sudo password: ' systemctl restart #{@game.name}")
17
+ end
18
+
19
+ def status
20
+ system("sudo -p 'sudo password: ' systemctl status #{@game.name}")
21
+ end
22
+
23
+ def stop
24
+ system("sudo -p 'sudo password: ' systemctl stop #{@game.name}")
25
+ end
26
+
27
+ def enable
28
+ system("sudo -p 'sudo password: ' systemctl enable #{@game.name}")
29
+ end
30
+
31
+ def disable
32
+ system("sudo -p 'sudo password: ' systemctl disable #{@game.name}")
33
+ end
34
+
35
+ def run
36
+ exec(@game.launch(@install_path))
37
+ end
38
+
39
+ def install(steamuser, steampassword)
40
+ puts "Beginning installation process. This may take a while..."
41
+ ensure_delete_unit_file()
42
+ if @game.app_id.nil?
43
+ @game.install_server(@install_path)
44
+ else
45
+ install_steam_server(steamuser, steampassword)
46
+ end
47
+ create_unit_file()
48
+ system("sudo -p 'sudo password: ' cp -f #{@file_path} /etc/systemd/system/#{@game.name}.service")
49
+ puts "Server installation & deployment complete!".green
50
+ end
51
+
52
+ # Generic cli-facing update function
53
+ # for updating installed dedicated game servers
54
+ def update
55
+ if @game.app_id.nil?
56
+ puts "Non-Steam games not supported."
57
+ else
58
+ install_steam_server()
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ # Installs or Updates a dedicated game server via Steamcmd
65
+ def install_steam_server(steamuser = nil, steampassword = nil)
66
+ login = if steamuser.nil?
67
+ "+login anonymous"
68
+ else
69
+ "+login #{steamuser} #{steampassword}"
70
+ end
71
+ system("/usr/games/steamcmd +login anonymous +quit")
72
+ system("/usr/games/steamcmd #{login} +force_install_dir #{@install_path} +app_update #{@game.app_id} validate +quit")
73
+ @game.post_install(@install_path) if defined? @game.post_install
74
+ end
75
+
76
+ def get_install_path(path)
77
+ install_path = if path.nil?
78
+ # puts "Install path not defined: installing to /tmp/#{@game.name}".yellow
79
+ "/tmp/#{@game.name}"
80
+ else
81
+ path
82
+ end
83
+ install_path
84
+ end
85
+
86
+ def ensure_delete_unit_file
87
+ File.delete(@file_path) if File.file?(@file_path)
88
+ end
89
+
90
+ def create_unit_file
91
+ out_file = File.new(@file_path, "w")
92
+ out_file.puts(unit_file_contents()) # TODO: Pass in map with config
93
+ out_file.close()
94
+ end
95
+
96
+ def unit_file_contents
97
+ "[Unit]
98
+ After=network.target
99
+ Description=#{@desc}
100
+ [Install]
101
+ WantedBy=default.target
102
+ [Service]
103
+ LimitNPROC=infinity
104
+ WorkingDirectory=#{Dir.pwd}
105
+ Type=simple
106
+ User=#{`whoami`}
107
+ ExecStart=#{Dir.pwd}/bin/gsd run #{@game.name} --path #{@install_path}"
108
+ end
109
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gsd-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Egee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple cli for launching dedicated game servers
14
+ email: brian@egee.io
15
+ executables:
16
+ - gsd-cli
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/gsd-cli
21
+ - lib/cli.rb
22
+ - lib/game_servers/ace_of_spades.rb
23
+ - lib/game_servers/gmod.rb
24
+ - lib/game_servers/minecraft_ftb.rb
25
+ - lib/game_servers/minecraft_spigot.rb
26
+ - lib/game_servers/rust.rb
27
+ - lib/game_servers/seven_days.rb
28
+ - lib/game_servers/starbound.rb
29
+ - lib/game_servers/team_fortress.rb
30
+ - lib/game_servers/terraria.rb
31
+ - lib/game_template.rb
32
+ homepage: https://github.com/Egeeio/gsd-cli
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.0.2
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: A cli for launching servers
55
+ test_files: []