-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpuppet-4-installer.ps1
61 lines (54 loc) · 2.42 KB
/
puppet-4-installer.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Param(
[string]$Version = "latest",
[string]$Source = "https://downloads.puppetlabs.com/windows",
[string]$Master,
[string]$CAServer,
[string]$WorkDirectory = 'C:\temp',
[switch]$x86, # You must specify X86 if you want the 32 bit mode. Nobody should want this.
[switch]$FirstRun
)
# Gather all installation options from command line.
[System.Collections.ArrayList]$installOptions = @()
If ($InstallDir) { $installOptions += "INSTALLDIR=$InstallDir"}
If ($MasterServer) { $installOptions += "PUPPET_MASTER_SERVER=$MasterServer"}
If ($CAServer) { $installOptions += "PUPPET_CA_SERVER=$CAServer "}
If ($CertName) { $installOptions += "PUPPET_AGENT_CERTNAME=$CertName "}
If ($Environment) { $installOptions += "PUPPET_AGENT_ENVIRONMENT=$Environment "}
If ($StartupMode) { $installOptions += "PUPPET_AGENT_STARTUP_MODE=$StartupMode "}
If ($User) { $installOptions += "PUPPET_AGENT_ACCOUNT_USER=$User "}
If ($Password) { $installOptions += "PUPPET_AGENT_ACCOUNT_PASSWORD=$Password "}
If ($Domain) { $installOptions += "PUPPET_AGENT_ACCOUNT_DOMAIN=$Domain "}
# Setup the work directory
If ((Test-Path $WorkDirectory) -match 'False') {
Write-Host "Creating Work Directory at $WorkDirectory..."
New-Item -ItemType Directory -Path $WorkDirectory
}
# Set the package name based on Puppet Labs current naming convention for the Windows agent.
switch($Version) {
"latest" {
If ($x86) { $package = "puppet-latest.msi" } else { $package = "puppet-x64-latest.msi" }
}
default {
If ($x86) { $package = "puppet-agent-$Version-x86.msi" } else { $package = "puppet-agent-$Version-x64.msi" }
}
}
# Setup the rest of our variables
$installPuppet = "${WorkDirectory}\${package}"
$installArguments = '/burp'
$runPuppet = 'C:\Program Files\Puppet Labs\Puppet\bin\puppet.bat -agent -t'
# Download Puppet from Puppet Labs
try {
Write-Host "Downloading Puppet 4 package - ${package}..."
Invoke-WebRequest ${source}/${package} -OutFile ${WorkDirectory}\${package}
} catch {
Write-Host "ERROR - MSI Could not be downloaded. Please check version and try again."
}
# Install the Puppet agent MSI
Write-Host "Installing Puppet Open Source 4.0 Windows Agent from ${installPuppet}..."
$installOptions.Insert(0,$installArguments)
Start-Process $installPuppet $installOptions -Wait
# Run Puppet for the first time if given the -FirstRun commandline switch
If ($FirstRun) {
Write-Host "Starting initial Puppet run..."
Start-Process $runPuppet -wait
}