installer.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env ruby
  2. require "./lib/core"
  3. require "./lib/config"
  4. module OSPatch
  5. def check_linux_debian_distro
  6. debian_distro = %w[debian ubuntu linuxmint linux-mint]
  7. os_release_file = "/etc/os-release"
  8. if File.exist?(os_release_file)
  9. os_release = File.read(os_release_file)
  10. debian_distro.each { |distro| return true if os_release.include?(distro) }
  11. end
  12. return false
  13. end
  14. def check_os
  15. case RUBY_PLATFORM.downcase
  16. when /darwin/
  17. @osname = "MacOS"
  18. when /linux/
  19. if check_linux_debian_distro
  20. @osname = "DebianLinux"
  21. else
  22. not_support_exit
  23. end
  24. when /mswin|win32|mingw|cygwin/
  25. @osname = "win"
  26. not_support_exit
  27. else
  28. not_support_exit
  29. end
  30. end
  31. end
  32. module RimeDeploy
  33. class Installer
  34. include OSPatch
  35. def initialize
  36. @osname = nil
  37. check_os
  38. dispatch
  39. run
  40. end
  41. def not_support_exit
  42. puts "Not support this system. Bye~"
  43. exit 0
  44. end
  45. def dispatch
  46. require "./os/#{@osname}"
  47. end
  48. def run
  49. os_prefix = @osname
  50. code = <<-CODE
  51. class #{os_prefix}JobGroup < JobGroup
  52. end
  53. mod = #{os_prefix}JobGroup.new(#{os_prefix}::Jobs, #{os_prefix}::FinishedHook)
  54. mod.call
  55. CODE
  56. instance_eval(code)
  57. end
  58. end
  59. end
  60. RimeDeploy::Installer.new