From f9e8866a520051385bcb89a60caaef0ec2fe23ad Mon Sep 17 00:00:00 2001 From: Kellen Carey Date: Sat, 10 Oct 2020 18:28:16 -0700 Subject: [PATCH 1/3] add support for wget to setup.sh --- docs/static/setup.sh | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/docs/static/setup.sh b/docs/static/setup.sh index 96e87688..fc5a7cdd 100644 --- a/docs/static/setup.sh +++ b/docs/static/setup.sh @@ -9,15 +9,25 @@ set -e check_exists() { command_to_run=$1 error_message=$2 + local __resultvar=$3 if ! eval "$command_to_run" &> /dev/null; then - printf "%s\n" "$error_message" - exit 1 + if [[ "$__resultvar" != "" ]]; then + eval $__resultvar="'false'" + else + printf "%s\n" "$error_message" + exit 1 + fi + else + if [[ "$__resultvar" != "" ]]; then + eval $__resultvar="'true'" + fi fi } check_exists "command -v git" "git is not installed, and is required for this script!" -check_exists "command -v curl" "curl is not installed, and is required for this script!" +check_exists "command -v curl" "curl is not installed, and is required for this script!" curl_exists +check_exists "command -v wget" "wget is not installed, and is required for this script!" wget_exists check_exists "git config user.name" "Git username not set!\nRun: git config --global user.name 'My Name'" check_exists "git config user.email" "Git email not set!\nRun: git config --global user.email 'example@myemail.com'" @@ -29,6 +39,30 @@ if [ ! -w `pwd` ]; then exit 1 fi +if [[ $curl_exists == "true" && $wget_exists == "true" ]]; then + prompt="Detected both curl and wget, which one would you like to use? [default is curl]" + options=("curl" "wget") + PS3="$prompt " + select opt in "${options[@]}" "Quit"; do + case "$REPLY" in + + 1 ) download_command="curl -O "; break;; + 2 ) download_command="wget "; break;; + + $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit 1;; + *) download_command="curl -O "; break;; + + esac + done +elif [[ $curl_exists == "true" ]]; then + download_command="curl -O " +elif [[ $wget_exists == "true" ]]; then + download_command="wget " +else + echo 'Neither curl nor wget are installed. One of the two is required for this script!' + exit 1 +fi + repo_path="https://github.com/zmkfirmware/zmk-config-split-template.git" title="ZMK Config Setup:" @@ -133,10 +167,10 @@ cd ${repo_name} pushd config -curl -O "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${shield}/${shield}.conf" +$download_command "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${shield}/${shield}.conf" if [ "$copy_keymap" == "yes" ]; then - curl -O "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${shield}/${shield}.keymap" + $download_command "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${shield}/${shield}.keymap" fi popd From b738cc9d75e50bf7400a621c33ce32e697f3c250 Mon Sep 17 00:00:00 2001 From: Kellen Carey Date: Sat, 10 Oct 2020 19:16:07 -0700 Subject: [PATCH 2/3] add option to use wget --- docs/static/setup.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/static/setup.sh b/docs/static/setup.sh index fc5a7cdd..b5abb288 100644 --- a/docs/static/setup.sh +++ b/docs/static/setup.sh @@ -39,21 +39,21 @@ if [ ! -w `pwd` ]; then exit 1 fi +# Parse all commandline options +while [[ "$#" -gt 0 ]]; do + case $1 in + -w|--wget) force_wget="true"; break;; + *) echo "Unknown parameter: $1"; exit 1;; + esac + shift +done + if [[ $curl_exists == "true" && $wget_exists == "true" ]]; then - prompt="Detected both curl and wget, which one would you like to use? [default is curl]" - options=("curl" "wget") - PS3="$prompt " - select opt in "${options[@]}" "Quit"; do - case "$REPLY" in - - 1 ) download_command="curl -O "; break;; - 2 ) download_command="wget "; break;; - - $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit 1;; - *) download_command="curl -O "; break;; - - esac - done + if [[ $force_wget == "true" ]]; then + download_command="wget " + else + download_command="curl -O " + fi elif [[ $curl_exists == "true" ]]; then download_command="curl -O " elif [[ $wget_exists == "true" ]]; then From 4bd41b9bf9b0721ac2dcc4e4f20ce0a3f003ad19 Mon Sep 17 00:00:00 2001 From: Kellen Carey Date: Thu, 15 Oct 2020 16:53:16 -0700 Subject: [PATCH 3/3] add wget flag to example --- docs/docs/user-setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/user-setup.md b/docs/docs/user-setup.md index 2aade829..f204c0ee 100644 --- a/docs/docs/user-setup.md +++ b/docs/docs/user-setup.md @@ -74,7 +74,7 @@ bash -c "$(curl -fsSL https://zmkfirmware.dev/setup.sh)" ``` -bash -c "$(wget https://zmkfirmware.dev/setup.sh -O -)" +bash -c "$(wget https://zmkfirmware.dev/setup.sh -O -)" '' --wget ```