Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

Vagrantfile: Share the checkout at the host’s path.

Anders Kaseorgcf386e43a077
diff --git a/Vagrantfile b/Vagrantfile
index 6824b092f08..bab29f7af85 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -18,7 +18,7 @@ Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-22.04"
config.vm.synced_folder ".", "/vagrant", disabled: true
- config.vm.synced_folder ".", "/srv/zulip", docker_consistency: "z"
+ config.vm.synced_folder ".", __dir__, docker_consistency: "z"
vagrant_config_file = ENV["HOME"] + "/.zulip-vagrant-config"
if File.file?(vagrant_config_file)
@@ -105,5 +105,5 @@ Vagrant.configure("2") do |config|
# We want provision to be run with the permissions of the vagrant user.
privileged: false,
path: "tools/setup/vagrant-provision",
- env: { "UBUNTU_MIRROR" => ubuntu_mirror }
+ env: { "UBUNTU_MIRROR" => ubuntu_mirror, "ZULIP_PATH" => __dir__ }
end
diff --git a/tools/diagnose b/tools/diagnose
index 042d6d98309..cc3bd67304f 100755
--- a/tools/diagnose
+++ b/tools/diagnose
@@ -56,7 +56,7 @@ def check_django() -> bool:
return True
except ImportError:
print(
- """
+ f"""
ERROR!
We cannot import Django, which is usually a
symptom of not having your Python venv
@@ -64,7 +64,7 @@ def check_django() -> bool:
Make sure your shell does this at init time:
- source /srv/zulip/.venv/bin/activate
+ source {ROOT_DIR}/.venv/bin/activate
Or maybe you forget to run inside your VM?
"""
diff --git a/tools/lib/provision_inner.py b/tools/lib/provision_inner.py
index 9663b770cec..7f31d4fa7e4 100755
--- a/tools/lib/provision_inner.py
+++ b/tools/lib/provision_inner.py
@@ -11,6 +11,7 @@ import glob
import os
import pwd
import re
+import shlex
import shutil
import subprocess
import sys
@@ -134,11 +135,10 @@ def setup_shell_profile(shell_profile: str) -> None:
"if [ -L /srv/zulip-py3-venv ]; then\n" # For development environment downgrades
"source /srv/zulip-py3-venv/bin/activate\n" # Not indented so old versions recognize and avoid re-adding this
"else\n"
- f"source {os.path.join(VENV_PATH, 'bin', 'activate')}\n"
+ f"source {shlex.quote(os.path.join(VENV_PATH, 'bin', 'activate'))}\n"
"fi\n"
)
- if os.path.exists("/srv/zulip"):
- zulip_code += "cd /srv/zulip\n"
+ zulip_code += f"cd {shlex.quote(ZULIP_PATH)}\n"
if zulip_code:
zulip_code = f"\n# begin Zulip setup\n{zulip_code}# end Zulip setup\n"
diff --git a/tools/pre-commit b/tools/pre-commit
index 6c4d91a66e8..2abae874480 100755
--- a/tools/pre-commit
+++ b/tools/pre-commit
@@ -19,10 +19,10 @@ if [ ${#changed_files} -eq 0 ]; then
fi
if [ -z "$VIRTUAL_ENV" ] && command -v vagrant >/dev/null && [ -e .vagrant ]; then
- vcmd="/srv/zulip/tools/lint --skip=gitlint --skip-provision-check $(printf '%q ' "${changed_files[@]}") || true"
+ vcmd="$(dirname "$0")/lint --skip=gitlint --skip-provision-check $(printf '%q ' "${changed_files[@]}") || true"
echo "Running lint using vagrant..."
vagrant ssh -c "$vcmd"
else
- ./tools/lint --skip=gitlint --skip-provision-check "${changed_files[@]}" || true
+ "$(dirname "$0")/lint" --skip=gitlint --skip-provision-check "${changed_files[@]}" || true
fi
exit 0
diff --git a/tools/setup/vagrant-provision b/tools/setup/vagrant-provision
index a3ecbb1b4bd..f09364a9eed 100755
--- a/tools/setup/vagrant-provision
+++ b/tools/setup/vagrant-provision
@@ -1,17 +1,20 @@
#!/usr/bin/env bash
-set -x
-set -e
-set -o pipefail
+set -euxo pipefail
# Code should go here, rather than tools/provision, only if it is
# something that we don't want to happen when running provision in a
# development environment not using Vagrant.
+if [ -e /srv/zulip ]; then
+ # Backwards compatibility
+ ZULIP_PATH=/srv/zulip
+fi
+
# Set the Ubuntu mirror
[ ! "$UBUNTU_MIRROR" ] || sudo sed -i 's|http://\(\w*\.\)*archive\.ubuntu\.com/ubuntu/\? |'"$UBUNTU_MIRROR"' |' /etc/apt/sources.list
# Set the MOTD on the system to have Zulip instructions
-sudo ln -nsf /srv/zulip/tools/setup/dev-motd /etc/update-motd.d/99-zulip-dev
+sudo ln -nsf "$ZULIP_PATH/tools/setup/dev-motd" /etc/update-motd.d/99-zulip-dev
sudo rm -f /etc/update-motd.d/10-help-text /etc/update-motd.d/99-bento
sudo dpkg --purge landscape-common
sudo dpkg-divert --add --rename /etc/default/motd-news
@@ -31,7 +34,7 @@ export SKIP_VENV_SHELL_WARNING=1
set +x
# Check if the zulip directory is writable
-if [ ! -w /srv/zulip ]; then
+if [ ! -w "$ZULIP_PATH" ]; then
echo "The vagrant user is unable to write to the zulip directory."
echo "To fix this, run the following commands on the host machine:"
# sudo is required since our uid is not 1000
@@ -45,11 +48,11 @@ if [ ! -w /srv/zulip ]; then
exit 1
fi
# Provision the development environment
-ln -nsf /srv/zulip ~/zulip
-/srv/zulip/tools/provision
+ln -nsf "$ZULIP_PATH" ~/zulip
+"$ZULIP_PATH/tools/provision"
# Run any custom provision hooks the user has configured
-if [ -f /srv/zulip/tools/custom_provision ]; then
- chmod +x /srv/zulip/tools/custom_provision
- /srv/zulip/tools/custom_provision
+if [ -f "$ZULIP_PATH/tools/custom_provision" ]; then
+ chmod +x "$ZULIP_PATH/tools/custom_provision"
+ "$ZULIP_PATH/tools/custom_provision"
fi