From 247db0c7f38172ffda7123313ffb408ed1cc37ae Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Sun, 11 Jan 2015 16:26:21 -0800 Subject: [PATCH 01/10] Testing for Python 2/3 before installing Node packages. --- scripts/devSetup/repositoryInstaller.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/devSetup/repositoryInstaller.py b/scripts/devSetup/repositoryInstaller.py index 3e854b876..147a88165 100644 --- a/scripts/devSetup/repositoryInstaller.py +++ b/scripts/devSetup/repositoryInstaller.py @@ -64,7 +64,14 @@ class RepositoryInstaller(): #TODO: "Replace npm with more robust package #npm_location = self.config.directory.bin_directory + os.sep + "node" + os.sep + "bin" + os.sep + "npm" npm_location = u"npm" - return_code = subprocess.call([npm_location,u"install"],cwd=self.config.directory.root_dir + os.sep + u"coco") + if sys.version_info[0] == 2: + py_cmd = "python" + else: + py_cmd = subprocess.check_output(['which', 'python2']) + return_code = subprocess.call([npm_location, u"install", + "--python=" + py_cmd], + cwd=self.config.directory.root_dir + + os.sep + u"coco") if return_code: raise errors.CoCoError(u"Failed to install node packages") else: From 9465a41efdf714f0c910dd6f32bc817f2278e2cf Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Sun, 11 Jan 2015 16:26:59 -0800 Subject: [PATCH 02/10] Added Arch and Ubuntu distro-specific installation options. --- scripts/devSetup/factories.py | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/scripts/devSetup/factories.py b/scripts/devSetup/factories.py index 1eab847bb..e256f3db6 100644 --- a/scripts/devSetup/factories.py +++ b/scripts/devSetup/factories.py @@ -80,9 +80,93 @@ class SetupFactory(object): class MacSetup(SetupFactory): def setup(self): super(self.__class__, self).setup() + class WinSetup(SetupFactory): def setup(self): super(self.__class__, self).setup() + class LinuxSetup(SetupFactory): def setup(self): + self.distroSetup() super(self.__class__, self).setup() + + 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 == "arch": + print("Arch Linux detected. Would you like to install \n" + "NodeJS and MongoDB via pacman? [y/N]") + if 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 = input().lower() + if answer in ["r", "retry"]: + return(self.distroSetup()) + elif answer in ["c", "continue"]: + return() + else: + exit(1) + else: + try: + print("Enabling and starting MongoDB in systemd.") + subprocess.check_call(["systemctl", "enable", + "mongodb.service"]) + subprocess.check_call(["systemctl", "start", + "mongodb.service"]) + print("Node and Mongo installed. Continuing.") + except subprocess.CalledProcessError as err: + print("Mongo failed to start. Aborting") + exit(1) + if distro == "ubuntu": + print("Ubuntu installation detected. Would you like to install \n" + "NodeJS and MongoDB via apt-get? [y/N]") + if input().lower() in ["y", "yes"]: + 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"]) + subprocess.check_call(["add-apt-repository", + "ppa:chris-lea/node.js"]) + 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]") + answer = input().lower() + 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", + "nodejs", "mongodb-org", "-y"]) + except subprocess.CalledProcessError as err: + print("Installation via apt-get failed. \nContinue " + "with manual installation, or Abort? [c/A]") + if input().lower() in ["c", "continue"]: + return() + else: + exit(1) From 33b505bd87852a1e6905ca79ac9aeca0ee4c8c7d Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Sun, 11 Jan 2015 19:01:01 -0800 Subject: [PATCH 03/10] Fixing Ubuntu code slightly. --- scripts/devSetup/factories.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/devSetup/factories.py b/scripts/devSetup/factories.py index e256f3db6..a22baf267 100644 --- a/scripts/devSetup/factories.py +++ b/scripts/devSetup/factories.py @@ -170,3 +170,11 @@ class LinuxSetup(SetupFactory): return() else: exit(1) + else: + print("NodeJS and MongoDB installed successfully. " + "Staring MongoDB.") + try: + subprocess.check_call(["service", "mongod", "start"]) + except subprocess.CalledProcessError as err: + print("Mongo failed to start. Aborting.") + exit(1) From 6c731d1e03252f284ed8e7a3eaa2167080199262 Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Sun, 11 Jan 2015 19:08:59 -0800 Subject: [PATCH 04/10] Python2 fix --- scripts/devSetup/factories.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/devSetup/factories.py b/scripts/devSetup/factories.py index a22baf267..8331e7800 100644 --- a/scripts/devSetup/factories.py +++ b/scripts/devSetup/factories.py @@ -104,7 +104,7 @@ class LinuxSetup(SetupFactory): if distro == "arch": print("Arch Linux detected. Would you like to install \n" "NodeJS and MongoDB via pacman? [y/N]") - if input().lower() in ["y", "yes"]: + if raw_input().lower() in ["y", "yes"]: try: subprocess.check_call(["pacman", "-S", "nodejs", "mongodb", @@ -112,7 +112,7 @@ class LinuxSetup(SetupFactory): except subprocess.CalledProcessError as err: print("Installation failed. Retry, Continue, or " "Abort? [r/c/A]") - answer = input().lower() + answer = raw_input().lower() if answer in ["r", "retry"]: return(self.distroSetup()) elif answer in ["c", "continue"]: @@ -133,7 +133,7 @@ class LinuxSetup(SetupFactory): if distro == "ubuntu": print("Ubuntu installation detected. Would you like to install \n" "NodeJS and MongoDB via apt-get? [y/N]") - if input().lower() in ["y", "yes"]: + if raw_input().lower() in ["y", "yes"]: print("Adding repositories for MongoDB and NodeJS...") try: subprocess.check_call(["apt-key", "adv", @@ -149,7 +149,7 @@ class LinuxSetup(SetupFactory): print("Adding repositories failed. Retry, Install without" "adding \nrepositories, Skip apt-get installation, " "or Abort? [r/i/s/A]") - answer = input().lower() + answer = raw_input().lower() if answer in ["r", "retry"]: return(self.distroSetup()) elif answer in ["i", "install"]: @@ -166,7 +166,7 @@ class LinuxSetup(SetupFactory): except subprocess.CalledProcessError as err: print("Installation via apt-get failed. \nContinue " "with manual installation, or Abort? [c/A]") - if input().lower() in ["c", "continue"]: + if raw_input().lower() in ["c", "continue"]: return() else: exit(1) From ace7d3d64e7d14ffd2ac1d89345f408e6f2c1dfc Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Sun, 11 Jan 2015 20:23:44 -0800 Subject: [PATCH 05/10] Switching to a fresher source of node for Ubuntu --- scripts/devSetup/factories.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/devSetup/factories.py b/scripts/devSetup/factories.py index 8331e7800..ae55fa061 100644 --- a/scripts/devSetup/factories.py +++ b/scripts/devSetup/factories.py @@ -142,8 +142,9 @@ class LinuxSetup(SetupFactory): "--recv", "7F0CEB10"]) subprocess.check_call(["add-apt-repository", "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen"]) - subprocess.check_call(["add-apt-repository", - "ppa:chris-lea/node.js"]) + subprocess.check_call(["curl", "-sL", + "https://deb.nodesource.com/setup", + "|", "bash"], shell=True) subprocess.check_call(["apt-get", "update"]) except subprocess.CalledProcessError as err: print("Adding repositories failed. Retry, Install without" From 9153e1463deba3fe94a0507715fcd08fe163fa9f Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Sun, 11 Jan 2015 20:42:34 -0800 Subject: [PATCH 06/10] Adjusting the subprocess call. --- scripts/devSetup/factories.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/devSetup/factories.py b/scripts/devSetup/factories.py index ae55fa061..400a7b8e8 100644 --- a/scripts/devSetup/factories.py +++ b/scripts/devSetup/factories.py @@ -142,9 +142,9 @@ class LinuxSetup(SetupFactory): "--recv", "7F0CEB10"]) subprocess.check_call(["add-apt-repository", "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen"]) - subprocess.check_call(["curl", "-sL", - "https://deb.nodesource.com/setup", - "|", "bash"], shell=True) + subprocess.check_call("curl -sL " + "https://deb.nodesource.com/setup" + " | bash", shell=True) subprocess.check_call(["apt-get", "update"]) except subprocess.CalledProcessError as err: print("Adding repositories failed. Retry, Install without" From 84c2d3b9a71dffb9fbda56bfc498b77715c863a6 Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Sun, 11 Jan 2015 22:32:51 -0800 Subject: [PATCH 07/10] Ubuntu starts mongo automatically --- scripts/devSetup/factories.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/devSetup/factories.py b/scripts/devSetup/factories.py index 400a7b8e8..ee7a002eb 100644 --- a/scripts/devSetup/factories.py +++ b/scripts/devSetup/factories.py @@ -174,8 +174,8 @@ class LinuxSetup(SetupFactory): else: print("NodeJS and MongoDB installed successfully. " "Staring MongoDB.") - try: - subprocess.check_call(["service", "mongod", "start"]) - except subprocess.CalledProcessError as err: - print("Mongo failed to start. Aborting.") - exit(1) + #try: + #subprocess.check_call(["service", "mongod", "start"]) + #except subprocess.CalledProcessError as err: + #print("Mongo failed to start. Aborting.") + #exit(1) From c638090cc9ed1ee372058a18d0118b403269ff8a Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Sun, 11 Jan 2015 22:35:24 -0800 Subject: [PATCH 08/10] Missing import --- scripts/devSetup/repositoryInstaller.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/devSetup/repositoryInstaller.py b/scripts/devSetup/repositoryInstaller.py index 147a88165..7262466fe 100644 --- a/scripts/devSetup/repositoryInstaller.py +++ b/scripts/devSetup/repositoryInstaller.py @@ -4,6 +4,7 @@ import configuration import errors import subprocess import os +import sys from which import which #git clone https://github.com/nwinter/codecombat.git coco class RepositoryInstaller(): From a9974b29294d69f0eee188e2c65a465c31e6d2d0 Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Sun, 11 Jan 2015 22:37:56 -0800 Subject: [PATCH 09/10] Adding build-essential for Ubuntu --- scripts/devSetup/factories.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/devSetup/factories.py b/scripts/devSetup/factories.py index ee7a002eb..e1c4dcf0a 100644 --- a/scripts/devSetup/factories.py +++ b/scripts/devSetup/factories.py @@ -163,7 +163,8 @@ class LinuxSetup(SetupFactory): try: print("Repositories added successfully. Installing NodeJS and MongoDB.") subprocess.check_call(["apt-get", "install", - "nodejs", "mongodb-org", "-y"]) + "nodejs", "mongodb-org", + "build-essential", "-y"]) except subprocess.CalledProcessError as err: print("Installation via apt-get failed. \nContinue " "with manual installation, or Abort? [c/A]") From 70542acb040dad412619261088c1d9aa838173ba Mon Sep 17 00:00:00 2001 From: Elliott Seyler Date: Mon, 12 Jan 2015 12:03:54 -0800 Subject: [PATCH 10/10] Commenting out mongo autostart on Arch. --- scripts/devSetup/factories.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/devSetup/factories.py b/scripts/devSetup/factories.py index e1c4dcf0a..493427072 100644 --- a/scripts/devSetup/factories.py +++ b/scripts/devSetup/factories.py @@ -120,16 +120,16 @@ class LinuxSetup(SetupFactory): else: exit(1) else: - try: - print("Enabling and starting MongoDB in systemd.") - subprocess.check_call(["systemctl", "enable", - "mongodb.service"]) - subprocess.check_call(["systemctl", "start", - "mongodb.service"]) - print("Node and Mongo installed. Continuing.") - except subprocess.CalledProcessError as err: - print("Mongo failed to start. Aborting") - exit(1) + #try: + #print("Enabling and starting MongoDB in systemd.") + #subprocess.check_call(["systemctl", "enable", + # "mongodb.service"]) + #subprocess.check_call(["systemctl", "start", + # "mongodb.service"]) + #print("Node and Mongo installed. Continuing.") + #except subprocess.CalledProcessError as err: + #print("Mongo failed to start. Aborting") + #exit(1) if distro == "ubuntu": print("Ubuntu installation detected. Would you like to install \n" "NodeJS and MongoDB via apt-get? [y/N]")