# Finishing puppet-dashboard 2.0 installation
  #
  # $ cd /usr/share/puppet-dashboard
  # $ RAILS_ENV=production bundle exec rake db:setup
  # $ RAILS_ENV=production bundle exec rake db:migrate
  # $ RAILS_ENV=production bundle exec rake assets:precompile

  $install_dir     = '/usr/share/puppet-dashboard'
  $dashboard_user  = 'puppet'
  $dashboard_group = 'puppet'

  file { "${install_dir}/db/schema.rb" :
    ensure  => present,
    owner   => $dashboard_user,
    group   => $dashboard_group,
    replace => false,
    require => Vcsrepo[$install_dir],
  }
  ~>
  file { [
    "${install_dir}/log",
    "${install_dir}/public",
    "${install_dir}/tmp",
    ] :
    ensure  => directory,
    owner   => $dashboard_user,
    group   => $dashboard_group,
  }
  ->
  exec { 'puppet_dashboard rake db:setup':
    cwd         => $install_dir,
    environment => 'RAILS_ENV=production',
    command     => 'bundle exec rake db:setup',
    onlyif      => 'test "Current version: 0" = "$(bundle exec rake db:version)"',
    user        => $dashboard_user,
    logoutput   => 'on_failure',
    returns     => [0, 1],
    require     => [
      Postgresql::Server::Db['puppet_dashboard'],
      Bundler::Install[$install_dir],
      File["${install_dir}/config/database.yml"],
      File["${install_dir}/log"],
    ],
  }
  ->
  exec { 'puppet_dashboard rake db:migrate':
    cwd         => $install_dir,
    environment => 'RAILS_ENV=production',
    command     => 'bundle exec rake db:migrate',
    onlyif      => 'bundle exec rake db:migrate:status |grep "[[:space:]]down[[:space:]]"',
    user        => $dashboard_user,
    logoutput   => 'on_failure',
    require     => [
      Postgresql::Server::Db['puppet_dashboard'],
      Bundler::Install[$install_dir],
      File["${install_dir}/config/database.yml"],
      File["${install_dir}/log"],
    ],
  }
  ->
  exec { 'puppet_dashboard rake assets:precompile':
    cwd         => $install_dir,
    command     => 'bundle exec rake assets:precompile',
    creates     => "${install_dir}/public/assets",
    user        => $dashboard_user,
    logoutput   => 'on_failure',
    require     => [
      Bundler::Install[$install_dir],
      File["${install_dir}/public"],
      File["${install_dir}/tmp"],
    ],
  }