---
# Install base packages
- name: Install necessary packages
  become: yes
  become_method: su
  become_user: root
  apt:
    name:
      - ack
      - black  # code formatting
      - feh  # set background
      - fish
      - fonts-roboto
      - fzf
      - htop
      - hsetroot
      - ispell
      - i3
      - i3lock-fancy
      - keychain
      - ncal
      - pass
      - python3-pylint-common
      - pulseaudio-utils  # pactl volume control
      - rofi  # dmenu replacement
      - scrot  # screenshot
      - tmux
      - vim
    state: present
    cache_valid_time: 3600


- name: Remove old backup
  file:
    path: '{{ home }}/tmp/dotfiles_backup'
    state: absent
- name: Create new backup dir
  file:
    path: '{{ home }}/tmp/dotfiles_backup'
    state: directory
    mode: 0755

- name: Backup stuff
  copy:
    src: '{{ item }}'
    dest: '{{ home }}/tmp/dotfiles_backup'
    remote_src: True  # copy the folder from the host instead of ansible
    mode: 0755
  ignore_errors: yes
  loop:
    # dirs (without trailing '/' copies the whole dir)
    - '{{ home }}/.config/fish'
    # files
    - '{{ home }}/.tmux.conf'
    - '{{ home }}/.vimrc'
    - '{{ home }}/.ssh/config'
    - '{{ home }}/.config/i3/config'
    - '{{ home }}/.config/i3status/config'
    - '{{ home }}/.config/rofi/config'
    - '{{ home }}/.gitconfig'
    - '{{ home }}/.gnupg/gpg-agent.conf'

- name: Make sure folders exist
  file:
    path: '{{ item }}'
    state: directory
    mode: 0755
  loop:
    - '{{ home }}/.config/i3/'
    - '{{ home }}/.config/i3status/'
    - '{{ home }}/.config/rofi/'
    - '{{ home }}/.ssh/'
    - '{{ home }}/pictures/shots/'
    - '{{ home }}/.gnupg/'

- name: Link files
  file:
    src: '{{ item.src }}'
    dest: '{{ item.dest }}'
    state: link
    force: True
  loop:
    - src: '{{ files_dir }}/vimrc'
      dest: '{{ home }}/.vimrc'
    - src: '{{ files_dir }}/i3_config'
      dest: '{{ home }}/.config/i3/config'
    - src: '{{ files_dir }}/i3status_config'
      dest: '{{ home }}/.config/i3status/config'
    - src: '{{ files_dir }}/rofi_config'
      dest: '{{ home }}/.config/rofi/config.rasi'
    - src: '{{ files_dir }}/tmux.conf'
      dest: '{{ home }}/.tmux.conf'
    - src: '{{ files_dir }}/ssh_config'
      dest: '{{ home }}/.ssh/config'
    - src: '{{ files_dir }}/fish'
      dest: '{{ home }}/.config/fish'
    - src: '{{ files_dir }}/wallpaper'
      dest: '{{ home }}/pictures/wallpaper'
    - src: '{{ files_dir }}/gitconfig'
      dest: '{{ home }}/.gitconfig'
    - src: '{{ files_dir }}/gpg-agent.conf'
      dest: '{{ home }}/.gnupg/gpg-agent.conf'
