-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin_install.ps1
68 lines (56 loc) · 2.35 KB
/
win_install.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
$art = @"
_ _ _ _ _ __ _ _
| | | | | | | | | | / _|(_)| |
__| | _ _ | |__ ___ | | __ _ _ __| | ___ | |_ | |_ _ | | ___ ___
/ _` || | | || '_ \ / __|| |/ /| | | | / _` | / _ \ | __|| _|| || | / _ \/ __|
| (_| || |_| || |_) |\__ \| < | |_| | _| (_| || (_) || |_ | | | || || __/\__ \
\__,_| \__,_||_.__/ |___/|_|\_\ \__, | (_)\__,_| \___/ \__||_| |_||_| \___||___/
__/ |
|___/
"@
function Test-Admin {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole($adminRole)
}
Write-Host $art -ForegroundColor Cyan
if (-not (Test-Admin)) {
Write-Host "This script must be run as an administrator!" -ForegroundColor Red
exit
}
$UserProfile = [System.Environment]::GetFolderPath('UserProfile')
$links = @(
@{
LinkPath = "$UserProfile\Documents\PowerShell\Microsoft.PowerShell_profile.ps1"
TargetPath = "$UserProfile\.dotfiles\powershell\Microsoft.PowerShell_profile.ps1"
},
@{
LinkPath = "$UserProfile\AppData\Local\nvim"
TargetPath = "$UserProfile\.dotfiles\nvim\.config\nvim"
},
@{
LinkPath = "$UserProfile\.wezterm.lua"
TargetPath = "$UserProfile\.dotfiles\wezterm\.config\wezterm\.wezterm.lua"
}
)
if (-not (Test-Path -Path "$UserProfile\Documents\PowerShell")) {
New-Item -ItemType Directory -Path "$UserProfile\Documents\PowerShell"
}
foreach ($link in $links) {
$LinkPath = $link.LinkPath
$TargetPath = $link.TargetPath
if (-Not (Test-Path -Path $TargetPath)) {
Write-Error "The target path '$TargetPath' does not exist."
continue
}
try {
if (Test-Path -Path $LinkPath) {
Remove-Item -Path $LinkPath -Recurse -Force
}
New-Item -Path $LinkPath -ItemType SymbolicLink -Value $TargetPath
Write-Output "Symbolic link created successfully: $LinkPath -> $TargetPath"
} catch {
Write-Error "Failed to create symbolic link: $_"
}
}