Skip to content

Commit

Permalink
vagrant: split lamp provisioning from other linux utils
Browse files Browse the repository at this point in the history
  • Loading branch information
w0ng committed Jun 27, 2015
1 parent 6552233 commit 00347c4
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 99 deletions.
25 changes: 18 additions & 7 deletions vagrant/debian-8.1.0/Vagrantfile
@@ -1,22 +1,27 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Config variables
# =============================================================================

# Set configuration variables here
project_name = File.basename(Dir.pwd)
server_ip = "192.168.22.10"
server_name = "dev.local.192.168.22.10.xip.io"
server_alias = "dev.local.*.xip.io"
doc_root = "/vagrant"
provision_extras = true

# =============================================================================

Vagrant.configure(2) do |config|

config.vm.box = "debian-8.1"
config.vm.box = "w0ng/debian-8.1.0-amd64"

config.vm.network "private_network", ip: server_ip
config.vm.network "forwarded_port", guest: 80, host: 8000

# Mount with NFS for speed.
config.vm.synced_folder '.', '/vagrant', :nfs => true, :mount_options => ['actimeo=2']
config.vm.synced_folder '.', doc_root, :nfs => true, :mount_options => ['actimeo=2']

# Name the vagrant VM the same as the base directory name.
config.vm.define project_name do |appname|
Expand All @@ -29,15 +34,15 @@ Vagrant.configure(2) do |config|
# Based on: https://stefanwrobel.com/how-to-make-vagrant-performance-not-suck
# Give VM 1/4 system memory & access to all cpu cores on the host
host = RbConfig::CONFIG['host_os']
# OSX
# OSX.
if host =~ /darwin/
cpus = `sysctl -n hw.ncpu`.to_i
mem = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4
# Linux
# Linux.
elsif host =~ /linux/
cpus = `nproc`.to_i
mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 / 4
# Windows
# Windows.
else
cpus = 2
mem = 1024
Expand All @@ -46,6 +51,12 @@ Vagrant.configure(2) do |config|
vb.customize ["modifyvm", :id, "--cpus", cpus]
end

config.vm.provision :shell, path: "install.sh",
# Provision for a core LAMP stack.
config.vm.provision :shell, path: "bootstrap-lamp.sh",
args: [server_name, server_alias, doc_root]

# Provision for some useful Linux tools (Optional).
if provision_extras
config.vm.provision :shell, path: "bootstrap-extras.sh", args: [server_name]
end
end
168 changes: 168 additions & 0 deletions vagrant/debian-8.1.0/bootstrap-extras.sh
@@ -0,0 +1,168 @@
#!/usr/bin/env bash

# =============================================================================

echo "--- Configuring inputrc ---"

cat <<'EOF' > /home/vagrant/.inputrc
$include /etc/inputrc
set editing-mode vi
set completion-ignore-case On
$if mode=vi
set keymap vi-command
#
set keymap vi-insert
"\C-a": beginning-of-line
"\C-e": end-of-line
"\C-l": clear-screen
"\C-n": history-search-forward
"\C-p": history-search-backward
"jj": vi-movement-mode
$endif
EOF

chown vagrant:vagrant /home/vagrant/.inputrc
echo "inputrc configured."

# =============================================================================

echo "--- Installing tmux ---"

apt-get install -y tmux

cat <<'EOF' > /home/vagrant/.tmux.conf
#
# ~/.tmux.conf
#
# split windows like vim
# vim's definition of a horizontal/vertical split is reversed from tmux's
bind s split-window -v
bind v split-window -h
# move around panes with hjkl, as one would in vim after pressing ctrl-w
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# resize panes like vim
# feel free to change the "1" to however many lines you want to resize by, only
# one at a time can be slow
bind < resize-pane -L 1
bind > resize-pane -R 1
bind - resize-pane -D 1
bind + resize-pane -U 1
# bind : to command-prompt like vim
# this is the default in tmux already
bind : command-prompt
# vi-style controls for copy mode
set-window-option -g mode-keys vi
# change prefix key
unbind C-b
set-option -g prefix C-a
# status bar
set-option -g status-bg black
set-option -g status-fg white
set-option -g status-left ""
set-option -g status-right "#[bg=colour8]#[fg=brightwhite] #(cut -d ' ' -f 1-3 /proc/loadavg) #[bg=brightwhite]#[fg=black] #(whoami)@#H "
set-option -g status-right-length 60
set-window-option -g window-status-bell-fg black
set-window-option -g window-status-bell-bg brightred
set-window-option -g window-status-current-fg brightyellow
# dynamic window title
set-option -g set-titles on
# set first window to 1 instead of 0
set-option -g base-index 1
# correct term for 256 colours
set-option -g default-terminal "screen-256color"
EOF

chown vagrant:vagrant /home/vagrant/.tmux.conf
echo 'alias tm="tmux attach-session -d -t 0"' >> /home/vagrant/.bashrc
echo "tmux installed"

# =============================================================================

echo "--- Installing vim ---"

apt-get install -y vim

