summaryrefslogtreecommitdiff
path: root/manifests/syncthing.pp
blob: e31449a7454691157cb8298af2059735c6cad80b (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
class profiles::syncthing (
  $data,
  Array[String] $enable_for = [],
  Array[String] $augrules = [],
) {

  class { 'syncthing':
    manage_repo => $::osfamily == 'Debian',
  }


  systemd::dropin_file { 'nospam.conf':
    ensure => absent,
    unit   => 'syncthing@.service',
    content => @(EOF)
      [Service]
      ExecStart=
      ExecStart=/bin/bash -c 'set -o pipefail; /usr/bin/syncthing -no-browser -no-restart -logflags=0 | grep -v "INFO: "'
      | EOF
  }

  $enable_for.map |$user| {

    user { $user:
      home       => "/home/${user}",
      managehome => true,
    }


    $hp = "/home/${user}/.config/syncthing"

    syncthing::instance { $user:
      home_path  => $hp,
      daemon_uid => $user,
    }

    $data['devices'].each |$name, $d| {
      syncthing::device { $name:
        home_path     => $hp,
        instance_name => $user,
        id            => $d['id'],
      }
    }

    $data['folders'].each |$name, $d| {
      syncthing::folder { $name:
        home_path     => $hp,
        instance_name => $user,
        id            => $d['id'],
        path          => $d['path'],
        devices       => $d['devices'].map |$name| { [ $data['devices'][$name]['id'], 'present' ] }.hash
      }
    }

    # $dir = "/home/${user}/.config/syncthing"
    # file { "/home/${user}/.config":
    #   ensure => directory,
    #   owner  => $user,
    #   group  => $user,
    # }
    # exec { "/usr/bin/syncthing -generate='${dir}'":
    #   user    => $user,
    #   creates => $dir,
    # }

    # # service { "syncthing@${user}":
    # #   enable => true,
    # # }

    # # augeas { 'syncthing_config':
    # #   # context => "/files/home/${user}.config/syncthing/config.xml/configuration",
    # #   changes => [
    # #     "defvar base /home/${user}/.config/syncthing/",
    # #     'set /augeas/load/Xml/incl[1] $base/*.xml',
    # #     'load',
    # #     'defvar $ctx $base/config.xml/configuration',
    # #     'set $ctx/gui/#attribute/enabled false',
    # #     'save',
    # #     'rm $ctx/folder/',
    # #     'set $ctx/folder[0]/#attribute/label Documentns',
    # #     'set $ctx/folder[0]/#attribute/path ~/sync/doc',
    # #     'set $ctx/folder[0]/#attribute/id rrrr-xxxx',
    # #     'set $ctx/folder[0]/#attribute/device[0]/#attribute/id something-really-long',
    # #     'save',
    # #   ],
    # # }

    # $device_rules = flatten($data['devices'].map |$name, $d| {
    #   [
    #     "defnode node device[#attribute/name=$name] ''",
    #     "set \$node/#attribute/name ${name}",
    #     "set \$node/#attribute/id ${d['id']}",
    #   ]
    # })

    # $folder_rules = flatten($data['folders'].map |$name, $d| {
    #   [
    #     "defnode node folder[#attribute/label=$name] ''",
    #     "set \$node/#attribute/label ${name}",
    #     "set \$node/#attribute/path ${d['path']}",
    #     "set \$node/#attribute/id ${d['id']}",
    #   ] + flatten($d['devices'].map |$name| {
    #     alert($name)
    #     alert($data['devices'][$name])
    #     [ "set \$node/device[0]/#attribute/id ${data['devices'][$name]['id']}", ]
    #   })
    # })

    # augeas { 'syncthing-config':
    #   lens    => 'Xml.lns',
    #   incl    => "/home/${user}/.config/syncthing/config.xml",
    #   context => "/files/home/${user}/.config/syncthing/config.xml/configuration",
    #   changes => $device_rules + $folder_rules,
    #   # [
    #   #   'rm folder/',
    #   #   'set folder[0]/#attribute/label Documentsn',
    #   #   'set folder[0]/#attribute/path ~/sync/doc',
    #   #   # 'set folder[0]/#attribute/id rrrr-xxxx',
    #   #   # 'set folder[0]/#attribute/device[0]/#attribute/id something-really-long',
    #   # ],
    # }
  }

  # # TODO manage synced data


}