MacOS.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. module RimeDeploy
  2. class MacOSJobGroup < JobGroup
  3. InstallCmd = "brew install --cask squirrel"
  4. ConfigPath = "~/Library/Rime"
  5. class InstallRimeJob < Job
  6. def call
  7. puts intro
  8. system(InstallCmd)
  9. sleep 1
  10. return :next
  11. end
  12. end
  13. class BackupRimeConfigJob < Job
  14. def call
  15. puts intro
  16. system(
  17. "mv #{MacOSJobGroup::ConfigPath} #{MacOSJobGroup::ConfigPath}.#{Time.now.to_i}.old"
  18. )
  19. sleep 1
  20. return :next
  21. end
  22. end
  23. class CloneConfigJob < Job
  24. def call
  25. puts intro
  26. system(
  27. "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{MacOSJobGroup::ConfigPath}"
  28. )
  29. sleep 1
  30. return :next
  31. end
  32. end
  33. class CopyCustomConfigJob < Job
  34. def call
  35. puts intro
  36. system("cp ./custom/*.yaml #{MacOSJobGroup::ConfigPath}/")
  37. sleep 1
  38. return :next
  39. end
  40. end
  41. class FinishedJob < Job
  42. def call
  43. puts ""
  44. puts "Tips: When finished all jobs. You need to do follow:".yellow
  45. puts "1) Restart system."
  46. puts "2) open Rime input method setting pane and click " +
  47. "DEPLOY".yellow + " button."
  48. puts "Enjoy~ 🍻"
  49. puts "more info:".yellow
  50. puts "Config path: #{MacOSJobGroup::ConfigPath}/"
  51. return :next
  52. end
  53. end
  54. class UpgradeRimeAutoDeployJob < Job
  55. def call
  56. puts "Upgrade `Rime Auto Deploy` script ..."
  57. project_path = File.expand_path(Dir.pwd)
  58. if File.directory?(File.join(project_path, ".git"))
  59. puts "Git repository found."
  60. system("cd #{project_path} && git remote get-url origin")
  61. puts "Try upgrading..."
  62. system("cd #{project_path} && git pull")
  63. else
  64. puts "You can download the latest version from here."
  65. puts "https://github.com/Mark24Code/rime-auto-deploy"
  66. end
  67. return :next
  68. end
  69. end
  70. class UpgradeRimeConfigJob < Job
  71. def call
  72. puts "Upgrade Rime Config"
  73. config_path = File.expand_path(ConfigPath)
  74. if File.directory?(File.join(config_path, ".git"))
  75. puts "Git repository found."
  76. system("cd #{config_path} && git remote get-url origin")
  77. puts "Try upgrading..."
  78. system("cd #{config_path} && git pull")
  79. else
  80. puts "Error:".yellow
  81. puts "Rime Config seems broken. You may delete the directory.".red
  82. puts "You can:"
  83. puts "Rerun the deploy script from start choose [Auto Mode] to reinstall."
  84. puts ""
  85. puts "After 5 seconds, will go to [Upgrade Mode].".yellow
  86. sleep 5
  87. throw :halt, :run_jobs_upgrade
  88. end
  89. return :next
  90. end
  91. end
  92. self.jobs = [
  93. InstallRimeJob,
  94. BackupRimeConfigJob,
  95. CloneConfigJob,
  96. CopyCustomConfigJob
  97. ]
  98. self.upgrade_jobs = [UpgradeRimeAutoDeployJob, UpgradeRimeConfigJob]
  99. self.after_jobs = [FinishedJob]
  100. end
  101. end