# 2022-06-08: This file used to be rpi_desk.yml

# 2022-06-09: Crucially, the 3 "dest" dirs (below) exist on all mainline OS's
- name: "Download 3 Node-RED enhancements: Node-RED icon, start menu item, /etc/logrotate.d/nodered"
  get_url:
    url: "{{ item.url }}"
    dest: "{{ item.dest }}"
    force: yes
    timeout: "{{ download_timeout }}"
  with_items:
    - url: https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-icon.svg
      dest: /usr/share/icons/hicolor/scalable/apps/node-red-icon.svg
    - url: https://raw.githubusercontent.com/node-red/linux-installers/master/resources/Node-RED.desktop
      dest: /usr/share/applications/Node-RED.desktop
    - url: https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.rotate
      dest: /etc/logrotate.d/nodered
    # 2022-06-08: New versions above, pasted from https://github.com/node-red/linux-installers/blob/master/deb/update-nodejs-and-nodered
    # - 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'
- name: 'Install 5 executables to /usr/bin: node-red-start, node-red-stop, node-red-restart, node-red-reload, node-red-log'
  get_url:
    url: "{{ item }}"
    dest: /usr/bin
    mode: a+x
    force: yes
    timeout: "{{ download_timeout }}"
  with_items:
    - https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-start
    - https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-stop
    - https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-restart
    - https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-reload
    - https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-log
    # 2022-08-06: New versions above, pasted from https://github.com/node-red/linux-installers/blob/master/deb/update-nodejs-and-nodered
    # - 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

# 2022-06-08 #3245: Raspberry Pi OS recently removed the 'pi' user.  For now,
# until converging on a longer-term strategy, let's comment out both stanzas:

# - 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
