# Copyright (c) Ontic. (http://www.ontic.com.au). All rights reserved.
# See the COPYING file bundled with this package for license details.

---

- name: 'Fonts | Configure shared font directories.'
  become: yes
  file:
    path: '/usr/local/share/fonts/{{ item.type }}/{{ item.dest | dirname }}'
    state: 'directory'
    group: 'root'
    owner: 'root'
    mode: '0755'
  with_items: '{{ fonts_shared }}'
  when: 'fonts_shared | default(None) != None'

- name: 'Fonts | Configure shared fonts.'
  become: yes
  copy:
    src: '{{ item.src }}'
    dest: '/usr/local/share/fonts/{{ item.type }}/{{ item.dest }}'
    owner: 'root'
    group: 'root'
    mode: '0644'
  register: 'fonts_shared_installed'
  notify: 'rebuild fonts cache'
  with_items: '{{ fonts_shared }}'
  when: 'fonts_shared | default(None) != None'

- name: 'Fonts | Configure user font directories.'
  become: yes
  file:
    path: '/home/{{ item.name }}/.fonts/{{ item.type }}/{{ item.dest | dirname }}'
    state: 'directory'
    owner: '{{ item.owner | default(item.name) }}'
    group: '{{ item.group | default(omit) }}'
    mode: '0755'
  with_items: '{{ fonts_user }}'
  when: 'fonts_user | default(None) != None'

- name: 'Fonts | Configure user fonts.'
  become: yes
  copy:
    src: '{{ item.src }}'
    dest: '/home/{{ item.name }}/.fonts/{{ item.type }}/{{ item.dest }}'
    owner: '{{ item.owner | default(item.name) }}'
    group: '{{ item.group | default(omit) }}'
    mode: '{{ item.mode | default(omit) }}'
  register: 'fonts_user_installed'
  notify: 'rebuild fonts cache'
  with_items: '{{ fonts_user }}'
  when: 'fonts_user | default(None) != None'