85 lines
3.7 KiB
Ruby
85 lines
3.7 KiB
Ruby
$:.push File.expand_path("lib", __dir__)
|
|
|
|
# Maintain your gem's version:
|
|
require "sync_nccu_personal_data/version"
|
|
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
|
|
if bundle_update_flag
|
|
env_pwd = ENV['PWD']
|
|
begin
|
|
require ::File.expand_path('app/helpers/bundler_helper.rb', env_pwd)
|
|
extend BundlerHelper
|
|
rescue LoadError
|
|
def bundler_with_clean_env(&block)
|
|
if block_given?
|
|
if Bundler.respond_to?(:with_unbundled_env)
|
|
Bundler.with_unbundled_env(&block)
|
|
else
|
|
Bundler.with_clean_env(&block)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
home_path = ENV['HOME']
|
|
ENV['FREETDS_DIR'] = "#{home_path}/freetds-1.1.24_build"
|
|
if Dir.glob("#{ENV["GEM_HOME"]}/gems/tiny_tds-*").count == 0 || Dir.glob("#{ENV["GEM_HOME"]}/extensions/*/*/tiny_tds-*/tiny_tds/*").count == 0
|
|
app_path = File.expand_path(__dir__)
|
|
if home_path.nil? || home_path == ""
|
|
home_path = app_path
|
|
else
|
|
require "fileutils"
|
|
FileUtils.rm_r("#{home_path}/freetds-1.1.24_build", :force => true)
|
|
FileUtils.cp_r("#{app_path}/freetds-1.1.24_build/", "#{home_path}/.")
|
|
end
|
|
FileUtils.chmod_R( 0755, Dir.glob("#{home_path}/freetds-1.1.24_build/bin/*"))
|
|
puts "Installing tiny_tds gem ..."
|
|
bundler_with_clean_env{ system("gem install tiny_tds -- '--with-freetds-dir=#{home_path}/freetds-1.1.24_build'") }
|
|
end
|
|
crontab_sync = `crontab -l|grep 'bundle exec rake sync_nccu_personal_plugins:sync'|grep #{ENV['PWD']}`
|
|
sync_cron="0 0 * * * /bin/bash -l -c 'cd #{ENV['PWD']} && bundle exec rake sync_nccu_personal_plugins:sync > /dev/null'"
|
|
crontab_sync_jobs = crontab_sync.split("\n")
|
|
if crontab_sync_jobs.count == 0
|
|
%x(CRON="#{sync_cron}" && (crontab -l; echo "$CRON" ) | crontab -)
|
|
elsif crontab_sync_jobs.count > 1
|
|
crontab_jobs = `crontab -l`
|
|
crontab_sync_jobs[1..-1].each do |s|
|
|
crontab_jobs = crontab_jobs.sub(s,"")
|
|
end
|
|
%x(CRON="#{crontab_jobs}" && (echo "$CRON" ) | crontab -)
|
|
elsif crontab_sync_jobs[0][0...3] == "0 5" #replace old cronjob settings
|
|
crontab_jobs = `crontab -l`
|
|
crontab_jobs = crontab_jobs.sub(crontab_sync_jobs[0],sync_cron)
|
|
%x(CRON="#{crontab_jobs}" && (echo "$CRON" ) | crontab -)
|
|
elsif crontab_sync_jobs[0].include?("-23/12") #replace 12 hours to 24 hours
|
|
crontab_jobs = `crontab -l`
|
|
crontab_jobs = crontab_jobs.sub(crontab_sync_jobs[0],crontab_sync_jobs[0].sub("-23/12",""))
|
|
%x(CRON="#{crontab_jobs}" && (echo "$CRON" ) | crontab -)
|
|
elsif crontab_sync_jobs[0].include?("*/12") #replace 12 hours to 24 hours
|
|
crontab_jobs = `crontab -l`
|
|
crontab_jobs = crontab_jobs.sub(crontab_sync_jobs[0],crontab_sync_jobs[0].sub("*/12","0"))
|
|
%x(CRON="#{crontab_jobs}" && (echo "$CRON" ) | crontab -)
|
|
end
|
|
end
|
|
# Describe your gem and declare its dependencies:
|
|
Gem::Specification.new do |spec|
|
|
spec.name = "sync_nccu_personal_data"
|
|
spec.version = SyncNccuPersonalData::VERSION
|
|
spec.authors = ["Bohung Chiu"]
|
|
spec.email = ["bohung@rulingcom.com"]
|
|
spec.homepage = "https://w3.rulingcom.com/"
|
|
spec.summary = "Sync Asia University's personal data for teachers"
|
|
spec.description = "Sync Asia University's personal data for teachers"
|
|
spec.license = "MIT"
|
|
|
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
if spec.respond_to?(:metadata)
|
|
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
else
|
|
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
"public gem pushes."
|
|
end
|
|
|
|
spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
|
spec.add_dependency "tiny_tds"
|
|
end
|