Add Samy-new.ps1
This commit is contained in:
136
Samy-new.ps1
Normal file
136
Samy-new.ps1
Normal file
@@ -0,0 +1,136 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Script Automation Monkey (SAMY) ...
|
||||
.NOTES
|
||||
Full documentation: https://git.svstools.ca/.../docs/SAMY.help.md
|
||||
#>
|
||||
|
||||
#region Safely bypass Restricted Execution Policy
|
||||
if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage' -or
|
||||
(Get-ExecutionPolicy) -eq 'Restricted') {
|
||||
|
||||
Write-Host "[Info] Relaunching with ExecutionPolicy Bypass..." -ForegroundColor Yellow
|
||||
|
||||
# Build token list (NO manual quoting)
|
||||
$argList = foreach ($a in $args) { [string]$a }
|
||||
|
||||
if ($PSCommandPath) {
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$PSCommandPath" @argList
|
||||
}
|
||||
else {
|
||||
# Download -> create ScriptBlock -> INVOKE it with @args so $args survives the relaunch
|
||||
$bootstrap = "& { `$sb = [ScriptBlock]::Create((Invoke-WebRequest 'https://samybeta.svstools.ca' -UseBasicParsing).Content); & `$sb @args }"
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command $bootstrap @argList
|
||||
|
||||
# temp
|
||||
Write-Host "[Debug] Script saw args: $($args -join ' | ')" -ForegroundColor Magenta
|
||||
}
|
||||
|
||||
exit
|
||||
}
|
||||
#endregion Safely bypass Restricted Execution Policy
|
||||
|
||||
# TLS and silent install defaults
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
$ConfirmPreference = 'None'
|
||||
|
||||
#region Remote chunk loader
|
||||
|
||||
function Import-SamyChunk {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Url,
|
||||
[Parameter(Mandatory)][string]$Name
|
||||
)
|
||||
|
||||
try {
|
||||
Write-Host "[Info] Loading chunk: $Name" -ForegroundColor Cyan
|
||||
$content = (Invoke-WebRequest -UseBasicParsing -Uri $Url -ErrorAction Stop).Content
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($content)) {
|
||||
throw "Downloaded content was empty."
|
||||
}
|
||||
|
||||
. ([ScriptBlock]::Create($content))
|
||||
Write-Host "[Success] Loaded: $Name" -ForegroundColor Green
|
||||
}
|
||||
catch {
|
||||
throw "Failed to load chunk '$Name' from $Url. $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
# Single source of truth for where chunks live
|
||||
# (Matches your current inline values)
|
||||
$Script:SamyRepoBase = 'https://git.svstools.ca/SVS_Public_Repo/SAMY/raw/branch'
|
||||
$Script:SamyBranch = 'beta' # 'main' or 'beta'
|
||||
|
||||
$Script:ChunkBase = "$Script:SamyRepoBase/$Script:SamyBranch/src"
|
||||
|
||||
# Load chunks (dependencies first)
|
||||
$chunks = @(
|
||||
@{ Name = 'config.ps1'; Url = "$Script:ChunkBase/config.ps1?raw=1" },
|
||||
@{ Name = 'logging.fallback.ps1'; Url = "$Script:ChunkBase/logging.fallback.ps1?raw=1" },
|
||||
@{ Name = 'remote.ps1'; Url = "$Script:ChunkBase/remote.ps1?raw=1" },
|
||||
@{ Name = 'helpers.ps1'; Url = "$Script:ChunkBase/helpers.ps1?raw=1" },
|
||||
@{ Name = 'tasks.ps1'; Url = "$Script:ChunkBase/tasks.ps1?raw=1" },
|
||||
@{ Name = 'http.ps1'; Url = "$Script:ChunkBase/http.ps1?raw=1" },
|
||||
|
||||
@{ Name = 'svsmsp.install.ps1'; Url = "$Script:ChunkBase/svsmsp.install.ps1?raw=1" },
|
||||
@{ Name = 'integrations.datto.ps1';Url = "$Script:ChunkBase/integrations.datto.ps1?raw=1" },
|
||||
|
||||
@{ Name = 'ui.ps1'; Url = "$Script:ChunkBase/ui.ps1?raw=1" },
|
||||
@{ Name = 'handlers.datto.ps1'; Url = "$Script:ChunkBase/handlers.datto.ps1?raw=1" },
|
||||
@{ Name = 'handlers.onboard.ps1'; Url = "$Script:ChunkBase/handlers.onboard.ps1?raw=1" },
|
||||
@{ Name = 'handlers.offboard.ps1'; Url = "$Script:ChunkBase/handlers.offboard.ps1?raw=1" },
|
||||
@{ Name = 'handlers.printers.ps1'; Url = "$Script:ChunkBase/handlers.printers.ps1?raw=1" },
|
||||
|
||||
@{ Name = 'router.ps1'; Url = "$Script:ChunkBase/router.ps1?raw=1" },
|
||||
@{ Name = 'server.ps1'; Url = "$Script:ChunkBase/server.ps1?raw=1" },
|
||||
|
||||
@{ Name = 'core.ps1'; Url = "$Script:ChunkBase/core.ps1?raw=1" }
|
||||
)
|
||||
|
||||
foreach ($c in $chunks) {
|
||||
Import-SamyChunk -Url $c.Url -Name $c.Name
|
||||
}
|
||||
|
||||
if (-not (Get-Command Invoke-ScriptAutomationMonkey -ErrorAction SilentlyContinue)) {
|
||||
throw "Bootstrap loaded chunks, but Invoke-ScriptAutomationMonkey was not found. Ensure src/core.ps1 defines it."
|
||||
}
|
||||
|
||||
#endregion Remote chunk loader
|
||||
|
||||
#region Entry behavior (same intent as your original)
|
||||
|
||||
if ($MyInvocation.InvocationName -eq '.') {
|
||||
# dot-sourced, don't invoke
|
||||
return
|
||||
}
|
||||
elseif ($PSCommandPath) {
|
||||
# script was saved and run directly
|
||||
Invoke-ScriptAutomationMonkey @args
|
||||
}
|
||||
else {
|
||||
# iwr | iex fallback
|
||||
if ($args.Count -gt 0) {
|
||||
$namedArgs = @{}
|
||||
for ($i = 0; $i -lt $args.Count; $i++) {
|
||||
if ($args[$i] -is [string] -and $args[$i].StartsWith('-')) {
|
||||
$key = $args[$i].TrimStart('-')
|
||||
$next = $args[$i + 1]
|
||||
if ($next -and ($next -notlike '-*')) {
|
||||
$namedArgs[$key] = $next
|
||||
$i++
|
||||
} else {
|
||||
$namedArgs[$key] = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
Invoke-ScriptAutomationMonkey @namedArgs
|
||||
} else {
|
||||
Invoke-ScriptAutomationMonkey
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Entry behavior
|
||||
Reference in New Issue
Block a user