11#!/usr/bin/env ruby
22require "fileutils"
3+ require "socket"
4+ require "timeout"
35
6+ REDIS_PORT = 6379
7+ REDIS_HOST = "localhost"
48APP_ROOT = File . expand_path ( ".." , __dir__ )
59
610def system! ( *args )
711 system ( *args , exception : true )
812end
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+
1028if ENV [ "RAILS_ENV" ] == "production"
1129 puts "RAILS_ENV is production; bailing out"
1230 exit
1533FileUtils . 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