mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-27 19:41:16 +00:00
Formatting.
This commit is contained in:
parent
4ef00cd6e8
commit
1921a4808f
@ -2,10 +2,6 @@
|
|||||||
# Copyright 2025 Nick Brassel (@tzarc)
|
# Copyright 2025 Nick Brassel (@tzarc)
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
{ # this ensures the entire script is downloaded #
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# This script will install the QMK CLI, toolchains, and flashing utilities.
|
# This script will install the QMK CLI, toolchains, and flashing utilities.
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -37,10 +33,14 @@ set -eu
|
|||||||
# Any other configurable items listed above may be specified in the same way.
|
# Any other configurable items listed above may be specified in the same way.
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# Work out which `sed` to use
|
{ # this ensures the entire script is downloaded #
|
||||||
command -v gsed >/dev/null 2>&1 && SED=gsed || SED=sed
|
|
||||||
|
|
||||||
script_args() {
|
set -eu
|
||||||
|
|
||||||
|
# Work out which `sed` to use
|
||||||
|
command -v gsed >/dev/null 2>&1 && SED=gsed || SED=sed
|
||||||
|
|
||||||
|
script_args() {
|
||||||
cat <<__EOT__
|
cat <<__EOT__
|
||||||
--help -- Shows this help text
|
--help -- Shows this help text
|
||||||
--yes -- Assumes "yes" for all prompts
|
--yes -- Assumes "yes" for all prompts
|
||||||
@ -53,18 +53,18 @@ script_args() {
|
|||||||
--skip-qmk-toolchains -- Skip installing the QMK toolchains
|
--skip-qmk-toolchains -- Skip installing the QMK toolchains
|
||||||
--skip-qmk-flashutils -- Skip installing the QMK flashing utilities
|
--skip-qmk-flashutils -- Skip installing the QMK flashing utilities
|
||||||
__EOT__
|
__EOT__
|
||||||
}
|
}
|
||||||
|
|
||||||
script_help() {
|
script_help() {
|
||||||
echo "$(basename ${this_script:-qmk-install.sh}) $(script_args | sort | ${SED} -e 's@^\s*@@g' -e 's@\s\+--.*@@g' -e 's@^@[@' -e 's@$@]@' | tr '\n' ' ')"
|
echo "$(basename ${this_script:-qmk-install.sh}) $(script_args | sort | ${SED} -e 's@^\s*@@g' -e 's@\s\+--.*@@g' -e 's@^@[@' -e 's@$@]@' | tr '\n' ' ')"
|
||||||
echo
|
echo
|
||||||
echo "Arguments:"
|
echo "Arguments:"
|
||||||
script_args
|
script_args
|
||||||
echo
|
echo
|
||||||
echo "Switch arguments may be negated by prefixing with '--no-' (e.g. '--no-skip-clean')."
|
echo "Switch arguments may be negated by prefixing with '--no-' (e.g. '--no-skip-clean')."
|
||||||
}
|
}
|
||||||
|
|
||||||
script_parse_args() {
|
script_parse_args() {
|
||||||
local N
|
local N
|
||||||
local V
|
local V
|
||||||
while [[ ! -z "${1:-}" ]]; do
|
while [[ ! -z "${1:-}" ]]; do
|
||||||
@ -101,9 +101,9 @@ script_parse_args() {
|
|||||||
unset N
|
unset N
|
||||||
unset V
|
unset V
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
download_url() {
|
download_url() {
|
||||||
local url=$1
|
local url=$1
|
||||||
local filename=${2:-$(basename "$url")}
|
local filename=${2:-$(basename "$url")}
|
||||||
local quiet=''
|
local quiet=''
|
||||||
@ -117,9 +117,9 @@ download_url() {
|
|||||||
echo "Please install 'curl' or 'wget' to continue." >&2
|
echo "Please install 'curl' or 'wget' to continue." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
fn_os() {
|
fn_os() {
|
||||||
local os_name=$(echo ${1:-} | tr 'A-Z' 'a-z')
|
local os_name=$(echo ${1:-} | tr 'A-Z' 'a-z')
|
||||||
if [ -z "$os_name" ]; then
|
if [ -z "$os_name" ]; then
|
||||||
os_name=$(uname -s | tr 'A-Z' 'a-z')
|
os_name=$(uname -s | tr 'A-Z' 'a-z')
|
||||||
@ -138,9 +138,9 @@ fn_os() {
|
|||||||
echo unknown
|
echo unknown
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
fn_arch() {
|
fn_arch() {
|
||||||
local arch_name=$(echo ${1:-} | tr 'A-Z' 'a-z')
|
local arch_name=$(echo ${1:-} | tr 'A-Z' 'a-z')
|
||||||
if [ -z "$arch_name" ]; then
|
if [ -z "$arch_name" ]; then
|
||||||
arch_name=$(uname -m | tr 'A-Z' 'a-z')
|
arch_name=$(uname -m | tr 'A-Z' 'a-z')
|
||||||
@ -159,9 +159,9 @@ fn_arch() {
|
|||||||
echo unknown
|
echo unknown
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
check_yesno() {
|
check_yesno() {
|
||||||
[ -z "${YES:-}" ] || return 0
|
[ -z "${YES:-}" ] || return 0
|
||||||
read -p "Proceed? [y/N] " res </dev/tty # Read from /dev/tty as stdin may not be connected when piping to sh
|
read -p "Proceed? [y/N] " res </dev/tty # Read from /dev/tty as stdin may not be connected when piping to sh
|
||||||
case $res in
|
case $res in
|
||||||
@ -170,9 +170,9 @@ check_yesno() {
|
|||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
install_package_manager_deps() {
|
install_package_manager_deps() {
|
||||||
# Install the necessary packages for the package manager
|
# Install the necessary packages for the package manager
|
||||||
case $(fn_os) in
|
case $(fn_os) in
|
||||||
macos)
|
macos)
|
||||||
@ -250,14 +250,14 @@ install_package_manager_deps() {
|
|||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
install_uv() {
|
install_uv() {
|
||||||
# Install `uv` (or update as necessary)
|
# Install `uv` (or update as necessary)
|
||||||
download_url https://astral.sh/uv/install.sh - | TMPDIR=${TMPDIR:-} UV_INSTALL_DIR=${UV_INSTALL_DIR:-} sh
|
download_url https://astral.sh/uv/install.sh - | TMPDIR=${TMPDIR:-} UV_INSTALL_DIR=${UV_INSTALL_DIR:-} sh
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_paths() {
|
setup_paths() {
|
||||||
# Set up the paths for any of the locations `uv` expects
|
# Set up the paths for any of the locations `uv` expects
|
||||||
if [ -n "${XDG_BIN_HOME:-}" ]; then
|
if [ -n "${XDG_BIN_HOME:-}" ]; then
|
||||||
export PATH="$XDG_BIN_HOME:$PATH"
|
export PATH="$XDG_BIN_HOME:$PATH"
|
||||||
@ -270,9 +270,9 @@ setup_paths() {
|
|||||||
if [ -n "${UV_INSTALL_DIR:-}" ]; then
|
if [ -n "${UV_INSTALL_DIR:-}" ]; then
|
||||||
export PATH="$UV_INSTALL_DIR/bin:$UV_INSTALL_DIR:$PATH" # cater for both "flat" and "hierarchical" installs of `uv`
|
export PATH="$UV_INSTALL_DIR/bin:$UV_INSTALL_DIR:$PATH" # cater for both "flat" and "hierarchical" installs of `uv`
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_qmk_cli() {
|
install_qmk_cli() {
|
||||||
# Install the QMK CLI
|
# Install the QMK CLI
|
||||||
uv tool install --force --with pip --upgrade --python 3.13 qmk
|
uv tool install --force --with pip --upgrade --python 3.13 qmk
|
||||||
|
|
||||||
@ -300,9 +300,9 @@ install_qmk_cli() {
|
|||||||
|
|
||||||
# Deactivate the environment
|
# Deactivate the environment
|
||||||
deactivate
|
deactivate
|
||||||
}
|
}
|
||||||
|
|
||||||
install_toolchains() {
|
install_toolchains() {
|
||||||
# Get the latest toolchain release from https://github.com/qmk/qmk_toolchains
|
# Get the latest toolchain release from https://github.com/qmk/qmk_toolchains
|
||||||
local latest_toolchains_release=$(download_url https://api.github.com/repos/qmk/qmk_toolchains/releases/latest - | grep -oE '"tag_name": "[^"]+' | grep -oE '[^"]+$')
|
local latest_toolchains_release=$(download_url https://api.github.com/repos/qmk/qmk_toolchains/releases/latest - | grep -oE '"tag_name": "[^"]+' | grep -oE '[^"]+$')
|
||||||
# Download the specific release asset with a matching keyword
|
# Download the specific release asset with a matching keyword
|
||||||
@ -320,9 +320,9 @@ install_toolchains() {
|
|||||||
# Extract the toolchain
|
# Extract the toolchain
|
||||||
echo "Extracting compiler toolchain..." >&2
|
echo "Extracting compiler toolchain..." >&2
|
||||||
tar xf "$target_file" -C "$QMK_DISTRIB_DIR" --strip-components=1
|
tar xf "$target_file" -C "$QMK_DISTRIB_DIR" --strip-components=1
|
||||||
}
|
}
|
||||||
|
|
||||||
install_flashing_tools() {
|
install_flashing_tools() {
|
||||||
# Get the latest flashing tools release from https://github.com/qmk/qmk_flashutils
|
# Get the latest flashing tools release from https://github.com/qmk/qmk_flashutils
|
||||||
local latest_flashutils_release=$(download_url https://api.github.com/repos/qmk/qmk_flashutils/releases/latest - | grep -oE '"tag_name": "[^"]+' | grep -oE '[^"]+$')
|
local latest_flashutils_release=$(download_url https://api.github.com/repos/qmk/qmk_flashutils/releases/latest - | grep -oE '"tag_name": "[^"]+' | grep -oE '[^"]+$')
|
||||||
# Download the specific release asset with a matching keyword
|
# Download the specific release asset with a matching keyword
|
||||||
@ -340,51 +340,51 @@ install_flashing_tools() {
|
|||||||
# Extract the flashing tools
|
# Extract the flashing tools
|
||||||
echo "Extracting flashing tools..." >&2
|
echo "Extracting flashing tools..." >&2
|
||||||
tar xf "$target_file" -C "$QMK_DISTRIB_DIR/bin"
|
tar xf "$target_file" -C "$QMK_DISTRIB_DIR/bin"
|
||||||
}
|
}
|
||||||
|
|
||||||
clean_tarballs() {
|
clean_tarballs() {
|
||||||
# Clean up the tarballs
|
# Clean up the tarballs
|
||||||
rm -f "$QMK_DISTRIB_DIR"/*.tar.zst || true
|
rm -f "$QMK_DISTRIB_DIR"/*.tar.zst || true
|
||||||
}
|
}
|
||||||
|
|
||||||
# Windows/MSYS doesn't like `/tmp` so we need to set a different temporary directory.
|
# Windows/MSYS doesn't like `/tmp` so we need to set a different temporary directory.
|
||||||
# Also set the default `UV_INSTALL_DIR` and `QMK_DISTRIB_DIR` to locations which don't pollute the user's home directory, keeping the installation internal to MSYS.
|
# Also set the default `UV_INSTALL_DIR` and `QMK_DISTRIB_DIR` to locations which don't pollute the user's home directory, keeping the installation internal to MSYS.
|
||||||
if [ "$(uname -o 2>/dev/null || true)" = "Msys" ]; then
|
if [ "$(uname -o 2>/dev/null || true)" = "Msys" ]; then
|
||||||
export TMPDIR="$(cygpath -w "$TMP")"
|
export TMPDIR="$(cygpath -w "$TMP")"
|
||||||
export UV_INSTALL_DIR=${UV_INSTALL_DIR:-/opt/uv}
|
export UV_INSTALL_DIR=${UV_INSTALL_DIR:-/opt/uv}
|
||||||
export QMK_DISTRIB_DIR=${QMK_DISTRIB_DIR:-/opt/qmk}
|
export QMK_DISTRIB_DIR=${QMK_DISTRIB_DIR:-/opt/qmk}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Work out where we want to install the distribution
|
# Work out where we want to install the distribution
|
||||||
export QMK_DISTRIB_DIR=${QMK_DISTRIB_DIR:-$HOME/.local/share/qmk}
|
export QMK_DISTRIB_DIR=${QMK_DISTRIB_DIR:-$HOME/.local/share/qmk}
|
||||||
|
|
||||||
script_parse_args "$@"
|
script_parse_args "$@"
|
||||||
|
|
||||||
echo "This script will install \`uv\` to ${UV_INSTALL_DIR:-the default location}, and the QMK CLI, toolchains, and flashing utilities to ${QMK_DISTRIB_DIR}."
|
echo "This script will install \`uv\` to ${UV_INSTALL_DIR:-the default location}, and the QMK CLI, toolchains, and flashing utilities to ${QMK_DISTRIB_DIR}."
|
||||||
[ -z "${SKIP_PACKAGE_MANAGER:-}" ] || { check_yesno || exit 1; }
|
[ -z "${SKIP_PACKAGE_MANAGER:-}" ] || { check_yesno || exit 1; }
|
||||||
[ -n "${SKIP_PACKAGE_MANAGER:-}" ] || install_package_manager_deps
|
[ -n "${SKIP_PACKAGE_MANAGER:-}" ] || install_package_manager_deps
|
||||||
[ -n "${SKIP_UV:-}" ] || install_uv
|
[ -n "${SKIP_UV:-}" ] || install_uv
|
||||||
setup_paths
|
setup_paths
|
||||||
[ -n "${SKIP_QMK_CLI:-}" ] || install_qmk_cli
|
[ -n "${SKIP_QMK_CLI:-}" ] || install_qmk_cli
|
||||||
|
|
||||||
# Clear out the distrib directory if necessary
|
# Clear out the distrib directory if necessary
|
||||||
if [ -z "${SKIP_CLEAN:-}" ] || [ -z "${SKIP_QMK_TOOLCHAINS:-}" -a -z "${SKIP_QMK_FLASHUTILS:-}" ]; then
|
if [ -z "${SKIP_CLEAN:-}" ] || [ -z "${SKIP_QMK_TOOLCHAINS:-}" -a -z "${SKIP_QMK_FLASHUTILS:-}" ]; then
|
||||||
if [ -d "$QMK_DISTRIB_DIR" ]; then
|
if [ -d "$QMK_DISTRIB_DIR" ]; then
|
||||||
echo "Removing old QMK distribution..." >&2
|
echo "Removing old QMK distribution..." >&2
|
||||||
rm -rf "$QMK_DISTRIB_DIR"
|
rm -rf "$QMK_DISTRIB_DIR"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
mkdir -p "$QMK_DISTRIB_DIR"
|
mkdir -p "$QMK_DISTRIB_DIR"
|
||||||
|
|
||||||
[ -n "${SKIP_QMK_TOOLCHAINS:-}" ] || install_toolchains
|
[ -n "${SKIP_QMK_TOOLCHAINS:-}" ] || install_toolchains
|
||||||
[ -n "${SKIP_QMK_FLASHUTILS:-}" ] || install_flashing_tools
|
[ -n "${SKIP_QMK_FLASHUTILS:-}" ] || install_flashing_tools
|
||||||
clean_tarballs
|
clean_tarballs
|
||||||
|
|
||||||
# Notify the user that they may need to restart their shell to get the `qmk` command
|
# Notify the user that they may need to restart their shell to get the `qmk` command
|
||||||
hash -r
|
hash -r
|
||||||
echo
|
echo
|
||||||
echo "You may need to restart your shell to gain access to the 'qmk' command."
|
echo "You may need to restart your shell to gain access to the 'qmk' command."
|
||||||
echo "Alternatively, add "$(dirname "$(command -v qmk)")" to your \$PATH:"
|
echo "Alternatively, add "$(dirname "$(command -v qmk)")" to your \$PATH:"
|
||||||
echo " export PATH=\"$(dirname "$(command -v qmk)"):\$PATH\""
|
echo " export PATH=\"$(dirname "$(command -v qmk)"):\$PATH\""
|
||||||
|
|
||||||
} # this ensures the entire script is downloaded #
|
} # this ensures the entire script is downloaded #
|
||||||
|
Loading…
Reference in New Issue
Block a user