mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-02-21 20:20:34 +09:00
78 lines
1.8 KiB
Ruby
Executable File
78 lines
1.8 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
require "fileutils"
|
|
require "socket"
|
|
require "timeout"
|
|
|
|
REDIS_PORT = 6379
|
|
REDIS_HOST = "localhost"
|
|
APP_ROOT = File.expand_path("..", __dir__)
|
|
|
|
def system!(*args)
|
|
system(*args, exception: true)
|
|
end
|
|
|
|
def installed?(tool)
|
|
system("command -v #{tool} > /dev/null 2>&1")
|
|
end
|
|
|
|
def redis_running?
|
|
Timeout::timeout(3) do
|
|
socket = TCPSocket.new(REDIS_HOST, REDIS_PORT)
|
|
socket.close
|
|
return true
|
|
end
|
|
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError, Timeout::Error
|
|
return false
|
|
end
|
|
|
|
if ENV["RAILS_ENV"] == "production"
|
|
puts "RAILS_ENV is production; bailing out"
|
|
exit
|
|
end
|
|
|
|
FileUtils.chdir APP_ROOT do
|
|
puts "== Installing dependencies =="
|
|
|
|
if installed?("brew")
|
|
system "brew install sqlite ffmpeg mise"
|
|
elsif installed?("pacman")
|
|
system "sudo pacman -S --noconfirm --needed sqlite ffmpeg mise"
|
|
elsif installed?("apt")
|
|
system "sudo apt-get install --no-install-recommends -y libsqlite3-0 ffmpeg"
|
|
end
|
|
|
|
if installed?("mise")
|
|
system "mise install"
|
|
else
|
|
puts "Couldn't install mise"
|
|
puts "Install mise using your package manager or via:"
|
|
puts "https://mise.jdx.dev/installing-mise.html"
|
|
exit 1
|
|
end
|
|
|
|
system("bundle check") || system!("bundle install")
|
|
|
|
puts "\n== Preparing database =="
|
|
if ARGV.include?("--reset")
|
|
system "rm -rf ./storage/{db,files}"
|
|
system! "bin/rails db:reset"
|
|
end
|
|
system! "bin/rails db:prepare"
|
|
|
|
unless redis_running?
|
|
if installed?("docker")
|
|
system("docker run -d --name campfire-redis -p #{REDIS_PORT}:#{REDIS_PORT} redis:7")
|
|
else
|
|
puts "Couldn't start Redis"
|
|
puts "Install either docker or redis and then run this command again"
|
|
exit 1
|
|
end
|
|
end
|
|
|
|
puts "\n== Removing old logs and tempfiles =="
|
|
system! "bin/rails log:clear tmp:clear"
|
|
|
|
puts "\n== Restarting services =="
|
|
system! "bin/rails restart"
|
|
end
|