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 Ubuntu.

use crate::ssh::SshCommand;

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

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

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

    #[test]
    fn test_dpkg_install() {
        assert_eq!(
            super::dpkg_install("foobar"),
            SshCommand::make_cmd(
                "sudo dpkg -i foobar".into(),
                None,
                false,
                false,
                false,
                false,
            ),
        );
    }

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