1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Functionality specific to Centos, RHEL, Amazon Linux, and other related distros.

use spurs::{cmd, SshCommand};

/// Install the given .rpm packages via `rpm`. Requires `sudo` priveleges.
pub fn rpm_install(pkg: &str) -> SshCommand {
    cmd!("sudo rpm -ivh {}", pkg)
}

/// Install the given list of packages via `yum install`. Requires `sudo` priveleges.
pub fn yum_install(pkgs: &[&str]) -> SshCommand {
    cmd!("sudo yum install -y {}", pkgs.join(" "))
}

#[cfg(test)]
mod test {
    use spurs::SshCommand;

    #[test]
    fn test_rpm_install() {
        assert_eq!(
            super::rpm_install("foobar"),
            SshCommand::make_cmd(
                "sudo rpm -ivh foobar".into(),
                None,
                false,
                false,
                false,
                false,
            ),
        );
    }

    #[test]
    fn test_yum_install() {
        assert_eq!(
            super::yum_install(&["foobar"]),
            SshCommand::make_cmd(
                "sudo yum install -y foobar".into(),
                None,
                false,
                false,
                false,
                false,
            ),
        );
    }
}