Skip to content

Commit

Permalink
Fix onboarding process. Add cheking for existing tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriiNazarenkoTine committed Nov 18, 2024
1 parent 0a9f1d5 commit 7c0962a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/app/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 52 additions & 9 deletions src/src/tabs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) => {
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
33 changes: 33 additions & 0 deletions src/src/utils/synoApiProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7c0962a

Please sign in to comment.