LinuxDistro.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_path =
  31. ::RimeDeploy::Config::LinuxDistro::ConfigPathIbus
  32. end
  33. ],
  34. [
  35. "fcitx-rime",
  36. -> do
  37. LinuxDistro.config_path =
  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. "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. BeforeHook = [CheckInstallRimeJob]
  101. Jobs = [BackupRimeConfigJob, CloneConfigJob, CopyCustomConfigJob]
  102. FinishedHook = [FinishedJob]
  103. end
  104. end