Commits

Mikhail Korobov  committed defc849

'fab create_linux_account' command

  • Participants
  • Parent commits a82c059

Comments (0)

Files changed (3)

File fab_deploy/__init__.py

 from fabric.api import *
 
 from fab_deploy.deploy import *
-from fab_deploy.commands import touch, pip, mysqldump, delete_pyc, pip_install, pip_update, restart_apache
+from fab_deploy.commands import touch, pip, mysqldump, delete_pyc, pip_install, pip_update
 from fab_deploy.django_commands import migrate, manage, syncdb, compress, test, coverage
 from fab_deploy.crontab import crontab_set, crontab_add, crontab_show, crontab_remove, crontab_update
 from fab_deploy.utils import run_as, update_env, inside_project, inside_virtualenv
+from fab_deploy.system import create_linux_account

File fab_deploy/deploy.py

 def setup_web_server():
     apache_install()
     nginx_install()
-
     apache_setup()
     nginx_setup()
-

File fab_deploy/system.py

 #coding: utf-8
 from __future__ import with_statement
-from fabric.api import run, settings
+import os.path
+from fabric.api import run, settings, env, prefix, cd
+from fabric.contrib.files import append
 from fab_deploy.utils import run_as
 
 @run_as('root')
     aptitude_install('mercurial git-core', 'lenny-backports')
     aptitude_install('subversion bzr')
 
+@run_as('root')
+def create_linux_account(pub_key_file):
+    """ Creates linux account and setups ssh access """
+    with open(os.path.normpath(pub_key_file), 'rt') as f:
+        ssh_key = f.read()
+    username = env.conf['USER']
+    with (settings(warn_only=True)):
+        run('adduser %s --disabled-password --gecos ""' % username)
+        with cd('/home/' + username):
+            run('mkdir -p .ssh')
+            append('.ssh/authorized_keys', ssh_key)
+            run('chown -R %s:%s .ssh' % (username, username))
+
+def ssh_add_key(pub_key_file):
+    with open(os.path.normpath(pub_key_file), 'rt') as f:
+        ssh_key = f.read()
+    append('.ssh/authorized_keys', ssh_key)
+
 
 #@run_as('root')
 #def install_backup_system():