forked from jagilber/powershellScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-vscode-setup.ps1
117 lines (95 loc) · 3.74 KB
/
git-vscode-setup.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<#
script to setup git, hub, and vscode with common settings and extensions
to download and execute script:
[net.servicePointManager]::Expect100Continue = $true;[net.servicePointManager]::SecurityProtocol = [net.SecurityProtocolType]::Tls12;
iwr https://raw.githubusercontent.com/jagilber/powershellScripts/master/git-vscode-setup.ps1 -outfile $pwd\git-vscode-setup.ps1;. $pwd\git-vscode-setup.ps1
or to just install vscode:
[net.webclient]::new().DownloadFile('https://vscode-update.azurewebsites.net/latest/win32-x64-user/stable', $pwd\VSCodeUserSetup-x64.exe)
#>
param(
[string]$gitHubDir = "c:\github",
[string[]]$additionalExtensions = @(
'msazurermtools.azurerm-vscode-tools',
'eamodio.gitlens',
'wengerk.highlight-bad-chars',
'rsbondi.highlight-words',
'sandcastle.vscode-open',
'mechatroner.rainbow-csv',
'grapeCity.gc-excelviewer',
'ms-dotnettools.csharp',
'ms-vscode.powershell'),
[string]$user,
[string]$email,
[switch]$ssh,
[int]$sshPort = 22
)
[io.directory]::CreateDirectory($gitHubDir)
if (!(test-path "$pwd\download-git-client.ps1")) {
invoke-webRequest "https://raw.githubusercontent.com/jagilber/powershellScripts/master/download-git-client.ps1" -outFile "$pwd/download-git-client.ps1";
}
$error.Clear()
if (!$user) {
$user = [regex]::Match((whoami /fqdn), "CN=(.+?),").Groups[1].Value
}
if ($error) {
$error.Clear()
$user = $env:USERNAME
}
if (!$email) {
$email = (whoami /upn)
}
if ($error) {
$error.Clear()
$email = "$env:USERNAME@$env:userdomain"
}
# git
$error.clear()
(git) | out-null
if ($error) {
.\download-git-client.ps1
}
# git config
git config --global user.name $user
git config --global user.email $email
git config --global core.editor "code --wait"
# hub git wrapper
$error.clear()
(hub) | out-null
if ($error) {
.\download-git-client.ps1 -hub -setpath
}
Set-Location $gitHubDir
$error.clear()
(code /?) | out-null
if ($error) {
invoke-webRequest "https://raw.githubusercontent.com/PowerShell/vscode-powershell/master/scripts/Install-VSCode.ps1" -outFile "$pwd/Install-VSCode.ps1";
.\Install-VSCode.ps1 -additionalExtensions @($additionalExtensions) -launchWhenDone -enableContextMenus
}
if ($ssh) {
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (!$isAdmin) {
write-error "run script as admin to configure ssh"
return
}
write-host "checking ssh config"
$hasSSHClient = (Get-WindowsCapability -Online | where-object Name -match 'OpenSSH.client').state -ieq "installed"
write-host "has ssh client installed: $hasSSHClient"
$hasSSHServer = (Get-WindowsCapability -Online | where-object Name -match 'OpenSSH.server').state -ieq "installed"
write-host "has ssh server installed: $hasSSHServer"
if (!$hasSSHClient) {
write-host "installing the OpenSSH Client"
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
}
if (!$hasSSHServer) {
write-host "installing the OpenSSH Server"
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
}
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup.
Get-NetFirewallRule -Name *ssh*
# There should be a firewall rule named "OpenSSH-Server-In-TCP", which should be enabled
# If the firewall does not exist, create one
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort $sshPort
}