# TEST UNNEC ICON/MENU FILE PLACEMENT ON RASPIAN LITE TOO !
- name: 'Download/Install 4 useful items for RPi: Node-RED icon, start menu item, /etc/logrotate.d/nodered, tweaked "Pi cpu temperature.json"'
  get_url:
    url: "{{ item.url }}"
    dest: "{{ item.dest }}"
  with_items:
    - url: https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-icon.svg
      dest: /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg
    - url: https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/Node-RED.desktop
      dest: /usr/share/applications/Node-RED.desktop
    - url: https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.rotate
      dest: /etc/logrotate.d/nodered
    - url: 'https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/Pi%20cpu%20temperature.json'
      dest: '/usr/lib/node_modules/node-red-contrib-ibm-watson-iot/examples/Pi cpu temperature.json'

#- name: Replace/Tweak "node-red-contrib-ibm-watson-iot/examples/Pi cpu temperature.json" (rpi)
#  command: 'curl -sL -o /usr/lib/node_modules/node-red-contrib-ibm-watson-iot/examples/Pi\ cpu\ temperature.json https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/Pi%20cpu%20temperature.json'
#  when: nodered_install and internet_available and is_raspbian

- name: 'Download/Install 4 RPi executables to /usr/bin: node-red-start, node-red-stop, node-red-restart, node-red-log'
  get_url:
    url: "{{ item }}"
    dest: /usr/bin
    mode: a+x
  with_items:
    - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start
    - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop
    - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-restart
    - https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-log

- name: Create /home/pi/.node-red/ directory (rpi)
  file:
    path: /home/pi/.node-red
    state: directory
    owner: pi
    group: pi
    mode: 0775

- name: Install /home/pi/.node-red/settings.js from template, with authentication (rpi)
  template:
    src: settings.js.j2
    dest: /home/pi/.node-red/settings.js
    owner: pi
    group: pi
    mode: 0755
