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:
39
client/modules/selfUpdater.mjs
Normal file
39
client/modules/selfUpdater.mjs
Normal 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');
|
||||
}
|
||||
Reference in New Issue
Block a user