-
Notifications
You must be signed in to change notification settings - Fork 1
/
windows-setup-script.ps1
133 lines (99 loc) · 4.96 KB
/
windows-setup-script.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# * Imports
Import-Module "$PSScriptRoot\app-install-helpers\chocolatey-install.psm1"
Import-Module "$PSScriptRoot\app-install-helpers\winget-install.psm1"
Import-Module "$PSScriptRoot\app-install-helpers\scoop-install.psm1"
Import-Module "$PSScriptRoot\app-install-helpers\python-poetry.ps1"
# * Variables
# URLs
$conf_url = "https://github.com/melvinquick/windows-config-files.git"
# App Install Lists
$chocolatey_apps = Get-Content -Path "$PSScriptRoot\app-install-lists\chocolatey-apps-list.txt"
$scoop_apps = Get-Content -Path "$PSScriptRoot\app-install-lists\scoop-apps-list.txt"
$winget_apps = Get-Content -Path "$PSScriptRoot\app-install-lists\winget-apps-list.txt"
# System/User Directories
$conf_dir = "$HOME\Downloads\windows-config-files\home"
$working_dir = "$HOME\Downloads"
# * Introduction
Write-Host "# --- Introduction --- #" -ForegroundColor Green
# Let user know that running scripts they find online can be dangerous and that they should proceed with caution
Write-Host "`nDISCLAIMER: NEVER RUN SCRIPTS YOU FIND ON THE INTERNET BEFORE FIRST READING THROUGH THEM!" -ForegroundColor Red
Write-Host "`nWelcome to your new Windows Setup Script!" -ForegroundColor Green
Write-Host "`nThis script downloads and installs programs, moves my configs for various programs to their correct locations, and a few other things."
Write-Host "Please read through the script BEFORE executing it to make sure it doesn't do anything you don't want it to!"
$user_input = Read-Host "Would you like to run the setup? (y/n)"
# * Main
Write-Host "`n# --- Main --- #" -ForegroundColor Green
if ($user_input.ToLower() -eq "y") {
# Set working directory for script
Write-Host "`nSetting the working directory for the script."
Set-Location -Path $working_dir
# * Poetry
Write-Host "`n# --- Poetry --- #" -ForegroundColor Green
Install-Poetry
# * Chocolatey
Write-Host "`n# --- Chocolatey --- #" -ForegroundColor Green
Install-Chocolatey
Write-Host "Installing programs via Chocolatey..."
# Install apps with Chocolatey
foreach ($chocolatey_app in $chocolatey_apps) {
choco install $chocolatey_app -y
}
# * Winget
Write-Host "`n# --- Winget --- #" -ForegroundColor Green
Install-Winget
Write-Host "Installing programs via Winget..."
# Install apps with Winget
foreach ($winget_app in $winget_apps) {
winget install -e --id $winget_app --silent --accept-package-agreements --accept-source-agreements
}
# * Scoop
Write-Host "`n# --- Scoop --- #" -ForegroundColor Green
Install-Scoop
Write-Host "Installing extra Buckets for Scoop..."
# Install apps with Scoop
foreach ($scoop_bucket in $scoop_buckets) {
scoop bucket add $scoop_bucket
}
Write-Host "Installing programs via Scoop..."
# Install apps with Scoop
foreach ($scoop_app in $scoop_apps) {
scoop install $scoop_app
}
# * Configs
Write-Host "`n# --- Configs --- #" -ForegroundColor Green
# Git clone repo
Write-Host "`nDownloading the config files from GitHub..."
git clone $conf_url --quiet
# Copy all configs to their correct locations
Write-Host "`nMoving all config files to their correct locations..."
# Set location to the correct directory and get the file paths for each config
Set-Location -Path $conf_dir
$base_path = Resolve-Path .
$file_paths = Get-ChildItem -LiteralPath $conf_dir -File -Recurse | ForEach-Object { (Join-Path ((Split-Path $_.FullName -Parent) -replace "^\\", "") $_.Name) -replace ("^{0}\\?" -f [regex]::Escape($base_path)), "" }
# Move each config to the correct location
foreach ($file in $file_paths) {
$destination = "$HOME\$file"
if ((Test-Path -Path $destination) -eq $false) {
New-Item -Path $destination -Force
}
Copy-Item -Path $file -Destination $destination -Force
}
# * Cleanup
Write-Host "`n# --- Cleanup --- #" -ForegroundColor Green
# Delete desktop icons and temp folder files that were created during the process of running this script
Write-Host "`nDeleting Desktop Icons and Temp Files that were created from program installs..."
Get-ChildItem -Path "$HOME\Desktop" | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
Get-ChildItem -Path "C:\Users\Public\Desktop" | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
Get-ChildItem -Path "$HOME\AppData\Local\Temp" | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
Get-ChildItem -Path $working_dir | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
# Clear the recycle bin
Write-Host "Emptying the Recycle Bin..."
Clear-RecycleBin -Force
}
elseif ($user_input.ToLower() -eq "n") {
Write-Host "`nYou decided to not run the script. No Problem! If you'd like to use it at a later date, just run it again!" -ForegroundColor Red
}
else {
Write-Host "`nInvalid input. Starting the script over again!`n" -ForegroundColor Yellow
.\"windows-setup-script.ps1"
}