2016-03-15 06:54:17 +00:00
|
|
|
# wget setup_frappe.py | python
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
2016-03-17 09:50:21 +00:00
|
|
|
import getpass
|
2016-03-15 06:54:17 +00:00
|
|
|
from distutils.spawn import find_executable
|
|
|
|
|
|
|
|
bench_repo = '/usr/local/frappe/bench-repo'
|
|
|
|
|
|
|
|
def install_bench(args):
|
|
|
|
# pre-requisites for bench repo cloning
|
2016-03-17 09:50:21 +00:00
|
|
|
success = run_os_command({
|
2016-03-22 07:44:31 +00:00
|
|
|
'apt-get': [
|
|
|
|
'sudo apt-get update',
|
|
|
|
'sudo apt-get install -y git build-essential python-setuptools python-dev'
|
|
|
|
],
|
|
|
|
'yum': [
|
|
|
|
'sudo yum groupinstall -y "Development tools"',
|
|
|
|
'sudo yum install -y git python-setuptools python-devel'
|
|
|
|
],
|
2016-03-17 09:50:21 +00:00
|
|
|
})
|
|
|
|
|
2016-03-22 07:44:31 +00:00
|
|
|
if not find_executable("git"):
|
|
|
|
success = run_os_command({
|
|
|
|
'brew': 'brew install git'
|
|
|
|
})
|
|
|
|
|
2016-03-17 09:50:21 +00:00
|
|
|
if not success:
|
2016-03-22 07:44:31 +00:00
|
|
|
print 'Could not install pre-requisites. Please check for errors or install them manually.'
|
2016-03-17 09:50:21 +00:00
|
|
|
return
|
|
|
|
|
2016-03-22 07:44:31 +00:00
|
|
|
# secure pip installation
|
|
|
|
if not os.path.exists("get-pip.py"):
|
|
|
|
run_os_command({
|
|
|
|
'apt-get': 'wget https://bootstrap.pypa.io/get-pip.py',
|
|
|
|
'yum': 'wget https://bootstrap.pypa.io/get-pip.py'
|
|
|
|
})
|
|
|
|
|
|
|
|
run_os_command({
|
|
|
|
'apt-get': 'sudo python get-pip.py',
|
|
|
|
'yum': 'sudo python get-pip.py',
|
|
|
|
})
|
|
|
|
|
2016-03-17 09:50:21 +00:00
|
|
|
success = run_os_command({
|
2016-03-22 07:44:31 +00:00
|
|
|
'pip': 'sudo pip install ansible'
|
2016-03-17 09:50:21 +00:00
|
|
|
})
|
2016-03-15 06:54:17 +00:00
|
|
|
|
2016-03-22 07:44:31 +00:00
|
|
|
if not success:
|
|
|
|
could_not_install('Ansible')
|
|
|
|
|
2016-03-17 07:29:44 +00:00
|
|
|
if is_sudo_user():
|
2016-03-22 07:44:31 +00:00
|
|
|
raise Exception('Please run this script as a non-root user with sudo privileges, but without using sudo')
|
2016-03-17 07:29:44 +00:00
|
|
|
|
2016-03-15 06:54:17 +00:00
|
|
|
# clone bench repo
|
2016-03-15 12:41:08 +00:00
|
|
|
clone_bench_repo()
|
2016-03-15 06:54:17 +00:00
|
|
|
|
|
|
|
if args.develop:
|
|
|
|
run_playbook('develop/install.yml', sudo=True)
|
|
|
|
|
|
|
|
def install_python27():
|
|
|
|
version = (sys.version_info[0], sys.version_info[1])
|
|
|
|
|
|
|
|
if version == (2, 7):
|
|
|
|
return
|
|
|
|
|
2016-03-22 07:44:31 +00:00
|
|
|
print 'Installing Python 2.7'
|
2016-03-15 06:54:17 +00:00
|
|
|
|
|
|
|
# install python 2.7
|
|
|
|
success = run_os_command({
|
2016-03-22 07:44:31 +00:00
|
|
|
'apt-get': 'sudo apt-get install -y python2.7',
|
|
|
|
'yum': 'sudo yum install -y python27',
|
|
|
|
'brew': 'brew install python'
|
2016-03-15 06:54:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
if not success:
|
2016-03-22 07:44:31 +00:00
|
|
|
could_not_install('Python 2.7')
|
2016-03-15 06:54:17 +00:00
|
|
|
|
|
|
|
# replace current python with python2.7
|
2016-03-22 07:44:31 +00:00
|
|
|
os.execvp('python2.7', ([] if is_sudo_user() else ['sudo']) + ['python2.7', __file__] + sys.argv[1:])
|
2016-03-15 06:54:17 +00:00
|
|
|
|
|
|
|
def clone_bench_repo():
|
2016-03-22 07:44:31 +00:00
|
|
|
'''Clones the bench repository in the user folder'''
|
2016-03-15 06:54:17 +00:00
|
|
|
|
|
|
|
if os.path.exists(bench_repo):
|
|
|
|
return 0
|
2016-03-17 07:29:44 +00:00
|
|
|
|
2016-03-17 09:50:21 +00:00
|
|
|
run_os_command({
|
|
|
|
'brew': 'mkdir -p /usr/local/frappe',
|
|
|
|
'apt-get': 'sudo mkdir -p /usr/local/frappe',
|
|
|
|
'yum': 'sudo mkdir -p /usr/local/frappe',
|
|
|
|
})
|
|
|
|
|
|
|
|
# change user
|
|
|
|
run_os_command({
|
|
|
|
'ls': 'sudo chown -R {user}:{user} /usr/local/frappe'.format(user=getpass.getuser()),
|
|
|
|
})
|
|
|
|
|
2016-03-15 06:54:17 +00:00
|
|
|
success = run_os_command(
|
2016-04-13 15:51:41 +00:00
|
|
|
{'git': 'git clone https://github.com/frappe/bench {bench_repo} --depth 1 --branch develop'.format(bench_repo=bench_repo)}
|
2016-03-15 06:54:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return success
|
|
|
|
|
|
|
|
def run_os_command(command_map):
|
2016-03-22 07:44:31 +00:00
|
|
|
'''command_map is a dictionary of {'executable': command}. For ex. {'apt-get': 'sudo apt-get install -y python2.7'} '''
|
|
|
|
success = True
|
|
|
|
for executable, commands in command_map.items():
|
2016-03-15 06:54:17 +00:00
|
|
|
if find_executable(executable):
|
2016-03-22 07:44:31 +00:00
|
|
|
if isinstance(commands, basestring):
|
|
|
|
commands = [commands]
|
|
|
|
|
|
|
|
for command in commands:
|
|
|
|
returncode = subprocess.check_call(command, shell=True)
|
|
|
|
success = success and ( returncode == 0 )
|
|
|
|
|
2016-03-15 06:54:17 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
return success
|
|
|
|
|
|
|
|
def could_not_install(package):
|
2016-03-22 07:44:31 +00:00
|
|
|
raise Exception('Could not install {0}. Please install it manually.'.format(package))
|
2016-03-15 06:54:17 +00:00
|
|
|
|
|
|
|
def is_sudo_user():
|
|
|
|
return os.geteuid() == 0
|
|
|
|
|
2016-03-17 07:29:44 +00:00
|
|
|
def run_playbook(playbook_name, sudo=False):
|
2016-03-22 07:44:31 +00:00
|
|
|
args = ['ansible-playbook', '-c', 'local', playbook_name]
|
2016-03-15 06:54:17 +00:00
|
|
|
if sudo:
|
|
|
|
args.append('-K')
|
2016-03-17 07:29:44 +00:00
|
|
|
|
2016-03-15 07:00:02 +00:00
|
|
|
success = subprocess.check_call(args, cwd=os.path.join(bench_repo, 'playbooks'))
|
2016-03-15 06:54:17 +00:00
|
|
|
return success
|
|
|
|
|
|
|
|
def parse_commandline_args():
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Frappe Installer')
|
|
|
|
parser.add_argument('--develop', dest='develop', action='store_true', default=False,
|
2016-03-22 07:44:31 +00:00
|
|
|
help='Install developer setup')
|
2016-03-15 06:54:17 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
return args
|
|
|
|
|
2016-03-22 07:44:31 +00:00
|
|
|
if __name__ == '__main__':
|
2016-03-15 06:54:17 +00:00
|
|
|
try:
|
|
|
|
import argparse
|
|
|
|
except ImportError:
|
|
|
|
# install python2.7
|
|
|
|
install_python27()
|
|
|
|
|
|
|
|
args = parse_commandline_args()
|
|
|
|
|
|
|
|
install_bench(args)
|