Last active
September 9, 2022 00:53
-
-
Save XenHat/fafa4697b51c3279f74967609af03120 to your computer and use it in GitHub Desktop.
Install SL Viewer dev env
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
# https://gist.github.com/XenHat/fafa4697b51c3279f74967609af03120 | |
# | |
# Settings | |
# Needs quotes | |
GitVersion="2.28.0" | |
# | |
# | |
# | |
# | |
# Self-Elevate | |
# Get the ID and security principal of the current user account | |
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent() | |
$myWindowsPrincipal = new-object System.Security.Principal.WindowsPrincipal($myWindowsID) | |
# Get the security principal for the Administrator role | |
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator | |
# Check to see if we are currently running "as Administrator" | |
if ($myWindowsPrincipal.IsInRole($adminRole)) { | |
# We are running "as Administrator" - so change the title and background color to indicate this | |
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + " (Elevated)" | |
$Host.UI.RawUI.BackgroundColor = "DarkRed" | |
clear-host | |
} | |
else { | |
# We are not running "as Administrator" - so relaunch as administrator | |
# Create a new process object that starts PowerShell | |
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell"; | |
# Minimize self | |
$newProcess.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Minimized; | |
# Specify the current script path and name as a parameter | |
$newProcess.Arguments = $myInvocation.MyCommand.Definition; | |
# Indicate that the process should be elevated | |
$newProcess.Verb = "runas"; | |
# Start the new process | |
[System.Diagnostics.Process]::Start($newProcess); | |
# Exit from the current, unelevated, process | |
exit | |
} | |
# Stop on error | |
$ErrorActionPreference = "Stop" | |
# Set UTF-8 encoding for python and such | |
$env:PYTHONIOENCODING = "UTF-8" | |
function IsInstalled { | |
$what = $args[0] | |
((Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*).DisplayName -Match $what).Length -gt 0 | |
} | |
# We require Internet Explorer, which is not always present (Windows 10 Pro 1903 notably) | |
# Get-WindowsOptionalFeature -Online | Select-Object FeatureName | Select-String "Internet-Explorer-Optional*" | |
# Enable-WindowsOptionalFeature -FeatureName 'Internet-Explorer-Optional-amd64' -Online | |
function Install-Remote { | |
$MyURL = $args[0] | |
$leaf = Split-Path $MyURL -leaf | |
$MyFile = "${DownloadDir}\$leaf" | |
$CustomArgs = $args[1] | |
if ( -not (Test-Path $MyFile)) { | |
Write-Output "Downloading $MyFile from $MyURL" | |
# Start-BitsTransfer -Source "$MyURL" -Destination "$MyFile" | |
$headers = @{} | |
$headers.Add('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0') | |
Invoke-WebRequest -UseBasicParsing -Uri "$MyURL" -OutFile "$MyFile" -Headers $headers | |
} | |
if ( $MyFile.EndsWith("msi")) { | |
Write-Output "Installer is MSI" | |
Write-Output "Installing $MyFile" | |
Start-Process -FilePath "msiexec.exe" -Wait -NoNewWindow -ArgumentList "/Package $MyFile /passive" | |
} | |
else { | |
Write-Output "Installer is EXE..." | |
if ($CustomArgs) { | |
Write-Output "Got custom args" | |
Write-Output "Installing $MyFile" | |
Start-Process -Verb runas powershell -Wait -ArgumentList "Start-Process -FilePath $MyFile -Wait -WindowStyle hidden -ArgumentList $CustomArgs" | |
} | |
else { | |
Write-Output "Installing $MyFile" | |
Start-Process -Verb runas powershell -Wait -ArgumentList "Start-Process -FilePath $MyFile -Wait -WindowStyle hidden" | |
} | |
} | |
} | |
function Install-TortoiseHG { | |
if (-not (IsInstalled "TortoiseHG")) { | |
$WebResponse = Invoke-WebRequest -UseBasicParsing -Uri 'https://tortoisehg.bitbucket.io/' | |
$MyURL = ($WebResponse.Links | Where-Object { $_.id -eq "altLink" }).href | |
Install-Remote($MyURL) | |
} | |
} | |
function Install-Cygwin { | |
# Cygwin does not appear in the uninstall list, therefore we cannot use the traditional method | |
if (-not (Test-Path 'C:\cygwin64\bin\bash.exe')) { | |
#Remove-Item -Path 'C:\cygwin64\*' -Recurse | |
$MyURL = "https://www.cygwin.com/setup-x86_64.exe" | |
$leaf = Split-Path $MyURL -leaf | |
$MyFile = "${DownloadDir}\${leaf}" | |
if ( -not (Test-Path $MyFile)) { | |
Write-Output "Downlading $MyFile from $MyURL" | |
Start-BitsTransfer -Source "$MyURL" -Destination "$MyFile" | |
} | |
Write-Output "Installing $MyFile" | |
$pkg_dir = "${DownloadDir}\packages" | |
if (-not (Test-Path $pkg_dir)) { | |
New-Item -Path "$pkg_dir" -ItemType Directory | |
} | |
$CygwinMirror = 'http://cygwin.mirror.globo.tech/' | |
$CygwinPackages = 'curl,unzip,nano,patchutils,perl,p7zip,wget,bison,flex' | |
Start-Process -Wait -FilePath "$MyFile" -ArgumentList " --disable-buggy-antivirus --upgrade-also --arch x86_64 --delete-orphans --quiet-mode --local-package-dir ${pkg_dir} --site ${CygwinMirror} --root C:\cygwin64 --packages ${CygwinPackages}" | |
#Start-Process -Wait -FilePath "$MyFile" -ArgumentList "--download --upgrade-also --arch x86_64 --delete-orphans --site http://mirrors.xmission.com/cygwin/ --local-package-dir $pkg_dir --packages curl,unzip,nano,patchutils,perl,p7zip,wget,bison,flex --verbose --disable-buggy-antivirus --quiet-mode" | |
} | |
} | |
function Install-VS2017 { | |
if (! (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe")) { | |
$MyURL = 'https://download.visualstudio.microsoft.com/download/pr/d125163a-cf26-489a-b62e-94995a66d7c5/1ff3b2c80236499af4ef5bd802277f64/vs_community.exe' | |
$MyFile = "${DownloadDir}\vs_2017_ce_installer.exe" | |
if ( -not (Test-Path "$MyFile")) { | |
Write-Output "Downlading $MyFile from $MyURL" | |
Start-BitsTransfer -Source "$MyURL" -Destination "$MyFile" | |
} | |
Write-Output "Installing $MyFile" | |
# Install minimal Visual Studio | |
# package list retrieved from https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/install/workload-component-id-vs-community.md and https://github.com/MicrosoftDocs/visualstudio-docs/blob/97c0a44b5563716699d0091c13c01550e80dce78/docs/install/automated-installation-with-response-file.md | |
# Create answer file through magic | |
$MyData = Write-Output ' | |
{ | |
"channelUri": "https://aka.ms/vs/15/release/channel", | |
"channelId": "VisualStudio.15.Release", | |
"productId": "Microsoft.VisualStudio.Product.Community", | |
"add": [ | |
"Microsoft.VisualStudio.Workload.NativeDesktop", | |
"Microsoft.VisualStudio.Component.CoreEditor", | |
"Microsoft.VisualStudio.Component.Debugger.JustInTime", | |
"Microsoft.VisualStudio.Component.NuGet", | |
"Microsoft.Component.MSBuild", | |
"Microsoft.VisualStudio.Component.VC.CoreIde", | |
"Microsoft.VisualStudio.Component.VC.CLI.Support", | |
"Microsoft.VisualStudio.Component.VC.CMake.Project", | |
"Microsoft.VisualStudio.Component.VC.CoreIde", | |
"Microsoft.VisualStudio.Component.VC.Redist.14.Latest", | |
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64", | |
"Microsoft.Net.Component.4.6.TargetingPack", | |
"Microsoft.Net.Component.4.6.1.SDK", | |
"Microsoft.Net.Component.4.6.1.TargetingPack", | |
"Microsoft.Net.Component.4.6.1.TargetingPack", | |
"Microsoft.Net.Component.4.6.2.SDK", | |
"Microsoft.Net.Component.4.6.2.TargetingPack" | |
], | |
"addProductLang": [ | |
"en-US" | |
] | |
} | |
' | ConvertTo-Json | |
# Fix up encoding | |
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False | |
$ManifestFileLocation = "${DownloadDir}\\viewerDevInstall_2017.json"; | |
if ((Test-Path "$ManifestFileLocation")) { | |
Remove-Item -Path "$ManifestFileLocation" | |
} | |
[System.IO.File]::WriteAllLines($ManifestFileLocation, ($MyData | ConvertFrom-Json), $Utf8NoBomEncoding) | |
Start-Process "$MyFile" -Wait -ArgumentList "--in $ManifestFileLocation --wait --passive" | |
# Start-Process "$MyFile" -Wait -ArgumentList "--in $ManifestFileLocation --wait" | |
} | |
} | |
function Install-VS2019 { | |
if (! (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe")) { | |
$MyURL = 'https://download.visualstudio.microsoft.com/download/pr/378e5eb4-c1d7-4c05-8f5f-55678a94e7f4/a81be4cb9a23a455de46790900701213962a0d63ea937ecf1941f846b580c8a5/vs_Community.exe' | |
$MyFile = "${DownloadDir}\vs_2019_ce_installer.exe" | |
if ( -not (Test-Path "$MyFile")) { | |
Write-Output "Downlading $MyFile from $MyURL" | |
Start-BitsTransfer -Source "$MyURL" -Destination "$MyFile" | |
} | |
Write-Output "Installing $MyFile" | |
# Install minimal Visual Studio | |
# package list retrieved from https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/install/workload-component-id-vs-community.md and https://github.com/MicrosoftDocs/visualstudio-docs/blob/97c0a44b5563716699d0091c13c01550e80dce78/docs/install/automated-installation-with-response-file.md | |
# Create answer file through magic | |
$MyData = Write-Output ' | |
{ | |
"channelUri": "https://aka.ms/vs/16/release/channel", | |
"channelId": "VisualStudio.16.Release", | |
"productId": "Microsoft.VisualStudio.Product.Community", | |
"add": [ | |
"Microsoft.VisualStudio.Component.CoreEditor", | |
"Microsoft.VisualStudio.Component.Debugger.JustInTime", | |
"Microsoft.VisualStudio.Component.NuGet", | |
"Microsoft.Component.MSBuild", | |
"Microsoft.VisualStudio.Component.VC.CoreIde", | |
"Microsoft.VisualStudio.Component.VC.CLI.Support", | |
"Microsoft.VisualStudio.Component.VC.CMake.Project", | |
"Microsoft.VisualStudio.Component.VC.CoreIde", | |
"Microsoft.VisualStudio.Component.VC.Redist.14.Latest", | |
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64", | |
"Microsoft.Net.Component.4.6.TargetingPack", | |
"Microsoft.Net.Component.4.6.1.SDK", | |
"Microsoft.Net.Component.4.6.1.TargetingPack", | |
"Microsoft.Net.Component.4.6.1.TargetingPack", | |
"Microsoft.Net.Component.4.6.2.SDK", | |
"Microsoft.Net.Component.4.6.2.TargetingPack", | |
"Microsoft.VisualStudio.Component.Windows10SDK", | |
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core", | |
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices", | |
"Microsoft.VisualStudio.Component.Roslyn.Compiler" | |
], | |
"addProductLang": [ | |
"en-US" | |
] | |
} | |
' | ConvertTo-Json | |
# Fix up encoding | |
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False | |
$ManifestFileLocation = "${DownloadDir}\\viewerDevInstall_2019.json"; | |
if ((Test-Path "$ManifestFileLocation")) { | |
Remove-Item -Path "$ManifestFileLocation" | |
} | |
[System.IO.File]::WriteAllLines($ManifestFileLocation, ($MyData | ConvertFrom-Json), $Utf8NoBomEncoding) | |
Start-Process "$MyFile" -Wait -ArgumentList "--in $ManifestFileLocation --wait --passive" | |
} | |
} | |
function Install-Autobuild { | |
if (-not (Test-Path 'C:\Python27\Scripts\pip.exe')) { | |
# Temporarily add python to the path, in order to let pip do its thing. | |
$env:Path += "C:\Python27\;C:\Python27\Scripts;C:\Program Files\TortoiseHg" | |
Start-Process -Wait -NoNewWindow -FilePath "C:\Python27\python.exe" -ArgumentList "-m pip install --upgrade pip" | |
# Start-Process -Wait -NoNewWindow -FilePath "C:\Python27\python.exe" -ArgumentList "-m pip uninstall autobuild --yes" | |
# Start-Process -Wait -NoNewWindow -FilePath "C:\Python27\python.exe" -ArgumentList '-m pip install "hg+https://bitbucket.org/polarityviewer/autobuild-polarity"' | |
} | |
} | |
function Install-Pipenv { | |
if (-not (Test-Path 'C:\Python27\Scripts\pipenv.exe')) { | |
# Temporarily add python to the path, in order to let pip do its thing. | |
$env:Path += "C:\Python27\;C:\Python27\Scripts;" | |
Start-Process -Wait -NoNewWindow -FilePath "C:\Python27\python.exe" -ArgumentList "-m pip install astroid" | |
Start-Process -Wait -NoNewWindow -FilePath "C:\Python27\python.exe" -ArgumentList "-m pip install --upgrade pipenv" | |
} | |
} | |
# env:TEMP does not always work, especially on windows server, using the admin account | |
#$DownloadDir = "${env:TEMP}\viewerDevEnvInstall" | |
$DownloadDir = "C:\viewerDevEnvInstall" | |
if ( -not (Test-Path "$DownloadDir")) { | |
mkdir -Path $DownloadDir | |
} | |
if (-not (IsInstalled "Cmake")) { | |
Install-Remote 'https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4-win64-x64.msi' "/Silent" | |
} | |
#Install-TortoiseHG | |
if (-not (IsInstalled "Git" )) { | |
Install-Remote "https://github.com/git-for-windows/git/releases/download/v${GitVersion}.windows.1/Git-${GitVersion}-64-bit.exe" "/Silent" | |
} | |
Install-Cygwin | |
if (-not (Test-Path 'C:\Python27')) { | |
Install-Remote 'https://www.python.org/ftp/python/2.7.15/python-2.7.15.msi' | |
} | |
if (-not (Test-Path 'C:\Program Files (x86)\Gpg4win')) { | |
Install-Remote 'https://files.gpg4win.org/gpg4win-3.1.2.exe' "/S" | |
} | |
Install-Pipenv | |
Install-Autobuild | |
#Install-VS2017 | |
#Install-VS2019 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Warning: This is currently outdated and shouldn't be ran blindly.