summaryrefslogtreecommitdiff
path: root/docs/static/setup.sh
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2020-09-24 14:36:07 -0400
committerGitHub <noreply@github.com>2020-09-24 14:36:07 -0400
commit819c82547d54227888e36df08460ea1f77dcfccd (patch)
tree50a65d58e9a48a423f3a063c715466e3d7de2afc /docs/static/setup.sh
parentd5ec32612d9a1d1bf07674fe4b01a926c727ba99 (diff)
parentcd194dbac4747126f017ce6e9ddf070ca6cc1fef (diff)
Merge pull request #180 from CrossR/CrossR/ShellScriptTidyUp
Shell script tidy up.
Diffstat (limited to 'docs/static/setup.sh')
-rw-r--r--docs/static/setup.sh95
1 files changed, 61 insertions, 34 deletions
diff --git a/docs/static/setup.sh b/docs/static/setup.sh
index 5d203a4..5bf3645 100644
--- a/docs/static/setup.sh
+++ b/docs/static/setup.sh
@@ -1,14 +1,29 @@
-#!/bin/sh
+#!/bin/bash
+
+# Copyright (c) 2020 The ZMK Contributors
+#
+# SPDX-License-Identifier: MIT
set -e
-repo_path="https://github.com/zmkfirmware/zmk-config-split-template.git"
-title="ZMK Config Setup:"
+check_exists() {
+ command_to_run=$1
+ error_message=$2
+ if ! eval "$command_to_run" &> /dev/null; then
+ printf "%s\n" "$error_message"
+ exit 1
+ fi
+}
-# TODO: Check for git being installed
-# TODO: Check for curl being installed
-# TODO: Check for user.name and user.email git configs being set
+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 "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'"
+
+repo_path="https://github.com/zmkfirmware/zmk-config-split-template.git"
+title="ZMK Config Setup:"
prompt="Pick an MCU board:"
options=("nice!nano" "QMK Proton-C" "BlueMicro840 (v1)")
@@ -17,7 +32,7 @@ echo "$title"
echo ""
echo "MCU Board Selection:"
PS3="$prompt "
-select opt in "${options[@]}" "Quit"; do
+select opt in "${options[@]}" "Quit"; do
case "$REPLY" in
@@ -25,15 +40,12 @@ select opt in "${options[@]}" "Quit"; do
2 ) board="proton_c"; break;;
3 ) board="bluemicro840_v1"; break;;
- $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit;;
- *) echo "Invalid option. Try another one.";continue;;
+ $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit 1;;
+ *) echo "Invalid option. Try another one."; continue;;
esac
done
-#read -p "Is this board a complete keyboard [yN]: " complete
-#echo "$complete"
-
echo ""
echo "Keyboard Shield Selection:"
@@ -42,8 +54,8 @@ options=("Kyria" "Lily58" "Corne" "Splitreus62" "Sofle" "Iris" "RoMac")
PS3="$prompt "
# TODO: Add support for "Other" and linking to docs on adding custom shields in user config repos.
-# select opt in "${options[@]}" "Other" "Quit"; do
-select opt in "${options[@]}" "Quit"; do
+# select opt in "${options[@]}" "Other" "Quit"; do
+select opt in "${options[@]}" "Quit"; do
case "$REPLY" in
@@ -56,8 +68,8 @@ select opt in "${options[@]}" "Quit"; do
7 ) shield_title="RoMac" shield="romac"; split="n"; break;;
# Add link to docs on adding your own custom shield in your ZMK config!
- # $(( ${#options[@]}+1 )) ) echo "Other!"; break;;
- $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit;;
+ # $(( ${#options[@]}+1 )) ) echo "Other!"; break;;
+ $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit 1;;
*) echo "Invalid option. Try another one.";continue;;
esac
@@ -67,41 +79,43 @@ if [ "$split" == "n" ]; then
repo_path="https://github.com/zmkfirmware/zmk-config-template.git"
fi
-read -e -p "Copy in the stock keymap for customization? [Yn]: " copy_keymap
+read -r -e -p "Copy in the stock keymap for customization? [Yn]: " copy_keymap
if [ -z "$copy_keymap" ] || [ "$copy_keymap" == "Y" ] || [ "$copy_keymap" == "y" ]; then copy_keymap="yes"; fi
-read -e -p "GitHub Username (leave empty to skip GitHub repo creation): " github_user
+read -r -e -p "GitHub Username (leave empty to skip GitHub repo creation): " github_user
if [ -n "$github_user" ]; then
- read -p "GitHub Repo Name [zmk-config]: " repo_name
- if [ -z "$repo_name" ]; then repo_name="zmk-config"; fi
+ read -r -p "GitHub Repo Name [zmk-config]: " repo_name
+ if [ -z "$repo_name" ]; then repo_name="zmk-config"; fi
- read -p "GitHub Repo [https://github.com/${github_user}/${repo_name}.git]: " github_repo
+ read -r -p "GitHub Repo [https://github.com/${github_user}/${repo_name}.git]: " github_repo
- if [ -z "$github_repo" ]; then github_repo="https://github.com/${github_user}/${repo_name}.git"; fi
+ if [ -z "$github_repo" ]; then github_repo="https://github.com/${github_user}/${repo_name}.git"; fi
else
- repo_name="zmk-config"
+ repo_name="zmk-config"
fi
echo ""
echo "Preparing a user config for:"
echo "* MCU Board: ${board}"
echo "* Shield: ${shield}"
+
if [ "$copy_keymap" == "yes" ]; then
echo "* Copy Keymap?: ✓"
else
echo "* Copy Keymap?: ❌"
fi
+
if [ -n "$github_repo" ]; then
- echo "* GitHub Repo To Push (please create this in GH first!): ${github_repo}"
+ echo "* GitHub Repo To Push (please create this in GH first!): ${github_repo}"
fi
echo ""
-read -p "Continue? [Yn]: " do_it
+read -r -p "Continue? [Yn]: " do_it
if [ -n "$do_it" ] && [ "$do_it" != "y" ] && [ "$do_it" != "Y" ]; then
- echo "Aborting..."
- exit
+ echo "Aborting..."
+ exit 1
fi
git clone --single-branch $repo_path ${repo_name}
@@ -118,10 +132,10 @@ fi
popd
sed -i'.orig' \
- -e "s/BOARD_NAME/$board/" \
- -e "s/SHIELD_NAME/$shield/" \
- -e "s/KEYBOARD_TITLE/$shield_title/" \
- .github/workflows/build.yml
+ -e "s/BOARD_NAME/$board/" \
+ -e "s/SHIELD_NAME/$shield/" \
+ -e "s/KEYBOARD_TITLE/$shield_title/" \
+ .github/workflows/build.yml
if [ "$board" == "proton_c" ]; then
# Proton-C board still fa
@@ -136,11 +150,24 @@ git add .
git commit -m "Initial User Config."
if [ -n "$github_repo" ]; then
- git remote add origin "$github_repo"
- git push --set-upstream origin $(git symbolic-ref --short HEAD)
+ git remote add origin "$github_repo"
+ git push --set-upstream origin "$(git symbolic-ref --short HEAD)"
+ push_return_code=$?
+
+ # If push failed, assume that the origin was incorrect and give instructions on fixing.
+ if [ ${push_return_code} -ne 0 ]; then
+ 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
+ fi
# TODO: Support determing the actions URL when non-https:// repo URL is used.
if [ "${github_repo}" != "${github_repo#https://}" ]; then
- echo "Your firmware should be available from the GitHub Actions shortly: ${github_url%.git}/actions"
+ echo "Your firmware should be available from GitHub Actions shortly: ${github_repo%.git}/actions"
fi
fi