-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/origin/master'
- Loading branch information
Showing
7 changed files
with
171 additions
and
129 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
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 was deleted.
Oops, something went wrong.
115 changes: 115 additions & 0 deletions
115
build/Chocolatey/gsudo/tools/chocolateyinstall.ps1.template
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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
function MarkFileDelete { | ||
param( | ||
[parameter(Mandatory=$true)] | ||
[string] $path | ||
) | ||
|
||
Add-Type @' | ||
using System; | ||
using System.Text; | ||
using System.Runtime.InteropServices; | ||
|
||
public class Posh | ||
{ | ||
public enum MoveFileFlags | ||
{ | ||
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004 | ||
} | ||
|
||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] | ||
static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags dwFlags); | ||
|
||
public static bool MarkFileDelete (string sourcefile) | ||
{ | ||
return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT); | ||
} | ||
} | ||
'@ | ||
$deleteResult = [Posh]::MarkFileDelete($path) | ||
|
||
if ($deleteResult) { | ||
write-Warning "(Delete of $path failed: Will be deleted at next boot.)" | ||
} else { | ||
write-Warning "(Error marking $path for deletion at next boot.)" | ||
} | ||
} | ||
|
||
Import-Module (Join-Path (Split-Path -parent $MyInvocation.MyCommand.Definition) "Uninstall-ChocolateyPath.psm1") | ||
|
||
# ********* Uninstall previous versions from $(Get-ToolsLocation)\gsudo | ||
|
||
$installPath = "$(Get-ToolsLocation)\gsudo" | ||
Uninstall-ChocolateyPath "$installPath\Current" 'Machine' | ||
|
||
$ErrorActionPreference="Ignore" | ||
|
||
# Delete symlinks in Pwsh 5. | ||
Get-ChildItem $installPath -Recurse |? LinkType -eq 'SymbolicLink'|%{$_.Delete()} | ||
# Delete the rest. | ||
Remove-Item $installPath -Recurse -Force -ErrorAction Ignore | ||
Remove-Item $installPath -Recurse -Force -ErrorAction Ignore | ||
|
||
if (Test-Path $installPath) { | ||
# Files are in use so delete failed. | ||
# Rename used files and directories. | ||
|
||
Get-ChildItem $installPath -Recurse -Exclude "*.deleteMe" | Sort-Object -Descending {(++$script:i)} | % { Rename-Item -Path $_.FullName -NewName ($_.Name + ".deleteMe") ; } *> $NULL | ||
# Mark remaining for delete after restart. | ||
Get-ChildItem $installPath -Recurse | % { MarkFileDelete ( $_.FullName) } | ||
MarkFileDelete ( $installPath ); | ||
} | ||
|
||
# ********* Install new versions using From GitHub's .MSI file. ** Based From Choco MSI Template. | ||
|
||
$ErrorActionPreference = 'Stop'; | ||
|
||
$packageName= 'gsudo' | ||
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" | ||
#$fileLocation = Join-Path $toolsDir 'NAME_OF_EMBEDDED_INSTALLER_FILE' | ||
|
||
$packageArgs = @{ | ||
packageName = $packageName | ||
unzipLocation = $toolsDir | ||
fileType = 'MSI' | ||
url = 'https://github.com/gerardog/gsudo/releases/download/v#VERSION#/gsudoSetup.msi' # download url, HTTPS preferred | ||
url64bit = 'https://github.com/gerardog/gsudo/releases/download/v#VERSION#/gsudoSetup.msi' # 64bit URL here (HTTPS preferred) or remove - if installer contains both (very rare), use $url | ||
# url = '[[Url]]' # download url, HTTPS preferred | ||
# url64bit = '[[Url64]]' # 64bit URL here (HTTPS preferred) or remove - if installer contains both (very rare), use $url | ||
#file = $fileLocation | ||
|
||
softwareName = 'gsudo v*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique | ||
|
||
checksum = '#SHA#' | ||
checksumType = 'sha256' #default is md5, can also be sha1, sha256 or sha512 | ||
checksum64 = '#SHA#' | ||
checksumType64= 'sha256' | ||
|
||
silentArgs = "" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0 | ||
validExitCodes= @(0, 3010, 1641) | ||
} | ||
|
||
#https://chocolatey.org/docs/helpers-install-chocolatey-package | ||
Install-ChocolateyPackage @packageArgs | ||
## If you are making your own internal packages (organizations), you can embed the installer or | ||
## put on internal file share and use the following instead (you'll need to add $file to the above) | ||
# https://chocolatey.org/docs/helpers-install-chocolatey-install-package | ||
#Install-ChocolateyInstallPackage @packageArgs | ||
|
||
# gsudo powershell module banner. | ||
""; | ||
|
||
Update-SessionEnvironment | ||
|
||
if (Get-Module gsudoModule) { | ||
if ((get-Module gsudoModule).Path) | ||
" Import-Module `'$((Get-Command gsudoModule.psd1).Source)`'" | ||
} else { | ||
& { | ||
"PowerShell users: To use enhanced gsudo and Invoke-Gsudo cmdlet, add the following line to your `$PROFILE" | ||
" Import-Module `'$((Get-Command gsudoModule.psd1).Source)`'" | ||
"Or run: " | ||
" Get-Command gsudoModule.psd1 | % { Write-Output `"``nImport-Module ```"`$(`$_.Source)```"`" | Add-Content `$PROFILE }" | ||
} | ||
Write-Output "`ngsudo successfully installed. Please restart your consoles to use gsudo.`n" | ||
|
||
} |
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,68 +1,47 @@ | ||
Import-Module (Join-Path (Split-Path -parent $MyInvocation.MyCommand.Definition) "Uninstall-ChocolateyPath.psm1") | ||
|
||
function MarkFileDelete { | ||
param( | ||
[parameter(Mandatory=$true)] | ||
[string] $path | ||
) | ||
|
||
# the code below has been used from | ||
# https://blogs.technet.com/b/heyscriptingguy/archive/2013/10/19/weekend-scripter-use-powershell-and-pinvoke-to-remove-stubborn-files.aspx | ||
# with inspiration from | ||
# http://www.leeholmes.com/blog/2009/02/17/moving-and-deleting-really-locked-files-in-powershell/ | ||
# and error handling from | ||
# https://blogs.technet.com/b/heyscriptingguy/archive/2013/06/25/use-powershell-to-interact-with-the-windows-api-part-1.aspx | ||
|
||
Add-Type @' | ||
using System; | ||
using System.Text; | ||
using System.Runtime.InteropServices; | ||
public class Posh | ||
{ | ||
public enum MoveFileFlags | ||
{ | ||
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004 | ||
} | ||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] | ||
static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags dwFlags); | ||
public static bool MarkFileDelete (string sourcefile) | ||
{ | ||
return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT); | ||
} | ||
$ErrorActionPreference = 'Stop'; # stop on all errors | ||
|
||
$packageName = 'gsudo' | ||
$softwareName = 'gsudo v*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique | ||
$installerType = 'MSI' | ||
$silentArgs = '/qn /norestart' | ||
# https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx | ||
$validExitCodes = @(0, 3010, 1605, 1614, 1641) | ||
|
||
$uninstalled = $false | ||
# Get-UninstallRegistryKey is new to 0.9.10, if supporting 0.9.9.x and below, | ||
# take a dependency on "chocolatey-uninstall.extension" in your nuspec file. | ||
# This is only a fuzzy search if $softwareName includes '*'. Otherwise it is | ||
# exact. In the case of versions in key names, we recommend removing the version | ||
# and using '*'. | ||
[array]$key = Get-UninstallRegistryKey -SoftwareName $softwareName | ||
|
||
if ($key.Count -eq 1) { | ||
$key | ForEach-Object { | ||
$file = "$($_.UninstallString)" | ||
|
||
if ($installerType -eq 'MSI') { | ||
# The Product Code GUID is all that should be passed for MSI, and very | ||
# FIRST, because it comes directly after /x, which is already set in the | ||
# Uninstall-ChocolateyPackage msiargs (facepalm). | ||
$silentArgs = "$($_.PSChildName) $silentArgs" | ||
|
||
# Don't pass anything for file, it is ignored for msi (facepalm number 2) | ||
# Alternatively if you need to pass a path to an msi, determine that and | ||
# use it instead of the above in silentArgs, still very first | ||
$file = '' | ||
} | ||
'@ | ||
$deleteResult = [Posh]::MarkFileDelete($path) | ||
|
||
if ($deleteResult) { | ||
write-Warning "(Delete of $path failed: Will be deleted at next boot.)" | ||
} else { | ||
write-Warning "(Error marking $path for deletion at next boot.)" | ||
} | ||
} | ||
|
||
|
||
$installPath = "$(Get-ToolsLocation)\gsudo" | ||
Uninstall-ChocolateyPath "$installPath\Current" 'Machine' | ||
|
||
$ErrorActionPreference="Ignore" | ||
|
||
# Delete symlinks in Pwsh 5. | ||
Get-ChildItem $installPath -Recurse |? LinkType -eq 'SymbolicLink'|%{$_.Delete()} | ||
# Delete the rest. | ||
Remove-Item $installPath -Recurse -Force -ErrorAction Ignore | ||
Remove-Item $installPath -Recurse -Force -ErrorAction Ignore | ||
|
||
if (Test-Path $installPath) { | ||
# Files are in use so delete failed. | ||
# Rename used files and directories. | ||
|
||
Get-ChildItem $installPath -Recurse -Exclude "*.deleteMe" | Sort-Object -Descending {(++$script:i)} | % { Rename-Item -Path $_.FullName -NewName ($_.Name + ".deleteMe") ; } *> $NULL | ||
# Mark remaining for delete after restart. | ||
Get-ChildItem $installPath -Recurse | % { MarkFileDelete ( $_.FullName) } | ||
MarkFileDelete ( $installPath ); | ||
} | ||
|
||
$ErrorActionPreference = 'Continue' | ||
Uninstall-ChocolateyPackage -PackageName $packageName ` | ||
-FileType $installerType ` | ||
-SilentArgs "$silentArgs" ` | ||
-ValidExitCodes $validExitCodes ` | ||
-File "$file" | ||
} | ||
} elseif ($key.Count -eq 0) { | ||
Write-Warning "$packageName has already been uninstalled by other means." | ||
} elseif ($key.Count -gt 1) { | ||
Write-Warning "$key.Count matches found!" | ||
Write-Warning "To prevent accidental data loss, no programs will be uninstalled." | ||
Write-Warning "Please alert package maintainer the following keys were matched:" | ||
$key | ForEach-Object {Write-Warning "- $_.DisplayName"} | ||
} |
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