diff --git a/Makefile b/Makefile index e3038d0..1ab4fcc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SPK_NAME = rr-manager SPK_VERS = 2.0 -SPK_REV = 78 +SPK_REV = 79 SPK_ICON = src/rr-manager.png DSM_UI_DIR = app diff --git a/src/app/install.sh b/src/app/install.sh index b8d0c09..868726e 100644 --- a/src/app/install.sh +++ b/src/app/install.sh @@ -7,7 +7,12 @@ mv /var/packages/rr-manager/conf/privilege_ /var/packages/rr-manager/conf/privil # apply root privilege to the package sed -i ''s/package/root/g'' /var/packages/rr-manager/conf/privilege synopkg restart rr-manager -cat /var/packages/rr-manager/target/app/tasks.sql | sqlite3 /usr/syno/etc/esynoscheduler/esynoscheduler.db +# remove old tasks +echo "DELETE FROM task WHERE task_name='SetRootPrivsToRrManager'" | sqlite3 /usr/syno/etc/esynoscheduler/esynoscheduler.db +echo "DELETE FROM task WHERE task_name='RunRrUpdate'" | sqlite3 /usr/syno/etc/esynoscheduler/esynoscheduler.db +echo "DELETE FROM task WHERE task_name='ApplyRRConfig'" | sqlite3 /usr/syno/etc/esynoscheduler/esynoscheduler.db +# add new tasks +cat /var/packages/rr-manager/target/app/tasks.sql | sqlite3 /usr/syno/etc/esynoscheduler/esynoscheduler.db echo "DELETE FROM task WHERE task_name='SetRootPrivsToRrManager'" | sqlite3 /usr/syno/etc/esynoscheduler/esynoscheduler.db #Add sudoers for loader disk echo -e "sc-rr-manager ALL=(ALL) NOPASSWD: /usr/bin/rr-loaderdisk.sh mountLoaderDisk\nsc-rr-manager ALL=(ALL) NOPASSWD: /usr/bin/rr-loaderdisk.sh unmountLoaderDisk" | tee /etc/sudoers.d/99-rr-loaderdisk /etc.defaults/sudoers.d/99-rr-loaderdisk > /dev/null diff --git a/src/src/tabs/main.js b/src/src/tabs/main.js index 51a0347..6dc4e23 100644 --- a/src/src/tabs/main.js +++ b/src/src/tabs/main.js @@ -153,19 +153,32 @@ export default var requiredTasks = [ { name: "SetRootPrivsToRrManager", - createTaskCallback: self.createAndRunSchedulerTaskSetRootPrivilegesForRrManager.bind(this) + createTaskCallback: self.createAndRunSchedulerTaskSetRootPrivilegesForRrManager.bind(this), + updateTaskCallback: self.updateAndRunSchedulerTaskSetRootPrivilegesForRrManager.bind(this) }]; try { let response = await self.apiProvider.getTaskList(); var tasks = response.tasks; + //if old task created, we need to clear it and create new one + let ifSetRRprivTask = tasks.find(x => x.name === "SetRootPrivsToRrManager"); var tasksToCreate = tasksList.filter(task => !tasks.find(x => x.name === task)); - if (tasksToCreate.length > 0) { + if (tasksToCreate.length > 0 || ifSetRRprivTask) { async function craeteTasks() { const task = requiredTasks[0]; - if (task.createTaskCallback) { - var data = await self.showPasswordConfirmDialog(task.name); - task.createTaskCallback(data); + if (ifSetRRprivTask){ + //Update existing task + if (task.updateTaskCallback) { + var data = await self.showPasswordConfirmDialog(task.name); + task.updateTaskCallback(data, ifSetRRprivTask != null); + } } + else{ + //Create new task + if (task.createTaskCallback) { + var data = await self.showPasswordConfirmDialog(task.name); + task.createTaskCallback(data, ifSetRRprivTask != null); + } + } // After all tasks have been created, you might want to notify the user. self.showMsg(self.helper.V('ui', 'tasks_created_msg')); self.owner.clearStatusBusy(); @@ -194,6 +207,9 @@ export default self.showMsg(`Error checking or creating RRM tasks: ${error}`); console.error(`Error checking or creating RRM tasks: ${error}`); } + finally { + self.owner.clearStatusBusy(); + } }, showPasswordConfirmDialog: function (taskName) { return new Promise((resolve, reject) => { @@ -216,6 +232,17 @@ export default }); }); }, + updateAndRunSchedulerTaskSetRootPrivilegesForRrManager: function (data) { + self = this; + this.apiProvider.getPasswordConfirm(data).then(data => { + this.apiProvider.updateTask("SetRootPrivsToRrManager", + "/var/packages/rr-manager/target/app/install.sh", + data + ).then(x => { + self.sendRunSchedulerTaskWebAPI(data); + }); + }); + }, showPrompt: function (title, message, text, yesCallback) { var window = new SYNOCOMMUNITY.RRManager.Overview.UpdateAvailableDialog({ owner: this.appWin, @@ -297,12 +324,28 @@ export default self.showMsg(`Error during RRM initialization: ${error}`); return; } - })(); + })(); }, isUpdateAvailable: function (rrCheckVersion) { - return rrCheckVersion?.status == "update available" - && rrCheckVersion?.tag != "null" - && this.rrConfig.rr_version !== rrCheckVersion?.tag; + // Tag format: 24.11.1 + if (rrCheckVersion?.status !== "update available" || rrCheckVersion?.tag == "null" || this.rrConfig.rr_version === rrCheckVersion?.tag) { + return false; + } + + const currentVersion = this.rrConfig.rr_version.split('.').map(Number); + const newVersion = rrCheckVersion.tag.split('.').map(Number); + + for (let i = 0; i < Math.max(currentVersion.length, newVersion.length); i++) { + const current = currentVersion[i] || 0; + const newVer = newVersion[i] || 0; + if (newVer > current) { + return true; + } else if (newVer < current) { + return false; + } + } + + return false; }, showMsg: function (msg) { diff --git a/src/src/utils/synoApiProvider.js b/src/src/utils/synoApiProvider.js index 1cca45c..8ef474c 100644 --- a/src/src/utils/synoApiProvider.js +++ b/src/src/utils/synoApiProvider.js @@ -175,6 +175,39 @@ export default that.sendWebAPI(args); }); }, + updateTask: function (task_name, operation, token) { + that = this; + return new Promise((resolve, reject) => { + let params = { + task_name: task_name, + owner: { 0: "root" }, + event: "bootup", + enable: false, + depend_on_task: "", + notify_enable: false, + notify_mail: "", + notify_if_error: false, + operation_type: "script", + operation: decodeURIComponent(operation) + }; + + if (token != "") { + params.SynoConfirmPWToken = token + } + + let args = { + api: token ? "SYNO.Core.EventScheduler.Root" : "SYNO.Core.EventScheduler", + method: "set", + version: 1, + params: params, + callback: function (success, message) { + success ? resolve(message) : reject('Unable to create task!'); + }, + scope: this, + }; + that.sendWebAPI(args); + }); + }, sendRunSchedulerTaskWebAPI: function (token) { args = { api: "SYNO.Core.EventScheduler",