diff --git a/README.md b/README.md index eeb815c66..23f4c71a3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ FabManager is the Fab Lab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects. -[![Coverage Status](https://coveralls.io/repos/github/sleede/fab-manager/badge.svg)](https://coveralls.io/github/sleede/fab-manager) +[![Coverage Status](https://coveralls.io/repos/github/sleede/fab-manager/badge.svg)](https://coveralls.io/github/sleede/fab-manager) [![Docker pulls](https://img.shields.io/docker/pulls/sleede/fab-manager.svg)](https://hub.docker.com/r/sleede/fab-manager/) [![Docker Build Status](https://img.shields.io/docker/build/sleede/fab-manager.svg)](https://hub.docker.com/r/sleede/fab-manager/builds) @@ -12,7 +12,6 @@ FabManager is the Fab Lab management solution. It provides a comprehensive, web- 3. [Setup a production environment](#setup-a-production-environment) 4. [Setup a development environment](#setup-a-development-environment)
4.1. [General Guidelines](#general-guidelines)
-4.2. [Virtual Machine Instructions](#virtual-machine-instructions) 5. [PostgreSQL](#postgresql)
5.1. [Install PostgreSQL 9.4](#setup-postgresql) 6. [ElasticSearch](#elasticsearch)
@@ -61,21 +60,24 @@ The procedure to follow is described in the [docker-compose readme](docker/READM ## Setup a development environment In you intend to run fab-manager on your local machine to contribute to the project development, you can set it up with the following procedure. + This procedure is not easy to follow so if you don't need to write some code for Fab-manager, please prefer the [docker-compose installation method](docker/README.md). +Optionally, you can use a virtual development environment that relies on Vagrant and Virtual Box by following the [virtual machine instructions](doc/virtual-machine.md). + ### General Guidelines 1. Install RVM, with the ruby version specified in the [.ruby-version file](.ruby-version). For more details about the process, please read the [official RVM documentation](http://rvm.io/rvm/install). If you're using ArchLinux, you may have to [read this](doc/archlinux_readme.md) before. - + 2. Install NVM, with the node.js version specified in the [.nvmrc file](.nvmrc). For instructions about installing NVM, please refer to [the NVM readme](https://github.com/creationix/nvm#installation). - + 3. Install Yarn, the front-end package manager. Depending on your system, the installation process may differ, please read the [official Yarn documentation](https://yarnpkg.com/en/docs/install#debian-stable). - + 4. Install docker. Your system may provide a pre-packaged version of docker in its repositories, but this version may be outdated. Please refer to [ubuntu](https://docs.docker.com/install/linux/docker-ce/ubuntu/), [debian](https://docs.docker.com/install/linux/docker-ce/debian/) or [MacOS](https://docs.docker.com/docker-for-mac/install/) documentation to setup a recent version of docker. @@ -94,7 +96,7 @@ This procedure is not easy to follow so if you don't need to write some code for You may have to change the network address if it is already in use. ```bash docker network create --subnet=172.18.0.0/16 fabmanager - ``` + ``` 7. Retrieve the project from Git @@ -154,7 +156,7 @@ This procedure is not easy to follow so if you don't need to write some code for 13. Build the databases. - **Warning**: **DO NOT** run `rake db:setup` instead of these commands, as this will not run some required raw SQL instructions. - - **Please note**: Your password length must be between 8 and 128 characters, otherwise db:seed will be rejected. This is configured in [config/initializers/devise.rb](config/initializers/devise.rb) + - **Please note**: Your password length must be between 8 and 128 characters, otherwise db:seed will be rejected. This is configured in [config/initializers/devise.rb](config/initializers/devise.rb) ```bash # for dev @@ -186,83 +188,6 @@ This procedure is not easy to follow so if you don't need to write some code for 18. Email notifications will be caught by MailCatcher. To see the emails sent by the platform, open your web browser at `http://localhost:1080` to access the MailCatcher interface. - -### Virtual Machine Instructions - -These instructions allow to deploy a testing or development instance of Fab Manager inside a virtual -machine, with most of the software dependencies installed automatically and avoiding to install a lot -of software and services directly on the host computer. - -**Note:** The provision scripts configure the sofware dependencies to play nice with each other while -they are inside the same virtual environment but said configuration is not optimized for a production -environment. - -1. Install [Vagrant][vagrant] and [Virtual Box][virtualbox] (with the extension package). - -2. Retrieve the project from Git - - ```bash - git clone https://github.com/sleede/fab-manager - ``` - -3. From the project directory, run: - - ```bash - vagrant up - ``` - -4. Once the virtual machine finished building, reload it with: - - ```bash - vagrant reload - ``` - -5. Log into the virtual machine with: - - ```bash - vagrant ssh - ``` - -6. While logged in, navigate to the project folder and install the Gemfile - dependencies: - - ```bash - cd /vagrant - bundle install - ``` - -7. Set a directory for Sidekick pids: - - ```bash - mkdir -p tmp/pids - ``` - -8. Copy the default configuration files: - - ```bash - cp config/database.yml.virtual config/database.yml - cp config/application.yml.default config/application.yml - ``` - -10. Set up the databases. (Note that you should provide the desired admin credentials and that these - specific set of commands must be used to set up the database as some raw SQL instructions are - included in the migrations. Password minimal length is 8 characters): - - ```bash - rake db:create - rake db:migrate - ADMIN_EMAIL='youradminemail' ADMIN_PASSWORD='youradminpassword' rake db:seed - rake fablab:es:build_stats - # for tests - RAILS_ENV=test rake db:create - RAILS_ENV=test rake db:migrate - ``` - -11. Start the application and visit `localhost:3000` on your browser to check that it works: - - ```bash - foreman s -p 3000 - ``` ## PostgreSQL @@ -310,7 +235,7 @@ In FabManager, it is used for the admin's statistics module and to perform searc mkdir -p .docker/elasticsearch/plugins mkdir -p .docker/elasticsearch/backups ``` - + 2. Copy the default configuration files ```bash cp docker/elasticsearch.yml .docker/elasticsearch/config @@ -396,8 +321,8 @@ In each cases, some inline comments are included in the localisation files. They can be recognized as they start with the sharp character (#). These comments are not required to be translated, they are intended to help the translator to have some context information about the sentence to translate. -You will also need to translate the invoice watermark, located in `app/pdfs/data/`. -You'll find there the [GIMP source of the image](app/pdfs/data/watermark.xcf), which is using [Rubik Mono One](https://fonts.google.com/specimen/Rubik+Mono+One) as font. +You will also need to translate the invoice watermark, located in `app/pdfs/data/`. +You'll find there the [GIMP source of the image](app/pdfs/data/watermark.xcf), which is using [Rubik Mono One](https://fonts.google.com/specimen/Rubik+Mono+One) as font. Use it to generate a similar localised PNG image which keep the default image size, as PDF are not responsive. @@ -516,8 +441,3 @@ Developers may find information on how to implement their own authentication pro - [AngularJS](https://docs.angularjs.org/api) - [Angular-Bootstrap](http://angular-ui.github.io/bootstrap/) - [ElasticSearch 5.6](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index.html) - - ---- -[vagrant]: https://www.vagrantup.com/downloads.html -[virtualbox]: https://www.virtualbox.org/wiki/Downloads diff --git a/Vagrantfile b/Vagrantfile index fc3ca62c7..c3cdeca7f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,10 +5,11 @@ VAGRANTFILE_API_VERSION = '2' Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - config.vm.box = 'ubuntu/xenial64' + config.vm.box = 'ubuntu/bionic64' config.vm.define 'fabmanager-devbox' - # Port forwarding + # Forward ports so services running in the virtual machine can be accessed by + # the host [ 3000, # rails/puma 9200, # elasticsearch @@ -19,23 +20,31 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.network "forwarded_port", guest: port, host: port end - # Provider-specific configuration + # Configuration to allocate resources fro the virtual machine config.vm.provider 'virtualbox' do |vb| vb.customize ['modifyvm', :id, '--memory', '2048'] end - # If you are using Windows o Linux with an encrypted volume + # If you are using Windows o Linux with an encrypted volume stick with the + # configuration below for file syncronization config.vm.synced_folder '.', '/vagrant', type: 'virtualbox' - # Provisioning - config.vm.provision "shell", privileged: true, run: "once" do |s| - s.inline = "export LC_ALL=en_US.UTF-8\n" \ - "export LANG=en_US.UTF-8\n" \ - "export LANGUAGE=en_US.UTF-8" - end + # Copy default configuration files for the database conenction and the Rails application + config.vm.provision "file", source: "./config/database.yml.default", destination: "/vagrant/config/database.yml" + config.vm.provision "file", source: "./config/application.yml.default", destination: "/vagrant/config/application.yml" + ## Provision software dependencies config.vm.provision "shell", privileged: false, run: "once", path: "provision/zsh_setup.sh" + config.vm.provision "shell", privileged: false, run: "once", - path: "provision/box_setup.zsh" + path: "provision/box_setup.zsh", + env: { + "LC_ALL" => "en_US.UTF-8", + "LANG" => "en_US.UTF-8", + "LANGUAGE" => "en_US.UTF-8", + } + + config.vm.provision "shell", privileged: true, run: "once", + path: "provision/box_tuning.zsh" end diff --git a/config/database.yml.virtual b/config/database.yml.virtual deleted file mode 100644 index ced14dc17..000000000 --- a/config/database.yml.virtual +++ /dev/null @@ -1,28 +0,0 @@ -development: &development - adapter: postgresql - host: localhost - encoding: unicode - database: fabmanager_development - pool: 25 - username: ubuntu - password: ubuntu - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - <<: *development - database: fabmanager_test - -production: &production - adapter: postgresql - host: ENV['DATABASE_HOST'] - encoding: unicode - database: fabmanager_production - pool: 25 - username: ENV['DATABASE_USER'] - password: ENV['DATABASE_PASS'] - -staging: - <<: *production - database: fabmanager_staging diff --git a/doc/virtual-machine.md b/doc/virtual-machine.md new file mode 100644 index 000000000..4173ab790 --- /dev/null +++ b/doc/virtual-machine.md @@ -0,0 +1,71 @@ +# Virtual Machine Instructions + +These instructions allow to deploy a testing or development instance of Fab Manager inside a virtual +machine, with most of the software dependencies installed automatically and avoiding to install a lot +of software and services directly on the host computer. + +**Note:** The provision scripts configure the sofware dependencies to play nice with each other while +they are inside the same virtual environment but said configuration is not optimized for a production +environment. + +**Note 2:** The perfomance of the application under the virtual machine depends on the resources that +the host can provide but will usually be much more slower than a production environment. + +1. Install [Vagrant][vagrant] and [Virtual Box][virtualbox] (with the extension package). + +2. Retrieve the project from Git + + ```bash + git clone https://github.com/sleede/fab-manager + ``` + +3. From the project directory, run: + + ```bash + vagrant up + ``` + +4. Once the virtual machine finished building, reload it with: + + ```bash + vagrant reload + ``` + +5. Log into the virtual machine with: + + ```bash + vagrant ssh + ``` + +6. While logged in, navigate to the project folder and install the Gemfile + dependencies: + + ```bash + bundle install + yarn install + ``` + +7. Set up the databases. (Note that you should provide the desired admin credentials and that these + specific set of commands must be used to set up the database as some raw SQL instructions are + included in the migrations. Password minimal length is 8 characters): + + ```bash + rake db:create + rake db:migrate + # Be sure not to use the default values below in production + ADMIN_EMAIL='admin@email' ADMIN_PASSWORD='adminpass' rake db:seed + rake fablab:es:build_stats + # for tests + RAILS_ENV=test rake db:create + RAILS_ENV=test rake db:migrate + ``` + +8. Start the application and visit `localhost:3000` on your browser to check that it works: + + ```bash + foreman s -p 3000 + ``` + +--- +[vagrant]: https://www.vagrantup.com/downloads.html +[virtualbox]: https://www.virtualbox.org/wiki/Downloads \ No newline at end of file diff --git a/provision/box_setup.zsh b/provision/box_setup.zsh index b0a05d5da..b5829f9dc 100755 --- a/provision/box_setup.zsh +++ b/provision/box_setup.zsh @@ -1,127 +1,112 @@ #!/usr/bin/env zsh -# Set environmen values ####################################################### +### +# Set user configuration +set_user_config() { + echo "Setting ´vagrant´ user profile configuration" # Virtual environment flag - echo '# Set virtual environment flag' >> ~/.profile - echo 'export VIRTUAL_DEV_ENV=true' >> ~/.profile - echo "\n" >> ~/.profile + echo -e '\n\n# Set virtual environment flag' >> ~/.profile + echo -e 'export VIRTUAL_DEV_ENV=true\n' >> ~/.profile # Language configuration - echo '# Set locale configuration' >> ~/.profile + echo -e '\n# Set locale configuration' >> ~/.profile echo 'export LC_ALL=en_US.UTF-8' >> ~/.profile echo 'export LANG=en_US.UTF-8' >> ~/.profile - echo 'export LANGUAGE=en_US.UTF-8' >> ~/.profile - echo "\n" >> ~/.profile + echo -e 'export LANGUAGE=en_US.UTF-8\n' >> ~/.profile -# Install and setup PostgreSQL ################################################ + # Switch to project path after login + echo -e '\n# Navigate to /vagrant after login' >> ~/.profile + echo -e 'cd /vagrant\n' >> ~/.profile +} -echo "***************************************************" -echo "Checking Postgres installation..." -echo "***************************************************" -if ! dpkg -s postgresql; then +### +# Install and configure PostgreSQL database manager +install_postgres() { echo "Installing PostgreSQL" - sudo apt update - sudo apt install -y postgresql postgresql-contrib + sudo apt-get update + sudo apt-get install -y postgresql postgresql-contrib - echo "Setting up user" + # Set up ubuntu user for Postgres 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;\"" - echo "Setting up extensions to all schemas" + # Make available useful extensions to the schemas 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;\"" -fi -echo "***************************************************" -echo " Starting Postgres server " -echo "***************************************************" -sudo service postgresql start + # Start service + sudo service postgresql start + # Replace default database user in the app database configuration + sed -i 's@username: postgres@username: ubuntu@g' /vagrant/config/database.yml + sed -i 's@password: postgres@password: ubuntu@g' /vagrant/config/database.yml +} -# Install Redis ############################################################### +### +# Install Redis data store +install_redis() { + echo "Installing Redis" + sudo apt-get install -y redis-server +} -echo "***************************************************" -echo "Checking Redis installation..." -echo "***************************************************" -if ! dpkg -s redis-server; then - echo "Instalating Redis" - sudo apt install -y redis-server -fi +### +# Install Imagemagick image manipulation utilities +install_imagemagick() { + echo "Installing Imagemagick" + sudo apt-get install -y imagemagick +} - -# Install Imagemagick ######################################################### - -echo "***************************************************" -echo "Checking Imagemagik installation..." -echo "***************************************************" -if ! dpkg -s imagemagick; then - sudo apt install -y imagemagick -else - echo 'OK' -fi - - -# Install Elastic Search ###################################################### - -echo "***************************************************" -echo "Checking ElasticSearch installation..." -echo "***************************************************" -if ! dpkg -s elasticsearch; then - sudo apt install -y openjdk-8-jre apt-transport-https +### +# Install ElasticSearch search engine +install_elasticsearch() { + echo "Installing Oracle Java 8 and ElasticSearch" + sudo apt-get install -y openjdk-8-jre apt-transport-https wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - - echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list - sudo apt update && sudo apt install -y elasticsearch + echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list + sudo apt-get update && sudo apt-get install -y elasticsearch # This configuration limits ElasticSearch memory use inside the virtual machine - sudo echo "node.master: true" >> /etc/elasticsearch/elasticsearch.yml - sudo echo "node.data: false" >> /etc/elasticsearch/elasticsearch.yml + sudo bash -c "echo 'node.master: true' >> /etc/elasticsearch/elasticsearch.yml" 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 -else - echo 'OK' -fi + # Create pids directory for Sidekick + sudo mkdir -p /vagrant/tmp/pids +} -# Install Ngrok exposer ###################################################### - -echo "***************************************************" -echo "Checking for Ngrok... " -echo "***************************************************" -if ! ngrok; then - sudo apt install -y unzip +### +# Install Ngrok secure tunnel manager +install_ngrok() { + echo 'Installing Ngrok' + sudo apt-get install -y unzip 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 -else - echo "OK" -fi +} +### +# Install Node Version Manager +install_nvm() { + echo "Installing NVM" + wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash -# Install Node Version Manager ################################################ - -echo "***************************************************" -echo "Checking for NVM... " -echo "***************************************************" -if [[ ! -x "$HOME/.nvm" ]]; then - wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash - - echo '# Node Version Manager' >> ~/.profile + echo -e "\n# Node Version Manager" >> ~/.profile 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 - echo "\n" >> ~/.profile + echo -e "\n" >> ~/.profile 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 - echo "\n" >> ~/.profile + echo -e "\n" >> ~/.profile echo ' if [ -n "$nvmrc_path" ]; then' >> ~/.profile echo ' local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")' >> ~/.profile - echo "\n" >> ~/.profile + echo -e "\n" >> ~/.profile echo ' if [ "$nvmrc_node_version" = "N/A" ]; then' >> ~/.profile echo ' nvm install' >> ~/.profile echo ' elif [ "$nvmrc_node_version" != "$node_version" ]; then' >> ~/.profile @@ -133,55 +118,73 @@ if [[ ! -x "$HOME/.nvm" ]]; then echo ' fi' >> ~/.profile echo '}' >> ~/.profile echo 'add-zsh-hook chpwd load-nvmrc' >> ~/.profile - echo 'load-nvmrc' >> ~/.profile + echo -e "load-nvmrc\n" >> ~/.profile export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" -else - echo "OK" -fi +} - -# Install Node.js ############################################################# - -echo "***************************************************" -echo "Checking for Node.js... " -echo "***************************************************" -if ! node --version; then +### +# Install stable version of Node.js +install_nodejs() { + echo 'Installing Node.js' nvm install stable nvm alias default stable nvm use default -else - echo 'OK' -fi +} +### +# 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 +} -# Ruby and Version Manager #################################################### - -echo "***************************************************" -echo 'Cheking for Ruby... ' -echo "***************************************************" -if ! ruby -v; then +### +# Install Ruby Version Manager +install_rvm() { + echo 'Installing RVM' gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB - sudo apt install -y libxml2 libxml2-dev libxslt1-dev libpq-dev \curl -sSL https://get.rvm.io | bash - source /home/vagrant/.rvm/scripts/rvm - rvm get head - 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 -else - echo 'OK' -fi + source $HOME/.rvm/scripts/rvm + rvm get stable +} +### +# Install Matz Ruby Interpreter +install_ruby() { + echo 'Installing Ruby' + sudo apt-get install -y libxml2-dev libxslt1-dev libpq-dev libidn11-dev + rvm install ruby-2.3.8 + rvm use ruby-2.3.8@global + gem update --system --no-doc + gem update --no-doc + rvm use ruby-2.3.8 --default + rvm cleanup all +} -# Cleaning up ################################################################# +### +# Remove unused software +clean_up() { + echo "Removing unused software" + sudo apt-get -y autoremove && sudo apt-get autoclean +} -echo "***************************************************" -echo 'Removing unused software... ' -echo "***************************************************" -rvm cleanup all -sudo apt autoremove +setup() { + set_user_config + install_postgres + install_redis + install_imagemagick + install_elasticsearch + install_ngrok + install_nvm + install_nodejs + install_yarn + install_rvm + install_ruby + clean_up +} + +setup "$@" diff --git a/provision/box_tuning.zsh b/provision/box_tuning.zsh new file mode 100644 index 000000000..ae2d9d7c1 --- /dev/null +++ b/provision/box_tuning.zsh @@ -0,0 +1,33 @@ +#!/usr/bin/env zsh + +### +# Tune-up the system settings +system_tuning() +{ + echo "Tunning up the system" + + # Enable overcomit memmory for Redis + 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 + + # Enagle huge pages for Redis + 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 + + # Increase virtual memory areas for ElasticSearch + 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 +} + +setup() { + system_tuning +} + +setup "$@" \ No newline at end of file diff --git a/provision/zsh_setup.sh b/provision/zsh_setup.sh index d414387eb..c05be6b1c 100755 --- a/provision/zsh_setup.sh +++ b/provision/zsh_setup.sh @@ -1,36 +1,48 @@ #!/usr/bin/env bash -echo "***************************************************" -echo 'Updating system packages... ' -echo "***************************************************" -sudo apt update && sudo apt upgrade -y +### +# Update system packages +update_system() { + echo 'Updating system' + sudo apt-get update && sudo apt-get upgrade -y + sudo apt-get install -y git curl +} +### +# Install ZSH shell +install_zsh() { + echo 'Installing ZSH' + # Install and set zsh as shell + sudo apt-get install -y zsh -echo "***************************************************" -echo 'Checking Zsh installation... ' -echo "***************************************************" -if ! dpkg -s zsh; then - # Install and set Zsh as shell - sudo apt install -y zsh + # Change shell to Zsh for the vagrant user + sudo chsh -s /bin/zsh vagrant +} - # Install Oh-My-Zsh! +### +# Install Oh My ZSH! plugin framework +install_ohmyzsh() { + echo "Installing Oh-My-ZSH!" git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc # Change the Oh-My-Zsh! default configuration. - sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="blinks"/g' ~/.zshrc - sed -i 's/# CASE_SENSITIVE="true"/CASE_SENSITIVE="true"/g' ~/.zshrc - sed -i 's/# COMPLETION_WAITING_DOTS="true"/COMPLETION_WAITING_DOTS="true"/g' ~/.zshrc - sed -i 's/# DISABLE_UNTRACKED_FILES_DIRTY="true"/DISABLE_UNTRACKED_FILES_DIRTY="true"/g' ~/.zshrc - sed -i 's/# HIST_STAMPS="mm/dd/yyyy"/HIST_STAMPS="yyyy-mm-dd"/g' ~/.zshrc - sed -i 's/plugins=(git)/plugins=(git dirhistory common-aliases command-not-found ruby)/g' ~/.zshrc + sed -i 's@ZSH_THEME="robbyrussell"@ZSH_THEME="blinks"@g' ~/.zshrc + sed -i 's@# CASE_SENSITIVE="true"@CASE_SENSITIVE="true"@g' ~/.zshrc + sed -i 's@# COMPLETION_WAITING_DOTS="true"@COMPLETION_WAITING_DOTS="true"@g' ~/.zshrc + sed -i 's@# DISABLE_UNTRACKED_FILES_DIRTY="true"@DISABLE_UNTRACKED_FILES_DIRTY="true"@g' ~/.zshrc + sed -i 's@# HIST_STAMPS="mm/dd/yyyy"@HIST_STAMPS="yyyy-mm-dd"@g' ~/.zshrc + sed -i 's@plugins=(git)@plugins=(git dirhistory common-aliases command-not-found ruby)@g' ~/.zshrc # Include .profile settings - echo ' ' >> ~/.zshrc - echo '# Include .profile settings' >> ~/.zshrc - echo 'source ~/.profile' >> ~/.zshrc - echo ' ' >> ~/.zshrc + echo -e "\n# Include .profile settings" >> ~/.zshrc + echo -e "source ~/.profile\n" >> ~/.zshrc +} - # Change shell to Zsh for the vagrant user - sudo chsh -s /bin/zsh vagrant -fi +setup() { + update_system + install_zsh + install_ohmyzsh +} + +setup "$@"