---
- name: Acquiring home of current user
  when: ansible_facts["system"] == "Linux"
  ansible.builtin.shell:
    cmd: "echo ~{{ ansible_user }}"
  register: ansible_user_home
- name: Acquiring current user
  when: ansible_facts["system"] == "Linux"
  ansible.builtin.shell:
    cmd: "echo {{ ansible_user }}"
  register: current_user
- name: Executing shell-scripted installation process for Radicle
  become: true
  become_user: "{{ current_user.stdout }}"
  ansible.builtin.shell:
    cmd: "{{ ansible_user_home.stdout }}/.local/bin/radicle-install.sh"
    creates: "{{ ansible_user_home.stdout }}/.radicle"
  async: 600
  poll: 5
- name: Bootstrapping Radicle
  become: true
  block:
    - name: Linking binaries to directories already in PATH environment variable
      ignore_errors: true
      ansible.builtin.file:
        src: "{{ ansible_user_home.stdout }}/.radicle/bin/{{ item }}"
        dest: "/usr/bin/{{ item }}"
        state: link
      loop:
        - rad
        - radicle-node
        - git-remote-rad
    - name: Create man1 subdirectory for man pages
      ansible.builtin.file:
        path: /usr/share/man/man1
        recurse: true
        owner: root
        group: root
        mode: "644"
        state: directory
    - name: Link manpages to Linux manpage directories
      ignore_errors: true
      ansible.builtin.file:
        src: "{{ ansible_user_home.stdout }}/.radicle/man/man1/{{ item }}.1"
        dest: "/usr/share/man/man1/{{ item }}.1"
        state: link
      loop:
        - rad
        - radicle-node
        - git-remote-rad
        - rad-id
        - rad-patch
# - name: Reboot machine for shell environment change
#   ansible.builtin.reboot:
#     msg: Rebooting machine