fix error of changing directory
This commit is contained in:
parent
b6ee458f20
commit
e7c798ecd5
|
@ -2,29 +2,30 @@ $:.push File.expand_path("../lib", __FILE__)
|
||||||
|
|
||||||
# Maintain your gem's version:
|
# Maintain your gem's version:
|
||||||
require "announcement/version"
|
require "announcement/version"
|
||||||
|
env_pwd = ENV['PWD']
|
||||||
app_path = File.expand_path(__dir__)
|
app_path = File.expand_path(__dir__)
|
||||||
template_path = ENV['PWD'] + '/app/templates'
|
template_path = env_pwd + '/app/templates'
|
||||||
all_template = Dir.glob(template_path+'/*/')
|
all_template = Dir.glob(template_path+'/*/')
|
||||||
puts 'editing files for sassc'
|
puts 'editing files for sassc'
|
||||||
new_gemfile_text = File.read(app_path+'/temp_file/Gemfile')
|
new_gemfile_text = File.read(app_path+'/temp_file/Gemfile')
|
||||||
old_gemfile_text = File.read(ENV['PWD']+'/Gemfile')
|
old_gemfile_text = File.read(env_pwd+'/Gemfile')
|
||||||
check_texts = ['@import "../../bootstrap/variables";',".response-content {\n position: relative;\n\n @media (min-width: $screen-sm) {\n width: 100%;\n }\n\n @media (min-width: $screen-md) {\n width: 970px;\n }\n\n @media (min-width: $screen-lg) {\n width: 1100px;\n }\n}\n"]
|
check_texts = ['@import "../../bootstrap/variables";',".response-content {\n position: relative;\n\n @media (min-width: $screen-sm) {\n width: 100%;\n }\n\n @media (min-width: $screen-md) {\n width: 970px;\n }\n\n @media (min-width: $screen-lg) {\n width: 1100px;\n }\n}\n"]
|
||||||
git_url = %x[cd '#{ENV['PWD']}' && git config --get remote.origin.url].sub("\n",'')
|
git_url = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git config --get remote.origin.url].sub("\n",'')}
|
||||||
git_remote = %x[cd '#{ENV['PWD']}' && git remote].sub("\n",'')
|
git_remote = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git remote].sub("\n",'')}
|
||||||
if git_url != 'https://ruling.digital/git'
|
if git_url != 'https://ruling.digital/git'
|
||||||
puts 'changing remote url'
|
puts 'changing remote url'
|
||||||
system("cd #{ENV['PWD']} && git remote set-url #{git_remote} https://ruling.digital/git")
|
Bundler.with_clean_env{system("cd #{env_pwd} && git remote set-url #{git_remote} https://ruling.digital/git")}
|
||||||
end
|
end
|
||||||
all_template.each do |folder|
|
all_template.each do |folder|
|
||||||
if !folder.include?('mobile')
|
if !folder.include?('mobile')
|
||||||
begin
|
begin
|
||||||
if folder.split('/')[-1] != 'mobile'
|
if folder.split('/')[-1] != 'mobile'
|
||||||
@filename = folder+'assets/stylesheets/template/base/_variables.scss'
|
filename = folder+'assets/stylesheets/template/base/_variables.scss'
|
||||||
texts = File.read(@filename)
|
texts = File.read(filename)
|
||||||
check_texts.each do |check_text|
|
check_texts.each do |check_text|
|
||||||
if !texts.include?(check_text)
|
if !texts.include?(check_text)
|
||||||
puts "editing #{folder}assets/stylesheets/template/base/_variables.scss"
|
puts "editing #{folder}assets/stylesheets/template/base/_variables.scss"
|
||||||
File.open(@filename, 'a') do |file|
|
File.open(filename, 'a') do |file|
|
||||||
file.puts check_text
|
file.puts check_text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -38,59 +39,62 @@ end
|
||||||
if old_gemfile_text != new_gemfile_text
|
if old_gemfile_text != new_gemfile_text
|
||||||
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
|
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
|
||||||
puts 'updating gemfile'
|
puts 'updating gemfile'
|
||||||
%x[cp -f '#{ENV['PWD']}'/Gemfile '#{ENV['PWD']}'/Gemfile.bak123]
|
Bundler.with_clean_env{%x[cp -f '#{env_pwd}'/Gemfile '#{env_pwd}'/Gemfile.bak123]}
|
||||||
%x[cp -f '#{app_path}'/temp_file/Gemfile '#{ENV['PWD']}'/Gemfile]
|
Bundler.with_clean_env{%x[cp -f '#{app_path}'/temp_file/Gemfile '#{env_pwd}'/Gemfile]}
|
||||||
old_playground = File.read (ENV['PWD']+'/app/controllers/admin/playground_controller.rb') rescue ''
|
old_playground = File.read (env_pwd+'/app/controllers/admin/playground_controller.rb') rescue ''
|
||||||
new_playground = File.read (app_path+'/temp_file/playground_controller.rb') rescue ''
|
new_playground = File.read (app_path+'/temp_file/playground_controller.rb') rescue ''
|
||||||
command2 = ''
|
command2 = ''
|
||||||
if old_playground != new_playground
|
if old_playground != new_playground
|
||||||
puts 'updating playground'
|
puts 'updating playground'
|
||||||
command2 = "cp -f #{app_path}/temp_file/playground_controller.rb #{ENV['PWD']}/app/controllers/admin/playground_controller.rb ;"
|
command2 = "cp -f #{app_path}/temp_file/playground_controller.rb #{env_pwd}/app/controllers/admin/playground_controller.rb ;"
|
||||||
#File.open(ENV['PWD']+'/app/controllers/admin/playground_controller.rb', 'w') do |file|
|
#File.open(ENV['PWD']+'/app/controllers/admin/playground_controller.rb', 'w') do |file|
|
||||||
# file.write new_playground
|
# file.write new_playground
|
||||||
#end
|
#end
|
||||||
end
|
end
|
||||||
old_multithread = File.read (ENV['PWD']+'/app/models/multithread.rb') rescue ''
|
old_multithread = File.read (env_pwd+'/app/models/multithread.rb') rescue ''
|
||||||
new_multithread = File.read (app_path+'/temp_file/multithread.rb') rescue ''
|
new_multithread = File.read (app_path+'/temp_file/multithread.rb') rescue ''
|
||||||
command3 = ''
|
command3 = ''
|
||||||
if old_multithread != new_multithread
|
if old_multithread != new_multithread
|
||||||
puts 'updating multithread'
|
puts 'updating multithread'
|
||||||
command3 = "cp -f #{app_path}/temp_file/multithread.rb #{ENV['PWD']}/app/models/multithread.rb ;"
|
command3 = "cp -f #{app_path}/temp_file/multithread.rb #{env_pwd}/app/models/multithread.rb ;"
|
||||||
#File.open(ENV['PWD']+'/app/models/multithread.rb', 'w') do |file|
|
#File.open(ENV['PWD']+'/app/models/multithread.rb', 'w') do |file|
|
||||||
# file.write new_multithread
|
# file.write new_multithread
|
||||||
#end
|
#end
|
||||||
end
|
end
|
||||||
command4 = "cp -rf #{app_path}/temp_file/app #{ENV['PWD']}/app"
|
command4 = "cp -rf #{app_path}/temp_file/app #{env_pwd}/app"
|
||||||
log_development = File.mtime(ENV['PWD']+'/log/development.log').strftime('%Y%m%d%H%M').to_i rescue 0
|
log_development = File.mtime(env_pwd+'/log/development.log').strftime('%Y%m%d%H%M').to_i rescue 0
|
||||||
log_production = File.mtime(ENV['PWD']+'/log/production.log').strftime('%Y%m%d%H%M').to_i rescue 0
|
log_production = File.mtime(env_pwd+'/log/production.log').strftime('%Y%m%d%H%M').to_i rescue 0
|
||||||
if log_development > log_production
|
if log_development > log_production
|
||||||
mode = 'development'
|
mode = 'development'
|
||||||
else
|
else
|
||||||
mode = 'production'
|
mode = 'production'
|
||||||
end
|
end
|
||||||
files = Dir[ENV['PWD']+'/Gemfile.lock']
|
files = Dir[env_pwd+'/Gemfile.lock']
|
||||||
dir_name = ENV['PWD'].split('/')[-1]
|
dir_name = env_pwd.split('/')[-1]
|
||||||
|
watch_dog = %x[screen -ls auto_reopen_#{dir_name}]
|
||||||
|
if watch_dog.scan("auto_reopen_#{dir_name}").count != 0
|
||||||
Bundler.with_clean_env{%x[screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill]}
|
Bundler.with_clean_env{%x[screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill]}
|
||||||
if files.count ==0
|
|
||||||
command1 = "cd #{ENV['PWD']} && gem install bundler -v 1.17.3 && bundle update"
|
|
||||||
else
|
|
||||||
command1 = "cd #{ENV['PWD']} && gem install bundler -v 1.17.3 && mv -f Gemfile.lock Gemfile.lock.bak123 && bundle update"
|
|
||||||
end
|
end
|
||||||
Bundler.with_clean_env{system("screen -d -m -S auto_reopen_#{dir_name} watch -n 30 bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now")}
|
if files.count ==0
|
||||||
filedata = File.read(ENV['PWD']+"/built_in_extensions.rb")
|
command1 = "cd #{env_pwd} && gem install bundler -v 1.17.3 && bundle update"
|
||||||
|
else
|
||||||
|
command1 = "cd #{env_pwd} && gem install bundler -v 1.17.3 && mv -f Gemfile.lock Gemfile.lock.bak123 && bundle update"
|
||||||
|
end
|
||||||
|
Bundler.with_clean_env{system("cd #{env_pwd} && screen -d -m -S auto_reopen_#{dir_name} watch -n 30 bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now")}
|
||||||
|
filedata = File.read(env_pwd+"/built_in_extensions.rb")
|
||||||
exist_str = "gem 'patchfile', git: 'http://gitlab.tp.rulingcom.com/chiu/patch_file.git'"
|
exist_str = "gem 'patchfile', git: 'http://gitlab.tp.rulingcom.com/chiu/patch_file.git'"
|
||||||
if filedata.include? exist_str
|
if filedata.include? exist_str
|
||||||
puts "patchfile exist"
|
puts "patchfile exist"
|
||||||
else
|
else
|
||||||
@file = ENV['PWD']+"/built_in_extensions.rb"
|
file = env_pwd+"/built_in_extensions.rb"
|
||||||
open(@file, 'a') { |f|
|
open(file, 'a') { |f|
|
||||||
f.puts exist_str
|
f.puts exist_str
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
all_command = "#{command1} && cd #{ENV['PWD']} && #{command2} #{command3} #{command4} && kill -s TERM `cat tmp/pids/unicorn.pid`; bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now"
|
all_command = "#{command1} && cd #{env_pwd} && #{command2} #{command3} #{command4} && kill -s TERM `cat tmp/pids/unicorn.pid`; bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now"
|
||||||
a = Thread.start do
|
a = Thread.start do
|
||||||
Bundler.with_clean_env do
|
Bundler.with_clean_env do
|
||||||
puts ENV['PWD']
|
puts env_pwd
|
||||||
puts mode
|
puts mode
|
||||||
exec(all_command)
|
exec(all_command)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue