-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.ps1
103 lines (88 loc) · 3.48 KB
/
config.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
[Diagnostics.CodeAnalysis.SuppressMessage("PSReviewUnusedParameter", "SkipBackup")]
param([switch]$DryRun, [switch]$SkipBackup, [string]$Run)
$totalDuration = [Diagnostics.Stopwatch]::StartNew()
. $PSScriptRoot\config-functions.ps1
mkdir C:\BenLocal\backup -ErrorAction Ignore
Block "Configure for" {
$configureForOptions = {
[Diagnostics.CodeAnalysis.SuppressMessage("PSUseDeclaredVarsMoreThanAssignments", "")]
$forHome = "home"
[Diagnostics.CodeAnalysis.SuppressMessage("PSUseDeclaredVarsMoreThanAssignments", "")]
$forWork = "work"
[Diagnostics.CodeAnalysis.SuppressMessage("PSUseDeclaredVarsMoreThanAssignments", "")]
$forKids = "kids"
[Diagnostics.CodeAnalysis.SuppressMessage("PSUseDeclaredVarsMoreThanAssignments", "")]
$forHtpc = "htpc"
[Diagnostics.CodeAnalysis.SuppressMessage("PSUseDeclaredVarsMoreThanAssignments", "")]
$forTest = "test"
}
. $configureForOptions
while (($configureFor = (Read-Host "Configure for ($forHome,$forWork,$forKids,$forHtpc,$forTest)")) -notin @($forHome, $forWork, $forKids, $forHtpc, $forTest)) { }
if (!(Test-Path $profile)) {
New-Item $profile -Force
}
Add-Content -Path $profile -Value "`n"
Add-Content -Path $profile $configureForOptions
Add-Content -Path $profile -Value "`$configureFor = `"$configureFor`""
Add-Content -Path $profile {
function Configured([Parameter(Mandatory)][ValidateSet("home", "work", "kids", "htpc", "test")][string[]]$for) {
return $configureFor -in $for
}
}
} {
(Test-Path $profile) -and (Select-String "\`$configureFor" $profile) # -Pattern is regex
}
if (!$DryRun -and !$Run) { . $profile } # make profile available to scripts below
Block "Backup Registry" {
if (!(Configured $forTest)) {
& $PSScriptRoot\backup-registry.ps1
}
} {
$SkipBackup
}
if (Configured $forHome) {
FirstRunBlock "Change drive letters" {
# Consider using Set-Partition or Set-Volume
start diskmgmt.msc
Write-ManualStep "Change drive letters"
Read-Host "Press Enter when done"
}
Block "Restore file backups" {
wt -w 0 nt pwsh -NoExit -File $PSScriptRoot\restore-file-backups.ps1
} {
Test-Path C:\Ben
}
}
& $PSScriptRoot\powershell\config.ps1
if (!$DryRun -and !$Run) {
. $profile.AllUsersAllHosts
. $profile.AllUsersCurrentHost
. $profile.CurrentUserAllHosts
. $profile.CurrentUserCurrentHost
Update-WindowsTerminalSettings
}
Block "Git config" {
git config --global --add include.path $PSScriptRoot\git\ben.gitconfig
} {
(git config --get-all --global include.path) -match "ben\.gitconfig"
}
& $PSScriptRoot\windows\config.ps1
& $PSScriptRoot\install\install.ps1
if (Configured $forHome, $forWork, $forTest) {
& $PSScriptRoot\work\config.ps1
}
& $PSScriptRoot\scheduled-tasks\config.ps1
if (Configured $forHome, $forWork, $forTest) {
Block "Configure taskbar" {
$taskbarVersion = (Configured $forWork) ? "work" : "home"
Import-StartLayout $PSScriptRoot\windows\start-task-tray\TaskbarLayout.$taskbarVersion.xml $env:SystemDrive\
} {
Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name LayoutXMLLastModified -ErrorAction Ignore
} -RequiresReboot
}
Block "Blocks of interest this run" {
$global:blocksOfInterest | % { Write-Output "`t$_" }
} {
$global:blocksOfInterest.Length -eq 0
}
Write-Output "Total duration: $($totalDuration.Elapsed)"