2014-01-03 13:32:13 -05:00
|
|
|
__author__ = u'schmatz'
|
|
|
|
|
|
|
|
import errors
|
|
|
|
import configuration
|
|
|
|
import mongo
|
|
|
|
import node
|
|
|
|
import repositoryInstaller
|
|
|
|
import ruby
|
|
|
|
import shutil
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import subprocess
|
2014-01-04 17:53:41 -05:00
|
|
|
def print_computer_information(os_name,address_width):
|
|
|
|
print(os_name + " detected, architecture: " + str(address_width) + " bit")
|
2014-01-03 13:32:13 -05:00
|
|
|
def constructSetup():
|
|
|
|
config = configuration.Configuration()
|
2014-01-04 17:53:41 -05:00
|
|
|
address_width = config.system.get_virtual_memory_address_width()
|
2014-01-03 13:32:13 -05:00
|
|
|
if config.system.operating_system == u"mac":
|
2014-01-04 17:53:41 -05:00
|
|
|
print_computer_information("Mac",address_width)
|
2014-01-03 13:32:13 -05:00
|
|
|
return MacSetup(config)
|
|
|
|
elif config.system.operating_system == u"win":
|
2014-01-04 17:53:41 -05:00
|
|
|
print_computer_information("Windows",address_width)
|
2014-01-03 13:32:13 -05:00
|
|
|
raise NotImplementedError("Windows is not supported at this time.")
|
|
|
|
elif config.system.operating_system == u"linux":
|
2014-01-04 17:53:41 -05:00
|
|
|
print_computer_information("Linux",address_width)
|
2014-01-03 13:32:13 -05:00
|
|
|
return LinuxSetup(config)
|
|
|
|
|
|
|
|
class SetupFactory(object):
|
|
|
|
def __init__(self,config):
|
|
|
|
self.config = config
|
|
|
|
self.mongo = mongo.MongoDB(self.config)
|
|
|
|
self.node = node.Node(self.config)
|
|
|
|
self.repoCloner = repositoryInstaller.RepositoryInstaller(self.config)
|
|
|
|
self.ruby = ruby.Ruby(self.config)
|
|
|
|
def setup(self):
|
|
|
|
mongo_version_string = ""
|
|
|
|
try:
|
|
|
|
mongo_version_string = subprocess.check_output("mongod --version",shell=True)
|
2014-02-27 14:58:45 -05:00
|
|
|
mongo_version_string = mongo_version_string.decode(encoding='UTF-8')
|
2014-04-11 23:48:42 -04:00
|
|
|
except Exception as e:
|
2014-04-11 23:37:06 -04:00
|
|
|
print("Mongod not found: %s"%e)
|
2014-03-29 19:04:36 -04:00
|
|
|
if "v2.6." not in mongo_version_string:
|
2014-04-11 23:37:06 -04:00
|
|
|
if mongo_version_string:
|
|
|
|
print("Had MongoDB version: %s"%mongo_version_string)
|
|
|
|
print("MongoDB not found, so installing a local copy...")
|
2014-01-03 13:32:13 -05:00
|
|
|
self.mongo.download_dependencies()
|
|
|
|
self.mongo.install_dependencies()
|
|
|
|
self.node.download_dependencies()
|
|
|
|
self.node.install_dependencies()
|
|
|
|
#self.repoCloner.cloneRepository()
|
|
|
|
self.repoCloner.install_node_packages()
|
|
|
|
self.ruby.install_gems()
|
|
|
|
|
|
|
|
print ("Doing initial bower install...")
|
|
|
|
bower_path = self.config.directory.root_dir + os.sep + "coco" + os.sep + "node_modules" + os.sep + ".bin" + os.sep + "bower"
|
|
|
|
subprocess.call(bower_path + " --allow-root install",shell=True,cwd=self.config.directory.root_dir + os.sep + "coco")
|
|
|
|
print("Removing temporary directories")
|
2014-01-05 22:42:43 -05:00
|
|
|
self.config.directory.remove_tmp_directory()
|
2014-01-03 13:32:13 -05:00
|
|
|
print("Changing permissions of files...")
|
|
|
|
#TODO: Make this more robust and portable(doesn't pose security risk though)
|
2014-01-03 15:08:14 -05:00
|
|
|
subprocess.call("chmod -R 755 " + self.config.directory.root_dir + os.sep + "coco" + os.sep + "bin",shell=True)
|
2014-01-08 18:43:06 -05:00
|
|
|
chown_command = "chown -R " + os.getenv("SUDO_USER") + " bower_components"
|
|
|
|
chown_directory = self.config.directory.root_dir + os.sep + "coco"
|
|
|
|
subprocess.call(chown_command,shell=True,cwd=chown_directory)
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-03-29 19:45:53 -04:00
|
|
|
print("")
|
|
|
|
print("Done! If you want to start the server, head into coco/bin and run ")
|
2014-01-03 21:31:36 -05:00
|
|
|
print("1. ./coco-mongodb")
|
2014-01-05 19:51:52 -05:00
|
|
|
print("2. ./coco-brunch ")
|
2014-01-03 21:31:36 -05:00
|
|
|
print("3. ./coco-dev-server")
|
2014-01-05 19:51:52 -05:00
|
|
|
print("NOTE: brunch may need to be run as sudo if it doesn't work (ulimit needs to be set higher than default)")
|
2014-03-29 19:45:53 -04:00
|
|
|
print("")
|
|
|
|
print("Before can play any levels you must update the database. See the Setup section here:")
|
2015-01-27 17:39:26 -05:00
|
|
|
print("https://github.com/codecombat/codecombat/wiki/Dev-Setup:-Linux#installing-the-database")
|
2014-03-29 19:45:53 -04:00
|
|
|
print("")
|
2014-03-29 19:59:10 -04:00
|
|
|
print("Go to http://localhost:3000 to see your local CodeCombat in action!")
|
2014-01-03 13:32:13 -05:00
|
|
|
def cleanup(self):
|
2014-01-05 14:01:19 -05:00
|
|
|
self.config.directory.remove_tmp_directory()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
class MacSetup(SetupFactory):
|
|
|
|
def setup(self):
|
|
|
|
super(self.__class__, self).setup()
|
2015-01-11 19:26:59 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
class WinSetup(SetupFactory):
|
|
|
|
def setup(self):
|
|
|
|
super(self.__class__, self).setup()
|
2015-01-11 19:26:59 -05:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
class LinuxSetup(SetupFactory):
|
|
|
|
def setup(self):
|
2015-01-11 19:26:59 -05:00
|
|
|
self.distroSetup()
|
2014-01-03 14:04:06 -05:00
|
|
|
super(self.__class__, self).setup()
|
2015-01-11 19:26:59 -05:00
|
|
|
|
|
|
|
def detectDistro(self):
|
|
|
|
distro_checks = {
|
|
|
|
"arch": "/etc/arch-release",
|
|
|
|
"ubuntu": "/etc/lsb-release"
|
|
|
|
}
|
|
|
|
for distro, path in distro_checks.items():
|
|
|
|
if os.path.exists(path):
|
|
|
|
return(distro)
|
|
|
|
|
|
|
|
def distroSetup(self):
|
|
|
|
distro = self.detectDistro()
|
|
|
|
if distro == "ubuntu":
|
|
|
|
print("Ubuntu installation detected. Would you like to install \n"
|
|
|
|
"NodeJS and MongoDB via apt-get? [y/N]")
|
2015-01-11 22:08:59 -05:00
|
|
|
if raw_input().lower() in ["y", "yes"]:
|
2015-01-11 19:26:59 -05:00
|
|
|
print("Adding repositories for MongoDB and NodeJS...")
|
|
|
|
try:
|
|
|
|
subprocess.check_call(["apt-key", "adv",
|
|
|
|
"--keyserver",
|
|
|
|
"hkp://keyserver.ubuntu.com:80",
|
|
|
|
"--recv", "7F0CEB10"])
|
|
|
|
subprocess.check_call(["add-apt-repository",
|
|
|
|
"deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen"])
|
2015-01-11 23:42:34 -05:00
|
|
|
subprocess.check_call("curl -sL "
|
|
|
|
"https://deb.nodesource.com/setup"
|
|
|
|
" | bash", shell=True)
|
2015-01-11 19:26:59 -05:00
|
|
|
subprocess.check_call(["apt-get", "update"])
|
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
print("Adding repositories failed. Retry, Install without"
|
|
|
|
"adding \nrepositories, Skip apt-get installation, "
|
|
|
|
"or Abort? [r/i/s/A]")
|
2015-01-11 22:08:59 -05:00
|
|
|
answer = raw_input().lower()
|
2015-01-11 19:26:59 -05:00
|
|
|
if answer in ["r", "retry"]:
|
|
|
|
return(self.distroSetup())
|
|
|
|
elif answer in ["i", "install"]:
|
|
|
|
pass
|
|
|
|
elif answer in ["s", "skip"]:
|
|
|
|
return()
|
|
|
|
else:
|
|
|
|
exit(1)
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
print("Repositories added successfully. Installing NodeJS and MongoDB.")
|
|
|
|
subprocess.check_call(["apt-get", "install",
|
2015-01-12 01:37:56 -05:00
|
|
|
"nodejs", "mongodb-org",
|
|
|
|
"build-essential", "-y"])
|
2015-01-11 19:26:59 -05:00
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
print("Installation via apt-get failed. \nContinue "
|
|
|
|
"with manual installation, or Abort? [c/A]")
|
2015-01-11 22:08:59 -05:00
|
|
|
if raw_input().lower() in ["c", "continue"]:
|
2015-01-11 19:26:59 -05:00
|
|
|
return()
|
|
|
|
else:
|
|
|
|
exit(1)
|
2015-01-11 22:01:01 -05:00
|
|
|
else:
|
|
|
|
print("NodeJS and MongoDB installed successfully. "
|
2015-01-27 17:39:26 -05:00
|
|
|
"Starting MongoDB.")
|
2015-01-12 01:32:51 -05:00
|
|
|
#try:
|
|
|
|
#subprocess.check_call(["service", "mongod", "start"])
|
|
|
|
#except subprocess.CalledProcessError as err:
|
|
|
|
#print("Mongo failed to start. Aborting.")
|
|
|
|
#exit(1)
|
2015-01-21 13:52:40 -05:00
|
|
|
if distro == "arch":
|
|
|
|
print("Arch Linux detected. Would you like to install \n"
|
|
|
|
"NodeJS and MongoDB via pacman? [y/N]")
|
|
|
|
if raw_input().lower() in ["y", "yes"]:
|
|
|
|
try:
|
|
|
|
subprocess.check_call(["pacman", "-S",
|
|
|
|
"nodejs", "mongodb",
|
|
|
|
"--noconfirm"])
|
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
print("Installation failed. Retry, Continue, or "
|
|
|
|
"Abort? [r/c/A]")
|
|
|
|
answer = raw_input().lower()
|
|
|
|
if answer in ["r", "retry"]:
|
|
|
|
return(self.distroSetup())
|
|
|
|
elif answer in ["c", "continue"]:
|
|
|
|
return()
|
|
|
|
else:
|
|
|
|
exit(1)
|