summaryrefslogtreecommitdiffstats
path: root/modules/package/manifests/cargo.pp
blob: 2f599b9186920b6a78ada621c17c771261d0bec1 (plain) (blame)
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
define package::cargo($package, $user, $ensure, $home=undef) {
  $_home = $home ? {
    undef => $user ? {
      'root' => '/root',
      default => "/home/$user",
    },
    default => $home,
  }

  case $ensure {
    'installed': {
      exec { "cargo install $package for $user":
        provider => "shell",
        command => "cargo install $package",
        unless => "cargo install --list | grep -q '^$package'",
        user => $user,
        timeout => 3600,
        require => [
          User[$user],
          Rust::User[$user],
          File["${_home}/.cargo"],
        ];
      }
    }
    'absent': {
      exec { "cargo uninstall $package for $user":
        provider => "shell",
        command => "cargo uninstall $package",
        onlyif => "cargo install --list | grep -q '^$package'",
        user => $user,
        require => [
          User[$user],
          Rust::User[$user],
          File["${_home}/.cargo"],
        ];
      }
    }
  }
}