-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.ps1
executable file
·46 lines (44 loc) · 3.89 KB
/
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
set-location "$PSScriptRoot"
[string] $SCRIPT_VERSION = "1.0.2"
write-host "libmecha インストールスクリプト Ver.$SCRIPT_VERSION" -foregroundcolor cyan
write-host "Created by M.s [22er]" -foregroundcolor cyan
write-host
if(((test-path "..\CMakeLists.txt") -eq "False") -or ((test-path "..\CMakeLists_template.txt") -eq "False")) {
write-host "Error: 親ディレクトリがSTM32プロジェクト(CMakeプロジェクト)ではありません。" -foregroundcolor red
write-host " STM32プロジェクトルートの直下にlibmechaディレクトリ、その配下にこのファイルが存在するようにして下さい。" -foregroundcolor red
exit 1
}
if((((get-acl "..\CMakeLists.txt").Access | where-object {$_.IdentityReference -match "$User" -and $_.AccessControlType -match "Allow"} | foreach-object {$t = $False} {$t = (($_FileSystemRights -band [System.Security.AccessControl.FileSystemRights]::Read) -eq [System.Security.AccessControl.FileSystemRights]::Read) -or $t} {$t}) -eq "False") -or (((get-acl "..\CMakeLists_template.txt").Access | where-object {$_.IdentityReference -match "$User" -and $_.AccessControlType -match "Allow"} | foreach-object {$t = $False} {$t = (($_FileSystemRights -band [System.Security.AccessControl.FileSystemRights]::Read) -eq [System.Security.AccessControl.FileSystemRights]::Read) -or $t} {$t}) -eq "False")) {
write-host "Error: ルートプロジェクトのCMakeLists.txtに読み取り権限がありません。" -foregroundcolor red
write-host " 権限を付与するか適切なユーザーで実行して下さい。" -foregroundcolor red
exit 2
}
if((((get-acl "..\CMakeLists.txt").Access | where-object {$_.IdentityReference -match "$User" -and $_.AccessControlType -match "Allow"} | foreach-object {$t = $False} {$t = (($_FileSystemRights -band [System.Security.AccessControl.FileSystemRights]::Write) -eq [System.Security.AccessControl.FileSystemRights]::Write) -or $t} {$t}) -eq "False") -or (((get-acl "..\CMakeLists_template.txt").Access | where-object {$_.IdentityReference -match "$User" -and $_.AccessControlType -match "Allow"} | foreach-object {$t = $False} {$t = (($_FileSystemRights -band [System.Security.AccessControl.FileSystemRights]::Write) -eq [System.Security.AccessControl.FileSystemRights]::Write) -or $t} {$t}) -eq "False")) {
write-host "Error: ルートプロジェクトのCMakeLists.txtに書き込み権限がありません。" -foregroundcolor red
write-host " 権限を付与するか適切なユーザーで実行して下さい。" -foregroundcolor red
exit 3
}
if(((get-content "..\CMakeLists.txt" | select-string -quiet "# Powered by libmecha from mechalab")) -or ((get-content "..\CMakeLists_template.txt" | select-string -quiet "# Powered by libmecha from mechalab"))) {
write-host "Info: 既に組み込まれています。" -foregroundcolor green
exit 0
}
write-host "Info: ルートプロジェクトにlibmechaを組み込みます。" -foregroundcolor green
$result = $host.ui.PromptForChoice("", "よろしいですか?", [System.Management.Automation.Host.ChoiceDescription[]]((new-object System.Management.Automation.Host.ChoiceDescription "&y" "インストールを実行する。"), (new-object System.Management.Automation.Host.ChoiceDescription "&n" "インストールを中断する。")), 0)
if($result -eq 1) {
write-host "Info: 中断しました。" -foregroundcolor green
exit 0
}
write-output @"
# Powered by libmecha from mechalab
include_directories(libmecha/include)
add_subdirectory(libmecha)
target_link_libraries(`${PROJECT_NAME}.elf mecha)
"@ | out-file -append "..\CMakeLists.txt"
write-output @"
# Powered by libmecha from mechalab
include_directories(libmecha/include)
add_subdirectory(libmecha)
target_link_libraries(`$`${PROJECT_NAME}.elf mecha)
"@ | out-file -append "..\CMakeLists_template.txt"
write-host "Info: 正常に終了しました。" -foreground green
exit 0