LinuxDistro.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. module RimeDeploy
  2. class LinuxDistroJobGroup < JobGroup
  3. ConfigPathIbus = "~/.config/ibus/rime"
  4. ConfigPathFcitx = "~/.config/fcitx/rime"
  5. ConfigPathFcitx5 = "~/.local/share/fcitx5/rime"
  6. @config_path = nil
  7. def self.config_path=(value)
  8. @config_path = value
  9. end
  10. def self.config_path
  11. @config_path
  12. end
  13. class CheckInstallRimeJob < Job
  14. def call
  15. puts "==== Rime auto deploy ====".green
  16. puts "Before Check Rime Installed Staus".yellow
  17. tips = <<-TIP
  18. Different Linux has it's own package manager. So make sure you had installed Rime before.
  19. For Fcitx5, install fcitx5-rime.
  20. For Fcitx, install fcitx-rime.
  21. For IBus, install ibus-rime.
  22. more:
  23. https://wiki.archlinux.org/title/Rime
  24. TIP
  25. puts tips
  26. puts ""
  27. puts "Then choose what your had installed."
  28. ChooseSession.new(
  29. [
  30. [
  31. "ibus-rime",
  32. -> do
  33. LinuxDistro.config_path = LinuxDistroJobGroup::ConfigPathIbus
  34. end
  35. ],
  36. [
  37. "fcitx-rime",
  38. -> do
  39. LinuxDistro.config_path = LinuxDistroJobGroup::ConfigPathFcitx
  40. end
  41. ],
  42. [
  43. "fcitx5-rime",
  44. -> do
  45. LinuxDistro.config_path = LinuxDistroJobGroup::ConfigPathFcitx5
  46. end
  47. ],
  48. [
  49. "I'll quit first.After installed Rime byself then run this program again.",
  50. -> { exit 0 }
  51. ]
  52. ]
  53. ).call
  54. sleep 1
  55. return :next
  56. end
  57. end
  58. class BackupRimeConfigJob < Job
  59. def call
  60. puts intro
  61. system(
  62. "mv #{LinuxDistro.config_path} #{LinuxDistro.config_path}.#{Time.now.to_i}.old"
  63. )
  64. sleep 1
  65. return :next
  66. end
  67. end
  68. class CloneConfigJob < Job
  69. def call
  70. puts intro
  71. system(
  72. "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{LinuxDistro.config_path}"
  73. )
  74. sleep 1
  75. return :next
  76. end
  77. end
  78. class CopyCustomConfigJob < Job
  79. def call
  80. puts intro
  81. system("cp ./custom/default.custom.yaml #{LinuxDistro.config_path}/")
  82. system("cp ./custom/squirrel.custom.yaml #{LinuxDistro.config_path}/")
  83. sleep 1
  84. return :next
  85. end
  86. end
  87. class FinishedJob < Job
  88. def call
  89. puts ""
  90. puts "Tips: When finished all jobs. You need to do follow:".yellow
  91. puts "1) Restart system."
  92. puts "2) open Rime input method setting pane and click " +
  93. "DEPLOY".yellow + " button."
  94. puts "Enjoy~ 🍻"
  95. puts "more info:".yellow
  96. puts "Config path: #{LinuxDistro.config_path}/"
  97. return :next
  98. end
  99. end
  100. self.before_jobs = [CheckInstallRimeJob]
  101. self.jobs = [BackupRimeConfigJob, CloneConfigJob, CopyCustomConfigJob]
  102. self.after_jobs = [FinishedJob]
  103. end
  104. end