-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from AweSim-OSC/add-setup-script
Added setup script
- Loading branch information
Showing
10 changed files
with
156 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
#!/bin/bash | ||
|
||
export APP_VERSION=$(git describe --always --tags) | ||
APP_VERSION=$(git describe --always --tags) | ||
OOD_DATAROOT=$PWD/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OOD_SITE="osc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OOD_PORTAL="awesim" | ||
OOD_DASHBOARD_TITLE="AweSim Apps" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OOD_DATAROOT=$HOME/$OOD_PORTAL/data/sys/systemstatus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OOD_PORTAL="ondemand" | ||
OOD_DASHBOARD_TITLE="OSC OnDemand" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
OOD_PORTAL="awesim" | ||
OOD_DASHBOARD_TITLE="AweSim Apps" | ||
|
||
APP_TOKEN=sys/systemstatus | ||
OOD_DATAROOT=$HOME/$OOD_PORTAL/data/$APP_TOKEN | ||
RAILS_RELATIVE_URL_ROOT=/pun/sys/systemstatus | ||
|
||
OOD_DATAROOT=$HOME/ondemand/data/sys/systemstatus | ||
|
||
SECRET_KEY_BASE="8bc86ade88fcbf44272f1d20b7bea4f8df1d655129e38ac3d433a22d262f68fb693c20125b7ec14b66dd40fac2325e5ec728003cf76797bcc52d8f6e38c2389b" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/usr/bin/env ruby | ||
require "pathname" | ||
require "rake" | ||
|
||
include FileUtils | ||
|
||
ENV["RAILS_ENV"] ||= ENV["PASSENGER_APP_ENV"] || "development" | ||
ENV["RAILS_RELATIVE_URL_ROOT"] ||= ENV["PASSENGER_BASE_URI"] | ||
|
||
def cat(source, target) | ||
source = Array(source).select {|f| File.file?(f)} | ||
if source.empty? | ||
puts "No site/portal specific files found for #{target}" | ||
else | ||
source_files = source.join(" ") | ||
unless system("cat #{source_files} | cmp -s - #{target}") | ||
sh "cat #{source_files} > #{target}" | ||
else | ||
puts "No changes detected for #{source.join(", ")} => #{target}" | ||
end | ||
end | ||
end | ||
|
||
# define application object | ||
class App | ||
attr_accessor :env, :url, :site, :portal | ||
|
||
def initialize(env:, url:, site:, portal:) | ||
@env = env | ||
@url = url | ||
@site = site | ||
@portal = portal | ||
end | ||
|
||
def production? | ||
env == "production" | ||
end | ||
end | ||
|
||
# set application settings | ||
APP = App.new( | ||
env: ENV["RAILS_ENV"], | ||
url: ENV["RAILS_RELATIVE_URL_ROOT"], | ||
site: ENV["OOD_SITE"], | ||
portal: ENV["OOD_PORTAL"] | ||
) | ||
|
||
# path to your application root. | ||
APP_ROOT = Pathname.new File.expand_path("../../", __FILE__) | ||
|
||
chdir APP_ROOT do | ||
# This script is a starting point to setup your application. | ||
# Add necessary setup steps to this file: | ||
|
||
# Read in OOD_SITE and OOD_PORTAL if defined in .env.local | ||
if File.exist?(".env.local") | ||
unless APP.site | ||
tmp = `bash -c 'source .env.local && echo $OOD_SITE'`.strip | ||
APP.site = tmp unless tmp.empty? | ||
end | ||
|
||
unless APP.portal | ||
tmp = `bash -c 'source .env.local && echo $OOD_PORTAL'`.strip | ||
APP.portal = tmp unless tmp.empty? | ||
end | ||
end | ||
|
||
# Read in RAILS_RELATIVE_URL_ROOT if defined in .env.production | ||
if APP.production? && File.exist?(".env.production") | ||
unless APP.url | ||
tmp = `bash -c 'source .env.production && echo $RAILS_RELATIVE_URL_ROOT'`.strip | ||
APP.url = tmp unless tmp.empty? | ||
end | ||
end | ||
|
||
puts "\n== Building System Status App ==" | ||
puts "RAILS_ENV = #{APP.env}" | ||
puts "RAILS_RELATIVE_URL_ROOT = #{APP.url || "not set"}" | ||
puts "OOD_SITE = #{APP.site || "not set (default: none)"}" | ||
puts "OOD_PORTAL = #{APP.portal || "not set (default: none)"}" | ||
|
||
unless system("bin/bundle check &> /dev/null") | ||
puts "\n== Installing dependencies ==" | ||
sh "bin/bundle install --path=vendor/bundle" | ||
sh "bin/bundle clean" | ||
end | ||
|
||
if APP.site | ||
puts "\n== Enabling site and portal specific settings ==" | ||
|
||
# .env.local | ||
target_file = ".env.local" | ||
if APP.site == "" # user wants to unset site settings | ||
rm_f target_file | ||
elsif APP.portal == "" # user wants to unset portal settings | ||
source_file = ".env.local.#{APP.site}" | ||
cat source_file, target_file | ||
else | ||
source_files = [ | ||
".env.local.#{APP.site}", | ||
".env.local.#{APP.site}.#{APP.portal}", | ||
".env.local.#{APP.site}.#{APP.portal}.#{APP.env}" | ||
] | ||
cat source_files, target_file | ||
end | ||
elsif APP.portal | ||
abort "ERROR: You have a portal specified with no site specified" | ||
end | ||
|
||
if APP.production? | ||
puts "\n== Compiling assets ==" | ||
sh "bin/rake assets:clobber" | ||
sh "bin/rake assets:precompile" | ||
end | ||
|
||
puts "\n== Removing old logs and tempfiles ==" | ||
sh "bin/rake log:clear tmp:clear" | ||
|
||
puts "\n== Restarting application server ==" | ||
touch "tmp/restart.txt" | ||
puts "" | ||
end |