2020-09-14 03:07:45 +10:00
|
|
|
#!/bin/bash
|
2020-08-05 03:41:07 +10:00
|
|
|
|
2020-09-25 02:42:34 +10:00
|
|
|
# Copyright (c) 2020 The ZMK Contributors
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2020-08-05 03:41:07 +10:00
|
|
|
set -e
|
|
|
|
|
2020-09-20 21:52:25 +10:00
|
|
|
check_exists() {
|
2020-09-14 03:07:45 +10:00
|
|
|
command_to_run=$1
|
|
|
|
error_message=$2
|
2020-10-11 12:28:16 +11:00
|
|
|
local __resultvar=$3
|
2020-09-25 02:42:34 +10:00
|
|
|
|
2020-09-14 03:07:45 +10:00
|
|
|
if ! eval "$command_to_run" &> /dev/null; then
|
2020-10-11 12:28:16 +11:00
|
|
|
if [[ "$__resultvar" != "" ]]; then
|
|
|
|
eval $__resultvar="'false'"
|
|
|
|
else
|
|
|
|
printf "%s\n" "$error_message"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [[ "$__resultvar" != "" ]]; then
|
|
|
|
eval $__resultvar="'true'"
|
|
|
|
fi
|
2020-09-14 03:07:45 +10:00
|
|
|
fi
|
|
|
|
}
|
2020-08-05 03:41:07 +10:00
|
|
|
|
2020-09-20 21:52:25 +10:00
|
|
|
check_exists "command -v git" "git is not installed, and is required for this script!"
|
2020-10-11 12:28:16 +11:00
|
|
|
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
|
2020-08-05 03:41:07 +10:00
|
|
|
|
2020-09-20 21:52:25 +10:00
|
|
|
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'"
|
2020-09-14 03:07:45 +10:00
|
|
|
|
2020-10-10 12:00:11 +11:00
|
|
|
# Check to see if the user has write permissions in this directory to prevent a cryptic error later on
|
|
|
|
if [ ! -w `pwd` ]; then
|
|
|
|
echo 'Sorry, you do not have write permissions in this directory.';
|
|
|
|
echo 'Please try running this script again from a directory that you do have write permissions for.';
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-10-11 13:16:07 +11:00
|
|
|
# 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
|
|
|
|
|
2020-10-11 12:28:16 +11:00
|
|
|
if [[ $curl_exists == "true" && $wget_exists == "true" ]]; then
|
2020-10-11 13:16:07 +11:00
|
|
|
if [[ $force_wget == "true" ]]; then
|
|
|
|
download_command="wget "
|
|
|
|
else
|
|
|
|
download_command="curl -O "
|
|
|
|
fi
|
2020-10-11 12:28:16 +11:00
|
|
|
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
|
|
|
|
|
2020-09-14 03:07:45 +10:00
|
|
|
repo_path="https://github.com/zmkfirmware/zmk-config-split-template.git"
|
|
|
|
title="ZMK Config Setup:"
|
2020-08-05 03:41:07 +10:00
|
|
|
|
|
|
|
prompt="Pick an MCU board:"
|
2020-10-06 00:43:05 +11:00
|
|
|
options=("nice!nano" "QMK Proton-C" "BlueMicro840 (v1)" "makerdiary nRF52840 M.2")
|
2020-08-05 03:41:07 +10:00
|
|
|
|
|
|
|
echo "$title"
|
|
|
|
echo ""
|
|
|
|
echo "MCU Board Selection:"
|
|
|
|
PS3="$prompt "
|
2020-09-25 02:42:34 +10:00
|
|
|
select opt in "${options[@]}" "Quit"; do
|
2020-08-05 03:41:07 +10:00
|
|
|
|
|
|
|
case "$REPLY" in
|
|
|
|
|
|
|
|
1 ) board="nice_nano"; break;;
|
|
|
|
2 ) board="proton_c"; break;;
|
2020-08-20 06:35:18 +10:00
|
|
|
3 ) board="bluemicro840_v1"; break;;
|
2020-10-06 00:43:05 +11:00
|
|
|
3 ) board="nrf52840_m2"; break;;
|
2020-08-05 03:41:07 +10:00
|
|
|
|
2020-09-20 21:52:25 +10:00
|
|
|
$(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit 1;;
|
|
|
|
*) echo "Invalid option. Try another one."; continue;;
|
2020-08-05 03:41:07 +10:00
|
|
|
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Keyboard Shield Selection:"
|
|
|
|
|
|
|
|
prompt="Pick an keyboard:"
|
2020-12-08 03:49:37 +11:00
|
|
|
options=("Kyria" "Lily58" "Corne" "Splitreus62" "Sofle" "Iris" "Reviung41" "RoMac" "RoMac+" "makerdiary M60" "Microdox" "TG4X" "QAZ" "Jorne" "Jian" "CRBN")
|
2020-08-05 03:41:07 +10:00
|
|
|
|
|
|
|
PS3="$prompt "
|
2020-08-05 04:12:10 +10:00
|
|
|
# TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos.
|
2020-09-25 02:42:34 +10:00
|
|
|
# select opt in "${options[@]}" "Other" "Quit"; do
|
|
|
|
select opt in "${options[@]}" "Quit"; do
|
2020-08-05 03:41:07 +10:00
|
|
|
|
|
|
|
case "$REPLY" in
|
|
|
|
|
|
|
|
1 ) shield_title="Kyria" shield="kyria"; split="y"; break;;
|
|
|
|
2 ) shield_title="Lily58" shield="lily58"; split="y"; break;;
|
2020-08-11 02:37:05 +10:00
|
|
|
3 ) shield_title="Corne" shield="corne"; split="y"; break;;
|
2020-08-21 05:13:51 +10:00
|
|
|
4 ) shield_title="Splitreus62" shield="splitreus62"; split="y"; break;;
|
2020-09-02 03:32:45 +10:00
|
|
|
5 ) shield_title="Sofle" shield="sofle"; split="y"; break;;
|
2020-09-03 13:53:14 +10:00
|
|
|
6 ) shield_title="Iris" shield="iris"; split="y"; break;;
|
2020-10-25 13:08:00 +11:00
|
|
|
7 ) shield_title="Reviung41" shield="reviung41"; split="n"; break;;
|
|
|
|
8 ) shield_title="RoMac" shield="romac"; split="n"; break;;
|
|
|
|
9 ) shield_title="RoMac+" shield="romac_plus"; split="n"; break;;
|
|
|
|
10 ) shield_title="M60" shield="m60"; split="n"; break;;
|
|
|
|
11 ) shield_title="Microdox" shield="microdox"; split="y"; break;;
|
|
|
|
12 ) shield_title="TG4X" shield="tg4x"; split="n"; break;;
|
|
|
|
13 ) shield_title="QAZ" shield="qaz"; split="n"; break;;
|
2020-10-22 14:17:31 +11:00
|
|
|
14 ) shield_title="NIBBLE" shield="nibble"; split="n"; break;;
|
2020-11-06 07:45:26 +11:00
|
|
|
15 ) shield_title="Jorne" shield="jorne"; split="y"; break;;
|
2020-11-06 07:45:46 +11:00
|
|
|
16 ) shield_title="Jian" shield="jian"; split="y"; break;;
|
2020-12-08 03:49:37 +11:00
|
|
|
17 ) shield_title="CRBN" shield="crbn"; split="n"; break;;
|
2020-08-05 03:41:07 +10:00
|
|
|
|
|
|
|
# Add link to docs on adding your own custom shield in your ZMK config!
|
2020-09-25 02:42:34 +10:00
|
|
|
# $(( ${#options[@]}+1 )) ) echo "Other!"; break;;
|
2020-09-20 21:52:25 +10:00
|
|
|
$(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit 1;;
|
2020-08-05 03:41:07 +10:00
|
|
|
*) echo "Invalid option. Try another one.";continue;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-09-07 00:51:12 +10:00
|
|
|
if [ "$split" == "n" ]; then
|
2020-09-07 02:54:45 +10:00
|
|
|
repo_path="https://github.com/zmkfirmware/zmk-config-template.git"
|
2020-09-07 00:51:12 +10:00
|
|
|
fi
|
|
|
|
|
2020-09-14 03:07:45 +10:00
|
|
|
read -r -e -p "Copy in the stock keymap for customization? [Yn]: " copy_keymap
|
2020-08-08 00:02:44 +10:00
|
|
|
|
|
|
|
if [ -z "$copy_keymap" ] || [ "$copy_keymap" == "Y" ] || [ "$copy_keymap" == "y" ]; then copy_keymap="yes"; fi
|
|
|
|
|
2020-09-14 03:07:45 +10:00
|
|
|
read -r -e -p "GitHub Username (leave empty to skip GitHub repo creation): " github_user
|
2020-08-05 03:41:07 +10:00
|
|
|
if [ -n "$github_user" ]; then
|
2020-09-14 03:07:45 +10:00
|
|
|
read -r -p "GitHub Repo Name [zmk-config]: " repo_name
|
|
|
|
if [ -z "$repo_name" ]; then repo_name="zmk-config"; fi
|
2020-08-05 03:41:07 +10:00
|
|
|
|
2020-09-14 03:07:45 +10:00
|
|
|
read -r -p "GitHub Repo [https://github.com/${github_user}/${repo_name}.git]: " github_repo
|
2020-08-05 03:41:07 +10:00
|
|
|
|
2020-09-14 03:07:45 +10:00
|
|
|
if [ -z "$github_repo" ]; then github_repo="https://github.com/${github_user}/${repo_name}.git"; fi
|
2020-08-05 03:41:07 +10:00
|
|
|
else
|
2020-09-14 03:07:45 +10:00
|
|
|
repo_name="zmk-config"
|
2020-08-05 03:41:07 +10:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Preparing a user config for:"
|
|
|
|
echo "* MCU Board: ${board}"
|
|
|
|
echo "* Shield: ${shield}"
|
2020-09-14 03:07:45 +10:00
|
|
|
|
2020-08-08 00:02:44 +10:00
|
|
|
if [ "$copy_keymap" == "yes" ]; then
|
|
|
|
echo "* Copy Keymap?: ✓"
|
|
|
|
else
|
|
|
|
echo "* Copy Keymap?: ❌"
|
|
|
|
fi
|
2020-09-14 03:07:45 +10:00
|
|
|
|
2020-08-05 03:41:07 +10:00
|
|
|
if [ -n "$github_repo" ]; then
|
2020-09-14 03:07:45 +10:00
|
|
|
echo "* GitHub Repo To Push (please create this in GH first!): ${github_repo}"
|
2020-08-05 03:41:07 +10:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo ""
|
2020-09-14 03:07:45 +10:00
|
|
|
read -r -p "Continue? [Yn]: " do_it
|
2020-08-05 03:41:07 +10:00
|
|
|
|
2020-08-11 22:40:13 +10:00
|
|
|
if [ -n "$do_it" ] && [ "$do_it" != "y" ] && [ "$do_it" != "Y" ]; then
|
2020-09-14 03:07:45 +10:00
|
|
|
echo "Aborting..."
|
2020-09-20 21:52:25 +10:00
|
|
|
exit 1
|
2020-08-05 03:41:07 +10:00
|
|
|
fi
|
|
|
|
|
|
|
|
git clone --single-branch $repo_path ${repo_name}
|
|
|
|
cd ${repo_name}
|
|
|
|
|
2020-08-08 00:02:44 +10:00
|
|
|
pushd config
|
|
|
|
|
2020-10-11 12:28:16 +11:00
|
|
|
$download_command "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${shield}/${shield}.conf"
|
2020-08-08 00:02:44 +10:00
|
|
|
|
|
|
|
if [ "$copy_keymap" == "yes" ]; then
|
2020-10-11 12:28:16 +11:00
|
|
|
$download_command "https://raw.githubusercontent.com/zmkfirmware/zmk/main/app/boards/shields/${shield}/${shield}.keymap"
|
2020-08-08 00:02:44 +10:00
|
|
|
fi
|
|
|
|
|
|
|
|
popd
|
|
|
|
|
2020-08-11 22:40:13 +10:00
|
|
|
sed -i'.orig' \
|
2020-09-14 03:07:45 +10:00
|
|
|
-e "s/BOARD_NAME/$board/" \
|
|
|
|
-e "s/SHIELD_NAME/$shield/" \
|
|
|
|
-e "s/KEYBOARD_TITLE/$shield_title/" \
|
|
|
|
.github/workflows/build.yml
|
2020-08-05 03:41:07 +10:00
|
|
|
|
2020-08-09 07:28:00 +10:00
|
|
|
if [ "$board" == "proton_c" ]; then
|
|
|
|
# Proton-C board still fa
|
2020-08-11 22:40:13 +10:00
|
|
|
sed -i'.orig' -e "s/uf2/hex/g" .github/workflows/build.yml
|
2020-08-09 07:28:00 +10:00
|
|
|
fi
|
|
|
|
|
2020-08-11 22:40:13 +10:00
|
|
|
rm .github/workflows/*.yml.orig
|
|
|
|
|
2020-08-05 03:41:07 +10:00
|
|
|
rm -rf .git
|
|
|
|
git init .
|
|
|
|
git add .
|
|
|
|
git commit -m "Initial User Config."
|
|
|
|
|
|
|
|
if [ -n "$github_repo" ]; then
|
2020-09-14 03:07:45 +10:00
|
|
|
git remote add origin "$github_repo"
|
|
|
|
git push --set-upstream origin "$(git symbolic-ref --short HEAD)"
|
2020-09-25 02:42:34 +10:00
|
|
|
push_return_code=$?
|
2020-08-05 04:12:10 +10:00
|
|
|
|
2020-09-20 21:52:25 +10:00
|
|
|
# If push failed, assume that the origin was incorrect and give instructions on fixing.
|
2020-09-25 02:42:34 +10:00
|
|
|
if [ ${push_return_code} -ne 0 ]; then
|
2020-09-20 21:52:25 +10:00
|
|
|
echo "Remote repository $github_repo not found..."
|
|
|
|
echo "Check GitHub URL, and try adding again."
|
|
|
|
echo "Run the following: "
|
|
|
|
echo " git remote rm origin"
|
|
|
|
echo " git remote add origin FIXED_URL"
|
|
|
|
echo " git push --set-upstream origin $(git symbolic-ref --short HEAD)"
|
|
|
|
echo "Once pushed, your firmware should be availalbe from GitHub Actions at: ${github_repo%.git}/actions"
|
|
|
|
exit 1
|
2020-09-25 02:42:34 +10:00
|
|
|
fi
|
2020-09-20 21:52:25 +10:00
|
|
|
|
2020-08-05 04:12:10 +10:00
|
|
|
# TODO: Support determing the actions URL when non-https:// repo URL is used.
|
|
|
|
if [ "${github_repo}" != "${github_repo#https://}" ]; then
|
2020-09-20 21:52:25 +10:00
|
|
|
echo "Your firmware should be available from GitHub Actions shortly: ${github_repo%.git}/actions"
|
2020-08-05 04:12:10 +10:00
|
|
|
fi
|
2020-08-05 03:41:07 +10:00
|
|
|
fi
|