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:
parent
5dae2a2af5
commit
6d2a23ae04
|
@ -171,10 +171,10 @@ Get-Command Reload-MyScripts -ErrorAction SilentlyContinue | ForEach-Object { .
|
||||||
Invoke-ExpressionEx -sudo:$shouldSudo chmod 'a+r' $tmpOutput.FullName
|
Invoke-ExpressionEx -sudo:$shouldSudo chmod 'a+r' $tmpOutput.FullName
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$local:errMsg = $(Invoke-ExpressionEx -sudo:$shouldSudo @"
|
$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 };
|
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;
|
`$null = Copy-Item "$($tmpOutput.FullName)" "$p" -Force:`$$Force -ErrorAction Stop;
|
||||||
Remove-Item $($tmpOutput.FullName) -Force:`$$Force -ErrorAction SilentlyContinue
|
Remove-Item "$($tmpOutput.FullName)" -Force:`$$Force -ErrorAction SilentlyContinue
|
||||||
"@ 2>&1)
|
"@ 2>&1)
|
||||||
if ( $errMsg ) {
|
if ( $errMsg ) {
|
||||||
Write-Error "$errMsg"
|
Write-Error "$errMsg"
|
||||||
|
@ -268,7 +268,7 @@ function Invoke-ExpressionEx {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $PSVersionTable.Platform -eq 'Unix' ) {
|
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 {
|
else {
|
||||||
$local:currentIdenity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
$local:currentIdenity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
|
@ -437,7 +437,8 @@ $SetupFromWeb = [bool]$(@( $SetupFromWeb, $sfw, $LoadCode ) | Where-Object { $_
|
||||||
|
|
||||||
if ( -not $SetupFromWeb ) {
|
if ( -not $SetupFromWeb ) {
|
||||||
_setup @PSBoundParameters
|
_setup @PSBoundParameters
|
||||||
Get-Item function:_setup | Remove-Item
|
Get-Item function:_setup | Remove-Item -Confirm:$false
|
||||||
Get-Command Reload-MyScripts -ErrorAction SilentlyContinue | ForEach-Object { . $_.Name }
|
Get-Command Reload-MyScripts -ErrorAction SilentlyContinue |
|
||||||
|
ForEach-Object { . $_.Name -Confirm:$false }
|
||||||
}
|
}
|
||||||
Remove-Variable SetupFromWeb -ErrorAction SilentlyContinue
|
Remove-Variable SetupFromWeb -ErrorAction SilentlyContinue -Confirm:$false
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
param([switch]$IgnoreSystem,[switch]$MissingOnly)
|
||||||
|
|
||||||
|
$local:currentSys = @('Always') + ([SystemName]::_GetValidValues('',$true,$true));
|
||||||
|
|
||||||
|
[MyConfig]::GetConfigPaths('mymodules',$false) |
|
||||||
|
ForEach-Object {
|
||||||
|
$local:modules = $( Get-Content $_ | ConvertFrom-Json );
|
||||||
|
$modules |
|
||||||
|
Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name |
|
||||||
|
Where-Object {
|
||||||
|
$IgnoreSystem -or ( $_ -in $currentSys )
|
||||||
|
} |
|
||||||
|
ForEach-Object { $modules."$_" }
|
||||||
|
} |
|
||||||
|
Where-Object {
|
||||||
|
-not $MissingOnly -or
|
||||||
|
$( try {
|
||||||
|
-not (Get-Module -ListAvailable $_ -ErrorAction stop)
|
||||||
|
} catch { $true }
|
||||||
|
)
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ process {
|
||||||
'~' {
|
'~' {
|
||||||
if( $p -match '^~[^/]*' ) {
|
if( $p -match '^~[^/]*' ) {
|
||||||
$local:m = $Matches[0]
|
$local:m = $Matches[0]
|
||||||
$p = $p -replace "^$m",((Get-Item $m).FullName)
|
$p = $p -replace "^$m",((Get-Item -Force $m).FullName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,13 @@ process {
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $Expand ) {
|
if( $Expand ) {
|
||||||
$p = $p | Get-Item | Select-Object -ExpandProperty FullName
|
$p = $p | ForEach-Object {
|
||||||
|
if( Test-Path $p ) {
|
||||||
|
$p | Get-Item -Force | Select-Object -ExpandProperty FullName
|
||||||
|
} else {
|
||||||
|
$p
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$p
|
$p
|
||||||
|
|
|
@ -1,24 +1,12 @@
|
||||||
param([switch]$Force)
|
param([switch]$Force)
|
||||||
|
|
||||||
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
|
|
||||||
|
|
||||||
if( -not $global:MyModulesWarning -or $Force ) {
|
if( -not $global:MyModulesWarning -or $Force ) {
|
||||||
$global:MyModulesWarning = @()
|
$global:MyModulesWarning = @()
|
||||||
}
|
}
|
||||||
|
|
||||||
[MyConfig]::GetConfigPaths('mymodules',$false) |
|
Get-MyModules -MissingOnly |
|
||||||
ForEach-Object {
|
Where-Object {
|
||||||
$local:modules = $( Get-Content $_ | ConvertFrom-Json );
|
$_ -notin $global:MyModulesWarning
|
||||||
$modules.Always
|
|
||||||
$currentSys | ForEach-Object { $modules."$_" }
|
|
||||||
} | Where-Object { $_ } | Where-Object {
|
|
||||||
$local:m = $_
|
|
||||||
if( $( try {
|
|
||||||
-not (Get-Module -ListAvailable $m -ErrorAction stop)
|
|
||||||
} catch { $true }
|
|
||||||
)) {
|
|
||||||
$m -notin $global:MyModulesWarning
|
|
||||||
}
|
|
||||||
} | ForEach-Object {
|
} | ForEach-Object {
|
||||||
$global:MyModulesWarning += $_
|
$global:MyModulesWarning += $_
|
||||||
Write-Warning "Missing module: $_"
|
Write-Warning "Missing module: $_"
|
||||||
|
|
Loading…
Reference in New Issue