sbcp 0.1.4 → 0.2.3
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.
- checksums.yaml +4 -4
- data/README.md +43 -18
- data/bin/sbcp +30 -621
- data/config.yml +3 -1
- data/lib/sbcp.rb +265 -33
- data/lib/sbcp/backup.rb +27 -7
- data/lib/sbcp/config.rb +229 -0
- data/lib/sbcp/daemon.rb +37 -73
- data/lib/sbcp/help.rb +27 -0
- data/lib/sbcp/logs.rb +16 -0
- data/lib/sbcp/panel.rb +44 -0
- data/lib/sbcp/parser.rb +110 -2
- data/lib/sbcp/rcon.rb +41 -0
- data/lib/sbcp/setup.rb +193 -0
- data/lib/sbcp/starbound.rb +45 -21
- data/lib/sbcp/version.rb +17 -1
- data/sbcp.gemspec +4 -3
- metadata +43 -4
data/config.yml
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
starbound_directory: ~
|
|
3
3
|
backup_directory: ~
|
|
4
4
|
backup_history: 90
|
|
5
|
-
backup_schedule:
|
|
5
|
+
backup_schedule: hourly
|
|
6
6
|
log_directory: ~
|
|
7
7
|
log_history: 90
|
|
8
8
|
log_style: daily
|
|
9
|
+
duplicate_names: false
|
|
10
|
+
duplicate_kick_msg: Another player is currently online with your character's name.
|
|
9
11
|
restart_schedule: 4
|
data/lib/sbcp.rb
CHANGED
|
@@ -1,38 +1,270 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
# SBCP - Starbound Server Management Solution for Linux Servers
|
|
2
|
+
# Copyright (C) 2016 Kazyyk
|
|
3
|
+
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU Affero General Public License as
|
|
6
|
+
# published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
# License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
# You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
require 'highline/import'
|
|
18
|
+
require 'celluloid/current'
|
|
19
|
+
require 'time_diff'
|
|
20
|
+
require 'tempfile'
|
|
7
21
|
require 'yaml'
|
|
22
|
+
require 'pp'
|
|
8
23
|
|
|
9
|
-
|
|
24
|
+
require_relative 'sbcp/backup'
|
|
25
|
+
require_relative 'sbcp/config'
|
|
26
|
+
require_relative 'sbcp/daemon'
|
|
27
|
+
require_relative 'sbcp/rcon'
|
|
28
|
+
require_relative 'sbcp/setup'
|
|
10
29
|
|
|
11
30
|
module SBCP
|
|
12
|
-
class
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
class SBCP
|
|
32
|
+
def initialize
|
|
33
|
+
@config = YAML.load_file(File.expand_path('../../config.yml', __FILE__))
|
|
34
|
+
@commands = ['backup', 'clear', 'config', 'detach', 'exit', 'get', 'kill', 'quit', 'reboot', 'restart', 'say', 'setup', 'start', 'stop', 'help']
|
|
35
|
+
@commands_scheme = [
|
|
36
|
+
"<%= color('backup', :command) %>",
|
|
37
|
+
"<%= color('clear', :command) %>",
|
|
38
|
+
"<%= color('config', :command) %>",
|
|
39
|
+
"<%= color('detach', :command) %>",
|
|
40
|
+
"<%= color('exit', :command) %>",
|
|
41
|
+
"<%= color('get', :command) %>",
|
|
42
|
+
"<%= color('kill', :command) %>",
|
|
43
|
+
"<%= color('quit', :command) %>",
|
|
44
|
+
"<%= color('reboot', :command) %>",
|
|
45
|
+
"<%= color('restart', :command) %>",
|
|
46
|
+
"<%= color('say', :command) %>",
|
|
47
|
+
"<%= color('setup', :command) %>",
|
|
48
|
+
"<%= color('start', :command) %>",
|
|
49
|
+
"<%= color('stop', :command) %>",
|
|
50
|
+
"<%= color('help', :command) %>"
|
|
51
|
+
]
|
|
52
|
+
scheme = HighLine::ColorScheme.new do |cs|
|
|
53
|
+
cs[:headline] = [ :bold, :yellow, :on_black ]
|
|
54
|
+
cs[:subheader] = [ :cyan, :on_black ]
|
|
55
|
+
cs[:command] = [ :green, :on_black ]
|
|
56
|
+
cs[:warning] = [ :red, :on_black ]
|
|
57
|
+
cs[:failure] = [ :bold, :red, :on_black ]
|
|
58
|
+
cs[:success] = [ :bold, :green, :on_black]
|
|
59
|
+
cs[:info] = [ :bold, :blue, :on_black ]
|
|
60
|
+
cs[:help] = [ :magenta, :on_black ]
|
|
61
|
+
end
|
|
62
|
+
HighLine.color_scheme = scheme
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def repl
|
|
66
|
+
system('clear')
|
|
67
|
+
say("<%= color(' .d8888b. 888888b. .d8888b. 8888888b.', :headline) %>")
|
|
68
|
+
say("<%= color('d88P Y88b 888 \"88b d88P Y88b 888 Y88b', :headline) %>")
|
|
69
|
+
say("<%= color('Y88b. 888 .88P 888 888 888 888', :headline) %>")
|
|
70
|
+
say("<%= color(' \"Y888b. 8888888K. 888 888 d88P', :headline) %>")
|
|
71
|
+
say("<%= color(' \"Y88b. 888 \"Y88b 888 8888888P\"', :headline) %>")
|
|
72
|
+
say("<%= color(' \"888 888 888 888 888 888', :headline) %>")
|
|
73
|
+
say("<%= color('Y88b d88P 888 d88P Y88b d88P 888', :headline) %>")
|
|
74
|
+
say("<%= color(' \"Y8888P\" 8888888P\" \"Y8888P\" 888', :headline) %>")
|
|
75
|
+
say("<%= color(' ( ( * ) (', :subheader) %>")
|
|
76
|
+
say("<%= color(' ( )\\ ) )\\ ) ( ` ( /( )\\ )', :subheader) %>")
|
|
77
|
+
say("<%= color(' )\\ (()/((()/( )\\))( )\\()|()/( (', :subheader) %>")
|
|
78
|
+
say("<%= color(' (((_) /(_))/(_)) ((_)()\\((_)\\ /(_)) )', :subheader) %>")
|
|
79
|
+
say("<%= color(' )\\___(_)) (_)) (_()((_) ((_|_))_ ((_)', :subheader) %>")
|
|
80
|
+
say("<%= color('((/ __| | |_ _| | \\/ |/ _ \\| \\| __|', :subheader) %>")
|
|
81
|
+
say("<%= color(' | (__| |__ | | | |\\/| | (_) | |) | _|', :subheader) %>")
|
|
82
|
+
say("<%= color(' \\___|____|___| |_| |_|\\___/|___/|___|', :subheader) %>")
|
|
83
|
+
say("\n")
|
|
84
|
+
loop do
|
|
85
|
+
input = ask('> ')
|
|
86
|
+
case input
|
|
87
|
+
when /^(backup|backup\s?(\S+))$/
|
|
88
|
+
backup($2)
|
|
89
|
+
when 'clear'
|
|
90
|
+
system('clear')
|
|
91
|
+
when 'config'
|
|
92
|
+
Config.new.config_menu(:main)
|
|
93
|
+
when 'detach'
|
|
94
|
+
system('screen -d')
|
|
95
|
+
when 'exit', 'quit'
|
|
96
|
+
say("<%= color('!!! This action could result in data loss !!!', :warning) %>")
|
|
97
|
+
say("<%= color('!!! Starbound shall be stopped if running !!!', :warning) %>")
|
|
98
|
+
if agree("Are you sure? ", true)
|
|
99
|
+
stop('SIGKILL') unless `pidof starbound_server`.empty?
|
|
100
|
+
exit
|
|
101
|
+
end
|
|
102
|
+
when /^(get|get\s?(\S+))$/
|
|
103
|
+
get($2)
|
|
104
|
+
when 'kill'
|
|
105
|
+
say("<%= color('!!! This action could result in data loss !!!', :warning) %>")
|
|
106
|
+
if agree("Are you sure? ", true)
|
|
107
|
+
stop('SIGKILL')
|
|
108
|
+
end
|
|
109
|
+
when 'reboot'
|
|
110
|
+
say("<%= color('!!! This action could result in data loss !!!', :warning) %>")
|
|
111
|
+
if agree("Are you sure? ", true)
|
|
112
|
+
restart('SIGKILL')
|
|
113
|
+
end
|
|
114
|
+
when 'restart'
|
|
115
|
+
if agree("Are you sure? ", true)
|
|
116
|
+
restart
|
|
117
|
+
end
|
|
118
|
+
when /^(say|say\s?(.+))$/
|
|
119
|
+
sb_say($2)
|
|
120
|
+
when 'setup'
|
|
121
|
+
Setup.new.run
|
|
122
|
+
when 'start'
|
|
123
|
+
if not @config['starbound_directory'].nil?
|
|
124
|
+
if `pidof starbound_server`.empty?
|
|
125
|
+
if $daemon.nil?
|
|
126
|
+
start
|
|
127
|
+
else
|
|
128
|
+
say("<%= color('Duplicate prevented.', :warning) %> The daemon is still processing. Please wait and try again.")
|
|
129
|
+
end
|
|
130
|
+
else
|
|
131
|
+
say("<%= color('Duplicate prevented.', :warning) %> The server is already running.")
|
|
132
|
+
end
|
|
133
|
+
else
|
|
134
|
+
say("<%= color('Error', :warning) %> Please run setup then restart SBCP.")
|
|
135
|
+
end
|
|
136
|
+
when 'stop'
|
|
137
|
+
if agree("Are you sure? ", true)
|
|
138
|
+
stop
|
|
139
|
+
end
|
|
140
|
+
when /^(help|help\s?(\S+))$/
|
|
141
|
+
command = $2
|
|
142
|
+
if not command.nil?
|
|
143
|
+
if @commands.include? command.strip
|
|
144
|
+
help(command)
|
|
145
|
+
else
|
|
146
|
+
say("The command \"#{command.strip}\" does not exist.")
|
|
147
|
+
end
|
|
148
|
+
else
|
|
149
|
+
help
|
|
150
|
+
end
|
|
151
|
+
else
|
|
152
|
+
say('Invalid command. Try help for a list of possible commands.')
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
ensure
|
|
156
|
+
$daemon.terminate unless $daemon.nil?
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def backup(type=nil)
|
|
160
|
+
if not type.nil?
|
|
161
|
+
case type
|
|
162
|
+
when 'starbound', 'sbcp', 'full'
|
|
163
|
+
Backup.create_backup(type)
|
|
164
|
+
else
|
|
165
|
+
say("Backup type \"#{type}\" is not valid.")
|
|
166
|
+
end
|
|
167
|
+
else
|
|
168
|
+
say('Please specify a backup type.')
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def get(data=nil)
|
|
173
|
+
if not data.nil?
|
|
174
|
+
case data
|
|
175
|
+
when 'info'
|
|
176
|
+
unless Starbound::SESSION.nil? || Starbound::SESSION.empty?
|
|
177
|
+
Starbound::SESSION[:info][:uptime] = Time.diff(Starbound::SESSION[:info][:started], Time.now, '%H %N %S')[:diff]
|
|
178
|
+
unless Starbound::SESSION[:info][:restart_in] == 'Never'
|
|
179
|
+
Starbound::SESSION[:info][:restart_in] = "#{(((@config['restart_schedule']*60*60) - (Time.now - Starbound::SESSION[:info][:started]))/60).to_i} minutes" # Inaccurate for first start, fairly acurrate thereafter
|
|
180
|
+
end
|
|
181
|
+
Starbound::SESSION[:info].each_pair do |key, value|
|
|
182
|
+
say("<%= color('#{key.to_s.capitalize}:', :info) %> #{value}")
|
|
183
|
+
end
|
|
184
|
+
else
|
|
185
|
+
say("<%= color('Error!', :failure) %> Session data is missing or empty.")
|
|
186
|
+
end
|
|
187
|
+
when 'players'
|
|
188
|
+
unless Starbound::SESSION.nil? || Starbound::SESSION.empty?
|
|
189
|
+
pp(Starbound::SESSION[:players])
|
|
190
|
+
else
|
|
191
|
+
say("<%= color('Error!', :failure) %> Session data is missing or empty.")
|
|
192
|
+
end
|
|
193
|
+
else
|
|
194
|
+
say("Data type \"#{data}\" is not valid.")
|
|
195
|
+
end
|
|
196
|
+
else
|
|
197
|
+
say('Please specify a data type.')
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def restart(signal='SIGTERM')
|
|
202
|
+
say('Sending restart request...')
|
|
203
|
+
kill(signal)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def start
|
|
207
|
+
say('Starting the Starbound server...')
|
|
208
|
+
supervisor = Daemon.supervise
|
|
209
|
+
$daemon = supervisor.actors.first
|
|
210
|
+
$daemon.async.start
|
|
211
|
+
say("<%= color('Operation complete.', :success) %>")
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def stop(signal='SIGTERM')
|
|
215
|
+
say('Sending stop request...')
|
|
216
|
+
file = Tempfile.new('sb-shutdown')
|
|
217
|
+
kill(signal)
|
|
218
|
+
ensure
|
|
219
|
+
unless file.nil?
|
|
220
|
+
file.close
|
|
221
|
+
file.unlink
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def sb_say(string)
|
|
226
|
+
unless string.nil?
|
|
227
|
+
if not $rcon.nil?
|
|
228
|
+
$rcon.execute("say #{string}")
|
|
229
|
+
say("<%= color('Message sent to server.', :success) %>")
|
|
230
|
+
else
|
|
231
|
+
say("<%= color('RCON is not running.', :warning) %>")
|
|
232
|
+
end
|
|
233
|
+
else
|
|
234
|
+
say("Please type something to say.")
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def kill(signal='SIGTERM')
|
|
239
|
+
pid = `pidof starbound_server`
|
|
240
|
+
unless pid.empty?
|
|
241
|
+
system("kill -s #{signal} #{pid.to_i}")
|
|
242
|
+
t = Time.now
|
|
243
|
+
d = 0
|
|
244
|
+
until `pidof starbound_server`.empty? || d >= 5
|
|
245
|
+
sleep(1)
|
|
246
|
+
d = Time.now - t
|
|
247
|
+
end
|
|
248
|
+
if not `pidof starbound_server`.empty?
|
|
249
|
+
return say("<%= color('Failure!', :failure) %> The server is still running.")
|
|
250
|
+
end
|
|
251
|
+
return say("<%= color('Operation complete.', :success) %>")
|
|
252
|
+
end
|
|
253
|
+
say("<%= color('Aborting request. See details below.', :failure) %>")
|
|
254
|
+
return say('Unable to locate the starbound_server process. Is it running?')
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def help(command=nil)
|
|
258
|
+
if not command.nil?
|
|
259
|
+
case command
|
|
260
|
+
when 'backup'
|
|
261
|
+
else
|
|
262
|
+
say("Could not find help for \"#{command}\" command.")
|
|
263
|
+
end
|
|
264
|
+
else
|
|
265
|
+
say("<%= color('Command list. Type help [command] to learn more.', :help) %>")
|
|
266
|
+
say("#{@commands_scheme.join(", ")}")
|
|
267
|
+
end
|
|
268
|
+
end
|
|
37
269
|
end
|
|
38
|
-
end
|
|
270
|
+
end
|
data/lib/sbcp/backup.rb
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# SBCP - Starbound Server Management Solution for Linux Servers
|
|
2
|
+
# Copyright (C) 2016 Kazyyk
|
|
3
|
+
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU Affero General Public License as
|
|
6
|
+
# published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
# License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
# You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
1
17
|
require 'securerandom'
|
|
2
18
|
require 'fileutils'
|
|
3
19
|
require 'rsync'
|
|
@@ -12,11 +28,14 @@ module SBCP
|
|
|
12
28
|
# Full: backs up both Starbound and SBCP data.
|
|
13
29
|
# Defaults to Starbound.
|
|
14
30
|
|
|
15
|
-
def self.create_backup(
|
|
31
|
+
def self.create_backup(type='starbound')
|
|
16
32
|
config = YAML.load_file(File.expand_path('../../../config.yml', __FILE__))
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
33
|
+
if config['backup_history'] == 'none'
|
|
34
|
+
puts 'Backups are currently disabled.'
|
|
35
|
+
return
|
|
36
|
+
end
|
|
37
|
+
case type
|
|
38
|
+
when 'starbound'
|
|
20
39
|
root = config['starbound_directory']
|
|
21
40
|
world_files = "#{root}/giraffe_storage/universe/*.world"
|
|
22
41
|
latest_files_directory = File.expand_path('../../../backup', __FILE__)
|
|
@@ -40,9 +59,9 @@ module SBCP
|
|
|
40
59
|
end
|
|
41
60
|
end
|
|
42
61
|
end
|
|
43
|
-
when
|
|
44
|
-
|
|
45
|
-
when
|
|
62
|
+
when 'sbcp'
|
|
63
|
+
puts "Unimplemented."
|
|
64
|
+
when 'full'
|
|
46
65
|
# This should take a complete backup of Starbound and SBCP.
|
|
47
66
|
# Currently only supports Starbound.
|
|
48
67
|
root = config['starbound_directory']
|
|
@@ -54,6 +73,7 @@ module SBCP
|
|
|
54
73
|
FileUtils.mv backup_name, backup_directory # Move the created backup to the backup directory
|
|
55
74
|
end
|
|
56
75
|
end
|
|
76
|
+
puts "Backup completed successfully."
|
|
57
77
|
end
|
|
58
78
|
end
|
|
59
79
|
end
|
data/lib/sbcp/config.rb
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# SBCP - Starbound Server Management Solution for Linux Servers
|
|
2
|
+
# Copyright (C) 2016 Kazyyk
|
|
3
|
+
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU Affero General Public License as
|
|
6
|
+
# published by the Free Software Foundation, either version 3 of the
|
|
7
|
+
# License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
# GNU Affero General Public License for more details.
|
|
13
|
+
|
|
14
|
+
# You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
require 'yaml'
|
|
18
|
+
require 'highline'
|
|
19
|
+
|
|
20
|
+
module SBCP
|
|
21
|
+
class Config
|
|
22
|
+
def initialize
|
|
23
|
+
@cli = HighLine.new
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def config_menu(menu)
|
|
27
|
+
config_file = File.expand_path('../../../config.yml', __FILE__)
|
|
28
|
+
config = YAML.load_file(config_file)
|
|
29
|
+
case menu
|
|
30
|
+
when :main
|
|
31
|
+
answer = @cli.choose do |menu|
|
|
32
|
+
menu.prompt = "Please select a menu option\n> "
|
|
33
|
+
@cli.say("=== SBCP Configuration Menu ===")
|
|
34
|
+
menu.choice(:General) { config_menu(:general) }
|
|
35
|
+
menu.choice(:Backups) { config_menu(:backups) }
|
|
36
|
+
menu.choice(:Logs) { config_menu(:logs) }
|
|
37
|
+
menu.choice(:Restarts) { config_menu(:restarts) }
|
|
38
|
+
menu.choice(:Exit) { puts 'Thank you for using SBCP.' }
|
|
39
|
+
end
|
|
40
|
+
when :general
|
|
41
|
+
answer = @cli.choose do |menu|
|
|
42
|
+
menu.prompt = "Please select a menu option\n> "
|
|
43
|
+
@cli.say("=== SBCP General Settings ===")
|
|
44
|
+
menu.choice('Starbound Directory') do
|
|
45
|
+
@cli.choose do |sub_menu|
|
|
46
|
+
sub_menu.prompt = "Please select a menu option\n> "
|
|
47
|
+
@cli.say("=== SBCP Starbound Directory Setting ===")
|
|
48
|
+
@cli.say('Your current starbound directory is:')
|
|
49
|
+
@cli.say("\"#{config['starbound_directory']}\"")
|
|
50
|
+
sub_menu.choice('Keep this directory') { @cli.say('Directory kept.'); config_menu(:general) }
|
|
51
|
+
sub_menu.choice('Change this directory') do
|
|
52
|
+
response = ''
|
|
53
|
+
until Dir.exist?(response) && Dir.exist?(response + '/giraffe_storage') && File.writable?(response)
|
|
54
|
+
response = @cli.ask("Please enter a new directory.\n> ")
|
|
55
|
+
if not Dir.exist?(response) && Dir.exist?(response + '/giraffe_storage')
|
|
56
|
+
@cli.say('Error - This dirctory does not exist or is not a valid starbound installation. Try again.')
|
|
57
|
+
elsif not File.writable?(response)
|
|
58
|
+
@cli.say('Error - This dirctory cannot be written to. Check permissions and try again.')
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
config['starbound_directory'] = response
|
|
62
|
+
File.write(config_file, config.to_yaml)
|
|
63
|
+
@cli.say('Changes saved successfully.')
|
|
64
|
+
config_menu(:general)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
menu.choice('Back to Main Menu') { config_menu(:main) }
|
|
69
|
+
end
|
|
70
|
+
when :backups
|
|
71
|
+
@cli.choose do |menu|
|
|
72
|
+
menu.prompt = "Please select a menu option\n> "
|
|
73
|
+
@cli.say("=== SBCP Backup Settings ===")
|
|
74
|
+
menu.choice('Backup Directory') do
|
|
75
|
+
@cli.choose do |sub_menu|
|
|
76
|
+
sub_menu.prompt = "Please select a menu option\n> "
|
|
77
|
+
@cli.say("=== SBCP Backup Directory Setting ===")
|
|
78
|
+
@cli.say('Your current backup directory is:')
|
|
79
|
+
@cli.say("\"#{config['backup_directory']}\"")
|
|
80
|
+
sub_menu.choice('Keep this directory') { @cli.say('Directory kept.'); config_menu(:backups) }
|
|
81
|
+
sub_menu.choice('Change this directory') do
|
|
82
|
+
response = ''
|
|
83
|
+
until Dir.exist?(response) && File.writable?(response)
|
|
84
|
+
response = @cli.ask("Please enter a new directory.\n> ")
|
|
85
|
+
if not Dir.exist?(response)
|
|
86
|
+
@cli.say('Error - This dirctory does not exist. Try again.')
|
|
87
|
+
elsif not File.writable?(response)
|
|
88
|
+
@cli.say('Error - This dirctory cannot be written to. Check permissions and try again.')
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
config['backup_directory'] = response
|
|
92
|
+
File.write(config_file, config.to_yaml)
|
|
93
|
+
@cli.say('Changes saved successfully.')
|
|
94
|
+
config_menu(:backups)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
menu.choice('Backup History') do
|
|
99
|
+
@cli.choose do |sub_menu|
|
|
100
|
+
sub_menu.prompt = "Please select a menu option\n> "
|
|
101
|
+
@cli.say("=== SBCP Backup History Setting ===")
|
|
102
|
+
@cli.say('Backups are currently set to remain archived for:')
|
|
103
|
+
@cli.say(config['backup_history'].to_s + ' days')
|
|
104
|
+
sub_menu.choice('Keep this setting') { @cli.say('Setting kept.'); config_menu(:backups) }
|
|
105
|
+
sub_menu.choice('Change this setting') do
|
|
106
|
+
until response > 0
|
|
107
|
+
response = @cli.ask("Enter a new value in days (enter 0 to disable backups)\n> ", Integer)
|
|
108
|
+
@cli.say('Value must be greater than zero.') if not response > 0
|
|
109
|
+
end
|
|
110
|
+
config['backup_history'] = response
|
|
111
|
+
File.write(config_file, config.to_yaml)
|
|
112
|
+
@cli.say('Changes saved successfully.')
|
|
113
|
+
config_menu(:backups)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
menu.choice('Backup Schedule') do
|
|
118
|
+
@cli.choose do |sub_menu|
|
|
119
|
+
sub_menu.prompt = "Please select a menu option\n> "
|
|
120
|
+
@cli.say("=== SBCP Backup Schedule Setting ===")
|
|
121
|
+
@cli.say('The backup schedule is currently set to:')
|
|
122
|
+
config['backup_schedule'].is_a?(Integer) ? @cli.say('Every ' + config['backup_schedule'].to_s + ' hours') : @cli.say(config['backup_schedule'].to_s)
|
|
123
|
+
sub_menu.choice('Keep this setting') { @cli.say('Setting kept.'); config_menu(:backups) }
|
|
124
|
+
sub_menu.choice('Change this setting') do
|
|
125
|
+
response = @cli.ask("Enter a new value in hours (enter 0 for on restart)\n> ", Integer) { |q| q.in = [0, 1, 2, 3, 4, 6, 8, 12, 24] }
|
|
126
|
+
response = 'restart' if response == 0
|
|
127
|
+
response = 'hourly' if response == 1
|
|
128
|
+
response = 'daily' if response == 24
|
|
129
|
+
config['backup_schedule'] = response
|
|
130
|
+
File.write(config_file, config.to_yaml)
|
|
131
|
+
@cli.say('Changes saved successfully.')
|
|
132
|
+
config_menu(:backups)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
menu.choice('Back to Main Menu') { config_menu(:main) }
|
|
137
|
+
end
|
|
138
|
+
when :logs
|
|
139
|
+
@cli.choose do |menu|
|
|
140
|
+
menu.prompt = "Please select a menu option\n> "
|
|
141
|
+
@cli.say("=== SBCP Log Settings ===")
|
|
142
|
+
menu.choice('Log Directory') do
|
|
143
|
+
@cli.choose do |sub_menu|
|
|
144
|
+
sub_menu.prompt = "Please select a menu option\n> "
|
|
145
|
+
@cli.say("=== SBCP Log Directory Setting ===")
|
|
146
|
+
@cli.say('Your current logs directory is:')
|
|
147
|
+
@cli.say("\"#{config['log_directory']}\"")
|
|
148
|
+
sub_menu.choice('Keep this directory') { @cli.say('Directory kept.'); config_menu(:logs) }
|
|
149
|
+
sub_menu.choice('Change this directory') do
|
|
150
|
+
response = ''
|
|
151
|
+
until Dir.exist?(response) && File.writable?(response)
|
|
152
|
+
response = @cli.ask("Please enter a new directory.\n> ")
|
|
153
|
+
if not Dir.exist?(response)
|
|
154
|
+
@cli.say('Error - This dirctory does not exist. Try again.')
|
|
155
|
+
elsif not File.writable?(response)
|
|
156
|
+
@cli.say('Error - This dirctory cannot be written to. Check permissions and try again.')
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
config['log_directory'] = response
|
|
160
|
+
File.write(config_file, config.to_yaml)
|
|
161
|
+
@cli.say('Changes saved successfully.')
|
|
162
|
+
config_menu(:logs)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
menu.choice('Log History') do
|
|
167
|
+
@cli.choose do |sub_menu|
|
|
168
|
+
sub_menu.prompt = "Please select a menu option\n> "
|
|
169
|
+
@cli.say("=== SBCP Log History Setting ===")
|
|
170
|
+
@cli.say('Logs are currently set to remain archived for:')
|
|
171
|
+
@cli.say(config['log_history'].to_s + ' days')
|
|
172
|
+
sub_menu.choice('Keep this setting') { @cli.say('Setting kept.'); config_menu(:logs) }
|
|
173
|
+
sub_menu.choice('Change this setting') do
|
|
174
|
+
until response >= 1
|
|
175
|
+
response = @cli.ask("Enter a new value in days\n> ", Integer)
|
|
176
|
+
@cli.say('Value must be greater than or equal to one.') if not response >= 1
|
|
177
|
+
end
|
|
178
|
+
config['log_history'] = response
|
|
179
|
+
File.write(config_file, config.to_yaml)
|
|
180
|
+
@cli.say('Changes saved successfully.')
|
|
181
|
+
config_menu(:logs)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
menu.choice('Log Style') do
|
|
186
|
+
@cli.choose do |sub_menu|
|
|
187
|
+
sub_menu.prompt = "Please select a menu option\n> "
|
|
188
|
+
@cli.say("=== SBCP Log Style Setting ===")
|
|
189
|
+
@cli.say('The log style is currently set to:')
|
|
190
|
+
@cli.say(config['log_style'])
|
|
191
|
+
sub_menu.choice('Keep this setting') { @cli.say('Setting kept.'); config_menu(:logs) }
|
|
192
|
+
sub_menu.choice('Change this setting') do
|
|
193
|
+
response = @cli.ask("Enter a style name (daily, restart))\n> ") { |q| q.in = ['daily', 'restart'] }
|
|
194
|
+
config['log_style'] = response
|
|
195
|
+
File.write(config_file, config.to_yaml)
|
|
196
|
+
@cli.say('Changes saved successfully.')
|
|
197
|
+
config_menu(:logs)
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
menu.choice('Back to Main Menu') { config_menu(:main) }
|
|
202
|
+
end
|
|
203
|
+
when :restarts
|
|
204
|
+
@cli.choose do |menu|
|
|
205
|
+
menu.prompt = "Please select a menu option\n> "
|
|
206
|
+
@cli.say("=== SBCP Restart Settings ===")
|
|
207
|
+
menu.choice('Restart Schedule') do
|
|
208
|
+
@cli.choose do |sub_menu|
|
|
209
|
+
sub_menu.prompt = "Please select a menu option\n> "
|
|
210
|
+
@cli.say("=== SBCP Restart Schedule Setting ===")
|
|
211
|
+
@cli.say('The restart schedule is currently set to:')
|
|
212
|
+
config['restart_schedule'].is_a?(Integer) ? @cli.say('Every ' + config['restart_schedule'].to_s + ' hours') : @cli.say(config['restart_schedule'].to_s.capitalize)
|
|
213
|
+
sub_menu.choice('Keep this setting') { @cli.say('Setting kept.'); config_menu(:restarts) }
|
|
214
|
+
sub_menu.choice('Change this setting') do
|
|
215
|
+
response = @cli.ask("Enter a new value in hours\n> ", Integer) { |q| q.in = [0, 1, 2, 3, 4, 6, 8, 12, 24] }
|
|
216
|
+
response = 'disabled' if response == 0
|
|
217
|
+
config['restart_schedule'] = response
|
|
218
|
+
File.write(config_file, config.to_yaml)
|
|
219
|
+
@cli.say('Changes saved successfully.')
|
|
220
|
+
config_menu(:restarts)
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
menu.choice('Back to Main Menu') { config_menu(:main) }
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|