- name: Setup gpg key
  apt_key:
    url: https://downloads.lux.network/node.gpg.key
    state: present

- name: Setup node repo
  apt_repository:
    repo: deb https://downloads.lux.network/apt jammy main
    state: present

- name: Setup golang repo
  apt_repository:
    repo: ppa:longsleep/golang-backports
    state: present

- name: Install go
  apt:
    name: golang
    state: latest

- name: Update git clone
  git:
    repo: "{{ repo_url }}"
    dest: "{{ repo_folder }}"
    version: "{{ tag }}"
    update: yes
    force: yes

- name: Setup systemd
  template:
    src: templates/node.service.j2
    dest: /etc/systemd/system/node.service
    mode: 0755

- name: Create Lux user
  user:
    name: "{{ lux_user }}"
    shell: /bin/bash
    uid: "{{ lux_uid }}"
    group: "{{ lux_group }}"

- name: Create Lux config dir
  file:
    path: /etc/node
    owner: "{{ lux_user }}"
    group: "{{ lux_group }}"
    state: directory

- name: Create Lux log dir
  file:
    path: "{{ log_dir }}"
    owner: "{{ lux_user }}"
    group: "{{ lux_group }}"
    state: directory

- name: Create Lux database dir
  file:
    path: "{{ db_dir }}"
    owner: "{{ lux_user }}"
    group: "{{ lux_group }}"
    state: directory

- name: Build node
  command: ./scripts/build.sh
  args:
    chdir: "{{ repo_folder }}"

- name: Copy node binaries to the correct location
  command: cp build/luxd /usr/local/bin/luxd
  args:
    chdir: "{{ repo_folder }}"

- name: Configure Lux
  template:
    src: templates/conf.json.j2
    dest: /etc/node/conf.json
    mode: 0644

- name: Enable Lux
  systemd:
    name: node
    enabled: yes
