-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.ps1
75 lines (60 loc) · 2.3 KB
/
deploy.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
function Test-Admin {
(
[Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::
GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Start-ScriptAsAdmin {
param(
[string]
$ScriptPath,
[object[]]
$ArgumentList
)
if (!(Test-Admin)) {
$list = @($ScriptPath)
if ($null -ne $ArgumentList) {
$list += @($ArgumentList)
}
# デフォルトのPowerShell
# Start-Process powershell -ArgumentList $list -Verb RunAs -Wait
# PowerShell Core
Start-Process pwsh -ArgumentList $list -Verb RunAs -Wait
}
}
# 管理者権限で再実行
Start-ScriptAsAdmin -ScriptPath $PSCommandPath
# dotfilesディレクトリの絶対パス取得
$path = (Convert-Path $PSCommandPath)
$parent = (Split-Path -Parent $path)
$configPath = (Join-Path -Path $parent -ChildPath "config")
$dotsPath = (Join-Path -Path $parent -ChildPath "dots")
Write-Host "${configPath}" -ForegroundColor Red
Write-Host "${dotsPath}" -ForegroundColor Red
if (Test-Admin) {
$directories = Get-ChildItem -name -Directory $parent
$configs = Get-ChildItem -name $configPath
$dots = Get-ChildItem -name $dotsPath
# ディレクトリのシンボリックリンク
foreach ($dir in $configs) {
$linkpath = (Join-Path -Resolve $configPath $dir)
New-Item -Type SymbolicLink -Path ~\.config -Name $dir -Value $linkpath
# alacrittyを%APPDATA%にリンクつくる
if ($dir -eq "alacritty") {
New-Item -Type SymbolicLink -Path $env:APPDATA -Name $dir -Value $linkpath
}
}
foreach ($dot in $dots) {
$linkpath = (Join-Path -Resolve $dotsPath $dot)
New-Item -Type SymbolicLink -Path ~ -Name $dot -Value $linkpath
}
$linkpath = (Join-Path -Resolve $parent "Profile.ps1")
$profilepath = (Split-Path -Parent $PROFILE)
# PROFILEのシンボリックリンク
New-Item -Force -Type SymbolicLink -Path $profilepath -Name "Profile.ps1" -Value $linkpath
$userChromeCssPath = (Join-Path -Resolve $parent "userChrome.css")
$firefoxProfilePath = (Join-Path -Path $env:UserProfile -ChildPath "scoop\persist\firefox\profile\chrome")
New-Item -Force -Type SymbolicLink -Path $firefoxProfilePath -Name "userChrome.css" -Value $userChromeCssPath
Write-Host "Complete!!" -ForegroundColor Red
Read-Host "Please press any key."
}