Skip to content

Commit

Permalink
Fix freezing
Browse files Browse the repository at this point in the history
  • Loading branch information
MotorTruck1221 committed Apr 8, 2024
1 parent 6405b7c commit e5c5b49
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /app
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
COPY . .
RUN bundle install
RUN touch .env
ENV DOCKER=true
EXPOSE 9292

CMD ["bundle", "exec", "ruby", "cli/cli.rb", "start"]
98 changes: 48 additions & 50 deletions cli/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,17 @@ class ByodCLI < Thor
desc "start", "Start the bot"
option :sqlite, type: :boolean, default: false, desc: "Use SQLite instead of PostgreSQL"
def start
if File.exist?(".env") == false
File.open(".env", "w") do |f|
end
end
if options[:sqlite] == true
if ENV['DATABASE'] == nil
File.open(".env", "a") do |f|
f.write("DATABASE=sqlite\n")
end
end
if ENV['DATABASE'] != "sqlite"
#delete the key
File.open(".env", "r+") do |f|
f.each_line do |line|
if line.include?("DATABASE")
f.seek(-line.length, IO::SEEK_CUR)
f.write("#" + line)
end
end
end
File.open(".env", "a") do |f|
f.write("DATABASE=sqlite\n")
#reinit the evvironment variables
ENV['DATABASE'] = "sqlite"
end
end
else
if ENV['DATABASE'] != "postgres"
#delete the key
File.open(".env", "r+") do |f|
f.each_line do |line|
if line.include?("DATABASE")
f.seek(-line.length, IO::SEEK_CUR)
f.write("#" + line)
end
end
end
File.open(".env", "a") do |f|
f.write("DATABASE=postgres\n")
#if running in docker, completley ignore this
if ENV['DOCKER'] != "true"
if File.exist?(".env") == false
File.open(".env", "w") do |f|
end
end
end

if ENV['REVERSE_PROXY'] == nil
while true
prompt = TTY::Prompt.new
reverseProxy = prompt.select("Which reverse proxy do you use?", %w(caddy), required: true, default: "caddy")
reverseProxy = prompt.select("Which reverse proxy do you use?", %w(caddy nginx apache), required: true, default: "caddy")
reverseProxyConfirm = prompt.yes?("Is #{reverseProxy} the correct reverse proxy?")
if reverseProxyConfirm == false
next
Expand Down Expand Up @@ -97,33 +61,67 @@ def start
f.write("SERVER_IP=#{serverIP}\n")
end
end
if options[:sqlite] != true
if options[:sqlite] == true
#delete any existing DATABSE key in the env
if ENV['DATABASE'] != "sqlite"
#delete the key
File.open(".env", "r+") do |f|
f.each_line do |line|
if line.include?("DATABASE")
f.seek(-line.length, IO::SEEK_CUR)
f.write("#" + line)
end
end
end
File.open(".env", "a") do |f|
f.write("DATABASE=sqlite\n")
ENV['DATABASE'] = "sqlite"
end
end
else
if ENV['DATABASE'] != "postgres"
#delete the key
File.open(".env", "r+") do |f|
f.each_line do |line|
if line.include?("DATABASE")
f.seek(-line.length, IO::SEEK_CUR)
f.write("#" + line)
end
end
end
File.open(".env", "a") do |f|
f.write("DATABASE=postgres\n")
end
end
end
if ENV['DATABASE'] == 'postgres' && ENV['DOCKER'] != "true"
puts "Running setup for PostgreSQL database".yellow
if ENV['DB_HOST'] == nil
prompt = TTY::Prompt.new
dbHost = prompt.ask("What is the host of your PostgreSQL database?", required: true)
host = prompt.ask("What is the host of your PostgreSQL database?", required: true)
File.open(".env", "a") do |f|
f.write("DB_HOST=#{dbHost}\n")
f.write("DB_HOST=#{host}\n")
end
end
if ENV['DB_USER'] == nil
prompt = TTY::Prompt.new
dbUser = prompt.ask("What is the user of your PostgreSQL database?", required: true)
user = prompt.ask("What is the user of your PostgreSQL database?", required: true)
File.open(".env", "a") do |f|
f.write("DB_USER=#{dbUser}\n")
f.write("DB_USER=#{user}\n")
end
end
if ENV['DB_PASSWORD'] == nil
prompt = TTY::Prompt.new
dbPassword = prompt.mask("What is the password of your PostgreSQL database?", required: true)
password = prompt.mask("What is the password of your PostgreSQL database?", required: true)
File.open(".env", "a") do |f|
f.write("DB_PASSWORD=#{dbPassword}\n")
f.write("DB_PASSWORD=#{password}\n")
end
end
if ENV['DB_NAME'] == nil
prompt = TTY::Prompt.new
dbName = prompt.ask("What is the name of your PostgreSQL database?", required: true)
database = prompt.ask("What is the name of your PostgreSQL database?", required: true)
File.open(".env", "a") do |f|
f.write("DB_DATABASE=#{dbName}\n")
f.write("DB_NAME=#{database}\n")
end
end
end
Expand Down

0 comments on commit e5c5b49

Please sign in to comment.