bin/setup
#!/usr/bin/env ruby
require 'pathname'
require 'yaml'
# path to your application root.
APP_ROOT = Pathname.new File.expand_path("../../", __FILE__)
def run(command)
abort "command failed (#{$?}): #{command}" unless system command
end
Dir.chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file:
puts %q[
______ _____
___ / _____________ ___(_)______ _______ _________ __
__ / _ __ \_ __ `/_ /__ __ \ __ __ `/ __ \_ | / /
_ /___/ /_/ / /_/ /_ / _ / / /___ /_/ // /_/ /_ |/ /
/_____/\____/_\__, / /_/ /_/ /_/_(_)\__, / \____/_____/
/____/ /____/
]
puts '== Setting up config overrides =='
default_application_yml = { 'development' => { 'config_key' => nil } }
File.write('config/application.yml', default_application_yml.to_yaml) unless File.exist?('config/application.yml')
puts "== Linking service_providers.yml =="
run "test -r config/service_providers.yml || ln -sv service_providers.localdev.yml config/service_providers.yml"
puts "== Linking agencies.yml =="
run "test -r config/agencies.yml || ln -sv agencies.localdev.yml config/agencies.yml"
puts "== Linking Agreements YAML files =="
run "test -r config/iaa_gtcs.yml || ln -sv iaa_gtcs.localdev.yml config/iaa_gtcs.yml"
run "test -r config/iaa_orders.yml || ln -sv iaa_orders.localdev.yml config/iaa_orders.yml"
run "test -r config/iaa_statuses.yml || ln -sv iaa_statuses.localdev.yml config/iaa_statuses.yml"
run "test -r config/integration_statuses.yml || ln -sv integration_statuses.localdev.yml config/integration_statuses.yml"
run "test -r config/integrations.yml || ln -sv integrations.localdev.yml config/integrations.yml"
run "test -r config/partner_account_statuses.yml || ln -sv partner_account_statuses.localdev.yml config/partner_account_statuses.yml"
run "test -r config/partner_accounts.yml || ln -sv partner_accounts.localdev.yml config/partner_accounts.yml"
puts "== Linking sample certs and keys =="
run "test -r certs || ln -sv certs.example certs"
run "test -r keys || ln -sv keys.example keys"
puts "== Copying sample pwned passwords list =="
run "cp pwned_passwords/pwned_passwords.txt.sample pwned_passwords/pwned_passwords.txt"
puts "\n== Installing dependencies =="
brew_installed = system "brew -v 2>&1"
run "brew bundle" if brew_installed
run "gem install bundler --conservative"
run 'gem install foreman --conservative && gem update foreman'
run "bundle check || bundle install --without deploy production"
run "yarn install"
puts "\n== Stopping running services to ensure clean start =="
run "brew services stop --all" if brew_installed
puts "\n== Starting services =="
run "brew services start redis" if brew_installed
run "brew services start postgresql@14" if brew_installed
puts "\n== Preparing database =="
run 'make clobber_db'
puts "\n== Cleaning up old assets =="
run "make clobber_assets"
puts "\n== Removing old logs and tempfiles =="
run "make clobber_logs"
puts "\n== Restarting application server =="
run "mkdir -p tmp/pids"
run "touch tmp/restart.txt"
end