From 8ca9f69691ae2d2269a166c946d223eeac86e504 Mon Sep 17 00:00:00 2001 From: Kload Date: Wed, 20 Nov 2013 23:40:20 +0100 Subject: [PATCH] fix postinstall --- yunohost.py | 30 +++++++++++++++++------------- yunohost.tac | 33 ++++++++++++++++----------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/yunohost.py b/yunohost.py index 4914a8d2..c0c23bff 100644 --- a/yunohost.py +++ b/yunohost.py @@ -106,7 +106,7 @@ def win_msg(astr): global win if os.isatty(1): print('\n' + colorize(_("Success: "), 'green') + astr + '\n') - + win.append(astr) @@ -277,18 +277,22 @@ class YunoHostLDAP(Singleton): elif self.pwd: pass else: - need_password = True - while need_password: - try: - self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow')) - self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd) - except KeyboardInterrupt, EOFError: - raise YunoHostError(125, _("Interrupted")) - except ldap.INVALID_CREDENTIALS: - print(_('Invalid password... Try again')) - else: - need_password = False - + try: + with open('/etc/yunohost/passwd') as f: + self.pwd = f.read() + except IOError: + need_password = True + while need_password: + try: + self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow')) + self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd) + except KeyboardInterrupt, EOFError: + raise YunoHostError(125, _("Interrupted")) + except ldap.INVALID_CREDENTIALS: + print(_('Invalid password... Try again')) + else: + need_password = False + try: self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd) self.connected = True diff --git a/yunohost.tac b/yunohost.tac index 13cbb96a..dba98f68 100755 --- a/yunohost.tac +++ b/yunohost.tac @@ -112,24 +112,23 @@ def http_exec(request, **kwargs): raise YunoHostError(168, _('Function not yet implemented : ') + dict['function'].split('.')[1]) # Execute requested function - with YunoHostLDAP(password=request.getPassword()): + try: + with open('/var/run/yunohost.pid', 'r'): + raise YunoHostError(1, _("A YunoHost command is already running")) + except IOError: + with open('/var/run/yunohost.pid', 'w') as f: + f.write('ldap') + os.system('chmod 400 /var/run/yunohost.pid') + with open('/etc/yunohost/passwd', 'w') as f: + f.write(request.getPassword()) + os.system('chmod 400 /etc/yunohost/passwd') try: - with open('/var/run/yunohost.pid', 'r'): - raise YunoHostError(1, _("A YunoHost command is already running")) - except IOError: - with open('/var/run/yunohost.pid', 'w') as f: - f.write('ldap') - os.system('chmod 400 /var/run/yunohost.pid') - with open('/etc/yunohost/passwd', 'w') as f: - f.write(request.getPassword()) - os.system('chmod 400 /etc/yunohost/passwd') - try: - result = func(**validated_args) - except KeyboardInterrupt, EOFError: - raise YunoHostError(125, _("Interrupted")) - finally: - os.remove('/etc/yunohost/passwd') - os.remove('/var/run/yunohost.pid') + result = func(**validated_args) + except KeyboardInterrupt, EOFError: + raise YunoHostError(125, _("Interrupted")) + finally: + os.remove('/etc/yunohost/passwd') + os.remove('/var/run/yunohost.pid') if result is None: result = {} if len(yunohost.win) > 0: