Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import with_statement
- from fabric.api import env, local, sudo, settings, hide, run, prompt
- from fabric.utils import warn
- def vagrant():
- env.user = 'vagrant'
- env.hosts = ['127.0.0.1:2222']
- result = local('vagrant global-status | grep running', capture=True)
- machineId = result.split()[0]
- result = local('vagrant ssh-config | grep IdentityFile'.format(machineId), capture=True)
- env.key_filename = result.split()[1]
- def install_mysql():
- # First ensure that MySQL has not already been installed
- if package_installed('mysql-server'):
- warn('MySQL has already been installed')
- return
- # Prompt the user for a MySQL root password
- mysql_root_password = prompt('Please input your MySQL root password:')
- mysql_root_password_again = prompt('Please input your MySQL root password again:')
- if (mysql_root_password != mysql_root_password_again):
- warn('Passwords must match')
- return
- # Prompt the user for a MySQL user and password
- mysql_user = prompt('Please input your MySQL username:')
- mysql_password = prompt('Please input your MySQL password:')
- mysql_password_again = prompt('Please input your MySQL password again:')
- if (mysql_password != mysql_password_again):
- warn('Passwords must match')
- return
- sudo('echo "mysql-server-5.0 mysql-server/root_password password %s" | debconf-set-selections' % mysql_root_password)
- sudo('echo "mysql-server-5.0 mysql-server/root_password_again password %s" | debconf-set-selections' % mysql_root_password_again)
- apt_get('mysql-server')
- # Update my.cnf
- sudo('sed -i "/^bind-address.*/ s/^#*/#/" /etc/mysql/my.cnf')
- sudo('sed -i "/^skip-external-locking/ s/^#*/#/" /etc/mysql/my.cnf')
- sudo('service mysql restart')
- # Create user and grant priveleges
- run('mysql -uroot -p%s -e "create user \'%s\'@\'%%\' identified by \'%s\'"' % (mysql_root_password, mysql_user, mysql_password))
- run('mysql -uroot -p%s -e "grant all on *.* to \'%s\'@\'%%\' identified by \'%s\'"' % (mysql_root_password, mysql_user, mysql_password))
- # Utils
- def package_installed(pkg_name):
- cmd_f = 'dpkg-query -l "%s" | grep -q ^.i'
- cmd = cmd_f % (pkg_name)
- with settings(hide('warnings', 'stderr'), warn_only=True):
- result = run(cmd)
- return result.succeeded
- def apt_get(*packages):
- sudo('apt-get -y --no-upgrade install %s' % ' '.join(packages), shell=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement