---
- name: install dwm with my patches
  community.general.pacman:
    name:
      - adwaita-icon-theme
      - arc-gtk-theme
      - arc-icon-theme
      - autorandr
      - awesome-terminal-fonts
      - bitwarden-cli
      - capitaine-cursors
      - dialog
      - dunst
      - earlyoom
      - feh
      - gnome-themes-extra
      - gtk-engine-murrine
      - gvfs
      - gvfs-mtp
      - libadwaita
      - libnotify
      - libxkbcommon
      - lxappearance
      - noto-fonts-emoji
      - pass
      - pcmanfm
      - powerline-fonts
      - profile-sync-daemon
      - rofi
      - ttc-iosevka
      - ttf-dejavu
      - ttf-droid
      - ttf-nerd-fonts-symbols
      - unclutter
      - pamixer
      - pipewire
      - pipewire-pulse
      - python-tldextract
      - wireplumber
      - wireguard-tools
      - xclip
      - xdg-user-dirs
      - xss-lock
      - yt-dlp
    state: present

- name: checkout dwm repo
  ansible.builtin.git:
    repo: 'https://gitlab.com/dbrw/dwm.git'
    dest: /tmp/dwm
    version: dhm-v2

- name: Copy dwm config.h
  ansible.builtin.copy:
    src: dwm.config.h
    dest: /tmp/dwm/config.h

- name: Build dwm
  community.general.make:
    chdir: /tmp/dwm

- name: Run 'install' dwm as root
  community.general.make:
    chdir: /tmp/dwm
    target: install
  become: yes

- name: checkout st repo
  ansible.builtin.git:
    repo: 'https://gitlab.com/dbrw/st.git'
    dest: /tmp/st
    version: dhm-custom

- name: Build st
  community.general.make:
    chdir: /tmp/st

- name: Run 'install' st as root
  community.general.make:
    chdir: /tmp/st
    target: install
  become: yes

- name: checkout slock repo
  ansible.builtin.git:
    repo: 'https://gitlab.com/dbrw/slock.git'
    dest: /tmp/slock
    version: dhm-custom

- name: Build slock
  community.general.make:
    chdir: /tmp/slock

- name: Run 'install' slock as root
  community.general.make:
    chdir: /tmp/slock
    target: install
  become: yes

- name: Set suid and guid for slock
  ansible.builtin.command: chmod u+s,g+s /usr/local/bin/slock

- name: checkout slstatus repo
  ansible.builtin.git:
    repo: 'https://gitlab.com/dbrw/slstatus.git'
    dest: /tmp/slstatus
    version: dhm-custom

- name: Build slstatus
  community.general.make:
    chdir: /tmp/slstatus

- name: Run 'install' slstatus as root
  community.general.make:
    chdir: /tmp/slstatus
    target: install
  become: yes

- name: Copy configuration files
  ansible.builtin.copy:
    src: 'user_home/{{ item }}'
    dest: /home/{{ username }}/
    mode: 'preserve'
    group: '{{ username }}'
    owner: '{{ username }}'
  with_items:
    - .config
    - .local
    - .xinitrc
    - .gtkrc-2.0
    - .Xresources
    - .Xresources.d
    - .tmux.conf
    - .zlogin

- name: Install TPM
  become_user: "{{ username }}"
  ansible.builtin.git:
    repo: 'https://github.com/tmux-plugins/tpm'
    dest: /home/{{ username }}/.tmux/plugins/tpm

- name: Install TPM plugins
  become_user: "{{ username }}"
  ansible.builtin.command: /home/{{ username }}/.tmux/plugins/tpm/bin/install_plugins

- name: Copy ssh config
  ansible.builtin.copy:
    src: user_home/.ssh
    dest: /home/{{ username }}
    force: no
    mode: 'preserve'
    group: '{{ username }}'
    owner: '{{ username }}'

- name: Enable autorandr service
  become: true
  ansible.builtin.systemd:
    daemon_reload: true
    name: autorandr
    enabled: true

- name: Enable fstrim timer
  become: true
  ansible.builtin.systemd:
    daemon_reload: true
    name: fstrim.timer
    enabled: true

- name: Enable earlyoom service
  become: true
  ansible.builtin.systemd:
    daemon_reload: true
    name: earlyoom
    enabled: true

- getent: database=passwd key={{username}}

- name: Enabling user services
  become: yes
  become_user: "{{ username }}"
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ ansible_facts['getent_passwd'][username][1] }}"
  ansible.builtin.systemd:
    scope: user
    daemon_reload: yes
    enabled: yes
    name: "{{ item }}"
  with_items:
    - slstatus.service
    - dunst.service
    - ssh-agent.service
    - xrdb.service
    - dwm.service
    - psd.service
