You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.2 KiB

  1. #!/bin/sh
  2. # NOTE: This script uses tabs for indentation
  3. errcho() {
  4. echo "$@" >&2
  5. }
  6. USAGE="Usage: $0 [keyboard[:keymap[:target]]]"
  7. # Check preconditions
  8. for arg; do
  9. if [ "$arg" = "--help" ]; then
  10. echo "$USAGE"
  11. exit 0
  12. fi
  13. done
  14. if [ $# -gt 1 ]; then
  15. errcho "$USAGE"
  16. exit 1
  17. fi
  18. # Allow $RUNTIME to be overridden by the user as an environment variable
  19. # Else check if either podman or docker exit and set them as runtime
  20. # if none are found error out
  21. if [ -z "$RUNTIME" ]; then
  22. if command -v podman >/dev/null 2>&1; then
  23. RUNTIME="podman"
  24. elif command -v docker >/dev/null 2>&1; then
  25. RUNTIME="docker"
  26. else
  27. errcho "Error: no compatible container runtime found."
  28. errcho "Either podman or docker are required."
  29. errcho "See https://podman.io/getting-started/installation"
  30. errcho "or https://docs.docker.com/install/#supported-platforms"
  31. errcho "for installation instructions."
  32. exit 2
  33. fi
  34. fi
  35. # Determine arguments
  36. if [ $# -eq 0 ]; then
  37. printf "keyboard=" && read -r keyboard
  38. [ -n "$keyboard" ] && printf "keymap=" && read -r keymap
  39. [ -n "$keymap" ] && printf "target=" && read -r target
  40. else
  41. IFS=':' read -r keyboard keymap target x <<-EOF
  42. $1
  43. EOF
  44. if [ -n "$x" ]; then
  45. errcho "$USAGE"
  46. exit 1
  47. fi
  48. fi
  49. if [ -z "$keyboard" ]; then
  50. keyboard=all
  51. fi
  52. if [ -n "$target" ]; then
  53. # IF we are using docker on non Linux and docker-machine isn't working print an error
  54. # ELSE set usb_args
  55. if [ ! "$(uname)" = "Linux" ] && [ "$RUNTIME" = "docker" ] && ! docker-machine active >/dev/null 2>&1; then
  56. errcho "Error: target requires docker-machine to work on your platform"
  57. errcho "See http://gw.tnode.com/docker/docker-machine-with-usb-support-on-windows-macos"
  58. errcho "Consider flashing with QMK Toolbox (https://github.com/qmk/qmk_toolbox) instead"
  59. exit 3
  60. else
  61. usb_args="--privileged -v /dev:/dev"
  62. fi
  63. fi
  64. dir=$(pwd -W 2>/dev/null) || dir=$PWD # Use Windows path if on Windows
  65. if [ "$RUNTIME" = "docker" ]; then
  66. uid_arg="--user $(id -u):$(id -g)"
  67. fi
  68. # Run container and build firmware
  69. "$RUNTIME" run --rm -it $usb_args \
  70. $uid_arg \
  71. -w /qmk_firmware \
  72. -v "$dir":/qmk_firmware \
  73. -e ALT_GET_KEYBOARDS=true \
  74. -e SKIP_GIT="$SKIP_GIT" \
  75. -e MAKEFLAGS="$MAKEFLAGS" \
  76. ghcr.io/qmk/qmk_cli \
  77. make "$keyboard${keymap:+:$keymap}${target:+:$target}"