Commits

Vladimir Mihailenco committed e77f917

Update create_linux_account

  • Participants
  • Parent commits 1447e65
  • Branches sudo_refactoring

Comments (0)

Files changed (2)

File fab_deploy/system.py

 
 def create_linux_account(pub_key_file, username=None):
     """ Creates linux account, setups ssh access and pip.conf file. """
-    with open(os.path.normpath(pub_key_file), 'rt') as f:
-        ssh_key = f.read()
 
-    if username is None:
-        username = env.conf.USER
+    @run_as(env.conf.SUDO_USER)
+    def wrapper():
+        with open(os.path.normpath(pub_key_file), 'rt') as f:
+            ssh_key = f.read()
 
-    @utils.run_as(username)
-    def setup_pip_conf():
-        from fab_deploy import virtualenv
-        virtualenv.pip_setup_conf()
+        if username is None:
+            username = env.conf.USER
 
-    with (settings(warn_only=True)):
-        utils.safe_sudo('adduser %s --disabled-password --gecos ""' % username)
+        @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):
-            utils.safe_sudo('mkdir -p .ssh')
-            files.append('.ssh/authorized_keys', ssh_key, use_sudo=True,
-                         user=env.conf.SUDO_USER)
-            utils.safe_sudo('chown -R %s:%s .ssh' % (username, username))
+            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()
 
+    return wrapper()
+
 @utils.run_as('root')
 def create_sudo_linux_account(pub_key_file, username=None):
     if username is None:
 
 def aptitude_install(packages, options=''):
     """ Installs package via aptitude. """
+    if not hasattr(env.conf, '_APTITUDE_UPDATED'):
+        utils.safe_sudo('aptitude update')
+        env.conf._APTITUDE_UPDATED = True
     utils.safe_sudo('aptitude install %s -y %s' % (options, packages,))
 
 

File fab_deploy/utils.py

             return path
 
 def safe_sudo(command, shell=True, pty=True, combine_stderr=True):
-    user = env.conf.SUDO_USER
     return sudo(command, shell=shell, pty=pty, combine_stderr=combine_stderr,
-                user=user)
+                user=env.conf.SUDO_USER)