diff --git a/base.linux/Backup-ViaSyncoid.ps1 b/base.linux/Backup-ViaSyncoid.ps1 new file mode 100644 index 0000000..4ae6e70 --- /dev/null +++ b/base.linux/Backup-ViaSyncoid.ps1 @@ -0,0 +1,9 @@ +[CmdletBinding()]param( + [switch]$NoClearScreen, + [string]$DataSet = 'szmedia/nextcloud', + [string]$DestBackupRoot = '_gw:z/szbackup' +) +if( -not $NoClearScreen ) { Clear-Host } +Write-Verbose "& syncoid --recursive `$DataSet{'$DataSet'} `"`$DestBackupRoot/`$DataSet`"{`"$DestBackupRoot/$DataSet`"}" +& syncoid --recursive $DataSet "$DestBackupRoot/$DataSet" +Write-Host "`n"*2 diff --git a/base/Get-ScriptFunction.ps1 b/base/Get-ScriptFunction.ps1 new file mode 100644 index 0000000..a4acec0 --- /dev/null +++ b/base/Get-ScriptFunction.ps1 @@ -0,0 +1,32 @@ +[CmdletBinding()]param( + [string[]]$Path + # Path to script +) +BEGIN{} +PROCESS{ + foreach( $local:scriptPath in $Path ) { + $rs = [runspacefactory]::CreateRunspace() + $rs.Open() + + # Get the AST of the file + $tokens = $errors = $null + $ast = [System.Management.Automation.Language.Parser]::ParseFile( + $scriptPath, + [ref]$tokens, + [ref]$errors) + + # Get only function definition ASTs + $functionDefinitions = $ast.FindAll({ + param([System.Management.Automation.Language.Ast] $Ast) + + $Ast -is [System.Management.Automation.Language.FunctionDefinitionAst] -and + # Class methods have a FunctionDefinitionAst under them as well, but we don't want them. + ($PSVersionTable.PSVersion.Major -lt 5 -or + $Ast.Parent -isnot [System.Management.Automation.Language.FunctionMemberAst]) + + }, $true) + + $functionDefinitions + } +} +END{} diff --git a/docker/Aliases/edc.ps1 b/docker/Aliases/edc.ps1 new file mode 100644 index 0000000..e95205b --- /dev/null +++ b/docker/Aliases/edc.ps1 @@ -0,0 +1 @@ +Edit-MyConfig diff --git a/docker/Aliases/eds.ps1 b/docker/Aliases/eds.ps1 new file mode 100644 index 0000000..f81eb02 --- /dev/null +++ b/docker/Aliases/eds.ps1 @@ -0,0 +1 @@ +Edit-MyScript diff --git a/docker/Edit-DockerCompose.ps1 b/docker/Edit-DockerCompose.ps1 index ebda20c..a332de1 100644 --- a/docker/Edit-DockerCompose.ps1 +++ b/docker/Edit-DockerCompose.ps1 @@ -16,7 +16,7 @@ foreach( $local:ext in @('.yml', '.yaml') ) { $local:testPath = Join-Path $path $fileName if( $Force -or $(Test-Path $testPath) ) { $editFiles += $testPath | Get-Path - $editFiles += Get-ChildItem $(Join-Path $path '*') -Include $EditBonus -Depth 1 | + $editFiles += Get-ChildItem $(Join-Path $path '*') -Include $EditBonus -Depth 1 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName } } diff --git a/git/Get-GitRepo.ps1 b/git/Get-GitRepo.ps1 index 342c77a..8252d16 100644 --- a/git/Get-GitRepo.ps1 +++ b/git/Get-GitRepo.ps1 @@ -3,10 +3,11 @@ [string]$LocalPath, [Parameter(Mandatory)] [string]$GitOrigin, - [string]$Branch='HEAD' + [string]$Branch='HEAD', + [switch]$sudo ) $local:gitPath = Join-Path 'themes' 'plextheme' | Get-Path -function doGit { git "--git-dir=`"$(Join-Path $LocalPath '.git')`"" "--work-tree=`"$LocalPath`"" $args } +function doGit { & $(if($sudo){"sudo"}) git "--git-dir=`"$(Join-Path $LocalPath '.git')`"" "--work-tree=`"$LocalPath`"" $args } $local:savedErrorActionPreference = $ErrorActionPreference $ErrorActionPreference = 'Stop' $local:exists = Test-Path $LocalPath diff --git a/git/Refresh-GitRepo.ps1 b/git/Refresh-GitRepo.ps1 index dab380d..a708c95 100644 --- a/git/Refresh-GitRepo.ps1 +++ b/git/Refresh-GitRepo.ps1 @@ -1,7 +1,15 @@ -$local:workTree = git worktree list --porcelain | Select-String worktree | ForEach-Object { $_ -split 'worktree ' } | Where-Object { $_ } +[CmdletBinding(SupportsShouldProcess)]param( + [switch]$sudo +) +$local:workTree = git worktree list --porcelain | + Select-String worktree | + ForEach-Object { $_ -split 'worktree ' } | + Where-Object { $_ } +$local:sudoCmd = [string]::Empty +if( $sudo ) { $sudoCmd = "env sudo" } Push-Location $workTree -$null = git reset HEAD -$null = git rm --cached -r . -$null = git add . +$null = Invoke-Expression "& $sudoCmd git reset HEAD 2>&1" +$null = Invoke-Expression "& $sudoCmd git rm --cached -r . 2>&1" +$null = Invoke-Expression "& $sudoCmd git add . 2>&1" git status Pop-Location