Update StackMonkey.ps1
This commit is contained in:
@@ -893,20 +893,21 @@ catch (e) {
|
|||||||
|
|
||||||
async function triggerInstall() {
|
async function triggerInstall() {
|
||||||
const runBtn = document.querySelector('.run-button');
|
const runBtn = document.querySelector('.run-button');
|
||||||
runBtn.disabled = true;
|
if (runBtn) runBtn.disabled = true;
|
||||||
|
|
||||||
const statusBox = document.getElementById('status-box');
|
const statusBox = document.getElementById('status-box');
|
||||||
statusBox.innerHTML = '';
|
if (statusBox) statusBox.innerHTML = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Count how many tasks are checked
|
const allTasks = typeof tasks !== 'undefined' ? tasks : [];
|
||||||
const taskCount = tasks.filter(t => {
|
const checkedTasks = allTasks.filter(t => {
|
||||||
const cb = document.getElementById(t.id);
|
const cb = document.getElementById(t.id);
|
||||||
return cb && cb.checked;
|
return cb && cb.checked;
|
||||||
}).length;
|
});
|
||||||
setTotalTaskCount(taskCount);
|
|
||||||
|
|
||||||
// 1. Run DattoRMM first
|
setTotalTaskCount(checkedTasks.length);
|
||||||
|
|
||||||
|
// Step 1: Run DattoRMM if selected
|
||||||
const dattoCB = document.getElementById('installDattoRMM');
|
const dattoCB = document.getElementById('installDattoRMM');
|
||||||
if (dattoCB && dattoCB.checked) {
|
if (dattoCB && dattoCB.checked) {
|
||||||
try {
|
try {
|
||||||
@@ -914,18 +915,15 @@ async function triggerInstall() {
|
|||||||
document.querySelectorAll('.sub-option-installDattoRMM:checked')
|
document.querySelectorAll('.sub-option-installDattoRMM:checked')
|
||||||
).map(x => x.value);
|
).map(x => x.value);
|
||||||
const dropdown = document.getElementById('dattoDropdown');
|
const dropdown = document.getElementById('dattoDropdown');
|
||||||
const uid = dropdown.value;
|
const uid = dropdown?.value;
|
||||||
const name = dropdown.selectedOptions[0].text;
|
const name = dropdown?.selectedOptions?.[0]?.text || 'Datto';
|
||||||
|
|
||||||
await fetch('/installDattoRMM', {
|
await fetch('/installDattoRMM', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({ checkedValues: sub, UID: uid, Name: name })
|
||||||
checkedValues: sub,
|
|
||||||
UID: uid,
|
|
||||||
Name: name
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
logProgress('Install DattoRMM', true);
|
logProgress('Install DattoRMM', true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logProgress('Install DattoRMM', false);
|
logProgress('Install DattoRMM', false);
|
||||||
@@ -933,7 +931,7 @@ async function triggerInstall() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Run SVSMSP module install second
|
// Step 2: Run SVSMSP module install
|
||||||
const svsCB = document.getElementById('installSVSMSPModule');
|
const svsCB = document.getElementById('installSVSMSPModule');
|
||||||
if (svsCB && svsCB.checked) {
|
if (svsCB && svsCB.checked) {
|
||||||
try {
|
try {
|
||||||
@@ -945,13 +943,10 @@ async function triggerInstall() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Run the remaining tasks
|
// Step 3: Remaining tasks
|
||||||
for (const t of tasks) {
|
for (const t of checkedTasks) {
|
||||||
if (['installDattoRMM', 'installSVSMSPModule'].includes(t.id)) continue;
|
if (['installDattoRMM', 'installSVSMSPModule'].includes(t.id)) continue;
|
||||||
|
|
||||||
const cb = document.getElementById(t.id);
|
|
||||||
if (!cb || !cb.checked) continue;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetch(t.handler, { method: 'GET' });
|
await fetch(t.handler, { method: 'GET' });
|
||||||
logProgress(t.label || t.id, true);
|
logProgress(t.label || t.id, true);
|
||||||
@@ -960,14 +955,15 @@ async function triggerInstall() {
|
|||||||
console.error(`Error running ${t.id}:`, e);
|
console.error(`Error running ${t.id}:`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (mainErr) {
|
||||||
console.error('Error during triggerInstall:', e);
|
console.error('triggerInstall failed:', mainErr);
|
||||||
} finally {
|
} finally {
|
||||||
runBtn.disabled = false;
|
if (runBtn) runBtn.disabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// Shutdown Handler
|
// Shutdown Handler
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user