-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47ef43f
commit d0cbda9
Showing
5 changed files
with
72 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,6 @@ | |
"commitizen", | ||
"cz-git", | ||
"degit", | ||
"git-open", | ||
"newman" | ||
], | ||
"install": true | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,64 @@ | ||
function Test-IsElevated { | ||
return (New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | ||
} | ||
|
||
function Update-Modules { | ||
<# | ||
.SYNOPSIS | ||
Update all installed modules | ||
.EXAMPLE | ||
Update-Modules -Scope CurrentUser | ||
.PARAMETER AllowPrerelease | ||
Updating module to latest prerelease version. | ||
.PARAMETER WhatIf | ||
Run function without actually executing it. | ||
.PARAMETER Name | ||
Name of the module you want to update. | ||
.PARAMETER Scope | ||
The scope apply when updating modules. | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Alias('p')][switch]$AllowPrerelease, | ||
[Alias('n', '-dry-run')][switch]$WhatIf, | ||
[switch]$AllowPrerelease, | ||
|
||
[switch]$WhatIf, | ||
|
||
[string]$Name = "*", | ||
[ValidateSet('AllUsers', 'CurrentUser')][string]$Scope = 'CurrentUser' | ||
|
||
[ValidateSet('AllUsers', 'CurrentUser')] | ||
[string]$Scope = "CurrentUser" | ||
) | ||
|
||
# Test elevated permissions for scope allusers | ||
if ($Scope -eq "AllUsers") { | ||
if ((Test-IsElevated) -eq $False) { | ||
if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -eq $False) { | ||
Write-Warning "Function $($MyInvocation.MyCommand) needs admin privileges to perform actions." | ||
Break | ||
break | ||
} | ||
} | ||
|
||
# Status of allow prerelease switch | ||
if ($AllowPrerelease) { | ||
'' | ||
Write-Host "Updating modules to latest " -ForegroundColor "Blue" -NoNewline | ||
Write-Host "prerelease " -ForegroundColor "Yellow" -NoNewline | ||
Write-Host "versions..." -ForegroundColor "Blue" | ||
Write-Host "-------------------------------------------------" -ForegroundColor "Blue" | ||
} else { | ||
'' | ||
Write-Host "Updating modules to latest " -ForegroundColor "Blue" -NoNewline | ||
Write-Host "stable " -ForegroundColor "Yellow" -NoNewline | ||
Write-Host "versions..." -ForegroundColor "Blue" | ||
Write-Host "---------------------------------------------" -ForegroundColor "Blue" | ||
} | ||
$CurrentModules = Get-InstalledModule -Name $Name -ErrorAction SilentlyContinue | Select-Object -Property Name, Version | Sort-Object Name | ||
|
||
# Get all installed modules | ||
if ((Test-Path "$Env:DOTFILES\modules.lock.json") -and ($Name -eq "*")) { | ||
$CurrentModules = Get-Content "$Env:DOTFILES\modules.lock.json" | ConvertFrom-Json | Select-Object -Property Name, Version | Sort-Object Name | ||
} else { | ||
$CurrentModules = Get-InstalledModule -Name $Name -ErrorAction SilentlyContinue | Select-Object -Property Name, Version | Sort-Object Name | ||
} | ||
if (!$CurrentModules) { Write-Host "No modules found." -ForegroundColor Red; return } | ||
else { | ||
$i = 1 | ||
$moduleCount = $CurrentModules.Count | ||
''; Write-Host "$moduleCount " -ForegroundColor Yellow -NoNewline; Write-Host "module(s) installed." -ForegroundColor Green; '' | ||
|
||
# If no modules installed. | ||
if (-not $CurrentModules) { | ||
'' | ||
Write-Host "No modules found." -ForegroundColor "Red" | ||
Return | ||
} else { | ||
'' | ||
$ModulesCount = $CurrentModules.Count | ||
Write-Host "$ModulesCount " -ForegroundColor "White" -NoNewLine | ||
Write-Host "module(s) installed." -ForegroundColor "Green" | ||
} | ||
if ($AllowPrerelease) { Write-Host "Trying to update modules to latest " -ForegroundColor Blue -NoNewline; Write-Host "prerelease " -NoNewline -ForegroundColor Magenta; Write-Host "version" -ForegroundColor Blue } | ||
else { Write-Host "Trying to update modules to latest " -ForegroundColor Blue -NoNewline; Write-Host "stable " -NoNewline -ForegroundColor Magenta; Write-Host "version" -ForegroundColor Blue } | ||
|
||
foreach ($Module in $CurrentModules) { | ||
'' | ||
Write-Host "Checking for updated version of module: " -ForegroundColor "Gray" -NoNewLine | ||
Write-Host "$($Module.Name)" -ForegroundColor "White" | ||
$OnlineVersion = (Find-Module -Name $Module.Name -AllVersions | Sort-Object PublishedDate -Descending)[0].Version | ||
$CurrentVersion = (Get-InstalledModule -Name $Module.Name).Version | ||
if ($CurrentVersion -lt $OnlineVersion) { | ||
try { | ||
Update-Module -Name $Module.Name -AllowPrerelease:$AllowPrerelease -Scope:$Scope -Force:$True -ErrorAction Stop -WhatIf:$WhatIf.IsPresent | ||
$CurrentVersion = $CurrentModules | Where-Object Name -EQ $Module.Name | ||
if ($CurrentVersion.Version -notlike $Module.Version) { | ||
Write-Host "Updated module $($Module.Name) from version $($CurrentVersion.Version) to $($Module.Version)" -ForegroundColor "Green" | ||
} | ||
foreach ($Version in $CurrentVersion) { | ||
if ($Version.Version -ne $CurrentVersion[0].Version) { | ||
Uninstall-Module -Name $Module.Name -RequiredVersion $Version.Version -Force:$True -ErrorAction Stop -WhatIf:$WhatIf.IsPresent | ||
} | ||
foreach ($module in $CurrentModules) { | ||
$OnlineVersion = (Find-Module -Name $($module.Name) -AllVersions | Sort-Object PublishedDate -Descending)[0].Version | ||
$CurrentVersion = (Get-InstalledModule -Name $($module.Name)).Version | ||
|
||
if ($CurrentVersion -ne $OnlineVersion) { | ||
try { | ||
Update-Module -Name $($module.Name) -AllowPrerelease:$AllowPrerelease -Scope:$Scope -Force:$True -WhatIf:$WhatIf.IsPresent | ||
} catch { | ||
Write-Error "Error occurred while updating module $($module.Name): $_" | ||
} | ||
} catch { | ||
Write-Error "Error occurred while updating module $($Module.Name): $_" | ||
} | ||
} else { | ||
Write-Host "Already up-to-date!" -ForegroundColor "Blue" | ||
|
||
[int]$percentCompleted = ($i / $moduleCount) * 100 | ||
Write-Progress -Activity "Updating Module $($module.Name)" -Status "$percentCompleted% Completed - $($module.Name) v$OnlineVersion" -PercentComplete $percentCompleted | ||
$i++ | ||
} | ||
if ($?) { Write-Host "Everything is up-to-date!" -ForegroundColor Green } | ||
} | ||
'' | ||
} |