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