#!/bin/sh # To run from Internet: # sudo sh -c "$(curl -s http://apps.control2net.com/apt/install-conectric-gateway)" # Doc: https://github.com/Conectric/node-gateway echo "Check Node.js" nodejs=$(nodejs --version 2>&1 | grep v) if [ -z "$nodejs" ]; then echo "Install Node.js first. Instructions:" echo " sudo su" echo " curl -sL https://deb.nodesource.com/setup_10.x | bash -" echo " apt-get install -y nodejs" exit 0 fi DIRECTORY="/home/pi/node-gateway" if [ ! -d "$DIRECTORY" ]; then echo "Install Conectric gateway from Internet..." cd /home/pi sudo -u pi git clone https://github.com/Conectric/node-gateway.git cd node-gateway sudo -u pi npm install echo "Update @goiot/goiot package..." sudo -u pi npm update @goiot/goiot else echo "..." fi FILE="/etc/systemd/system/node-gateway.service" if [ ! -f "$FILE" ]; then echo "Setup service..." cd /etc/systemd/system sudo touch node-gateway.service echo "[Unit]" >> node-gateway.service echo "Description=Node Gateway Service" >> node-gateway.service echo "After=rc-local.service" >> node-gateway.service echo "" >> node-gateway.service echo "[Service]" >> node-gateway.service echo "WorkingDirectory=/home/pi/node-gateway" >> node-gateway.service echo "ExecStart=/usr/bin/npm start" >> node-gateway.service echo "Restart=on-failure" >> node-gateway.service echo "" >> node-gateway.service echo "[Install]" >> node-gateway.service echo "WantedBy=multi-user.target" >> node-gateway.service sudo systemctl daemon-reload fi echo "Finished." echo "Use these commands to control the service:" echo " sudo systemctl status node-gateway.service (show service status)" echo " sudo systemctl start node-gateway.service (start the service)" echo " sudo systemctl stop node-gateway.service (stop the service)" echo " sudo systemctl restart node-gateway.service (restart the service)" echo " sudo systemctl enable node-gateway.service (service starts after reboot)" echo " sudo systemctl disable node-gateway.service (service does not start after reboot)" echo " journalctl -f -u node-gateway.service (show real-time log)"