Kaynağa Gözat

feat: add debian linux

Mark24 2 yıl önce
ebeveyn
işleme
a35975330a
4 değiştirilmiş dosya ile 58 ekleme ve 34 silme
  1. 34 16
      installer.rb
  2. 6 5
      lib/config.rb
  3. 10 7
      os/DebianLinux.rb
  4. 8 6
      os/MacOS.rb

+ 34 - 16
installer.rb

@@ -2,29 +2,47 @@
 
 require "./lib/core"
 require "./lib/config"
+
+module OSPatch
+  def check_linux_debian?
+    return File.exist?("/etc/debian_version")
+  end
+
+  def check_os
+    case RUBY_PLATFORM.downcase
+    when /darwin/
+      @osname = "MacOS"
+    when /ubuntu/i
+      @osname = "DebianLinux"
+    when /debian/i
+      @osname = "DebianLinux"
+      # when /centos/i
+      #   @osname = "CentOS"
+      # when /fedora/i
+      #   @osname = "Fedora"
+      # when /redhat/i
+      #   @osname = "Red Hat"
+      # when /suse/i
+      #   @osname = "SUSE"
+      # when /unix/
+      #   @osname = "unix"
+    when /mswin|win32|mingw|cygwin/
+      @osname = "win"
+      not_support_exit
+    else
+      not_support_exit
+    end
+  end
+end
 module RimeDeploy
   class Installer
+    include OSPatch
     def initialize
       @osname = nil
       check_os
       dispatch
       run
     end
-    def check_os
-      case RUBY_PLATFORM
-      when /darwin/
-        @osname = "mac"
-      when /linux/
-        @osname = "linux"
-      when /unix/
-        @osname = "unix"
-      when /mswin|win32|mingw|cygwin/
-        @osname = "win"
-        not_support_exit
-      else
-        not_support_exit
-      end
-    end
 
     def not_support_exit
       puts "Not support this system. Bye~"
@@ -36,7 +54,7 @@ module RimeDeploy
     end
 
     def run
-      os_prefix = @osname.capitalize
+      os_prefix = @osname
       code = <<-CODE
   class #{os_prefix}JobGroup < JobGroup
   end

+ 6 - 5
lib/config.rb

@@ -1,14 +1,15 @@
 module RimeDeploy
-  RIME_CONFIG_REPO = "https://github.com/iDvel/rime-ice.git"
-  module OSConfig
-    module Mac
+  module Config
+    RIME_CONFIG_REPO = "https://github.com/iDvel/rime-ice.git"
+
+    class Mac
       InstallCmd = "brew install --cask squirrel"
       ConfigPath = "~/Library/Rime"
     end
 
-    module Linux
+    class DebianLinux
       InstallCmd = "sudo apt install ibus-rime"
-      ConfigPath = "~/.config/ibus/rime/"
+      ConfigPath = "~/.config/ibus/rime"
     end
   end
 end

+ 10 - 7
os/linux.rb → os/DebianLinux.rb

@@ -1,9 +1,10 @@
 module RimeDeploy
-  module Linux
+  module DebianLinux
     class InstallRimeJob < Job
       def call
         puts intro
-        system(OSConfig::Linux::InstallCmd)
+        puts "use Rime-ibus".yellow
+        system(Config::DebianLinux::InstallCmd)
         sleep 1
         return :next
       end
@@ -13,7 +14,7 @@ module RimeDeploy
       def call
         puts "Job: BackupRimeConfigJob".blue
         system(
-          "mv #{OSConfig::Linux::ConfigPath} #{OSConfig::Linux::ConfigPath}.#{Time.now.to_i}.old"
+          "mv #{Config::DebianLinux::ConfigPath} #{Config::DebianLinux::ConfigPath}.#{Time.now.to_i}.old"
         )
         sleep 1
         return :next
@@ -23,7 +24,9 @@ module RimeDeploy
     class CloneConfigJob < Job
       def call
         puts intro
-        system("git clone #{RIME_CONFIG_REPO} #{OSConfig::Linux::ConfigPath}")
+        system(
+          "git clone #{Config::RIME_CONFIG_REPO} #{Config::DebianLinux::ConfigPath}"
+        )
         sleep 1
         return :next
       end
@@ -33,10 +36,10 @@ module RimeDeploy
       def call
         puts intro
         system(
-          "cp ./custom/default.custom.yaml #{OSConfig::Linux::ConfigPath}/"
+          "cp ./custom/default.custom.yaml #{Config::DebianLinux::ConfigPath}/"
         )
         system(
-          "cp ./custom/squirrel.custom.yaml #{OSConfig::Linux::ConfigPath}/"
+          "cp ./custom/squirrel.custom.yaml #{Config::DebianLinux::ConfigPath}/"
         )
         sleep 1
         return :next
@@ -52,7 +55,7 @@ module RimeDeploy
                "DEPLOY".yellow + " button."
         puts "Enjoy~ 🍻"
         puts "more info:".yellow
-        puts "Config path: #{OSConfig::Linux::ConfigPath}/"
+        puts "Config path: #{Config::DebianLinux::ConfigPath}/"
         return :next
       end
     end

+ 8 - 6
os/mac.rb → os/MacOS.rb

@@ -3,7 +3,7 @@ module RimeDeploy
     class InstallRimeJob < Job
       def call
         puts intro
-        system(OSConfig::Mac::InstallCmd)
+        system(Config::MacOS::InstallCmd)
         sleep 1
         return :next
       end
@@ -13,7 +13,7 @@ module RimeDeploy
       def call
         puts "Job: BackupRimeConfigJob".blue
         system(
-          "mv #{OSConfig::Mac::ConfigPath} #{OSConfig::Mac::ConfigPath}.#{Time.now.to_i}.old"
+          "mv #{Config::MacOS::ConfigPath} #{Config::MacOS::ConfigPath}.#{Time.now.to_i}.old"
         )
         sleep 1
         return :next
@@ -23,7 +23,9 @@ module RimeDeploy
     class CloneConfigJob < Job
       def call
         puts intro
-        system("git clone #{RIME_CONFIG_REPO} #{OSConfig::Mac::ConfigPath}")
+        system(
+          "git clone #{Config::RIME_CONFIG_REPO} #{Config::MacOS::ConfigPath}"
+        )
         sleep 1
         return :next
       end
@@ -32,8 +34,8 @@ module RimeDeploy
     class CopyCustomConfigJob < Job
       def call
         puts intro
-        system("cp ./custom/default.custom.yaml #{OSConfig::Mac::ConfigPath}/")
-        system("cp ./custom/squirrel.custom.yaml #{OSConfig::Mac::ConfigPath}/")
+        system("cp ./custom/default.custom.yaml #{Config::MacOS::ConfigPath}/")
+        system("cp ./custom/squirrel.custom.yaml #{Config::MacOS::ConfigPath}/")
         sleep 1
         return :next
       end
@@ -48,7 +50,7 @@ module RimeDeploy
                "DEPLOY".yellow + " button."
         puts "Enjoy~ 🍻"
         puts "more info:".yellow
-        puts "Config path: #{OSConfig::Mac::ConfigPath}/"
+        puts "Config path: #{Config::MacOS::ConfigPath}/"
         return :next
       end
     end