add vagrant scripts
authorCornelius Weiß <mail@corneliusweiss.de>
Mon, 25 Nov 2013 15:16:06 +0000 (16:16 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 2 Dec 2013 13:07:53 +0000 (14:07 +0100)
- first approach for FAI (dev) with vagrant

Change-Id: I658862be0ef2a24bae88185dd062c01ba8255237
Reviewed-on: https://gerrit.tine20.org/tine20/2590
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
12 files changed:
scripts/vagrant/Vagrantfile [new file with mode: 0644]
scripts/vagrant/hiera.yaml [new file with mode: 0644]
scripts/vagrant/phpmyadmin [new symlink]
scripts/vagrant/puppet/Puppetfile [new file with mode: 0644]
scripts/vagrant/puppet/hieradata/common.yaml [new file with mode: 0644]
scripts/vagrant/puppet/hieradata/tine20.yaml [new file with mode: 0644]
scripts/vagrant/puppet/manifests/default.pp [new file with mode: 0644]
scripts/vagrant/shell/initial-setup.sh [new file with mode: 0644]
scripts/vagrant/shell/librarian-puppet-vagrant.sh [new file with mode: 0644]
scripts/vagrant/shell/os-detect.sh [new file with mode: 0644]
scripts/vagrant/shell/self-promotion.txt [new file with mode: 0644]
scripts/vagrant/shell/update-puppet.sh [new file with mode: 0644]

diff --git a/scripts/vagrant/Vagrantfile b/scripts/vagrant/Vagrantfile
new file mode 100644 (file)
index 0000000..2574c30
--- /dev/null
@@ -0,0 +1,39 @@
+Vagrant.configure("2") do |config|
+  config.vm.box = "debian-wheezy72-x64-vbox43"
+  config.vm.box_url = "https://puphpet.s3.amazonaws.com/debian-wheezy72-x64-vbox43.box"
+
+  config.vm.network "private_network", ip: "192.168.56.101"
+
+
+  config.vm.synced_folder "../../tine20", "/var/www", id: "vagrant-root", :nfs => false
+
+  config.vm.usable_port_range = (2200..2250)
+  config.vm.provider :virtualbox do |virtualbox|
+    virtualbox.customize ["modifyvm", :id, "--name", "my-vm-box"]
+    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/scripts/vagrant/hiera.yaml b/scripts/vagrant/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/scripts/vagrant/phpmyadmin b/scripts/vagrant/phpmyadmin
new file mode 120000 (symlink)
index 0000000..3b895ec
--- /dev/null
@@ -0,0 +1 @@
+/usr/share/phpmyadmin
\ No newline at end of file
diff --git a/scripts/vagrant/puppet/Puppetfile b/scripts/vagrant/puppet/Puppetfile
new file mode 100644 (file)
index 0000000..252ae8e
--- /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 'apache', :git => 'git://github.com/puphpet/puppetlabs-apache.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/scripts/vagrant/puppet/hieradata/common.yaml b/scripts/vagrant/puppet/hieradata/common.yaml
new file mode 100644 (file)
index 0000000..48bc8cd
--- /dev/null
@@ -0,0 +1,106 @@
+---
+vagrantfile-local:
+    vm:
+        box: debian-wheezy72-x64-vbox43
+        box_url: 'https://puphpet.s3.amazonaws.com/debian-wheezy72-x64-vbox43.box'
+        hostname: null
+        network:
+            private_network: 192.168.56.101
+            forwarded_port:
+                hS7jk0Np9Ab5:
+                    host: ''
+                    guest: ''
+        provider:
+            virtualbox:
+                modifyvm:
+                    name: my-vm-box
+                    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:
+            LxME30gm6SNU:
+                id: vagrant-root
+                source: ./
+                target: /var/www
+                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: {  }
+    dot_files:
+        -
+            bash_aliases: null
+    _prevent_empty: ''
+apache:
+    modules:
+        - php
+        - rewrite
+    vhosts:
+        Xan8mqMbuDOQ:
+            servername: awesome.dev
+            serveraliases:
+                - www.awesome.dev
+            docroot: /var/www/awesome
+            port: '80'
+            setenv:
+                - 'APP_ENV dev'
+            override:
+                - All
+    user: www-data
+    group: www-data
+    default_vhost: true
+    mpm_module: prefork
+php:
+    version: '55'
+    composer: '1'
+    modules:
+        php:
+            - cli
+            - intl
+            - mcrypt
+            - ldap
+            - xsl
+        pear: {  }
+        pecl:
+            - pecl_http
+    ini:
+        display_errors: On
+        error_reporting: '-1'
+        session.save_path: /var/lib/php/session
+    timezone: Europe/Berlin
+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'
+xhprof:
+    install: '1'
+    location: /var/www/xhprof
+mysql:
+    root_password: '123'
+    phpmyadmin: '1'
+
+
diff --git a/scripts/vagrant/puppet/hieradata/tine20.yaml b/scripts/vagrant/puppet/hieradata/tine20.yaml
new file mode 100644 (file)
index 0000000..7a23d9b
--- /dev/null
@@ -0,0 +1,13 @@
+---
+database:
+    name: tine20
+    host: localhost
+    user: tine20
+    password: pass
+setupuser:
+    user: tine20admin
+    password: lars
+initialuser:
+    user: tine20admin
+    password: lars
+    email: admin@eample.org
\ No newline at end of file
diff --git a/scripts/vagrant/puppet/manifests/default.pp b/scripts/vagrant/puppet/manifests/default.pp
new file mode 100644 (file)
index 0000000..4c4b93c
--- /dev/null
@@ -0,0 +1,611 @@
+## 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'
+
+Exec { path => [ '/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/' ] }
+File { owner => 0, group => 0, mode => 0644 }
+
+group { 'puppet': ensure => present }
+group { 'www-data': ensure => present }
+
+user { $::ssh_username:
+  shell  => '/bin/bash',
+  home   => "/home/${::ssh_username}",
+  ensure => present
+}
+
+user { ['apache', 'nginx', 'httpd', 'www-data']:
+  shell  => '/bin/bash',
+  ensure => present,
+  groups => 'www-data',
+  require => Group['www-data']
+}
+
+file { "/home/${::ssh_username}":
+    ensure => directory,
+    owner  => $::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'] )
+  }
+}
+
+if $php_values == undef {
+  $php_values = hiera('php', false)
+}
+
+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 Apache manifest
+
+if $yaml_values == undef {
+  $yaml_values = loadyaml('/vagrant/puppet/hieradata/common.yaml')
+}
+
+if $apache_values == undef {
+  $apache_values = $yaml_values['apache']
+}
+
+include puphpet::params
+
+$webroot_location = $puphpet::params::apache_webroot_location
+
+exec { "exec mkdir -p ${webroot_location}":
+  command => "mkdir -p ${webroot_location}",
+  onlyif  => "test -d ${webroot_location}",
+}
+
+if ! defined(File[$webroot_location]) {
+  file { $webroot_location:
+    ensure  => directory,
+    group   => 'www-data',
+    mode    => 0775,
+    require => [
+      Exec["exec mkdir -p ${webroot_location}"],
+      Group['www-data']
+    ]
+  }
+}
+
+class { 'apache':
+  user          => $apache_values['user'],
+  group         => $apache_values['group'],
+  default_vhost => $apache_values['default_vhost'],
+  mpm_module    => $apache_values['mpm_module'],
+  manage_user   => false,
+  manage_group  => false
+}
+
+if $::osfamily == 'debian' {
+  case $apache_values['mpm_module'] {
+    'prefork': { ensure_packages( ['apache2-mpm-prefork'] ) }
+    'worker':  { ensure_packages( ['apache2-mpm-worker'] ) }
+    'event':   { ensure_packages( ['apache2-mpm-event'] ) }
+  }
+} elsif $::osfamily == 'redhat' and ! defined(Iptables::Allow['tcp/80']) {
+  iptables::allow { 'tcp/80':
+    port     => '80',
+    protocol => 'tcp'
+  }
+}
+
+create_resources(apache::vhost, $apache_values['vhosts'])
+
+define apache_mod {
+  if ! defined(Class["apache::mod::${name}"]) {
+    class { "apache::mod::${name}": }
+  }
+}
+
+if count($apache_values['modules']) > 0 {
+  apache_mod { $apache_values['modules']: }
+}
+
+## 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) {
+  include apache::params
+
+  $php_webserver_service = 'httpd'
+  $php_webserver_user = $apache::params::user
+
+  class { 'php':
+    service => $php_webserver_service
+  }
+} elsif is_hash($nginx_values) {
+  include nginx::params
+
+  $php_webserver_service = "${php_prefix}fpm"
+  $php_webserver_user = $nginx::params::nx_daemon_user
+
+  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
+    }
+  }
+
+  if $php_values['ini']['session.save_path'] != undef {
+    exec {"mkdir -p ${php_values['ini']['session.save_path']}":
+      onlyif  => "test ! -d ${php_values['ini']['session.save_path']}",
+    }
+
+    file { $php_values['ini']['session.save_path']:
+      ensure  => directory,
+      group   => 'www-data',
+      mode    => 0775,
+      require => Exec["mkdir -p ${php_values['ini']['session.save_path']}"]
+    }
+  }
+}
+
+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 Xhprof manifest
+
+if $xhprof_values == undef {
+  $xhprof_values = hiera('xhprof', false)
+}
+
+if is_hash($xhprof_values) and $xhprof_values['install'] == 1 {
+  $xhprofPath = $xhprof_values['location']
+
+  php::pecl::module { 'xhprof':
+    use_package     => false,
+    preferred_state => 'beta',
+  }
+
+  exec { 'delete-xhprof-path-if-not-git-repo':
+    command => "rm -rf ${xhprofPath}",
+    onlyif => "test ! -d ${xhprofPath}/.git"
+  }
+
+  vcsrepo { $xhprofPath:
+    ensure   => present,
+    provider => git,
+    source   => 'https://github.com/facebook/xhprof.git',
+    require  => Exec['delete-xhprof-path-if-not-git-repo']
+  }
+
+  file { "${xhprofPath}/xhprof_html":
+    ensure  => directory,
+    mode    => 0775,
+    require => Vcsrepo[$xhprofPath]
+  }
+
+  composer::exec { 'xhprof-composer-run':
+    cmd     => 'install',
+    cwd     => $xhprofPath,
+    require => [
+      Class['composer'],
+      File["${xhprofPath}/xhprof_html"]
+    ]
+  }
+}
+
+## Begin MySQL manifest
+
+if $mysql_values == undef {
+  $mysql_values = hiera('mysql', false)
+}
+
+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)
+}
+
+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,
+  }
+}
+
+if $mysql_values['phpmyadmin'] == 1 and is_hash($php_values) {
+  if $::osfamily == 'debian' {
+    if $::operatingsystem == 'ubuntu' {
+      apt::key { '80E7349A06ED541C': }
+      apt::ppa { 'ppa:nijel/phpmyadmin': require => Apt::Key['80E7349A06ED541C'] }
+    }
+
+    $phpMyAdmin_package = 'phpmyadmin'
+    $phpMyAdmin_folder = 'phpmyadmin'
+  } elsif $::osfamily == 'redhat' {
+    $phpMyAdmin_package = 'phpMyAdmin.noarch'
+    $phpMyAdmin_folder = 'phpMyAdmin'
+  }
+
+  if ! defined(Package[$phpMyAdmin_package]) {
+    package { $phpMyAdmin_package:
+      require => Class['mysql::server']
+    }
+  }
+
+  include puphpet::params
+
+  if is_hash($apache_values) {
+    $mysql_webroot_location = $puphpet::params::apache_webroot_location
+  } elsif is_hash($nginx_values) {
+    $mysql_webroot_location = $puphpet::params::nginx_webroot_location
+
+    mysql_nginx_default_conf { 'override_default_conf':
+      webroot => $mysql_webroot_location
+    }
+  }
+
+  file { "${mysql_webroot_location}/phpmyadmin":
+    target  => "/usr/share/${phpMyAdmin_folder}",
+    ensure  => link,
+    replace => 'no',
+    require => [
+      Package[$phpMyAdmin_package],
+      File[$mysql_webroot_location]
+    ]
+  }
+}
+
+define mysql_nginx_default_conf (
+  $webroot
+) {
+  if $php5_fpm_sock == undef {
+    $php5_fpm_sock = '/var/run/php5-fpm.sock'
+  }
+
+  if $fastcgi_pass == undef {
+    $fastcgi_pass = $php_values['version'] ? {
+      undef   => null,
+      '53'    => '127.0.0.1:9000',
+      default => "unix:${php5_fpm_sock}"
+    }
+  }
+
+  class { 'puphpet::nginx':
+    fastcgi_pass => $fastcgi_pass,
+    notify       => Class['nginx::service'],
+  }
+}
+
+# tine20 manifest
+
+if $tine20_values == undef {
+  $tine20_values = loadyaml('/vagrant/puppet/hieradata/tine20.yaml')
+}
+
+mysql::db { $tine20_values['database']['name']:
+    user     => $tine20_values['database']['user'],
+    password => $tine20_values['database']['password'],
+    host     => $tine20_values['database']['host'],
+    grant    => ['ALL'],
+#    sql      => $sql_file,
+}
+  
+file { "config.inc.php":
+  path    => "/var/www/config.inc.php",
+  ensure  => present,
+  owner   => 'root',
+  group   => 'root',
+  mode    => '0644',
+  content => "<?php return array(
+    'database' => array(
+        'host'          => '${tine20_values['database']['host']}',
+        'dbname'        => '${tine20_values['database']['name']}',
+        'username'      => '${tine20_values['database']['user']}',
+        'password'      => '${tine20_values['database']['password']}',
+        'adapter'       => 'pdo_mysql',
+        'tableprefix'   => 'tine20_',
+    ),
+    'setupuser' => array(
+        'username'      => '${tine20_values['setupuser']['user']}',
+        'password'      => '${tine20_values['setupuser']['password']}' 
+    ),
+    
+    'caching' => array (
+        'active' => true,
+        'path' => '/tmp',
+        'lifetime' => 3600,
+    ),
+    
+    'logger' => array (
+        'active' => true,
+        'filename' => '/tmp/tine20.log',
+        'priority' => '7',
+    ),
+  );"
+}
+
+# coposer install
+composer::exec { 'tine20-composer-run':
+  cmd     => 'install',
+  cwd     => '/var/www/',
+  dev     => true,
+}
+# phing install
+file { "install.properties":
+  path    => "/var/www/install.properties",
+  ensure  => present,
+  owner   => 'root',
+  group   => 'root',
+  mode    => '0644',
+  content => "adminLoginName=${tine20_values['initialuser']['user']}
+adminPassword=${tine20_values['initialuser']['password']}
+adminEmailAddress=${tine20_values['initialuser']['email']}
+#authentication=
+#accounts=
+#imap=
+#smtp="
+}
+
+exec { 'phing-tine-install':
+  cwd     => "/var/www/",
+  command => "sudo sudo -u www-data /var/www/vendor/bin/phing tine-install",
+  require => [
+    File['/var/www/install.properties']
+  ]
+}
diff --git a/scripts/vagrant/shell/initial-setup.sh b/scripts/vagrant/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/scripts/vagrant/shell/librarian-puppet-vagrant.sh b/scripts/vagrant/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/scripts/vagrant/shell/os-detect.sh b/scripts/vagrant/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/scripts/vagrant/shell/self-promotion.txt b/scripts/vagrant/shell/self-promotion.txt
new file mode 100644 (file)
index 0000000..f474331
--- /dev/null
@@ -0,0 +1,7 @@
+
+ ____        ____  _   _ ____      _      generated using
+|  _ \ _   _|  _ \| | | |  _ \ ___| |_   ___ ___  _ __ ___
+| |_) | | | | |_) | |_| | |_) / _ \ __| / __/ _ \| '_ ` _ \
+|  __/| |_| |  __/|  _  |  __/  __/ |_ | (_| (_) | | | | | |
+|_|    \__,_|_|   |_| |_|_|   \___|\__(_)___\___/|_| |_| |_|
+
diff --git a/scripts/vagrant/shell/update-puppet.sh b/scripts/vagrant/shell/update-puppet.sh
new file mode 100644 (file)
index 0000000..128707c
--- /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 http://apt.puppetlabs.com/puppetlabs-release-${CODENAME}.deb"
+        wget --quiet --tries=5 --timeout=10 -O "/.puphpet-stuff/puppetlabs-release-${CODENAME}.deb" "http://apt.puppetlabs.com/puppetlabs-release-${CODENAME}.deb"
+        echo "Finished downloading http://apt.puppetlabs.com/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