Skip to content

Commit

Permalink
add function for Vs C++ redist
Browse files Browse the repository at this point in the history
and beautify hte code for better readability
  • Loading branch information
Krish Patel committed Jun 23, 2023
1 parent babe791 commit 2029cc4
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions install/install_openadapt.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# PowerShell script to pull OpenAdapt and install

################################ PARAMETERS ################################

# Change these if a different version of is required

$tesseractCmd = "tesseract"
$tesseractInstaller = "tesseract-ocr-w64-setup-5.3.1.20230401.exe"
$tesseractInstallerLoc = "https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w64-setup-5.3.1.20230401.exe"
$tesseractPath = "C:\Program Files\Tesseract-OCR"

$pythonCmd = "python3.10"
$pythonVerStr = "Python 3.10*"
$pythonInstaller = "python-3.10.11-amd64.exe"
Expand All @@ -15,13 +23,10 @@ $VCRedistInstaller = "vc_redist.x64.exe"
$VCRedistInstallerLoc = "https://aka.ms/vs/17/release/vc_redist.x64.exe"
$VCRedistRegPath = "HKLM:\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64"

# Tesseract OCR installation
$tesseractCmd = "tesseract"
$tesseractInstaller = "tesseract-ocr-w64-setup-5.3.1.20230401.exe"
$tesseractInstallerLoc = "https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w64-setup-5.3.1.20230401.exe"
$tesseractPath = "C:\Program Files\Tesseract-OCR"
################################ PARAMETERS ################################


################################ FUNCTIONS ################################
# Run a command and ensure it did not fail
function RunAndCheck {
Param
Expand Down Expand Up @@ -128,7 +133,6 @@ function GetTesseractCMD() {
exit
}


# Install the Tesseract OCR Setup exe (binary file)
Write-Host "Installing Tesseract OCR, click 'Yes' if prompted for permission"
Start-Process -FilePath $tesseractInstaller -Verb runAs -ArgumentList "/S" -Wait
Expand Down Expand Up @@ -203,23 +207,12 @@ function GetGitCMD() {
return $gitCmd
}

# Check and Install TesseractOCR -> Python 3.10 -> Git

$tesseract = GetTesseractCMD
RunAndCheck "$tesseract --version" "check tesseract version"

$python = GetPythonCMD
RunAndCheck "$python --version" "check python version"

$git = GetGitCMD
RunAndCheck "$git --version" "check git version"


function GetVSCppRedistCMD {
# Check if Visual C++ Redist is installed
# Note: Temporarily setting $ErrorActionPreference as -erroraction 'silentlycontinue' doesn't prevent non-terminating error with Get-ItemPropertyValue
$ErrorActionPreference="SilentlyContinue"
$ErrorActionPreference = "SilentlyContinue"
$vcredistExists = Get-ItemPropertyValue -Path $VCRedistRegPath -erroraction 'silentlycontinue' -Name Installed
$ErrorActionPreference="Continue"
$ErrorActionPreference = "Continue"

if (!$vcredistExists) {
# Install Visual C++ Redist
Expand All @@ -229,6 +222,7 @@ RunAndCheck "$git --version" "check git version"
$exists = Test-Path -Path $VCRedistInstaller -PathType Leaf
if(!$exists) {
Write-Host "Failed to download Visual C++ installer"
Cleanup
exit
}

Expand All @@ -237,12 +231,31 @@ RunAndCheck "$git --version" "check git version"
Remove-Item $VCRedistInstaller

if($LastExitCode) {
"Failed to install Visual C++ Redist: $LastExitCode"
Write-Host "Failed to install Visual C++ Redist: $LastExitCode"
Cleanup
exit
}
}
}

################################ FUNCTIONS ################################


################################ SCRIPT ################################
# Script Runs from here:
# Check and Install TesseractOCR -> Python 3.10 -> Git -> VS C++ Redist.

$tesseract = GetTesseractCMD
RunAndCheck "$tesseract --version" "check tesseract version"

$python = GetPythonCMD
RunAndCheck "$python --version" "check python version"

$git = GetGitCMD
RunAndCheck "$git --version" "check git version"

GetVSCppRedistCMD

# Install OpenAdapt

RunAndCheck "git clone -q https://github.com/MLDSAI/OpenAdapt.git" "clone git repo"
Expand All @@ -252,3 +265,6 @@ RunAndCheck "poetry install"
RunAndCheck "poetry shell"
RunAndCheck "alembic upgrade head" "alembic upgrade head"
RunAndCheck "pytest" "run OpenAdapt tests"
Write-Host "OpenAdapt installed successfully"

################################ SCRIPT ################################

0 comments on commit 2029cc4

Please sign in to comment.