2024-06-07 22:21:02 -05:00
|
|
|
const fs = require("fs"),
|
2024-06-07 23:06:24 -05:00
|
|
|
path = require("path"),
|
|
|
|
shell = require("shelljs")
|
2024-06-07 22:21:02 -05:00
|
|
|
|
|
|
|
var configsPath = path.join(__dirname, "config")
|
|
|
|
var confPath = path.join(configsPath, "config.json")
|
|
|
|
|
|
|
|
if (!fs.existsSync(configsPath)) {
|
|
|
|
fs.mkdirSync(configsPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fs.existsSync(confPath)) {
|
|
|
|
console.log("It would appear you have not created a config file yet! Generating one now.")
|
|
|
|
fs.cpSync(path.join(__dirname, "defaults/config.json"), confPath)
|
|
|
|
console.log("Done!")
|
2024-06-07 23:06:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var runningPrograms = {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateLoop() {
|
|
|
|
var config = JSON.parse(fs.readFileSync(confPath))
|
|
|
|
|
|
|
|
for (var i = 0; i < config.autoUpdates.length; i++) {
|
|
|
|
var program = config.autoUpdates[i]
|
|
|
|
var pull = shell.exec(`cd ${program.dir} && git pull`)
|
|
|
|
if (!runningPrograms[program.name]) {
|
|
|
|
runningPrograms[program.name] = shell.exec(`cd ${program.dir} && ${program.startCommand}`, { async: true })
|
|
|
|
}
|
|
|
|
if (!pull.stdout.includes("Already up to date.")) {
|
|
|
|
if (runningPrograms[program.name]) {
|
|
|
|
runningPrograms[program.name].kill()
|
|
|
|
}
|
|
|
|
runningPrograms[program.name] = shell.exec(`cd ${program.dir} && ${program.startCommand}`, { async: true })
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
updateLoop()
|
|
|
|
}, config.updateSpeedMinutes * 60 * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateLoop()
|