2018-02-14 19:35:08 +01:00
|
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
|
2019-08-30 18:43:05 +02:00
|
|
|
|
###
|
|
|
|
|
# Set user configuration
|
|
|
|
|
set_user_config() {
|
|
|
|
|
echo "Setting ´vagrant´ user profile configuration"
|
2018-02-27 01:18:24 +01:00
|
|
|
|
|
|
|
|
|
# Virtual environment flag
|
2019-08-30 18:43:05 +02:00
|
|
|
|
echo -e '\n\n# Set virtual environment flag' >> ~/.profile
|
|
|
|
|
echo -e 'export VIRTUAL_DEV_ENV=true\n' >> ~/.profile
|
2018-02-27 01:18:24 +01:00
|
|
|
|
|
|
|
|
|
# Language configuration
|
2019-08-30 18:43:05 +02:00
|
|
|
|
echo -e '\n# Set locale configuration' >> ~/.profile
|
2018-02-27 01:18:24 +01:00
|
|
|
|
echo 'export LC_ALL=en_US.UTF-8' >> ~/.profile
|
|
|
|
|
echo 'export LANG=en_US.UTF-8' >> ~/.profile
|
2019-08-30 18:43:05 +02:00
|
|
|
|
echo -e 'export LANGUAGE=en_US.UTF-8\n' >> ~/.profile
|
2019-08-30 18:49:50 +02:00
|
|
|
|
|
|
|
|
|
# Switch to project path after login
|
|
|
|
|
echo -e '\n# Navigate to /vagrant after login' >> ~/.profile
|
|
|
|
|
echo -e 'cd /vagrant\n' >> ~/.profile
|
2019-08-30 18:43:05 +02:00
|
|
|
|
}
|
2018-02-27 01:18:24 +01:00
|
|
|
|
|
2019-08-30 18:43:05 +02:00
|
|
|
|
###
|
|
|
|
|
# Install and configure PostgreSQL database manager
|
|
|
|
|
install_postgres() {
|
2018-02-14 19:35:08 +01:00
|
|
|
|
echo "Installing PostgreSQL"
|
2019-08-30 18:43:05 +02:00
|
|
|
|
sudo apt-get update
|
|
|
|
|
sudo apt-get install -y postgresql postgresql-contrib
|
2018-02-14 19:35:08 +01:00
|
|
|
|
|
2019-08-30 18:43:05 +02:00
|
|
|
|
# Set up ubuntu user
|
2018-02-14 19:35:08 +01:00
|
|
|
|
sudo -u postgres bash -c "psql -c \"CREATE USER ubuntu WITH PASSWORD 'ubuntu';\""
|
|
|
|
|
sudo -u postgres bash -c "psql -c \"ALTER USER ubuntu WITH SUPERUSER;\""
|
|
|
|
|
|
2019-08-30 18:43:05 +02:00
|
|
|
|
# Make available useful extensions to the schemas
|
2018-02-14 19:35:08 +01:00
|
|
|
|
sudo -u postgres bash -c "psql -c \"CREATE EXTENSION unaccent SCHEMA pg_catalog;\""
|
|
|
|
|
sudo -u postgres bash -c "psql -c \"CREATE EXTENSION pg_trgm SCHEMA pg_catalog;\""
|
|
|
|
|
|
2019-08-30 18:43:05 +02:00
|
|
|
|
# Start service
|
|
|
|
|
sudo service postgresql start
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
# Install Redis data store
|
|
|
|
|
install_redis() {
|
|
|
|
|
echo "Installing Redis"
|
|
|
|
|
sudo apt-get install -y redis-server
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
# Install Imagemagick image manipulation utilities
|
|
|
|
|
install_imagemagick() {
|
|
|
|
|
echo "Installing Imagemagick"
|
|
|
|
|
sudo apt-get install -y imagemagick
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
# Install ElasticSearch search engine
|
|
|
|
|
install_elasticsearch() {
|
|
|
|
|
echo "Installing Oracle Java 8 and ElasticSearch"
|
|
|
|
|
sudo apt-get install -y openjdk-8-jre apt-transport-https
|
2018-02-14 19:35:08 +01:00
|
|
|
|
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
|
2019-08-30 18:43:05 +02:00
|
|
|
|
echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list
|
|
|
|
|
sudo apt-get update && sudo apt-get install -y elasticsearch
|
2018-02-14 19:35:08 +01:00
|
|
|
|
|
|
|
|
|
# This configuration limits ElasticSearch memory use inside the virtual machine
|
2019-08-30 18:43:05 +02:00
|
|
|
|
sudo bash -c "echo 'node.master: true' >> /etc/elasticsearch/elasticsearch.yml"
|
2018-02-14 19:35:08 +01:00
|
|
|
|
sudo sed -i 's/#bootstrap.memory_lock: true/bootstrap.memory_lock: true/g' /etc/elasticsearch/elasticsearch.yml
|
|
|
|
|
sudo sed -i 's/#ES_JAVA_OPTS=/ES_JAVA_OPTS="-Xms256m -Xmx256m"/g' /etc/default/elasticsearch
|
|
|
|
|
|
|
|
|
|
sudo /bin/systemctl daemon-reload
|
|
|
|
|
sudo /bin/systemctl enable elasticsearch.service
|
2019-08-30 18:43:05 +02:00
|
|
|
|
}
|
2018-02-14 19:35:08 +01:00
|
|
|
|
|
2019-08-30 18:43:05 +02:00
|
|
|
|
###
|
|
|
|
|
# Install Ngrok secure tunnel manager
|
|
|
|
|
install_ngrok() {
|
|
|
|
|
echo 'Installing Ngrok'
|
|
|
|
|
sudo apt-get install -y unzip
|
2018-02-14 19:35:08 +01:00
|
|
|
|
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
|
|
|
|
|
sudo unzip ngrok-stable-linux-amd64.zip -d /usr/local/bin
|
|
|
|
|
rm -rf ngrok-stable-linux-amd64.zip
|
2019-08-30 18:43:05 +02:00
|
|
|
|
}
|
2018-02-14 19:35:08 +01:00
|
|
|
|
|
2019-08-30 18:43:05 +02:00
|
|
|
|
###
|
|
|
|
|
# Install Node Version Manager
|
|
|
|
|
install_nvm() {
|
|
|
|
|
echo "Installing NVM"
|
|
|
|
|
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
|
2018-02-14 19:35:08 +01:00
|
|
|
|
|
2019-08-30 18:43:05 +02:00
|
|
|
|
echo -e "\n# Node Version Manager" >> ~/.profile
|
2018-02-14 19:35:08 +01:00
|
|
|
|
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.profile
|
|
|
|
|
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.profile
|
|
|
|
|
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> ~/.profile
|
2019-08-30 18:43:05 +02:00
|
|
|
|
echo -e "\n" >> ~/.profile
|
2018-02-14 19:35:08 +01:00
|
|
|
|
echo 'autoload -U add-zsh-hook' >> ~/.profile
|
|
|
|
|
echo 'load-nvmrc() {' >> ~/.profile
|
|
|
|
|
echo ' local node_version="$(nvm version)"' >> ~/.profile
|
|
|
|
|
echo ' local nvmrc_path="$(nvm_find_nvmrc)"' >> ~/.profile
|
2019-08-30 18:43:05 +02:00
|
|
|
|
echo -e "\n" >> ~/.profile
|
2018-02-14 19:35:08 +01:00
|
|
|
|
echo ' if [ -n "$nvmrc_path" ]; then' >> ~/.profile
|
|
|
|
|
echo ' local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")' >> ~/.profile
|
2019-08-30 18:43:05 +02:00
|
|
|
|
echo -e "\n" >> ~/.profile
|
2018-02-14 19:35:08 +01:00
|
|
|
|
echo ' if [ "$nvmrc_node_version" = "N/A" ]; then' >> ~/.profile
|
|
|
|
|
echo ' nvm install' >> ~/.profile
|
|
|
|
|
echo ' elif [ "$nvmrc_node_version" != "$node_version" ]; then' >> ~/.profile
|
|
|
|
|
echo ' nvm use' >> ~/.profile
|
|
|
|
|
echo ' fi' >> ~/.profile
|
|
|
|
|
echo ' elif [ "$node_version" != "$(nvm version default)" ]; then' >> ~/.profile
|
|
|
|
|
echo ' echo "Reverting to nvm default version"' >> ~/.profile
|
|
|
|
|
echo ' nvm use default' >> ~/.profile
|
|
|
|
|
echo ' fi' >> ~/.profile
|
|
|
|
|
echo '}' >> ~/.profile
|
|
|
|
|
echo 'add-zsh-hook chpwd load-nvmrc' >> ~/.profile
|
2019-08-30 18:43:05 +02:00
|
|
|
|
echo -e "load-nvmrc\n" >> ~/.profile
|
2018-02-14 19:35:08 +01:00
|
|
|
|
|
|
|
|
|
export NVM_DIR="$HOME/.nvm"
|
|
|
|
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
|
|
|
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
2019-08-30 18:43:05 +02:00
|
|
|
|
}
|
2018-02-14 19:35:08 +01:00
|
|
|
|
|
2019-08-30 18:43:05 +02:00
|
|
|
|
###
|
|
|
|
|
# Install stable version of Node.js
|
|
|
|
|
install_nodejs() {
|
|
|
|
|
echo 'Installing Node.js'
|
2018-02-14 19:35:08 +01:00
|
|
|
|
nvm install stable
|
|
|
|
|
nvm alias default stable
|
|
|
|
|
nvm use default
|
2019-08-30 18:43:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
# Install Yarn package manager
|
|
|
|
|
install_yarn() {
|
|
|
|
|
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
|
|
|
|
|
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
|
|
|
|
|
sudo apt-get update && sudo apt-get -y install yarn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
# Install Ruby Version Manager
|
|
|
|
|
install_rvm() {
|
|
|
|
|
echo 'Installing RVM'
|
2018-02-14 19:35:08 +01:00
|
|
|
|
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
|
|
|
|
\curl -sSL https://get.rvm.io | bash
|
2019-08-30 18:43:05 +02:00
|
|
|
|
source $HOME/.rvm/scripts/rvm
|
2018-02-14 19:35:08 +01:00
|
|
|
|
rvm get head
|
2019-08-30 18:43:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
# Install Matz Ruby Interpreter
|
|
|
|
|
install_ruby() {
|
|
|
|
|
echo 'Installing Ruby'
|
|
|
|
|
sudo apt-get install -y libxml2-dev libxslt1-dev libpq-dev libidn11-dev
|
2018-02-14 19:35:08 +01:00
|
|
|
|
rvm install ruby-2.3.6
|
|
|
|
|
rvm use ruby-2.3.6@global
|
|
|
|
|
gem update --system --no-ri --no-rdoc
|
|
|
|
|
gem update --no-ri --no-rdoc
|
|
|
|
|
rvm use ruby-2.3.6 --default
|
2019-08-30 18:43:05 +02:00
|
|
|
|
rvm cleanup all
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
# Tune-up the system settings
|
|
|
|
|
system_tuning()
|
|
|
|
|
{
|
|
|
|
|
echo "Tunning up the system"
|
|
|
|
|
|
2019-09-01 04:35:07 +02:00
|
|
|
|
# Create pids directory for Sidekick
|
|
|
|
|
sudo mkdir -p /vagrant/tmp/pids
|
|
|
|
|
|
|
|
|
|
# Enable overcomit memmory for Redis
|
2019-08-30 18:43:05 +02:00
|
|
|
|
sudo echo -e "\n## Redis tune-up" >> /etc/sysctl.conf
|
|
|
|
|
sudo echo '# Allow background save on low memory conditions' >> /etc/sysctl.conf
|
|
|
|
|
sudo echo -e "vm.overcommit_memory = 1\n" >> /etc/sysctl.conf
|
|
|
|
|
|
2019-09-01 04:35:07 +02:00
|
|
|
|
# Enagle huge pages for Redis
|
2019-08-30 18:43:05 +02:00
|
|
|
|
sudo touch /etc/rc.local
|
|
|
|
|
sudo echo '## Redis tune-up' >> /etc/rc.local
|
|
|
|
|
sudo echo '# Reduce latency and memory usage' >> /etc/rc.local
|
|
|
|
|
sudo echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local
|
|
|
|
|
sudo echo -e "\n\n"
|
|
|
|
|
sudo echo -e "exit 0\n" >> /etc/rc.local
|
|
|
|
|
sudo chmod +x /etc/rc.local
|
|
|
|
|
|
2019-09-01 04:35:07 +02:00
|
|
|
|
# Increase virtual memory areas for ElasticSearch
|
2019-08-30 18:43:05 +02:00
|
|
|
|
sudo echo -e "\n## ElasticSearch tune-up" >> /etc/sysctl.conf
|
|
|
|
|
sudo echo '# Increase max virtual memory areas' >> /etc/sysctl.conf
|
|
|
|
|
sudo echo -e "vm.max_map_count = 262144\n" >> /etc/sysctl.conf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
# Remove unused software
|
|
|
|
|
clean_up() {
|
|
|
|
|
echo "Removing unused software"
|
|
|
|
|
sudo apt-get -y autoremove && sudo apt-get autoclean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
|
set_user_config
|
|
|
|
|
install_postgres
|
|
|
|
|
install_redis
|
|
|
|
|
install_imagemagick
|
|
|
|
|
install_elasticsearch
|
|
|
|
|
install_ngrok
|
|
|
|
|
install_nvm
|
|
|
|
|
install_nodejs
|
|
|
|
|
install_yarn
|
|
|
|
|
install_rvm
|
|
|
|
|
install_ruby
|
2019-09-01 04:35:07 +02:00
|
|
|
|
system_tuning
|
2019-08-30 18:43:05 +02:00
|
|
|
|
clean_up
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setup "$@"
|