Enhance First Run Setup and User Interaction
1. Added a method to ask for the default mode (TUI, GUI, or WebApp) during the first run setup. 2. Implemented a method to validate the input mode. 3. Improved the database connection test method to handle exceptions and return a boolean value. 4. Added a method to ask for database details (username, password, and database name). 5. Enhanced the user interface by adding Curses.clear before each question to make the interface cleaner. 6. Improved the password input process by disabling echo to hide the input from the screen. 7. Added validation for uplink and downlink speeds. 8. Added a method to ask for services the system should be aware of.
This commit is contained in:
parent
71a777d0bd
commit
d968e17823
|
@ -10,3 +10,7 @@ gem 'console'
|
||||||
gem "rubocop", "~> 1.52"
|
gem "rubocop", "~> 1.52"
|
||||||
|
|
||||||
gem "solargraph", "~> 0.49.0"
|
gem "solargraph", "~> 0.49.0"
|
||||||
|
|
||||||
|
gem "sequel", "~> 5.69"
|
||||||
|
|
||||||
|
gem "mysql2", "~> 0.5.5"
|
||||||
|
|
|
@ -16,6 +16,7 @@ GEM
|
||||||
rexml
|
rexml
|
||||||
kramdown-parser-gfm (1.1.0)
|
kramdown-parser-gfm (1.1.0)
|
||||||
kramdown (~> 2.0)
|
kramdown (~> 2.0)
|
||||||
|
mysql2 (0.5.5)
|
||||||
nokogiri (1.15.2-x86_64-linux)
|
nokogiri (1.15.2-x86_64-linux)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
parallel (1.23.0)
|
parallel (1.23.0)
|
||||||
|
@ -41,6 +42,7 @@ GEM
|
||||||
rubocop-ast (1.29.0)
|
rubocop-ast (1.29.0)
|
||||||
parser (>= 3.2.1.0)
|
parser (>= 3.2.1.0)
|
||||||
ruby-progressbar (1.13.0)
|
ruby-progressbar (1.13.0)
|
||||||
|
sequel (5.69.0)
|
||||||
solargraph (0.49.0)
|
solargraph (0.49.0)
|
||||||
backport (~> 1.2)
|
backport (~> 1.2)
|
||||||
benchmark
|
benchmark
|
||||||
|
@ -68,7 +70,9 @@ PLATFORMS
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
console
|
console
|
||||||
curses (~> 1.4)
|
curses (~> 1.4)
|
||||||
|
mysql2 (~> 0.5.5)
|
||||||
rubocop (~> 1.52)
|
rubocop (~> 1.52)
|
||||||
|
sequel (~> 5.69)
|
||||||
solargraph (~> 0.49.0)
|
solargraph (~> 0.49.0)
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
|
|
20
lib/utils/database_manager.rb
Normal file
20
lib/utils/database_manager.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
class DatabaseManager
|
||||||
|
def initialize
|
||||||
|
@db = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_db_connection(db_details)
|
||||||
|
begin
|
||||||
|
connection_string = "mysql2://#{db_details[:username]}:#{db_details[:password]}@localhost/#{db_details[:database]}"
|
||||||
|
@db = Sequel.connect(connection_string)
|
||||||
|
# Try a simple query to test the connection
|
||||||
|
@db.run "SELECT 1"
|
||||||
|
true
|
||||||
|
rescue Sequel::DatabaseConnectionError
|
||||||
|
false
|
||||||
|
ensure
|
||||||
|
@db.disconnect if @db
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
59
lib/utils/first_run_init.rb
Normal file
59
lib/utils/first_run_init.rb
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
require 'curses'
|
||||||
|
|
||||||
|
def first_run_setup
|
||||||
|
color = ask_for_color
|
||||||
|
# TODO: Use the color for something
|
||||||
|
db_details = ask_for_db_details
|
||||||
|
while !test_db_connection(db_details)
|
||||||
|
Curses.setpos(4, 0)
|
||||||
|
Curses.addstr("Whoops! We couldn't connect to the database with the details you provided. Please try again!")
|
||||||
|
Curses.refresh
|
||||||
|
db_details = ask_for_db_details
|
||||||
|
end
|
||||||
|
uplink_speed = ask_for_uplink_speed
|
||||||
|
# TODO: Use the uplink speed for something
|
||||||
|
downlink_speed = ask_for_downlink_speed
|
||||||
|
# TODO: Use the downlink speed for something
|
||||||
|
total_bandwidth = calculate_total_bandwidth(uplink_speed, downlink_speed)
|
||||||
|
# TODO: Use the total bandwidth for something
|
||||||
|
services = ask_for_services
|
||||||
|
# TODO: Use the services for something
|
||||||
|
# ...
|
||||||
|
end
|
||||||
|
|
||||||
|
def ask_for_color
|
||||||
|
while true
|
||||||
|
Curses.clear
|
||||||
|
Curses.setpos(0, 0)
|
||||||
|
Curses.addstr("Please enter your preferred color (white, red, or black): ")
|
||||||
|
Curses.refresh
|
||||||
|
color = Curses.getstr.strip.downcase
|
||||||
|
if ['white', 'red', 'black'].include?(color)
|
||||||
|
return color
|
||||||
|
else
|
||||||
|
Curses.setpos(1, 0)
|
||||||
|
Curses.addstr("Whoops! That didn't appear to be a valid color. Please try again!")
|
||||||
|
Curses.refresh
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def ask_for_default_mode
|
||||||
|
while true
|
||||||
|
Curses.setpos(8, 0)
|
||||||
|
Curses.addstr("Please enter the default mode (TUI, GUI, or WebApp): ")
|
||||||
|
Curses.refresh
|
||||||
|
mode = Curses.getstr.strip.downcase
|
||||||
|
if valid_mode?(mode)
|
||||||
|
return mode
|
||||||
|
else
|
||||||
|
Curses.setpos(9, 0)
|
||||||
|
Curses.addstr("Whoops! That didn't appear to be a valid mode. Please try again!")
|
||||||
|
Curses.refresh
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_mode?(mode)
|
||||||
|
['tui', 'gui', 'webapp'].include?(mode)
|
||||||
|
end
|
93
lib/utils/system_information_gather.rb
Normal file
93
lib/utils/system_information_gather.rb
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
def ask_for_uplink_speed
|
||||||
|
while true
|
||||||
|
Curses.clear
|
||||||
|
Curses.setpos(2, 0)
|
||||||
|
Curses.addstr("Please enter your uplink speed (upload speed, e.g., 1000Mbps or 1Gbps). ")
|
||||||
|
Curses.addstr("This is typically the maximum upload speed provided by your ISP. ")
|
||||||
|
Curses.addstr("You can check your ISP bill, use an online speed test, or contact your ISP if you're unsure. ")
|
||||||
|
Curses.refresh
|
||||||
|
speed = Curses.getstr.strip.downcase
|
||||||
|
if valid_speed?(speed)
|
||||||
|
return convert_speed_to_mbps(speed)
|
||||||
|
else
|
||||||
|
Curses.setpos(3, 0)
|
||||||
|
Curses.addstr("Whoops! That didn't appear to be a valid speed. Please try again!")
|
||||||
|
Curses.refresh
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def ask_for_downlink_speed
|
||||||
|
while true
|
||||||
|
Curses.clear
|
||||||
|
Curses.setpos(4, 0)
|
||||||
|
Curses.addstr("Please enter your downlink speed (download speed, e.g., 1000Mbps or 1Gbps). ")
|
||||||
|
Curses.addstr("This is typically the maximum download speed provided by your ISP. ")
|
||||||
|
Curses.addstr("You can check your ISP bill, use an online speed test, or contact your ISP if you're unsure. ")
|
||||||
|
Curses.refresh
|
||||||
|
speed = Curses.getstr.strip.downcase
|
||||||
|
if valid_speed?(speed)
|
||||||
|
return convert_speed_to_mbps(speed)
|
||||||
|
else
|
||||||
|
Curses.setpos(5, 0)
|
||||||
|
Curses.addstr("Whoops! That didn't appear to be a valid speed. Please try again!")
|
||||||
|
Curses.refresh
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_speed?(speed)
|
||||||
|
speed.to_i > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def ask_for_services
|
||||||
|
while true
|
||||||
|
Curses.clear
|
||||||
|
Curses.setpos(6, 0)
|
||||||
|
Curses.addstr("Please enter the services the system should be aware of (e.g., webserver, database). ")
|
||||||
|
Curses.addstr("Enter the services as a comma-separated list (e.g., webserver,database). ")
|
||||||
|
Curses.refresh
|
||||||
|
services = Curses.getstr.strip.downcase.split(',').map(&:strip)
|
||||||
|
if valid_services?(services)
|
||||||
|
return services_to_hash(services)
|
||||||
|
else
|
||||||
|
Curses.setpos(7, 0)
|
||||||
|
Curses.addstr("Whoops! That didn't appear to be a valid list of services. Please try again!")
|
||||||
|
Curses.refresh
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_services?(services)
|
||||||
|
# TODO: Validate the services
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def services_to_hash(services)
|
||||||
|
services_hash = {}
|
||||||
|
services.each { |service| services_hash[service] = true }
|
||||||
|
services_hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def ask_for_db_details
|
||||||
|
Curses.clear
|
||||||
|
Curses.setpos(1, 0)
|
||||||
|
Curses.addstr("Please enter your database username: ")
|
||||||
|
Curses.refresh
|
||||||
|
username = Curses.getstr.strip
|
||||||
|
|
||||||
|
Curses.setpos(2, 0)
|
||||||
|
Curses.addstr("Please enter your database password: ")
|
||||||
|
Curses.refresh
|
||||||
|
Curses.echo = false
|
||||||
|
password = Curses.getstr.strip
|
||||||
|
Curses.echo = true
|
||||||
|
|
||||||
|
Curses.setpos(3, 0)
|
||||||
|
Curses.addstr("Please enter your database name: ")
|
||||||
|
Curses.refresh
|
||||||
|
database = Curses.getstr.strip
|
||||||
|
|
||||||
|
{ username: username, password: password, database: database }
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user