#!/bin/bash

which npm;
if [ $? -ne 0 ]; then
  echo "Please, install NPM first:"
  echo "dnf install nodejs-npm"
  exit 1;
fi;

X[0]="s node-red-node-sqlite"
X[1]="s node-utf-8-validate"
X[2]="s node-bufferutil"
X[3]="s node-serialport"
X[4]="s node-red-contrib-ibm-watson-iot"
X[5]="cd /usr/lib/node_modules/"
X[6]="n @tibbo-tps/gpio"
X[7]="n @tibbo-tps/tibbit-28"
X[8]="n @tibbo-tps/tibbit-30"
X[9]="n @tibbo-tps/tibbit-35"
X[10]="n node-red-dashboard"
X[11]="n node-red-contrib-bigtimer"
X[12]="n node-red-contrib-moment"
#X[13]="s node-red-node-serialport"
X[13]="s node-red-contrib-modbus"
X[14]="s node-red-contrib-modbustcp"
X[15]="n node-red-contrib-esplogin"

for t in "${X[@]}"; do
  Y=( $t )
  if [ "${Y[0]}" == "s" ]; then
    dnf install -y ${Y[1]}
    continue;
  fi;
  if [ "${Y[0]}" == "n" ]; then
    npm install -g ${Y[1]}
    continue;
  fi;
  $t;
done;

echo "----------------------------------------"
echo "Please, restart node-red after modules installation:"
echo "systemctl restart node-red"
