Vladimir Mihailenco committed e718154

Fix username handling for create_linux_account

Comments (0)

Files changed (3)


 from fabric.contrib import files
 from fabric import utils as fabric_utils
 from fab_deploy import utils
+from fab_deploy import virtualenv
 __all__ = ['create_linux_account', 'create_sudo_linux_account',
     username = username or env.conf.USER
-    @utils.run_as(username)
-    def setup_pip_conf():
-        from fab_deploy import virtualenv
-        virtualenv.pip_setup_conf()
     with (settings(warn_only=True)):
         sudo('adduser %s --disabled-password --gecos ""' % username)
-    with cd(env.conf.HOME_DIR):
+    home_dir = utils.get_home_dir(username)
+    with cd(home_dir):
         sudo('mkdir -p .ssh')
         files.append('.ssh/authorized_keys', ssh_key, use_sudo=True)
         sudo('chown -R %s:%s .ssh' % (username, username))
-    setup_pip_conf()
+    virtualenv.pip_setup_conf(username=username)
 def create_sudo_linux_account(pub_key_file, username=None):


     """ Prints env values. Useful for debugging. """
+def get_home_dir(username):
+    if username == 'root':
+        return '/root/'
+    return '/home/%s/' % username
 def _data_path(fname):
     """Return the path to a data file of ours."""
     return os.path.join(os.path.split(__file__)[0], fname)


     if restart:
-def pip_setup_conf():
+def pip_setup_conf(username=None):
     """ Sets up pip.conf file """
-    run('mkdir -p .pip')
+    username = username or env.conf.USER
+    home_dir = utils.get_home_dir(username)
+    run('mkdir --parents %s.pip' % home_dir)
-        env.conf.HOME_DIR + '/.pip/pip.conf', skip_unexistent=True)
+        home_dir + '.pip/pip.conf', skip_unexistent=True)
 def virtualenv_create():
     run('mkdir -p envs')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.