def create_user(): with settings(user='******'): cuisine.user_ensure('ssmjp') append('/etc/sudoers', 'ssmjp ALL=(ALL) ALL') cuisine.ssh_authorize('ssmjp', cuisine.file_local_read('~/.ssh/ssmjp.pub')) conf = Pit.get('ssmjp-user', { 'require': { 'password': '******' } }) cuisine.user_passwd('ssmjp', conf['password'])
def setup_os(): with cuisine.mode_sudo(): cuisine.ssh_authorize( "matze" , cuisine.file_local_read("./cuisine_id.pub")) for _ in PACKAGE_ENSURE: cuisine.package_ensure(_) cuisine.run("a2enmod rewrite") # TODO enable AllowOverride none => all for /var/www cuisine.run("service apache2 restart")
def inject_ssl_pubkey(user): ssl_pub = file_local_read('~/.ssh/id_dsa.pub') ssh_folder = '/home/{user}/.ssh/'.format(user=user) sudo('mkdir -p %s' % ssh_folder) append("/home/{user}/.ssh/authorized_keys".format(user=user), ssl_pub, use_sudo=True) sudo('chown -R {user}:{user} {ssh_folder}'.format( user=user, ssh_folder=ssh_folder)) sudo('chmod -R 0700 %s' % ssh_folder) sudo('chmod 0600 %s' % "/home/{user}/.ssh/authorized_keys".format(user=user))
def create_user(): with settings(user='******'): cuisine.user_ensure('ssmjp') append('/etc/sudoers', 'ssmjp ALL=(ALL) ALL') cuisine.ssh_authorize('ssmjp', cuisine.file_local_read('~/.ssh/ssmjp.pub')) conf = Pit.get('ssmjp-user', {'require': { 'password': '******' }}) cuisine.user_passwd('ssmjp', conf['password'])
def install_nginx_upstart(version): """Install nginx upstart config.""" install_dir = os.path.join(_INSTALL_DIR, 'nginx', version) nginx_bin = os.path.join(install_dir, 'sbin', 'nginx') nginx_pid = os.path.join(install_dir, 'logs', 'nginx.pid') context = { 'nginx_bin': nginx_bin, 'nginx_pid': nginx_pid, } nginx_tpl = os.path.join(ETC_DIR, 'init', 'nginx.conf') tpl_content = file_local_read(nginx_tpl) content = text_template(tpl_content, context) with mode_sudo(): file_write('/etc/init/nginx.conf', content)
def install_upstart(): """Install nginx upstart config.""" version = get_config()['version'] install_dir = os.path.join(_INSTALL_DIR, 'nginx', version) nginx_bin = os.path.join(install_dir, 'sbin', 'nginx') nginx_pid = os.path.join(install_dir, 'logs', 'nginx.pid') context = { 'nginx_bin': nginx_bin, 'nginx_pid': nginx_pid, } nginx_tpl = os.path.join(ETC_DIR, 'init', 'nginx.conf') tpl_content = cuisine.file_local_read(nginx_tpl) content = cuisine.text_template(tpl_content, context) with cuisine.mode_sudo(): cuisine.file_write('/etc/init/nginx.conf', content)
def setup_dokuwiki(): if not cuisine.file_exists('/tmp/dokuwiki-stable.tgz'): cuisine.cd("/tmp") cuisine.run( " wget -c http://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz") if not cuisine.dir_exists('/tmp/dokuwiki-20*'): cuisine.cd( "/tmp" ) cuisine.run("tar xvzf dokuwiki-stable.tgz"); ## Improve for update purpose #if not cuisine.dir_exists( www_folder + "/dokuwiki" ): if True: cuisine.log_message("Installing") with cuisine.mode_sudo(): cuisine.dir_ensure( www_folder + "/dokuwiki" ) cuisine.run("cp -rv /tmp/dokuwiki-20*/* " + www_folder + "/dokuwiki" ) for _ in ( 'data', 'conf' , 'bin' , 'inc'): cuisine.file_write( www_folder + "/dokuwiki" + "/" + _ + "/.htaccess" , cuisine.file_local_read("./htaccess_template") , owner=http_user , group=http_user) cuisine.dir_ensure( www_folder + "/dokuwiki", owner=http_user , group=http_user , recursive=True ) print "now visit <IP>/dokuwiki/install.php"
def setup_ssh(): puts(fabric.colors.green('[Install SSH Publickey]', True)) with cuisine.mode_sudo(): cuisine.ssh_authorize("pi", cuisine.file_local_read('~/.ssh/id_rsa.pub'))