Files
DRBv3/client/modules/selfUpdater.mjs
Logan Cusano 956dc89107 Adding functional usage of client self updater #10
- Added update command to the server
- Server can request nodes update
- Nodes have an 'endpoint' for updating
- Fixes to the install script
2024-03-03 20:49:29 -05:00

41 lines
1.2 KiB
JavaScript

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();
return true
} else {
console.log('The application is up to date.');
return false
}
} 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');
}