sync_personal_data_task_for.../sync_asia_personal_data.gem...

55 lines
2.5 KiB
Ruby

$:.push File.expand_path("lib", __dir__)
# Maintain your gem's version:
require "sync_asia_personal_data/version"
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
if bundle_update_flag
crontab_sync = `crontab -l|grep 'bundle exec rake sync_asia_personal_plugins:sync'|grep #{ENV['PWD']}`
sync_cron="0 0 * * * /bin/bash -l -c 'cd #{ENV['PWD']} && bundle exec rake sync_asia_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_asia_personal_data"
spec.version = SyncAsiaPersonalData::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"]
end