#!/bin/sh # To run from Internet: # sudo sh -c "$(curl -s https://apps.control2net.com/apt/install-dingo-lorawan-server)" 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 -fsSL https://deb.nodesource.com/setup_16.x | bash -" #echo " apt-get install -y nodejs" echo "Install Node.js 16.x" curl -fsSL https://deb.nodesource.com/setup_16.x | bash - apt-get install -y nodejs #exit 0 else nv=$(echo $nodejs | tr -d "v" | tr -d ".") if [ "$nv" -lt "16150" ]; then echo "Install Node.js 16.x" curl -fsSL https://deb.nodesource.com/setup_16.x | bash - apt-get install -y nodejs fi fi FILE="/opt/dingo-lorawan-server/dingo-lorawan-server.js" if [ -f "$FILE" ]; then echo "DINGO LORAWAN SERVER IS ALREADY INSTALLED." echo "Doing upgrade..." echo "Stop service..." sudo systemctl stop dingo-lorawan-server.service echo "Take backup..." DIRECTORYBACKUP="/opt/GoIoT/backup" if [ ! -d "$DIRECTORYBACKUP" ]; then mkdir /opt/GoIoT/backup sudo chmod 0755 /opt/GoIoT/backup fi DIRECTORYTMPBACKUP="/opt/GoIoT/tmpdingolorawanserver" if [ ! -d "$DIRECTORYTMPBACKUP" ]; then mkdir /opt/GoIoT/tmpdingolorawanserver sudo chmod 0755 /opt/GoIoT/tmpdingolorawanserver fi echo "Uninstall obsolete modules..." cd /opt/dingo-lorawan-server npm uninstall @goiot/goiot cp -p /opt/dingo-lorawan-server/server.json /opt/GoIoT/tmpdingolorawanserver/ cp -p /opt/dingo-lorawan-server/server.json /opt/GoIoT/backup/server.json.`date +%Y%m%d%H%M%S` cp -p /opt/dingo-lorawan-server/db/dingo-lorawan-server.db /opt/GoIoT/tmpdingolorawanserver/ cp -p /opt/dingo-lorawan-server/db/dingo-lorawan-server.db /opt/GoIoT/backup/dingo-lorawan-server.db.`date +%Y%m%d%H%M%S` echo "Upgrade DINGO LoRaWAN Server..." cd /opt/GoIoT/tmpdingolorawanserver wget https://apps.control2net.com/apt/lorawan/dingo-lorawan-server-1.0.0.zip sudo unzip -o -q dingo-lorawan-server-1.0.0.zip -d /opt echo "Return the files that were backed-up..." cp -p /opt/GoIoT/tmpdingolorawanserver/server.json /opt/dingo-lorawan-server/ cp -p /opt/GoIoT/tmpdingolorawanserver/dingo-lorawan-server.db /opt/dingo-lorawan-server/db/ echo "Install modules..." cd /opt/dingo-lorawan-server npm install node-machine-id npm install enum npm install neo-blessed npm install blessed npm install blessed-contrib npm i --save gps-time npm install json-multi-parse echo "Delete old obfusucated files on wrong location by Danjal" rm /opt/dingo-lorawan-server/dev-time.js rm /opt/dingo-lorawan-server/dev-status.js rm /opt/dingo-lorawan-server/end-device_trans_params.js rm /opt/dingo-lorawan-server/link-check.js rm /opt/dingo-lorawan-server/link-adr.js rm /opt/dingo-lorawan-server/service_adr.js rm /opt/dingo-lorawan-server/WorkStuff.js rm /opt/dingo-lorawan-server/downlinks.js rm /opt/dingo-lorawan-server/downlink.js rm /opt/dingo-lorawan-server/entity.js rm /opt/dingo-lorawan-server/get_uid.js echo "Delete obsolete stuff" rm -r /opt/dingo-lorawan-server/node_modules/@goiot/ echo "Restart DINGO-Stack will take care of LoRaWAN Server db-updates if any" sudo systemctl restart dingo.service # 221220 TJ, Commented out. LoraWan server has to be manually restarted # This is done to be sure all DB-updates from the command above are finished #echo "Start service..." #sudo systemctl restart dingo-lorawan-server.service echo "Clean up..." sudo rm -r /opt/GoIoT/tmpdingolorawanserver #exit 0 else DIRECTORYTMPBACKUP="/opt/GoIoT/tmpdingolorawanserver" if [ ! -d "$DIRECTORYTMPBACKUP" ]; then mkdir /opt/GoIoT/tmpdingolorawanserver sudo chmod 0755 /opt/GoIoT/tmpdingolorawanserver fi echo "Installing DINGO LoRaWAN Server..." cd /opt/GoIoT/tmpdingolorawanserver wget https://apps.control2net.com/apt/lorawan/dingo-lorawan-server-1.0.0.zip sudo unzip -q dingo-lorawan-server-1.0.0.zip -d /opt #echo "Setup shortcuts..." #cd /opt/dingo-lorawan-server/bin #sudo cp -p dingo-lorawan-server* /opt/GoIoT/DinGo/bin echo "Setup service..." cd /opt/dingo-lorawan-server/systemd sudo cp -p dingo-lorawan-server.service /lib/systemd/system sudo systemctl daemon-reload echo "Install modules..." cd /opt/dingo-lorawan-server npm install node-machine-id npm install enum npm install neo-blessed npm install blessed npm install blessed-contrib npm i --save gps-time npm install json-multi-parse echo "Start service...." sudo systemctl enable dingo-lorawan-server.service sudo systemctl restart dingo-lorawan-server.service echo "Clean up..." sudo rm -r /opt/GoIoT/tmpdingolorawanserver echo "Delete obsolete stuff" rm -r /opt/dingo-lorawan-server/node_modules/@goiot/ fi sudo grep -q -F 'LORAWAN_SERVER_DB=' /etc/profile.d/dingo.sh || sudo sed -i -e '$i \# Refers to the DINGO LORAWAN SERVER Database location.\nexport LORAWAN_SERVER_DB="/opt/dingo-lorawan-server/db/"\n' /etc/profile.d/dingo.sh sudo grep -q -F 'LORAWAN_SERVER_HOME=' /etc/profile.d/dingo.sh || sudo sed -i -e '$i \# Refers to the DINGO LORAWAN SERVER home directory.\nexport LORAWAN_SERVER_HOME="/opt/dingo-lorawan-server/"\n' /etc/profile.d/dingo.sh sudo grep -q -F 'LORAWAN_SERVER_SERVICE=' /etc/profile.d/dingo.sh || sudo sed -i -e '$i \# Refers to the service that controls the DINGO LORAWAN SERVER\nexport LORAWAN_SERVER_SERVICE="dingo-lorawan-server.service"\n' /etc/profile.d/dingo.sh echo "Finished." echo "Use these commands to control the service:" echo " sudo systemctl status dingo-lorawan-server.service (show service status)" echo " sudo systemctl start dingo-lorawan-server.service (start the service)" echo " sudo systemctl stop dingo-lorawan-server.service (stop the service)" echo " sudo systemctl restart dingo-lorawan-server.service (restart the service)" echo " sudo systemctl enable dingo-lorawan-server.service (service starts after reboot)" echo " sudo systemctl disable dingo-lorawan-server.service (service does not start after reboot)" echo " cd /opt/dingo-lorawan-server && sudo node dingo-lorawan-server.js (start server directly, not as service)" echo " journalctl -f -u dingo-lorawan-server.service (show service log)"