From 512fd452f0f2843236e48f0cf05fcabccea61740 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Fri, 11 Jul 2025 09:29:18 -0400 Subject: [PATCH] Update StackMonkey.ps1 --- StackMonkey.ps1 | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index 3b1286f..e3374a8 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -893,20 +893,21 @@ catch (e) { async function triggerInstall() { const runBtn = document.querySelector('.run-button'); - runBtn.disabled = true; + if (runBtn) runBtn.disabled = true; const statusBox = document.getElementById('status-box'); - statusBox.innerHTML = ''; + if (statusBox) statusBox.innerHTML = ''; try { - // Count how many tasks are checked - const taskCount = tasks.filter(t => { + const allTasks = typeof tasks !== 'undefined' ? tasks : []; + const checkedTasks = allTasks.filter(t => { const cb = document.getElementById(t.id); 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'); if (dattoCB && dattoCB.checked) { try { @@ -914,18 +915,15 @@ async function triggerInstall() { document.querySelectorAll('.sub-option-installDattoRMM:checked') ).map(x => x.value); const dropdown = document.getElementById('dattoDropdown'); - const uid = dropdown.value; - const name = dropdown.selectedOptions[0].text; + const uid = dropdown?.value; + const name = dropdown?.selectedOptions?.[0]?.text || 'Datto'; await fetch('/installDattoRMM', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - checkedValues: sub, - UID: uid, - Name: name - }) + body: JSON.stringify({ checkedValues: sub, UID: uid, Name: name }) }); + logProgress('Install DattoRMM', true); } catch (e) { 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'); if (svsCB && svsCB.checked) { try { @@ -945,13 +943,10 @@ async function triggerInstall() { } } - // 3. Run the remaining tasks - for (const t of tasks) { + // Step 3: Remaining tasks + for (const t of checkedTasks) { if (['installDattoRMM', 'installSVSMSPModule'].includes(t.id)) continue; - const cb = document.getElementById(t.id); - if (!cb || !cb.checked) continue; - try { await fetch(t.handler, { method: 'GET' }); logProgress(t.label || t.id, true); @@ -960,14 +955,15 @@ async function triggerInstall() { console.error(`Error running ${t.id}:`, e); } } - } catch (e) { - console.error('Error during triggerInstall:', e); + } catch (mainErr) { + console.error('triggerInstall failed:', mainErr); } finally { - runBtn.disabled = false; + if (runBtn) runBtn.disabled = false; } } + // ======================================================================= // Shutdown Handler // =======================================================================