- 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
39 lines
1.2 KiB
JavaScript
39 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();
|
|
} 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');
|
|
} |