---
- name: Install packages
  yum: name={{ gitea_packages }}
  tags: gitea

- name: Download gitea binary
  get_url:
    url: "{{ gitea_bin_url }}"
    dest: "{{ gitea_root_dir }}/bin/gitea"
    checksum: "sha256:{{ gitea_bin_sha256 }}"
    mode: 755
  when: gitea_install_mode != 'none'
  notify: restart gitea
  tags: gitea

- name: Deploy gitea service unit
  template: src=gitea.service.j2 dest=/etc/systemd/system/gitea.service
  register: gitea_unit
  notify: restart gitea
  tags: gitea

- name: Reload systemd
  systemd: daemon_reload=True
  when: gitea_unit.changed
  tags: gitea

  # Create MySQL database
- import_tasks: ../includes/webapps_create_mysql_db.yml
  vars:
    - db_name: "{{ gitea_db_name }}"
    - db_user: "{{ gitea_db_user }}"
    - db_server: "{{ gitea_db_server }}"
    - db_pass: "{{ gitea_db_pass }}"
  tags: gitea

- name: Deploy pre/post backup scripts
  template: src={{ item }}_backup.sh.j2 dest=/etc/backup/{{ item }}.d/gitea.sh mode=0750
  with_items:
    - pre
    - post
  tags: gitea

- name: Deploy permission script
  template: src=perms.sh.j2 dest={{ gitea_root_dir }}/perms.sh mode=755
  tags: gitea

- name: Set correct SELinux context
  sefcontext:
    target: "{{ gitea_root_dir }}/.ssh(/.*)?"
    setype: ssh_home_t
    state: present
  when: ansible_selinux.status == 'enabled'
  tags: gitea
