This commit is contained in:
BoHung Chiu 2022-08-23 13:30:17 +08:00
parent 8b13101c08
commit 00b1ed264f
1 changed files with 25 additions and 22 deletions

View File

@ -2,29 +2,32 @@ $:.push File.expand_path("lib", __dir__)
# Maintain your gem's version:
require "sync_asia_personal_data/version"
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,"")
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
%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
# Describe your gem and declare its dependencies:
Gem::Specification.new do |spec|