From 595dff68710f7f58e7e257c3d060e80e413dfb87 Mon Sep 17 00:00:00 2001 From: CrossR Date: Sun, 13 Sep 2020 18:07:45 +0100 Subject: Add PowerShell script and tidy up bash script. --- docs/static/setup.ps1 | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 docs/static/setup.ps1 (limited to 'docs/static/setup.ps1') diff --git a/docs/static/setup.ps1 b/docs/static/setup.ps1 new file mode 100644 index 0000000..acda194 --- /dev/null +++ b/docs/static/setup.ps1 @@ -0,0 +1,176 @@ +$ErrorActionPreference = "Stop" + +function Get-Choice-From-Options { + param( + [String[]] $Options, + [String] $Prompt + ) + + while ($true) { + for ($i = 0; $i -lt $Options.length; $i++) { + Write-Host "$($i + 1)) $($Options[$i])" + } + + Write-Host "$($Options.length + 1)) Quit" + $selection = Read-Host $Prompt + + if ($selection -eq $Options.length + 1) { + Write-Host "Goodbye!" + exit + } + elseif ($selection -le $Options.length) { + $choice = $($selection - 1) + break + } + else { + Write-Host "Invalid Option. Try another one." + } + } + + return $choice +} + +function Test-Git-Config { + param( + [String] $Option, + [String] $ErrMsg + ) + + git config $Option | Out-Null + + if ($lastExitCode -ne 0) { + Write-Host $ErrMsg + exit + } +} + +try { + git | Out-Null +} +catch [System.Management.Automation.CommandNotFoundException] { + Write-Host "Git is not installed, and is required for this script!" + exit +} + +Test-Git-Config -Option "user.name" -ErrMsg "Git username not set!`nRun: git config --global user.name 'My Name'" +Test-Git-Config -Option "user.email" -ErrMsg "Git email not set!`nRun: git config --global user.name 'example@myemail.com'" + +$repo_path = "https://github.com/zmkfirmware/zmk-config-split-template.git" + +$title = "ZMK Config Setup:" +$prompt = "Pick an MCU board" +$options = "nice!nano", "QMK Proton-C", "BlueMicro840 (v1)" +$boards = "nice_nano", "proton_c", "bluemicro840_v1" + +Write-Host "$title" +Write-Host "" +Write-Host "MCU Board Selection:" + +$choice = Get-Choice-From-Options -Options $options -Prompt $prompt +$board = $($boards[$choice]) + +Write-Host "" +Write-Host "Keyboard Shield Selection:" +$prompt = "Pick a keyboard" + +# TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos. +$options = "Kyria", "Lily58", "Corne", "Splitreus62", "Sofle", "Iris", "RoMac" +$names = "kyria", "lily58", "corne", "splitreus62", "sofle", "iris", "romac" +$splits = "y", "y", "y", "y", "y", "y", "n" + +$choice = Get-Choice-From-Options -Options $options -Prompt $prompt +$shield_title = $($options[$choice]) +$shield = $($names[$choice]) +$split = $($splits[$choice]) + +if ($split -eq "n") { + $repo_path = "https://github.com/zmkfirmware/zmk-config-template.git" +} + +$copy_keymap = Read-Host "Copy in the stock keymap for customisation? [Yn]" + +if ($copy_keymap -eq "" -or $copy_keymap -eq "Y" -or $copy_keymap -eq "y") { + $copy_keymap = "yes" +} + +$github_user = Read-Host "GitHub Username (leave empty to skip GitHub repo creation)" + +if ($github_user -ne "") { + $repo_name = Read-Host "GitHub Repo Name [zmk-config]" + + if ($repo_name -eq "") { + $repo_name = "zmk-config" + } + + $github_repo = Read-Host "GitHub Repo [https://github.com/$github_user/$repo_name.git]" + + if ($github_repo -eq "") { + $github_repo = "https://github.com/$github_user/$repo_name.git" + } +} +else { + $repo_name = "zmk-config" + $github_repo = "" +} + +Write-Host "" +Write-Host "Preparing a user config for:" +Write-Host "* MCU Board: ${board}" +Write-Host "* Shield: ${shield}" + +if ($copy_keymap -eq "yes") { + Write-Host "* Copy Keymap?: Yes" +} +else { + Write-Host "* Copy Keymap?: No" +} + +if ($github_repo -ne "") { + Write-Host "* GitHub Repo to Push (please create this in GH first!): $github_repo" +} + +Write-Host "" +$do_it = Read-Host "Continue? [Yn]" + +if ($do_it -ne "" -and $do_it -ne "Y" -and $do_it -ne "y") { + Write-Host "Aborting..." + exit +} + +git clone --single-branch "$repo_path" "$repo_name" +Set-Location "$repo_name" + +Push-Location config + +Invoke-RestMethod -Uri "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${shield}/${shield}.conf" -OutFile "${shield}.conf" + +if ($copy_keymap -eq "yes") { + Invoke-RestMethod -Uri "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${shield}/${shield}.keymap" -OutFile "${shield}.keymap" +} + +Pop-Location + +$build_file = (Get-Content .github/workflows/build.yml).replace("BOARD_NAME", $board) +$build_file = $build_file.replace("SHIELD_NAME", $shield) +$build_file = $build_file.replace("KEYBOARD_TITLE", $shield_title) + +if ($board -eq "proton_c") { + $build_file = $build_file.replace("uf2", "hex") +} + +Set-Content -Path .github/workflows/build.yml -Value $build_file + +Remove-Item -Recurse -Force .git +git init . +git add . +git commit -m "Initial User Config." + +if ($github_repo -ne "") { + git remote add origin "$github_repo" + git push --set-upstream origin $(git symbolic-ref --short HEAD) + + if ($github_repo -imatch "https") { + $actions = "$($github_repo.substring(0, $github_repo.length - 4))/actions" + Write-Host "Your firmware should be availalbe from the GitHub Actions shortly: $actions" + } +} -- cgit v1.2.3 From 550c35db23f15c6835a43fe1d2e4a3b5a04ac2b8 Mon Sep 17 00:00:00 2001 From: CrossR Date: Sun, 20 Sep 2020 12:52:25 +0100 Subject: Fix PR comments, add error checking for push. --- docs/static/setup.ps1 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'docs/static/setup.ps1') diff --git a/docs/static/setup.ps1 b/docs/static/setup.ps1 index acda194..a2d66ee 100644 --- a/docs/static/setup.ps1 +++ b/docs/static/setup.ps1 @@ -16,7 +16,7 @@ function Get-Choice-From-Options { if ($selection -eq $Options.length + 1) { Write-Host "Goodbye!" - exit + exit 1 } elseif ($selection -le $Options.length) { $choice = $($selection - 1) @@ -40,7 +40,7 @@ function Test-Git-Config { if ($lastExitCode -ne 0) { Write-Host $ErrMsg - exit + exit 1 } } @@ -49,7 +49,7 @@ try { } catch [System.Management.Automation.CommandNotFoundException] { Write-Host "Git is not installed, and is required for this script!" - exit + exit 1 } Test-Git-Config -Option "user.name" -ErrMsg "Git username not set!`nRun: git config --global user.name 'My Name'" @@ -134,7 +134,7 @@ $do_it = Read-Host "Continue? [Yn]" if ($do_it -ne "" -and $do_it -ne "Y" -and $do_it -ne "y") { Write-Host "Aborting..." - exit + exit 1 } git clone --single-branch "$repo_path" "$repo_name" @@ -167,10 +167,23 @@ git commit -m "Initial User Config." if ($github_repo -ne "") { git remote add origin "$github_repo" + git push --set-upstream origin $(git symbolic-ref --short HEAD) + # If push failed, assume that the origin was incorrect and give instructions on fixing. + if ($lastExitCode -ne 0) { + Write-Host "Remote repository $github_repo not found..." + Write-Host "Check GitHub URL, and try adding again." + Write-Host "Run the following: " + Write-Host " git remote rm origin" + Write-Host " git remote add origin FIXED_URL" + Write-Host " git push --set-upstream origin $(git symbolic-ref --short HEAD)" + Write-Host "Once pushed, your firmware should be availalbe from GitHub Actions at: $actions" + exit 1 + } + if ($github_repo -imatch "https") { $actions = "$($github_repo.substring(0, $github_repo.length - 4))/actions" - Write-Host "Your firmware should be availalbe from the GitHub Actions shortly: $actions" + Write-Host "Your firmware should be availalbe from GitHub Actions shortly: $actions" } } -- cgit v1.2.3 From cd194dbac4747126f017ce6e9ddf070ca6cc1fef Mon Sep 17 00:00:00 2001 From: CrossR Date: Thu, 24 Sep 2020 17:42:34 +0100 Subject: Add licenses. --- docs/static/setup.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'docs/static/setup.ps1') diff --git a/docs/static/setup.ps1 b/docs/static/setup.ps1 index a2d66ee..3946e66 100644 --- a/docs/static/setup.ps1 +++ b/docs/static/setup.ps1 @@ -1,3 +1,7 @@ +# Copyright (c) 2020 The ZMK Contributors +# +# SPDX-License-Identifier: MIT + $ErrorActionPreference = "Stop" function Get-Choice-From-Options { @@ -10,7 +14,7 @@ function Get-Choice-From-Options { for ($i = 0; $i -lt $Options.length; $i++) { Write-Host "$($i + 1)) $($Options[$i])" } - + Write-Host "$($Options.length + 1)) Quit" $selection = Read-Host $Prompt @@ -103,7 +107,7 @@ if ($github_user -ne "") { } $github_repo = Read-Host "GitHub Repo [https://github.com/$github_user/$repo_name.git]" - + if ($github_repo -eq "") { $github_repo = "https://github.com/$github_user/$repo_name.git" } -- cgit v1.2.3 From 4de7cc45de18f791ecbb361bfc2330a45e97d79e Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 5 Oct 2020 09:43:05 -0400 Subject: feat(setup): Add M.2 and M60 to setup scripts. --- docs/static/setup.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/static/setup.ps1') diff --git a/docs/static/setup.ps1 b/docs/static/setup.ps1 index 3946e66..dc7b18c 100644 --- a/docs/static/setup.ps1 +++ b/docs/static/setup.ps1 @@ -63,8 +63,8 @@ $repo_path = "https://github.com/zmkfirmware/zmk-config-split-template.git" $title = "ZMK Config Setup:" $prompt = "Pick an MCU board" -$options = "nice!nano", "QMK Proton-C", "BlueMicro840 (v1)" -$boards = "nice_nano", "proton_c", "bluemicro840_v1" +$options = "nice!nano", "QMK Proton-C", "BlueMicro840 (v1)", "makerdiary nRF52840 M.2" +$boards = "nice_nano", "proton_c", "bluemicro840_v1", "nrf52840_m2" Write-Host "$title" Write-Host "" @@ -78,9 +78,9 @@ Write-Host "Keyboard Shield Selection:" $prompt = "Pick a keyboard" # TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos. -$options = "Kyria", "Lily58", "Corne", "Splitreus62", "Sofle", "Iris", "RoMac" -$names = "kyria", "lily58", "corne", "splitreus62", "sofle", "iris", "romac" -$splits = "y", "y", "y", "y", "y", "y", "n" +$options = "Kyria", "Lily58", "Corne", "Splitreus62", "Sofle", "Iris", "RoMac", "makerdiary M60" +$names = "kyria", "lily58", "corne", "splitreus62", "sofle", "iris", "romac", "m60" +$splits = "y", "y", "y", "y", "y", "y", "n", "n" $choice = Get-Choice-From-Options -Options $options -Prompt $prompt $shield_title = $($options[$choice]) -- cgit v1.2.3 From 81a4ffef7efb45f30c74802dca97d949312a1785 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 9 Oct 2020 15:44:39 -0400 Subject: feat(setup): Add Microdox to setup scripts. --- docs/static/setup.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/static/setup.ps1') diff --git a/docs/static/setup.ps1 b/docs/static/setup.ps1 index dc7b18c..abdb698 100644 --- a/docs/static/setup.ps1 +++ b/docs/static/setup.ps1 @@ -78,9 +78,9 @@ Write-Host "Keyboard Shield Selection:" $prompt = "Pick a keyboard" # TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos. -$options = "Kyria", "Lily58", "Corne", "Splitreus62", "Sofle", "Iris", "RoMac", "makerdiary M60" -$names = "kyria", "lily58", "corne", "splitreus62", "sofle", "iris", "romac", "m60" -$splits = "y", "y", "y", "y", "y", "y", "n", "n" +$options = "Kyria", "Lily58", "Corne", "Splitreus62", "Sofle", "Iris", "RoMac", "makerdiary M60", "Microdox" +$names = "kyria", "lily58", "corne", "splitreus62", "sofle", "iris", "romac", "m60", "microdox" +$splits = "y", "y", "y", "y", "y", "y", "n", "n", "y" $choice = Get-Choice-From-Options -Options $options -Prompt $prompt $shield_title = $($options[$choice]) -- cgit v1.2.3 From b64517943deb3dfe72e2e37ca62319856bc35752 Mon Sep 17 00:00:00 2001 From: Kellen Carey Date: Fri, 9 Oct 2020 18:53:21 -0700 Subject: add powershell check --- docs/static/setup.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docs/static/setup.ps1') diff --git a/docs/static/setup.ps1 b/docs/static/setup.ps1 index abdb698..1da5737 100644 --- a/docs/static/setup.ps1 +++ b/docs/static/setup.ps1 @@ -59,6 +59,19 @@ catch [System.Management.Automation.CommandNotFoundException] { Test-Git-Config -Option "user.name" -ErrMsg "Git username not set!`nRun: git config --global user.name 'My Name'" Test-Git-Config -Option "user.email" -ErrMsg "Git email not set!`nRun: git config --global user.name 'example@myemail.com'" +$permission = (Get-Acl $PSScriptRoot).Access | +?{$_.IdentityReference -match $env:UserName ` + -and $_.FileSystemRights -match "Read" ` + -or $_.FileSystemRights -match "Write" } | + + Select IdentityReference,FileSystemRights + +If (-Not $permission){ + Write-Host "Sorry, you do not have write permissions in this directory." + Write-Host "Please try running this script again from a directory that you do have write permissions for." + exit 1 +} + $repo_path = "https://github.com/zmkfirmware/zmk-config-split-template.git" $title = "ZMK Config Setup:" -- cgit v1.2.3 From 4aa45c6f40c3e640cebce58b4d10cd24dc61b8ed Mon Sep 17 00:00:00 2001 From: Kellen Carey Date: Sat, 10 Oct 2020 17:00:13 -0700 Subject: update setup.ps1 --- docs/static/setup.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/static/setup.ps1') diff --git a/docs/static/setup.ps1 b/docs/static/setup.ps1 index 1da5737..63bd5c0 100644 --- a/docs/static/setup.ps1 +++ b/docs/static/setup.ps1 @@ -57,11 +57,11 @@ catch [System.Management.Automation.CommandNotFoundException] { } Test-Git-Config -Option "user.name" -ErrMsg "Git username not set!`nRun: git config --global user.name 'My Name'" -Test-Git-Config -Option "user.email" -ErrMsg "Git email not set!`nRun: git config --global user.name 'example@myemail.com'" +Test-Git-Config -Option "user.email" -ErrMsg "Git email not set!`nRun: git config --global user.email 'example@myemail.com'" -$permission = (Get-Acl $PSScriptRoot).Access | +$permission = (Get-Acl $pwd).Access | ?{$_.IdentityReference -match $env:UserName ` - -and $_.FileSystemRights -match "Read" ` + -and $_.FileSystemRights -match "FullControl" ` -or $_.FileSystemRights -match "Write" } | Select IdentityReference,FileSystemRights -- cgit v1.2.3 From 94bc2c31b14d5ace4c51f409f934ef077323eb32 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 13 Oct 2020 00:23:25 -0400 Subject: feat: Add a couple missing shields to user setup. --- docs/static/setup.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/static/setup.ps1') diff --git a/docs/static/setup.ps1 b/docs/static/setup.ps1 index 63bd5c0..1686be2 100644 --- a/docs/static/setup.ps1 +++ b/docs/static/setup.ps1 @@ -91,9 +91,9 @@ Write-Host "Keyboard Shield Selection:" $prompt = "Pick a keyboard" # TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos. -$options = "Kyria", "Lily58", "Corne", "Splitreus62", "Sofle", "Iris", "RoMac", "makerdiary M60", "Microdox" -$names = "kyria", "lily58", "corne", "splitreus62", "sofle", "iris", "romac", "m60", "microdox" -$splits = "y", "y", "y", "y", "y", "y", "n", "n", "y" +$options = "Kyria", "Lily58", "Corne", "Splitreus62", "Sofle", "Iris", "RoMac", "RoMac+", "makerdiary M60", "Microdox", "TG4X" +$names = "kyria", "lily58", "corne", "splitreus62", "sofle", "iris", "romac", "romac_plus", "m60", "microdox", "tg4x" +$splits = "y", "y", "y", "y", "y", "y", "n", "n", "n", "y", "n" $choice = Get-Choice-From-Options -Options $options -Prompt $prompt $shield_title = $($options[$choice]) -- cgit v1.2.3 From 43c900f94a9394bc09bdfc646bfd3f42f947d927 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 13 Oct 2020 19:46:02 -0400 Subject: feat: Add qaz to setup scripts. --- docs/static/setup.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/static/setup.ps1') diff --git a/docs/static/setup.ps1 b/docs/static/setup.ps1 index 1686be2..5ebd376 100644 --- a/docs/static/setup.ps1 +++ b/docs/static/setup.ps1 @@ -91,9 +91,9 @@ Write-Host "Keyboard Shield Selection:" $prompt = "Pick a keyboard" # TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos. -$options = "Kyria", "Lily58", "Corne", "Splitreus62", "Sofle", "Iris", "RoMac", "RoMac+", "makerdiary M60", "Microdox", "TG4X" -$names = "kyria", "lily58", "corne", "splitreus62", "sofle", "iris", "romac", "romac_plus", "m60", "microdox", "tg4x" -$splits = "y", "y", "y", "y", "y", "y", "n", "n", "n", "y", "n" +$options = "Kyria", "Lily58", "Corne", "Splitreus62", "Sofle", "Iris", "RoMac", "RoMac+", "makerdiary M60", "Microdox", "TG4X", "QAZ" +$names = "kyria", "lily58", "corne", "splitreus62", "sofle", "iris", "romac", "romac_plus", "m60", "microdox", "tg4x", "qaz" +$splits = "y", "y", "y", "y", "y", "y", "n", "n", "n", "y", "n", "n" $choice = Get-Choice-From-Options -Options $options -Prompt $prompt $shield_title = $($options[$choice]) -- cgit v1.2.3