Created
June 19, 2015 01:52
-
-
Save iDVB/9ee53de53bdcb31a37b9 to your computer and use it in GitHub Desktop.
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
$puppetVersion = '3.8.1' | |
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-$puppetVersion.msi" | |
$MsiUrlx64 = "https://downloads.puppetlabs.com/windows/puppet-$puppetVersion-x64.msi" | |
$PuppetInstallerPath = 'c:\vagrantshared\resources\installers' | |
$PuppetInstallerFile = 'puppet-agent.msi' | |
if ([System.IntPtr]::Size -eq 8) { | |
Write-Host "Going Puppet 64-bit." | |
$MsiUrl = $MsiUrlx64 | |
$PuppetInstallerFile = 'puppet-agent-x64.msi' | |
} | |
$PuppetInstaller = Join-Path $PuppetInstallerPath $PuppetInstallerFile | |
$PuppetInstalled = $false | |
try { | |
$ErrorActionPreference = "Stop"; | |
Get-Command puppet | Out-Null | |
$PuppetInstalled = $true | |
$PuppetVersion=&puppet "--version" | |
Write-Host "Puppet $PuppetVersion is installed. This process does not ensure the exact version or at least version specified, but only that puppet is installed. Exiting..." | |
Exit 0 | |
} catch { | |
Write-Host "Puppet is not installed, continuing..." | |
} | |
if (!($PuppetInstalled)) { | |
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) | |
if (! ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) { | |
Write-Host -ForegroundColor Red "You must run this script as an administrator." | |
Exit 1 | |
} | |
if (!(Test-Path $PuppetInstallerPath)) { | |
Write-Host "Creating folder `'$PuppetInstallerPath`'" | |
$null = New-Item -Path "$PuppetInstallerPath" -ItemType Directory | |
} | |
if (!(Test-Path $PuppetInstaller)) { | |
Write-Host "Downloading `'$MsiUrl`' to `'$PuppetInstaller`'" | |
(New-Object Net.WebClient).DownloadFile("$MsiUrl","$PuppetInstaller") | |
} | |
# Install it - msiexec will download from the url | |
$install_args = @("/qn", "/norestart","/i", "$PuppetInstaller") | |
Write-Host "Installing Puppet. Running msiexec.exe $install_args" | |
$process = Start-Process -FilePath msiexec.exe -ArgumentList $install_args -Wait -PassThru | |
if ($process.ExitCode -ne 0) { | |
Write-Host "Installer failed." | |
Exit 1 | |
} | |
Write-Host "Notifing processes of PATH Change" | |
# Notifies other processes that the global environment block has changed. | |
# This lets other processes pick changes to ENV: without having to reboot or logoff/logon. | |
# A non-zero result from SendMessageTimeout indicates success. | |
if (-not ("win32.nativemethods" -as [type])) { | |
# import sendmessagetimeout from win32 | |
add-type -Namespace Win32 -Name NativeMethods -MemberDefinition @" | |
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] | |
public static extern IntPtr SendMessageTimeout( | |
IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, | |
uint fuFlags, uint uTimeout, out UIntPtr lpdwResult); | |
"@ | |
} | |
$HWND_BROADCAST = [intptr]0xffff; | |
$WM_SETTINGCHANGE = 0x1a; | |
$result = [uintptr]::zero | |
# notify all windows of environment block change | |
[win32.nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [uintptr]::Zero, "Environment", 2, 5000, [ref]$result); | |
Write-Host "Puppet successfully installed." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment