Starting to work on instal and update function #10

- Added a new self updater module that will update the git repo and restart the node service
- Added a setup script that will install and setup both OP25 and the DRB node
- Updated service names
This commit is contained in:
Logan Cusano
2024-03-03 19:41:06 -05:00
parent 54a6d544e4
commit 1395130d6d
4 changed files with 241 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
import simpleGit from 'simple-git';
import { restartService } from './serviceHandler.mjs'
const git = simpleGit();
// Function to check for updates
export const checkForUpdates = async () => {
try {
// Fetch remote changes
await git.fetch();
// Get the latest commit hash
const latestCommitHash = await git.revparse(['@{u}']);
// Compare with the local commit hash
const localCommitHash = await git.revparse(['HEAD']);
if (latestCommitHash !== localCommitHash) {
console.log('An update is available. Updating...');
// Pull the latest changes from the remote repository
await git.pull();
console.log('Update completed successfully. Restarting the application...');
// Restart the application to apply the updates
restartApplication();
} else {
console.log('The application is up to date.');
}
} catch (error) {
console.error('Error checking for updates:', error);
}
}
// Function to restart the application
const restartApplication = () => {
console.log('Restarting the application...');
restartService('discord-radio-bot');
}