LinuxDistro.rb 2.7 KB

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