2024-08-23 17:43:04 +00:00
|
|
|
svc_systemd = {
|
|
|
|
'nmbd': {
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:samba',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'smbd': {
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:samba',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-12-22 19:20:20 +00:00
|
|
|
timemachine_shares = node.metadata.get('samba/timemachine-shares', set())
|
|
|
|
|
2024-08-23 17:43:04 +00:00
|
|
|
files = {
|
|
|
|
'/etc/samba/smb.conf': {
|
|
|
|
'content_type': 'mako',
|
2024-12-22 19:20:20 +00:00
|
|
|
'context': {
|
|
|
|
'timemachine': timemachine_shares,
|
|
|
|
},
|
2024-08-23 17:43:04 +00:00
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nmbd:restart',
|
|
|
|
'svc_systemd:smbd:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/systemd/system/nmbd.service.d/bundlewrap.conf': {
|
|
|
|
'source': 'override.conf',
|
|
|
|
'triggers': {
|
|
|
|
'action:systemd-reload',
|
|
|
|
'svc_systemd:nmbd:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/systemd/system/smbd.service.d/bundlewrap.conf': {
|
|
|
|
'source': 'override.conf',
|
|
|
|
'triggers': {
|
|
|
|
'action:systemd-reload',
|
|
|
|
'svc_systemd:smbd:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
last_action = set()
|
|
|
|
for user, uconfig in node.metadata.get('users', {}).items():
|
|
|
|
if (
|
|
|
|
'password' not in uconfig
|
|
|
|
or uconfig.get('delete')
|
|
|
|
or user in ('root',)
|
|
|
|
):
|
|
|
|
continue
|
|
|
|
|
|
|
|
actions[f'smbpasswd_for_user_{user}'] = {
|
|
|
|
'command': f'smbpasswd -a -s {user}',
|
|
|
|
'unless': f'pdbedit -L | grep -E "^{user}:"',
|
|
|
|
'data_stdin': uconfig['password'] + '\n' + uconfig['password'],
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:samba',
|
|
|
|
f'user:{user}',
|
|
|
|
},
|
|
|
|
'after': last_action,
|
|
|
|
}
|
|
|
|
last_action = {
|
|
|
|
f'action:smbpasswd_for_user_{user}',
|
|
|
|
}
|
2024-12-22 19:20:20 +00:00
|
|
|
|
|
|
|
if timemachine_shares:
|
|
|
|
assert node.has_bundle('avahi-daemon'), f'{node.name}: samba needs avahi-daemon to publish time machine shares'
|
|
|
|
|
|
|
|
files['/etc/avahi/services/timemachine.service'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'shares': timemachine_shares,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for share_name in timemachine_shares:
|
|
|
|
users[f'timemachine-{share_name}'] = {
|
|
|
|
'home': f'/srv/timemachine/{share_name}',
|
|
|
|
}
|
|
|
|
|
|
|
|
directories[f'/srv/timemachine/{share_name}'] = {
|
|
|
|
'owner': f'timemachine-{share_name}',
|
|
|
|
'group': f'timemachine-{share_name}',
|
|
|
|
'mode': '0700',
|
|
|
|
}
|