summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2015-05-10 14:04:19 +0200
committerJohannes Löthberg <johannes@kyriasis.com>2015-05-10 18:56:55 +0200
commitc1830f48c92fc7017d47646565c6bd811771614e (patch)
tree36216d8541fe8ccef9ef1bf0477103ed9c8ab961
parent953f6a7a8963a2976196e83a4a937c7762b31ab8 (diff)
downloadsmtpd-conf-c1830f48c92fc7017d47646565c6bd811771614e.tar.xz
Add initial fabfile
-rw-r--r--fabfile.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/fabfile.py b/fabfile.py
new file mode 100644
index 0000000..c366dd2
--- /dev/null
+++ b/fabfile.py
@@ -0,0 +1,28 @@
+from fabric.api import env, local, put, run, sudo, task
+
+env.hosts = ['theos.kyriasis.com', 'lucifer.kyriasis.com']
+
+def checksum_match(local_file, remote_file):
+ md5 = '/usr/bin/md5sum {}'
+ local_sum = local(md5.format(local_file), capture=True).split()[0]
+ remote_sum = run(md5.format(remote_file)).split()[0]
+
+ return local_sum == remote_sum
+
+@task
+def upload_conf():
+ local_file = '{}/smtpd.conf'.format(env.host)
+
+ if not checksum_match(local_file, '/etc/smtpd/smtpd.conf'):
+ print("Config changed, uploading new file...")
+ put(local_path=local_file, remote_path='/etc/smtpd/smtpd.conf')
+ sudo('systemctl restart smtpd.service')
+
+@task
+def upload_users():
+ local_file = 'common/users'
+
+ if not checksum_match(local_file, '/etc/smtpd/users'):
+ print("Users changed, uploading new file...")
+ put(local_path=local_file, remote_path='/etc/smtpd/users')
+ sudo('smtpctl update table users')