ufbt-fm.ps1 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. param ([Parameter(Mandatory)]$command, [Parameter(Mandatory)]$arg1)
  2. Push-Location $PSScriptRoot
  3. if ($command -eq 'use') {
  4. $firmwares_raw_text = Get-Content (Resolve-Path './firmwares.json') -Raw
  5. $firmwares = $firmwares_raw_text | ConvertFrom-Json
  6. $matching_firmware = ($firmwares.firmwares | Where-Object { $_.alias -contains $arg1 })[0]
  7. $ufbt_command = ''
  8. if (!$matching_firmware) {
  9. throw "Unable to recognize which firmware to use"
  10. }
  11. if ($matching_firmware.type -eq 'index') {
  12. $ufbt_command = "ufbt update --index-url=$($matching_firmware.index_url) --channel=$($matching_firmware.channel)"
  13. }
  14. elseif ($matching_firmware.type -eq 'git-release') {
  15. $release_info = Invoke-RestMethod -Uri "https://api.github.com/repos/$($matching_firmware.git_repo)/releases/$($matching_firmware.git_release)"
  16. $sdk_uri = ($release_info.assets | Where-Object { $_.name.EndsWith("-sdk.zip") } | Select-Object -Index 0).browser_download_url
  17. $ufbt_state_file = Join-Path (Resolve-Path "~/") ".ufbt/current/ufbt_state.json"
  18. $need_update = $true
  19. if (Test-Path $ufbt_state_file) {
  20. $ufbt_state = Get-Content $ufbt_state_file -Raw | ConvertFrom-Json
  21. if ($ufbt_state.url -eq $sdk_uri) {
  22. $need_update = $false
  23. }
  24. }
  25. if ($need_update) {
  26. $ufbt_command = "ufbt update --url=$sdk_uri --hw-target=f7"
  27. }
  28. }
  29. if ($ufbt_command) {
  30. Invoke-Expression $ufbt_command
  31. }
  32. Write-Host "Updated `"$($matching_firmware.description)`" firmware for uFBT"
  33. }
  34. else {
  35. throw "Unknown command"
  36. }
  37. Pop-Location