forked from nblagoev/Gmail.ps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
74 lines (58 loc) · 2.43 KB
/
install.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
$ErrorCount = $Error.Count
$ModulePaths = @($Env:PSModulePath -split ';')
$ExpectedUserModulePath = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath WindowsPowerShell\Modules
$Destination = $ModulePaths | Where-Object { $_ -eq $ExpectedUserModulePath}
if (-not $Destination) {
$Destination = $ModulePaths | Select-Object -Index 0
}
if (-not (Test-Path $Destination)) {
New-Item $Destination -ItemType Directory -Force | Out-Null
} elseif (Test-Path (Join-Path $Destination "Gmail.ps\Gmail.ps.psm1")) {
Write-Host "Gmail.ps is already installed" -Foreground Green
return
}
try {
git --version | Out-Null
$hasGit = $true
} catch {
$hasGit = $false
$ErrorCount -= 1
}
$CurrentLocation = Get-Location
Push-Location $Destination
if (Test-Path (Join-Path $CurrentLocation "Gmail.ps.psm1")) {
Copy-Item -Path $CurrentLocation -Destination ($Destination + "\Gmail.ps\") -Recurse
} elseif ($hasGit) {
git clone https://github.com/nikoblag/Gmail.ps.git
} else {
New-Item ($Destination + "\Gmail.ps\") -ItemType Directory -Force | Out-Null
Write-Host "Downloading Gmail.ps from https://github.com/nikoblag/Gmail.ps"
$rawMasterURL = "https://github.com/nikoblag/Gmail.ps/raw/master/"
$files = @("Gmail.ps.psm1","Gmail.ps.psd1","AE.Net.Mail.dll","LICENSE","README.md","FormatData\MailMessage.Format.ps1xml","FormatData\Mailbox.Format.ps1xml","FormatData\Attachment.Format.ps1xml")
$client = (New-Object Net.WebClient)
$client.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
foreach ($file in $files) {
$client.DownloadFile($rawMasterURL + $file, $Destination + "\Gmail.ps\" + $file)
}
}
Pop-Location
$executionPolicy = (Get-ExecutionPolicy)
$executionRestricted = ($executionPolicy -eq "Restricted")
if ($executionRestricted) {
Write-Warning @"
Your execution policy is $executionPolicy, this means you will not be able import or use any scripts including modules.
To fix this, change your execution policy to something like RemoteSigned.
PS> Set-ExecutionPolicy RemoteSigned
For more information execute:
PS> Get-Help about_execution_policies
"@
}
if (!$executionRestricted) {
Import-Module -Name $Destination\Gmail.ps
}
if ($ErrorCount -eq $Error.Count) {
Write-Host "Gmail.ps is installed and ready to use" -Foreground Green
} else {
Write-Host "Something went wrong. Gmail.ps may not work." -Foreground Red
}