cat <<'EOF' > /home/vagrant/.vimrc
"
" ~/.vimrc
"
" Compatability
set nocompatible " use vim defaults instead of vi
set encoding=utf-8 " always encode in utf
filetype plugin indent on
syntax on
" General
set backspace=2 " enable <BS> for everything
"set colorcolumn=80 " visual indicator of column
set completeopt-=preview " dont show preview window
"set cursorline " visual indicator of current line
set hidden " hide when switching buffers, don't unload
set laststatus=2 " always show status line
set lazyredraw " don't update screen when executing macros
"set mouse=a " enable mouse in all modes
set showmode " show mode in status line
set nowrap " disable word wrap
set number " show line numbers
set showcmd " show command on last line of screen
set showmatch " show bracket matches
set spelllang=en_au " spell check with Australian English
set textwidth=0 " don't break lines after some maximum width
set ttyfast " increase chars sent to screen for redrawing
"set ttyscroll=3 " limit lines to scroll to speed up display
set title " use filename in window title
set wildmenu " enhanced cmd line completion
" Folding
set foldignore= " don't ignore anything when folding
set foldlevelstart=99 " no folds closed on open
set foldmethod=indent " collapse code using indent levels
set foldnestmax=20 " limit max folds for indent and syntax methods
" Tabs
set autoindent " copy indent from previous line
set expandtab " replace tabs with spaces
set shiftwidth=4 " spaces for autoindenting
set smarttab " <BS> removes shiftwidth worth of spaces
set softtabstop=4 " spaces for editing, e.g. <Tab> or <BS>
set tabstop=4 " spaces for <Tab>
" Searches
set hlsearch " highlight search results
set incsearch " search whilst typing
set ignorecase " case insensitive searching
set smartcase " override ignorecase if upper case typed
" Colours
set t_Co=256
set background=dark
" Copy to OSX CLIPBOARD
"vnoremap ,y "*y
" Vimdiff display
if &diff
set diffopt=filler,foldcolumn:0
endif
EOF

chown vagrant:vagrant /home/vagrant/.vimrc
echo "Vim installed."

# =============================================================================

echo "--- Finalising installation ---"
updatedb && echo "mlocate DB updated."

# =============================================================================

echo "--- FINISHED ---"
SERVER_NAME="$1"
echo "View the dev site via http://${SERVER_NAME}"
Expand Up @@ -112,7 +112,7 @@ sed -i "s/^;\?date.timezone =.*/date.timezone = \"Australia\/Sydney\"/" \
# Xdebug: enable extension, do not limit output, enable triggered profiler
[[ ! -d "/vagrant/tmp" ]] && mkdir -p "/vagrant/tmp"
cat > "$(find /etc/php5 -name xdebug.ini)" << EOF
cat > "$(find /etc/php5 -name xdebug.ini)" <<EOF
zend_extension=$(find /usr/lib/php5 -name xdebug.so)
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
Expand Down Expand Up @@ -240,105 +240,19 @@ echo "--- Installing Composer ---"
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
echo "Composer installed."
# =============================================================================
echo "--- Installing vim ---"
apt-get install -y vim
cat <<EOF > /home/vagrant/.vimrc
"
" ~/.vimrc
"
" Compatability
set nocompatible " use vim defaults instead of vi
set encoding=utf-8 " always encode in utf
filetype plugin indent on
syntax on
" General
set backspace=2 " enable <BS> for everything
"set colorcolumn=80 " visual indicator of column
set completeopt-=preview " dont show preview window
"set cursorline " visual indicator of current line
set hidden " hide when switching buffers, don't unload
set laststatus=2 " always show status line
set lazyredraw " don't update screen when executing macros
"set mouse=a " enable mouse in all modes
set showmode " show mode in status line
set nowrap " disable word wrap
set number " show line numbers
set showcmd " show command on last line of screen
set showmatch " show bracket matches
set spelllang=en_au " spell check with Australian English
set textwidth=0 " don't break lines after some maximum width
set ttyfast " increase chars sent to screen for redrawing
"set ttyscroll=3 " limit lines to scroll to speed up display
set title " use filename in window title
set wildmenu " enhanced cmd line completion
" Folding
set foldignore= " don't ignore anything when folding
set foldlevelstart=99 " no folds closed on open
set foldmethod=indent " collapse code using indent levels
set foldnestmax=20 " limit max folds for indent and syntax methods
" Tabs
set autoindent " copy indent from previous line
set expandtab " replace tabs with spaces
set shiftwidth=4 " spaces for autoindenting
set smarttab " <BS> removes shiftwidth worth of spaces
set softtabstop=4 " spaces for editing, e.g. <Tab> or <BS>
set tabstop=4 " spaces for <Tab>
" Searches
set hlsearch " highlight search results
set incsearch " search whilst typing
set ignorecase " case insensitive searching
set smartcase " override ignorecase if upper case typed
" Colours
set t_Co=256
set background=dark
" Copy to OSX CLIPBOARD
"vnoremap ,y "*y
" Vimdiff display
if &diff
set diffopt=filler,foldcolumn:0
endif
EOF
chown vagrant /home/vagrant/.vimrc
echo "Vim installed."
echo "Composer installed."
# =============================================================================
echo "--- Set vi editing mode for Readline ---"
cat <<EOF > /home/vagrant/.inputrc
\$include /etc/inputrc
set editing-mode vi
set completion-ignore-case On
\$if mode=vi
set keymap vi-command
#
set keymap vi-insert
"\C-a": beginning-of-line
"\C-e": end-of-line
"\C-l": clear-screen
"\C-n": history-search-forward
"\C-p": history-search-backward
"jj": vi-movement-mode
\$endif
EOF
chown vagrant /home/vagrant/.inputrc
echo "Vi Readline set."
echo "--- Finalising installation ---"
# =============================================================================
updatedb
echo "--- Finalising installation ---"
updatedb && echo "mlocate DB updated."
echo "mlocate DB updated."
# =============================================================================
echo "--- FINISHED ---"
echo "View the dev site via http://${SERVER_NAME}"

0 comments on commit 00347c4

Please sign in to comment.