From 02a2196150b16ee1c343a5587cadb177016fe222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sat, 15 Oct 2016 19:22:44 +0200 Subject: Update files to changes done while abandoning systemd Now I use openrc. --- local/sbin/syncemail | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'local/sbin/syncemail') 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() -- cgit v1.2.3