logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

docker_cmd.sh (2574B)


  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 SKIP_FLASHING_SUPPORT is defined, do not check for docker-machine and do not run a privileged container
  33. if [ -z "$SKIP_FLASHING_SUPPORT" ]; then
  34. # IF we are using docker on non Linux and docker-machine isn't working print an error
  35. # ELSE set usb_args
  36. if [ ! "$(uname)" = "Linux" ] && [ "$RUNTIME" = "docker" ] && ! docker-machine active >/dev/null 2>&1; then
  37. errcho "Error: target requires docker-machine to work on your platform"
  38. errcho "See http://gw.tnode.com/docker/docker-machine-with-usb-support-on-windows-macos"
  39. exit 3
  40. else
  41. usb_args="--privileged -v /dev:/dev"
  42. fi
  43. fi
  44. qmk_firmware_dir=$(pwd -W 2>/dev/null) || qmk_firmware_dir=$PWD # Use Windows path if on Windows
  45. qmk_userspace_dir=""
  46. userspace_docker_args=""
  47. if [ -n "$QMK_USERSPACE" ] && [ -e "$QMK_USERSPACE/qmk.json" ]; then
  48. qmk_userspace_dir=$(cd "$QMK_USERSPACE" && pwd -W 2>/dev/null) || qmk_userspace_dir=$QMK_USERSPACE # Use Windows path if on Windows
  49. elif [ -n "$(which qmk 2>/dev/null)" ] && [ -n "$(qmk userspace-path)" ]; then
  50. qmk_userspace_dir=$(cd "$(qmk userspace-path)" && pwd -W 2>/dev/null) || qmk_userspace_dir=$(qmk userspace-path) # Use Windows path if on Windows
  51. fi
  52. if [ -n "$qmk_userspace_dir" ]; then
  53. userspace_docker_args="-v $qmk_userspace_dir:/qmk_userspace:z -e QMK_USERSPACE=/qmk_userspace"
  54. fi
  55. if [ "$RUNTIME" = "docker" ]; then
  56. uid_arg="--user $(id -u):$(id -g)"
  57. fi
  58. # Run container and build firmware
  59. "$RUNTIME" run --rm -it \
  60. $usb_args \
  61. $uid_arg \
  62. -w /qmk_firmware \
  63. -v "$qmk_firmware_dir":/qmk_firmware:z \
  64. $userspace_docker_args \
  65. -e SKIP_GIT="$SKIP_GIT" \
  66. -e SKIP_VERSION="$SKIP_VERSION" \
  67. -e MAKEFLAGS="$MAKEFLAGS" \
  68. ghcr.io/qmk/qmk_cli \
  69. "$@"