diff --git a/docs/install.md b/docs/install.md index a060347a7f1b9cbdb1b110f39361be0e54f585e3..ca93d8361ae6fc91a2e278fb9812737e62c3e54b 100644 --- a/docs/install.md +++ b/docs/install.md @@ -43,7 +43,7 @@ This guide **does not** cover how to setup the JTAG probe on your system. In order to compile and flash a working OpenSK firmware, you will need the following: -* a working [Rust](https://rustup.rs/) toolchain installed on your system +* rustup (can be installed with https://rustup.rs/) * python3 and pip * the OpenSSL command line tool diff --git a/setup.sh b/setup.sh index ccaf518f99598cf116b5d0951a0d7dc692bb6926..ae0fd0cacaf8f118a9a5550a7a7ec3783d49fa95 100755 --- a/setup.sh +++ b/setup.sh @@ -13,18 +13,49 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -e + +# Check that rustup and pip3 are installed +check_command () { + if ! which "$1" >/dev/null + then + echo "Missing $1 command.$2" + exit 1 + fi +} +check_command rustup " Follow the steps under https://rustup.rs/ to install it." +check_command pip3 + # Ensure the submodules are pulled and up-to-date git submodule update --init done_text="$(tput bold)DONE.$(tput sgr0)" +patch_conflict_detected () { + cat <<EOF + +This script cannot be run twice without reverting the patches. + +To do so, follow these instructions: +1. Commit any changes you want to save. +2. Run the ./reset.sh script to revert all uncommitted changes. +3. Run the ./setup.sh script again. +EOF + exit 1 +} + # Apply patches to kernel. Do that in a sub-shell ( cd third_party/tock/ && \ for p in ../../patches/tock/[0-9][0-9]-*.patch do echo -n '[-] Applying patch "'$(basename $p)'"... ' - git apply "$p" && echo $done_text + if git apply "$p" + then + echo $done_text + else + patch_conflict_detected + fi done ) @@ -34,7 +65,12 @@ done_text="$(tput bold)DONE.$(tput sgr0)" for p in ../../patches/libtock-rs/[0-9][0-9]-*.patch do echo -n '[-] Applying patch "'$(basename $p)'"... ' - git apply "$p" && echo $done_text + if git apply "$p" + then + echo $done_text + else + patch_conflict_detected + fi done )