mirror of
https://github.com/kellymichels/zscripts-token-savers
synced 2026-10-07 07:18:18 +00:00
zdeploy ended with two blank lines and nothing else did, so its output
was the only one that did not butt up against the next prompt. Applied
everywhere.
Implemented in Stop-ZTracking rather than per script, because every
tracked script ends by calling it - including the usage and guard paths
that do `Stop-ZTracking; exit 1`. One place therefore covers every exit
of sixteen scripts.
* Write-ZTrailer emits the two lines. Stop-ZTracking calls it on both
paths, including the early return when tracking never started - a
script that printed output still deserves the separation.
* -FinalNote prints one last line AFTER the tracking footer and BEFORE
the blanks. zdeploy's "Last deployed at ..." now goes through it, so
it stays the last thing on screen instead of being followed by the
token count.
* The standalone tools (zchecksums, zversion, zrelease) get a local
three-line copy at each exit rather than dot-sourcing ZHelpers -
they are deliberately dependency-free so they run from an extracted
release zip with nothing beside them.
* Redundant trailing blanks were removed where a script already
printed one before exiting, so the count is exactly two, not three.
Also fixes a related gap found while testing: the error exits inside
Get-ZConfig and Get-ZProject bypassed Stop-ZTracking entirely, so a run
that died on a missing zconfig.json printed no trailer AND no token
footer. Those three exits now route through Stop-ZTracking.
zkill/zrestart are one-line wrappers around scripts that already trail,
so they are untouched - adding it would double the blanks.
Verified by running each script and counting the trailing blank lines in
its captured output: 2 on every success path, every usage path, and the
config-error path. Suite 231/231. CHECKSUMS.txt refreshed.
82 lines
3.0 KiB
PowerShell
82 lines
3.0 KiB
PowerShell
# Evomedia.net Token Savers — https://github.com/evomedia-net/evo.zscripts
|
|
# Created by Kelly Michels · dev@evomedia.net
|
|
# Licensed under the MIT License. See LICENSE.
|
|
# Version: v1.0.0.0.14
|
|
|
|
# setup_backup_schedule.ps1 — create a scheduled task for daily backups + OneDrive sync
|
|
#
|
|
# Usage:
|
|
# Right-click PowerShell -> "Run as Administrator"
|
|
# Then run: .\setup_backup_schedule.ps1
|
|
#
|
|
# This creates a task that runs zbackup_and_sync.ps1 every day at 2:00 AM
|
|
|
|
#Requires -RunAsAdministrator
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
. (Join-Path $PSScriptRoot "ZHelpers.ps1")
|
|
|
|
$cfg = Get-ZConfig
|
|
$ScriptPath = Join-Path $cfg.paths.scriptsRoot "zbackup_and_sync.ps1"
|
|
$TaskName = "ZScripts-Backup-And-Sync"
|
|
|
|
Write-Host ""
|
|
Write-Host "Setting up scheduled backup task..." -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
if (-not (Test-Path -LiteralPath $ScriptPath)) {
|
|
Write-Host "ERROR: Script not found: $ScriptPath" -ForegroundColor Red
|
|
Write-Host " Check paths.scriptsRoot in zconfig.json" -ForegroundColor DarkGray
|
|
Write-ZTrailer
|
|
exit 1
|
|
}
|
|
|
|
$existingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
|
|
if ($existingTask) {
|
|
Write-Host "Task already exists: $TaskName" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
$deleteChoice = Read-Host "Delete and recreate? (y/n)"
|
|
if ($deleteChoice -eq "y") {
|
|
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
|
|
Write-Host "Deleted existing task." -ForegroundColor Green
|
|
} else {
|
|
Write-Host "Keeping existing task. Exiting." -ForegroundColor Yellow
|
|
Write-ZTrailer
|
|
exit 0
|
|
}
|
|
}
|
|
|
|
$trigger = New-ScheduledTaskTrigger -Daily -At "02:00"
|
|
$action = New-ScheduledTaskAction `
|
|
-Execute "powershell.exe" `
|
|
-Argument "-ExecutionPolicy Bypass -NoProfile -File `"$ScriptPath`" all"
|
|
$settings = New-ScheduledTaskSettingsSet `
|
|
-AllowStartIfOnBatteries `
|
|
-DontStopIfGoingOnBatteries `
|
|
-StartWhenAvailable `
|
|
-Compatibility Win8
|
|
|
|
Write-Host "Creating scheduled task: $TaskName" -ForegroundColor Yellow
|
|
Register-ScheduledTask `
|
|
-TaskName $TaskName `
|
|
-Trigger $trigger `
|
|
-Action $action `
|
|
-Settings $settings `
|
|
-Description "Daily backup of all projects + OneDrive sync. Runs at 2:00 AM daily." `
|
|
-Force
|
|
|
|
Write-Host ""
|
|
Write-Host "Success! Scheduled task created." -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "Task Details:" -ForegroundColor Cyan
|
|
Write-Host " Name: $TaskName" -ForegroundColor Gray
|
|
Write-Host " Schedule: Daily at 2:00 AM" -ForegroundColor Gray
|
|
Write-Host " Action: $ScriptPath" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "To manage the task:" -ForegroundColor Gray
|
|
Write-Host " View: Get-ScheduledTask -TaskName '$TaskName'" -ForegroundColor DarkGray
|
|
Write-Host " Run now: Start-ScheduledTask -TaskName '$TaskName'" -ForegroundColor DarkGray
|
|
Write-Host " Disable: Disable-ScheduledTask -TaskName '$TaskName'" -ForegroundColor DarkGray
|
|
Write-Host " Delete: Unregister-ScheduledTask -TaskName '$TaskName'" -ForegroundColor DarkGray
|
|
Write-Host ""
|