2 Commits

Author SHA1 Message Date
Logan Cusano
3719fce86a Update client package.json 2023-05-27 18:25:12 -04:00
Logan Cusano
ba927bae8c Implement install and update system for the bot
- LINUX OR WINDOW WSL ONLY
2023-05-27 17:00:57 -04:00
6 changed files with 89 additions and 11 deletions

View File

@@ -185,3 +185,10 @@ exports.removePreset = async (req, res) => {
});
}
/**
* Runs the updater service
*/
exports.updateClient = async (req, res) => {
await executeAsyncConsoleCommand("systemctl start RadioNodeUpdater.service");
return res.sendStatus(200);
}

View File

@@ -19,13 +19,7 @@
"morgan": "~1.9.1",
"replace-in-file": "~6.3.5",
"@discordjs/builders": "^1.4.0",
"@discordjs/opus": "^0.9.0",
"@discordjs/rest": "^1.4.0",
"@discordjs/voice": "^0.14.0",
"@mapbox/node-pre-gyp": "^1.0.10",
"discord.js": "^14.7.1",
"node-gyp": "^9.3.0",
"libsodium-wrappers": "^0.7.10",
"naudiodon": "^2.3.6"
"discord.js": "^14.7.1"
}
}

View File

@@ -0,0 +1,7 @@
#!/bin/bash
# This script should be another service on the machine to watch the main script for failures and restart it if there are any
( tail -f -n0 /opt/sdr-scanner/scanner_log & ) | grep -q ": cb transfer status: 1, canceling..."
systemctl restart radioNode.service
echo "Restarted SDR Scanner service"

View File

@@ -2,7 +2,7 @@
const express = require('express');
const router = express.Router();
// Controllers
const {requestCheckIn, getPresets, updatePreset, addNewPreset, removePreset} = require("../controllers/clientController");
const { requestCheckIn, getPresets, updatePreset, addNewPreset, removePreset, updateClient } = require("../controllers/clientController");
/** GET Request a check in from the client
* Queue the client to check in with the server
@@ -45,4 +45,10 @@ router.post('/addPreset', addNewPreset);
router.post('/removePreset', removePreset);
/** POST Update the bot
*
* @param req The request sent from the master
*/
router.post('/updateClient', updateClient);
module.exports = router;

View File

@@ -5,6 +5,16 @@ if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ls -ld $SCRIPT_DIR | awk '{print $3}' >> ./config/installerName
# Setup user for service
useradd -M RadioNode
usermod -s -L RadioNode
# Change the ownership of the directory to the service user
chown RadioNode -R $SCRIPT_DIR
# Check for updates
apt-get update
@@ -26,4 +36,41 @@ pulseaudio
npm i
# Install the python packages needed for the bot
pip install -r
pip install -r
# Setup bot service
echo "[Unit]
Description=Radio Node Service
After=network.target
[Service]
WorkingDirectory=
ExecStart=/usr/bin/node .
Restart=always
RestartDelay=10
User=RadioNode
Environment=DEBUG='server:*'
[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/RadioNode.service
# Setup bot update service
echo "[Unit]
Description=Radio Node Updater Service
After=network.target
[Service]
WorkingDirectory=
ExecStart=/usr/bin/node .
Restart=on-failure
User=RadioNode
Environment=DEBUG='server:*'
[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/RadioNodeUpdater.service
# Enable the service
systemctl enable RadioNode.service
# Start the service
systemctl start RadioNode.service

View File

@@ -1,15 +1,32 @@
#!/bin/bash
# Check if the user is root
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# Sleeping to give the client time to respond to the requester
sleep 5
# Stating Message
echo "<!-- UPDATING ---!>"
# TODO - Add an updater for Stable Diffusion API
# Stop any running service
systemctl stop RadioNode
# Update the git Repo
git fetch -a -p
git pull
installUser=$(cat ./config/installerName)
sudo su -l $installUser -c 'git fetch -a -p'
sudo su -l $installUser -c 'git pull'
# Install any new libraries
npm i
# Start the service
systemctl start RadioNode
# Update complete message
echo "<!--- UPDATE COMPLETE! ---!>"