Last active
August 29, 2015 14:00
-
-
Save Garbee/11401946 to your computer and use it in GitHub Desktop.
Install script in progress for vagrant
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
#!/bin/bash | |
function upgrade_os { | |
echo 'Upgrading the OS' | |
sudo apt-get update > /dev/null | |
sudo apt-get upgrade -y > /dev/null | |
} | |
function essentials { | |
echo 'Installing essentials' | |
sudo apt-get install -y git curl vim software-properties-common zsh supervisor git-flow > /dev/null | |
sudo mkdir -p /srv/web/etc/{run,log}/ | |
sudo chown -R vagrant:vagrant /srv/web | |
sudo chmod -R 775 /srv/web | |
git config --global user.name 'Jonathan Garbee' | |
git config --global user.email '[email protected]' | |
git config --global push.default matching | |
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh | |
sudo chsh -s /bin/zsh vagrant | |
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="miloshadzic"/g' ~/.zshrc | |
sed -i 's/plugins=(git)/plugins=(git laravel4 composer git-flow nvm)/g' ~/.zshrc | |
} | |
function install_nginx { | |
echo 'Installing build requirements for Nginx' | |
sudo apt-get install -y libpcre3-dev zlib1g-dev libssl-dev openssl libcurl4-openssl-dev > /dev/null | |
mkdir -p ~/tmp | |
cd ~/tmp | |
echo 'Grabbing nginx pagespeed module' | |
wget -quiet https://github.com/pagespeed/ngx_pagespeed/archive/release-1.7.30.4-beta.tar.gz | |
tar -xf release-1.7.30.4-beta.tar.gz | |
cd ngx_pagespeed-release-1.7.30.4-beta/ | |
echo 'Grabbing PSOL library for pagespeed mod' | |
wget -quiet https://dl.google.com/dl/page-speed/psol/1.7.30.4.tar.gz | |
tar -xzf 1.7.30.4.tar.gz | |
cd ~/tmp | |
echo 'Grabbing nginx source code' | |
wget -quiet http://nginx.org/download/nginx-1.4.7.tar.gz -O nginx.tar.gz | |
tar -xf nginx.tar.gz | |
cd nginx-1.4.7/ | |
./configure \ | |
--user=vagrant \ | |
--group=vagrant \ | |
--with-http_ssl_module \ | |
--error-log-path=/srv/web/etc/log/nginx-error.log \ | |
--http-log-path=/srv/web/etc/log/nginx-access.log \ | |
--sbin-path=/usr/local/sbin \ | |
--conf-path=/usr/local/etc/nginx/nginx.conf \ | |
--pid-path=/srv/web/etc/run/nginx.pid \ | |
--lock-path=/srv/web/etc/lock/nginx.lock \ | |
--add-module=$HOME/tmp/ngx_pagespeed-release-1.7.30.4-beta | |
echo 'Making and Installing nginx' | |
make -quiet | |
sudo make install | |
} | |
function configure_nginx { | |
echo 'Setting up nginx config' | |
cd /usr/local/etc | |
sudo mv nginx orig_nginx | |
sudo git clone https://github.com/h5bp/server-configs-nginx.git nginx | |
cd nginx | |
sudo cp ../orig_nginx/{fastcgi.conf,fastcgi_params,koi-utf,koi-win,scgi_params,uwsgi_params,win-utf} . | |
cd sites-available | |
sudo cp example.com uw.dev | |
sudo sed -i 's/example.com/uw.dev/g' uw.dev | |
sudo sed -i 's/root \/sites/root \/srv\/web/g' uw.dev | |
sudo sed -i 's/server_name www.uw.dev;/server_name uw.dev;/g' uw.dev | |
# Next sed replaces the second server_name in the file with the www version. | |
# http://www.linuxquestions.org/questions/programming-9/replace-2nd-occurrence-of-a-string-in-a-file-sed-or-awk-800171/ | |
sudo sed -i '0,/server_name uw.dev;/! s/server_name uw.dev;/server_name www.uw.dev;/g' uw.dev | |
insertconfig=' location \\\/ {\n try_files $uri $uri\/ \/index.php$is_args$args;\n }\n\n # pass the PHP scripts to FastCGI server listening on \/var\/run\/php5-fpm.sock\n location ~ \\.php$ {\n try_files $uri \/index.php =404;\n fastcgi_pass unix:\/srv\/web\/etc\/run\/php5-fpm.sock;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n include fastcgi_params;\n }' | |
insertindex=' # Set the index for requests to be send to. \n index index.php;' | |
sudo sed -i "0,/listen 80;/! s/listen 80;/listen 80;\n$insertindex/g" uw.dev | |
sudo sed -i "s/include h5bp\/basic.conf;/include h5bp\/basic.conf;\n$insertconfig/g" uw.dev | |
sudo sed -i 's/ return 301 $scheme:\/\/uw.dev$request_uri;/ return 301 $scheme:\/\/www.uw.dev$request_uri;/g' uw.dev | |
ln -s uw.dev ../sites-enabled/uw.dev | |
cd /usr/local/etc/nginx/ | |
sudo sed -i 's/user www www;/user vagrant vagrant;/g' nginx.conf | |
sudo sed -i 's/access_log logs\/access.log main;/access_log logs\/nginx-access.log main;/g' nginx.conf | |
sudo sed -i 's/error_log logs\/error.log warn;/error_log logs\/nginx-error.log warn;/g' nginx.conf | |
sudo sed -i 's/logs/\/srv\/web\/etc\/log/g' nginx.conf | |
sudo sed -i 's/\/var\/run/\/srv\/web\/etc\/run/g' nginx.conf | |
sudo sed -i 's/\/etc\/nginx\/mime.types;/mime.types;/g' nginx.conf | |
sudo sed -i 's/logs/\/srv\/web\/etc\/log/g' h5bp/location/expires.conf | |
} | |
function install_mariadb { | |
echo 'Setting up MariaDB repository' | |
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password root" | |
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password root" | |
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db > /dev/null | |
sudo add-apt-repository -y 'deb http://mirror.jmu.edu/pub/mariadb/repo/10.0/ubuntu trusty main' | |
sudo apt-get update > /dev/null | |
echo 'Installing MariaDB' | |
sudo apt-get install -y mariadb-server > /dev/null | |
} | |
function install_php { | |
echo 'Installing PHP5 and modules' | |
sudo apt-get install -y mcrypt php5 php5-cli php5-fpm php5-curl php5-json php5-mysqlnd php5-mcrypt php5-gd php5-imagick > /dev/null | |
sudo php5enmod mcrypt | |
cd /etc/php5/fpm | |
sudo sed -i 's/error_log = \/var\/log\/php5-fpm.log/error_log = \/srv\/web\/etc\/log\/php-fpm-error.log/g' /etc/php5/fpm/php-fpm.conf | |
sudo sed -i 's/listen = \/var\/run\/php5-fpm.sock/listen = \/srv\/web\/etc\/run/php5-fpm.sock/g' /etc/php5/fpm/pool.d/www.conf | |
sudo sed -i 's/www-data/vagrant/g' /etc/php5/fpm/pool.d/www.conf | |
sudo sed -i 's/cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini | |
sudo sed -i 's/pid = \/var\/run\/php5-fpm.pid/pid = \/srv\/web\/etc\/run\/php5-fpm.pid/g' /etc/php5/fpm/php-fpm.conf | |
sudo service php5-fpm restart | |
} | |
function install_composer { | |
mkdir -p ~/tmp | |
cd ~/tmp | |
curl -sS https://getcomposer.org/installer | php | |
sudo mv composer.phar /usr/local/bin/composer | |
} | |
function install_nvm { | |
echo 'Installing NVM' | |
curl -silent https://raw.github.com/creationix/nvm/master/install.sh | sh | |
source ~/.zshrc | |
echo 'Installing NodeJS 0.10 and setting as default' | |
nvm install 0.10 | |
nvm alias default 0.10 | |
echo 'Installing Bower' | |
nvm install -g bower | |
} | |
upgrade_os | |
essentials | |
install_nginx | |
configure_nginx | |
install_mariadb | |
install_php | |
install_composer | |
install_nvm | |
echo 'All Done!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment