foam_sync.ps1 (LIFEBALANCE) 2025-06-19T19:28:08Z
This commit is contained in:
@ -53,12 +53,12 @@ try {
|
|||||||
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
if ($existingTask) {
|
if ($existingTask) {
|
||||||
Write-Host "Scheduled task '$taskName' already exists. Checking configuration..."
|
Write-Verbose "Scheduled task '$taskName' already exists. Checking configuration..."
|
||||||
$currentTrigger = $existingTask.Triggers[0]
|
$currentTrigger = $existingTask.Triggers[0]
|
||||||
$currentAction = $existingTask.Actions[0]
|
$currentAction = $existingTask.Actions[0]
|
||||||
|
|
||||||
# Check Trigger
|
# Check Trigger
|
||||||
Write-Host "Checking trigger..."
|
Write-Verbose "Checking trigger..."
|
||||||
$triggerMatches = $false
|
$triggerMatches = $false
|
||||||
if ($currentTrigger -is [Microsoft.Management.Infrastructure.CimInstance] `
|
if ($currentTrigger -is [Microsoft.Management.Infrastructure.CimInstance] `
|
||||||
-and $currentTrigger.Repetition.Interval -eq $trigger.Repetition.Interval) {
|
-and $currentTrigger.Repetition.Interval -eq $trigger.Repetition.Interval) {
|
||||||
@ -96,15 +96,15 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($triggerMatches -and $actionMatches -and $principalMatches -and $settingsMatch) {
|
if ($triggerMatches -and $actionMatches -and $principalMatches -and $settingsMatch) {
|
||||||
Write-Host "Scheduled task '$taskName' is already correctly configured."
|
Write-Verbose "Scheduled task '$taskName' is already correctly configured."
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host "Scheduled task '$taskName' configuration differs."
|
Write-Verbose "Scheduled task '$taskName' configuration differs."
|
||||||
Write-Host "`$triggerMatches: $triggerMatches, `$actionMatches: $actionMatches, `$principalMatches: $principalMatches, `$settingsMatch: $settingsMatch"
|
Write-Verbose "`$triggerMatches: $triggerMatches, `$actionMatches: $actionMatches, `$principalMatches: $principalMatches, `$settingsMatch: $settingsMatch"
|
||||||
Write-Host "Attempting to update in-place..."
|
Write-Verbose "Attempting to update in-place..."
|
||||||
try {
|
try {
|
||||||
Set-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Principal $taskPrincipal -ErrorAction Stop
|
Set-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Principal $taskPrincipal -ErrorAction Stop
|
||||||
Write-Host "Scheduled task '$taskName' updated successfully."
|
Write-Verbose "Scheduled task '$taskName' updated successfully."
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Warning "Failed to update scheduled task '$taskName' in-place. Error: $($_.Exception.Message)"
|
Write-Warning "Failed to update scheduled task '$taskName' in-place. Error: $($_.Exception.Message)"
|
||||||
@ -113,10 +113,10 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host "Creating scheduled task '$taskName'..."
|
Write-Verbose "Creating scheduled task '$taskName'..."
|
||||||
try {
|
try {
|
||||||
Register-ScheduledTask -TaskName $taskName -Description $taskDescription -Principal $taskPrincipal -Trigger $trigger -Action $action -Settings $settings -ErrorAction Stop
|
Register-ScheduledTask -TaskName $taskName -Description $taskDescription -Principal $taskPrincipal -Trigger $trigger -Action $action -Settings $settings -ErrorAction Stop
|
||||||
Write-Host "Scheduled task '$taskName' created successfully."
|
Write-Verbose "Scheduled task '$taskName' created successfully."
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Warning "Failed to create scheduled task '$taskName'. Error: $($_.Exception.Message)"
|
Write-Warning "Failed to create scheduled task '$taskName'. Error: $($_.Exception.Message)"
|
||||||
@ -130,7 +130,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# --- Git Operations ---
|
# --- Git Operations ---
|
||||||
Write-Host "Navigating to repository: $scriptDir"
|
Write-Information "Navigating to repository: $scriptDir"
|
||||||
try {
|
try {
|
||||||
Set-Location -Path $scriptDir -ErrorAction Stop
|
Set-Location -Path $scriptDir -ErrorAction Stop
|
||||||
}
|
}
|
||||||
@ -139,35 +139,35 @@ try {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Staging all changes with 'git add .'"
|
Write-Information "Staging all changes with 'git add .'"
|
||||||
git add .
|
git add .
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Warning "'git add .' command failed with exit code $LASTEXITCODE."
|
Write-Warning "'git add .' command failed with exit code $LASTEXITCODE."
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Checking for staged changes with 'git diff --staged --quiet'..."
|
Write-Information "Checking for staged changes with 'git diff --staged --quiet'..."
|
||||||
git diff --staged --quiet
|
git diff --staged --quiet
|
||||||
$changesStaged = ($LASTEXITCODE -ne 0)
|
$changesStaged = ($LASTEXITCODE -ne 0)
|
||||||
|
|
||||||
if ($changesStaged) {
|
if ($changesStaged) {
|
||||||
Write-Host "Staged changes detected. Creating commit..."
|
Write-Information "Staged changes detected. Creating commit..."
|
||||||
$commitMessage = "$scriptName ($($env:COMPUTERNAME)) $(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssZ')"
|
$commitMessage = "$scriptName ($($env:COMPUTERNAME)) $(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssZ')"
|
||||||
Write-Host "Commit message: $commitMessage"
|
Write-Information "Commit message: $commitMessage"
|
||||||
git commit -m $commitMessage
|
git commit -m $commitMessage
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Warning "'git commit' command failed with exit code $LASTEXITCODE."
|
Write-Warning "'git commit' command failed with exit code $LASTEXITCODE."
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host "Commit created successfully."
|
Write-Information "Commit created successfully."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host "No relevant changes detected to commit."
|
Write-Information "No relevant changes detected to commit."
|
||||||
Write-Host "Resetting staging area with 'git reset HEAD --quiet'."
|
Write-Information "Resetting staging area with 'git reset HEAD --quiet'."
|
||||||
git reset HEAD --quiet
|
git reset HEAD --quiet
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Updating remote 'origin' with 'git remote update origin --prune'..."
|
Write-Information "Updating remote 'origin' with 'git remote update origin --prune'..."
|
||||||
git remote update origin --prune
|
git remote update origin --prune
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Error "Unable to update remote 'origin'. Exiting script."
|
Write-Error "Unable to update remote 'origin'. Exiting script."
|
||||||
@ -181,16 +181,16 @@ try {
|
|||||||
$remoteCommit = (git rev-parse $remoteBranch 2>$null).Trim()
|
$remoteCommit = (git rev-parse $remoteBranch 2>$null).Trim()
|
||||||
if ($LASTEXITCODE -ne 0 -or -not $remoteCommit) { Write-Error "Failed to get remote '$remoteBranch' commit. Exiting script."; exit 1 }
|
if ($LASTEXITCODE -ne 0 -or -not $remoteCommit) { Write-Error "Failed to get remote '$remoteBranch' commit. Exiting script."; exit 1 }
|
||||||
|
|
||||||
Write-Host "Local HEAD commit: $localCommit"
|
Write-Information "Local HEAD commit: $localCommit"
|
||||||
Write-Host "Remote '$remoteBranch' commit: $remoteCommit"
|
Write-Information "Remote '$remoteBranch' commit: $remoteCommit"
|
||||||
|
|
||||||
if ($localCommit -eq $remoteCommit) {
|
if ($localCommit -eq $remoteCommit) {
|
||||||
Write-Host "Local and remote are already in sync."
|
Write-Information "Local and remote are already in sync."
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
$sleepyTime = Get-Random -Minimum 1 -Maximum 15
|
$sleepyTime = Get-Random -Minimum 1 -Maximum 15
|
||||||
Write-Host "Local and remote differ. Sleeping for $sleepyTime seconds..."
|
Write-Information "Local and remote differ. Sleeping for $sleepyTime seconds..."
|
||||||
Start-Sleep -Seconds $sleepyTime
|
Start-Sleep -Seconds $sleepyTime
|
||||||
|
|
||||||
$localCommitAfterSleep = (git rev-parse HEAD 2>$null).Trim()
|
$localCommitAfterSleep = (git rev-parse HEAD 2>$null).Trim()
|
||||||
@ -199,13 +199,13 @@ try {
|
|||||||
if ($LASTEXITCODE -ne 0 -or -not $remoteCommitAfterSleep) { Write-Error "Failed to re-get remote '$remoteBranch' commit. Exiting script."; exit 1 }
|
if ($LASTEXITCODE -ne 0 -or -not $remoteCommitAfterSleep) { Write-Error "Failed to re-get remote '$remoteBranch' commit. Exiting script."; exit 1 }
|
||||||
|
|
||||||
if ($localCommitAfterSleep -eq $remoteCommitAfterSleep) {
|
if ($localCommitAfterSleep -eq $remoteCommitAfterSleep) {
|
||||||
Write-Host "Local and remote became synchronized during sleep."
|
Write-Information "Local and remote became synchronized during sleep."
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
$localCommit = $localCommitAfterSleep
|
$localCommit = $localCommitAfterSleep
|
||||||
$remoteCommit = $remoteCommitAfterSleep
|
$remoteCommit = $remoteCommitAfterSleep
|
||||||
|
|
||||||
Write-Host "Proceeding with sync logic..."
|
Write-Information "Proceeding with sync logic..."
|
||||||
|
|
||||||
git merge-base --is-ancestor $localCommit $remoteCommit
|
git merge-base --is-ancestor $localCommit $remoteCommit
|
||||||
$localIsAncestorOfRemote = ($LASTEXITCODE -eq 0)
|
$localIsAncestorOfRemote = ($LASTEXITCODE -eq 0)
|
||||||
@ -214,17 +214,17 @@ try {
|
|||||||
$remoteIsAncestorOfLocal = ($LASTEXITCODE -eq 0)
|
$remoteIsAncestorOfLocal = ($LASTEXITCODE -eq 0)
|
||||||
|
|
||||||
if ($localIsAncestorOfRemote) {
|
if ($localIsAncestorOfRemote) {
|
||||||
Write-Host "Remote '$remoteBranch' is ahead. Pulling with rebase..."
|
Write-Information "Remote '$remoteBranch' is ahead. Pulling with rebase..."
|
||||||
git pull --rebase origin main
|
git pull --rebase origin main
|
||||||
if ($LASTEXITCODE -ne 0) { Write-Error "'git pull --rebase' failed. Manual intervention may be required."; exit 1 }
|
if ($LASTEXITCODE -ne 0) { Write-Error "'git pull --rebase' failed. Manual intervention may be required."; exit 1 }
|
||||||
}
|
}
|
||||||
elseif ($remoteIsAncestorOfLocal) {
|
elseif ($remoteIsAncestorOfLocal) {
|
||||||
Write-Host "Local HEAD is ahead. Pushing..."
|
Write-Information "Local HEAD is ahead. Pushing..."
|
||||||
git push origin main
|
git push origin main
|
||||||
if ($LASTEXITCODE -ne 0) { Write-Error "'git push' failed. Manual intervention may be required."; exit 1 }
|
if ($LASTEXITCODE -ne 0) { Write-Error "'git push' failed. Manual intervention may be required."; exit 1 }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host "Local HEAD and remote '$remoteBranch' have diverged."
|
Write-Information "Local HEAD and remote '$remoteBranch' have diverged."
|
||||||
$remoteTimestampStr = (git log --pretty=format:"%at" -n 1 $remoteBranch 2>$null).Trim()
|
$remoteTimestampStr = (git log --pretty=format:"%at" -n 1 $remoteBranch 2>$null).Trim()
|
||||||
if ($LASTEXITCODE -ne 0 -or -not $remoteTimestampStr) { Write-Error "Failed to get remote commit timestamp for '$remoteBranch'. Exiting script."; exit 1 }
|
if ($LASTEXITCODE -ne 0 -or -not $remoteTimestampStr) { Write-Error "Failed to get remote commit timestamp for '$remoteBranch'. Exiting script."; exit 1 }
|
||||||
$remoteTimestamp = [long]$remoteTimestampStr
|
$remoteTimestamp = [long]$remoteTimestampStr
|
||||||
@ -233,27 +233,25 @@ try {
|
|||||||
if ($LASTEXITCODE -ne 0 -or -not $localTimestampStr) { Write-Error "Failed to get local commit timestamp for HEAD. Exiting script."; exit 1 }
|
if ($LASTEXITCODE -ne 0 -or -not $localTimestampStr) { Write-Error "Failed to get local commit timestamp for HEAD. Exiting script."; exit 1 }
|
||||||
$localTimestamp = [long]$localTimestampStr
|
$localTimestamp = [long]$localTimestampStr
|
||||||
|
|
||||||
# It's good practice to check if conversion was successful, though [long] will error on failure.
|
Write-Verbose "Local timestamp: $localTimestamp, Remote timestamp: $remoteTimestamp"
|
||||||
|
|
||||||
Write-Host "Local timestamp: $localTimestamp, Remote timestamp: $remoteTimestamp"
|
|
||||||
|
|
||||||
if ($remoteTimestamp -gt $localTimestamp) {
|
if ($remoteTimestamp -gt $localTimestamp) {
|
||||||
Write-Host "Remote is newer. Pulling with rebase, strategy 'theirs'..."
|
Write-Information "Remote is newer. Pulling with rebase, strategy 'theirs'..."
|
||||||
git pull --rebase -X theirs origin main
|
git pull --rebase -X theirs origin main
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host "Local is newer or same age. Pulling with rebase, strategy 'ours'..."
|
Write-Information "Local is newer or same age. Pulling with rebase, strategy 'ours'..."
|
||||||
git pull --rebase -X ours origin main
|
git pull --rebase -X ours origin main
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) { Write-Error "Rebase during divergence failed. Manual intervention may be required."; exit 1 }
|
if ($LASTEXITCODE -ne 0) { Write-Error "Rebase during divergence failed. Manual intervention may be required."; exit 1 }
|
||||||
|
|
||||||
Write-Host "Pushing changes after rebase..."
|
Write-Information "Pushing changes after rebase..."
|
||||||
git push origin main
|
git push origin main
|
||||||
if ($LASTEXITCODE -ne 0) { Write-Error "'git push' after rebase failed. Manual intervention may be required."; exit 1 }
|
if ($LASTEXITCODE -ne 0) { Write-Error "'git push' after rebase failed. Manual intervention may be required."; exit 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Synchronization process completed successfully."
|
Write-Information "Synchronization process completed successfully."
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|||||||
@ -28,9 +28,9 @@
|
|||||||
## Things that I've printed
|
## Things that I've printed
|
||||||
|
|
||||||
* [[2025-06-19]] - [Anti-Stress Spikeroll by Paul_Drosser - Thingiverse](https://www.thingiverse.com/thing:4575204)
|
* [[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]] - [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)
|
* [[2025-06-18]] - [Bambu Lab AMS Ultimate Front Rollers](https://makerworld.com/en/models/452104-bambu-lab-ams-ultimate-front-rollers#profileId-359257)
|
||||||
|
* [[2025-06-15]] - https://makerworld.com/en/models/192760-multiboard-pliers-holder#profileId-213102
|
||||||
|
|
||||||
|
|
||||||
[//begin]: # "Autogenerated link references for markdown compatibility"
|
[//begin]: # "Autogenerated link references for markdown compatibility"
|
||||||
|
|||||||
Reference in New Issue
Block a user