2016-04-15 21:01:16 +00:00
|
|
|
# Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This source code is licensed under the BSD-style license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
2016-11-02 17:46:45 +00:00
|
|
|
# We make heavy use of Write-Host, because colors are awesome. #dealwithit.
|
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", '', Scope="Function", Target="*")]
|
|
|
|
param()
|
|
|
|
|
2016-04-15 21:01:16 +00:00
|
|
|
# URL of where our pre-compiled third-party dependenices are archived
|
2016-09-06 23:42:20 +00:00
|
|
|
$THIRD_PARTY_ARCHIVE_URL = 'https://osquery-packages.s3.amazonaws.com/choco'
|
2016-04-15 21:01:16 +00:00
|
|
|
|
|
|
|
# Adapted from http://www.jonathanmedd.net/2014/01/testing-for-admin-privileges-in-powershell.html
|
|
|
|
function Test-IsAdmin {
|
|
|
|
return ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
|
|
|
[Security.Principal.WindowsBuiltInRole] "Administrator"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-11-02 17:46:45 +00:00
|
|
|
function Test-RebootPending {
|
|
|
|
$compBasedServ = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -ErrorAction Ignore
|
|
|
|
$winUpdate = Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction Ignore
|
|
|
|
$ccm = $false
|
|
|
|
try {
|
|
|
|
$util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
|
|
|
|
$status = $util.DetermineIfRebootPending()
|
|
|
|
if(($null -ne $status) -and $status.RebootPending){
|
|
|
|
$ccm = $true
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
$ccm = $false
|
|
|
|
}
|
|
|
|
return $compBasedServ -or $winUpdate -or $ccm
|
|
|
|
}
|
|
|
|
|
2016-12-06 00:55:49 +00:00
|
|
|
# Checks for the existence of a supplied string in the System path. If the
|
|
|
|
# string does not exist, this function adds it. If it does exist this function
|
|
|
|
# does nothing.
|
|
|
|
function Add-ToPath {
|
|
|
|
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium")]
|
|
|
|
param(
|
|
|
|
[string] $appendPath = ''
|
|
|
|
)
|
|
|
|
if (-not $PSCmdlet.ShouldProcess('Add-ToPath')) {
|
|
|
|
Exit -1
|
|
|
|
}
|
|
|
|
if ($appendPath[-1] -ne ';') {
|
|
|
|
$appendPath += ';'
|
|
|
|
}
|
|
|
|
$oldPath = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
|
|
|
|
if (($appendPath[0] -ne ';') -and ($oldPath[-1] -ne ';')) {
|
|
|
|
$appendPath = ';' + $appendPath
|
|
|
|
}
|
|
|
|
if (-not ($oldPath -imatch [regex]::escape($appendPath))) {
|
|
|
|
$newPath = $oldPath + ';' + $appendPath
|
|
|
|
[System.Environment]::SetEnvironmentVariable('Path', $newPath, 'Machine')
|
|
|
|
}
|
|
|
|
# Append the newly added path to the sessions Path variable, for immediate use.
|
|
|
|
$env:Path += $appendPath
|
|
|
|
}
|
|
|
|
|
|
|
|
# Searchs the system path for a specified directory, and if exists, deletes
|
|
|
|
# the value from the system path.
|
|
|
|
function Remove-FromPath {
|
|
|
|
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium")]
|
|
|
|
param(
|
|
|
|
[string] $removePath = ''
|
|
|
|
)
|
|
|
|
if (-not $PSCmdlet.ShouldProcess('Remove-FromPath')) {
|
|
|
|
Exit -1
|
|
|
|
}
|
|
|
|
if ($removePath[-1] -ne ';') {
|
|
|
|
$removePath += ';'
|
|
|
|
}
|
|
|
|
if ($removePath[0] -ne ';') {
|
|
|
|
$removePath = ';' + $removePath
|
|
|
|
}
|
|
|
|
$oldPath = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
|
|
|
|
if ($oldPath -imatch [regex]::escape($removePath)) {
|
|
|
|
$newPath = $oldPath -Replace [regex]::escape($removePath), $NULL
|
|
|
|
[System.Environment]::SetEnvironmentVariable('Path', $newPath, 'Machine')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 06:00:26 +00:00
|
|
|
# Checks if a package is already installed through chocolatey
|
|
|
|
# Returns true if:
|
|
|
|
# * The package is installed and the user supplies no version
|
|
|
|
# * The package is installed and the version matches the user supplied version
|
2016-09-19 20:46:49 +00:00
|
|
|
function Test-ChocoPackageInstalled {
|
2016-08-29 06:00:26 +00:00
|
|
|
param(
|
|
|
|
[string] $packageName = '',
|
|
|
|
[string] $packageVersion = ''
|
|
|
|
)
|
|
|
|
$out = choco list -lr
|
|
|
|
|
|
|
|
# Parse through the locally installed chocolatey packages and look
|
|
|
|
# to see if the supplied package already exists
|
|
|
|
ForEach ($pkg in $out) {
|
|
|
|
$name, $version = $pkg -split '\|'
|
|
|
|
if ($name -eq $packageName) {
|
|
|
|
if ($packageVersion -ne "" -and $packageVersion -ne $version) {
|
|
|
|
return $false;
|
|
|
|
}
|
|
|
|
return $true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $false
|
|
|
|
}
|
|
|
|
|
2016-09-20 18:29:29 +00:00
|
|
|
# Installs the Powershell Analzyer: https://github.com/PowerShell/PSScriptAnalyzer
|
|
|
|
function Install-PowershellLinter {
|
|
|
|
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium")]
|
|
|
|
param()
|
|
|
|
if (-not $PSCmdlet.ShouldProcess('PSScriptAnalyzer')) {
|
|
|
|
Exit -1
|
|
|
|
}
|
|
|
|
|
|
|
|
$nugetProviderInstalled = $false
|
|
|
|
Write-Host " => Determining whether NuGet package provider is already installed." -foregroundcolor DarkYellow
|
2016-11-02 17:46:45 +00:00
|
|
|
foreach ($provider in Get-PackageProvider) {
|
2016-09-20 18:29:29 +00:00
|
|
|
if ($provider.Name -eq "NuGet" -and $provider.Version -ge 2.8.5.206) {
|
|
|
|
$nugetProviderInstalled = $true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (-not $nugetProviderInstalled) {
|
|
|
|
Write-Host " => NuGet provider either not installed or out of date. Installing..." -foregroundcolor Cyan
|
|
|
|
Install-PackageProvider -Name NuGet -Force
|
|
|
|
Write-Host "[+] NuGet package provider installed!" -foregroundcolor Green
|
|
|
|
} else {
|
|
|
|
Write-Host "[*] NuGet provider already installed." -foregroundcolor Green
|
|
|
|
}
|
|
|
|
|
2016-09-21 00:45:43 +00:00
|
|
|
$psScriptAnalyzerInstalled = $false
|
2016-09-20 18:29:29 +00:00
|
|
|
Write-Host " => Determining whether PSScriptAnalyzer is already installed." -foregroundcolor DarkYellow
|
|
|
|
foreach ($module in Get-Module -ListAvailable) {
|
|
|
|
if ($module.Name -eq "PSScriptAnalyzer" -and $module.Version -ge 1.7.0) {
|
2016-09-21 00:45:43 +00:00
|
|
|
$psScriptAnalyzerInstalled = $true
|
|
|
|
break
|
2016-09-20 18:29:29 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-21 00:45:43 +00:00
|
|
|
if (-not $psScriptAnalyzerInstalled) {
|
|
|
|
Write-Host " => PSScriptAnalyzer either not installed or out of date. Installing..." -foregroundcolor Cyan
|
|
|
|
Install-Module -Name PSScriptAnalyzer -Force
|
|
|
|
Write-Host "[+] PSScriptAnalyzer installed!" -foregroundcolor Green
|
|
|
|
} else {
|
|
|
|
Write-Host "[*] PSScriptAnalyzer already installed." -foregroundcolor Green
|
|
|
|
}
|
2016-09-20 18:29:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-15 21:01:16 +00:00
|
|
|
# Attempts to install chocolatey if not already
|
|
|
|
function Install-Chocolatey {
|
2016-09-19 20:46:49 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium")]
|
|
|
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingInvokeExpression", "")]
|
|
|
|
param()
|
|
|
|
if (-not $PSCmdlet.ShouldProcess('Chocolatey')) {
|
|
|
|
Exit -1
|
|
|
|
}
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host " => Attemping to detect presence of chocolatey..." -foregroundcolor DarkYellow
|
2016-09-19 20:46:49 +00:00
|
|
|
if ($null -eq (Get-Command 'choco.exe' -ErrorAction SilentlyContinue)) {
|
2016-12-06 00:55:49 +00:00
|
|
|
if (Test-Path "$env:ALLUSERSPROFILE\chocolatey\bin") {
|
|
|
|
Write-Host "[-] WARN: Chocolatey appears to be installed, but cannot be found in the system path!" -foregroundcolor Yellow
|
2016-08-29 06:00:26 +00:00
|
|
|
} else {
|
|
|
|
Write-Host " => Did not find. Installing chocolatey..." -foregroundcolor Cyan
|
2016-09-19 20:46:49 +00:00
|
|
|
Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
|
2016-08-29 06:00:26 +00:00
|
|
|
}
|
|
|
|
Write-Host " => Adding chocolatey to path."
|
2016-12-06 00:55:49 +00:00
|
|
|
$chocoPath = $env:ALLUSERSPROFILE+'\chocolatey\bin'
|
|
|
|
Add-ToPath $chocoPath
|
2016-04-15 21:01:16 +00:00
|
|
|
} else {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[*] Chocolatey is already installed." -foregroundcolor Green
|
2016-04-15 21:01:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 06:00:26 +00:00
|
|
|
# Attempts to install a chocolatey package of a specific version if
|
2016-04-15 21:01:16 +00:00
|
|
|
# not already there.
|
|
|
|
function Install-ChocoPackage {
|
2016-09-19 20:46:49 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium")]
|
|
|
|
param(
|
|
|
|
[string] $packageName = '',
|
|
|
|
[string] $packageVersion = '',
|
|
|
|
[array] $packageOptions = @()
|
|
|
|
)
|
|
|
|
if (-not $PSCmdlet.ShouldProcess($packageName)) {
|
|
|
|
Exit -1
|
|
|
|
}
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host " => Determining whether $packageName is already installed..." -foregroundcolor DarkYellow
|
2016-09-19 20:46:49 +00:00
|
|
|
$isInstalled = Test-ChocoPackageInstalled $packageName $packageVersion
|
2016-08-29 06:00:26 +00:00
|
|
|
if (-not $isInstalled) {
|
|
|
|
Write-Host " => Did not find. Installing $packageName $packageVersion" -foregroundcolor Cyan
|
2016-12-02 20:20:52 +00:00
|
|
|
$args = @("install", "-s", "https://chocolatey.org/api/v2/", "-y", "-r", "${packageName}")
|
2016-04-15 21:01:16 +00:00
|
|
|
if ($packageVersion -ne '') {
|
|
|
|
$args += @("--version", "${packageVersion}")
|
|
|
|
}
|
|
|
|
if ($packageOptions.count -gt 0) {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "Options: $packageOptions" -foregroundcolor Cyan
|
2016-04-15 21:01:16 +00:00
|
|
|
$args += ${packageOptions}
|
|
|
|
}
|
|
|
|
choco ${args}
|
2016-12-18 19:24:41 +00:00
|
|
|
# Visual studio will occasionally exit with one of the following codes,
|
|
|
|
# indicating a system reboot is needed before continuing.
|
2016-11-02 17:46:45 +00:00
|
|
|
if (@(3010,2147781575,-2147185721,-2147205120) -Contains $LastExitCode){
|
|
|
|
$LastExitCode = 0
|
|
|
|
}
|
2016-12-18 19:24:41 +00:00
|
|
|
if (1638 -eq $LastExitCode){
|
|
|
|
$LastExitCode = 0
|
|
|
|
Write-Host "[*] WARN: A version of $packageName already exists, skipping" -foregroundcolor Yellow
|
|
|
|
}
|
2016-04-15 21:01:16 +00:00
|
|
|
if ($LastExitCode -ne 0) {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[-] ERROR: $packageName $packageVersion failed to install!" -foregroundcolor Red
|
2016-04-15 21:01:16 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[+] Done." -foregroundcolor Green
|
2016-04-15 21:01:16 +00:00
|
|
|
} else {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[*] $packageName $packageVersion already installed." -foregroundcolor Green
|
2016-04-15 21:01:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-19 20:46:49 +00:00
|
|
|
function Install-PipPackage {
|
|
|
|
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium")]
|
|
|
|
param()
|
|
|
|
if (-not $PSCmdlet.ShouldProcess('Pip required modules')) {
|
|
|
|
Exit -1
|
|
|
|
}
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host " => Attempting to install Python packages" -foregroundcolor DarkYellow
|
2016-12-10 01:18:44 +00:00
|
|
|
$pythonPath = [Environment]::GetEnvironmentVariable("OSQUERY_PYTHON_PATH", "Machine")
|
2016-12-06 00:55:49 +00:00
|
|
|
Add-ToPath $pythonPath
|
2016-12-10 01:18:44 +00:00
|
|
|
$pipPath = "$pythonPath\Scripts"
|
|
|
|
Add-ToPath $pipPath
|
|
|
|
if (-not (Test-Path "$pythonPath\python.exe")) {
|
|
|
|
Write-Host "[-] ERROR: failed to find python in C:\tools\python2!" -foregroundcolor Red
|
2016-04-15 21:01:16 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
2016-12-10 01:18:44 +00:00
|
|
|
if (-not (Test-Path "$pipPath\pip.exe")) {
|
|
|
|
Write-Host "[-] ERROR: failed to find pip in C:\tools\python2\Scripts!" -foregroundcolor Red
|
2016-04-15 21:01:16 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
2016-12-10 01:18:44 +00:00
|
|
|
|
2016-04-15 21:01:16 +00:00
|
|
|
$requirements = Resolve-Path ([System.IO.Path]::Combine($PSScriptRoot, '..', 'requirements.txt'))
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host " => Upgrading pip..." -foregroundcolor DarkYellow
|
2016-12-10 01:18:44 +00:00
|
|
|
& "$pythonPath\python.exe" -m pip -q install --upgrade pip
|
2016-04-15 21:01:16 +00:00
|
|
|
if ($LastExitCode -ne 0) {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[-] ERROR: pip upgrade failed." -foregroundcolor Red
|
2016-04-15 21:01:16 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host " => Installing from requirements.txt" -foregroundcolor DarkYellow
|
2016-12-10 01:18:44 +00:00
|
|
|
& "$pipPath\pip.exe" -q install -r $requirements.path
|
2016-04-15 21:01:16 +00:00
|
|
|
if ($LastExitCode -ne 0) {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[-] ERROR: Install packages from requirements failed." -foregroundcolor Red
|
2016-04-15 21:01:16 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-19 20:46:49 +00:00
|
|
|
function Install-ThirdParty {
|
|
|
|
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium")]
|
|
|
|
param()
|
|
|
|
if (-not $PSCmdlet.ShouldProcess('Thirdparty Chocolatey Libraries')) {
|
|
|
|
Exit -1
|
|
|
|
}
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host " => Retrieving third-party dependencies" -foregroundcolor DarkYellow
|
|
|
|
|
2016-04-15 21:01:16 +00:00
|
|
|
# XXX: The code below exists because our chocolatey packages are not currently in the chocolatey
|
|
|
|
# repository. For now, we will download our packages locally and install from a local source.
|
|
|
|
# We also include the official source since thrift-dev depends on the chocolatey thrift package.
|
2016-08-29 06:00:26 +00:00
|
|
|
#
|
2016-04-15 21:01:16 +00:00
|
|
|
# Once our chocolatey packages are added to the official repository, installing the third-party
|
|
|
|
# dependencies will be as easy as Install-ChocoPackage '<package-name>'.
|
|
|
|
$packages = @(
|
2017-03-08 22:51:41 +00:00
|
|
|
"boost-msvc14.1.63.0",
|
2016-04-15 21:01:16 +00:00
|
|
|
"bzip2.1.0.6",
|
|
|
|
"doxygen.1.8.11",
|
2016-11-30 23:48:50 +00:00
|
|
|
"gflags-dev.2.2.0",
|
2016-04-15 21:01:16 +00:00
|
|
|
"glog.0.3.4",
|
2016-11-30 23:48:50 +00:00
|
|
|
"openssl.1.0.2-j",
|
2017-03-16 00:53:39 +00:00
|
|
|
"rocksdb.5.1.4",
|
2016-04-15 21:01:16 +00:00
|
|
|
"snappy-msvc.1.1.1.8",
|
2016-06-24 15:47:48 +00:00
|
|
|
"thrift-dev.0.9.3",
|
2017-03-08 22:51:41 +00:00
|
|
|
"cpp-netlib.0.12.0-r2",
|
2016-09-06 23:42:20 +00:00
|
|
|
"linenoise-ng.1.0.0",
|
2016-09-20 21:18:58 +00:00
|
|
|
"clang-format.3.9.0",
|
|
|
|
"zlib.1.2.8"
|
2016-04-15 21:01:16 +00:00
|
|
|
)
|
|
|
|
$tmpDir = Join-Path $env:TEMP 'osquery-packages'
|
|
|
|
Remove-Item $tmpDir -Recurse -ErrorAction Ignore
|
2016-09-20 18:29:29 +00:00
|
|
|
New-Item -Force -Type directory -Path $tmpDir
|
2016-04-15 21:01:16 +00:00
|
|
|
Try {
|
|
|
|
foreach ($package in $packages) {
|
2016-09-20 18:29:29 +00:00
|
|
|
$chocoForce = ""
|
2017-03-08 21:15:35 +00:00
|
|
|
$executionTimeout = 7200
|
2016-08-29 06:00:26 +00:00
|
|
|
$packageData = $package -split '\.'
|
|
|
|
$packageName = $packageData[0]
|
|
|
|
$packageVersion = [string]::Join('.', $packageData[1..$packageData.length])
|
2016-09-20 18:29:29 +00:00
|
|
|
|
2016-11-14 20:10:08 +00:00
|
|
|
if (($packageName -eq "clang-format") -and (Test-Path env:OSQUERY_BUILD_HOST)) {
|
|
|
|
Write-Host "[*] Skipping $packageName $packageVersion on build hosts." -foregroundcolor Green
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host " => Determining whether $packageName is already installed..." -foregroundcolor DarkYellow
|
2016-09-19 20:46:49 +00:00
|
|
|
$isInstalled = Test-ChocoPackageInstalled $packageName $packageVersion
|
2016-08-29 06:00:26 +00:00
|
|
|
if ($isInstalled) {
|
|
|
|
Write-Host "[*] $packageName $packageVersion already installed." -foregroundcolor Green
|
|
|
|
continue
|
|
|
|
}
|
2016-11-14 20:10:08 +00:00
|
|
|
|
2016-09-20 18:29:29 +00:00
|
|
|
# Chocolatey package is installed, but version is off
|
|
|
|
$oldVersionInstalled = Test-ChocoPackageInstalled $packageName
|
|
|
|
if ($oldVersionInstalled) {
|
|
|
|
Write-Host " => An old version of $packageName is installed. Forcing re-installation" -foregroundcolor Cyan
|
|
|
|
$chocoForce = "-f"
|
|
|
|
} else {
|
|
|
|
Write-Host " => Did not find. Installing $packageName $packageVersion" -foregroundcolor Cyan
|
|
|
|
}
|
2016-04-15 21:01:16 +00:00
|
|
|
$downloadUrl = "$THIRD_PARTY_ARCHIVE_URL/$package.nupkg"
|
|
|
|
$tmpFilePath = Join-Path $tmpDir "$package.nupkg"
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host " => Downloading $downloadUrl" -foregroundcolor DarkCyan
|
2016-04-15 21:01:16 +00:00
|
|
|
Try {
|
|
|
|
(New-Object net.webclient).DownloadFile($downloadUrl, $tmpFilePath)
|
|
|
|
} catch [Net.WebException] {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[-] ERROR: Downloading $package failed. Check connection?" -foregroundcolor Red
|
2016-04-15 21:01:16 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
2017-03-08 21:15:35 +00:00
|
|
|
choco install --pre -y -r --execution-timeout=$executionTimeout $chocoForce $packageName --version=$packageVersion --source="$tmpDir;https://chocolatey.org/api/v2"
|
2016-04-15 21:01:16 +00:00
|
|
|
if ($LastExitCode -ne 0) {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[-] ERROR: Install of $package failed." -foregroundcolor Red
|
2016-04-15 21:01:16 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[+] DONE" -foregroundcolor Green
|
2016-04-15 21:01:16 +00:00
|
|
|
}
|
2016-08-29 06:00:26 +00:00
|
|
|
} Finally {
|
2016-04-15 21:01:16 +00:00
|
|
|
Remove-Item $tmpDir -Recurse
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function Update-GitSubmodule {
|
2016-09-19 20:46:49 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Low")]
|
|
|
|
param()
|
|
|
|
if (-not $PSCmdlet.ShouldProcess('Git Submodules')) {
|
|
|
|
Exit -1
|
|
|
|
}
|
|
|
|
if ($null -eq (Get-Command 'git.exe' -ErrorAction SilentlyContinue)) {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[-] ERROR: Git was not found on the system. Install git." -foregroundcolor Red
|
2016-04-15 21:01:16 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
|
|
|
$thirdPartyPath = Resolve-Path ([System.IO.Path]::Combine($PSScriptRoot, '..', 'third-party'))
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host " => Updating git submodules in $thirdPartyPath ..." -foregroundcolor Yellow
|
2016-09-19 20:46:49 +00:00
|
|
|
Push-Location $thirdPartyPath
|
2016-11-02 17:46:45 +00:00
|
|
|
git submodule --quiet update --init
|
2016-09-19 20:46:49 +00:00
|
|
|
Pop-Location
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[+] Submodules updated!" -foregroundcolor Yellow
|
2016-04-15 21:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Main {
|
2016-11-02 17:46:45 +00:00
|
|
|
if ($PSVersionTable.PSVersion.Major -lt 3.0 ) {
|
|
|
|
Write-Output "This installer currently requires Powershell 3.0 or greater."
|
2016-09-19 20:46:49 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
|
|
|
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[+] Provisioning a Win64 build environment for osquery" -foregroundcolor Yellow
|
|
|
|
Write-Host " => Verifying script is running with Admin privileges" -foregroundcolor Yellow
|
2016-04-15 21:01:16 +00:00
|
|
|
if (-not (Test-IsAdmin)) {
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[-] ERROR: Please run this script with Admin privileges!" -foregroundcolor Red
|
2016-04-15 21:01:16 +00:00
|
|
|
Exit -1
|
|
|
|
}
|
2016-11-14 20:10:08 +00:00
|
|
|
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[+] Success!" -foregroundcolor Green
|
2016-11-02 17:46:45 +00:00
|
|
|
$out = Install-Chocolatey
|
|
|
|
$out = Install-ChocoPackage 'cppcheck'
|
|
|
|
$out = Install-ChocoPackage '7zip.commandline'
|
|
|
|
$out = Install-ChocoPackage 'cmake.portable' '3.6.1'
|
2016-12-10 01:18:44 +00:00
|
|
|
$chocoParams = @("--params=`"/InstallDir:C:\tools\python2`"")
|
|
|
|
$out = Install-ChocoPackage 'python2' '' ${chocoParams}
|
|
|
|
# Convenience variable for accessing Python
|
|
|
|
[Environment]::SetEnvironmentVariable("OSQUERY_PYTHON_PATH", "C:\tools\python2", "Machine")
|
2016-11-02 17:46:45 +00:00
|
|
|
$out = Install-PipPackage
|
|
|
|
$out = Update-GitSubmodule
|
2016-11-14 04:29:40 +00:00
|
|
|
if (Test-Path env:OSQUERY_BUILD_HOST) {
|
|
|
|
$out = Install-ChocoPackage 'visualcppbuildtools'
|
|
|
|
} else {
|
|
|
|
$deploymentFile = Resolve-Path ([System.IO.Path]::Combine($PSScriptRoot, 'vsdeploy.xml'))
|
|
|
|
$chocoParams = @("--execution-timeout", "7200", "-packageParameters", "--AdminFile ${deploymentFile}")
|
|
|
|
$out = Install-ChocoPackage 'visualstudio2015community' '' ${chocoParams}
|
2016-11-14 20:10:08 +00:00
|
|
|
|
|
|
|
if(Test-RebootPending -eq $true) {
|
|
|
|
Write-Host "[*] Windows requires a reboot to complete installing Visual Studio." -foregroundcolor yellow
|
|
|
|
Write-Host "[*] Please reboot your system and re-run this provisioning script." -foregroundcolor yellow
|
|
|
|
Exit 0
|
|
|
|
}
|
|
|
|
|
2016-12-10 01:18:44 +00:00
|
|
|
if ($PSVersionTable.PSVersion.Major -lt 5 -and $PSVersionTable.PSVersion.Minor -lt 1 ) {
|
2016-11-14 20:54:33 +00:00
|
|
|
Write-Host "[*] Powershell version is < 5.1. Skipping Powershell Linter Installation." -foregroundcolor yellow
|
|
|
|
} else {
|
|
|
|
$out = Install-PowershellLinter
|
|
|
|
}
|
2016-11-02 17:46:45 +00:00
|
|
|
}
|
2016-11-14 20:54:33 +00:00
|
|
|
$out = Install-ThirdParty
|
2016-08-29 06:00:26 +00:00
|
|
|
Write-Host "[+] Done." -foregroundcolor Yellow
|
2016-04-15 21:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$null = Main
|