1#!/usr/bin/env bash 2# 3# Setup script to configure an MSYS2 environment for ESP-IDF. 4# 5# Use of this script is optional, there is also a prebuilt MSYS2 environment available 6# which can be downloaded and used as-is. 7# 8# See https://docs.espressif.com/projects/esp-idf/en/latest/get-started/windows-setup.html for full details. 9 10if [ "$OSTYPE" != "msys" ]; then 11 echo "This setup script expects to be run from an MSYS2 environment on Windows." 12 exit 1 13fi 14if ! [ -x /bin/pacman ]; then 15 echo "This setup script expects to use the pacman package manager from MSYS2." 16 exit 1 17fi 18if [ "$MSYSTEM" != "MINGW32" ]; then 19 echo "This setup script must be started from the 'MSYS2 MinGW 32-bit' start menu shortcut" 20 echo "OR by running `cygpath -w /mingw32.exe`" 21 echo "(The current MSYSTEM mode is $MSYSTEM but it expects it to be MINGW32)" 22 exit 1 23fi 24 25# if update-core still exists, run it to get the latest core MSYS2 system 26# (which no longer needs or includes update-core!) 27# 28# If this step runs, it will require a full restart of MSYS2 before it 29# can continue. 30[ -x /usr/bin/update-core ] && /usr/bin/update-core 31 32set -e 33 34pacman --noconfirm -Syu # This step may require the terminal to be closed and restarted 35 36pacman --noconfirm -S --needed gettext-devel gcc git make ncurses-devel flex bison gperf vim \ 37 mingw-w64-i686-python-pip mingw-w64-i686-python-cryptography unzip winpty mingw-w64-i686-gcc 38 39# if IDF_PATH is set, install requirements now as well 40if [ -n "$IDF_PATH" ]; then 41 python -m pip install -r "$IDF_PATH/requirements.txt" 42fi 43 44# Automatically download precompiled toolchain, unpack at /opt/xtensa-esp32-elf/ 45TOOLCHAIN_ZIP=xtensa-esp32-elf-gcc8_4_0-esp-2021r2-win32.zip 46echo "Downloading precompiled toolchain ${TOOLCHAIN_ZIP}..." 47cd ~ 48curl -LO --retry 10 https://dl.espressif.com/dl/${TOOLCHAIN_ZIP} 49mkdir -p /opt 50cd /opt 51rm -rf /opt/xtensa-esp32-elf # for upgrades 52unzip ~/${TOOLCHAIN_ZIP} 53rm ~/${TOOLCHAIN_ZIP} 54 55cat > /etc/profile.d/esp32_toolchain.sh << EOF 56# This file was created by ESP-IDF windows_install_prerequisites.sh 57# and will be overwritten if that script is run again. 58export PATH="/opt/xtensa-esp32-elf/bin:\$PATH" 59EOF 60 61# clean up pacman package cache to save some disk space 62pacman --noconfirm -Scc 63 64cat << EOF 65************************************************ 66MSYS2 environment is now ready to use ESP-IDF. 67 681) Run 'source /etc/profile' to add the toolchain to 69your path in this terminal. This command produces no output. 70You only need to do this once, future terminals do this 71automatically when opened. 72 732) After ESP-IDF is set up (see setup guide), edit the file 74`cygpath -w /etc/profile` 75and add a line to set the variable IDF_PATH so it points to the 76IDF directory, ie: 77 78export IDF_PATH=/c/path/to/esp-idf/directory 79 80************************************************ 81EOF 82