2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2015-08-17 06:37:14 +02:00
|
|
|
import os
|
2015-08-20 02:46:50 +02:00
|
|
|
import sys
|
2015-08-19 04:18:08 +02:00
|
|
|
import logging
|
|
|
|
import platform
|
2016-04-06 20:12:32 +02:00
|
|
|
import subprocess
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2016-04-06 17:15:31 +02:00
|
|
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
|
|
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from zulip_tools import run
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2015-08-19 04:18:08 +02:00
|
|
|
SUPPORTED_PLATFORMS = {
|
|
|
|
"Ubuntu": [
|
|
|
|
"trusty",
|
2016-04-04 23:22:14 +02:00
|
|
|
"xenial",
|
2015-08-19 04:18:08 +02:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2016-03-22 12:24:25 +01:00
|
|
|
VENV_PATH = "/srv/zulip-venv"
|
2016-04-24 18:31:09 +02:00
|
|
|
PY3_VENV_PATH = "/srv/zulip-py3-venv"
|
2016-04-06 19:09:16 +02:00
|
|
|
ZULIP_PATH = os.path.dirname(os.path.abspath(__file__))
|
2015-08-17 20:15:21 +02:00
|
|
|
|
2016-04-06 19:09:16 +02:00
|
|
|
if not os.path.exists(os.path.join(ZULIP_PATH, ".git")):
|
|
|
|
print("Error: No Zulip git repository present!")
|
2015-11-01 17:11:06 +01:00
|
|
|
print("To setup the Zulip development environment, you should clone the code")
|
|
|
|
print("from GitHub, rather than using a Zulip production release tarball.")
|
2015-10-14 01:18:49 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2016-04-06 19:27:42 +02:00
|
|
|
if platform.architecture()[0] == '64bit':
|
|
|
|
arch = 'amd64'
|
|
|
|
elif platform.architecture()[0] == '32bit':
|
|
|
|
arch = "i386"
|
|
|
|
else:
|
|
|
|
logging.critical("Only x86 is supported; ping zulip-devel@googlegroups.com if you want another architecture.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-04-06 20:12:32 +02:00
|
|
|
# Ideally we wouldn't need to install a dependency here, before we
|
|
|
|
# know the codename.
|
|
|
|
subprocess.check_call(["sudo", "apt-get", "install", "-y", "lsb-release"])
|
|
|
|
vendor = subprocess.check_output(["lsb_release", "-is"]).strip()
|
|
|
|
codename = subprocess.check_output(["lsb_release", "-cs"]).strip()
|
2016-04-06 19:27:42 +02:00
|
|
|
if not (vendor in SUPPORTED_PLATFORMS and codename in SUPPORTED_PLATFORMS[vendor]):
|
|
|
|
logging.critical("Unsupported platform: {} {}".format(vendor, codename))
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-04-06 19:30:16 +02:00
|
|
|
POSTGRES_VERSION_MAP = {
|
|
|
|
"trusty": "9.3",
|
2016-04-04 23:22:14 +02:00
|
|
|
"xenial": "9.5",
|
2016-04-06 19:30:16 +02:00
|
|
|
}
|
|
|
|
POSTGRES_VERSION = POSTGRES_VERSION_MAP[codename]
|
|
|
|
|
2016-04-04 23:22:14 +02:00
|
|
|
UBUNTU_COMMON_APT_DEPENDENCIES = [
|
|
|
|
"closure-compiler",
|
|
|
|
"libfreetype6-dev",
|
|
|
|
"libffi-dev",
|
|
|
|
"memcached",
|
|
|
|
"rabbitmq-server",
|
|
|
|
"libldap2-dev",
|
|
|
|
"redis-server",
|
|
|
|
"postgresql-server-dev-all",
|
|
|
|
"libmemcached-dev",
|
|
|
|
"python-dev",
|
|
|
|
"hunspell-en-us",
|
|
|
|
"nodejs",
|
|
|
|
"nodejs-legacy",
|
|
|
|
"python-virtualenv",
|
|
|
|
"supervisor",
|
|
|
|
"git",
|
|
|
|
"npm",
|
|
|
|
"yui-compressor",
|
|
|
|
"wget",
|
|
|
|
"ca-certificates", # Explicit dependency in case e.g. wget is already installed
|
|
|
|
"puppet", # Used by lint-all
|
|
|
|
"gettext", # Used by makemessages i18n
|
|
|
|
"curl", # Used for fetching PhantomJS as wget occasionally fails on redirects
|
|
|
|
"netcat", # Used for flushing memcached
|
|
|
|
]
|
|
|
|
|
|
|
|
APT_DEPENDENCIES = {
|
|
|
|
"trusty": UBUNTU_COMMON_APT_DEPENDENCIES + [
|
|
|
|
"postgresql-9.3",
|
|
|
|
],
|
|
|
|
"xenial": UBUNTU_COMMON_APT_DEPENDENCIES + [
|
|
|
|
"postgresql-9.5",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2015-08-17 06:37:14 +02:00
|
|
|
# tsearch-extras is an extension to postgres's built-in full-text search.
|
|
|
|
# TODO: use a real APT repository
|
2016-03-30 05:58:56 +02:00
|
|
|
TSEARCH_URL_PATTERN = "https://github.com/zulip/zulip-dist-tsearch-extras/raw/master/{}_{}_{}.deb?raw=1"
|
2016-04-06 19:30:16 +02:00
|
|
|
TSEARCH_PACKAGE_NAME = "postgresql-%s-tsearch-extras" % (POSTGRES_VERSION,)
|
2016-03-11 07:38:00 +01:00
|
|
|
TSEARCH_VERSION = "0.1.3"
|
2016-04-06 19:30:16 +02:00
|
|
|
TSEARCH_URL = TSEARCH_URL_PATTERN.format(TSEARCH_PACKAGE_NAME, TSEARCH_VERSION, arch)
|
|
|
|
TSEARCH_STOPWORDS_PATH = "/usr/share/postgresql/%s/tsearch_data/" % (POSTGRES_VERSION,)
|
2015-08-17 06:37:14 +02:00
|
|
|
REPO_STOPWORDS_PATH = os.path.join(
|
|
|
|
ZULIP_PATH,
|
|
|
|
"puppet",
|
|
|
|
"zulip",
|
|
|
|
"files",
|
|
|
|
"postgresql",
|
|
|
|
"zulip_english.stop",
|
|
|
|
)
|
|
|
|
|
2015-08-21 03:06:18 +02:00
|
|
|
LOUD = dict(_out=sys.stdout, _err=sys.stderr)
|
|
|
|
|
2015-08-20 02:46:50 +02:00
|
|
|
def main():
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["sudo", "apt-get", "update"])
|
|
|
|
run(["sudo", "apt-get", "-y", "install"] + APT_DEPENDENCIES[codename])
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2016-04-06 17:15:31 +02:00
|
|
|
temp_deb_path = subprocess.check_output(["mktemp", "package_XXXXXX.deb", "--tmpdir"])
|
|
|
|
run(["wget", "-O", temp_deb_path, TSEARCH_URL])
|
|
|
|
run(["sudo", "dpkg", "--install", temp_deb_path])
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["sudo", "rm", "-rf", VENV_PATH])
|
|
|
|
run(["sudo", "mkdir", "-p", VENV_PATH])
|
|
|
|
run(["sudo", "chown", "{}:{}".format(os.getuid(), os.getgid()), VENV_PATH])
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2016-04-24 18:31:09 +02:00
|
|
|
run(["sudo", "rm", "-rf", PY3_VENV_PATH])
|
|
|
|
run(["sudo", "mkdir", "-p", PY3_VENV_PATH])
|
|
|
|
run(["sudo", "chown", "{}:{}".format(os.getuid(), os.getgid()), PY3_VENV_PATH])
|
|
|
|
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["virtualenv", VENV_PATH])
|
2016-04-24 18:31:09 +02:00
|
|
|
run(["virtualenv", "-p", "python3", PY3_VENV_PATH])
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2015-08-20 02:46:50 +02:00
|
|
|
# Put Python virtualenv activation in our .bash_profile.
|
|
|
|
with open(os.path.expanduser('~/.bash_profile'), 'w+') as bash_profile:
|
|
|
|
bash_profile.writelines([
|
|
|
|
"source .bashrc\n",
|
|
|
|
"source %s\n" % (os.path.join(VENV_PATH, "bin", "activate"),),
|
|
|
|
])
|
2015-08-20 22:40:06 +02:00
|
|
|
|
2016-04-24 18:31:09 +02:00
|
|
|
# Switch current Python context to the python3 virtualenv
|
|
|
|
activate_this = os.path.join(PY3_VENV_PATH, "bin", "activate_this.py")
|
|
|
|
execfile(activate_this, dict(__file__=activate_this))
|
|
|
|
|
|
|
|
run(["pip", "install", "--upgrade", "pip"])
|
|
|
|
# install requirement
|
|
|
|
run(["pip", "install", "--no-deps", "--requirement",
|
|
|
|
os.path.join(ZULIP_PATH, "tools", "py3_test_reqs.txt")])
|
|
|
|
|
|
|
|
# Switch current Python context to the python2 virtualenv.
|
2015-08-20 02:46:50 +02:00
|
|
|
activate_this = os.path.join(VENV_PATH, "bin", "activate_this.py")
|
|
|
|
execfile(activate_this, dict(__file__=activate_this))
|
2015-08-20 22:40:06 +02:00
|
|
|
|
2016-04-24 18:31:09 +02:00
|
|
|
run(["pip", "install", "--upgrade", "pip"])
|
2016-04-09 19:59:10 +02:00
|
|
|
run(["pip", "install", "--no-deps", "--requirement",
|
2016-04-06 17:15:31 +02:00
|
|
|
os.path.join(ZULIP_PATH, "requirements.txt")])
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["sudo", "cp", REPO_STOPWORDS_PATH, TSEARCH_STOPWORDS_PATH])
|
2015-08-20 22:40:06 +02:00
|
|
|
|
2016-03-22 12:24:25 +01:00
|
|
|
# npm install and management commands expect to be run from the root of the
|
|
|
|
# project.
|
2015-08-20 02:46:50 +02:00
|
|
|
os.chdir(ZULIP_PATH)
|
2015-08-20 22:40:06 +02:00
|
|
|
|
2016-04-06 23:39:07 +02:00
|
|
|
run(["tools/install-phantomjs"])
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["tools/download-zxcvbn"])
|
|
|
|
run(["tools/emoji_dump/build_emoji"])
|
|
|
|
run(["scripts/setup/generate_secrets.py", "-d"])
|
2015-09-28 18:17:23 +02:00
|
|
|
if "--travis" in sys.argv:
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["sudo", "service", "rabbitmq-server", "restart"])
|
|
|
|
run(["sudo", "service", "redis-server", "restart"])
|
|
|
|
run(["sudo", "service", "memcached", "restart"])
|
2015-12-12 14:17:30 +01:00
|
|
|
elif "--docker" in sys.argv:
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["sudo", "service", "rabbitmq-server", "restart"])
|
|
|
|
run(["sudo", "pg_dropcluster", "--stop", POSTGRES_VERSION, "main"])
|
|
|
|
run(["sudo", "pg_createcluster", "-e", "utf8", "--start", POSTGRES_VERSION, "main"])
|
|
|
|
run(["sudo", "service", "redis-server", "restart"])
|
|
|
|
run(["sudo", "service", "memcached", "restart"])
|
|
|
|
run(["scripts/setup/configure-rabbitmq"])
|
|
|
|
run(["tools/postgres-init-dev-db"])
|
|
|
|
run(["tools/do-destroy-rebuild-database"])
|
|
|
|
run(["tools/postgres-init-test-db"])
|
|
|
|
run(["tools/do-destroy-rebuild-test-database"])
|
2016-04-07 00:42:53 +02:00
|
|
|
# Install the latest npm.
|
|
|
|
run(["sudo", "npm", "install", "-g", "npm"])
|
2016-03-30 06:56:19 +02:00
|
|
|
# Run npm install last because it can be flaky, and that way one
|
|
|
|
# only needs to rerun `npm install` to fix the installation.
|
2016-04-06 17:15:31 +02:00
|
|
|
run(["npm", "install"])
|
2016-01-26 02:59:30 +01:00
|
|
|
return 0
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2015-08-20 02:46:50 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|