Last active
May 5, 2016 13:25
-
-
Save justinmoh/8cc6eed3ea18a5dc0ba6f58f2175a404 to your computer and use it in GitHub Desktop.
Homestead setup for extra development toolsets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # If you would like to do some extra provisioning you may | |
| # add any commands you wish to this file and they will | |
| # be run after the Homestead machine is provisioned. | |
| wanted_packages="php7.0-intl"; | |
| ################################################################################ | |
| # General | |
| ################################################################################ | |
| # sudo ln -sf /usr/share/zoneinfo/Asia/Kuala_Lumpur /etc/localtime | |
| sudo timedatectl set-timezone Asia/Kuala_Lumpur | |
| # sudo apt-get update; | |
| ################################################################################ | |
| # Function declaration | |
| ################################################################################ | |
| function modify_npm_global_dir() { | |
| # @url https://docs.npmjs.com/getting-started/fixing-npm-permissions | |
| printf "Checking NPM global directory...\n" | |
| if [[ ${USER} == "root" ]]; then | |
| echo "The after.sh provisioner should be running as vagrant." | |
| echo "Try adding privileged: false after the provisioner script." | |
| exit 0; | |
| fi | |
| local npm_global_dir_name='.npm-global'; | |
| local npm_global_path="${HOME}/${npm_global_dir_name}"; | |
| if [[ ! -d "${npm_global_path}" ]]; then | |
| mkdir -p ${npm_global_path} && \ | |
| printf " * Created directory %s\n" "${npm_global_path}" | |
| else | |
| printf " * ${npm_global_path} exists.\n"; | |
| fi | |
| local result=$( npm config get prefix | grep '.npm-global$' ); | |
| if [[ "${result}" = "" ]]; then | |
| npm config set prefix ${npm_global_path} && \ | |
| printf " * NPM global directory set to %s\n" "${npm_global_path}"; | |
| else | |
| local npm_prefix="$( npm config get prefix )"; | |
| printf " * NPM global directory path is %s\n" "${npm_prefix}"; | |
| fi | |
| local profile_path="${HOME}/.profile"; | |
| local result=$( grep '^export PATH=$HOME/.npm-global/bin:$PATH$' ${profile_path} ); | |
| if [[ "${result}" = "" ]]; then | |
| echo -e '\nexport PATH=$HOME/.npm-global/bin:$PATH' >> ${profile_path} && \ | |
| printf " * NPM global bin path included in PATH variable.\n" | |
| else | |
| printf " * NPM global directory & bin path checked and looks fine.\n" | |
| fi | |
| } | |
| function apt_is_installed() { | |
| dpkg -s "${1}" >/dev/null 2>&1 || echo 'nope'; | |
| } | |
| function apt_install_this() { | |
| # We could accept multiple inputs, seperated by space. | |
| while [[ "${1}" != "" ]]; do | |
| local package="${1}"; | |
| local result=$(apt_is_installed ${package}); | |
| printf "Checking %s...\n" "${package}"; | |
| if [[ ${result} = 'nope' ]]; then | |
| printf "\n"; | |
| sudo apt-get install --yes "${package}"; | |
| else | |
| printf " * %s is installed\n" "${package}"; | |
| fi | |
| shift | |
| done | |
| } | |
| function check_rvm() { | |
| local result=$(type rvm >/dev/null 2>&1 || echo 'nope'); | |
| printf "Checking %s...\n" "RVM"; | |
| if [[ ${result} = 'nope' ]]; then | |
| printf "\n"; | |
| install_rvm; | |
| else | |
| printf " * RVM is installed\n"; | |
| fi | |
| } | |
| function install_rvm() { | |
| # @url https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma | |
| # @url https://rvm.io/rvm/install | |
| gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3; | |
| curl -sSL https://get.rvm.io | bash -s stable --ruby; | |
| source /home/vagrant/.rvm/scripts/rvm; | |
| rvm requirements; | |
| } | |
| function config_xdebug() { | |
| printf "Checking xdebug configuration...\n" | |
| local xdebug_ini_path='/etc/php/7.0/mods-available/xdebug.ini'; | |
| local line_count=$(grep -c '' ${xdebug_ini_path}); | |
| if [[ ${line_count} -lt 3 ]]; then | |
| local content='zend_extension=xdebug.so\n | |
| \nxdebug.remote_enable=1\nxdebug.remote_connect_back=1\nxdebug.remote_port=9000\nxdebug.scream=0\nxdebug.cli_color=1\nxdebug.show_local_vars=1\nxdebug.ide_key=vagrant\nxdebug.remote_host=192.168.10.10' | |
| echo -e ${content} | sudo tee ${xdebug_ini_path} | |
| sudo service php7.0-fpm restart | |
| fi | |
| printf " * xdebug.ini is configured.\n" | |
| } | |
| ################################################################################ | |
| # Main | |
| ################################################################################ | |
| # for wanted_package in ${wanted_packages}; do | |
| # echo ${wanted_package} | |
| # | |
| # install_this(${wanted_package}); | |
| # done | |
| apt_install_this $wanted_packages && \ | |
| config_xdebug && \ | |
| check_rvm && \ | |
| modify_npm_global_dir && \ | |
| echo "Wanted packages are checked and installed."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment