diff --git a/BitWarden/_.package.json b/BitWarden/_.package.json new file mode 100644 index 0000000..ccb690e --- /dev/null +++ b/BitWarden/_.package.json @@ -0,0 +1,19 @@ +{ + "package": { + "Name": "BitWarden", + "Condition": [ + { + "custom": null, + "System": null, + "Hostname": null, + "Username": null, + "CmdletExists": null, + "ModuleExists": null, + "AppExeExists": [ + "bw" + ], + "Logic": 0 + } + ] + } +} diff --git a/BitWarden/profile.d/env.ps1 b/BitWarden/profile.d/env.ps1 new file mode 100644 index 0000000..8b8eb9b --- /dev/null +++ b/BitWarden/profile.d/env.ps1 @@ -0,0 +1,10 @@ +if( -not (Test-Path env:BITWARDEN_CLI_PATH) ) { + $env:BITWARDEN_CLI_PATH = Get-Command bw -Type Application | Select-Object -First 1 -ExpandProperty Source +} + +$local:bwPath = Join-Path $HOME 'tmp' +$null = New-Item -ItemType Directory -Path $bwPath -Force +$bwPath = Join-Path $bwPath 'git-credential-bw.key' +if( Test-Path $bwPath ) { + $env:BW_SESSION= Get-Content $bwPath +} \ No newline at end of file diff --git a/BitWarden/src/modules.json b/BitWarden/src/modules.json new file mode 100644 index 0000000..ce3be90 --- /dev/null +++ b/BitWarden/src/modules.json @@ -0,0 +1,6 @@ +{ + "Always": [ + "BitwardenWrapper" + ] +} + diff --git a/HomeAssistant/Get-HA_Addon.ps1 b/HomeAssistant/Get-HA_Addon.ps1 index a9a43ef..0c25a03 100644 --- a/HomeAssistant/Get-HA_Addon.ps1 +++ b/HomeAssistant/Get-HA_Addon.ps1 @@ -1,5 +1,7 @@ [CmdletBinding(SupportsShouldProcess)]param( + [Alias('Slug')] [string[]]$AddOnSlug, + [Alias('Name')] [string[]]$AddOnName, [switch]$InspectContainer, [switch]$NoPatternMatch, @@ -14,7 +16,7 @@ $addons = $addons.data.addons switch( $Status ) { 'Installed' { $addons = $addons | Where-Object Installed } 'NotInstalled' { $addons = $addons | Where-Object -Not Installed } - 'Running' { + default { $addons = $addons | Where-Object Installed $InspectContainer = $true } @@ -49,7 +51,7 @@ switch( $Status ) { $addons = $addons | Where-Object Status -eq 'running' } 'Stopped' { - $addons = $addons | Where-Object Status -eq 'running' + $addons = $addons | Where-Object Status -ne 'running' } } diff --git a/HomeAssistant/Start-HA_Addon.ps1 b/HomeAssistant/Start-HA_Addon.ps1 index 6c05c28..3319184 100644 --- a/HomeAssistant/Start-HA_Addon.ps1 +++ b/HomeAssistant/Start-HA_Addon.ps1 @@ -1,8 +1,23 @@ [CmdletBinding(SupportsShouldProcess)]param( + [Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName)] + [Alias('Slug')] [string[]]$AddOnSlug, [switch]$NoPatternMatch ) -Get-HA_Addon 'Installed' -AddOnSlug:$AddOnSlug -NoPatternMatch:$NoPatternMatch | ForEach-Object { - Invoke-HomeAssistantCli addons start $_.slug +begin{} +process{ + foreach( $slug in $AddOnSlug ) { + Get-HA_Addon 'Running' -AddOnSlug:$slug -NoPatternMatch:$NoPatternMatch | ForEach-Object { + $local:a = $_ + $local:invocation = Invoke-HomeAssistantCli addons start $a.slug + Get-HA_Addon -InspectContainer -NoPatternMatch -AddOnSlug $a.slug | + Select-Object @{ + L='result';E={$invocation.result} + },@{ + L='data';E={$invocation.data} + },* + } + } } +end{} diff --git a/HomeAssistant/Stop-HA_Addon.ps1 b/HomeAssistant/Stop-HA_Addon.ps1 index dc4b65d..a1d9166 100644 --- a/HomeAssistant/Stop-HA_Addon.ps1 +++ b/HomeAssistant/Stop-HA_Addon.ps1 @@ -1,8 +1,23 @@ [CmdletBinding(SupportsShouldProcess)]param( + [Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName)] + [Alias('Slug')] [string[]]$AddOnSlug, [switch]$NoPatternMatch ) -Get-HA_Addon 'Running' -AddOnSlug:$AddOnSlug -NoPatternMatch:$NoPatternMatch | ForEach-Object { - Invoke-HomeAssistantCli addons stop $_.slug +begin{} +process{ + foreach( $slug in $AddOnSlug ) { + Get-HA_Addon 'Running' -AddOnSlug:$slug -NoPatternMatch:$NoPatternMatch | ForEach-Object { + $local:a = $_ + $local:invocation = Invoke-HomeAssistantCli addons stop $a.slug + Get-HA_Addon -InspectContainer -NoPatternMatch -AddOnSlug $a.slug | + Select-Object @{ + L='result';E={$invocation.result} + },@{ + L='data';E={$invocation.data} + },* + } + } } +end{} diff --git a/Proxmox/Restart-Proxmox.ps1 b/Proxmox/Restart-Proxmox.ps1 new file mode 100644 index 0000000..83bfffa --- /dev/null +++ b/Proxmox/Restart-Proxmox.ps1 @@ -0,0 +1,9 @@ + +sudo killall -9 corosync +sudo systemctl restart pve-cluster +sudo systemctl restart pvedaemon +sudo systemctl restart pveproxy +sudo systemctl restart pvestatd + +sudo qm stop 100 +sudo qm start 100 diff --git a/Proxmox/_.package.json b/Proxmox/_.package.json new file mode 100644 index 0000000..b9138ac --- /dev/null +++ b/Proxmox/_.package.json @@ -0,0 +1,17 @@ +{ + "package": { + "Name": "Proxmox", + "Condition": [ + { + "custom": null, + "System": [ "Linux" ], + "Hostname": null, + "Username": null, + "CmdletExists": null, + "ModuleExists": null, + "AppExeExists": "/usr/sbin/qm", + "Logic": 0 + } + ] + } +} diff --git a/base.linux/Edit-MountUnit.ps1 b/base.linux/Edit-MountUnit.ps1 index b9f8d69..2ee1430 100644 --- a/base.linux/Edit-MountUnit.ps1 +++ b/base.linux/Edit-MountUnit.ps1 @@ -5,6 +5,10 @@ $local:pathChar = [IO.Path]::DirectorySeparatorChar $MountPath = Get-Path $MountPath -$local:MountName = $MountPath -replace '-','\\x2d' -replace $pathChar,'-' -replace '^-','' -replace '-^','' +$local:MountName = $($($( + $MountPath -replace '-','\\x2d' + ).Replace( $pathChar, '-' ) + ) -replace '^-','' +) $MountName diff --git a/base.linux/Update-OSz.ps1 b/base.linux/Update-OSz.ps1 index a82dfcc..8a8df0a 100644 --- a/base.linux/Update-OSz.ps1 +++ b/base.linux/Update-OSz.ps1 @@ -5,6 +5,10 @@ param( $local:detectedDisistro = cat /etc/os-release | Select-String -Pattern "^ID=" | ForEach-Object { $_ -split '=' | Select-Object -Skip 1 } switch ($detectedDisistro) { - 'arch' { Update-ArchOSz -Mode:$Mode $args } - 'ubuntu' { Update-UbuntuOSz -Mode:$Mode $args } + 'arch' { + Update-ArchOSz -Mode:$Mode $args + } + {$_ -in 'debian','ubuntu','zorin'} { + Update-UbuntuOSz -Mode:$Mode $args + } } diff --git a/base.linux/profile.d/env.ps1 b/base.linux/profile.d/env.ps1 index 4e3e64d..56073a8 100644 --- a/base.linux/profile.d/env.ps1 +++ b/base.linux/profile.d/env.ps1 @@ -6,4 +6,21 @@ if( -not (Test-Path env:XDG_DATA_HOME) ) { } if( -not (Test-Path env:XDG_CONFIG_HOME) ) { $env:XDG_CONFIG_HOME="$HOME/.config" -} \ No newline at end of file +} + +if( -not ( + Test-Path env:SHELL_PARENT + ) -and -not ( + $env:SHELL -match 'p(wsh|owershell)$' + ) -and ( + Test-Path env:SHELL + ) +) { + $env:COMPLETION_SHELL_PREFERENCE = $env:SHELL + $env:SHELL_PARENT = $env:SHELL +} +$env:SHELL = Get-Process -Id $PID | Select-Object -ExpandProperty Path +Get-Command -ListImported Set-UnixCompleter -ErrorAction Ignore | + ForEach-Object { + Set-UnixCompleter -Shell $env:COMPLETION_SHELL_PREFERENCE + } diff --git a/base/Get-Path.ps1 b/base/Get-Path.ps1 index c07385e..b12326b 100644 --- a/base/Get-Path.ps1 +++ b/base/Get-Path.ps1 @@ -5,17 +5,6 @@ [string[]]$Path ) process { - - function Get-FullPath { - param([string]$Path) - - if([System.IO.Path]::IsPathRooted($Path)){ - [System.IO.Path]::GetFullPath($Path) - }else{ - [System.IO.Path]::GetFullPath((Join-Path $PWD $Path)) - } - } - foreach( $local:p in $Path ) { switch( $p[0] ) { '@' { $p = Join-Path $MyPSScriptRoot $p.Substring(1) } @@ -27,6 +16,9 @@ process { } } + # clean end of path from DirectorySeparatorChars + $p = $p -replace '[/\\]+$','' + $p = $p -replace '#C-','#C-#' -replace '\*','#C-A#' -replace '\?','#C-Q#' if([System.IO.Path]::IsPathRooted($p)){ $p = [System.IO.Path]::GetFullPath($p) @@ -44,9 +36,3 @@ process { $p } } -# try { -# get-item $Path -Force -ErrorAction Stop | -# Select-Object -ExpandProperty FullName -# } catch { -# $_.targetObject -# } diff --git a/docker/profile.d/Docker.class.ps1 b/docker/profile.d/Docker.class.ps1 index 79444d9..3720c12 100644 --- a/docker/profile.d/Docker.class.ps1 +++ b/docker/profile.d/Docker.class.ps1 @@ -37,6 +37,7 @@ class DockerNetworks { } } +if( -not (Get-Command docker-compose -ErrorAction Ignore) ) { return } class DockerComposeCommands { #: System.Management.Automation.IValidateSetValuesGenerator { static [string[]] $cachedCommands = @() static [string[]] _GetValidValues([string]$wordToComplete,[string]$subcommand,[bool]$Strict) { diff --git a/zfs/Aliases/zls.ps1 b/zfs/Aliases/zls.ps1 new file mode 100644 index 0000000..1261402 --- /dev/null +++ b/zfs/Aliases/zls.ps1 @@ -0,0 +1 @@ +Get-ZfsItem diff --git a/zfs/Get-ZfsItem.ps1 b/zfs/Get-ZfsItem.ps1 new file mode 100644 index 0000000..3cc1d13 --- /dev/null +++ b/zfs/Get-ZfsItem.ps1 @@ -0,0 +1,25 @@ +[CmdletBinding()]param( + [string[]]$Options='name,used,avail,refer,canmount,mounted,mountpoint' +) + +$Options = $Options -join ',' +if( $options -split ',' -notcontains 'name' ) { $options = "name,$Options" } +$local:prev = ''; +zfs list -o $Options | + ForEach-Object { $_ -replace ' +',"`t" } | + ConvertFrom-Csv -Delimiter "`t" | + Where-Object Name -NotMatch '^rpool/var/lib/docker/' | + ForEach-Object { + $local:o = $_ | Select-Object @{L='-';E={''}},* + $local:tmpPrev = $o.Name -replace '^(\w+(\W\w+(\W\w+)?)?).*','$1'; + if( $tmpPrev -notmatch "^$prev" -and $prev -notin ('','NAME') ) { + $o.'-' = "`n-" + }; + $prev = $tmpPrev; + if( $o.MOUNTPOINT ) { + $o.MOUNTPOINT = $o.MOUNTPOINT -replace '^none$','' + } + $o + } | + Format-Table -Wrap + diff --git a/zfs/zls.ps1 b/zfs/zls.ps1 deleted file mode 100644 index cc156e1..0000000 --- a/zfs/zls.ps1 +++ /dev/null @@ -1,11 +0,0 @@ -$local:prev = ""; -zfs list -o name,used,avail,refer,canmount,mounted,mountpoint $args | - grep -v 'docker/' | - ForEach-Object { - $local:tmpPrev = $_ -replace '^(\w+(\W\w+(\W\w+)?)?).*','$1'; - if( $tmpPrev -notmatch "^$prev" -and $prev -notin ('','NAME') ) { - '-----------------' - }; - $prev = $tmpPrev; - $_ - } \ No newline at end of file