<commit_before>{%- from "diaspora/map.jinja" import diaspora with context %}
{%- set environment = diaspora.configuration.server.rails_environment %}

include:
  - diaspora.config

diaspora_dependencies:
  pkg.installed:
    - pkgs: {{ diaspora.dependencies|json }}
    - require:
      - pkg: diaspora_database_dependency

diaspora_database_dependency:
  pkg.installed:
  {%- if diaspora.database.type == "mysql" %}
    - name: {{ diaspora.mysql_package }}
  {%- else %}
    - name: {{ diaspora.postgresql_package }}
  {%- endif %}

{%- if diaspora.install_redis %}
redis_package:
  pkg.installed:
    - name: {{ diaspora.redis_package }}

redis_service:
  service.running:
    - name: {{ diaspora.redis_service }}
{%- endif %}

diaspora_user:
  user.present:
    - name: {{ diaspora.user.username }}
  {%- if 'shell' in diaspora.user %}
    - shell: {{ diaspora.user.shell }}
  {%- endif %}
  {%- if 'home' in diaspora.user %}
    - home: {{ diaspora.user.home }}
  {%- endif %}

diaspora_rvm_gpg_key:
  cmd.run:
    - name: gpg2 --keyserver hkp://keys.gnupg.net --recv-keys <KEY>
    - unless: gpg --list-keys <KEY>
    - runas: {{ diaspora.user.username }}
    - require:
      - user: diaspora_user

diaspora_rvm_ruby:
  rvm.installed:
    - name: ruby-{{ diaspora.ruby_version }}
    - user: {{ diaspora.user.username }}<commit_msg>Use 'gpg' instead of 'gpg2'<commit_after>{%- from "diaspora/map.jinja" import diaspora with context %}
{%- set environment = diaspora.configuration.server.rails_environment %}

include:
  - diaspora.config

diaspora_dependencies:
  pkg.installed:
    - pkgs: {{ diaspora.dependencies|json }}
    - require:
      - pkg: diaspora_database_dependency

diaspora_database_dependency:
  pkg.installed:
  {%- if diaspora.database.type == "mysql" %}
    - name: {{ diaspora.mysql_package }}
  {%- else %}
    - name: {{ diaspora.postgresql_package }}
  {%- endif %}

{%- if diaspora.install_redis %}
redis_package:
  pkg.installed:
    - name: {{ diaspora.redis_package }}

redis_service:
  service.running:
    - name: {{ diaspora.redis_service }}
{%- endif %}

diaspora_user:
  user.present:
    - name: {{ diaspora.user.username }}
  {%- if 'shell' in diaspora.user %}
    - shell: {{ diaspora.user.shell }}
  {%- endif %}
  {%- if 'home' in diaspora.user %}
    - home: {{ diaspora.user.home }}
  {%- endif %}

diaspora_rvm_gpg_key:
  cmd.run:
    - name: gpg --keyserver hkp://keys.gnupg.net --recv-keys <KEY>
    - unless: gpg --list-keys <KEY>
    - runas: {{ diaspora.user.username }}
    - require:
      - user: diaspora_user

diaspora_rvm_ruby:
  rvm.installed:
    - name: ruby-{{ diaspora.ruby_version }}
    - user: {{ diaspora.user.username }}