2020-04-05 14:38:26 +00:00
|
|
|
# encoding: UTF-8
|
2014-04-01 07:12:43 +00:00
|
|
|
$:.push File.expand_path("../lib", __FILE__)
|
|
|
|
|
|
|
|
# Maintain your gem's version:
|
|
|
|
require "announcement/version"
|
2021-04-07 08:12:42 +00:00
|
|
|
require 'json'
|
2021-11-18 01:34:36 +00:00
|
|
|
require 'yaml'
|
2021-04-26 08:18:16 +00:00
|
|
|
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
|
|
|
|
if bundle_update_flag
|
2021-07-13 11:39:43 +00:00
|
|
|
env_pwd = ENV['PWD']
|
2021-07-13 11:37:00 +00:00
|
|
|
if File.exist?("#{env_pwd}/app/models/google.rb")
|
|
|
|
system("rm -f #{env_pwd}/app/models/google.rb")
|
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
app_path = File.expand_path(__dir__)
|
|
|
|
template_path = env_pwd + '/app/templates'
|
|
|
|
all_template = Dir.glob(template_path+'/*/')
|
|
|
|
puts 'editing files for sassc'
|
|
|
|
new_gemfile_text = File.read(app_path+'/temp_file/Gemfile')
|
|
|
|
old_gemfile_text = File.read(env_pwd+'/Gemfile')
|
|
|
|
check_texts = ['@import "../../bootstrap/variables";',".response-content {\n justify-self: auto;\n}\n"]
|
|
|
|
git_url = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git config --get remote.origin.url].split("\n")[0]}
|
|
|
|
git_remote = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git remote].split("\n")[0]}
|
|
|
|
if git_url != 'http://ruling.digital/git'
|
|
|
|
puts 'changing remote url'
|
|
|
|
Bundler.with_clean_env{system("cd #{env_pwd} && git remote set-url #{git_remote} http://ruling.digital/git")}
|
|
|
|
end
|
|
|
|
default_announcement_widget_info = JSON.parse(File.read("#{app_path}/modules/announcement/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
|
|
|
all_template.each do |folder|
|
|
|
|
if !folder.include?('mobile')
|
|
|
|
begin
|
|
|
|
if folder.split('/')[-1] != 'mobile'
|
|
|
|
unity_text = File.open(folder+'assets/stylesheets/template/base/_unity.scss','r:UTF-8') do |f|
|
|
|
|
f.read
|
|
|
|
end rescue ''
|
|
|
|
if unity_text.split(/\n/).join.strip.empty?
|
|
|
|
File.open(folder+'assets/stylesheets/template/base/_unity.scss', 'a') do |file|
|
|
|
|
file.puts "@charset \"utf-8\";\n\n@import \"variables\";\n\n// Title\n.unity-title {\n margin: 0.5em 0;\n line-height: 1.5;\n font-family: $main-font;\n font-size: $font-h1;\n\n .layout-footer & {\n margin-bottom: 10px;\n border-bottom: none;\n\n span {\n display: inline;\n margin-bottom: 0;\n border-bottom: none;\n }\n }\n}\n\n.status {\n font-family: $main-font;\n font-size: 0.75rem;\n}\n\n.status-top {\n background-color: $theme-color-second;\n}\n\n.status-hot {\n background-color: $theme-color-third;\n}\n\n.status-source {\n background-color: $theme-color-main;\n\n a {\n color: $theme-white;\n }\n}\n"
|
|
|
|
end
|
2020-02-25 13:08:08 +00:00
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
filename = folder+'assets/stylesheets/template/base/_variables.scss'
|
|
|
|
texts = File.open(filename,'r:UTF-8') do |f|
|
|
|
|
f.read
|
|
|
|
end.force_encoding('UTF-8')
|
|
|
|
s1 = texts.scan(/{|}/)
|
|
|
|
if s1.count % 2 != 0
|
|
|
|
i = texts.rindex(s1[-1])
|
|
|
|
texts[i] = ""
|
2020-02-25 13:08:08 +00:00
|
|
|
end
|
2021-08-13 05:03:51 +00:00
|
|
|
regex_pattern = /((?=^)[ \t\r\n]*)*\.response-content {\n justify-self: auto;\n}[\r\n]*|((?=^)[ \t\r\n]*)*\.response-content {\n position: static;\n}[\r\n]*|((?=^)[ \t\r\n]*)*\.response-content {\n position: relative;\n}[\r\n]*/m #|((?=^)[ \t\r\n]*)*\.response-content[^{]*{[^}]*@media[^{]*{[^{]*}[^{]*@media[^{]*{[^{]*}[^}]*}[^}]*}
|
2021-04-26 08:18:16 +00:00
|
|
|
if !texts.include? "$font-h1:"
|
|
|
|
texts = "$font-h1: 1.5rem;\n$font-h2: 1.35rem;\n$font-h3: 1.2rem;\n$font-h4: 1.1rem;\n$font-h5: 1rem;\n$font-h6: 0.9rem;\n\n" + texts
|
2020-02-25 13:08:08 +00:00
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
if !texts.include? "$main-font:"
|
|
|
|
texts = "$main-font: Arial, \"微軟正黑體\", \"Helvetica Neue\", Helvetica, sans-serif;\n" + texts
|
|
|
|
end
|
|
|
|
if !texts.include? "$theme-white"
|
|
|
|
texts = "$theme-white: #fff;\n" + texts
|
|
|
|
end
|
|
|
|
File.open(filename,'w') do |f|
|
|
|
|
f.write texts
|
|
|
|
end
|
|
|
|
tp_text = File.read(folder+'assets/stylesheets/template/template.scss').force_encoding('UTF-8') rescue ''
|
|
|
|
tp_last_text = tp_text
|
|
|
|
tp_text.scan(/@import.*http.*;/).each do |pat|
|
|
|
|
if pat.scan(/@import\W+url/).count==0
|
|
|
|
pat1 = pat.sub(/@import\W/,"@import url(")
|
|
|
|
pat1 = pat1.sub(/;/,");")
|
|
|
|
tp_last_text = tp_last_text.sub(pat,pat1)
|
|
|
|
end
|
2020-02-25 13:08:08 +00:00
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
if tp_last_text != tp_text
|
|
|
|
File.open(folder+'assets/stylesheets/template/template.scss','w') do |f|
|
|
|
|
f.write tp_last_text
|
|
|
|
end
|
2020-02-25 13:08:08 +00:00
|
|
|
end
|
2021-09-14 05:33:21 +00:00
|
|
|
texts = texts.gsub(/\n{2,}/,"\n")
|
2021-08-13 04:42:14 +00:00
|
|
|
auto_save_array = texts.scan(regex_pattern)
|
|
|
|
if auto_save_array.count > 1
|
|
|
|
auto_save_text = auto_save_array.join('')
|
2021-04-26 08:18:16 +00:00
|
|
|
File.open(folder+'assets/stylesheets/template/base/_autobackup.bak', 'a') do |file|
|
|
|
|
file.puts auto_save_text
|
|
|
|
end
|
2021-08-13 05:03:51 +00:00
|
|
|
texts = texts.gsub(regex_pattern,"")
|
2021-04-26 08:18:16 +00:00
|
|
|
File.open(filename, 'w') do |file|
|
2021-08-13 04:42:14 +00:00
|
|
|
file.write (texts)
|
2021-04-26 08:18:16 +00:00
|
|
|
end
|
2021-08-13 04:42:14 +00:00
|
|
|
end
|
|
|
|
check_texts.each do |check_text|
|
|
|
|
if !texts.include?(check_text)
|
|
|
|
puts "editing #{folder}assets/stylesheets/template/base/_variables.scss"
|
2021-08-13 04:46:36 +00:00
|
|
|
texts = texts + "\n" + check_text
|
2021-08-13 04:42:14 +00:00
|
|
|
File.open(filename, 'w') do |file|
|
|
|
|
file.write(texts)
|
2020-02-25 13:08:08 +00:00
|
|
|
end
|
2020-02-14 14:31:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
rescue => e
|
|
|
|
puts "not found #{folder}assets/stylesheets/template/base/_variables.scss"
|
2020-02-14 14:31:52 +00:00
|
|
|
end
|
2021-04-07 08:12:42 +00:00
|
|
|
begin
|
2021-04-26 08:18:16 +00:00
|
|
|
puts "updating announcement show page"
|
|
|
|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/announcement/show.html.erb #{folder}modules/announcement/show.html.erb]}
|
|
|
|
rescue
|
|
|
|
puts "There has some error in updating announcement show page"
|
|
|
|
end
|
|
|
|
info_json_file = "#{folder}modules/announcement/info.json"
|
|
|
|
if File.exist?(info_json_file)
|
|
|
|
begin
|
|
|
|
file_text = File.read(info_json_file) rescue ""
|
|
|
|
encode_file_text = file_text.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???")
|
|
|
|
next if (encode_file_text.include?("???") rescue true)
|
|
|
|
info = JSON.parse(encode_file_text) rescue {}
|
|
|
|
flag = (info.count != 0 rescue false)
|
|
|
|
if flag
|
|
|
|
puts "Checking announcement widgets"
|
|
|
|
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
|
|
|
update_flag = false
|
|
|
|
last_index = widget_info[-1]["filename"].match(/\d+/)[0].to_i rescue nil
|
|
|
|
if !last_index.nil?
|
2021-09-06 05:53:11 +00:00
|
|
|
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
|
2021-04-26 08:18:16 +00:00
|
|
|
default_announcement_widget_info.each do |h|
|
2021-09-06 05:53:11 +00:00
|
|
|
name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'')
|
|
|
|
widget_info_index = (widget_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1)
|
2021-06-09 06:38:43 +00:00
|
|
|
if (widget_info_index == -1 || widget_info_index.nil?)
|
2021-04-26 08:18:16 +00:00
|
|
|
update_flag = true
|
|
|
|
copy_h = h.dup
|
2021-05-19 13:54:38 +00:00
|
|
|
h.delete("force_cover")
|
2021-04-26 08:18:16 +00:00
|
|
|
last_index = last_index + 1
|
|
|
|
copy_h["filename"] = copy_h["filename"].sub(/\d+/){|ff| last_index.to_s}
|
|
|
|
copy_h["name"].keys.each do |locale|
|
|
|
|
copy_h["name"][locale] = copy_h["name"][locale].sub(/\d+/){|ff| last_index.to_s}
|
|
|
|
end
|
|
|
|
widget_info << copy_h
|
|
|
|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/announcement/_#{h["filename"]}.html.erb #{folder}modules/announcement/_#{copy_h["filename"]}.html.erb]}
|
2021-05-19 13:54:38 +00:00
|
|
|
elsif h["force_cover"] == "true"
|
|
|
|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/announcement/_#{h["filename"]}.html.erb #{folder}modules/announcement/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
if update_flag
|
|
|
|
info["widgets"] = widget_info
|
|
|
|
puts "Writing json #{info["widgets"].count} in #{info_json_file}"
|
|
|
|
begin
|
|
|
|
info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n")
|
|
|
|
rescue
|
|
|
|
info_json = info.to_s.gsub("=>",": \n")
|
|
|
|
end
|
|
|
|
File.open(info_json_file,"w+"){|f| f.write(info_json)}
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
2021-11-12 06:32:00 +00:00
|
|
|
Bundler.with_clean_env{%x[cp -rn #{app_path}/modules/announcement/thumbs/* #{folder}modules/announcement/thumbs/.]}
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
rescue => e
|
|
|
|
puts e
|
|
|
|
puts "There has some error when checking announcement widgets"
|
2021-04-07 08:12:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-14 14:31:52 +00:00
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
if old_gemfile_text != new_gemfile_text
|
|
|
|
unicorn_rails = %x[which unicorn_rails].sub("\n",'')
|
|
|
|
puts 'updating gemfile'
|
2021-11-17 11:43:53 +00:00
|
|
|
if Dir["#{env_pwd}/config/secrets.yml"].length==0
|
|
|
|
r = open("#{env_pwd}/config/environment.rb",'r'){|f| f.read()}
|
|
|
|
secret_key = r.scan(/Orbit::Application\.config\.secret_key_base = '(.*)'/).flatten[0] rescue nil
|
|
|
|
if !secret_key.nil?
|
2021-11-18 01:33:12 +00:00
|
|
|
open("#{env_pwd}/config/secrets.yml",'w+') do |f|
|
2021-11-18 01:34:36 +00:00
|
|
|
c = {"production"=> {"secret_key_base"=> secret_key},"development"=> {"secret_key_base"=> secret_key}}
|
|
|
|
c = c.to_yaml.sub("---\n",'')
|
2021-11-17 11:43:53 +00:00
|
|
|
f.write(c)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
Bundler.with_clean_env{%x[cp -f '#{env_pwd}'/Gemfile '#{env_pwd}'/Gemfile.bak123]}
|
|
|
|
Bundler.with_clean_env{%x[cp -f '#{app_path}'/temp_file/Gemfile '#{env_pwd}'/Gemfile]}
|
2021-11-21 02:52:37 +00:00
|
|
|
if system("cd #{env_pwd} && git branch --contains '2f23511469505bd114df2c863a477a8730bcdefa'") #update mongoid version
|
|
|
|
command4 = ""
|
2021-11-21 02:55:04 +00:00
|
|
|
puts 'mongoid has been updated!'
|
2021-11-21 02:52:37 +00:00
|
|
|
else
|
2021-11-27 05:45:01 +00:00
|
|
|
command4 = ";mv #{env_pwd}/app/controllers/sessions_controller.rb #{env_pwd}/tmp/sessions_controller_backup.rb;cp -rf #{app_path}/temp_file/app #{env_pwd};cp -rf #{app_path}/temp_file/config #{env_pwd};rm #{env_pwd}/app/models/google.rb"
|
2021-11-21 02:52:37 +00:00
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
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
|
|
|
|
if log_development > log_production
|
|
|
|
mode = 'development'
|
|
|
|
else
|
|
|
|
mode = 'production'
|
|
|
|
end
|
|
|
|
files = Dir[env_pwd+'/Gemfile.lock']
|
|
|
|
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]}
|
|
|
|
end
|
|
|
|
if %x[ruby -v].scan(/\d\.\d\.\d/)[0] == '2.1.3'
|
|
|
|
install_cmd = 'rvm install 2.1.10 && rvm use default 2.1.10;'
|
|
|
|
use_cmd = 'source ~/.rvm/scripts/rvm && rvm use 2.1.10 --default;'
|
|
|
|
else
|
|
|
|
install_cmd = ''
|
|
|
|
use_cmd = ''
|
|
|
|
end
|
|
|
|
#if files.count ==0
|
|
|
|
# command1 = "gem install bundler -v 1.17.3 ; bundle update --all"
|
|
|
|
#else
|
|
|
|
command1 = "gem install bundler -v 1.17.3 ; bundle update --all"
|
|
|
|
#end
|
|
|
|
filedata = File.read(env_pwd+"/built_in_extensions.rb")
|
|
|
|
exist_str = "gem 'patchfile', git: 'http://gitlab.tp.rulingcom.com/chiu/patch_file.git'"
|
|
|
|
if filedata.include? exist_str
|
|
|
|
puts "patchfile exist"
|
|
|
|
else
|
|
|
|
file = env_pwd+"/built_in_extensions.rb"
|
|
|
|
open(file, 'a') { |f|
|
|
|
|
f.puts exist_str
|
|
|
|
}
|
|
|
|
end
|
|
|
|
all_command = "#{install_cmd} #{command1} #{command4} "
|
|
|
|
watch_dog_cmd = "watch -n 30 \'unset UNICORN_FD && bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}\'"
|
|
|
|
#file = File.new(File.join(env_pwd,'bundle_update_background.sh'),"w")
|
|
|
|
#file.write(all_command)
|
|
|
|
#file.chmod(0755)
|
|
|
|
#file.close
|
2021-08-20 04:26:50 +00:00
|
|
|
restart_cmd = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s TERM $UNICORN_PID ; while (kill -0 $UNICORN_PID > /dev/null 2>&1) ; do printf '.' && sleep 1 ; done ; unset UNICORN_FD; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{mode}"
|
2021-08-11 08:16:21 +00:00
|
|
|
|
2021-04-26 08:18:16 +00:00
|
|
|
a = Thread.start do
|
|
|
|
Bundler.with_clean_env do
|
|
|
|
puts env_pwd
|
|
|
|
puts mode
|
2021-08-11 08:16:21 +00:00
|
|
|
exec("cd #{env_pwd} && env -i HOME=\"$HOME\" bash -l -c \"#{all_command}\" ;screen -d -m -S auto_reopen_#{dir_name} bash -c \"#{use_cmd} #{restart_cmd};#{watch_dog_cmd}\" ")
|
2021-04-26 08:18:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
now_priority = Thread.current.priority.to_i
|
|
|
|
system('sleep 2')
|
|
|
|
a.priority = now_priority + 2
|
|
|
|
a.run
|
|
|
|
#Thread.exit
|
2020-02-19 10:36:14 +00:00
|
|
|
else
|
2021-04-26 08:18:16 +00:00
|
|
|
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]}
|
2020-02-14 14:31:52 +00:00
|
|
|
end
|
2021-04-26 08:18:16 +00:00
|
|
|
#system("cp -rf #{app_path}/temp_file/app #{env_pwd}")
|
2020-02-14 14:31:52 +00:00
|
|
|
end
|
2021-11-20 14:58:24 +00:00
|
|
|
c = open("#{env_pwd}/config/mongoid.yml",'r'){|f| f.read}
|
|
|
|
if c.scan(/^[ \t]*sessions\:/).length != 0
|
|
|
|
c = c.gsub(/^([ \t]*)sessions\:/,'\1clients:')
|
|
|
|
r = YAML.load(c)
|
|
|
|
r.each do |mode,v1|
|
|
|
|
v1.each do |clients,d|
|
|
|
|
d.each do |k,v|
|
2021-11-26 03:49:39 +00:00
|
|
|
next if v.class != Hash
|
2021-11-20 15:06:16 +00:00
|
|
|
if !v["username"].nil?
|
|
|
|
if v["options"].nil?
|
2021-11-20 14:58:24 +00:00
|
|
|
v["options"] = {}
|
|
|
|
end
|
|
|
|
v["options"]["user"] = v["username"]
|
|
|
|
v.delete "username"
|
|
|
|
end
|
2021-11-20 15:06:16 +00:00
|
|
|
if !v["password"].nil?
|
2021-11-21 04:14:44 +00:00
|
|
|
if v["options"].nil?
|
2021-11-20 14:58:24 +00:00
|
|
|
v["options"] = {}
|
|
|
|
end
|
|
|
|
v["options"]["password"] = v["password"]
|
|
|
|
v.delete "password"
|
|
|
|
end
|
2021-11-20 15:06:16 +00:00
|
|
|
if !v["options"].nil? && !v["options"]["pool_size"].nil?
|
2021-11-20 14:58:24 +00:00
|
|
|
v["options"]["max_pool_size"] = v["options"]["pool_size"]
|
|
|
|
v["options"].delete "pool_size"
|
|
|
|
end
|
2021-11-20 15:06:16 +00:00
|
|
|
if !v["options"].nil? && v["options"]["read"].class == String
|
2021-11-20 15:07:42 +00:00
|
|
|
v["options"]["read"] = {"mode"=> v["options"]["read"]}
|
2021-11-20 14:58:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
c = YAML.dump(r).sub("---\n",'')
|
|
|
|
open("#{env_pwd}/config/mongoid.yml",'w+'){|f| f.write(c)}
|
|
|
|
end
|
2020-02-14 14:31:52 +00:00
|
|
|
end
|
2014-04-01 07:12:43 +00:00
|
|
|
# Describe your gem and declare its dependencies:
|
|
|
|
Gem::Specification.new do |s|
|
|
|
|
s.name = "announcement"
|
|
|
|
s.version = Announcement::VERSION
|
|
|
|
s.authors = ["RulingDigital"]
|
|
|
|
s.email = ["orbit@rulingcom.com"]
|
|
|
|
s.homepage = "http://www.rulingcom.com"
|
|
|
|
s.summary = "Announcements for Orbit"
|
|
|
|
s.description = "Announcements for Orbit"
|
|
|
|
s.license = "MIT"
|
|
|
|
|
|
|
|
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
|
|
|
|
s.test_files = Dir["test/**/*"]
|
2019-10-09 08:43:37 +00:00
|
|
|
|
|
|
|
s.add_dependency "rufus-scheduler", "~> 3.6.0"
|
2021-03-29 05:31:23 +00:00
|
|
|
s.add_dependency "mimemagic" , "0.3.9"
|
2014-04-01 07:12:43 +00:00
|
|
|
end
|