From 35f1161453c73ab8b1ddcd5352c0fb13fc67b151 Mon Sep 17 00:00:00 2001 From: Mriyam Tamuli Date: Sat, 8 Oct 2016 14:53:53 +0530 Subject: [PATCH] Solves SSH Key problem when admin user already exists --- contrib/dokku-installer.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/contrib/dokku-installer.py b/contrib/dokku-installer.py index b57cf3b63..ab01a01a6 100755 --- a/contrib/dokku-installer.py +++ b/contrib/dokku-installer.py @@ -3,6 +3,7 @@ import cgi import json import os +import re import SimpleHTTPServer import SocketServer import subprocess @@ -100,7 +101,10 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): with open('{0}/HOSTNAME'.format(dokku_root), 'w') as f: f.write(params['hostname'].value) - command = ['sshcommand', 'acl-add', 'dokku', 'admin'] + user = 'admin' + if self.admin_user_exists(): + user = 'web-admin' + command = ['sshcommand', 'acl-add', 'dokku', user] for key in params['keys'].value.split("\n"): proc = subprocess.Popen(command, stdin=subprocess.PIPE) proc.stdin.write(key) @@ -119,6 +123,16 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): self.end_headers() self.wfile.write(json.dumps({'status': 'ok'})) + def admin_user_exists(self): + command = 'dokku ssh-keys:list' + pattern = re.compile(r'NAME="admin"') + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + for line in proc.stdout: + if pattern.search(line): + return True + else: + return False + def set_debconf_selection(debconf_type, key, value): found = False