LinuxDistro.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. LinuxDistroJobGroup.config_path =
  34. LinuxDistroJobGroup::ConfigPathIbus
  35. end
  36. ],
  37. [
  38. "fcitx-rime",
  39. -> do
  40. LinuxDistroJobGroup.config_path =
  41. LinuxDistroJobGroup::ConfigPathFcitx
  42. end
  43. ],
  44. [
  45. "fcitx5-rime",
  46. -> do
  47. LinuxDistroJobGroup.config_path =
  48. LinuxDistroJobGroup::ConfigPathFcitx5
  49. end
  50. ],
  51. [
  52. "I'll quit first.After installed Rime by myself then run this program again.",
  53. -> { exit 0 }
  54. ]
  55. ]
  56. ).call
  57. sleep 1
  58. return :next
  59. end
  60. end
  61. class BackupRimeConfigJob < Job
  62. def call
  63. puts intro
  64. system(
  65. "mv #{LinuxDistroJobGroup.config_path} #{LinuxDistroJobGroup.config_path}.#{Time.now.to_i}.old"
  66. )
  67. sleep 1
  68. return :next
  69. end
  70. end
  71. class CloneConfigJob < Job
  72. def call
  73. puts intro
  74. system(
  75. "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{LinuxDistroJobGroup.config_path}"
  76. )
  77. sleep 1
  78. return :next
  79. end
  80. end
  81. class CopyCustomConfigJob < Job
  82. def call
  83. puts intro
  84. system("cp ./custom/*.yaml #{LinuxDistroJobGroup.config_path}/")
  85. sleep 1
  86. return :next
  87. end
  88. end
  89. class FinishedJob < Job
  90. def call
  91. puts ""
  92. puts "Tips: When finished all jobs. You need to do follow:".yellow
  93. puts "1) Restart system."
  94. puts "2) open Rime input method setting pane and click " +
  95. "DEPLOY".yellow + " button."
  96. puts "Enjoy~ 🍻"
  97. puts "more info:".yellow
  98. puts "Config path: #{LinuxDistroJobGroup.config_path}/"
  99. return :next
  100. end
  101. end
  102. self.before_jobs = [CheckInstallRimeJob]
  103. self.jobs = [BackupRimeConfigJob, CloneConfigJob, CopyCustomConfigJob]
  104. self.after_jobs = [FinishedJob]
  105. end
  106. end