users.pp 5.39 KB
Newer Older
1
class nest::base::users {
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
  case $facts['osfamily'] {
    'Gentoo': {
      file { '/bin/zsh':
        ensure => file,
        mode   => '0755',
        owner  => 'root',
        group  => 'root',
      }

      package { 'app-shells/zsh':
        ensure => installed,
      }

      file_line { 'useradd-group':
        path  => '/etc/default/useradd',
        line  => 'GROUP=1000',
        match => '^GROUP=',
      }

      group {
        'users':
          gid     => '1000',
          require => File_line['useradd-group'];
        'media':
          gid => '1001';
        'bitwarden':
          gid => '1003';
      }

      # This is because I abuse UIDs (I create "system" users like
      # plex above 1000, so useradd wants to create its home directory
      # by default).  We can explicitly control this behavior with the
      # 'managehome' attribute.
      file_line { 'login.defs-create_home':
        path  => '/etc/login.defs',
        line  => 'CREATE_HOME no',
        match => '^CREATE_HOME ',
      }

41
42
43
44
      unless $facts['build'] == 'stage1' or $facts['tool'] {
        $pw_hash = $::nest::pw_hash
      }

45
46
47
      user {
        default:
          managehome => false,
48
49
          require    => File_line['login.defs-create_home'],
        ;
50
51
52
53

        'root':
          shell    => '/bin/zsh',
          require  => File['/bin/zsh'],
54
55
          password => $pw_hash,
        ;
56
57
58
59
60
61
62
63

        'james':
          uid      => '1000',
          gid      => 'users',
          groups   => ['plugdev', 'video', 'wheel'],
          home     => '/home/james',
          comment  => 'James Lee',
          shell    => '/bin/zsh',
64
          password => $pw_hash,
65
66
          require  => [
            Package['app-shells/zsh'],
67
            Class['::nest::base::network'],  # networkmanager creates 'plugdev' group
68
69
          ],
        ;
70
71
72
73
74
75

        'ombi':
          uid     => '3579',
          gid     => 'media',
          home    => '/srv/ombi',
          comment => 'Ombi',
76
77
          shell   => '/sbin/nologin',
        ;
78
79
80
81
82
83

        'couchpotato':
          uid     => '5050',
          gid     => 'media',
          home    => '/srv/couchpotato',
          comment => 'CouchPotato',
84
85
          shell   => '/sbin/nologin',
        ;
86
87
88
89
90
91

        'nzbget':
          uid     => '6789',
          gid     => 'media',
          home    => '/srv/nzbget',
          comment => 'NZBGet',
92
93
          shell   => '/sbin/nologin',
        ;
94
95
96
97
98
99

        'radarr':
          uid     => '7878',
          gid     => 'media',
          home    => '/srv/radarr',
          comment => 'Radarr',
100
101
          shell   => '/sbin/nologin',
        ;
102
103
104
105
106
107

        'sonarr':
          uid     => '8989',
          gid     => 'media',
          home    => '/srv/sonarr',
          comment => 'Sonarr',
108
109
          shell   => '/sbin/nologin',
        ;
110
111
112
113
114
115

        'transmission':
          uid     => '9091',
          gid     => 'media',
          home    => '/srv/transmission',
          comment => 'Transmission',
116
117
          shell   => '/sbin/nologin',
        ;
118
119
120
121
122
123

        'plex':
          uid     => '32400',
          gid     => 'media',
          home    => '/srv/plex',
          comment => 'Plex Media Server',
124
125
          shell   => '/sbin/nologin',
        ;
126
127
128
129
130
131

        'bitwarden':
          uid     => '1003',
          gid     => '1003',
          home    => '/srv/bitwarden',
          comment => 'Bitwarden',
132
133
          shell   => '/bin/zsh',
        ;
134
135
136
      }

      file {
137
138
139
140
        [
          '/root/.distcc',
          '/root/.keep',
        ]:
141
          ensure => absent,
142
          force  => true,
143
144
          before => Vcsrepo['/root'],
        ;
145
146
147
148
149

        '/home/james':
          ensure => directory,
          mode   => '0755',
          owner  => 'james',
150
151
152
          group  => 'users',
          before => Vcsrepo['/home/james'],
        ;
153
154
      }

155
156
157
      $homes = {
        'root'  => '/root',
        'james' => '/home/james',
158
      }
159
160
    }

161
162
163
164
165
    'windows': {
      package { 'zsh':
        ensure   => installed,
        provider => 'cygwin',
      }
166

167
168
169
170
171
172
173
      windows_env { 'james-SHELL':
        user     => 'james',
        variable => 'SHELL',
        value    => '/bin/zsh',
        require  => Package['zsh'],
      }

174
      $homes = {
James T. Lee's avatar
James T. Lee committed
175
        'james' => '/home/james',
176
177
178
179
180
      }
    }
  }

  $homes.each |$user, $dir| {
James T. Lee's avatar
James T. Lee committed
181
182
    case $facts['osfamily'] {
      'windows': {
183
        $exec_user   = undef
184
        $home_dir    = "C:/tools/cygwin${dir}"
185
186
        $refresh_cmd = "C:/tools/cygwin/bin/bash.exe -c 'source /etc/profile && ${home_dir}/.refresh'"
        $test_cmd    = "C:/tools/cygwin/bin/test.exe -x ${home_dir}/.refresh"
James T. Lee's avatar
James T. Lee committed
187
188
189
      }

      default: {
190
        $exec_user   = $user
191
        $home_dir    = $dir
192
193
        $refresh_cmd = "${home_dir}/.refresh"
        $test_cmd    = "/usr/bin/test -x ${home_dir}/.refresh"
James T. Lee's avatar
James T. Lee committed
194
      }
195
196
    }

197
    vcsrepo { "$home_dir":
198
199
      ensure   => latest,
      provider => git,
200
      source   => 'https://gitlab.james.tl/james/dotfiles.git',
201
202
      revision => 'main',
      user     => $exec_user,
203
    }
204
    ~>
James T. Lee's avatar
James T. Lee committed
205
    exec { "refresh-${home_dir}":
James T. Lee's avatar
James T. Lee committed
206
      environment => "HOME=${home_dir}",
207
      command     => $refresh_cmd,
208
      user        => $exec_user,
209
210
      onlyif      => $test_cmd,
      refreshonly => true,
James T. Lee's avatar
James T. Lee committed
211
    }
212

213
    unless $facts['build'] == 'stage1' or $facts['tool'] {
214
      file { "${home_dir}/.ssh/id_rsa":
215
216
217
218
        mode      => '0600',
        owner     => $user,
        content   => $::nest::ssh_private_key,
        show_diff => false,
219
        require   => Vcsrepo[$home_dir],
220
      }
221
    }
222
223
  }
}