-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-windows.ps1
48 lines (38 loc) · 1.67 KB
/
setup-windows.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
Param($setupScript)
$setupScriptArgs = $Args
Set-ExecutionPolicy Bypass -Scope Process -Force
$ErrorActionPreference = "Stop"
# 管理者権限の確認
if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -eq $False) {
# 管理者に昇格して再実行
$argList = "-File ""$PSCommandPath"" ""$setupScript"" "+($setupScriptArgs -replace "^|$", """" -join " ")
Start-Process powershell.exe -Verb runas -ArgumentList $argList -Wait
exit $?
}
# Script設置フォルダパス
$Current = Split-Path $PSCommandPath
# 再起動が必要
$reboot = $False
# WSLの有効化
powershell -File "$Current\script\windows\configure-wsl.ps1"
if ($LASTEXITCODE -eq -1) { $reboot = $True }
elseif (-Not $?) { exit 1 }
# Ansibleによる設定の受付準備
powershell -File "$Current\script\windows\configure-openssh.ps1"
if ($LASTEXITCODE -eq -1) { $reboot = $True }
elseif (-Not $?) { exit 1 }
if ($reboot) {
$scriptName = Split-Path -Leaf $PSCommandPath
Write-Host "Windowsの設定を変更しました。再起動後、もう一度 $scriptName を実行してください。"
}
else {
# ubuntuのインストール
powershell -File "$Current\script\windows\install-wsl-ubuntu.ps1"
if ($? -eq $False) { exit 1 }
# セットアップコマンドの実行
$driveLetter = $Current.Substring(0, 1).ToLower()
$wslPath = "$Current\$setupScript" -replace "\\", "/" -replace "^\w:", "/mnt/$driveLetter" -replace "^//wsl.localhost/Ubuntu", ""
ubuntu run bash "$wslPath" "-e win_username=$env:USERNAME" $setupScriptArgs
if ($? -eq $False) { exit 1 }
}
exit 0