Class: Convert2Ascii::CheckPackage

Inherits:
Object
  • Object
show all
Includes:
OS
Defined in:
lib/convert2ascii/check_package.rb

Direct Known Subclasses

CheckFFmpeg, CheckImageMagick

Instance Method Summary collapse

Methods included from OS

#detect_os

Constructor Details

#initializeCheckPackage

Returns a new instance of CheckPackage.



32
33
34
# File 'lib/convert2ascii/check_package.rb', line 32

def initialize
  @os_name = nil
end

Instance Method Details

#arch_installed?(package_name) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
105
# File 'lib/convert2ascii/check_package.rb', line 102

def arch_installed?(package_name)
  output = `pacman -Q | grep #{package_name}`
  !output.strip.empty?
end

#centos_installed?(package_name) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
# File 'lib/convert2ascii/check_package.rb', line 92

def centos_installed?(package_name)
  output = `rpm -qa | grep #{package_name}`
  !output.strip.empty?
end

#checkObject



107
108
109
110
# File 'lib/convert2ascii/check_package.rb', line 107

def check
  @os_name = detect_os
  __send__ "#{@os_name}_check"
end

#debian_installed?(package_name) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
90
# File 'lib/convert2ascii/check_package.rb', line 87

def debian_installed?(package_name)
  output = `dpkg -l | grep #{package_name}`
  !output.strip.empty?
end

#detect_linux_distributionObject

Raises:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/convert2ascii/check_package.rb', line 55

def detect_linux_distribution

  if !File.exist?('/etc/os-release')
    raise CheckPackageError, Rainbow("[Error] can not detect_os! #{@os_name} ").red
  end

  os_release = File.read('/etc/os-release')

  if os_release.include?('debian')
    # debian/ubuntu
    return'debian'
  end

  if os_release.include?('centos')
    # centos
    return'centos'
  end

  if os_release.include?('redhat')
    # redhat
    return'redhat'
  end

  if os_release.include?('arch')
    # arch linux
    return'arch'
  end

  raise CheckPackageError, Rainbow("[Error] #{@os_name} linux platform not support!").red
end

#linux_checkObject



42
43
# File 'lib/convert2ascii/check_package.rb', line 42

def linux_check
end

#macos_checkObject



36
37
# File 'lib/convert2ascii/check_package.rb', line 36

def macos_check
end

#macos_installed?(package_name) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/convert2ascii/check_package.rb', line 50

def macos_installed?(package_name)
  output = `brew list #{package_name} 2>/dev/null`
  return output != ""
end

#ms_checkObject



39
40
# File 'lib/convert2ascii/check_package.rb', line 39

def ms_check
end

#redhat_installed?(package_name) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
100
# File 'lib/convert2ascii/check_package.rb', line 97

def redhat_installed?(package_name)
  output = `yum list installed | grep #{package_name}`
  !output.strip.empty?
end

#unknow_checkObject

Raises:



45
46
47
# File 'lib/convert2ascii/check_package.rb', line 45

def unknow_check
  raise CheckPackageError, Rainbow("[Error] #{@os_name} not support!").red
end