Skip to content

Commit db19c0e

Browse files
monorkinjjasghar
andcommitted
Install system dependencies
Co-authored-by: milos-dukic <milos-dukic@users.noreply.github.com> Co-authored-by: jjasghar <jjasghar@users.noreply.github.com>
1 parent 1b4e28b commit db19c0e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

bin/setup

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
#!/usr/bin/env ruby
22
require "fileutils"
3+
require "socket"
4+
require "timeout"
35

6+
REDIS_PORT = 6379
7+
REDIS_HOST = "localhost"
48
APP_ROOT = File.expand_path("..", __dir__)
59

610
def system!(*args)
711
system(*args, exception: true)
812
end
913

14+
def installed?(tool)
15+
system("command -v #{tool} > /dev/null 2>&1")
16+
end
17+
18+
def redis_running?
19+
Timeout::timeout(3) do
20+
socket = TCPSocket.new(REDIS_HOST, REDIS_PORT)
21+
socket.close
22+
return true
23+
end
24+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError, Timeout::Error
25+
return false
26+
end
27+
1028
if ENV["RAILS_ENV"] == "production"
1129
puts "RAILS_ENV is production; bailing out"
1230
exit
@@ -15,6 +33,15 @@ end
1533
FileUtils.chdir APP_ROOT do
1634
puts "== Installing dependencies =="
1735
system "mise install"
36+
37+
if installed?("brew")
38+
system "brew install sqlite ffmpeg"
39+
elsif installed?("pacman")
40+
system "sudo pacman -S --noconfirm --needed sqlite ffmpeg"
41+
elsif installed?("apt")
42+
system "sudo apt-get install --no-install-recommends -y libsqlite3-0 ffmpeg"
43+
end
44+
1845
system("bundle check") || system!("bundle install")
1946

2047
puts "\n== Preparing database =="
@@ -24,6 +51,16 @@ FileUtils.chdir APP_ROOT do
2451
end
2552
system! "bin/rails db:prepare"
2653

54+
unless redis_running?
55+
if installed?("docker")
56+
system("docker run -d --name campfire-redis -p #{REDIS_PORT}:#{REDIS_PORT} redis:7")
57+
else
58+
puts "Couldn't start Redis"
59+
puts "Install either docker or redis and then run this command again"
60+
exit 1
61+
end
62+
end
63+
2764
puts "\n== Removing old logs and tempfiles =="
2865
system! "bin/rails log:clear tmp:clear"
2966

0 commit comments

Comments
 (0)