docker_cmd.sh 2.3 KB

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