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 }