forked from jourdant/powershell-paperless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitialize-Environment.ps1
102 lines (82 loc) · 7.53 KB
/
Initialize-Environment.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#
# Title: Initialize-Environment.ps1
# Author: Jourdan Templeton
# Email: [email protected]
# Modified: 21/07/2015 04:35PM NZDT
#
#properties
#================================================================
$tesseract_url = "https://nuget.org/api/v2/package/Tesseract"
$tessdata_url = "https://nuget.org/api/v2/package/tesseract-ocr"
$itextsharp_url = "https://nuget.org/api/v2/package/iTextSharp"
$tesseract_zip_name = "$PSScriptRoot\tesseract.zip"
$tessdata_zip_name = "$PSScriptRoot\tessdata.zip"
$itextsharp_zip_name = "$PSScriptRoot\itextsharp.zip"
$input_dir_name = "$PSScriptRoot\Input"
$output_dir_name = "$PSScriptRoot\Output"
$lib_dir_name = "$PSScriptRoot\Lib"
#================================================================
#create dir structure
If ((Test-Path $input_dir_name) -eq $False) { mkdir $input_dir_name | Out-Null }
If ((Test-Path $output_dir_name) -eq $False) { mkdir $output_dir_name | Out-Null }
If ((Test-Path $lib_dir_name) -eq $False) { mkdir $lib_dir_name | Out-Null }
#import assemblies into session
Add-Type -Assembly "System.IO.Compression.FileSystem"
#download and extract tesseract libraries
If ((Test-Path $tesseract_zip_name) -eq $False) {
Write-Output "Downloading: '$tesseract_url' To: '$tesseract_zip_name'"
Invoke-WebRequest -Uri $tesseract_url -OutFile $tesseract_zip_name
}
If ((Test-Path $tesseract_zip_name) -eq $True) {
$zip = [IO.Compression.ZipFile]::OpenRead($tesseract_zip_name)
#extract tesseract libraries
$zip.Entries | where FullName -Match "(?i)lib\/net45[0-9]*\/tesseract\.dll" | % {
$dir = (Get-Item $lib_dir_name).FullName
If ($_.FullName.Contains("content")) { $dir += "\" + $matches[0] }
If ((Test-Path $dir) -eq $False) { mkdir $dir | Out-Null }
$file = $dir + "\" + $_.Name
[IO.Compression.ZipFileExtensions]::ExtractToFile($_, $file, $true)
}
$zip.Entries | where FullName -Match "(x86|x64)" | % {
$dir = (Get-Item $lib_dir_name).FullName
$dir += "\" + $matches[0]
If ((Test-Path $dir) -eq $False) { mkdir $dir | Out-Null }
$file = $dir + "\" + $_.Name
[IO.Compression.ZipFileExtensions]::ExtractToFile($_, $file, $true)
}
$zip.Dispose()
Remove-Item $tesseract_zip_name -Force
}
#download and extract tesseract data files
If ((Test-Path $tessdata_zip_name) -eq $False) {
Write-Output "Downloading: '$tessdata_url' To: '$tessdata_zip_name'"
Invoke-WebRequest -Uri $tessdata_url -OutFile $tessdata_zip_name
}
If ((Test-Path $tessdata_zip_name) -eq $True) {
$zip = [IO.Compression.ZipFile]::OpenRead($tessdata_zip_name)
#extract tessdata libraries
$zip.Entries | where FullName -Match "eng" | % {
$dir = (Get-Item $lib_dir_name).FullName + "\tessdata"
If ((Test-Path $dir) -eq $False) { mkdir $dir | Out-Null }
$file = $dir + "\" + $_.Name
[IO.Compression.ZipFileExtensions]::ExtractToFile($_, $file, $true)
}
$zip.Dispose()
Remove-Item $tessdata_zip_name -Force
}
#download and extract iTextSharp library
If ((Test-Path $itextsharp_zip_name) -eq $False) {
Write-Output "Downloading: '$itextsharp_url' To: '$itextsharp_zip_name'"
Invoke-WebRequest -Uri $itextsharp_url -OutFile $itextsharp_zip_name
}
If ((Test-Path $itextsharp_zip_name) -eq $True) {
$zip = [IO.Compression.ZipFile]::OpenRead($itextsharp_zip_name)
#extract itextsharp libraries
$zip.Entries | where FullName -Match "itextsharp.dll" | % {
$dir = (Get-Item $lib_dir_name).FullName
$file = $dir + "\" + $_.Name
[IO.Compression.ZipFileExtensions]::ExtractToFile($_, $file, $true)
}
$zip.Dispose()
Remove-Item $itextsharp_zip_name -Force
}