Merge branch 'feature/vagrant'
authorPascal Hofmann <mail@pascalhofmann.de>
Sun, 3 Nov 2013 11:11:33 +0000 (12:11 +0100)
committerPascal Hofmann <mail@pascalhofmann.de>
Sun, 3 Nov 2013 11:11:33 +0000 (12:11 +0100)
13 files changed:
.gitignore [new file with mode: 0644]
Vagrantfile [new file with mode: 0644]
files/dot/.bash_aliases [new file with mode: 0644]
files/dot/.vimrc [new file with mode: 0644]
hiera.yaml [new file with mode: 0644]
puppet/Puppetfile [new file with mode: 0644]
puppet/hieradata/common.yaml [new file with mode: 0644]
puppet/manifests/default.pp [new file with mode: 0644]
shell/initial-setup.sh [new file with mode: 0644]
shell/librarian-puppet-vagrant.sh [new file with mode: 0644]
shell/os-detect.sh [new file with mode: 0644]
shell/self-promotion.txt [new file with mode: 0644]
shell/update-puppet.sh [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..fab038f
--- /dev/null
@@ -0,0 +1,3 @@
+config.php
+.idea
+.vagrant
diff --git a/Vagrantfile b/Vagrantfile
new file mode 100644 (file)
index 0000000..1b5164d
--- /dev/null
@@ -0,0 +1,43 @@
+Vagrant.configure("2") do |config|
+  config.vm.box = "ubuntu-precise12042-x64-vbox43"
+  config.vm.box_url = "https://puphpet.s3.amazonaws.com/ubuntu-precise12042-x64-vbox43.box"
+
+  config.vm.network "private_network", ip: "192.168.56.101"
+
+  config.vm.network "forwarded_port", guest: 80, host: 8080
+
+  config.vm.synced_folder "./", "/var/www/memberdb", id: "vagrant-root", :nfs => false
+
+  config.vm.usable_port_range = (2200..2250)
+  config.vm.provider :virtualbox do |virtualbox|
+    virtualbox.customize ["modifyvm", :id, "--name", "memberdb"]
+    virtualbox.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
+    virtualbox.customize ["modifyvm", :id, "--memory", "512"]
+    virtualbox.customize ["setextradata", :id, "--VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
+  end
+
+  config.vm.provision :shell, :path => "shell/initial-setup.sh"
+  config.vm.provision :shell, :path => "shell/update-puppet.sh"
+  config.vm.provision :shell, :path => "shell/librarian-puppet-vagrant.sh"
+  config.vm.provision :puppet do |puppet|
+    puppet.facter = {
+      "ssh_username" => "vagrant"
+    }
+
+    puppet.manifests_path = "puppet/manifests"
+    puppet.options = ["--verbose", "--hiera_config /vagrant/hiera.yaml", "--parser future"]
+  end
+
+
+
+
+  config.ssh.username = "vagrant"
+
+  config.ssh.shell = "bash -l"
+
+  config.ssh.keep_alive = true
+  config.ssh.forward_agent = false
+  config.ssh.forward_x11 = false
+  config.vagrant.host = :detect
+end
+
diff --git a/files/dot/.bash_aliases b/files/dot/.bash_aliases
new file mode 100644 (file)
index 0000000..b1ab498
--- /dev/null
@@ -0,0 +1,52 @@
+if [ -f /etc/bash_completion ]; then
+    source /etc/bash_completion
+fi
+
+__has_parent_dir () {
+    # Utility function so we can test for things like .git/.hg without firing up a
+    # separate process
+    test -d "$1" && return 0;
+
+    current="."
+    while [ ! "$current" -ef "$current/.." ]; do
+        if [ -d "$current/$1" ]; then
+            return 0;
+        fi
+        current="$current/..";
+    done
+
+    return 1;
+}
+
+__vcs_name() {
+    if [ -d .svn ]; then
+        echo "-[svn]";
+    elif __has_parent_dir ".git"; then
+        echo "-[$(__git_ps1 'git %s')]";
+    elif __has_parent_dir ".hg"; then
+        echo "-[hg $(hg branch)]"
+    fi
+}
+
+black=$(tput -Txterm setaf 0)
+red=$(tput -Txterm setaf 1)
+green=$(tput -Txterm setaf 2)
+yellow=$(tput -Txterm setaf 3)
+dk_blue=$(tput -Txterm setaf 4)
+pink=$(tput -Txterm setaf 5)
+lt_blue=$(tput -Txterm setaf 6)
+
+bold=$(tput -Txterm bold)
+reset=$(tput -Txterm sgr0)
+
+# Nicely formatted terminal prompt
+export PS1='\n\[$bold\]\[$black\][\[$dk_blue\]\@\[$black\]]-[\[$green\]\u\[$yellow\]@\[$green\]\h\[$black\]]-[\[$pink\]\w\[$black\]]\[\033[0;33m\]$(__vcs_name) \[\033[00m\]\[$reset\]\n\[$reset\]\$ '
+
+alias ls='ls -F --color=always'
+alias dir='dir -F --color=always'
+alias ll='ls -l'
+alias cp='cp -iv'
+alias rm='rm -i'
+alias mv='mv -iv'
+alias grep='grep --color=auto -in'
+alias ..='cd ..'
diff --git a/files/dot/.vimrc b/files/dot/.vimrc
new file mode 100644 (file)
index 0000000..2ff1aa6
--- /dev/null
@@ -0,0 +1,414 @@
+set rtp+=$GOROOT/misc/vim
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Maintainer:
+"       Amir Salihefendic
+"       http://amix.dk - amix@amix.dk
+"
+" Version:
+"       5.0 - 29/05/12 15:43:36
+"
+" Blog_post:
+"       http://amix.dk/blog/post/19691#The-ultimate-Vim-configuration-on-Github
+"
+" Awesome_version:
+"       Get this config, nice color schemes and lots of plugins!
+"
+"       Install the awesome version from:
+"
+"           https://github.com/amix/vimrc
+"
+" Syntax_highlighted:
+"       http://amix.dk/vim/vimrc.html
+"
+" Raw_version:
+"       http://amix.dk/vim/vimrc.txt
+"
+" Sections:
+"    -> General
+"    -> VIM user interface
+"    -> Colors and Fonts
+"    -> Files and backups
+"    -> Text, tab and indent related
+"    -> Visual mode related
+"    -> Moving around, tabs and buffers
+"    -> Status line
+"    -> Editing mappings
+"    -> vimgrep searching and cope displaying
+"    -> Spell checking
+"    -> Misc
+"    -> Helper functions
+"
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => General
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Sets how many lines of history VIM has to remember
+set history=700
+
+" Enable filetype plugins
+filetype plugin on
+filetype indent on
+
+" Set to auto read when a file is changed from the outside
+set autoread
+
+" With a map leader it's possible to do extra key combinations
+" like <leader>w saves the current file
+let mapleader = ","
+let g:mapleader = ","
+
+" Fast saving
+nmap <leader>w :w!<cr>
+
+" :W sudo saves the file
+" (useful for handling the permission-denied error)
+command W w !sudo tee % > /dev/null
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => VIM user interface
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Set 7 lines to the cursor - when moving vertically using j/k
+set so=7
+
+" Turn on the WiLd menu
+set wildmenu
+
+" Ignore compiled files
+set wildignore=*.o,*~,*.pyc
+if has("win16") || has("win32")
+    set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
+else
+    set wildignore+=.git\*,.hg\*,.svn\*
+endif
+
+"Always show current position
+set ruler
+
+" Height of the command bar
+set cmdheight=2
+
+" A buffer becomes hidden when it is abandoned
+set hid
+
+" Configure backspace so it acts as it should act
+set backspace=eol,start,indent
+set whichwrap+=<,>,h,l
+
+" Ignore case when searching
+set ignorecase
+
+" When searching try to be smart about cases
+set smartcase
+
+" Highlight search results
+set hlsearch
+
+" Makes search act like search in modern browsers
+set incsearch
+
+" Don't redraw while executing macros (good performance config)
+set lazyredraw
+
+" For regular expressions turn magic on
+set magic
+
+" Show matching brackets when text indicator is over them
+set showmatch
+" How many tenths of a second to blink when matching brackets
+set mat=2
+
+" No annoying sound on errors
+set noerrorbells
+set novisualbell
+set t_vb=
+set tm=500
+
+" Add a bit extra margin to the left
+set foldcolumn=1
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => Colors and Fonts
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Enable syntax highlighting
+syntax enable
+
+try
+    colorscheme desert
+catch
+endtry
+
+set background=dark
+
+" Set extra options when running in GUI mode
+if has("gui_running")
+    set guioptions-=T
+    set guioptions-=e
+    set t_Co=256
+    set guitablabel=%M\ %t
+endif
+
+" Set utf8 as standard encoding and en_US as the standard language
+set encoding=utf8
+
+" Use Unix as the standard file type
+set ffs=unix,dos,mac
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => Files, backups and undo
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Turn backup off, since most stuff is in SVN, git et.c anyway...
+set nobackup
+set nowb
+set noswapfile
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => Text, tab and indent related
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Use spaces instead of tabs
+set expandtab
+
+" Be smart when using tabs ;)
+set smarttab
+
+" 1 tab == 4 spaces
+set shiftwidth=4
+set tabstop=4
+
+" Linebreak on 500 characters
+set lbr
+set tw=500
+
+set ai "Auto indent
+set si "Smart indent
+set wrap "Wrap lines
+
+
+""""""""""""""""""""""""""""""
+" => Visual mode related
+""""""""""""""""""""""""""""""
+" Visual mode pressing * or # searches for the current selection
+" Super useful! From an idea by Michael Naumann
+vnoremap <silent> * :call VisualSelection('f', '')<CR>
+vnoremap <silent> # :call VisualSelection('b', '')<CR>
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => Moving around, tabs, windows and buffers
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Treat long lines as break lines (useful when moving around in them)
+map j gj
+map k gk
+
+" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
+map <space> /
+map <c-space> ?
+
+" Disable highlight when <leader><cr> is pressed
+map <silent> <leader><cr> :noh<cr>
+
+" Smart way to move between windows
+map <C-j> <C-W>j
+map <C-k> <C-W>k
+map <C-h> <C-W>h
+map <C-l> <C-W>l
+
+" Close the current buffer
+map <leader>bd :Bclose<cr>
+
+" Close all the buffers
+map <leader>ba :1,1000 bd!<cr>
+
+" Useful mappings for managing tabs
+map <leader>tn :tabnew<cr>
+map <leader>to :tabonly<cr>
+map <leader>tc :tabclose<cr>
+map <leader>tm :tabmove
+map <leader>t<leader> :tabnext
+
+" Opens a new tab with the current buffer's path
+" Super useful when editing files in the same directory
+map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
+
+" Switch CWD to the directory of the open buffer
+map <leader>cd :cd %:p:h<cr>:pwd<cr>
+
+" Specify the behavior when switching between buffers
+try
+  set switchbuf=useopen,usetab,newtab
+  set stal=2
+catch
+endtry
+
+" Return to last edit position when opening files (You want this!)
+autocmd BufReadPost *
+     \ if line("'\"") > 0 && line("'\"") <= line("$") |
+     \   exe "normal! g`\"" |
+     \ endif
+" Remember info about open buffers on close
+set viminfo^=%
+
+
+""""""""""""""""""""""""""""""
+" => Status line
+""""""""""""""""""""""""""""""
+" Always show the status line
+set laststatus=2
+
+" Format the status line
+set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => Editing mappings
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Remap VIM 0 to first non-blank character
+map 0 ^
+
+" Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
+nmap <M-j> mz:m+<cr>`z
+nmap <M-k> mz:m-2<cr>`z
+vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
+vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
+
+if has("mac") || has("macunix")
+  nmap <D-j> <M-j>
+  nmap <D-k> <M-k>
+  vmap <D-j> <M-j>
+  vmap <D-k> <M-k>
+endif
+
+" Delete trailing white space on save, useful for Python and CoffeeScript ;)
+func! DeleteTrailingWS()
+  exe "normal mz"
+  %s/\s\+$//ge
+  exe "normal `z"
+endfunc
+autocmd BufWrite *.py :call DeleteTrailingWS()
+autocmd BufWrite *.coffee :call DeleteTrailingWS()
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => vimgrep searching and cope displaying
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" When you press gv you vimgrep after the selected text
+vnoremap <silent> gv :call VisualSelection('gv', '')<CR>
+
+" Open vimgrep and put the cursor in the right position
+map <leader>g :vimgrep // **/*.<left><left><left><left><left><left><left>
+
+" Vimgreps in the current file
+map <leader><space> :vimgrep // <C-R>%<C-A><right><right><right><right><right><right><right><right><right>
+
+" When you press <leader>r you can search and replace the selected text
+vnoremap <silent> <leader>r :call VisualSelection('replace', '')<CR>
+
+" Do :help cope if you are unsure what cope is. It's super useful!
+"
+" When you search with vimgrep, display your results in cope by doing:
+"   <leader>cc
+"
+" To go to the next search result do:
+"   <leader>n
+"
+" To go to the previous search results do:
+"   <leader>p
+"
+map <leader>cc :botright cope<cr>
+map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
+map <leader>n :cn<cr>
+map <leader>p :cp<cr>
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => Spell checking
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Pressing ,ss will toggle and untoggle spell checking
+map <leader>ss :setlocal spell!<cr>
+
+" Shortcuts using <leader>
+map <leader>sn ]s
+map <leader>sp [s
+map <leader>sa zg
+map <leader>s? z=
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => Misc
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Remove the Windows ^M - when the encodings gets messed up
+noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
+
+" Quickly open a buffer for scripbble
+map <leader>q :e ~/buffer<cr>
+
+" Toggle paste mode on and off
+map <leader>pp :setlocal paste!<cr>
+
+
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" => Helper functions
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+function! CmdLine(str)
+    exe "menu Foo.Bar :" . a:str
+    emenu Foo.Bar
+    unmenu Foo
+endfunction
+
+function! VisualSelection(direction, extra_filter) range
+    let l:saved_reg = @"
+    execute "normal! vgvy"
+
+    let l:pattern = escape(@", '\\/.*$^~[]')
+    let l:pattern = substitute(l:pattern, "\n$", "", "")
+
+    if a:direction == 'b'
+        execute "normal ?" . l:pattern . "^M"
+    elseif a:direction == 'gv'
+        call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.' . a:extra_filter)
+    elseif a:direction == 'replace'
+        call CmdLine("%s" . '/'. l:pattern . '/')
+    elseif a:direction == 'f'
+        execute "normal /" . l:pattern . "^M"
+    endif
+
+    let @/ = l:pattern
+    let @" = l:saved_reg
+endfunction
+
+
+" Returns true if paste mode is enabled
+function! HasPaste()
+    if &paste
+        return 'PASTE MODE  '
+    en
+    return ''
+endfunction
+
+" Don't close window, when deleting a buffer
+command! Bclose call <SID>BufcloseCloseIt()
+function! <SID>BufcloseCloseIt()
+   let l:currentBufNum = bufnr("%")
+   let l:alternateBufNum = bufnr("#")
+
+   if buflisted(l:alternateBufNum)
+     buffer #
+   else
+     bnext
+   endif
+
+   if bufnr("%") == l:currentBufNum
+     new
+   endif
+
+   if buflisted(l:currentBufNum)
+     execute("bdelete! ".l:currentBufNum)
+   endif
+endfunction
diff --git a/hiera.yaml b/hiera.yaml
new file mode 100644 (file)
index 0000000..2cab35e
--- /dev/null
@@ -0,0 +1,7 @@
+---
+:backends: yaml
+:yaml:
+    :datadir: '/vagrant/puppet/hieradata'
+:hierarchy:
+    - common
+:logger: console
diff --git a/puppet/Puppetfile b/puppet/Puppetfile
new file mode 100644 (file)
index 0000000..5452939
--- /dev/null
@@ -0,0 +1,13 @@
+forge "http://forge.puppetlabs.com"
+mod 'stdlib', :git => 'git://github.com/puphpet/puppetlabs-stdlib.git'
+mod 'concat', :git => 'git://github.com/puphpet/puppetlabs-concat.git'
+mod 'apt', :git => 'git://github.com/puphpet/puppetlabs-apt.git'
+mod 'yum', :git => 'git://github.com/puphpet/puppet-yum.git'
+mod 'vcsrepo', :git => 'git://github.com/puphpet/puppetlabs-vcsrepo.git'
+mod 'ntp', :git => 'git://github.com/puphpet/puppetlabs-ntp.git'
+mod 'iptables', :git => 'git://github.com/puphpet/puppet-iptables.git'
+mod 'nginx', :git => 'git://github.com/puphpet/puppet-nginx.git'
+mod 'php', :git => 'git://github.com/puphpet/puppet-php.git'
+mod 'composer', :git => 'git://github.com/puphpet/puppet-composer.git'
+mod 'puphpet', :git => 'git://github.com/puphpet/puppet-puphpet.git'
+mod 'mysql', :git => 'git://github.com/puphpet/puppetlabs-mysql.git'
diff --git a/puppet/hieradata/common.yaml b/puppet/hieradata/common.yaml
new file mode 100644 (file)
index 0000000..d9665e4
--- /dev/null
@@ -0,0 +1,101 @@
+---
+vagrantfile-local:
+    vm:
+        box: ubuntu-precise12042-x64-vbox43
+        box_url: 'https://puphpet.s3.amazonaws.com/ubuntu-precise12042-x64-vbox43.box'
+        hostname: null
+        network:
+            private_network: 192.168.56.101
+            forwarded_port:
+                krDtH5qLxBem:
+                    host: '8080'
+                    guest: '80'
+        provider:
+            virtualbox:
+                modifyvm:
+                    name: memberdb
+                    natdnshostresolver1: on
+                    memory: '512'
+                setextradata:
+                    VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root: 1
+        provision:
+            puppet:
+                manifests_path: puppet/manifests
+                options:
+                    - --verbose
+                    - '--hiera_config /vagrant/hiera.yaml'
+                    - '--parser future'
+        synced_folder:
+            jh4J64KOAvzL:
+                id: vagrant-root
+                source: ./
+                target: /var/www/memberdb
+                nfs: 'false'
+        usable_port_range: 2200..2250
+    ssh:
+        host: null
+        port: null
+        private_key_path: null
+        username: vagrant
+        guest_port: null
+        keep_alive: true
+        forward_agent: false
+        forward_x11: false
+        shell: 'bash -l'
+    vagrant:
+        host: ':detect'
+server:
+    packages:
+        - vim-tiny
+    dot_files:
+        -
+            bash_aliases: null
+    _prevent_empty: ''
+nginx:
+    vhosts:
+        ehPNxiNc7gg6:
+            server_name: memberdb.dev
+            server_aliases:
+                - www.memberdb.dev
+            www_root: /var/www/memberdb
+            listen_port: '80'
+            index_files:
+                - index.php
+            envvars:
+                - 'APP_ENV dev'
+php:
+    version: '53'
+    composer: '1'
+    modules:
+        php:
+            - cli
+            - intl
+            - mcrypt
+        pear: {  }
+        pecl: {  }
+    ini:
+        display_errors: On
+        error_reporting: '-1'
+    timezone: UTC
+xdebug:
+    install: '1'
+    settings:
+        xdebug.default_enable: '1'
+        xdebug.remote_autostart: '0'
+        xdebug.remote_connect_back: '1'
+        xdebug.remote_enable: '1'
+        xdebug.remote_handler: dbgp
+        xdebug.remote_port: '9000'
+mysql:
+    root_password: '123'
+    phpmyadmin: 0
+    databases:
+        soZOdGgfFKij:
+            grant:
+                - ALL
+            name: memberdb
+            host: localhost
+            user: memberdb
+            password: memberdb
+            sql_file: ''
+
diff --git a/puppet/manifests/default.pp b/puppet/manifests/default.pp
new file mode 100644 (file)
index 0000000..f753377
--- /dev/null
@@ -0,0 +1,443 @@
+## Begin Server manifest
+
+if $server_values == undef {
+  $server_values = hiera('server', false)
+}
+
+# Ensure the time is accurate, reducing the possibilities of apt repositories
+# failing for invalid certificates
+include '::ntp'
+
+group { 'puppet': ensure => present }
+Exec { path => [ '/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/' ] }
+File { owner => 0, group => 0, mode => 0644 }
+
+user { $::ssh_username:
+    shell  => '/bin/bash',
+    home   => "/home/${::ssh_username}",
+    ensure => present
+}
+
+file { "/home/${::ssh_username}":
+    ensure => directory,
+    owner  => $::ssh_username,
+}
+
+# in case php extension was not loaded
+if $php_values == undef {
+  $php_values = hiera('php', false)
+}
+
+# copy dot files to ssh user's home directory
+exec { 'dotfiles':
+  cwd     => "/home/${::ssh_username}",
+  command => "cp -r /vagrant/files/dot/.[a-zA-Z0-9]* /home/${::ssh_username}/ && chown -R ${::ssh_username} /home/${::ssh_username}/.[a-zA-Z0-9]*",
+  onlyif  => "test -d /vagrant/files/dot",
+  require => User[$::ssh_username]
+}
+
+case $::osfamily {
+  # debian, ubuntu
+  'debian': {
+    class { 'apt': }
+
+    Class['::apt::update'] -> Package <|
+        title != 'python-software-properties'
+    and title != 'software-properties-common'
+    |>
+
+    ensure_packages( ['augeas-tools'] )
+  }
+  # redhat, centos
+  'redhat': {
+    class { 'yum': extrarepo => ['epel'] }
+
+    Class['::yum'] -> Yum::Managed_yumrepo <| |> -> Package <| |>
+
+    exec { 'bash_git':
+      cwd     => "/home/${::ssh_username}",
+      command => "curl https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > /home/${::ssh_username}/.bash_git",
+      creates => "/home/${::ssh_username}/.bash_git"
+    }
+
+    file_line { 'link ~/.bash_git':
+      ensure  => present,
+      line    => 'if [ -f ~/.bash_git ] ; then source ~/.bash_git; fi',
+      path    => "/home/${::ssh_username}/.bash_profile",
+      require => [
+        Exec['dotfiles'],
+        Exec['bash_git'],
+      ]
+    }
+
+    file_line { 'link ~/.bash_aliases':
+      ensure  => present,
+      line    => 'if [ -f ~/.bash_aliases ] ; then source ~/.bash_aliases; fi',
+      path    => "/home/${::ssh_username}/.bash_profile",
+      require => [
+        File_line['link ~/.bash_git'],
+      ]
+    }
+
+    ensure_packages( ['augeas'] )
+  }
+}
+
+case $::operatingsystem {
+  'debian': {
+    add_dotdeb { 'packages.dotdeb.org': release => $lsbdistcodename }
+
+    if is_hash($php_values) {
+      # Debian Squeeze 6.0 can do PHP 5.3 (default) and 5.4
+      if $lsbdistcodename == 'squeeze' and $php_values['version'] == '54' {
+        add_dotdeb { 'packages.dotdeb.org-php54': release => 'squeeze-php54' }
+      }
+      # Debian Wheezy 7.0 can do PHP 5.4 (default) and 5.5
+      elsif $lsbdistcodename == 'wheezy' and $php_values['version'] == '55' {
+        add_dotdeb { 'packages.dotdeb.org-php55': release => 'wheezy-php55' }
+      }
+    }
+  }
+  'ubuntu': {
+    apt::key { '4F4EA0AAE5267A6C': }
+
+    if is_hash($php_values) {
+      # Ubuntu Lucid 10.04, Precise 12.04, Quantal 12.10 and Raring 13.04 can do PHP 5.3 (default <= 12.10) and 5.4 (default <= 13.04)
+      if $lsbdistcodename in ['lucid', 'precise', 'quantal', 'raring'] and $php_values['version'] == '54' {
+        if $lsbdistcodename == 'lucid' {
+          apt::ppa { 'ppa:ondrej/php5-oldstable': require => Apt::Key['4F4EA0AAE5267A6C'], options => '' }
+        } else {
+          apt::ppa { 'ppa:ondrej/php5-oldstable': require => Apt::Key['4F4EA0AAE5267A6C'] }
+        }
+      }
+      # Ubuntu Precise 12.04, Quantal 12.10 and Raring 13.04 can do PHP 5.5
+      elsif $lsbdistcodename in ['precise', 'quantal', 'raring'] and $php_values['version'] == '55' {
+        apt::ppa { 'ppa:ondrej/php5': require => Apt::Key['4F4EA0AAE5267A6C'] }
+      }
+      elsif $lsbdistcodename in ['lucid'] and $php_values['version'] == '55' {
+        err('You have chosen to install PHP 5.5 on Ubuntu 10.04 Lucid. This will probably not work!')
+      }
+    }
+  }
+  'redhat', 'centos': {
+    if is_hash($php_values) {
+      if $php_values['version'] == '54' {
+        class { 'yum::repo::remi': }
+      }
+      # remi_php55 requires the remi repo as well
+      elsif $php_values['version'] == '55' {
+        class { 'yum::repo::remi': }
+        class { 'yum::repo::remi_php55': }
+      }
+    }
+  }
+}
+
+if !empty($server_values['packages']) {
+  ensure_packages( $server_values['packages'] )
+}
+
+define add_dotdeb ($release){
+   apt::source { $name:
+    location          => 'http://packages.dotdeb.org',
+    release           => $release,
+    repos             => 'all',
+    required_packages => 'debian-keyring debian-archive-keyring',
+    key               => '89DF5277',
+    key_server        => 'keys.gnupg.net',
+    include_src       => true
+  }
+}
+
+## Begin Nginx manifest
+
+if $nginx_values == undef {
+   $nginx_values = hiera('nginx', false)
+}
+
+if $php_values == undef {
+   $php_values = hiera('php', false)
+}
+
+if $::osfamily == 'debian' and $lsbdistcodename in ['lucid'] and is_hash($php_values) and $php_values['version'] == '53' {
+  apt::key { '67E15F46': }
+  apt::ppa { 'ppa:l-mierzwa/lucid-php5':
+    options => '',
+    require => Apt::Key['67E15F46']
+  }
+}
+
+$php5_fpm_sock = '/var/run/php5-fpm.sock'
+
+if $php_values['version'] == undef {
+  $fastcgi_pass = null
+} elsif $php_values['version'] == '53' {
+  $fastcgi_pass = '127.0.0.1:9000'
+} else {
+  $fastcgi_pass = "unix:${php5_fpm_sock}"
+}
+
+class { 'nginx': }
+
+if count($nginx_values['vhosts']) > 0 {
+  create_resources(nginx_vhost, $nginx_values['vhosts'])
+}
+
+if $::osfamily == 'redhat' and ! defined(Iptables::Allow['tcp/80']) {
+  iptables::allow { 'tcp/80':
+    port     => '80',
+    protocol => 'tcp'
+  }
+}
+
+define nginx_vhost (
+  $server_name,
+  $server_aliases = [],
+  $www_root,
+  $listen_port,
+  $index_files,
+  $envvars = [],
+){
+  $merged_server_name = concat([$server_name], $server_aliases)
+
+  if is_array($index_files) and count($index_files) > 0 {
+    $try_files = $index_files[count($index_files) - 1]
+  } else {
+    $try_files = 'index.php'
+  }
+
+  nginx::resource::vhost { $server_name:
+    server_name => $merged_server_name,
+    www_root    => $www_root,
+    listen_port => $listen_port,
+    index_files => $index_files,
+    try_files   => ['$uri', '$uri/', "/${try_files}?\$args"],
+  }
+
+  $fastcgi_param = concat(
+  [
+    'PATH_INFO $fastcgi_path_info',
+    'PATH_TRANSLATED $document_root$fastcgi_path_info',
+    'SCRIPT_FILENAME $document_root$fastcgi_script_name',
+  ], $envvars)
+
+  nginx::resource::location { "${server_name}-php":
+    ensure              => present,
+    vhost               => $server_name,
+    location            => '~ \.php$',
+    proxy               => undef,
+    try_files           => ['$uri', '$uri/', "/${try_files}?\$args"],
+    www_root            => $www_root,
+    location_cfg_append => {
+      'fastcgi_split_path_info' => '^(.+\.php)(/.+)$',
+      'fastcgi_param'           => $fastcgi_param,
+      'fastcgi_pass'            => $fastcgi_pass,
+      'fastcgi_index'           => 'index.php',
+      'include'                 => 'fastcgi_params'
+    },
+    notify              => Class['nginx::service'],
+  }
+}
+
+if $::osfamily == 'redhat' and $fastcgi_pass == "unix:${php5_fpm_sock}" {
+  exec { "create ${php5_fpm_sock} file":
+    command => "touch ${php5_fpm_sock} && chmod 777 ${php5_fpm_sock}",
+    onlyif  => ["test ! -f ${php5_fpm_sock}", "test ! -f ${php5_fpm_sock}="],
+    require => Package['nginx']
+  }
+
+  exec { "listen = 127.0.0.1:9000 => listen = ${php5_fpm_sock}":
+    command => "perl -p -i -e 's#listen = 127.0.0.1:9000#listen = ${php5_fpm_sock}#gi' /etc/php-fpm.d/www.conf",
+    unless  => "grep -c 'listen = 127.0.0.1:9000' '${php5_fpm_sock}'",
+    notify  => [
+      Class['nginx::service'],
+      Service['php-fpm']
+    ],
+    require => Exec["create ${php5_fpm_sock} file"]
+  }
+}
+
+## Begin PHP manifest
+
+if $php_values == undef {
+  $php_values = hiera('php', false)
+}
+
+if $apache_values == undef {
+  $apache_values = hiera('apache', false)
+}
+
+if $nginx_values == undef {
+  $nginx_values = hiera('nginx', false)
+}
+
+Class['Php'] -> Class['Php::Devel'] -> Php::Module <| |> -> Php::Pear::Module <| |> -> Php::Pecl::Module <| |>
+
+if $php_prefix == undef {
+  $php_prefix = $::operatingsystem ? {
+    /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => 'php5-',
+    default                                 => 'php-',
+  }
+}
+
+if $php_fpm_ini == undef {
+  $php_fpm_ini = $::operatingsystem ? {
+    /(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5/fpm/php.ini',
+    default                                 => '/etc/php.ini',
+  }
+}
+
+if is_hash($apache_values) {
+  $php_webserver_service = 'httpd'
+
+  class { 'php':
+    service => $php_webserver_service
+  }
+} elsif is_hash($nginx_values) {
+  $php_webserver_service = "${php_prefix}fpm"
+
+  class { 'php':
+    package             => $php_webserver_service,
+    service             => $php_webserver_service,
+    service_autorestart => false,
+    config_file         => $php_fpm_ini,
+  }
+
+  service { $php_webserver_service:
+    ensure     => running,
+    enable     => true,
+    hasrestart => true,
+    hasstatus  => true,
+    require    => Package[$php_webserver_service]
+  }
+}
+
+class { 'php::devel': }
+
+if count($php_values['modules']['php']) > 0 {
+  php_mod { $php_values['modules']['php']:; }
+}
+if count($php_values['modules']['pear']) > 0 {
+  php_pear_mod { $php_values['modules']['pear']:; }
+}
+if count($php_values['modules']['pecl']) > 0 {
+  php_pecl_mod { $php_values['modules']['pecl']:; }
+}
+if count($php_values['ini']) > 0 {
+  $php_values['ini'].each { |$key, $value|
+    puphpet::ini { $key:
+      entry       => "CUSTOM/${key}",
+      value       => $value,
+      php_version => $php_values['version'],
+      webserver   => $php_webserver_service
+    }
+  }
+}
+
+puphpet::ini { $key:
+  entry       => 'CUSTOM/date.timezone',
+  value       => $php_values['timezone'],
+  php_version => $php_values['version'],
+  webserver   => $php_webserver_service
+}
+
+define php_mod {
+  php::module { $name: }
+}
+define php_pear_mod {
+  php::pear::module { $name: use_package => false }
+}
+define php_pecl_mod {
+  php::pecl::module { $name: use_package => false }
+}
+
+if $php_values['composer'] == 1 {
+  class { 'composer':
+    target_dir      => '/usr/local/bin',
+    composer_file   => 'composer',
+    download_method => 'curl',
+    logoutput       => false,
+    tmp_path        => '/tmp',
+    php_package     => "${php::params::module_prefix}cli",
+    curl_package    => 'curl',
+    suhosin_enabled => false,
+  }
+}
+
+if $xdebug_values == undef {
+  $xdebug_values = hiera('xdebug', false)
+}
+
+if is_hash($apache_values) {
+  $xdebug_webserver_service = 'httpd'
+} elsif is_hash($nginx_values) {
+  $xdebug_webserver_service = 'nginx'
+} else {
+  $xdebug_webserver_service = undef
+}
+
+if $xdebug_values['install'] != undef and $xdebug_values['install'] == 1 {
+  class { 'puphpet::xdebug':
+    webserver => $xdebug_webserver_service
+  }
+
+  if is_hash($xdebug_values['settings']) and count($xdebug_values['settings']) > 0 {
+    $xdebug_values['settings'].each { |$key, $value|
+      puphpet::ini { $key:
+        entry       => "XDEBUG/${key}",
+        value       => $value,
+        php_version => $php_values['version'],
+        webserver   => $xdebug_webserver_service
+      }
+    }
+  }
+}
+
+## Begin MySQL manifest
+
+if $mysql_values == undef {
+  $mysql_values = hiera('mysql', false)
+}
+
+if $php_values == undef {
+  $php_values = hiera('php', false)
+}
+
+if $mysql_values['root_password'] {
+  class { 'mysql::server':
+    root_password => $mysql_values['root_password'],
+  }
+
+  if is_hash($mysql_values['databases']) and count($mysql_values['databases']) > 0 {
+    create_resources(mysql_db, $mysql_values['databases'])
+  }
+
+  if is_hash($php_values) {
+    if $::osfamily == 'redhat' and $php_values['version'] == '53' and ! defined(Php::Module['mysql']) {
+      php::module { 'mysql': }
+    } elsif ! defined(Php::Module['mysqlnd']) {
+      php::module { 'mysqlnd': }
+    }
+  }
+}
+
+define mysql_db (
+  $user,
+  $password,
+  $host,
+  $grant    = [],
+  $sql_file = false
+) {
+  if $name == '' or $password == '' or $host == '' {
+    fail( 'MySQL DB requires that name, password and host be set. Please check your settings!' )
+  }
+
+  mysql::db { $name:
+    user     => $user,
+    password => $password,
+    host     => $host,
+    grant    => $grant,
+    sql      => $sql_file,
+  }
+}
+
diff --git a/shell/initial-setup.sh b/shell/initial-setup.sh
new file mode 100644 (file)
index 0000000..724963a
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+OS=$(/bin/bash /vagrant/shell/os-detect.sh ID)
+CODENAME=$(/bin/bash /vagrant/shell/os-detect.sh CODENAME)
+
+if [[ ! -d /.puphpet-stuff ]]; then
+    cat /vagrant/shell/self-promotion.txt
+    mkdir /.puphpet-stuff
+    echo "Created directory /.puphpet-stuff"
+fi
+
+if [[ ! -f /.puphpet-stuff/initial-setup-repo-update ]]; then
+    if [ "$OS" == 'debian' ] || [ "$OS" == 'ubuntu' ]; then
+        echo "Running initial-setup apt-get update"
+        apt-get update >/dev/null
+        touch /.puphpet-stuff/initial-setup-repo-update
+        echo "Finished running initial-setup apt-get update"
+    elif [[ "$OS" == 'centos' ]]; then
+        echo "Running initial-setup yum update"
+        yum update -y >/dev/null
+        echo "Finished running initial-setup yum update"
+
+        echo "Installing basic development tools (CentOS)"
+        yum -y groupinstall "Development Tools" >/dev/null
+        echo "Finished installing basic development tools (CentOS)"
+        touch /.puphpet-stuff/initial-setup-repo-update
+    fi
+fi
+
+if [[ "$OS" == 'ubuntu' && ("$CODENAME" == 'lucid' || "$CODENAME" == 'precise') && ! -f /.puphpet-stuff/ubuntu-required-libraries ]]; then
+    echo 'Installing basic curl packages (Ubuntu only)'
+    apt-get install -y libcurl3 libcurl4-gnutls-dev >/dev/null
+    echo 'Finished installing basic curl packages (Ubuntu only)'
+
+    touch /.puphpet-stuff/ubuntu-required-libraries
+fi
diff --git a/shell/librarian-puppet-vagrant.sh b/shell/librarian-puppet-vagrant.sh
new file mode 100644 (file)
index 0000000..46569a8
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+OS=$(/bin/bash /vagrant/shell/os-detect.sh ID)
+CODENAME=$(/bin/bash /vagrant/shell/os-detect.sh CODENAME)
+
+# Directory in which librarian-puppet should manage its modules directory
+PUPPET_DIR=/etc/puppet/
+
+$(which git > /dev/null 2>&1)
+FOUND_GIT=$?
+
+if [ "$FOUND_GIT" -ne '0' ] && [ ! -f /.puphpet-stuff/librarian-puppet-installed ]; then
+    $(which apt-get > /dev/null 2>&1)
+    FOUND_APT=$?
+    $(which yum > /dev/null 2>&1)
+    FOUND_YUM=$?
+
+    echo 'Installing git'
+
+    if [ "${FOUND_YUM}" -eq '0' ]; then
+        yum -q -y makecache
+        yum -q -y install git
+    else
+        apt-get -q -y install git-core >/dev/null
+    fi
+
+    echo 'Finished installing git'
+fi
+
+if [[ ! -d "$PUPPET_DIR" ]]; then
+    mkdir -p "$PUPPET_DIR"
+    echo "Created directory $PUPPET_DIR"
+fi
+
+cp "/vagrant/puppet/Puppetfile" "$PUPPET_DIR"
+echo "Copied Puppetfile"
+
+if [ "$OS" == 'debian' ] || [ "$OS" == 'ubuntu' ]; then
+    if [[ ! -f /.puphpet-stuff/librarian-base-packages ]]; then
+        echo 'Installing base packages for librarian'
+        apt-get install -y build-essential ruby-dev >/dev/null
+        echo 'Finished installing base packages for librarian'
+
+        touch /.puphpet-stuff/librarian-base-packages
+    fi
+fi
+
+if [ "$OS" == 'ubuntu' ]; then
+    if [[ ! -f /.puphpet-stuff/librarian-libgemplugin-ruby ]]; then
+        echo 'Updating libgemplugin-ruby (Ubuntu only)'
+        apt-get install -y libgemplugin-ruby >/dev/null
+        echo 'Finished updating libgemplugin-ruby (Ubuntu only)'
+
+        touch /.puphpet-stuff/librarian-libgemplugin-ruby
+    fi
+
+    if [ "$CODENAME" == 'lucid' ] && [ ! -f /.puphpet-stuff/librarian-rubygems-update ]; then
+        echo 'Updating rubygems (Ubuntu Lucid only)'
+        echo 'Ignore all "conflicting chdir" errors!'
+        gem install rubygems-update >/dev/null
+        /var/lib/gems/1.8/bin/update_rubygems >/dev/null
+        echo 'Finished updating rubygems (Ubuntu Lucid only)'
+
+        touch /.puphpet-stuff/librarian-rubygems-update
+    fi
+fi
+
+if [[ ! -f /.puphpet-stuff/librarian-puppet-installed ]]; then
+    echo 'Installing librarian-puppet'
+    gem install librarian-puppet >/dev/null
+    echo 'Finished installing librarian-puppet'
+
+    echo 'Running initial librarian-puppet'
+    cd "$PUPPET_DIR" && librarian-puppet install --clean >/dev/null
+    echo 'Finished running initial librarian-puppet'
+
+    touch /.puphpet-stuff/librarian-puppet-installed
+else
+    echo 'Running update librarian-puppet'
+    cd "$PUPPET_DIR" && librarian-puppet update >/dev/null
+    echo 'Finished running update librarian-puppet'
+fi
diff --git a/shell/os-detect.sh b/shell/os-detect.sh
new file mode 100644 (file)
index 0000000..07d2adb
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+# Try and get debian operating system
+# id, codename, and release
+
+TYPE=$(echo "$1" | tr '[A-Z]' '[a-z]')
+OS=$(uname)
+ID="unknown"
+CODENAME="unknown"
+RELEASE="unknown"
+
+if [ "$OS" == "Linux" ]; then
+    # detect centos
+    grep "centos" /etc/issue -i -q
+    if [ $? = '0' ]; then
+        ID="centos"
+        RELEASE=$(cat /etc/redhat-release | grep -o 'release [0-9]' | cut -d " " -f2)
+    # could be debian or ubuntu
+    elif [ $(which lsb_release) ]; then
+        ID=$(lsb_release -i | cut -f2)
+        CODENAME=$(lsb_release -c | cut -f2)
+        RELEASE=$(lsb_release -r | cut -f2)
+    elif [ -f "/etc/lsb-release" ]; then
+        ID=$(cat /etc/lsb-release | grep DISTRIB_ID | cut -d "=" -f2)
+        CODENAME=$(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d "=" -f2)
+        RELEASE=$(cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d "=" -f2)
+    elif [ -f "/etc/issue" ]; then
+        ID=$(head -1 /etc/issue | cut -d " " -f1)
+        if [ -f "/etc/debian_version" ]; then
+          RELEASE=$(</etc/debian_version)
+        else
+          RELEASE=$(head -1 /etc/issue | cut -d " " -f2)
+        fi
+    fi
+fi
+
+declare -A info
+
+info[id]=$(echo "$ID" | tr '[A-Z]' '[a-z]')
+info[codename]=$(echo "$CODENAME" | tr '[A-Z]' '[a-z]')
+info[release]=$(echo "$RELEASE" | tr '[A-Z]' '[a-z]')
+
+if [ "$TYPE" ] ; then 
+    echo "${info[$TYPE]}"
+else 
+    echo -e "ID\t${info[id]}"
+    echo -e "CODENAME\t${info[codename]}"
+    echo -e "RELEASE\t${info[release]}"
+fi
diff --git a/shell/self-promotion.txt b/shell/self-promotion.txt
new file mode 100644 (file)
index 0000000..f474331
--- /dev/null
@@ -0,0 +1,7 @@
+
+ ____        ____  _   _ ____      _      generated using
+|  _ \ _   _|  _ \| | | |  _ \ ___| |_   ___ ___  _ __ ___
+| |_) | | | | |_) | |_| | |_) / _ \ __| / __/ _ \| '_ ` _ \
+|  __/| |_| |  __/|  _  |  __/  __/ |_ | (_| (_) | | | | | |
+|_|    \__,_|_|   |_| |_|_|   \___|\__(_)___\___/|_| |_| |_|
+
diff --git a/shell/update-puppet.sh b/shell/update-puppet.sh
new file mode 100644 (file)
index 0000000..25f8e1d
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+OS=$(/bin/bash /vagrant/shell/os-detect.sh ID)
+RELEASE=$(/bin/bash /vagrant/shell/os-detect.sh RELEASE)
+CODENAME=$(/bin/bash /vagrant/shell/os-detect.sh CODENAME)
+
+if [[ ! -f /.puphpet-stuff/update-puppet ]]; then
+    if [ "$OS" == 'debian' ] || [ "$OS" == 'ubuntu' ]; then
+        echo "Downloading https://github.com/puphpet/apt-puppetlabs-com/raw/master/puppetlabs-release-${CODENAME}.deb"
+        wget --quiet --tries=5 --timeout=10 -O "/.puphpet-stuff/puppetlabs-release-${CODENAME}.deb" "https://github.com/puphpet/apt-puppetlabs-com/raw/master/puppetlabs-release-${CODENAME}.deb"
+        echo "Finished downloading https://github.com/puphpet/apt-puppetlabs-com/raw/master/puppetlabs-release-${CODENAME}.deb"
+
+        dpkg -i "/.puphpet-stuff/puppetlabs-release-${CODENAME}.deb" >/dev/null
+
+        echo "Running update-puppet apt-get update"
+        apt-get update >/dev/null
+        echo "Finished running update-puppet apt-get update"
+
+        echo "Updating Puppet to latest version"
+        apt-get -y install puppet >/dev/null
+        PUPPET_VERSION=$(puppet help | grep 'Puppet v')
+        echo "Finished updating puppet to latest version: $PUPPET_VERSION"
+
+        touch /.puphpet-stuff/update-puppet
+        echo "Created empty file /.puphpet-stuff/update-puppet"
+    elif [ "$OS" == 'centos' ]; then
+        echo "Downloading http://yum.puppetlabs.com/el/${RELEASE}/products/x86_64/puppetlabs-release-6-7.noarch.rpm"
+        yum -y --nogpgcheck install "http://yum.puppetlabs.com/el/${RELEASE}/products/x86_64/puppetlabs-release-6-7.noarch.rpm" >/dev/null
+        echo "Finished downloading http://yum.puppetlabs.com/el/${RELEASE}/products/x86_64/puppetlabs-release-6-7.noarch.rpm"
+
+        echo "Running update-puppet yum update"
+        yum -y update >/dev/null
+        echo "Finished running update-puppet yum update"
+
+        echo "Installing/Updating Puppet to latest version"
+        yum -y install puppet >/dev/null
+        PUPPET_VERSION=$(puppet help | grep 'Puppet v')
+        echo "Finished installing/updating puppet to latest version: $PUPPET_VERSION"
+
+        touch /.puphpet-stuff/update-puppet
+        echo "Created empty file /.puphpet-stuff/update-puppet"
+    fi
+fi