Modify Setup, Path, added Get-MyModules

+ base/Get-MyModules added
* base/profile.d/Test-MyModules modified to use Get-MyModules
* Setup-Profile modified so that sudo witll preserve environment
* Get-Path fixed bug introduced in last commit, Get-Path would fail when
  file to be edited didn't exist
This commit is contained in:
lksz 2021-02-19 19:22:46 -05:00
parent 5dae2a2af5
commit 6d2a23ae04
4 changed files with 41 additions and 25 deletions

View file

@ -171,10 +171,10 @@ Get-Command Reload-MyScripts -ErrorAction SilentlyContinue | ForEach-Object { .
Invoke-ExpressionEx -sudo:$shouldSudo chmod 'a+r' $tmpOutput.FullName
}
try {
$local:errMsg = $(Invoke-ExpressionEx -sudo:$shouldSudo @"
if( -not (Test-Path $(Split-Path -Parent $p)) ) { New-Item -Type Directory $(Split-Path -Parent $p) -Force };
Copy-Item $($tmpOutput.FullName) $p -Force:`$$Force -ErrorAction Stop | Out-Null;
Remove-Item $($tmpOutput.FullName) -Force:`$$Force -ErrorAction SilentlyContinue
$local:errMsg = $(Invoke-ExpressionEx -Confirm:$false -sudo:$shouldSudo @"
if( -not (Test-Path $(Split-Path -Parent $p)) ) { New-Item -Type Directory "$(Split-Path -Parent $p)" -Force };
`$null = Copy-Item "$($tmpOutput.FullName)" "$p" -Force:`$$Force -ErrorAction Stop;
Remove-Item "$($tmpOutput.FullName)" -Force:`$$Force -ErrorAction SilentlyContinue
"@ 2>&1)
if ( $errMsg ) {
Write-Error "$errMsg"
@ -268,7 +268,7 @@ function Invoke-ExpressionEx {
}
if ( $PSVersionTable.Platform -eq 'Unix' ) {
/usr/bin/env sudo $(Get-PowerShellPath) "-noprofile" "-EncodedCommand" $(ConvertTo-Base64 $sudo_cmd)
/usr/bin/env sudo "--preserve-env" $(Get-PowerShellPath) "-noprofile" "-EncodedCommand" $(ConvertTo-Base64 $sudo_cmd)
}
else {
$local:currentIdenity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
@ -437,7 +437,8 @@ $SetupFromWeb = [bool]$(@( $SetupFromWeb, $sfw, $LoadCode ) | Where-Object { $_
if ( -not $SetupFromWeb ) {
_setup @PSBoundParameters
Get-Item function:_setup | Remove-Item
Get-Command Reload-MyScripts -ErrorAction SilentlyContinue | ForEach-Object { . $_.Name }
Get-Item function:_setup | Remove-Item -Confirm:$false
Get-Command Reload-MyScripts -ErrorAction SilentlyContinue |
ForEach-Object { . $_.Name -Confirm:$false }
}
Remove-Variable SetupFromWeb -ErrorAction SilentlyContinue
Remove-Variable SetupFromWeb -ErrorAction SilentlyContinue -Confirm:$false