forked from asolopovas/winconf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.ps1
More file actions
113 lines (96 loc) · 3.43 KB
/
init.ps1
File metadata and controls
113 lines (96 loc) · 3.43 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
param([switch]$Software)
Start-Transcript -Path "$ENV:TEMP\winconf.log" -Append
$DOTFILES = "$env:userprofile\winconf"
$SCRIPTS_DIR = "$DOTFILES\scripts"
$REPO_URL = 'https://github.com/asolopovas/winconf.git'
$AUTOHOTKEYVERSION = 2
$USER = $env:USERNAME
$ESSENTIAL_SOFTWARE = @(
'AutoHotkey.AutoHotkey'
'Git.Git'
'junegunn.fzf'
"Microsoft.PowerToys"
'Microsoft.PowerShell'
'voidtools.Everything'
'Starship.Starship'
"sharkdp.fd"
"VideoLAN.VLC"
)
$SOURCE_FILES = @(
'Bloatware-Removal'
'Cleanup'
'Setup-EnvironmentPaths'
'Setup-NerdFonts'
'Setup-Powershell'
'Setup-Terminal'
'Setup-Autohotkey'
)
if ($Software) {
$SOURCE_FILES += 'Setup-Software'
}
Write-Host "Setting execution policy to RemoteSigned..." -ForegroundColor Yellow
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
function Test-CommandExists {
Param ($command)
try { return [bool](Get-Command $command -ErrorAction Stop) }
Catch { return $false }
}
function SourceFile {
param ($file)
Write-Host "`nSourcing $file ..." -ForegroundColor DarkCyan
if ($file -eq 'Setup-Autohotkey') {
& "$SCRIPTS_DIR\$file.ps1" -version $AUTOHOTKEYVERSION
} else {
& "$SCRIPTS_DIR\$file.ps1"
}
}
Write-Host "Resetting and updating winget sources..." -ForegroundColor Green
winget source reset --force
winget source update
Write-Host "Winget sources updated." -ForegroundColor Green
foreach ($soft in $ESSENTIAL_SOFTWARE) {
Write-Host "Installing $soft... " -ForegroundColor DarkGray
winget install --id $soft -h --disable-interactivity --accept-source-agreements --accept-package-agreements --force
}
if (!(Test-CommandExists git)) {
Write-Host "Adding git to Path" -ForegroundColor Yellow
$gitPath = "$env:ProgramFiles\Git\cmd"
if (Test-Path $gitPath) {
[System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";$gitPath", [System.EnvironmentVariableTarget]::Machine)
$env:PATH += ";$gitPath"
Write-Host "Git added to PATH." -ForegroundColor Green
} else {
Write-Host "Git still not found. Please install Git manually." -ForegroundColor Red
exit 1
}
}
git config --global --add safe.directory "$DOTFILES"
if (!(Test-Path -Path $DOTFILES)) {
Write-Host "Cloning repository into $DOTFILES..." -ForegroundColor DarkGray
git clone $REPO_URL $DOTFILES
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to clone the repository. Exiting..." -ForegroundColor Red
exit 1
}
Write-Host "Fixing repository ownership for $USER..." -ForegroundColor Yellow
takeown /F $DOTFILES /R /D Y
icacls $DOTFILES /grant "${USER}:(OI)(CI)F" /T /C
} else {
Write-Host "$DOTFILES already exists. Pulling the latest changes..." -ForegroundColor DarkGray
Set-Location -Path $DOTFILES
git pull
}
$modulePath = "$env:USERPROFILE\winconf\powershell\modules"
if (Test-Path $modulePath) {
$env:PSModulePath = "$modulePath;$env:PSModulePath"
Write-Host "Added $modulePath to PSModulePath." -ForegroundColor Green
}
if (!(Test-Path -Path $SCRIPTS_DIR)) {
Write-Host "Scripts directory not found. Cloning might have failed." -ForegroundColor Red
exit 1
}
foreach ($file in $SOURCE_FILES) {
SourceFile $file
}
Write-Host "Initialization complete!" -ForegroundColor Green
Stop-Transcript