- hosts: localhost
  tasks:

  - name: Create .bash_aliases file
    file: path=/home/{{ ansible_env.USER }}/.bash_aliases state=touch owner={{ ansible_env.USER }} group={{ ansible_env.USER }} mode=0644

  - name: Add aliases to bashrc file
    lineinfile: dest=/home/{{ ansible_env.USER }}/.bash_aliases regexp="{{ item }}" line="{{ item }}" state=present
    with_items:
      - alias gosh="cd ~/work/home/shell"

  - name: Create config dir
    file:
      path: ~/.config
      state: directory
      force: no

  - name: Install Apt Packages
    become: yes
    apt:
      state: present
      name:
        - bluefish
        - docker.io
        - keepassxc
        - retext
        - jq
        - xtightvncviewer
        - meld
        - sublime-text
        - git
        - openjdk-11-jre
        - alsa-utils
        - ffmpeg
        - imagemagick
        - libimage-exiftool-perl
        - ethtool
        - htop
        - wmctrl

#  - name: Install Standard Packages
#    become: yes
#    package:
#      name: caja
#      state: present

  - name: Copy lsetup files
    copy:
      src: ./lsetup.sh
      dest: /home/{{ ansible_env.USER }}/lsetup.sh
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - personal
      - never

  - name: Copy lsetup files
    copy:
      src: ./lsetup.cfg
      dest: /home/{{ ansible_env.USER }}/lsetup.cfg
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0665'
      force: no
    tags:
      - personal
      - never

  - name: Copy lsetup files
    copy:
      src: ./mateterm.lsetup.conf
      dest: /home/{{ ansible_env.USER }}/mateterm.lsetup.conf
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0665'
      force: no
    tags:
      - personal
      - never

  - name: Copy lsetup files
    copy:
      src: ./mlan.lsetup.sh
      dest: /home/{{ ansible_env.USER }}/mlan.lsetup.sh
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - personal
      - never

  - name: Copy lsetup files
    copy:
      src: ./mounts.lsetup.conf
      dest: /home/{{ ansible_env.USER }}/mounts.lsetup.conf
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0665'
      force: no
    tags:
      - personal
      - never

  - name: Create Theme dir
    file:
      path: /home/{{ ansible_env.USER }}/.themes/TheoAppearancePreference
      state: directory
      force: no
    tags:
      - desktop
      - never

  - name: Copy Theme files
    copy:
      src: ./dot_themes/TheoAppearancePreference/index.theme
      dest: /home/{{ ansible_env.USER }}/.themes/TheoAppearancePreference/index.theme
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0665'
      force: no
    tags:
      - desktop
      - never


  - name: Copy Desktop files
    copy:
      src: ./Desktop/org.keepassxc.KeePassXC.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/org.keepassxc.KeePassXC.desktop
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never

  - name: Copy Desktop files
    copy:
      src: ./Desktop/sublime_text.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/sublime_text.desktop
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never

  - name: Copy Desktop files
    copy:
      src: ./Desktop/Terminator.desktop
      dest: /home/{{ ansible_env.USER }}/Desktop/Terminator.desktop
      owner: "{{ ansible_env.USER }}"
      group: "{{ ansible_env.USER }}"
      mode: '0775'
      force: no
    tags:
      - desktop
      - never


# The following is for the WakeOnLan server feature setup
# For clients only the wakeonlan is required, install this one manually if you need it

  - name: Install WOL Apt Packages
    become: yes
    apt:
      state: present
      name:
        - wakeonlan
    tags:
      - wakeonlan
      - never


  - name: Create wakeonlan file
    become: yes
    file: path=/usr/bin/wakewol state=touch owner=root group=root mode=0755
    tags:
      - wakeonlan
      - never

# For the following WOL sections to work you must specify the actual network interface
# eth0 is a good default as it tends to be the right answer, but you might need to change this

  - name: Add ethtool to file
    become: yes
    lineinfile: dest=/usr/bin/wakewol regexp="{{ item }}" line="{{ item }}" state=present
    with_items:
      - ethtool -s eth0 wol g
    tags:
      - wakeonlan
      - never

  - name: Add call to our script
    become: yes
    lineinfile: dest=/etc/network/interfaces regexp="{{ item }}" line="{{ item }}" state=present
    with_items:
      - post-down /usr/bin/wakewol
      - up ethtool -s eth0 wol g
    tags:
      - wakeonlan
      - never
