From cebd264a9e968e02a2f40db5cdb8fae827749674 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Thu, 24 Jul 2025 08:33:54 +0200 Subject: [PATCH] Updated some scripts --- scripts/build-repo.ps1 | 2 +- scripts/build-repos.ps1 | 2 +- scripts/clean-repo.ps1 | 2 +- scripts/clean-repos.ps1 | 2 +- scripts/fetch-repo.ps1 | 2 +- scripts/install-basic-apps.ps1 | 2 +- scripts/install-basic-snaps.ps1 | 2 +- scripts/install-calibre-server.ps1 | 2 +- scripts/install-edit.ps1 | 6 +++--- scripts/install-evcc.ps1 | 2 +- scripts/install-github-cli.ps1 | 2 +- scripts/install-knot-resolver.ps1 | 2 +- scripts/install-salesforce-cli.ps1 | 2 +- scripts/install-signal-cli.ps1 | 6 +++--- scripts/install-skype.ps1 | 27 -------------------------- scripts/install-ssh-server.ps1 | 2 +- scripts/install-twitter.ps1 | 27 -------------------------- scripts/install-unbound-server.ps1 | 2 +- scripts/install-updates.ps1 | 2 +- scripts/install-visual-studio-code.ps1 | 2 +- scripts/list-updates.ps1 | 2 +- scripts/new-branch.ps1 | 2 +- scripts/new-dir.ps1 | 2 +- scripts/new-email.ps1 | 2 +- scripts/new-junction.ps1 | 2 +- scripts/new-markdown-file.ps1 | 2 +- scripts/new-powershell-script.ps1 | 2 +- scripts/new-symlink.ps1 | 2 +- scripts/new-tag.ps1 | 4 ++-- scripts/new-user.ps1 | 2 +- scripts/pull-repo.ps1 | 2 +- scripts/pull-repos.ps1 | 2 +- scripts/remove-dir.ps1 | 12 +++++++----- 33 files changed, 42 insertions(+), 94 deletions(-) delete mode 100755 scripts/install-skype.ps1 delete mode 100755 scripts/install-twitter.ps1 diff --git a/scripts/build-repo.ps1 b/scripts/build-repo.ps1 index 53e2cff5..06ed345e 100755 --- a/scripts/build-repo.ps1 +++ b/scripts/build-repo.ps1 @@ -162,7 +162,7 @@ try { } exit 0 # success } catch { - "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." Set-Location "$previousPath" exit 1 } diff --git a/scripts/build-repos.ps1 b/scripts/build-repos.ps1 index 1cbc75bf..335be023 100755 --- a/scripts/build-repos.ps1 +++ b/scripts/build-repos.ps1 @@ -35,6 +35,6 @@ try { "✅ Built $FolderCount Git repositories at 📂$ParentDirName in $Elapsed sec" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/clean-repo.ps1 b/scripts/clean-repo.ps1 index d8044902..3f383cca 100755 --- a/scripts/clean-repo.ps1 +++ b/scripts/clean-repo.ps1 @@ -48,6 +48,6 @@ try { "✅ Repo '$repoName' cleaned in $($elapsed)s." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/clean-repos.ps1 b/scripts/clean-repos.ps1 index 4802f5a5..671b1136 100755 --- a/scripts/clean-repos.ps1 +++ b/scripts/clean-repos.ps1 @@ -49,6 +49,6 @@ try { "✅ Cleaned $numFolders Git repositories under 📂$parentDirName in $($elapsed)s." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/fetch-repo.ps1 b/scripts/fetch-repo.ps1 index 208e134c..6220910f 100755 --- a/scripts/fetch-repo.ps1 +++ b/scripts/fetch-repo.ps1 @@ -38,6 +38,6 @@ try { "✅ Updates fetched into 📂$repoDirName repo in $($elapsed)s." exit 0 # success } catch { - "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-basic-apps.ps1 b/scripts/install-basic-apps.ps1 index ec1a727b..f6fe1e59 100755 --- a/scripts/install-basic-apps.ps1 +++ b/scripts/install-basic-apps.ps1 @@ -52,6 +52,6 @@ try { "✅ Installed $numInstalled basic apps ($numSkipped skipped) in $elapsed sec." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-basic-snaps.ps1 b/scripts/install-basic-snaps.ps1 index 434e1783..25e3293c 100755 --- a/scripts/install-basic-snaps.ps1 +++ b/scripts/install-basic-snaps.ps1 @@ -44,6 +44,6 @@ try { "✅ Installed 20 snap apps in $($elapsed)s." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-calibre-server.ps1 b/scripts/install-calibre-server.ps1 index 0b505576..34dd3d34 100755 --- a/scripts/install-calibre-server.ps1 +++ b/scripts/install-calibre-server.ps1 @@ -53,6 +53,6 @@ try { " (URL=http://$(hostname):$port media=$mediaFolder userDB=$userDB log=$logfile)." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-edit.ps1 b/scripts/install-edit.ps1 index d7273c0b..94996ada 100755 --- a/scripts/install-edit.ps1 +++ b/scripts/install-edit.ps1 @@ -6,7 +6,7 @@ .EXAMPLE PS> ./install-edit.ps1 ⏳ Installing Microsoft Edit from Microsoft Store... - ✅ Microsoft Edit installed successfully in 25s. + ✅ Microsoft Edit installed successfully (took 25s). .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -28,9 +28,9 @@ try { if ($lastExitCode -ne 0) { throw "Can't install Microsoft Edit, is it already installed?" } } [int]$elapsed = $stopWatch.Elapsed.TotalSeconds - "✅ Microsoft Edit installed successfully in $($elapsed)s." + "✅ Microsoft Edit installed successfully (took $($elapsed)s)." exit 0 # success } catch { - "⚠️ ERROR: $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-evcc.ps1 b/scripts/install-evcc.ps1 index 2dccdd13..6ef70d37 100755 --- a/scripts/install-evcc.ps1 +++ b/scripts/install-evcc.ps1 @@ -41,6 +41,6 @@ try { "✅ evcc installed successfully in $($elapsed)s." exit 0 # success } catch { - "Sorry: $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-github-cli.ps1 b/scripts/install-github-cli.ps1 index 75c25afd..3cf6dc83 100755 --- a/scripts/install-github-cli.ps1 +++ b/scripts/install-github-cli.ps1 @@ -31,6 +31,6 @@ try { "✅ GitHub CLI installed successfully in $($elapsed)s - to authenticate execute: 'gh auth login'" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-knot-resolver.ps1 b/scripts/install-knot-resolver.ps1 index 11640dc9..02a5c3e7 100755 --- a/scripts/install-knot-resolver.ps1 +++ b/scripts/install-knot-resolver.ps1 @@ -32,6 +32,6 @@ try { "✅ installed Knot Resolver in $Elapsed sec" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-salesforce-cli.ps1 b/scripts/install-salesforce-cli.ps1 index 97023547..45644d59 100755 --- a/scripts/install-salesforce-cli.ps1 +++ b/scripts/install-salesforce-cli.ps1 @@ -33,6 +33,6 @@ try { exit 0 # success } catch { - Write-Output "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + Write-Output "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-signal-cli.ps1 b/scripts/install-signal-cli.ps1 index 2df06a9c..df57ff53 100755 --- a/scripts/install-signal-cli.ps1 +++ b/scripts/install-signal-cli.ps1 @@ -40,10 +40,10 @@ try { rm "signal-cli-$Version.tar.gz" if ($lastExitCode -ne 0) { throw "'rm' failed" } - [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds - "✅ installed signal-cli $Version to /opt and /usr/local/bin in $Elapsed sec" + [int]$elapsed = $StopWatch.Elapsed.TotalSeconds + "✅ Signal-cli $Version installed to /opt and /usr/local/bin in $elapsed sec." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-skype.ps1 b/scripts/install-skype.ps1 deleted file mode 100755 index 9e8217d2..00000000 --- a/scripts/install-skype.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -<# -.SYNOPSIS - Installs Skype -.DESCRIPTION - This PowerShell script installs Skype from the Microsoft Store. -.EXAMPLE - PS> ./install-skype.ps1 -.LINK - https://github.com/fleschutz/PowerShell -.NOTES - Author: Markus Fleschutz | License: CC0 -#> - -#requires -version 5.1 - -try { - "Installing Skype, please wait..." - - & winget install "Skype" --source msstore --accept-package-agreements --accept-source-agreements - if ($lastExitCode -ne 0) { throw "'winget install' failed" } - - "Skype installed successfully." - exit 0 # success -} catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" - exit 1 -} diff --git a/scripts/install-ssh-server.ps1 b/scripts/install-ssh-server.ps1 index e6dc9df4..c8675fff 100755 --- a/scripts/install-ssh-server.ps1 +++ b/scripts/install-ssh-server.ps1 @@ -40,6 +40,6 @@ try { "✅ installed and started SSH server in $Elapsed sec" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-twitter.ps1 b/scripts/install-twitter.ps1 deleted file mode 100755 index fa2102bf..00000000 --- a/scripts/install-twitter.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -<# -.SYNOPSIS - Installs Twitter -.DESCRIPTION - This PowerShell script installs Twitter from the Microsoft Store. -.EXAMPLE - PS> ./install-twitter.ps1 -.LINK - https://github.com/fleschutz/PowerShell -.NOTES - Author: Markus Fleschutz | License: CC0 -#> - -#requires -version 5.1 - -try { - "Installing Twitter, please wait..." - - & winget install "Twitter" --source msstore --accept-package-agreements --accept-source-agreements - if ($lastExitCode -ne 0) { throw "'winget install' failed" } - - "Twitter installed successfully." - exit 0 # success -} catch { - "Sorry: $($Error[0])" - exit 1 -} diff --git a/scripts/install-unbound-server.ps1 b/scripts/install-unbound-server.ps1 index a797a310..c709b7f1 100755 --- a/scripts/install-unbound-server.ps1 +++ b/scripts/install-unbound-server.ps1 @@ -61,6 +61,6 @@ try { "✅ Installed Unbound in $Elapsed sec" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-updates.ps1 b/scripts/install-updates.ps1 index 9bc36c10..57378818 100755 --- a/scripts/install-updates.ps1 +++ b/scripts/install-updates.ps1 @@ -74,6 +74,6 @@ try { "✅ Updates installed in $($elapsed)s." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/install-visual-studio-code.ps1 b/scripts/install-visual-studio-code.ps1 index 5dc21751..dff803a8 100755 --- a/scripts/install-visual-studio-code.ps1 +++ b/scripts/install-visual-studio-code.ps1 @@ -22,6 +22,6 @@ try { "Visual Studio Code installed successfully." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/list-updates.ps1 b/scripts/list-updates.ps1 index e1370d2a..c192c539 100755 --- a/scripts/list-updates.ps1 +++ b/scripts/list-updates.ps1 @@ -55,6 +55,6 @@ try { "💡 Execute 'install-updates.ps1' to install the listed updates." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/new-branch.ps1 b/scripts/new-branch.ps1 index 0d2ffd49..b42311b4 100755 --- a/scripts/new-branch.ps1 +++ b/scripts/new-branch.ps1 @@ -65,6 +65,6 @@ try { "✅ Repo '$repoName' on new branch '$newBranch' (based on '$currentBranch', took $($elapsed)s)." exit 0 # success } catch { - "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/new-dir.ps1 b/scripts/new-dir.ps1 index 258d6698..6bb0effc 100755 --- a/scripts/new-dir.ps1 +++ b/scripts/new-dir.ps1 @@ -27,6 +27,6 @@ try { "✅ New 📂$path created." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/new-email.ps1 b/scripts/new-email.ps1 index af653d66..fbbe369b 100755 --- a/scripts/new-email.ps1 +++ b/scripts/new-email.ps1 @@ -20,6 +20,6 @@ try { Start-Process $URL exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/new-junction.ps1 b/scripts/new-junction.ps1 index b1773bea..1af2c116 100755 --- a/scripts/new-junction.ps1 +++ b/scripts/new-junction.ps1 @@ -27,6 +27,6 @@ try { "✅ New junction '$junction' created, linking to: 📂$targetDir" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/new-markdown-file.ps1 b/scripts/new-markdown-file.ps1 index d034e9cd..1ecc0c3d 100755 --- a/scripts/new-markdown-file.ps1 +++ b/scripts/new-markdown-file.ps1 @@ -26,6 +26,6 @@ try { "✅ New '$path' created (from data/templates/New.md)." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/new-powershell-script.ps1 b/scripts/new-powershell-script.ps1 index 7425b284..fff4c588 100755 --- a/scripts/new-powershell-script.ps1 +++ b/scripts/new-powershell-script.ps1 @@ -26,6 +26,6 @@ try { "✅ New '$path' created (from data/templates/New.ps1)." exit 0 # success } catch { - "⚠️ Error: $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/new-symlink.ps1 b/scripts/new-symlink.ps1 index 6ade6d31..60343bdd 100755 --- a/scripts/new-symlink.ps1 +++ b/scripts/new-symlink.ps1 @@ -28,6 +28,6 @@ try { "✅ Created new symlink '$symlink' linking to: $target" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/new-tag.ps1 b/scripts/new-tag.ps1 index 168cbbe9..63fb2b00 100755 --- a/scripts/new-tag.ps1 +++ b/scripts/new-tag.ps1 @@ -42,9 +42,9 @@ try { if ($lastExitCode -ne 0) { throw "Error: 'git push origin $TagName' failed!" } [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds - "✅ created new tag '$TagName' in $Elapsed sec" + "✅ Created new tag '$TagName' in $Elapsed sec" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/new-user.ps1 b/scripts/new-user.ps1 index 61d13178..1c393a55 100755 --- a/scripts/new-user.ps1 +++ b/scripts/new-user.ps1 @@ -29,6 +29,6 @@ try { "✅ Created user account '$username' with encrypted home directory in $($elapsed)s." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/pull-repo.ps1 b/scripts/pull-repo.ps1 index b9552309..9495a65a 100755 --- a/scripts/pull-repo.ps1 +++ b/scripts/pull-repo.ps1 @@ -48,6 +48,6 @@ try { "✅ Repo '$dirName' updated in $($elapsed)s." exit 0 # success } catch { - "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/pull-repos.ps1 b/scripts/pull-repos.ps1 index e502b2ee..4a0b2dea 100755 --- a/scripts/pull-repos.ps1 +++ b/scripts/pull-repos.ps1 @@ -55,6 +55,6 @@ try { exit 1 } } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 } diff --git a/scripts/remove-dir.ps1 b/scripts/remove-dir.ps1 index ffdf1a28..11618dfe 100755 --- a/scripts/remove-dir.ps1 +++ b/scripts/remove-dir.ps1 @@ -8,7 +8,7 @@ Specifies the file path to the directory tree .EXAMPLE PS> ./remove-dir.ps1 C:\Temp - ⏳ Removing 'C:\Temp'... (please wait)" + ⏳ Removing directory 'C:\Temp', please wait..." ✅ Directory C:\Temp\ removed (took 9s). .LINK https://github.com/fleschutz/PowerShell @@ -20,16 +20,18 @@ param([string]$pathToDir = "") try { if ($pathToDir -eq "" ) { $pathToDir = Read-Host "Enter the file path to the obsolete directory" } - $stopWatch = [system.diagnostics.stopwatch]::startNew() - "⏳ Removing '$pathToDir'... (please wait)" - Remove-Item -Force -Recurse -Confirm:$false $pathToDir + $stopWatch = [system.diagnostics.stopwatch]::startNew() + if (!(Test-Path "$pathToDir" -pathType container)) { throw "Cannot access directory '$pathToDir'" } + + "⏳ Removing directory '$pathToDir', please wait..." + Remove-Item -force -recurse -confirm:$false $pathToDir if ($lastExitCode -ne 0) { throw "'Remove-Item' failed with exit code $lastExitCode" } [int]$elapsed = $stopWatch.Elapsed.TotalSeconds "✅ Directory $pathToDir removed (took $($elapsed)s)." exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 }