-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprovision-base.ps1
More file actions
323 lines (279 loc) · 13.5 KB
/
provision-base.ps1
File metadata and controls
323 lines (279 loc) · 13.5 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# set keyboard layout.
# NB you can get the name from the list:
# [Globalization.CultureInfo]::GetCultures('InstalledWin32Cultures') | Out-GridView
Set-WinUserLanguageList pt-PT -Force
# set the date format, number format, etc.
Set-Culture pt-PT
# set the welcome screen culture and keyboard layout.
# NB the .DEFAULT key is for the local SYSTEM account (S-1-5-18).
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS | Out-Null
'Control Panel\International','Keyboard Layout' | ForEach-Object {
Remove-Item -Path "HKU:.DEFAULT\$_" -Recurse -Force
Copy-Item -Path "HKCU:$_" -Destination "HKU:.DEFAULT\$_" -Recurse -Force
}
# set the timezone.
# tzutil /l lists all available timezone ids
& $env:windir\system32\tzutil /s "GMT Standard Time"
# show window content while dragging.
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name DragFullWindows -Value 1
# show hidden files.
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -Value 1
# show file extensions.
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideFileExt -Value 0
# display full path in the title bar.
New-Item -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState -Force `
| New-ItemProperty -Name FullPath -Value 1 -PropertyType DWORD `
| Out-Null
Write-Host 'Setting the Desktop Background...'
Add-Type -AssemblyName System.Drawing
$backgroundColor = [System.Drawing.Color]::FromArgb(30, 30, 30)
$backgroundPath = 'C:\Windows\Web\Wallpaper\Windows\sql-server.png'
$logo = [System.Drawing.Image]::FromFile((Resolve-Path 'sql-server.png'))
$b = New-Object System.Drawing.Bitmap($logo.Width, $logo.Height)
$g = [System.Drawing.Graphics]::FromImage($b)
$g.Clear($backgroundColor)
$g.DrawImage($logo, 0, 0, $logo.Width, $logo.Height)
$b.Save($backgroundPath)
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name Wallpaper -Value $backgroundPath
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name WallpaperStyle -Value 0
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name TileWallpaper -Value 0
Set-ItemProperty -Path 'HKCU:Control Panel\Colors' -Name Background -Value ($backgroundColor.R,$backgroundColor.G,$backgroundColor.B -join ' ')
Add-Type @'
using System;
using System.Drawing;
using System.Runtime.InteropServices;
public static class WindowsWallpaper
{
private const int COLOR_DESKTOP = 0x01;
[DllImport("user32", SetLastError=true)]
private static extern bool SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues);
private const uint SPI_SETDESKWALLPAPER = 0x14;
private const uint SPIF_UPDATEINIFILE = 0x01;
private const uint SPIF_SENDWININICHANGE = 0x02;
[DllImport("user32", SetLastError=true)]
private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, string pvParam, uint fWinIni);
public static void Set(Color color, string path)
{
var elements = new int[] { COLOR_DESKTOP };
var colors = new int[] { ColorTranslator.ToWin32(color) };
SetSysColors(elements.Length, elements, colors);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_SENDWININICHANGE);
}
}
'@ -ReferencedAssemblies System.Drawing
[WindowsWallpaper]::Set($backgroundColor, $backgroundPath)
Write-Host 'Setting the Lock Screen Background...'
$backgroundPath = 'C:\Windows\Web\Screen\lock-screen.png'
Copy-Item 'sql-server.png' $backgroundPath
New-Item -Path HKLM:Software\Policies\Microsoft\Windows\Personalization -Force `
| New-ItemProperty -Name LockScreenImage -Value $backgroundPath `
| New-ItemProperty -Name PersonalColors_Background -Value '#1e1e1e' `
| New-ItemProperty -Name PersonalColors_Accent -Value '#007acc' `
| Out-Null
# configure microsoft edge.
# see https://learn.microsoft.com/en-us/deployedge/microsoft-edge-browser-policies/hidefirstrunexperience
# see https://learn.microsoft.com/en-us/deployedge/microsoft-edge-browser-policies/syncdisabled
# see https://learn.microsoft.com/en-us/deployedge/microsoft-edge-browser-policies/restoreonstartup
# see https://learn.microsoft.com/en-us/deployedge/microsoft-edge-browser-policies/restoreonstartupurls
# see https://learn.microsoft.com/en-us/deployedge/microsoft-edge-browser-policies/homepagelocation
# see https://learn.microsoft.com/en-us/deployedge/microsoft-edge-browser-policies/newtabpagelocation
$edgePolicyPath = "HKLM:\SOFTWARE\Policies\Microsoft\Edge"
if (-not (Test-Path $edgePolicyPath)) {
New-Item -Path $edgePolicyPath -Force | Out-Null
}
Set-ItemProperty -Path $edgePolicyPath -Name HideFirstRunExperience -Value 1
Set-ItemProperty -Path $edgePolicyPath -Name SyncDisabled -Value 1
Set-ItemProperty -Path $edgePolicyPath -Name RestoreOnStartup -Value 5
Set-ItemProperty -Path $edgePolicyPath -Name RestoreOnStartupURLs -Value "about:blank"
Set-ItemProperty -Path $EdgePolicyPath -Name HomepageLocation -Value "about:blank"
Set-ItemProperty -Path $EdgePolicyPath -Name NewTabPageLocation -Value "about:blank"
# add support for installing powershell modules from powershellgallery.
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
# replace notepad with notepad3.
choco install -y notepad3
# install 7zip.
choco install -y 7zip.install
# install git.
choco install -y git --params '/GitOnlyOnPath /NoAutoCrlf /SChannel'
choco install -y gitextensions
choco install -y meld
# update $env:PATH with the recently installed Chocolatey packages.
Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1
Update-SessionEnvironment
# configure git.
# see http://stackoverflow.com/a/12492094/477532
git config --global user.name 'Rui Lopes'
git config --global user.email 'rgl@ruilopes.com'
git config --global push.default simple
git config --global core.autocrlf false
git config --global diff.guitool meld
git config --global difftool.meld.path 'C:/Program Files (x86)/Meld/Meld.exe'
git config --global difftool.meld.cmd '\"C:/Program Files (x86)/Meld/Meld.exe\" \"$LOCAL\" \"$REMOTE\"'
git config --global merge.tool meld
git config --global mergetool.meld.path 'C:/Program Files (x86)/Meld/Meld.exe'
git config --global mergetool.meld.cmd '\"C:/Program Files (x86)/Meld/Meld.exe\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" --auto-merge --output \"$MERGED\"'
#git config --list --show-origin
# install Visual Studio Code.
choco install -y vscode
Update-SessionEnvironment
code --install-extension ms-mssql.mssql
code --install-extension ms-vscode.PowerShell
# install msys2.
choco install -y msys2
# configure the msys2 launcher to let the shell inherith the PATH.
$msys2BasePath = 'C:\tools\msys64'
$msys2ConfigPath = "$msys2BasePath\msys2.ini"
[IO.File]::WriteAllText(
$msys2ConfigPath,
([IO.File]::ReadAllText($msys2ConfigPath) `
-replace '#?(MSYS2_PATH_TYPE=).+','$1inherit')
)
# configure msys2 to mount C:\Users at /home.
[IO.File]::WriteAllText(
"$msys2BasePath\etc\nsswitch.conf",
([IO.File]::ReadAllText("$msys2BasePath\etc\nsswitch.conf") `
-replace '(db_home: ).+','$1windows')
)
Write-Output 'C:\Users /home' | Out-File -Encoding ASCII -Append "$msys2BasePath\etc\fstab"
# define a function for easying the execution of bash scripts.
$bashPath = "$msys2BasePath\usr\bin\bash.exe"
function Bash($script) {
$eap = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
try {
# we also redirect the stderr to stdout because PowerShell
# oddly interleaves them.
# see https://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
echo 'exec 2>&1;set -eu;export PATH="/usr/bin:$PATH"' $script | &$bashPath
if ($LASTEXITCODE) {
throw "bash execution failed with exit code $LASTEXITCODE"
}
} finally {
$ErrorActionPreference = $eap
}
}
# configure the shell.
Bash @'
pacman --noconfirm -S vim
cat>~/.bash_history<<"EOF"
EOF
cat>~/.bashrc<<"EOF"
# If not running interactively, don't do anything
[[ "$-" != *i* ]] && return
export EDITOR=vim
export PAGER=less
alias l='ls -lF --color'
alias ll='l -a'
alias h='history 25'
alias j='jobs -l'
EOF
cat>~/.inputrc<<"EOF"
"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOD": backward-word
"\eOC": forward-word
set show-all-if-ambiguous on
set completion-ignore-case on
EOF
cat>~/.vimrc<<"EOF"
syntax on
set background=dark
set esckeys
set ruler
set laststatus=2
set nobackup
autocmd BufNewFile,BufRead Vagrantfile set ft=ruby
autocmd BufNewFile,BufRead *.config set ft=xml
" Usefull setting for working with Ruby files.
autocmd FileType ruby set tabstop=2 shiftwidth=2 smarttab expandtab softtabstop=2 autoindent
autocmd FileType ruby set smartindent cinwords=if,elsif,else,for,while,try,rescue,ensure,def,class,module
" Usefull setting for working with Python files.
autocmd FileType python set tabstop=4 shiftwidth=4 smarttab expandtab softtabstop=4 autoindent
" Automatically indent a line that starts with the following words (after we press ENTER).
autocmd FileType python set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
" Usefull setting for working with Go files.
autocmd FileType go set tabstop=4 shiftwidth=4 smarttab expandtab softtabstop=4 autoindent
" Automatically indent a line that starts with the following words (after we press ENTER).
autocmd FileType go set smartindent cinwords=if,else,switch,for,func
EOF
'@
# install ConEmu.
choco install -y conemu
cp ConEmu.xml "$env:APPDATA\ConEmu.xml"
reg import ConEmu.reg
# cleanup the taskbar by removing the existing icons and unpinning all applications; once the user logs on.
# NB the shell executes these RunOnce commands about ~10s after the user logs on.
[IO.File]::WriteAllText(
"$env:TEMP\ConfigureTaskbar.ps1",
@'
# unpin all applications.
# NB this can only be done in a logged on session.
$pinnedTaskbarPath = "$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
(New-Object -Com Shell.Application).NameSpace($pinnedTaskbarPath).Items() `
| ForEach-Object {
$unpinVerb = $_.Verbs() | Where-Object { $_.Name -eq 'Unpin from tas&kbar' }
if ($unpinVerb) {
$unpinVerb.DoIt()
} else {
$shortcut = (New-Object -Com WScript.Shell).CreateShortcut($_.Path)
if (!$shortcut.TargetPath -and ($shortcut.IconLocation -eq '%windir%\explorer.exe,0')) {
Remove-Item -Force $_.Path
}
}
}
Get-Item HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband `
| Set-ItemProperty -Name Favorites -Value 0xff `
| Set-ItemProperty -Name FavoritesResolve -Value 0xff `
| Set-ItemProperty -Name FavoritesVersion -Value 3 `
| Set-ItemProperty -Name FavoritesChanges -Value 1 `
| Set-ItemProperty -Name FavoritesRemovedChanges -Value 1
# hide the search icon.
Set-ItemProperty -Path HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -Value 0
# hide the task view icon.
Set-ItemProperty -Path HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -Value 0
# never combine the taskbar buttons.
# possibe values:
# 0: always combine and hide labels (default)
# 1: combine when taskbar is full
# 2: never combine
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarGlomLevel -Value 2
# restart explorer to apply the changed settings.
(Get-Process explorer).Kill()
# create Desktop shortcuts.
Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1
Remove-Item -Force 'C:\Users\Public\Desktop\*.lnk'
Remove-Item -Force "$env:USERPROFILE\Desktop\*.lnk"
Install-ChocolateyShortcut `
-ShortcutFilePath "$env:USERPROFILE\Desktop\Computer Certificates.lnk" `
-TargetPath 'C:\Windows\System32\certlm.msc'
Install-ChocolateyShortcut `
-ShortcutFilePath "$env:USERPROFILE\Desktop\Failover Cluster Manager.lnk" `
-TargetPath 'C:\Windows\System32\cluadmin.msc'
Install-ChocolateyShortcut `
-ShortcutFilePath "$env:USERPROFILE\Desktop\Services.lnk" `
-TargetPath 'C:\Windows\System32\services.msc'
# add MSYS2 shortcut to the Desktop and Start Menu.
Install-ChocolateyShortcut `
-ShortcutFilePath "$env:USERPROFILE\Desktop\MSYS2 Bash.lnk" `
-TargetPath 'C:\Program Files\ConEmu\ConEmu64.exe' `
-Arguments '-run {MSYS2} -icon C:\tools\msys64\msys2.ico' `
-IconLocation C:\tools\msys64\msys2.ico `
-WorkingDirectory '%USERPROFILE%'
Install-ChocolateyShortcut `
-ShortcutFilePath "C:\Users\All Users\Microsoft\Windows\Start Menu\Programs\MSYS2 Bash.lnk" `
-TargetPath 'C:\Program Files\ConEmu\ConEmu64.exe' `
-Arguments '-run {MSYS2} -icon C:\tools\msys64\msys2.ico' `
-IconLocation C:\tools\msys64\msys2.ico `
-WorkingDirectory '%USERPROFILE%'
# add SQL Server Management Studio shortcut to the Desktop.
$ssmsPath = Resolve-Path 'C:\Program Files\Microsoft SQL Server Management Studio *\Release\Common7\IDE\Ssms.exe'
if ($ssmsPath -and (Test-Path $ssmsPath)) {
Install-ChocolateyShortcut `
-ShortcutFilePath "$env:USERPROFILE\Desktop\SQL Server Management Studio.lnk" `
-TargetPath $ssmsPath
}
'@)
New-Item -Path HKCU:Software\Microsoft\Windows\CurrentVersion\RunOnce -Force `
| New-ItemProperty -Name ConfigureTaskbar -Value 'PowerShell -WindowStyle Hidden -File "%TEMP%\ConfigureTaskbar.ps1"' -PropertyType ExpandString `
| Out-Null