From b8fb218a0195974a3df8367670051acf864d395e Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Fri, 16 Dec 2022 14:43:47 -0800 Subject: [PATCH] fix(setup): Make keymap/conf fall back to using dirname --- docs/src/templates/setup.ps1.mustache | 35 +++++++++++++++++---------- docs/src/templates/setup.sh.mustache | 24 ++++++++++-------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/docs/src/templates/setup.ps1.mustache b/docs/src/templates/setup.ps1.mustache index 54c5ae82..a2bf0c58 100644 --- a/docs/src/templates/setup.ps1.mustache +++ b/docs/src/templates/setup.ps1.mustache @@ -209,27 +209,36 @@ Set-Location "$repo_name" Push-Location config -$config_file = "${keyboard}.conf" -$keymap_file = "${keyboard}.keymap" - if ($keyboard_type -eq "shield") { - $config_url = "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${basedir}/${keyboard}.conf" - $keymap_url = "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${basedir}/${keyboard}.keymap" + $url_base = "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${basedir}" } else { - $config_url = "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/${keyboard_arch}/${basedir}/${keyboard}.conf" - $keymap_url = "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/${keyboard_arch}/${basedir}/${keyboard}.keymap" + $url_base = "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/${keyboard_arch}/${basedir}" } -Write-Host "Downloading config file (${config_url})" +Write-Host "Downloading config file (${url_base}/${keyboard}.conf)" Try { - Invoke-RestMethod -Uri "${config_url}" -OutFile "${config_file}" + Invoke-RestMethod -Uri "${config_url}" -OutFile "${keyboard}.conf" } Catch { - Set-Content -Path $config_file "# Place configuration items here" + Try { + Write-Host "Could not find it, falling back to ${url_base}/${basedir}.conf" + Invoke-RestMethod -Uri "${url_base}/${basedir}.conf" -OutFile "${basedir}.conf" + } Catch { + Set-Content -Path "${keyboard}.conf" "# Put configuration options here" + } } if ($copy_keymap -eq "yes") { - Write-Host "Downloading keymap file (${keymap_url})" - Invoke-RestMethod -Uri "${keymap_url}" -OutFile "${keymap_file}" + Write-Host "Downloading keymap file (${url_base}/${keyboard}.keymap)" + Try { + Invoke-RestMethod -Uri "${url_base}/${keyboard}.keymap" -OutFile "${keyboard}.keymap" + } Catch { + Write-Host "Could not find it, falling back to ${url_base}/${basedir}.keymap" + Try { + Invoke-RestMethod -Uri "${url_base}/${basedir}.keymap" -OutFile "${basedir}.keymap" + } Catch { + Write-Host "Warning: Could not find a keymap file to download!" + } + } } Pop-Location @@ -264,7 +273,7 @@ if ($github_repo -ne "") { 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" + Write-Host "Once pushed, your firmware should be available from GitHub Actions at: $actions" exit 1 } diff --git a/docs/src/templates/setup.sh.mustache b/docs/src/templates/setup.sh.mustache index 3184aab2..4c3868ec 100644 --- a/docs/src/templates/setup.sh.mustache +++ b/docs/src/templates/setup.sh.mustache @@ -205,19 +205,23 @@ cd ${repo_name} pushd config if [ "$keyboard_shield" == "y" ]; then - config_file="https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${keyboard_basedir}/${shield}.conf" - - keymap_file="https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${keyboard_basedir}/${shield}.keymap" + url_base="https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${keyboard_basedir}" else - config_file="https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/${keyboard_arch}/${keyboard_basedir}/${board}.conf" - keymap_file="https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/${keyboard_arch}/${keyboard_basedir}/${board}.keymap" + url_base="https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/${keyboard_arch}/${keyboard_basedir}" +fi + +echo "Downloading config file (${url_base}/${keyboard}.conf)" +if ! $download_command "${url_base}/${keyboard}.conf"; then + echo "Could not find it, falling back to ${url_base}/${keyboard_basedir}.conf" + $download_command "${url_base}/${keyboard_basedir}.conf" || echo "# Put configuration options here" > "${keyboard}.conf" fi -echo "Downloading config file (${config_file})" -$download_command "${config_file}" || echo "# Put configuration options here" > "${keyboard}.conf" if [ "$copy_keymap" == "yes" ]; then - echo "Downloading keymap file (${keymap_file})" - $download_command "${keymap_file}" + echo "Downloading keymap file (${url_base}/${keyboard}.keymap)" + if ! $download_command "${url_base}/${keyboard}.keymap"; then + echo "Could not find it, falling back to ${url_base}/${keyboard_basedir}.keymap" + $download_command "${url_base}/${keyboard_basedir}.keymap" || echo "Warning: Could not find a keymap file to download!" + fi fi popd @@ -254,7 +258,7 @@ if [ -n "$github_repo" ]; then echo " git remote rm origin" echo " git remote add origin FIXED_URL" echo " git push --set-upstream origin $(git symbolic-ref --short HEAD)" - echo "Once pushed, your firmware should be availalbe from GitHub Actions at: ${github_repo%.git}/actions" + echo "Once pushed, your firmware should be available from GitHub Actions at: ${github_repo%.git}/actions" exit 1 fi