anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: dokku/dokku
Issue: dokku upgrade wipes out VHOST, empties HOSTNAME

Whenever dokku is upgraded (automatically via Ubuntu updates or manually triggered) the /home/dokku/VHOST file gets wiped out. Also, /home/dokku/HOSTNAME gets emptied out.

Whenever an upgrade is done I have to manually patch these 2 files and restart nginx.


Changed files:
contrib/dokku-installer.py

diff --git a/contrib/dokku-installer.py b/contrib/dokku-installer.py
index b5b776cc6..86da5c452 100755
--- a/contrib/dokku-installer.py
+++ b/contrib/dokku-installer.py
@@ -86,8 +86,10 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
                                       'REQUEST_METHOD': 'POST',
                                       'CONTENT_TYPE': self.headers['Content-Type']})
 
+        vhost_enable = 'false'
         dokku_root = os.getenv('DOKKU_ROOT', '/home/dokku')
         if 'vhost' in params and params['vhost'].value == 'true':
+            vhost_enable = 'true'
             with open('{0}/VHOST'.format(dokku_root), 'w') as f:
                 f.write(params['hostname'].value)
         else:
@@ -98,7 +100,6 @@ 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']
         for key in params['keys'].value.split("\\n"):
             proc = subprocess.Popen(command, stdin=subprocess.PIPE)
@@ -109,11 +110,38 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
         if 'selfdestruct' in sys.argv:
             DeleteInstallerThread()
 
+        set_debconf_selection('boolean', 'skip_key_file', 'true')
+        set_debconf_selection('boolean', 'vhost_enable', vhost_enable)
+        set_debconf_selection('boolean', 'web_config', 'false')
+        set_debconf_selection('string', 'hostname', params['hostname'].value)
+
         self.send_response(200)
         self.end_headers()
         self.wfile.write(json.dumps({'status': 'ok'}))
 
 
+def set_debconf_selection(debconf_type, key, value):
+    found = False
+    with open('/etc/os-release', 'r') as f:
+        for line in f:
+            if 'debian' in line:
+                found = True
+
+    if not found:
+        return
+
+    ps = subprocess.Popen(['echo', 'dokku dokku/{0} {1} {2}'.format(
+        key, debconf_type, value
+    )], stdout=subprocess.PIPE)
+
+    try:
+        subprocess.check_output(['debconf-set-selections'], stdin=ps.stdout)
+    except subprocess.CalledProcessError:
+        pass
+
+    ps.wait()
+
+
 class DeleteInstallerThread(object):
     def __init__(self, interval=1):
         thread = threading.Thread(target=self.run, args=())
Repository: dokku/dokku
Issue: Web SSH Key not added when key is already attached to server

As both the debian package and the web ui use the `admin` user, the web ui will fail to add the ssh key, resulting in some users not having access to dokku push.

We should instead use `admin-web` as the admin user from the web ui if we detect that there is an existing `admin` user.

[Here](https://github.com/dokku/dokku/blob/master/contrib/dokku-installer.py#L103) is the line of code that executes this. What I'd do is list users, check if `admin` is in the list, and if so, change the username there from `admin` to `admin-web`.


Changed files:
contrib/dokku-installer.py

diff --git a/contrib/dokku-installer.py b/contrib/dokku-installer.py
index b57cf3b63..9c897fc70 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,8 +101,20 @@ 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']
-        for key in params['keys'].value.split("\\n"):
+        for (index, key) in enumerate(params['keys'].value.splitlines(), 1):
+            user = 'admin'
+            if self.admin_user_exists() is not None:
+                user = 'web-admin'
+                if self.web_admin_user_exists() is not None:
+                    index = int(self.web_admin_user_exists()) + 1
+                elif self.web_admin_user_exists() is None:
+                    index = 1
+            elif self.admin_user_exists() is None:
+                pass
+            else:
+                index = int(self.admin_user_exists()) + 1
+            user = user + str(index)
+            command = ['sshcommand', 'acl-add', 'dokku', user]
             proc = subprocess.Popen(command, stdin=subprocess.PIPE)
             proc.stdin.write(key)
             proc.stdin.close()
@@ -119,6 +132,29 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
         self.end_headers()
         self.wfile.write(json.dumps({'status': 'ok'}))
 
+    def web_admin_user_exists(self):
+        return self.user_exists('web-admin(\\d+)')
+
+    def admin_user_exists(self):
+        return self.user_exists('admin(\\d+)')
+
+    def user_exists(self, name):
+        command = 'dokku ssh-keys:list'
+        pattern = re.compile(r'NAME="' + name + '"')
+        proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
+        max_num = 0
+        exists = False
+        for line in proc.stdout:
+            m = pattern.search(line)
+            if m:
+                # User of the form `user` or `user#` exists
+                exists = True
+                max_num = max(max_num, m.group(1))
+        if exists:
+            return max_num
+        else:
+            return None
+
 
 def set_debconf_selection(debconf_type, key, value):
     found = False