Skip to content

Commit 016eae6

Browse files
committed
chore(tools): add esp-idf installer script
1 parent eab797a commit 016eae6

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

tools/install_idf.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ESP_IDF_VERSION=${ESP_IDF_VERSION:-v5.4.2}
5+
ESP_IDF_TARGET=${ESP_IDF_TARGET:-esp32p4}
6+
ESP_IDF_ROOT=${ESP_IDF_ROOT:-$HOME/.espressif}
7+
8+
IDF_PATH="${ESP_IDF_ROOT}/esp-idf-${ESP_IDF_VERSION}"
9+
REPO_URL="https://github.com/espressif/esp-idf.git"
10+
11+
for cmd in git python3 bash; do
12+
if ! command -v "$cmd" >/dev/null 2>&1; then
13+
echo "Error: '$cmd' is required but was not found in PATH." >&2
14+
echo "Please install $cmd before running this script." >&2
15+
exit 1
16+
fi
17+
done
18+
19+
mkdir -p "${ESP_IDF_ROOT}"
20+
21+
if [ -d "${IDF_PATH}" ] && [ ! -d "${IDF_PATH}/.git" ]; then
22+
echo "Error: ${IDF_PATH} exists but is not a git repository." >&2
23+
echo "Please remove or rename it before running this script." >&2
24+
exit 1
25+
fi
26+
27+
if [ ! -d "${IDF_PATH}/.git" ]; then
28+
echo "Cloning ESP-IDF ${ESP_IDF_VERSION} into ${IDF_PATH}"
29+
git clone --depth 1 --branch "${ESP_IDF_VERSION}" "${REPO_URL}" "${IDF_PATH}"
30+
else
31+
echo "Updating existing ESP-IDF checkout at ${IDF_PATH}"
32+
git -C "${IDF_PATH}" fetch --depth 1 origin "${ESP_IDF_VERSION}"
33+
git -C "${IDF_PATH}" reset --hard FETCH_HEAD
34+
fi
35+
36+
if [ ! -x "${IDF_PATH}/install.sh" ]; then
37+
echo "Error: install.sh not found or not executable in ${IDF_PATH}." >&2
38+
exit 1
39+
fi
40+
41+
"${IDF_PATH}/install.sh" "${ESP_IDF_TARGET}"
42+
43+
export IDF_PATH
44+
45+
# shellcheck source=/dev/null
46+
source "${IDF_PATH}/export.sh"
47+
48+
idf.py --version
49+
50+
echo
51+
cat <<INSTRUCTIONS
52+
ESP-IDF is installed at: ${IDF_PATH}
53+
To use ESP-IDF in new shells, run:
54+
export IDF_PATH="${IDF_PATH}"
55+
source "${IDF_PATH}/export.sh"
56+
Then, verify with:
57+
idf.py --version
58+
INSTRUCTIONS

0 commit comments

Comments
 (0)