LinuxDistro.rb 2.7 KB

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