From d5ca7cf365d7102769f60b6f26a848cfad95e184 Mon Sep 17 00:00:00 2001 From: Ben Miller Date: Thu, 19 Jun 2025 13:43:24 -0600 Subject: [PATCH] foam_sync.ps1 (LIFEBALANCE) 2025-06-19T13:43:24Z --- 2025-06-19.md | 1 + foam_sync.ps1 | 87 +++------------------------------------------------ making.md | 6 +++- 3 files changed, 10 insertions(+), 84 deletions(-) create mode 100644 2025-06-19.md diff --git a/2025-06-19.md b/2025-06-19.md new file mode 100644 index 0000000..b05b69e --- /dev/null +++ b/2025-06-19.md @@ -0,0 +1 @@ +# 2025-06-19 diff --git a/foam_sync.ps1 b/foam_sync.ps1 index 78ee4ad..03787ba 100644 --- a/foam_sync.ps1 +++ b/foam_sync.ps1 @@ -1,36 +1,5 @@ #Requires -Version 5.1 -<# -.SYNOPSIS - A PowerShell script to periodically synchronize a Git repository, similar to the foam_sync.sh bash script. - It stages all changes, commits if there are any, and then syncs with the 'origin/main' remote. - It also attempts to set up a Windows Scheduled Task to run itself periodically. - -.DESCRIPTION - This script performs the following actions: - 1. Configures a Scheduled Task to run this script at a defined frequency. - - The first time this script is run, it might require Administrator privileges to register the task. - 2. Navigates to the script's directory (assumed to be the Git repository root). - 3. Stages all changes using 'git add .'. - 4. Checks for actual staged changes using 'git diff --staged --quiet'. - 5. If changes exist, commits them with a timestamped message. - 6. If no meaningful changes were staged, resets the staging area. - 7. Updates the local knowledge of the remote 'origin'. - 8. Compares local HEAD with 'origin/main'. - 9. If they differ, it sleeps for a random interval to avoid race conditions. - 10. Determines if local is ahead, remote is ahead, or they have diverged. - 11. Performs 'git pull --rebase' or 'git push' accordingly. - 12. In case of divergence, it attempts a rebase, preferring the newer commit (based on timestamp) - or 'ours' if timestamps are equal. Then pushes. - -.NOTES - Author: Gemini Code Assist (Translated from bash) - Version: 1.0 - Prerequisites: Git must be installed and in the system PATH. - Running for the first time: You may need to run this script as an Administrator - to allow the Scheduled Task to be registered. -#> - # --- Configuration --- $frequencyMinutes = 2 # How often the Scheduled Task should attempt to run this script $executionTimeLimitBufferSeconds = 30 # Buffer: task stops if it runs longer than (frequency - buffer) @@ -66,57 +35,12 @@ try { # Run as the user who executes this script. $taskPrincipal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive - # Define a very long duration (e.g., 40 years) - $practicallyIndefiniteDuration = New-TimeSpan -Days (365 * 40 + 10) # Approx 40 years, accounting for leap years - # Trigger configuration - $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes $frequencyMinutes) -RepetitionDuration $practicallyIndefiniteDuration - - # Action configuration: - # We use an indirection technique to ensure the window is truly hidden. - # The scheduled task launches an initial PowerShell. - # This initial PowerShell then uses Start-Process to launch the *actual* script in a new, hidden PowerShell process. - - # 1. Innermost PowerShell's -File argument: Path to the script, with internal double quotes escaped as "" - # e.g., \"C:\path\to your script.ps1\" - $scriptPathForInnermostFileParam = $scriptPath.Replace('"', '""') - $innermostFileArg = "\`"$scriptPathForInnermostFileParam\`"" - - # 2. Argument string for the innermost PowerShell instance (the one executing the actual script) - # e.g., -NoProfile -NonInteractive -ExecutionPolicy Bypass -File \"C:\path\to your script.ps1\" - $innermostPSArgs = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -File $innermostFileArg" - - # 3. The innermostPSArgs string needs its single quotes escaped (as '') because it will be wrapped in single quotes for Start-Process's -ArgumentList - $innermostPSArgsEscapedForStartProcess = $innermostPSArgs.Replace("'", "''") - - # 4. Command string that the first PowerShell instance (launched by Task Scheduler) will execute using Start-Process. - # e.g., Start-Process -FilePath powershell.exe -ArgumentList '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File \"C:\path\to your script.ps1\"' -WindowStyle Hidden - $commandToRunViaStartProcess = "Start-Process -FilePath powershell.exe -ArgumentList '$innermostPSArgsEscapedForStartProcess' -WindowStyle Hidden" - - # 5. Argument string FOR THE TASK SCHEDULER to pass to the first powershell.exe. - # The $commandToRunViaStartProcess is the value for -Command, and needs to be quoted for registration. - # e.g., -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Start-Process -FilePath powershell.exe -ArgumentList '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File \"C:\path\to your script.ps1\"' -WindowStyle Hidden" - # $actionArgumentForRegistration = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command \`"$commandToRunViaStartProcess\`"" - - # TEMPORARY: For troubleshooting the flashing window. - # We simplify the command to see if the intermediate PowerShell itself has an issue parsing/executing Start-Process. - # Errors from this *intermediate* powershell should appear in the Task Scheduler history. - $actionArgumentForRegistration = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command \`"$commandToRunViaStartProcess\`"" # Reverted to original, but without explicit redirection for now. - - - # 6. Expected argument string WHEN RETRIEVED by Get-ScheduledTask. - # Task Scheduler/PowerShell often strips the outermost quotes from the -Command value when retrieved. - $expectedRetrievedActionArgument = "-NoProfile -NonInteractive -ExecutionPolicy Bypass -Command $commandToRunViaStartProcess" # Reverted to match the above - + $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes $frequencyMinutes) + $actionArgumentForRegistration = "-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File $scriptPath" $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $actionArgumentForRegistration # Task settings - # Calculate a realistic execution time limit based on the frequency - $executionTimeLimitTotalSeconds = ($frequencyMinutes * 60) - $executionTimeLimitBufferSeconds - if ($executionTimeLimitTotalSeconds -lt 30) { - # Ensure a minimum sensible execution time (e.g., 30 seconds) - $executionTimeLimitTotalSeconds = 30 - } - $taskExecutionTimeLimit = New-TimeSpan -Seconds $executionTimeLimitTotalSeconds + $taskExecutionTimeLimit = New-TimeSpan -Seconds 30 $settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit $taskExecutionTimeLimit # Check and configure the scheduled task @@ -127,14 +51,11 @@ try { Write-Host "Scheduled task '$taskName' already exists. Checking configuration..." $currentTrigger = $existingTask.Triggers[0] $currentAction = $existingTask.Actions[0] - # You could also compare $existingTask.Principal.UserId with $taskPrincipal.UserId - # and $existingTask.Description with $taskDescription if strict matching is needed for those. # Check Trigger $triggerMatches = $false if ($currentTrigger -is [Microsoft.Management.Infrastructure.CimInstance] ` - -and $currentTrigger.RepetitionInterval.TotalMinutes -eq $frequencyMinutes ` - -and $currentTrigger.RepetitionDuration -eq $practicallyIndefiniteDuration) { + -and $currentTrigger.RepetitionInterval.TotalMinutes -eq $frequencyMinutes) { $triggerMatches = $true } diff --git a/making.md b/making.md index 3863111..1866ddc 100644 --- a/making.md +++ b/making.md @@ -6,6 +6,7 @@ * https://www.printables.com/@beepmill_1805142/collections * [Gumroad](https://gumroad.com/library) * https://cults3d.com/en/design-collections +* https://www.thingiverse.com/beepmill/collections ## Systems @@ -22,16 +23,19 @@ * Printing metric [[2025-06-15]] * Printing imperial [[2025-06-17]] * [AMS Driven Rear Roller replacement](https://makerworld.com/en/models/80150-ams-driven-rear-roller-replacement#profileId-85113) -* [Bambu Lab AMS Ultimate Front Rollers](https://makerworld.com/en/models/452104-bambu-lab-ams-ultimate-front-rollers#profileId-359257) + ## Things that I've printed +* [[2025-06-19]] - [Anti-Stress Spikeroll by Paul_Drosser - Thingiverse](https://www.thingiverse.com/thing:4575204) * [[2025-06-15]] - https://makerworld.com/en/models/192760-multiboard-pliers-holder#profileId-213102 * [[2025-06-18]] - [Lid Riser for Bambu Lab AMS](https://www.printables.com/model/602705-ams-lid-riser-for-bambu-lab-ams/comments) +* [[2025-06-18]] - [Bambu Lab AMS Ultimate Front Rollers](https://makerworld.com/en/models/452104-bambu-lab-ams-ultimate-front-rollers#profileId-359257) [//begin]: # "Autogenerated link references for markdown compatibility" [2025-06-15]: 2025-06-15.md "2025-06-15" [2025-06-17]: 2025-06-17.md "2025-06-17" +[2025-06-19]: 2025-06-19.md "2025-06-19" [2025-06-18]: 2025-06-18.md "2025-06-18" [//end]: # "Autogenerated link references"