1 | # -*- coding: utf-8; -*- |
---|
2 | ################################################################################ |
---|
3 | # |
---|
4 | # Rattail -- Retail Software Framework |
---|
5 | # Copyright © 2010-2018 Lance Edgar |
---|
6 | # |
---|
7 | # This file is part of Rattail. |
---|
8 | # |
---|
9 | # Rattail is free software: you can redistribute it and/or modify it under the |
---|
10 | # terms of the GNU General Public License as published by the Free Software |
---|
11 | # Foundation, either version 3 of the License, or (at your option) any later |
---|
12 | # version. |
---|
13 | # |
---|
14 | # Rattail is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
15 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
16 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
17 | # details. |
---|
18 | # |
---|
19 | # You should have received a copy of the GNU General Public License along with |
---|
20 | # Rattail. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | # |
---|
22 | ################################################################################ |
---|
23 | """ |
---|
24 | Fabric library for Rattail itself |
---|
25 | """ |
---|
26 | |
---|
27 | from __future__ import unicode_literals, absolute_import |
---|
28 | |
---|
29 | import os |
---|
30 | |
---|
31 | from rattail_fabric2 import postgresql, make_deploy, make_system_user, mkdir |
---|
32 | |
---|
33 | |
---|
34 | deploy = make_deploy(__file__) |
---|
35 | |
---|
36 | |
---|
37 | def bootstrap_rattail(c, home='/var/lib/rattail', uid=None, shell='/bin/bash'): |
---|
38 | """ |
---|
39 | Bootstrap a basic Rattail software environment. |
---|
40 | """ |
---|
41 | make_system_user(c, 'rattail', home=home, uid=uid, shell=shell) |
---|
42 | mkdir(c, os.path.join(home, '.ssh'), owner='rattail:', mode='0700', use_sudo=True) |
---|
43 | |
---|
44 | mkdir(c, '/etc/rattail', use_sudo=True) |
---|
45 | mkdir(c, '/srv/rattail', use_sudo=True) |
---|
46 | mkdir(c, '/var/log/rattail', owner='rattail:rattail', mode='0775', use_sudo=True) |
---|
47 | |
---|
48 | mkdir(c, '/srv/rattail/init', use_sudo=True) |
---|
49 | deploy(c, 'daemon', '/srv/rattail/init/daemon', use_sudo=True) |
---|
50 | deploy(c, 'check-rattail-daemon', '/usr/local/bin/check-rattail-daemon', use_sudo=True) |
---|
51 | deploy(c, 'luigid', '/srv/rattail/init/luigid', use_sudo=True) |
---|
52 | deploy(c, 'soffice', '/srv/rattail/init/soffice', use_sudo=True) |
---|
53 | # TODO: deprecate / remove these |
---|
54 | deploy(c, 'bouncer', '/srv/rattail/init/bouncer', use_sudo=True) |
---|
55 | deploy(c, 'datasync', '/srv/rattail/init/datasync', use_sudo=True) |
---|
56 | deploy(c, 'filemon', '/srv/rattail/init/filemon', use_sudo=True) |
---|
57 | |
---|
58 | |
---|
59 | def delete_email_recipients(c, dbname): |
---|
60 | """ |
---|
61 | Purge all email recipient settings for the given database. |
---|
62 | """ |
---|
63 | postgresql.sql(c, "delete from setting where name like 'rattail.mail.%.to';", database=dbname) |
---|
64 | postgresql.sql(c, "delete from setting where name like 'rattail.mail.%.cc';", database=dbname) |
---|
65 | postgresql.sql(c, "delete from setting where name like 'rattail.mail.%.bcc';", database=dbname) |
---|
66 | |
---|
67 | |
---|
68 | def disable_emails(c, dbname): |
---|
69 | """ |
---|
70 | Disable all emails for the given database. |
---|
71 | """ |
---|
72 | postgresql.sql(c, "update setting set value = 'false' where name like 'rattail.mail.%.enabled';", database=dbname) |
---|