Class: Shutter::OS
- Inherits:
-
Object
- Object
- Shutter::OS
- Defined in:
- lib/shutter/os.rb
Instance Method Summary collapse
- #debian? ⇒ Boolean
- #dist ⇒ Object
- #family ⇒ Object
-
#initialize ⇒ OS
constructor
A new instance of OS.
- #iptables_restore ⇒ Object
- #iptables_save ⇒ Object
- #linux? ⇒ Boolean
- #persist_file ⇒ Object
- #redhat? ⇒ Boolean (also: #centos?, #fedora?)
- #ubuntu? ⇒ Boolean
- #unknown? ⇒ Boolean
- #validate! ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize ⇒ OS
Returns a new instance of OS.
3 4 5 6 7 |
# File 'lib/shutter/os.rb', line 3 def initialize unless File.exist?('/proc/version') @version = "Unknown" end end |
Instance Method Details
#debian? ⇒ Boolean
69 70 71 |
# File 'lib/shutter/os.rb', line 69 def debian? dist == "Debian" end |
#dist ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/shutter/os.rb', line 48 def dist case version when /Red Hat/ "RedHat" when /Debian/ "Debian" when /Ubuntu/ "Ubuntu" else "Unknown" end end |
#family ⇒ Object
15 16 17 |
# File 'lib/shutter/os.rb', line 15 def family @family ||= ENV['OS'] ? ENV['OS'] : RUBY_PLATFORM.split('-').last end |
#iptables_restore ⇒ Object
31 32 33 |
# File 'lib/shutter/os.rb', line 31 def iptables_restore "/sbin/iptables-restore" end |
#iptables_save ⇒ Object
27 28 29 |
# File 'lib/shutter/os.rb', line 27 def iptables_save "/sbin/iptables-save" end |
#linux? ⇒ Boolean
23 24 25 |
# File 'lib/shutter/os.rb', line 23 def linux? family == "linux" end |
#persist_file ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shutter/os.rb', line 35 def persist_file case version when /Red Hat/ "/etc/sysconfig/iptables" when /Debian/ "/etc/iptables/rules" when /Ubuntu/ "/etc/iptables/rules" else "/tmp/iptables.rules" end end |
#redhat? ⇒ Boolean Also known as: centos?, fedora?
61 62 63 |
# File 'lib/shutter/os.rb', line 61 def redhat? dist == "RedHat" end |
#ubuntu? ⇒ Boolean
65 66 67 |
# File 'lib/shutter/os.rb', line 65 def ubuntu? dist == "Ubuntu" end |
#unknown? ⇒ Boolean
73 74 75 |
# File 'lib/shutter/os.rb', line 73 def unknown? dist == "Unknown" end |
#validate! ⇒ Object
9 10 11 12 13 |
# File 'lib/shutter/os.rb', line 9 def validate! if unknown? raise "ERROR: Unsupported operating system" end end |
#version ⇒ Object
19 20 21 |
# File 'lib/shutter/os.rb', line 19 def version @version ||= IO.read('/proc/version') end |