Skip to content

Instantly share code, notes, and snippets.

@gutocarvalho
Last active November 19, 2015 22:06
Show Gist options
  • Save gutocarvalho/3f1822f851f1f4a38d6a to your computer and use it in GitHub Desktop.
Save gutocarvalho/3f1822f851f1f4a38d6a to your computer and use it in GitHub Desktop.
Facter.add(:dovecot) do
setcode do
confine :kernel => 'Linux'
dovecot = {}
distid = Facter.value(:osfamily)
case distid
when /RedHat|Suse/
dovecot_check = Facter::Core::Execution.exec('which dovecot')
when "Debian"
dovecot_check = Facter::Core::Execution.exec('which dovecot')
dovecot_imapd_check = Facter::Core::Execution.exec('dpkg-query -W --showformat=\'${Status}\' dovecot-imapd|egrep ^install')
dovecot_pop3d_check = Facter::Core::Execution.exec('dpkg-query -W --showformat=\'${Status}\' dovecot-pop3d|egrep ^install')
end
if dovecot_check.empty?
dovecot_installed = false
else
dovecot_installed = true
end
if distid == "Debian"
if dovecot_imapd_check.empty?
dovecot_imapd_installed = false
else
dovecot_imapd_installed = true
end
if dovecot_pop3d_check.empty?
dovecot_pop3d_installed = false
else
dovecot_pop3d_installed = true
end
end
if dovecot_installed
distid = Facter.value(:osfamily)
case distid
when /RedHat|Suse/
dovecot_version = Facter::Core::Execution.exec('rpm -q --queryformat "%{VERSION}" dovecot')
when "Debian"
dovecot_version = Facter::Core::Execution.exec('dpkg-query -W -f=\'${Version}\' dovecot-core')
else
dovecot_version = 'Unknown'
end
end
dovecot[:installed] = dovecot_installed
if dovecot_installed
dovecot[:version] = dovecot_version
end
if ( distid == "Debian" ) && ( dovecot_installed == true )
dovecot[:imapd_installed] = dovecot_imapd_installed
dovecot[:pop3d_installed] = dovecot_pop3d_installed
end
dovecot
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment