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.

59 lines
1.6 KiB

  1. #!/bin/sh
  2. # NOTE: This script uses tabs for indentation
  3. errcho() {
  4. echo "$@" >&2
  5. }
  6. USAGE="Usage: $0 <command>"
  7. # Check preconditions
  8. for arg; do
  9. if [ "$arg" = "--help" ]; then
  10. echo "$USAGE"
  11. exit 0
  12. fi
  13. done
  14. # Allow $RUNTIME to be overridden by the user as an environment variable
  15. # Else check if either podman or docker exit and set them as runtime
  16. # if none are found error out
  17. if [ -z "$RUNTIME" ]; then
  18. if command -v podman >/dev/null 2>&1; then
  19. RUNTIME="podman"
  20. elif command -v docker >/dev/null 2>&1; then
  21. RUNTIME="docker"
  22. else
  23. errcho "Error: no compatible container runtime found."
  24. errcho "Either podman or docker are required."
  25. errcho "See https://podman.io/getting-started/installation"
  26. errcho "or https://docs.docker.com/install/#supported-platforms"
  27. errcho "for installation instructions."
  28. exit 2
  29. fi
  30. fi
  31. # IF we are using docker on non Linux and docker-machine isn't working print an error
  32. # ELSE set usb_args
  33. if [ ! "$(uname)" = "Linux" ] && [ "$RUNTIME" = "docker" ] && ! docker-machine active >/dev/null 2>&1; then
  34. errcho "Error: target requires docker-machine to work on your platform"
  35. errcho "See http://gw.tnode.com/docker/docker-machine-with-usb-support-on-windows-macos"
  36. exit 3
  37. else
  38. usb_args="--privileged -v /dev:/dev"
  39. fi
  40. dir=$(pwd -W 2>/dev/null) || dir=$PWD # Use Windows path if on Windows
  41. if [ "$RUNTIME" = "docker" ]; then
  42. uid_arg="--user $(id -u):$(id -g)"
  43. fi
  44. # Run container and build firmware
  45. "$RUNTIME" run --rm -it \
  46. $usb_args \
  47. $uid_arg \
  48. -w /qmk_firmware \
  49. -v "$dir":/qmk_firmware \
  50. ghcr.io/qmk/qmk_cli \
  51. "$@"