aboutsummaryrefslogtreecommitdiff
path: root/local/sbin
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2016-10-15 19:22:44 +0200
committerKarel Kočí <cynerd@email.cz>2016-10-15 19:22:44 +0200
commit02a2196150b16ee1c343a5587cadb177016fe222 (patch)
tree8ef95619620a4689a12d26eff0a0287954a2cd3c /local/sbin
parentb17cad80bfaf348ce805868dc4b35211a4c32906 (diff)
downloadmyconfigs-02a2196150b16ee1c343a5587cadb177016fe222.tar.gz
myconfigs-02a2196150b16ee1c343a5587cadb177016fe222.tar.bz2
myconfigs-02a2196150b16ee1c343a5587cadb177016fe222.zip
Update files to changes done while abandoning systemd
Now I use openrc.
Diffstat (limited to 'local/sbin')
-rwxr-xr-xlocal/sbin/syncemail48
1 files changed, 22 insertions, 26 deletions
diff --git a/local/sbin/syncemail b/local/sbin/syncemail
index 95deb7e..d0ea682 100755
--- a/local/sbin/syncemail
+++ b/local/sbin/syncemail
@@ -1,36 +1,32 @@
#!/usr/bin/python2
-# This starts offlineimap, but first it requests passwords from pass by user
-# notification launching script at front.
+# This starts offlineimap, but first it requests passwords from pass
import os
import sys
import subprocess
+import daemon
+import lockfile
from offlineimap import OfflineImap
-frontscript = """
-echo "Asking for gpg password to access pass" 1>&2
-pass mail/cynerd@email.cz
-echo "All done" 1>&2
-"""
-annoyme = [
- os.path.expanduser("~/.local/sbin/annoyme-request"),
- "syncemail",
- "Imap email synchronization service password request."
- ]
+if os.path.isfile('/home/cynerd/.run/syncemail.pid.lock'):
+ sys.exit(0)
-anproc = subprocess.Popen(annoyme, stdin=subprocess.PIPE,
- stdout=subprocess.PIPE)
-anproc.stdin.write(frontscript)
-anproc.stdin.close()
-output = anproc.stdout.read().splitlines()
-excode = anproc.wait()
+accounts = [
+ ["email", "mail/cynerd@email.cz"],
+ ]
-if excode != 0:
- print("Authentication failed. Please start emailsync again")
- sys.exit(1)
-print(output)
+for acc in accounts:
+ pproc = subprocess.Popen("pass " + acc[1],
+ stdout=subprocess.PIPE, shell=True)
+ output = pproc.stdout.read().rstrip()
+ if pproc.wait() != 0:
+ print("Password receive failed.")
+ sys.exit(1)
+ sys.argv.append('-k')
+ sys.argv.append('Repository_' + acc[0] + '-remote:remotepass=' + output)
-sys.argv.append('-k')
-sys.argv.append('Repository_email-remote:remotepass=' + output[0])
+sys.argv.append('-s') # output to syslog
-
-OfflineImap().run()
+with daemon.DaemonContext(
+ pidfile=lockfile.FileLock('/home/cynerd/.run/syncemail.pid')
+ ):
+ OfflineImap().run()