use command::{Command, CommandResult};
use error::{Error, Result};
use host::Host;
use regex::Regex;
use super::*;
pub struct Yum;
impl Provider for Yum {
fn get_providers(&self) -> Providers {
Providers::Yum
}
fn is_active(&self, host: &mut Host) -> Result<bool> {
let cmd = Command::new("type yum");
let result = try!(cmd.exec(host));
Ok(result.exit_code == 0)
}
fn is_installed(&self, host: &mut Host, name: &str) -> Result<bool> {
let cmd = Command::new("yum list installed");
let result = try!(cmd.exec(host));
if result.exit_code != 0 {
return Err(Error::Agent(result.stderr));
}
let arch = try!(needstr!(host.data() => "/_telemetry/os/arch"));
let re = try!(Regex::new(&format!("(?m)^{}\\.({}|noarch)\\s+", name, arch)));
Ok(re.is_match(&result.stdout))
}
fn install(&self, host: &mut Host, name: &str) -> Result<CommandResult> {
let cmd = Command::new(&format!("yum -y install {}", name));
cmd.exec(host)
}
fn uninstall(&self, host: &mut Host, name: &str) -> Result<CommandResult> {
let cmd = Command::new(&format!("yum -y remove {}", name));
cmd.exec(host)
}
}