-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
178 lines (146 loc) · 4.94 KB
/
install.ps1
File metadata and controls
178 lines (146 loc) · 4.94 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
. .\scriptsUtils.ps1
$script:powerShellDir = Split-Path $PROFILE
$script:installDir = "$powerShellDir\Workspace scripts"
$script:poshGitDir = "$installDir\Posh-Git"
$script:configurationFile = "configuration.ps1"
$script:configurationFilePath = "$installDir\$configurationFile"
function script:Invoke-ErrorCheck($errorMessage) {
if (!$?) {
Write-ErrorMessage ($errorMessage + " Installation aborted.")
if (Test-Path $installDir) {
Remove-Item -Recurse -Force $installDir
}
exit 1
}
}
function script:Invoke-InstallationStep($step) {
Write-Host
& $step
}
function script:Start-Installation() {
Write-Host "Starting installation..."
Write-Host "Instalation directory: $installDir"
}
function script:Remove-OldInstallation() {
Write-Host "Removing old installations..."
if ((Test-Path $installDir)) {
Remove-Item -Recurse -Force -Exclude $configurationFile "$installDir\*"
Invoke-ErrorCheck "Cannot create PowerShell directory."
Write-Host "Old installations removed."
}
else {
Write-Host "Old installations were not found."
}
}
function script:Create-PowerShellDirectory() {
Write-Host "Creating PowerShell directory..."
if (!(Test-Path $powerShellDir)) {
New-Item -Type Directory $powerShellDir > $null
Invoke-ErrorCheck "Cannot create PowerShell directory."
Write-Host "PowerShell directory created."
}
else {
Write-Host "PowerShell directory already exists."
}
}
function script:Create-InstallationDirectory() {
Write-Host "Creating installation directory..."
if (!(Test-Path $installDir)) {
New-Item -Type Directory $installDir > $null
Invoke-ErrorCheck "Cannot create installation directory."
Write-Host "Installation directory created."
}
else {
Write-Host "Installation directory already exists."
}
}
function script:Get-PoshGit() {
Write-Host "Downloading Posh-Git..."
git clone https://github.com/dahlbyk/posh-git.git $poshGitDir
Invoke-ErrorCheck "Cannot download Posh-Git."
Write-Host "Posh-Git downloaded."
}
function script:Invoke-PoshGitInstallation() {
Write-Host "Installing Posh-Git..."
& "$poshGitDir\install.ps1"
Invoke-ErrorCheck "Cannot install Posh-Git."
Write-Host "Posh-Git installed."
}
function script:Copy-Files() {
Write-Host "Copying files..."
if (!(Test-Path $configurationFilePath)) {
Copy-Item * $installDir
}
else {
Write-Warning "Old configuration file was detected. It wont be removed..."
$oldConfigurationContent = Get-Content -Path $configurationFilePath
Copy-Item * $installDir
Set-Content -Path $configurationFilePath -Value $oldConfigurationContent
}
Invoke-ErrorCheck "Cannot copy files."
Write-Host "Files copied."
}
function script:Create-PowerShellProfile() {
Write-Host "Creating PowerShell profile file..."
if (!(Test-Path $PROFILE)) {
New-Item -type File $PROFILE > $null
Invoke-ErrorCheck "Cannot create PowerShell profile file."
Write-Host "PowerShell profile file created."
}
else {
Write-Host "PowerShell profile file already exists."
}
}
function script:Set-ModuleConfiguration() {
Write-Host "Configuring PowerShell module..."
$loadLine = "Import-Module '$installDir\workspace.psm1'"
if (Select-String -Path $PROFILE -Pattern $loadLine -SimpleMatch -Quiet) {
Write-Warning "It seems workspace scripts were already installed..."
}
else {
@"
# Load workspace scripts
$loadLine
# Start Pageant
Start-Pageant
"@ | Out-File $PROFILE -Append -Encoding utf8
Invoke-ErrorCheck "Cannot configure PowerShell module."
}
Write-Host "Poweshell module configured."
}
function script:Load-NeededConfigurationVariables() {
. $configurationFilePath
$script:gitUserName = $gitUserName
$script:gitUserEmail = $gitUserEmail
$script:puttyDirPath = $puttyDirPath
}
function script:Set-GitUserSettings() {
Write-Host "Setting Git user settings..."
git config --global user.name $script:gitUserName
git config --global user.email $script:gitUserEmail
Write-Host "Git user settings set (user.name = $gitUserName, user.email = $gitUserEmail)."
}
function script:Set-GitSSHVariable() {
Write-Host "Setting GIT_SSH environment variable..."
$plinkPath = "$script:puttyDirPath\plink.exe"
[Environment]::SetEnvironmentVariable("GIT_SSH", $plinkPath, "User")
Write-Host "GIT_SSH variable set to $plinkPath."
}
function script:Stop-Installation() {
Write-Host "Installation ended."
Write-Host
}
#Installation
Invoke-InstallationStep("Start-Installation")
Invoke-InstallationStep("Remove-OldInstallation")
Invoke-InstallationStep("Create-PowerShellDirectory")
Invoke-InstallationStep("Create-InstallationDirectory")
Invoke-InstallationStep("Get-PoshGit")
Invoke-InstallationStep("Invoke-PoshGitInstallation")
Invoke-InstallationStep("Copy-Files")
Invoke-InstallationStep("Create-PowerShellProfile")
Invoke-InstallationStep("Set-ModuleConfiguration")
Invoke-InstallationStep("Load-NeededConfigurationVariables")
Invoke-InstallationStep("Set-GitUserSettings")
Invoke-InstallationStep("Set-GitSSHVariable")
Invoke-InstallationStep("Stop-Installation")